summaryrefslogtreecommitdiff
path: root/stage3/font.c
diff options
context:
space:
mode:
authorLizzy Fleckenstein <eliasfleckenstein@web.de>2023-11-27 20:03:41 +0100
committerLizzy Fleckenstein <eliasfleckenstein@web.de>2023-11-27 20:03:41 +0100
commit0c1d5e64c32f9e35264910d6defb693829df6f52 (patch)
tree042b3ae06da8af4e8cbd3babdfa9702c67517ef6 /stage3/font.c
parent8b9f33dd745ebba0e819927ab3906635bfb3bf34 (diff)
downloadcuddles-0c1d5e64c32f9e35264910d6defb693829df6f52.tar.xz
font fixes
Diffstat (limited to 'stage3/font.c')
-rw-r--r--stage3/font.c98
1 files changed, 79 insertions, 19 deletions
diff --git a/stage3/font.c b/stage3/font.c
index 5933c14..5af691e 100644
--- a/stage3/font.c
+++ b/stage3/font.c
@@ -2,23 +2,33 @@
#include "letters.h"
#include "gfx.h"
-#define FONT_SIZE 2
+// important: must be a multiple of 2, else code won't work
+#define TAB_SIZE 4
-static const u16 outer_width = (LETTER_WIDTH + 2) * FONT_SIZE;
-static const u16 outer_height = (LETTER_HEIGHT + 2) * FONT_SIZE;
+static u16 font_size;
-static u16 cursor_x = 0;
-static u16 cursor_y = 0;
+static u16 outer_width, outer_height;
+static u16 cursor_x, cursor_y;
-static void print_chr(u16 at_x, u16 at_y, u8 c)
+static u16 screen_width, screen_height;
+
+void set_font_size(u16 size)
{
- u16 base_x = at_x * outer_width;
- u16 base_y = at_y * outer_height;
+ font_size = size;
+
+ outer_width = (LETTER_WIDTH + 2) * font_size;
+ outer_height = (LETTER_HEIGHT + 2) * font_size;
+
+ screen_width = gfx_info->width / outer_width;
+ screen_height = gfx_info->height / outer_height;
+}
- //gfx_set_area(base_x, base_y, outer_width, outer_height, 0xFF000000);
+static void render_char(u8 c)
+{
+ u16 base_x = cursor_x * outer_width;
+ u16 base_y = cursor_y * outer_height;
- if (c > 127)
- return;
+ gfx_set_area(base_x, base_y, outer_width, outer_height, 0xFF000000);
for (u16 x = 0; x < LETTER_WIDTH; x++)
for (u16 y = 0; y < LETTER_HEIGHT; y++) {
@@ -26,18 +36,68 @@ static void print_chr(u16 at_x, u16 at_y, u8 c)
continue;
gfx_set_area(
- base_x + (x + 1) * FONT_SIZE,
- base_y + (y + 1) * FONT_SIZE,
- FONT_SIZE, FONT_SIZE, 0xFFFFFFFF);
+ base_x + (x + 1) * font_size,
+ base_y + (y + 1) * font_size,
+ font_size, font_size, 0xFFFFFFFF);
}
}
-void println(char *line)
+static void fix_cursor()
{
- for (; *line != '\0'; ++cursor_x, ++line)
- print_chr(cursor_x, cursor_y, *line);
+ while (cursor_x >= screen_width) {
+ cursor_x -= screen_width;
+ cursor_y++;
+ }
+
+ while (cursor_y >= screen_height)
+ cursor_y -= screen_height;
+}
+
+void print_char(char c)
+{
+ switch (c) {
+ case '\n':
+ cursor_y++;
+ cursor_x = 0;
+ break;
+
+ case '\t':
+ cursor_x = (cursor_x + TAB_SIZE) & ~(TAB_SIZE - 1);
+ break;
- cursor_y++;
- cursor_x = 0;
+ case '\b':
+ if (cursor_x > 0)
+ cursor_x--;
+ break;
+
+ case '\r':
+ cursor_x = 0;
+ break;
+
+ case '\v':
+ // vertical tab intentionally unimplemented
+ break;
+
+ case '\a':
+ // todo: bell
+ break;
+
+ case '\f':
+ cursor_y = 0;
+ cursor_x = 0;
+ break;
+
+ default:
+ render_char(c);
+ cursor_x++;
+ }
+
+ fix_cursor();
+}
+
+void print(char *line)
+{
+ while (*line != '\0')
+ print_char(*line++);
}