From 682b215c0d7350a8eb1b544f1e5275328118998d Mon Sep 17 00:00:00 2001 From: shibedrill Date: Fri, 11 Apr 2025 17:48:15 -0400 Subject: [PATCH] Remove o files --- .gitignore | 1 + Makefile | 1 + console/console.c | 32 ++++++++++++++++++++++++++++++-- include/console.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3ac583 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.bin \ No newline at end of file diff --git a/Makefile b/Makefile index 9f86a67..a9ba89e 100644 --- a/Makefile +++ b/Makefile @@ -17,3 +17,4 @@ $(O_FILES): gcc -Iinclude -fno-pie -m32 -ffreestanding -c ${@:.o=.c} -o $@ clean: find . -name \*.o | xargs --no-run-if-empty rm + find . -name \*.bin | xargs --no-run-if-empty rm diff --git a/console/console.c b/console/console.c index e047ca4..06c828e 100644 --- a/console/console.c +++ b/console/console.c @@ -1,3 +1,4 @@ +#include "../include/console.h" const int VGA_WIDTH = 80; const int VGA_HEIGHT = 25; @@ -7,6 +8,22 @@ char* const VGA_BUFFER = (char*) 0xb8000; static int terminal_position = 0; +static VGA_Color terminal_font_color = LIGHT_GRAY; // Default font color will be light gray + +static VGA_Color terminal_background_color = BLACK; // Default background color is black + +void set_terminal_font_color(VGA_Color col) { + + terminal_font_color = col; + +} + +void set_terminal_background_color(VGA_Color col) { + + terminal_background_color = col; + +} + void clear_terminal() { for (int i=0; i<(VGA_WIDTH * VGA_HEIGHT); i++) { @@ -19,19 +36,30 @@ void clear_terminal() { } void print_character(char c) { + print_character_with_color(c, terminal_background_color, terminal_font_color); +} + +void print_character_with_color(char c, VGA_Color bg, VGA_Color fg) { if (c == '\n') { terminal_position = (terminal_position + (VGA_BYTES_PER_CHARACTER * VGA_WIDTH)) - (terminal_position % (VGA_BYTES_PER_CHARACTER * VGA_WIDTH)); } else { VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER)] = c; - VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER) + 1] = 0x07; + int full_color = (bg << 4) | fg; + VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER) + 1] = full_color; terminal_position++; } } void print_string(char* string) { + print_string_with_color(string, terminal_background_color, terminal_font_color); + +} + +void print_string_with_color(char* string, VGA_Color bg, VGA_Color fg) { + for (int i=0; string[i] != '\0'; i++) { - print_character(string[i]); + print_character_with_color(string[i], bg, fg); } } diff --git a/include/console.h b/include/console.h index 10e3aab..101250e 100644 --- a/include/console.h +++ b/include/console.h @@ -16,4 +16,50 @@ void print_line(char* str); + typedef enum { + + BLACK=0, + + BLUE, + + GREEN, + + CYAN, + + RED, + + MAGENTA, + + BROWN, + + LIGHT_GRAY, + + DARK_GRAY, + + LIGHT_BLUE, + + LIGHT_GREEN, + + LIGHT_CYAN, + + LIGHT_RED, + + LIGHT_MAGENTA, + + YELLOW, + + WHITE + + } VGA_Color; + + void print_character_with_color(char c, VGA_Color bg_color, VGA_Color font_color); + + void print_string_with_color(char* str, VGA_Color bg_color, VGA_Color font_color); + + void print_line_with_color(char* str, VGA_Color bg_color, VGA_Color font_color); + + void set_terminal_font_color(VGA_Color col); + + void set_terminal_background_color(VGA_Color col); + #endif \ No newline at end of file