# HG changeset patch # User Paul Boddie # Date 1542110272 -3600 # Node ID f124b4ddd0aede9fd14829ec879d461d5fa44c80 # Parent b2e2bf6df1f5e005d2143166f8de4a3e8f39d816 Introduced static font initialisation, modifying the font data format slightly. diff -r b2e2bf6df1f5 -r f124b4ddd0ae data/font.S --- a/data/font.S Tue Nov 13 00:34:10 2018 +0100 +++ b/data/font.S Tue Nov 13 12:57:52 2018 +0100 @@ -5,9 +5,6 @@ .section .flash, "a" -fontbase: -.word 33 - fontchars: /* 33 */ .byte 2 /* width in pixels */ @@ -1325,6 +1322,9 @@ .byte 0b000000 .byte 0b000000 +fontbase: +.word 33 + fontlimit: .word 127 fonttable: diff -r b2e2bf6df1f5 -r f124b4ddd0ae examples/vga/main.c --- a/examples/vga/main.c Tue Nov 13 00:34:10 2018 +0100 +++ b/examples/vga/main.c Tue Nov 13 12:57:52 2018 +0100 @@ -97,10 +97,9 @@ static SpriteOverwriting(scr, &screendata, &display_config, SOURCE_YSTEP); extern uint8_t fontchars[]; -extern uint32_t fonttable[]; -extern uint32_t fontbase, fontlimit; +extern font_range_t fontbase; -static font_config_t font_config; +static Font(font_config, fontchars, &fontbase); @@ -197,8 +196,6 @@ { int frame, x = 0, y = 0; - init_font(&font_config, fontchars, fonttable, fontbase, fontlimit); - for (frame = 0; frame < banner_config.frames; frame++) { /* Obtain the frame. */ diff -r b2e2bf6df1f5 -r f124b4ddd0ae include/font.h --- a/include/font.h Tue Nov 13 00:34:10 2018 +0100 +++ b/include/font.h Tue Nov 13 12:57:52 2018 +0100 @@ -34,23 +34,36 @@ } char_definition_t; +typedef struct +{ + uint32_t base; + uint32_t limit; + uint32_t table[]; + +} font_range_t; + /* Font configuration type. */ typedef struct { char_definition_t *chars; - uint32_t *table; - uint32_t base; - uint32_t limit; + font_range_t *range; } font_config_t; -/* Access functions. */ +/* Initialise a font. + + Font(, uint8_t *chars, font_range_t *range) +*/ -void init_font(font_config_t *cfg, uint8_t *chars, uint32_t *table, - uint32_t base, uint32_t limit); +#define Font(NAME, CHARS, RANGE) \ + font_config_t NAME = { \ + .chars = (char_definition_t *) (CHARS), \ + .range = RANGE}; + +/* Access functions. */ char_definition_t *get_char_definition(font_config_t *cfg, char c); diff -r b2e2bf6df1f5 -r f124b4ddd0ae lib/font.c --- a/lib/font.c Tue Nov 13 00:34:10 2018 +0100 +++ b/lib/font.c Tue Nov 13 12:57:52 2018 +0100 @@ -32,19 +32,6 @@ -/* Initialise a font configuration. */ - -void init_font(font_config_t *cfg, uint8_t *chars, uint32_t *table, - uint32_t base, uint32_t limit) -{ - cfg->chars = (char_definition_t *) chars; - cfg->table = table; - cfg->base = base; - cfg->limit = limit; -} - - - /* Return the character definition for the given character. */ char_definition_t *get_char_definition(font_config_t *fcfg, char c) @@ -52,8 +39,8 @@ /* Obtain the offset from the table and combine it with the character definitions base address. */ - if ((c >= fcfg->base) && (c < fcfg->limit)) - return (char_definition_t *) ((uint8_t *) fcfg->chars + fcfg->table[c - fcfg->base]); + if ((c >= fcfg->range->base) && (c < fcfg->range->limit)) + return (char_definition_t *) ((uint8_t *) fcfg->chars + fcfg->range->table[c - fcfg->range->base]); else return &space; } diff -r b2e2bf6df1f5 -r f124b4ddd0ae tools/makefont.py --- a/tools/makefont.py Tue Nov 13 00:34:10 2018 +0100 +++ b/tools/makefont.py Tue Nov 13 12:57:52 2018 +0100 @@ -76,10 +76,7 @@ .section .flash, "a" -fontbase: -.word %d - -fontchars:""" % base +fontchars:""" lineno = 1 offset = 0 @@ -108,8 +105,11 @@ # Write the limit of characters. print >>f_out, """\ +fontbase: +.word %d + fontlimit: -.word %d""" % point +.word %d""" % (base, point) # Write the offset table.