diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/font.c | 38 | ||||
-rw-r--r-- | firmware/font.h | 7 | ||||
-rw-r--r-- | firmware/loadfont.c | 28 | ||||
-rw-r--r-- | firmware/system.c | 4 |
4 files changed, 49 insertions, 28 deletions
diff --git a/firmware/font.c b/firmware/font.c index 5237f7d2aa..e9c70cd64e 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -83,6 +83,8 @@ getfont(int font) | |||
83 | { | 83 | { |
84 | PMWCFONT pf; | 84 | PMWCFONT pf; |
85 | 85 | ||
86 | if (font >= MAXFONTS) | ||
87 | font = 0; | ||
86 | while (1) { | 88 | while (1) { |
87 | pf = sysfonts[font].pf; | 89 | pf = sysfonts[font].pf; |
88 | if (pf && pf->height) | 90 | if (pf && pf->height) |
@@ -115,13 +117,13 @@ lcd_getstringsize(unsigned char *str, int font, int *w, int *h) | |||
115 | int width = 0; | 117 | int width = 0; |
116 | 118 | ||
117 | while((ch = *str++)) { | 119 | while((ch = *str++)) { |
118 | /* check input range*/ | 120 | /* check input range*/ |
119 | if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) | 121 | if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) |
120 | ch = pf->defaultchar; | 122 | ch = pf->defaultchar; |
121 | ch -= pf->firstchar; | 123 | ch -= pf->firstchar; |
122 | 124 | ||
123 | /* get proportional width and glyph bits*/ | 125 | /* get proportional width and glyph bits*/ |
124 | width += pf->width? pf->width[ch]: pf->maxwidth; | 126 | width += pf->width? pf->width[ch]: pf->maxwidth; |
125 | } | 127 | } |
126 | *w = width; | 128 | *w = width; |
127 | *h = pf->height; | 129 | *h = pf->height; |
@@ -150,7 +152,11 @@ lcd_putsxy(int x, int y, unsigned char *str, int font) | |||
150 | 152 | ||
151 | /* get proportional width and glyph bits*/ | 153 | /* get proportional width and glyph bits*/ |
152 | width = pf->width? pf->width[ch]: pf->maxwidth; | 154 | width = pf->width? pf->width[ch]: pf->maxwidth; |
153 | if(x + width > LCD_WIDTH) | 155 | if (x + width > LCD_WIDTH) |
156 | break; | ||
157 | |||
158 | /* no partial-height drawing for now...*/ | ||
159 | if (y + pf->height > LCD_HEIGHT) | ||
154 | break; | 160 | break; |
155 | bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch)); | 161 | bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch)); |
156 | 162 | ||
@@ -224,29 +230,29 @@ rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width, | |||
224 | MWIMAGEBITS srcmap; /* current src input bit*/ | 230 | MWIMAGEBITS srcmap; /* current src input bit*/ |
225 | MWIMAGEBITS dstmap; /* current dst output bit*/ | 231 | MWIMAGEBITS dstmap; /* current dst output bit*/ |
226 | 232 | ||
227 | /* calc src input bit*/ | 233 | /* calc src input bit*/ |
228 | srcmap = 1 << (sizeof(MWIMAGEBITS)*8-1); | 234 | srcmap = 1 << (sizeof(MWIMAGEBITS)*8-1); |
229 | 235 | ||
230 | /* calc dst output bit*/ | 236 | /* calc dst output bit*/ |
231 | if (i>0 && (i%8==0)) { | 237 | if (i>0 && (i%8==0)) { |
232 | ++dst_col; | 238 | ++dst_col; |
233 | dst_shift = 0; | 239 | dst_shift = 0; |
234 | } | 240 | } |
235 | dstmap = 1 << dst_shift++; | 241 | dstmap = 1 << dst_shift++; |
236 | 242 | ||
237 | /* for each input column...*/ | 243 | /* for each input column...*/ |
238 | for(j=0; j < width; j++) { | 244 | for(j=0; j < width; j++) { |
239 | 245 | ||
240 | /* calc input bitmask*/ | 246 | /* calc input bitmask*/ |
241 | MWIMAGEBITS bit = srcmap >> j; | 247 | MWIMAGEBITS bit = srcmap >> j; |
242 | if (bit==0) { | 248 | if (bit==0) { |
243 | srcmap = 1 << (sizeof(MWIMAGEBITS)*8-1); | 249 | srcmap = 1 << (sizeof(MWIMAGEBITS)*8-1); |
244 | bit = srcmap >> (j % 16); | 250 | bit = srcmap >> (j % 16); |
245 | } | 251 | } |
246 | 252 | ||
247 | /* if set in input, set in rotated output*/ | 253 | /* if set in input, set in rotated output*/ |
248 | if (bit & src[i]) { | 254 | if (bit & src[i]) { |
249 | /* input column j becomes output row*/ | 255 | /* input column j becomes output row*/ |
250 | dst[j*dst_linelen + dst_col] |= dstmap; | 256 | dst[j*dst_linelen + dst_col] |= dstmap; |
251 | } | 257 | } |
252 | /*debugf((bit & src[i])? "*": ".");*/ | 258 | /*debugf((bit & src[i])? "*": ".");*/ |
@@ -259,6 +265,6 @@ rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width, | |||
259 | /* ----------------------------------------------------------------- | 265 | /* ----------------------------------------------------------------- |
260 | * local variables: | 266 | * local variables: |
261 | * eval: (load-file "rockbox-mode.el") | 267 | * eval: (load-file "rockbox-mode.el") |
262 | * vim: et sw=4 ts=4 sts=4 tw=78 | 268 | * vim: et sw=4 ts=8 sts=4 tw=78 |
263 | * end: | 269 | * end: |
264 | */ | 270 | */ |
diff --git a/firmware/font.h b/firmware/font.h index 8535ab216b..645848ee18 100644 --- a/firmware/font.h +++ b/firmware/font.h | |||
@@ -46,7 +46,7 @@ | |||
46 | /* | 46 | /* |
47 | * .fnt (.rbf) loadable font file format definition | 47 | * .fnt (.rbf) loadable font file format definition |
48 | * | 48 | * |
49 | * format len description | 49 | * format len description |
50 | * ------------------------- ---- ------------------------------ | 50 | * ------------------------- ---- ------------------------------ |
51 | * UCHAR version[4] 4 magic number and version bytes | 51 | * UCHAR version[4] 4 magic number and version bytes |
52 | * UCHAR name[64] 64 font name, space padded | 52 | * UCHAR name[64] 64 font name, space padded |
@@ -54,6 +54,7 @@ | |||
54 | * USHORT maxwidth 2 font max width in pixels | 54 | * USHORT maxwidth 2 font max width in pixels |
55 | * USHORT height 2 font height in pixels | 55 | * USHORT height 2 font height in pixels |
56 | * USHORT ascent 2 font ascent (baseline) in pixels | 56 | * USHORT ascent 2 font ascent (baseline) in pixels |
57 | * USHORT pad 2 unused, pad to 32-bit boundary | ||
57 | * ULONG firstchar 4 first character code in font | 58 | * ULONG firstchar 4 first character code in font |
58 | * ULONG defaultchar 4 default character code in font | 59 | * ULONG defaultchar 4 default character code in font |
59 | * ULONG size 4 # characters in font | 60 | * ULONG size 4 # characters in font |
@@ -61,12 +62,13 @@ | |||
61 | * ULONG noffset 4 # longs offset data in file | 62 | * ULONG noffset 4 # longs offset data in file |
62 | * ULONG nwidth 4 # bytes width data in file | 63 | * ULONG nwidth 4 # bytes width data in file |
63 | * MWIMAGEBITS bits nbits*2 image bits variable data | 64 | * MWIMAGEBITS bits nbits*2 image bits variable data |
65 | * [MWIMAGEBITS padded to 32-bit boundary] | ||
64 | * ULONG offset noffset*4 offset variable data | 66 | * ULONG offset noffset*4 offset variable data |
65 | * UCHAR width nwidth*1 width variable data | 67 | * UCHAR width nwidth*1 width variable data |
66 | */ | 68 | */ |
67 | 69 | ||
68 | /* loadable font magic and version #*/ | 70 | /* loadable font magic and version #*/ |
69 | #define VERSION "RB10" | 71 | #define VERSION "RB11" |
70 | 72 | ||
71 | /* MWIMAGEBITS helper macros*/ | 73 | /* MWIMAGEBITS helper macros*/ |
72 | #define MWIMAGE_WORDS(x) (((x)+15)/16) /* image size in words*/ | 74 | #define MWIMAGE_WORDS(x) (((x)+15)/16) /* image size in words*/ |
@@ -122,5 +124,6 @@ void font_init(void); | |||
122 | /* ----------------------------------------------------------------- | 124 | /* ----------------------------------------------------------------- |
123 | * local variables: | 125 | * local variables: |
124 | * eval: (load-file "rockbox-mode.el") | 126 | * eval: (load-file "rockbox-mode.el") |
127 | * vim: et sw=4 ts=8 sts=4 tw=78 | ||
125 | * end: | 128 | * end: |
126 | */ | 129 | */ |
diff --git a/firmware/loadfont.c b/firmware/loadfont.c index 7f572a4841..e78f208b13 100644 --- a/firmware/loadfont.c +++ b/firmware/loadfont.c | |||
@@ -39,9 +39,8 @@ | |||
39 | /* static buffer allocation structures*/ | 39 | /* static buffer allocation structures*/ |
40 | static unsigned char mbuf[MAX_FONT_SIZE]; | 40 | static unsigned char mbuf[MAX_FONT_SIZE]; |
41 | static unsigned char *freeptr = mbuf; | 41 | static unsigned char *freeptr = mbuf; |
42 | typedef unsigned char CFILE; | 42 | static unsigned char *fileptr; |
43 | static CFILE *fileptr; | 43 | static unsigned char *eofptr; |
44 | static CFILE *eofptr; | ||
45 | 44 | ||
46 | static int | 45 | static int |
47 | READSHORT(unsigned short *sp) | 46 | READSHORT(unsigned short *sp) |
@@ -101,9 +100,9 @@ PMWCFONT | |||
101 | rbf_load_font(char *path, PMWCFONT pf) | 100 | rbf_load_font(char *path, PMWCFONT pf) |
102 | { | 101 | { |
103 | int fd, filesize; | 102 | int fd, filesize; |
104 | unsigned short maxwidth, height, ascent; | 103 | unsigned short maxwidth, height, ascent, pad; |
105 | unsigned long firstchar, defaultchar, size; | 104 | unsigned long firstchar, defaultchar, size; |
106 | unsigned long nbits, noffset, nwidth; | 105 | unsigned long i, nbits, noffset, nwidth; |
107 | char version[4+1]; | 106 | char version[4+1]; |
108 | char copyright[256+1]; | 107 | char copyright[256+1]; |
109 | 108 | ||
@@ -115,10 +114,12 @@ rbf_load_font(char *path, PMWCFONT pf) | |||
115 | DEBUGF("Can't open font: %s\n", path); | 114 | DEBUGF("Can't open font: %s\n", path); |
116 | return NULL; | 115 | return NULL; |
117 | } | 116 | } |
117 | freeptr = (unsigned char *)(((int)mbuf + 3) & ~3); | ||
118 | fileptr = freeptr; | 118 | fileptr = freeptr; |
119 | filesize = read(fd, fileptr, MAX_FONT_SIZE); | 119 | filesize = read(fd, fileptr, MAX_FONT_SIZE); |
120 | freeptr += filesize; | ||
121 | eofptr = fileptr + filesize; | 120 | eofptr = fileptr + filesize; |
121 | //freeptr += filesize; | ||
122 | //freeptr = (unsigned char *)(freeptr + 3) & ~3; /* pad freeptr*/ | ||
122 | close(fd); | 123 | close(fd); |
123 | if (filesize == MAX_FONT_SIZE) { | 124 | if (filesize == MAX_FONT_SIZE) { |
124 | DEBUGF("Font %s too large: %d\n", path, filesize); | 125 | DEBUGF("Font %s too large: %d\n", path, filesize); |
@@ -151,6 +152,8 @@ rbf_load_font(char *path, PMWCFONT pf) | |||
151 | if (!READSHORT(&ascent)) | 152 | if (!READSHORT(&ascent)) |
152 | return NULL; | 153 | return NULL; |
153 | pf->ascent = ascent; | 154 | pf->ascent = ascent; |
155 | if (!READSHORT(&pad)) | ||
156 | return NULL; | ||
154 | if (!READLONG(&firstchar)) | 157 | if (!READLONG(&firstchar)) |
155 | return NULL; | 158 | return NULL; |
156 | pf->firstchar = firstchar; | 159 | pf->firstchar = firstchar; |
@@ -177,16 +180,22 @@ rbf_load_font(char *path, PMWCFONT pf) | |||
177 | 180 | ||
178 | /* variable font data*/ | 181 | /* variable font data*/ |
179 | pf->bits = (MWIMAGEBITS *)fileptr; | 182 | pf->bits = (MWIMAGEBITS *)fileptr; |
180 | fileptr += nbits*sizeof(MWIMAGEBITS); | 183 | for (i=0; i<nbits; ++i) |
184 | if (!READSHORT(&pf->bits[i])) | ||
185 | return NULL; | ||
186 | /* pad to longword boundary*/ | ||
187 | fileptr = (unsigned char *)(((int)fileptr + 3) & ~3); | ||
181 | 188 | ||
182 | if (noffset) { | 189 | if (noffset) { |
183 | pf->offset = (unsigned long *)fileptr; | 190 | pf->offset = (unsigned long *)fileptr; |
184 | fileptr += noffset*sizeof(unsigned long); | 191 | for (i=0; i<noffset; ++i) |
192 | if (!READLONG(&pf->offset[i])) | ||
193 | return NULL; | ||
185 | } else pf->offset = NULL; | 194 | } else pf->offset = NULL; |
186 | 195 | ||
187 | if (nwidth) { | 196 | if (nwidth) { |
188 | pf->width = (unsigned char *)fileptr; | 197 | pf->width = (unsigned char *)fileptr; |
189 | fileptr += noffset*sizeof(unsigned char); | 198 | fileptr += nwidth*sizeof(unsigned char); |
190 | } else pf->width = NULL; | 199 | } else pf->width = NULL; |
191 | 200 | ||
192 | if (fileptr > eofptr) | 201 | if (fileptr > eofptr) |
@@ -198,5 +207,6 @@ rbf_load_font(char *path, PMWCFONT pf) | |||
198 | /* ----------------------------------------------------------------- | 207 | /* ----------------------------------------------------------------- |
199 | * local variables: | 208 | * local variables: |
200 | * eval: (load-file "rockbox-mode.el") | 209 | * eval: (load-file "rockbox-mode.el") |
210 | * vim: et sw=4 ts=8 sts=4 tw=78 | ||
201 | * end: | 211 | * end: |
202 | */ | 212 | */ |
diff --git a/firmware/system.c b/firmware/system.c index 74e3fce95d..1dce076093 100644 --- a/firmware/system.c +++ b/firmware/system.c | |||
@@ -19,7 +19,8 @@ | |||
19 | #include <stdio.h> | 19 | #include <stdio.h> |
20 | #include "config.h" | 20 | #include "config.h" |
21 | 21 | ||
22 | #include <lcd.h> | 22 | #include "lcd.h" |
23 | #include "font.h" | ||
23 | #include "led.h" | 24 | #include "led.h" |
24 | #include "system.h" | 25 | #include "system.h" |
25 | 26 | ||
@@ -325,6 +326,7 @@ void UIE (unsigned int pc) /* Unexpected Interrupt or Exception */ | |||
325 | 326 | ||
326 | /* clear screen */ | 327 | /* clear screen */ |
327 | lcd_clear_display (); | 328 | lcd_clear_display (); |
329 | lcd_setfont(FONT_SYSFIXED); | ||
328 | /* output exception */ | 330 | /* output exception */ |
329 | n = (n - (unsigned)UIE0 - 4)>>2; // get exception or interrupt number | 331 | n = (n - (unsigned)UIE0 - 4)>>2; // get exception or interrupt number |
330 | snprintf(str,sizeof(str),"I%02x:%s",n,irqname[n]); | 332 | snprintf(str,sizeof(str),"I%02x:%s",n,irqname[n]); |