diff --git a/TODO.md b/TODO.md index c9d8fa5..bba626c 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,7 @@ # TO DO + - Refactor the VGA driver - Finish the book! - Multiboot support (for grub etc) - - VGA Library (Graphics) + - Rendering (VGA) - User input (Keyboard) - File system? diff --git a/drivers/vga.c b/drivers/vga.c index cde216f..3ea9cf6 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -1,5 +1,5 @@ // VGA Graphics Library -#include +#include "../kernel/io.h" // VGA base address: 0xb8000 // Charpos = 0xb8000 + 2(row*80 + col) @@ -19,10 +19,10 @@ char* get_vga_charpos_pointer(unsigned int col, unsigned int row) { return (char*)(VIDEO_MEM + 2*((row*80) + col)); } -void writechar(char c, unsigned int col, unsigned int row, int colorcode) { +void writechar(char c, unsigned int col, unsigned int row, int attribute_byte) { char* mem = get_vga_charpos_pointer(col, row); *mem = c; // Write the character - *(mem+1) = colorcode; // Write the colorcode + *(mem+1) = attribute_byte; // Write the attribute_byte } @@ -35,9 +35,9 @@ void clear_screen() { *c = 0x20; } -void disable_cursor() { - outb(0x3d4, 0x0a); - outb(0x3d5, 0x20); +void disable_vga_cursor() { + port_outb(0x0a, 0x3d4); + port_outb(0x20, 0x3d5); } @@ -49,19 +49,19 @@ void set_cursor_pos(unsigned int x, unsigned int y) { cursor_row = y; } -void print(char* str, int colorcode) { +void print(char* str, int attribute_byte) { for( char* c = str; *c != '\0'; c++ ) - writechar(*c, (unsigned int)(c - str) + cursor_col, cursor_row, colorcode); + writechar(*c, (unsigned int)(c - str) + cursor_col, cursor_row, attribute_byte); } -void println(char* str, int colorcode) { - print(str, colorcode); +void println(char* str, int attribute_byte) { + print(str, attribute_byte); cursor_row++; // Increment to next y-pos (newline) } // VGA Initialization Function void vga_init() { - disable_cursor(); + disable_vga_cursor(); clear_screen(); } diff --git a/drivers/vga.h b/drivers/vga.h index b5f2517..cf7a721 100644 --- a/drivers/vga.h +++ b/drivers/vga.h @@ -1,7 +1,7 @@ char* get_vga_charpos_pointer(unsigned int col, unsigned int row); void writechar(char c, unsigned int col, unsigned int row, int colorcode); void clear_screen(); -void disable_cursor(); +void disable_vga_cursor(); void set_cursor_pos(); void print(); void println(); diff --git a/kernel/io.c b/kernel/io.c index 4bdffb8..951ba67 100644 --- a/kernel/io.c +++ b/kernel/io.c @@ -1,5 +1,5 @@ // Function to read a byte from port -unsigned char port_byte_in(unsigned short port) { +unsigned char port_inb(unsigned short port) { unsigned char res; __asm__("in %%dx, %%al" : "=a" (res) : "d" (port)); @@ -7,13 +7,13 @@ unsigned char port_byte_in(unsigned short port) { } // to write a byte to port -void port_byte_out(unsigned short port, unsigned char data) { +void port_outb(unsigned short port, unsigned char data) { __asm__("out %%al, %%dx" : :"a" (data), "d" (port)); } // Read word from port -unsigned short port_word_in(unsigned short port) { +unsigned short port_inw(unsigned short port) { unsigned short res; __asm__("in %%dx, %%ax" : "=a" (res) : "d" (port)); @@ -21,6 +21,6 @@ unsigned short port_word_in(unsigned short port) { } // write word to port -void port_word_out(unsigned short port, unsigned short data) { +void port_outw(unsigned short port, unsigned short data) { __asm__("out %%ax, %%dx" : :"a" (data), "d" (port)); } diff --git a/kernel/io.h b/kernel/io.h index 87c3e5c..74b7419 100644 --- a/kernel/io.h +++ b/kernel/io.h @@ -1,5 +1,5 @@ -unsigned char port_byte_in(); -void port_byte_out(); +unsigned char port_inb(); +void port_outb(); -unsigned short port_word_in(); -void port_word_out(); +unsigned short port_inw(); +void port_outw();