summaryrefslogtreecommitdiff
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
parent8b9f33dd745ebba0e819927ab3906635bfb3bf34 (diff)
downloadcuddles-0c1d5e64c32f9e35264910d6defb693829df6f52.tar.xz
font fixes
-rw-r--r--bochsrc2
-rw-r--r--stage3.ld1
-rw-r--r--stage3/font.c98
-rw-r--r--stage3/font.h6
-rw-r--r--stage3/halt.c2
-rw-r--r--stage3/heap.c2
-rw-r--r--stage3/letters.c8
-rw-r--r--stage3/main.c44
-rw-r--r--stage3/paging.h2
9 files changed, 126 insertions, 39 deletions
diff --git a/bochsrc b/bochsrc
index 8b486a5..74b84ff 100644
--- a/bochsrc
+++ b/bochsrc
@@ -1,4 +1,4 @@
floppya: 1_44=lizzyx.img, status=inserted
boot: a
-display_library: x, options="gui_debug"
+#display_library: x, options="gui_debug"
megs: 32
diff --git a/stage3.ld b/stage3.ld
index da72329..002874a 100644
--- a/stage3.ld
+++ b/stage3.ld
@@ -1,6 +1,5 @@
OUTPUT(stage3.out)
OUTPUT_FORMAT(binary)
-ENTRY(kmain)
SECTIONS
{
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++);
}
diff --git a/stage3/font.h b/stage3/font.h
index fd2f2c0..2f43e9e 100644
--- a/stage3/font.h
+++ b/stage3/font.h
@@ -1,6 +1,10 @@
#ifndef _FONT_H_
#define _FONT_H_
-void println(char *line);
+#include "def.h"
+
+void print(char *line);
+void set_font_size(u16 size);
+void print_char(char c);
#endif
diff --git a/stage3/halt.c b/stage3/halt.c
index d4d0f64..39bc3c9 100644
--- a/stage3/halt.c
+++ b/stage3/halt.c
@@ -9,6 +9,6 @@ void halt()
void panic(char *msg)
{
- println(msg);
+ print(msg);
halt();
}
diff --git a/stage3/heap.c b/stage3/heap.c
index d9bc583..2909ba7 100644
--- a/stage3/heap.c
+++ b/stage3/heap.c
@@ -111,7 +111,7 @@ void heap_add_region(MemRegion *region)
void *region_end = region->start + region->size;
// rounds up region->start to pagesize align
- void *use_begin = (void *) ((u64) (region->start + PAGESIZE - 1) & (PAGESIZE - 1));
+ void *use_begin = (void *) ((u64) (region->start + PAGESIZE - 1) & ~(PAGESIZE - 1));
void *use_end = use_begin + region->used;
heap_add(region->start, use_begin - region->start);
diff --git a/stage3/letters.c b/stage3/letters.c
index ccec644..43f78fb 100644
--- a/stage3/letters.c
+++ b/stage3/letters.c
@@ -1,6 +1,6 @@
#include "letters.h"
-Letter letters[128];
+Letter letters[256];
void letters_init()
{
@@ -229,7 +229,7 @@ void letters_init()
0, 1, 0
}};
letters['@'] = (Letter) {{
- 0, 0, 1,
+ 0, 0, 0,
1, 1, 1,
1, 0, 1,
1, 1, 1,
@@ -362,11 +362,11 @@ void letters_init()
1, 0, 1
}};
letters['I'] = letters['i'] = (Letter) {{
+ 1, 1, 1,
0, 1, 0,
- 0, 0, 0,
0, 1, 0,
0, 1, 0,
- 0, 1, 0
+ 1, 1, 1
}};
letters['J'] = letters['j'] = (Letter) {{
0, 0, 1,
diff --git a/stage3/main.c b/stage3/main.c
index 3a96992..133dd42 100644
--- a/stage3/main.c
+++ b/stage3/main.c
@@ -8,11 +8,15 @@
void clear_screen(); // framebuffer.asm
-void kmain()
+void kmain();
+
+void init()
{
clear_screen();
letters_init();
+
heap_init();
+ set_font_size(3);
#define MMAP for (MemRegion *mreg = (void *) 0x500; mreg->start != nil; mreg++)
@@ -26,17 +30,37 @@ void kmain()
MMAP heap_add_region(mreg);
- gfx_set_area(0, 0, gfx_info->width, gfx_info->height, 0xFF000000);
+ kmain();
+ halt();
+}
+
+void charset_demo()
+{
+ const u8 max = '~' - '!' + 1;
- char str[128];
- str[127] = '\0';
- for (u8 i = 1; i < 128; i++)
- str[i-1] = i;
+ char str[max + 1];
+ str[max] = '\0';
- println(str);
+ for (u8 i = 0; i < max; i++)
+ str[i] = i + '!';
- halt();
+ print("charset demo:\n");
+ print(str);
+ print("\n");
}
-// 0xE0000000
-// 0xE03E8000
+void kmain()
+{
+ gfx_set_area(0, 0, gfx_info->width, gfx_info->height, 0xFF000000);
+ charset_demo();
+
+ print(
+ "\n"
+ "#include <stdio.h>\n\n"
+ "int main()\n{\n"
+ "\tprintf(\"hello, world\\n\");\n"
+ "\treturn 0;\n"
+ "}\n"
+ "\n"
+ );
+}
diff --git a/stage3/paging.h b/stage3/paging.h
index e05ab1a..cfcad6b 100644
--- a/stage3/paging.h
+++ b/stage3/paging.h
@@ -11,7 +11,7 @@ typedef enum {
typedef struct __attribute__((packed)) {
void *start;
usize size;
- u32 used;
+ usize used;
} MemRegion;
void page_region(MemRegion *region);