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) +}