diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-01-13 14:16:50 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-01-13 14:16:50 +0100 |
| commit | 5a41c39169e45de71263c2419309244665cfa890 (patch) | |
| tree | 2f1a09d36d03bff98facb88f90ffe2bb9d39209e /arch/x86_64/src/vga/text/device.cpp | |
| parent | 67f4809a04999be393e5b10e924bcb0f685c721c (diff) | |
| download | teachos-5a41c39169e45de71263c2419309244665cfa890.tar.xz teachos-5a41c39169e45de71263c2419309244665cfa890.zip | |
x86_64/vga: extract buffer type
Diffstat (limited to 'arch/x86_64/src/vga/text/device.cpp')
| -rw-r--r-- | arch/x86_64/src/vga/text/device.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
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 <bit> +#include <cstddef> +#include <cstdint> +#include <string_view> + +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<buffer::cell *>(default_buffer_address + + std::bit_cast<std::uintptr_t>(&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 |
