diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-02-11 16:17:53 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-02-11 21:33:21 +0200 |
commit | 9a299f2fe91554a1b9d9db402391ae757c591ef8 (patch) | |
tree | 2ec839c869316804954e6b09220140346874aa8d /src/vga.cc | |
parent | Generate target dependency files (diff) | |
download | kernel.cpp-9a299f2fe91554a1b9d9db402391ae757c591ef8.tar.xz |
Add comments to explain CGA ports better
Diffstat (limited to 'src/vga.cc')
-rw-r--r-- | src/vga.cc | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/src/vga.cc b/src/vga.cc deleted file mode 100644 index 66a6b3a..0000000 --- a/src/vga.cc +++ /dev/null @@ -1,92 +0,0 @@ -#include "vga.h" -#include <string.h> - -static_assert(sizeof(VGA::Entry) == 2); - -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].c = ' '; - buffer[index].fg = color_fg; - buffer[index].bg = color_bg; - } - } - - enable_cursor(14, 15); - update_cursor(); -} - -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; - } - } -} - -void VGA::enable_cursor(uint8_t start, uint8_t end) { - p_3d4.write(0x0a); - p_3d5.write((p_3d5.read() & 0xc0) | start); - - p_3d4.write(0x0b); - p_3d5.write((p_3d5.read() & 0xe0) | end); -} -void VGA::disable_cursor() { - p_3d4.write(0x0a); - p_3d5.write(0x20); -} -void VGA::update_cursor() { - const uint16_t pos = row * max_columns + column; - - p_3d4.write(0x0f); - p_3d5.write(static_cast<uint8_t>(pos & 0xff)); - - p_3d4.write(0x0e); - p_3d5.write(static_cast<uint8_t>((pos >> 8) & 0xff)); -} - -void VGA::write(char c) { - switch (c) { - case '\n': - column = 0; - ++row; - break; - default: { - const size_t index = row * max_columns + column; - buffer[index].c = c; - ++column; - } - } - - if (column == max_columns) { - column = 0; - ++row; - } - - if (row == max_rows) { - // scroll up - move rows 1~25 up by one - for (size_t y = 1; y < max_rows; y++) { - const auto prev_y = y - 1; - for (size_t x = 0; x < max_columns; ++x) { - const auto prev = prev_y * max_columns + x; - const auto idx = y * max_columns + x; - buffer[prev] = buffer[idx]; - } - } - --row; - } -} - -void VGA::write(ViewIterator& iter) { - while (iter) { - write(iter.next()); - } -} |