diff options
Diffstat (limited to 'arch/x86_64/src/video/vga/text.cpp')
| -rw-r--r-- | arch/x86_64/src/video/vga/text.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/arch/x86_64/src/video/vga/text.cpp b/arch/x86_64/src/video/vga/text.cpp index f1e7412..0137ddb 100644 --- a/arch/x86_64/src/video/vga/text.cpp +++ b/arch/x86_64/src/video/vga/text.cpp @@ -1,6 +1,5 @@ #include "arch/video/vga/text.hpp" -#include "arch/boot/pointers.hpp" #include "arch/video/vga/io.hpp" #include "memory/asm_pointer.hpp" @@ -10,24 +9,18 @@ namespace teachos::arch::video::vga::text { - namespace { - auto constexpr default_text_buffer_address = 0xb8000; + auto constexpr DEFAULT_TEXT_BUFFER_WIDTH = 80U; + auto constexpr DEFAULT_TEXT_BUFFER_HEIGHT = 25U; extern "C" std::pair<char, attribute> * vga_buffer_pointer; auto constinit text_buffer = teachos::memory::asm_pointer{vga_buffer_pointer}; - - auto write(char code_point, attribute attribute) -> void - { - auto & p = *text_buffer; - (*p++) = std::pair{code_point, attribute}; - }; } // namespace auto clear(attribute attribute) -> void { - *text_buffer = reinterpret_cast<decltype(text_buffer)::pointer>(default_text_buffer_address); + *text_buffer = reinterpret_cast<decltype(text_buffer)::pointer>(DEFAULT_VGA_TEXT_BUFFER_ADDRESS); std::ranges::fill_n(*text_buffer, 2000, std::pair{' ', attribute}); } @@ -39,9 +32,34 @@ namespace teachos::arch::video::vga::text crtc::data_port::write(vga::crtc::data_port::read() | cursor_disable_byte); } - auto write(std::string_view code_points, attribute attribute) -> void + auto newline() -> void { - std::ranges::for_each(code_points, [&](auto code_point) { write(code_point, attribute); }); + auto base = reinterpret_cast<decltype(text_buffer)::pointer>(DEFAULT_VGA_TEXT_BUFFER_ADDRESS); + auto & raw_buffer = *text_buffer; + auto current_line = (raw_buffer - base) / DEFAULT_TEXT_BUFFER_WIDTH; + auto next_line = current_line + 1; + + if (next_line >= DEFAULT_TEXT_BUFFER_HEIGHT) + { + auto begin = base + DEFAULT_TEXT_BUFFER_WIDTH; + auto end = base + DEFAULT_TEXT_BUFFER_WIDTH * DEFAULT_TEXT_BUFFER_HEIGHT; + std::ranges::move(begin, end, base); + raw_buffer = base + current_line * DEFAULT_TEXT_BUFFER_WIDTH; + } + else + { + raw_buffer = base + next_line * DEFAULT_TEXT_BUFFER_WIDTH; + } } + auto write_char(char code_point, attribute attribute) -> void + { + auto & p = *text_buffer; + (*p++) = std::pair{code_point, attribute}; + }; + + auto write(std::string_view code_points, attribute attribute) -> void + { + std::ranges::for_each(code_points, [&](auto code_point) { write_char(code_point, attribute); }); + } } // namespace teachos::arch::video::vga::text |
