diff options
author | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2022-10-07 16:42:35 +0200 |
---|---|---|
committer | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2022-10-07 16:42:35 +0200 |
commit | 1155e97dab101fd1215e12ff8737048b0f6bedaf (patch) | |
tree | 91ac7806d9c39593a5c6972e9fe02fa6fbb882b0 /stage3/font.c | |
parent | f8397815545adb7d0da36614e0065aa68453a2e4 (diff) | |
download | cuddles-1155e97dab101fd1215e12ff8737048b0f6bedaf.tar.xz |
Font rendering
Diffstat (limited to 'stage3/font.c')
-rw-r--r-- | stage3/font.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/stage3/font.c b/stage3/font.c new file mode 100644 index 0000000..c9ef520 --- /dev/null +++ b/stage3/font.c @@ -0,0 +1,42 @@ +#include "font.h" +#include "gfx.h" + +#define FONT_SIZE 3 + +static const u16 outer_width = (CHAR_WIDTH + 2) * FONT_SIZE; +static const u16 outer_height = (CHAR_HEIGHT + 2) * FONT_SIZE; + +extern u8 letters['z' - 'a' + 1][CHAR_HEIGHT * CHAR_WIDTH]; + +static u16 line_count = 0; + +static void print_chr(u16 at_x, u16 at_y, char c) +{ + u16 base_x = at_x * outer_width; + u16 base_y = at_y * outer_height; + + gfx_set_area(base_x, base_y, outer_width, outer_height, 0xFF000000); + + if (c > 'z' || c < 'a') + return; + + for (u16 x = 0; x < CHAR_WIDTH; x++) + for (u16 y = 0; y < CHAR_HEIGHT; y++) { + if (!letters[c - 'a'][y * CHAR_WIDTH + x]) + continue; + + gfx_set_area( + base_x + (x + 1) * FONT_SIZE, + base_y + (y + 1) * FONT_SIZE, + FONT_SIZE, FONT_SIZE, 0xFFFFFFFF); + } +} + +void print(char *line) +{ + for (u16 x = 0; *line != '\0'; ++x, ++line) + print_chr(x, line_count, *line); + + line_count++; +} + |