diff --git a/Makefile b/Makefile index 5b13a7e..4c23ad8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -C_SOURCES = $(wildcard kernel/*.c drivers/*.c) -HEADERS = $(wildcard kernel/*.h drivers/*.h) +C_SOURCES = $(wildcard kernel/*.c drivers/*.c lib/*.c) +HEADERS = $(wildcard kernel/*.h drivers/*.h lib/*.h) OBJ = $(C_SOURCES:.c=.o) all: os-image diff --git a/TODO.md b/TODO.md index bba626c..32bdb54 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,11 @@ # TO DO - - Refactor the VGA driver - - Finish the book! + - Malloc + - String Library + + - Concat + - Format + + - Scrolling - Multiboot support (for grub etc) - Rendering (VGA) - User input (Keyboard) diff --git a/drivers/vga.c b/drivers/vga.c index c53692b..2138ab7 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -50,7 +50,7 @@ void set_cursor_pos(unsigned int col, unsigned int row) { void clear_screen() { for( int c = 0; c < MAX_COLS; c++ ) for( int r = 0; r < MAX_ROWS; r++ ) - writechar(0x20, c, r, 0xf0); + writechar(0x20, c, r, 0x0f); } /* diff --git a/kernel/kernel.c b/kernel/kernel.c index 290d9e5..13aacf8 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,15 +1,18 @@ #include "../drivers/vga.h" +#include "../lib/str.h" +#include "../lib/strf.h" void main() { vga_init(); // Initialize the screen first // i.e. clear the screen et cetera. set_cursor_pos(28, 2); - print("eOS Version 0.1 2021", 0xf0); + print("eOS Version 0.1 2021", 0x0f); - /* + + char* strbuf = "Hello"; + char* str2 = "World!"; + strbuf = strcat(strbuf, str2); set_cursor_pos(0, 0); - for( int i = 0; i < 255; i++ ) - println("X", i); - */ + println(strbuf, 0x0f); } diff --git a/kernel/memory.c b/kernel/memory.c new file mode 100644 index 0000000..b31569d --- /dev/null +++ b/kernel/memory.c @@ -0,0 +1 @@ +#include "memory.h" diff --git a/kernel/memory.h b/kernel/memory.h new file mode 100644 index 0000000..b2b140d --- /dev/null +++ b/kernel/memory.h @@ -0,0 +1,2 @@ +char* malloc(unsigned int size); +void mfree(char* p); diff --git a/lib/str.c b/lib/str.c new file mode 100644 index 0000000..d9345e1 --- /dev/null +++ b/lib/str.c @@ -0,0 +1,28 @@ +#include "str.h" + +unsigned int strlen(char* str) { + unsigned int len = 0; + for( char* c = str; *c != '\0'; c++ ) // search for end-of-string + len++; + + return len; +} + +char* strcat(char* buf, char* str) { + unsigned int bufferlen = strlen(buf); + + // remove the 0x0 char from the buffer + *(buf + bufferlen) = 0x3f; // replace end-of-string + // with a placeholder + + // concat the str to buf + int cc = 0; + for( char* c = str; *c != '\0'; c++ ) { + *(buf + bufferlen + cc) = *c; + cc++; + } + + *(buf + bufferlen + cc) = '\0'; // add end-of-string + + return buf; +} diff --git a/lib/str.h b/lib/str.h new file mode 100644 index 0000000..f50e596 --- /dev/null +++ b/lib/str.h @@ -0,0 +1,2 @@ +unsigned int strlen(char* str); +char* strcat(char* buf, char* str); diff --git a/lib/strf.c b/lib/strf.c new file mode 100644 index 0000000..65dddc7 --- /dev/null +++ b/lib/strf.c @@ -0,0 +1,15 @@ +#include "strf.h" + +#define int_offset 48 +// 0:48 - 9:57 + +char* int_to_str(int i, char* strbuf) { + if( i == 0 ) { + return (char*)(int_offset); + } else { + char cbuf; + cbuf = (char)((i % 10) + int_offset); + + return int_to_str(i / 10, strbuf + cbuf); + } +} diff --git a/lib/strf.h b/lib/strf.h new file mode 100644 index 0000000..29649bc --- /dev/null +++ b/lib/strf.h @@ -0,0 +1 @@ +char* int_to_str(int i, char* strbuf);