diff --git a/kernel/src/vga.c b/kernel/src/vga.c index 9ad8d48..bb353a6 100644 --- a/kernel/src/vga.c +++ b/kernel/src/vga.c @@ -1,14 +1,33 @@ #include +#include #include "vga.h" -#define VGA_ADDRESS 0xb8000 - -static uint8_t current_color = VGA_WHITE; -uint16_t *vga_buffer = (uint16_t*)VGA_ADDRESS; +static const size_t VGA_WIDTH = 80; +static const size_t VGA_HEIGHT = 25; + +static volatile size_t terminal_row; +static volatile size_t terminal_column; +static volatile uint8_t current_color = VGA_WHITE; +static uint16_t *terminal_buffer = (uint16_t*)0xb8000; void vga_putc(char c) { - *(vga_buffer++) = (uint16_t)c | (uint16_t)(current_color) << 8; + size_t index = terminal_row*VGA_WIDTH + terminal_column; + if(c == '\t') { + vga_putc(' '); + while(terminal_column % 8 != 0) { + vga_putc(' '); + } + return; + } + if(c != '\n' && c != '\t') + terminal_buffer[index] = (uint16_t)c | (uint16_t)(current_color) << 8; + + if (c == '\n' || ++terminal_column == VGA_WIDTH) { + terminal_column = 0; + if (++terminal_row == VGA_HEIGHT) + terminal_row = 0; + } } void vga_puts(char *c) {