diff options
author | Nils Wallménius <nils@rockbox.org> | 2007-06-30 17:54:02 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2007-06-30 17:54:02 +0000 |
commit | df155c85778d1294b9e030929bfcd210fd8bc165 (patch) | |
tree | c777a6723d693817ba0781ef12933783eb29f3f1 | |
parent | 6cfb906a0eb07308ef5e2fa610ea2b966343186d (diff) | |
download | rockbox-df155c85778d1294b9e030929bfcd210fd8bc165.tar.gz rockbox-df155c85778d1294b9e030929bfcd210fd8bc165.zip |
Change unsigned long to uint32_t and long to int32_t to fix a crash in
64 bit sims. Make a couple of private functions 'static'.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13743 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/export/font.h | 5 | ||||
-rw-r--r-- | firmware/font.c | 53 |
2 files changed, 31 insertions, 27 deletions
diff --git a/firmware/export/font.h b/firmware/export/font.h index 57991a5d50..649a1d080d 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h | |||
@@ -19,6 +19,8 @@ | |||
19 | #ifndef _FONT_H | 19 | #ifndef _FONT_H |
20 | #define _FONT_H | 20 | #define _FONT_H |
21 | 21 | ||
22 | #include "inttypes.h" | ||
23 | |||
22 | /* | 24 | /* |
23 | * Incore font and image definitions | 25 | * Incore font and image definitions |
24 | */ | 26 | */ |
@@ -99,7 +101,7 @@ struct font { | |||
99 | const unsigned short *offset; /* offsets into bitmap data*/ | 101 | const unsigned short *offset; /* offsets into bitmap data*/ |
100 | const unsigned char *width; /* character widths or NULL if fixed*/ | 102 | const unsigned char *width; /* character widths or NULL if fixed*/ |
101 | int defaultchar; /* default char (not glyph index)*/ | 103 | int defaultchar; /* default char (not glyph index)*/ |
102 | long bits_size; /* # bytes of glyph bits*/ | 104 | int32_t bits_size; /* # bytes of glyph bits*/ |
103 | }; | 105 | }; |
104 | 106 | ||
105 | /* font routines*/ | 107 | /* font routines*/ |
@@ -111,7 +113,6 @@ int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) | |||
111 | int font_get_width(struct font* ft, unsigned short ch); | 113 | int font_get_width(struct font* ft, unsigned short ch); |
112 | const unsigned char * font_get_bits(struct font* ft, unsigned short ch); | 114 | const unsigned char * font_get_bits(struct font* ft, unsigned short ch); |
113 | void glyph_cache_save(void); | 115 | void glyph_cache_save(void); |
114 | void glyph_cache_load(void); | ||
115 | 116 | ||
116 | #else /* HAVE_LCD_BITMAP */ | 117 | #else /* HAVE_LCD_BITMAP */ |
117 | 118 | ||
diff --git a/firmware/font.c b/firmware/font.c index 1635441b7a..cf4a16a517 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #include <string.h> | 30 | #include <string.h> |
31 | #include "inttypes.h" | ||
31 | #include "lcd.h" | 32 | #include "lcd.h" |
32 | #include "font.h" | 33 | #include "font.h" |
33 | #include "file.h" | 34 | #include "file.h" |
@@ -60,13 +61,15 @@ static unsigned char *eofptr; | |||
60 | /* Font cache structures */ | 61 | /* Font cache structures */ |
61 | static struct font_cache font_cache_ui; | 62 | static struct font_cache font_cache_ui; |
62 | static int fnt_file = -1; /* >=0 if font is cached */ | 63 | static int fnt_file = -1; /* >=0 if font is cached */ |
63 | unsigned long file_width_offset; /* offset to file width data */ | 64 | uint32_t file_width_offset; /* offset to file width data */ |
64 | unsigned long file_offset_offset; /* offset to file offset data */ | 65 | uint32_t file_offset_offset; /* offset to file offset data */ |
65 | static void cache_create(int maxwidth, int height); | 66 | static void cache_create(int maxwidth, int height); |
66 | static int long_offset = 0; | 67 | static int long_offset = 0; |
67 | static int glyph_file; | 68 | static int glyph_file; |
68 | /* End Font cache structures */ | 69 | /* End Font cache structures */ |
69 | 70 | ||
71 | static void glyph_cache_load(void); | ||
72 | |||
70 | void font_init(void) | 73 | void font_init(void) |
71 | { | 74 | { |
72 | memset(&font_ui, 0, sizeof(struct font)); | 75 | memset(&font_ui, 0, sizeof(struct font)); |
@@ -89,14 +92,14 @@ static short readshort(void) | |||
89 | return s; | 92 | return s; |
90 | } | 93 | } |
91 | 94 | ||
92 | static long readlong(void) | 95 | static int32_t readlong(void) |
93 | { | 96 | { |
94 | unsigned long l; | 97 | uint32_t l; |
95 | 98 | ||
96 | l = *fileptr++ & 0xff; | 99 | l = *fileptr++ & 0xff; |
97 | l |= *fileptr++ << 8; | 100 | l |= *fileptr++ << 8; |
98 | l |= ((unsigned long)(*fileptr++)) << 16; | 101 | l |= ((uint32_t)(*fileptr++)) << 16; |
99 | l |= ((unsigned long)(*fileptr++)) << 24; | 102 | l |= ((uint32_t)(*fileptr++)) << 24; |
100 | return l; | 103 | return l; |
101 | } | 104 | } |
102 | 105 | ||
@@ -143,9 +146,9 @@ static struct font* font_load_header(struct font *pf) | |||
143 | return pf; | 146 | return pf; |
144 | } | 147 | } |
145 | /* Load memory font */ | 148 | /* Load memory font */ |
146 | struct font* font_load_in_memory(struct font* pf) | 149 | static struct font* font_load_in_memory(struct font* pf) |
147 | { | 150 | { |
148 | long i, noffset, nwidth; | 151 | int32_t i, noffset, nwidth; |
149 | 152 | ||
150 | if (!HAVEBYTES(4)) | 153 | if (!HAVEBYTES(4)) |
151 | return NULL; | 154 | return NULL; |
@@ -163,12 +166,12 @@ struct font* font_load_in_memory(struct font* pf) | |||
163 | if ( pf->bits_size < 0xFFDB ) | 166 | if ( pf->bits_size < 0xFFDB ) |
164 | { | 167 | { |
165 | /* pad to 16-bit boundary */ | 168 | /* pad to 16-bit boundary */ |
166 | fileptr = (unsigned char *)(((long)fileptr + 1) & ~1); | 169 | fileptr = (unsigned char *)(((int32_t)fileptr + 1) & ~1); |
167 | } | 170 | } |
168 | else | 171 | else |
169 | { | 172 | { |
170 | /* pad to 32-bit boundary*/ | 173 | /* pad to 32-bit boundary*/ |
171 | fileptr = (unsigned char *)(((long)fileptr + 3) & ~3); | 174 | fileptr = (unsigned char *)(((int32_t)fileptr + 3) & ~3); |
172 | } | 175 | } |
173 | 176 | ||
174 | if (noffset) | 177 | if (noffset) |
@@ -193,12 +196,12 @@ struct font* font_load_in_memory(struct font* pf) | |||
193 | pf->offset = (unsigned short *)fileptr; | 196 | pf->offset = (unsigned short *)fileptr; |
194 | 197 | ||
195 | /* Check we have sufficient buffer */ | 198 | /* Check we have sufficient buffer */ |
196 | if (!HAVEBYTES(noffset * sizeof(long))) | 199 | if (!HAVEBYTES(noffset * sizeof(int32_t))) |
197 | return NULL; | 200 | return NULL; |
198 | 201 | ||
199 | for (i=0; i<noffset; ++i) | 202 | for (i=0; i<noffset; ++i) |
200 | { | 203 | { |
201 | ((unsigned long*)(pf->offset))[i] = (unsigned long)readlong(); | 204 | ((uint32_t*)(pf->offset))[i] = (uint32_t)readlong(); |
202 | } | 205 | } |
203 | } | 206 | } |
204 | } | 207 | } |
@@ -219,12 +222,12 @@ struct font* font_load_in_memory(struct font* pf) | |||
219 | } | 222 | } |
220 | 223 | ||
221 | /* Load cached font */ | 224 | /* Load cached font */ |
222 | struct font* font_load_cached(struct font* pf) | 225 | static struct font* font_load_cached(struct font* pf) |
223 | { | 226 | { |
224 | unsigned long noffset, nwidth; | 227 | uint32_t noffset, nwidth; |
225 | unsigned char* oldfileptr = fileptr; | 228 | unsigned char* oldfileptr = fileptr; |
226 | 229 | ||
227 | if (!HAVEBYTES(2 * sizeof(long))) | 230 | if (!HAVEBYTES(2 * sizeof(int32_t))) |
228 | return NULL; | 231 | return NULL; |
229 | 232 | ||
230 | /* # longs of offset*/ | 233 | /* # longs of offset*/ |
@@ -243,17 +246,17 @@ struct font* font_load_cached(struct font* pf) | |||
243 | { | 246 | { |
244 | long_offset = 0; | 247 | long_offset = 0; |
245 | /* pad to 16-bit boundary */ | 248 | /* pad to 16-bit boundary */ |
246 | fileptr = (unsigned char *)(((long)fileptr + 1) & ~1); | 249 | fileptr = (unsigned char *)(((int32_t)fileptr + 1) & ~1); |
247 | } | 250 | } |
248 | else | 251 | else |
249 | { | 252 | { |
250 | long_offset = 1; | 253 | long_offset = 1; |
251 | /* pad to 32-bit boundary*/ | 254 | /* pad to 32-bit boundary*/ |
252 | fileptr = (unsigned char *)(((long)fileptr + 3) & ~3); | 255 | fileptr = (unsigned char *)(((int32_t)fileptr + 3) & ~3); |
253 | } | 256 | } |
254 | 257 | ||
255 | if (noffset) | 258 | if (noffset) |
256 | file_offset_offset = (unsigned long)(fileptr - freeptr); | 259 | file_offset_offset = (uint32_t)(fileptr - freeptr); |
257 | else | 260 | else |
258 | file_offset_offset = 0; | 261 | file_offset_offset = 0; |
259 | 262 | ||
@@ -261,10 +264,10 @@ struct font* font_load_cached(struct font* pf) | |||
261 | if ( pf->bits_size < 0xFFDB ) | 264 | if ( pf->bits_size < 0xFFDB ) |
262 | fileptr += noffset * sizeof(unsigned short); | 265 | fileptr += noffset * sizeof(unsigned short); |
263 | else | 266 | else |
264 | fileptr += noffset * sizeof(unsigned long); | 267 | fileptr += noffset * sizeof(uint32_t); |
265 | 268 | ||
266 | if (nwidth) | 269 | if (nwidth) |
267 | file_width_offset = (unsigned long)(fileptr - freeptr); | 270 | file_width_offset = (uint32_t)(fileptr - freeptr); |
268 | else | 271 | else |
269 | file_width_offset = 0; | 272 | file_width_offset = 0; |
270 | 273 | ||
@@ -416,11 +419,11 @@ load_cache_entry(struct font_cache_entry* p, void* callback_data) | |||
416 | p->width = pf->maxwidth; | 419 | p->width = pf->maxwidth; |
417 | } | 420 | } |
418 | 421 | ||
419 | long bitmap_offset = 0; | 422 | int32_t bitmap_offset = 0; |
420 | 423 | ||
421 | if (file_offset_offset) | 424 | if (file_offset_offset) |
422 | { | 425 | { |
423 | long offset = file_offset_offset + char_code * (long_offset ? sizeof(long) : sizeof(short)); | 426 | int32_t offset = file_offset_offset + char_code * (long_offset ? sizeof(int32_t) : sizeof(short)); |
424 | lseek(fnt_file, offset, SEEK_SET); | 427 | lseek(fnt_file, offset, SEEK_SET); |
425 | read (fnt_file, tmp, 2); | 428 | read (fnt_file, tmp, 2); |
426 | bitmap_offset = tmp[0] | (tmp[1] << 8); | 429 | bitmap_offset = tmp[0] | (tmp[1] << 8); |
@@ -434,7 +437,7 @@ load_cache_entry(struct font_cache_entry* p, void* callback_data) | |||
434 | bitmap_offset = ((pf->height + 7) / 8) * p->width * char_code; | 437 | bitmap_offset = ((pf->height + 7) / 8) * p->width * char_code; |
435 | } | 438 | } |
436 | 439 | ||
437 | long file_offset = FONT_HEADER_SIZE + bitmap_offset; | 440 | int32_t file_offset = FONT_HEADER_SIZE + bitmap_offset; |
438 | lseek(fnt_file, file_offset, SEEK_SET); | 441 | lseek(fnt_file, file_offset, SEEK_SET); |
439 | 442 | ||
440 | int src_bytes = p->width * ((pf->height + 7) / 8); | 443 | int src_bytes = p->width * ((pf->height + 7) / 8); |
@@ -492,7 +495,7 @@ const unsigned char* font_get_bits(struct font* pf, unsigned short char_code) | |||
492 | return bits; | 495 | return bits; |
493 | } | 496 | } |
494 | 497 | ||
495 | void glyph_file_write(void* data) | 498 | static void glyph_file_write(void* data) |
496 | { | 499 | { |
497 | struct font_cache_entry* p = data; | 500 | struct font_cache_entry* p = data; |
498 | struct font* pf = &font_ui; | 501 | struct font* pf = &font_ui; |
@@ -530,7 +533,7 @@ void glyph_cache_save(void) | |||
530 | return; | 533 | return; |
531 | } | 534 | } |
532 | 535 | ||
533 | void glyph_cache_load(void) | 536 | static void glyph_cache_load(void) |
534 | { | 537 | { |
535 | if (fnt_file >= 0) { | 538 | if (fnt_file >= 0) { |
536 | 539 | ||