diff --git a/drivers/vga.c b/drivers/vga.c index 2138ab7..959b491 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -1,13 +1,7 @@ // VGA Graphics Library #include "vga.h" #include "../kernel/io.h" - -// Memory -#define VGA_ADDRESS (char*)0xb8000 -#define VGA_ADDRESS_MAX (char*)0xb8fa0 - -#define MAX_ROWS 25 -#define MAX_COLS 80 +#include "../lib/str.h" static unsigned int cursor_row = 0; static unsigned int cursor_col = 0; @@ -50,7 +44,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, 0x0f); + writechar(0x20, c, r, 0xf0); } /* @@ -66,4 +60,18 @@ void println(char* str, int attribute_byte) { cursor_row++; // Increment to next y-pos (newline) } +void printalign(char* str, int attribute_byte, enum align alignment) { + unsigned int strlenbuf = strlen(str); + + if( !alignment || alignment == LEFT ) { + print(str, attribute_byte); + } else if ( alignment == RIGHT ) { + set_cursor_pos(MAX_COLS - strlenbuf, cursor_row); + } else if ( alignment == MIDDLE ) { + set_cursor_pos((MAX_COLS/2) - (strlenbuf/2), cursor_row); + } + + print(str, attribute_byte); +} + diff --git a/drivers/vga.h b/drivers/vga.h index 983fb09..04306ae 100644 --- a/drivers/vga.h +++ b/drivers/vga.h @@ -1,7 +1,19 @@ +#define VGA_ADDRESS (char*)0xb8000 +#define VGA_ADDRESS_MAX (char*)0xb8fa0 + +#define MAX_ROWS 25 +#define MAX_COLS 80 + +static unsigned int cursor_row; +static unsigned int cursor_col; + +enum align {LEFT, RIGHT, MIDDLE}; + char* get_memory_charpos(unsigned int col, unsigned int row); void writechar(char c, unsigned int col, unsigned int row, int colorcode); void clear_screen(); void set_cursor_pos(); void print(); void println(); +void printalign(char* str, int attribute_byte, enum align alignment); void vga_init(); diff --git a/kernel/kernel.c b/kernel/kernel.c index 13aacf8..ad32614 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -6,13 +6,18 @@ 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", 0x0f); + char* title = "eOS Version 0.1 2021"; + set_cursor_pos(0, 2); + printalign(title, 0xf0, MIDDLE); + char* subtitle = "A x86 operating system, licenced under GPL-2.0"; + set_cursor_pos(0, 3); + printalign(subtitle, 0xf8, MIDDLE); - char* strbuf = "Hello"; - char* str2 = "World!"; + + char* strbuf = "String concat: "; + char* str2 = "WORKS! :D"; strbuf = strcat(strbuf, str2); set_cursor_pos(0, 0); - println(strbuf, 0x0f); + println(strbuf, 0xf0); } diff --git a/preview.png b/preview.png index 285c5d7..42cc7ae 100644 Binary files a/preview.png and b/preview.png differ