diff --git a/Makefile b/Makefile index 4a99e2c..0eea523 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ all: os-image run: all qemu-system-x86_64 os-image +drun: clean run + grub: eOS.iso qemu-system-x86_64 eOS.iso @@ -32,4 +34,3 @@ clean: kernel.dis : kernel.bin ndisasm -b 32 $< > $@ - diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..94694f8 --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +# TO DO + - Multiboot support (for grub etc) + - Expand os-image so there is no error 0x8b00! diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 8629a26..ce6a1ec 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -4,7 +4,8 @@ void main() { // Do kernel stuff char* vidmem = (char*)0xb8000; *vidmem = 'X'; - for( int i = 0; i < 16; i++ ) { - println("C-Printing test!", 16); - } + + clear_screen(); + set_cursor_pos(24, 0); + println("\t eOS Version 0.0 2021", 0xf0); } diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c new file mode 100644 index 0000000..7b9dcd4 --- /dev/null +++ b/src/kernel/lib/string.c @@ -0,0 +1,8 @@ +// Generic String Library +#define INDEX(s, c) (int)(c-s) + +unsigned int length(char* str) { + char* p; + for( p = str; *p != '\0'; p++ ) {} + return (unsigned int)(p-str); +} diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index e3948e9..9d5d7cd 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -3,20 +3,52 @@ // VGA base address: 0xb8000 // Charpos = 0xb8000 + 2(row*80 + col) -#define VIDEO_MEM (char*)0xb8000 -#define GET_INDEX(s, c) (int)(c-s) -static int cursor_y = 0; +// Memory +#define VIDEO_MEM (char*)0xb8000 +#define VIDEO_MEM_MAX (char*)0xb8fa0 -char* get_cursor_pos(unsigned int col, unsigned int row) { +// Global +static unsigned int cursor_row = 0; +static unsigned int cursor_col = 0; + +/* + VGA & Memory Functions +*/ +char* get_vga_charpos_pointer(unsigned int col, unsigned int row) { return (char*)(VIDEO_MEM + 2*((row*80) + col)); } -void print(char* str, unsigned int str_len) { +void putc(char c, unsigned int col, unsigned int row, int colorcode) { + char* mem = get_vga_charpos_pointer(col, row); + *mem = c; // Write the character + *(mem+1) = colorcode; // Write the colorcode + +} + +/* + Graphics Functions +*/ +void clear_screen() { + // Make all the characters spaces + for( char* c = VIDEO_MEM; c <= VIDEO_MEM_MAX; c += 2 ) + *c = 0x20; +} + + +/* + General Printing Functions +*/ +void set_cursor_pos(unsigned int x, unsigned int y) { + cursor_col = x; + cursor_row = y; +} + +void print(char* str, int colorcode) { for( char* c = str; *c != '\0'; c++ ) - *get_cursor_pos( GET_INDEX(str, c), cursor_y ) = *c; + putc(*c, (unsigned int)(c - str) + cursor_col, cursor_row, colorcode); } -void println(char* str, unsigned int str_len) { - print(str, str_len); - cursor_y++; // Increment to next y-pos (newline) +void println(char* str, int colorcode) { + print(str, colorcode); + cursor_row++; // Increment to next y-pos (newline) }