forked from 400plus/400plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmp.c
147 lines (111 loc) · 3.5 KB
/
bmp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Thanks to Coutts for porting this.
#if FALSE // Temporarily disable until we make it stable
#include <vxworks.h>
#include <stdarg.h>
#include "firmware/misc.h"
#include "debug.h"
#include "bmp.h"
uint8_t *VramAddrOverride;
static void _draw_char(uint8_t *vram_address, unsigned fontspec, uint8_t *bmp_vram_row, char c) {
//~ if (!bmp_enabled) return;
unsigned i,j;
const font_t * const font = fontspec_font( fontspec );
uint32_t fg_color = fontspec_fg( fontspec ) << 24;
uint32_t bg_color = fontspec_bg( fontspec ) << 24;
// Special case -- fg=bg=0 => white on black
if( fg_color == 0 && bg_color == 0 ) {
fg_color = COLOR_WHITE << 24;
bg_color = COLOR_BLACK << 24;
}
// Protect us from unprintable characters
if (c < 32 || c > 126)
c = '?';
const uint32_t pitch = BMPPITCH / 4;
uint32_t * front_row = (uint32_t *) bmp_vram_row;
//uint32_t flags = cli();
for( i=0 ; i<font->height ; i++ ) {
// Start this scanline
uint32_t * row = front_row;
// move to the next scanline
front_row += pitch;
uint16_t pixels = font->bitmap[ c + (i << 7) ];
uint8_t pixel;
for( j=0 ; j<font->width/4 ; j++ ) {
uint32_t bmp_pixels = 0;
for( pixel=0 ; pixel<4 ; pixel++, pixels <<=1 ) {
bmp_pixels >>= 8;
bmp_pixels |= (pixels & 0x8000) ? fg_color : bg_color;
}
if ((void *)row >= (void *)vram_address && (void *)row < (void *)(vram_address + VramSize)) {
*(row++) = bmp_pixels;
} else {
debug_log("VRAM: draw outside vram region (0x%08X)", row);
return;
}
}
}
//sei( flags );
}
void bmp_puts(uint8_t *vram_address, unsigned fontspec, unsigned * x, unsigned * y, const char * s) {
const uint32_t pitch = BMPPITCH;
if( !vram_address || ((int)vram_address & 1) == 1 )
return;
const unsigned initial_x = *x;
uint8_t * first_row = (uint8_t*) ((int)vram_address + ((*y) * pitch) + (*x));
uint8_t * row = first_row;
char c;
const font_t * const font = fontspec_font( fontspec );
while( (c = *s++) ) {
if( c == '\n' ) {
row = first_row += pitch * font->height;
(*y) += font->height;
(*x) = initial_x;
continue;
}
_draw_char(vram_address, fontspec, row, c );
row += font->width;
(*x) += font->width;
}
}
void bmp_printf(uint8_t *vram_address, unsigned fontspec, unsigned x, unsigned y, const char * fmt, ...) {
va_list ap;
char buf[256];
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
bmp_puts(vram_address, fontspec, &x, &y, buf);
}
// Andrew:
// bmp_hexdump(FONT_SMALL, 0, y_offset, 0xlocation_to_dump, 16*[# of lines to show on screen]);
// always keep x offset as 0 because it fills the whole screen as is :P
//
//~ Scaled in half from ML version. always have len as a multiple of 16. General
//~ use is 16 * num of lines desired printed.
void bmp_hexdump(uint8_t *vram_address, unsigned fontspec, unsigned x, unsigned y, const void * buf, int len) {
if( len == 0 )
return;
// Round up
len = (len + 15) & ~15;
const uint32_t * d = (uint32_t*) buf;
do {
bmp_printf(vram_address,fontspec, x, y,
"%08x: %08x %08x %08x %08x",
(unsigned) d,
len > 0 ? MEM(d+0) : 0,
len > 4 ? MEM(d+1) : 0,
len > 8 ? MEM(d+2) : 0,
len > 12 ? MEM(d+3) : 0
);
y += fontspec_height( fontspec );
d += 4;
len -= 16;
} while(len > 0);
}
/** Draw a picture of the BMP color palette. */
void bmp_draw_palette(uint8_t *vram_address) {
uint32_t x, y;
for (x = 0; x < 16 * 8; x++)
for (y = 0; y < 16 * 8; y++)
vram_address[x + y * 360] = (x / 8) | ((y / 8) << 4);
}
#endif