From 6e1d10528b1c04c34c57995c85b45448715767f2 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 11 Oct 2023 15:37:06 +0200 Subject: x86_64: vga: improve text printing code --- source/arch/x86_64/src/video/vga/text.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source/arch/x86_64/src/video') diff --git a/source/arch/x86_64/src/video/vga/text.cpp b/source/arch/x86_64/src/video/vga/text.cpp index 11e3b1a..df61ce6 100644 --- a/source/arch/x86_64/src/video/vga/text.cpp +++ b/source/arch/x86_64/src/video/vga/text.cpp @@ -5,25 +5,34 @@ #include #include +#include namespace teachos::arch::video::vga::text { namespace { - auto constinit text_buffer = teachos::boot::asm_pointer{boot::vga_buffer_pointer}; + auto constexpr default_text_buffer_address = 0xb8000; - auto write(char character, std::byte color) -> void + extern "C" std::pair * vga_buffer_pointer; + auto constinit text_buffer = teachos::boot::asm_pointer{vga_buffer_pointer}; + + auto write(char code_point, attribute attribute) -> void { auto & p = *text_buffer; - (*p++) = static_cast(character); - (*p++) = color; + (*p++) = std::pair{code_point, attribute}; }; } // namespace - auto write(std::string_view text, std::byte color) -> void + auto clear(attribute attribute) -> void + { + *text_buffer = reinterpret_cast(default_text_buffer_address); + std::ranges::generate_n(*text_buffer, 2000, [&]{ return std::pair{' ', attribute}; }); + } + + auto write(std::string_view code_points, attribute attribute) -> void { - std::ranges::for_each(text, [&](auto character) { write(character, color); }); + std::ranges::for_each(code_points, [&](auto code_point) { write(code_point, attribute); }); } } // namespace teachos::arch::video::vga::text \ No newline at end of file -- cgit v1.2.3