aboutsummaryrefslogtreecommitdiff
path: root/source/arch/x86_64/src/video
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2023-10-11 15:37:06 +0200
committerFelix Morgner <felix.morgner@ost.ch>2023-10-11 15:37:06 +0200
commit6e1d10528b1c04c34c57995c85b45448715767f2 (patch)
tree08531be2d19fc666a23d96371c8e91aab97ce53f /source/arch/x86_64/src/video
parent74eaee0fcc7390d4290b41a2a92ee34346e2f7c2 (diff)
downloadteachos-6e1d10528b1c04c34c57995c85b45448715767f2.tar.xz
teachos-6e1d10528b1c04c34c57995c85b45448715767f2.zip
x86_64: vga: improve text printing code
Diffstat (limited to 'source/arch/x86_64/src/video')
-rw-r--r--source/arch/x86_64/src/video/vga/text.cpp21
1 files changed, 15 insertions, 6 deletions
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 <algorithm>
#include <string_view>
+#include <utility>
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<char, attribute> * 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<std::byte>(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<decltype(text_buffer)::pointer>(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