# HG changeset patch # User Paul Boddie # Date 1542063735 -3600 # Node ID b8630308b29e80d479bf12e04fc141743322e54c # Parent e7cf90210d941b89c889c9350b8f4289fb34ed90 Introduced an undefined character definition. Added string writing support. diff -r e7cf90210d94 -r b8630308b29e include/font.h --- a/include/font.h Mon Nov 12 17:55:53 2018 +0100 +++ b/include/font.h Tue Nov 13 00:02:15 2018 +0100 @@ -57,4 +57,7 @@ int write_char(display_config_t *cfg, font_config_t *fcfg, char c, int x, int y, uint8_t colour); +void write_string(display_config_t *cfg, font_config_t *fcfg, const char *s, + int *x, int *y, uint8_t colour); + #endif /* __FONT_H__ */ diff -r e7cf90210d94 -r b8630308b29e lib/font.c --- a/lib/font.c Mon Nov 12 17:55:53 2018 +0100 +++ b/lib/font.c Tue Nov 13 00:02:15 2018 +0100 @@ -24,6 +24,14 @@ +/* Space is a special case. */ + +static char_definition_t space = { + .width = 3, .height = 9, .data = {0, 0, 0, 0, 0, 0, 0, 0, 0} + }; + + + /* Initialise a font configuration. */ void init_font(font_config_t *cfg, uint8_t *chars, uint32_t *table, @@ -47,7 +55,7 @@ if ((c >= fcfg->base) && (c < fcfg->limit)) return (char_definition_t *) ((uint8_t *) fcfg->chars + fcfg->table[c - fcfg->base]); else - return NULL; + return &space; } /* Write a character to the screen, returning the next character position. */ @@ -61,11 +69,6 @@ *displayline = cfg->screen_start + y * cfg->line_length, bitmap, mask; - /* Space is a special case. */ - - if (c == ' ') - return x + 3; - for (sy = 0, dy = y; (sy < chardef->height) && (dy < cfg->line_count); sy++, dy++) { if (displayline >= cfg->screen_limit) @@ -85,3 +88,26 @@ return x + chardef->width; } + +/* Write a string to the screen, updating the coordinates to indicate the next + character position. */ + +void write_string(display_config_t *cfg, font_config_t *fcfg, const char *s, + int *x, int *y, uint8_t colour) +{ + const int line_height = 9; + + while (*s) + { + if (*x + get_char_definition(fcfg, *s)->width > cfg->line_length) + { + *x = 0; *y += line_height; + } + + if (*y + line_height >= cfg->line_count) + break; + + *x = write_char(cfg, fcfg, *s, *x, *y, colour); + s++; + } +}