#include "../include/console.h" const int VGA_WIDTH = 80; const int VGA_HEIGHT = 25; const int VGA_BYTES_PER_CHARACTER = 2; 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++) { // Text byte gets nulled VGA_BUFFER[i*2] = '\0'; // Style byte gets 0x07 for white text on a black background? VGA_BUFFER[i*2 + 1] = 0x07; } } 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; 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_with_color(string[i], bg, fg); } } void print_line(char* string) { print_string(string); print_character('\n'); }