From 5a41c39169e45de71263c2419309244665cfa890 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 13 Jan 2026 14:16:50 +0100 Subject: x86_64/vga: extract buffer type --- arch/x86_64/src/vga/text/device.cpp | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 arch/x86_64/src/vga/text/device.cpp (limited to 'arch/x86_64/src/vga/text/device.cpp') diff --git a/arch/x86_64/src/vga/text/device.cpp b/arch/x86_64/src/vga/text/device.cpp new file mode 100644 index 0000000..2da9e06 --- /dev/null +++ b/arch/x86_64/src/vga/text/device.cpp @@ -0,0 +1,60 @@ +#include "kapi/cio.hpp" + +#include "x86_64/boot/boot.hpp" +#include "x86_64/boot/ld.hpp" +#include "x86_64/vga/crtc.hpp" +#include "x86_64/vga/text.hpp" + +#include +#include +#include +#include + +namespace teachos::vga::x86_64::text +{ + namespace + { + constexpr auto default_buffer_address = std::uintptr_t{0xb8000}; + constexpr auto default_buffer_width = 80z; + constexpr auto default_buffer_height = 25z; + + constexpr auto bit_cursor_enabled = 5U; + } // namespace + + device::device() + : m_buffer{default_buffer_width, default_buffer_height, + std::bit_cast(default_buffer_address + + std::bit_cast(&teachos::boot::x86_64::TEACHOS_VMA)), + boot::bootstrap_information.vga_buffer_index} + { + clear(); + } + + auto device::clear() -> void + { + m_buffer.clear(); + } + + auto device::cursor(bool enabled) -> void + { + auto cursor_disable_byte = std::byte{!enabled} << bit_cursor_enabled; + + crtc::address::write(crtc::registers::cursor_start); + crtc::data::write(crtc::data::read() | cursor_disable_byte); + } + + auto device::write(cio::output_stream stream, std::string_view text) -> void + { + auto attributes = [&] -> attribute { + switch (stream) + { + case cio::output_stream::stderr: + return red_on_black; + default: + return green_on_black; + } + }(); + m_buffer.write(text, attributes); + } + +} // namespace teachos::vga::x86_64::text -- cgit v1.2.3