diff options
Diffstat (limited to 'src/vga.cc')
-rw-r--r-- | src/vga.cc | 31 |
1 files changed, 19 insertions, 12 deletions
@@ -1,23 +1,30 @@ #include "vga.h" #include <string.h> -constexpr uint8_t vga_entry_color(VGA::vga_color fg, VGA::vga_color bg) { - return fg | bg << 4; -} - -constexpr uint16_t vga_entry(unsigned char uc, uint8_t color) { - return (uint16_t)uc | (uint16_t)color << 8; -} +static_assert(sizeof(VGA::Entry) == 2); -VGA::VGA(vga_color fg, vga_color bg, uint32_t address) { - color = vga_entry_color(fg, bg); - buffer = (uint16_t*)address; +VGA::VGA(vga_color fg, vga_color bg, uint32_t address) : color_fg(fg), color_bg(bg) { + buffer = reinterpret_cast<Entry*>(address); // clear buffer for (size_t y = 0; y < max_rows; y++) { for (size_t x = 0; x < max_columns; x++) { const size_t index = y * max_columns + x; - buffer[index] = vga_entry(' ', color); + buffer[index].c = ' '; + buffer[index].fg = color_fg; + buffer[index].bg = color_bg; + } + } +} + +void VGA::set_color(vga_color fg, vga_color bg) { + color_fg = fg; + color_bg = bg; + for (size_t y = 0; y < max_rows; y++) { + for (size_t x = 0; x < max_columns; x++) { + const size_t index = y * max_columns + x; + buffer[index].fg = color_fg; + buffer[index].bg = color_bg; } } } @@ -30,7 +37,7 @@ void VGA::write(char c) { break; default: { const size_t index = row * max_columns + column; - buffer[index] = vga_entry(c, (color == 0) ? this->color : color); + buffer[index].c = c; ++column; } } |