From 7c901071a1168d41905025177f1a7d5f6b873f7f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 23 Aug 2021 21:18:15 +0200 Subject: [PATCH] Refactor --- drivers/vga.c | 20 +++++++++++++------- kernel/kernel.c | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/vga.c b/drivers/vga.c index 3ea9cf6..c2e1dbe 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -5,8 +5,11 @@ // Charpos = 0xb8000 + 2(row*80 + col) // Memory -#define VIDEO_MEM (char*)0xb8000 -#define VIDEO_MEM_MAX (char*)0xb8fa0 +#define VGA_ADDRESS (char*)0xb8000 +#define VGA_ADDRESS_MAX (char*)0xb8fa0 + +#define MAX_ROWS 25 +#define MAX_COLS 80 // Global static unsigned int cursor_row = 0; @@ -16,12 +19,15 @@ 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)); + return (char*)(VGA_ADDRESS + 2*((row*80) + col)); } void writechar(char c, unsigned int col, unsigned int row, int attribute_byte) { + if( !attribute_byte ) + attribute_byte = 0x0f; + char* mem = get_vga_charpos_pointer(col, row); - *mem = c; // Write the character + *mem = c; // Write the character *(mem+1) = attribute_byte; // Write the attribute_byte } @@ -30,9 +36,9 @@ void writechar(char c, unsigned int col, unsigned int row, int attribute_byte) { Graphics Functions */ void clear_screen() { - // Make all the characters spaces - for( char* c = VIDEO_MEM; c <= VIDEO_MEM_MAX; c += 2 ) - *c = 0x20; + for( int c = 0; c < MAX_COLS; c++ ) + for( int r = 0; r < MAX_ROWS; r++ ) + writechar(0x20, c, r, 0x0); } void disable_vga_cursor() { diff --git a/kernel/kernel.c b/kernel/kernel.c index 2d24fd9..2620165 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,3 +1,5 @@ +#define NULL ((void*)0x0) + #include "../drivers/vga.h" void main() {