1.1 --- a/lib/font.c Mon Nov 12 17:55:53 2018 +0100
1.2 +++ b/lib/font.c Tue Nov 13 00:02:15 2018 +0100
1.3 @@ -24,6 +24,14 @@
1.4
1.5
1.6
1.7 +/* Space is a special case. */
1.8 +
1.9 +static char_definition_t space = {
1.10 + .width = 3, .height = 9, .data = {0, 0, 0, 0, 0, 0, 0, 0, 0}
1.11 + };
1.12 +
1.13 +
1.14 +
1.15 /* Initialise a font configuration. */
1.16
1.17 void init_font(font_config_t *cfg, uint8_t *chars, uint32_t *table,
1.18 @@ -47,7 +55,7 @@
1.19 if ((c >= fcfg->base) && (c < fcfg->limit))
1.20 return (char_definition_t *) ((uint8_t *) fcfg->chars + fcfg->table[c - fcfg->base]);
1.21 else
1.22 - return NULL;
1.23 + return &space;
1.24 }
1.25
1.26 /* Write a character to the screen, returning the next character position. */
1.27 @@ -61,11 +69,6 @@
1.28 *displayline = cfg->screen_start + y * cfg->line_length,
1.29 bitmap, mask;
1.30
1.31 - /* Space is a special case. */
1.32 -
1.33 - if (c == ' ')
1.34 - return x + 3;
1.35 -
1.36 for (sy = 0, dy = y; (sy < chardef->height) && (dy < cfg->line_count); sy++, dy++)
1.37 {
1.38 if (displayline >= cfg->screen_limit)
1.39 @@ -85,3 +88,26 @@
1.40
1.41 return x + chardef->width;
1.42 }
1.43 +
1.44 +/* Write a string to the screen, updating the coordinates to indicate the next
1.45 + character position. */
1.46 +
1.47 +void write_string(display_config_t *cfg, font_config_t *fcfg, const char *s,
1.48 + int *x, int *y, uint8_t colour)
1.49 +{
1.50 + const int line_height = 9;
1.51 +
1.52 + while (*s)
1.53 + {
1.54 + if (*x + get_char_definition(fcfg, *s)->width > cfg->line_length)
1.55 + {
1.56 + *x = 0; *y += line_height;
1.57 + }
1.58 +
1.59 + if (*y + line_height >= cfg->line_count)
1.60 + break;
1.61 +
1.62 + *x = write_char(cfg, fcfg, *s, *x, *y, colour);
1.63 + s++;
1.64 + }
1.65 +}