From 43e8caefdf80c6f7945c09a42ba09f70d907e68e Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 11 Aug 2021 19:36:51 +0200 Subject: [PATCH] Added VGA print --- src/kernel.c | 7 +++---- src/lib/vga.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/lib/vga.c diff --git a/src/kernel.c b/src/kernel.c index c5bc72d..4076de7 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,7 +1,6 @@ -// VGA base address: 0xb8000 -// Charpos = 0xb8000 + 2(row*80 + col) +#include "lib/vga.c" void main() { - char* video_mem = (char*)0xb8000; // VGA Video Memory location - *video_mem = 'X'; + // Do kernel stuff + println("HEJ", 3); } diff --git a/src/lib/vga.c b/src/lib/vga.c new file mode 100644 index 0000000..61e6275 --- /dev/null +++ b/src/lib/vga.c @@ -0,0 +1,18 @@ +// VGA Graphics Library + +// VGA base address: 0xb8000 +// Charpos = 0xb8000 + 2(row*80 + col) + +#define VIDEO_MEM (char*)0xb8000 +static char* cursor_pos = VIDEO_MEM; +static int cursor_y = 0; + +void set_cursor_pos(int row, int col) { cursor_pos = (char*)(VIDEO_MEM + 2*(row*80 + col)); } + +void println(char* str, int str_len) { + for( int i = 0; i < str_len; i++ ) { + set_cursor_pos(i, cursor_y); // set cursor pos + *cursor_pos = str[i]; // Write char to video memory + } + cursor_y++; // Increment to next y-pos (newline) +}