From 22b1676cb7aa0e2fa7087d631b1f3f9b74387a6b Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 18 Aug 2021 22:24:00 +0200 Subject: [PATCH 1/4] Better function name --- drivers/vga.c | 11 ++++++++--- drivers/vga.h | 2 +- kernel/io.c | 8 ++++---- kernel/io.h | 8 ++++---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/vga.c b/drivers/vga.c index cde216f..56a76c8 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) @@ -35,9 +35,14 @@ void clear_screen() { *c = 0x20; } -void disable_cursor() { +void disable_vga_cursor() { + /* outb(0x3d4, 0x0a); outb(0x3d5, 0x20); + */ + + port_outb(0x0a, 0x3d4); + port_outb(0x20, 0x3d5); } @@ -62,6 +67,6 @@ void println(char* str, int colorcode) { // 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(); From 3bbbf7b114dd8381ef370c465bb6f3dfd8117906 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 18 Aug 2021 22:24:55 +0200 Subject: [PATCH 2/4] Cleanup --- drivers/vga.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/vga.c b/drivers/vga.c index 56a76c8..76cf14d 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -36,11 +36,6 @@ void clear_screen() { } void disable_vga_cursor() { - /* - outb(0x3d4, 0x0a); - outb(0x3d5, 0x20); - */ - port_outb(0x0a, 0x3d4); port_outb(0x20, 0x3d5); } From d70a3b03df5f2f67df0f9cffb7193d2250aff038 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 18 Aug 2021 22:33:33 +0200 Subject: [PATCH 3/4] TODO update --- TODO.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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? From d0050227bc983d09a1dc1d3d6ed5b0a32b63a2e9 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 19 Aug 2021 10:35:44 +0200 Subject: [PATCH 4/4] Better var name --- drivers/vga.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/vga.c b/drivers/vga.c index 76cf14d..3ea9cf6 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -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 } @@ -49,13 +49,13 @@ 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) }