#include #include #include #include "lib/string.h" struct vga_display display; void vga_set_color(uint16_t c) { display.color = c; } void vga_set_pos(size_t r, size_t c) { display.row = r; display.col = c; } static uint16_t vga_build_char(char c, char color) { return (uint16_t)((color << 8) | c); } void vga_put_char(size_t row, size_t col, char c, uint16_t color) { size_t pos = (VGA_WIDTH * row) + col; display.buf[pos] = vga_build_char(c, color); } void vga_write_char(char c) { switch (c) { case '\n': vga_set_pos(++display.row, 0); break; default: vga_put_char(display.row, display.col, c, display.color); display.col++; } if (display.col == VGA_WIDTH) vga_set_pos(++display.row, 0); } void vprintl(char *str) { int i = 0; size_t len = strlen(str); for (i = 0; i <= len; i++) { vga_write_char(str[i]); } } static void clean_display(void) { int row, col; for (row = 0; row < VGA_HEIGHT; row++) for (col = 0; col < VGA_WIDTH; col++) vga_put_char(row, col, ' ', 0); } void init_display(uint16_t color) { display.buf = (uint16_t *)VGA_ADDRESS; vga_set_pos(0, 0); clean_display(); vga_set_color(color); vga_set_pos(0, 0); }