From fc05642b74f4fc8ebbc787d15c43b5de18545dac Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 30 Dec 2022 19:57:44 +0200 Subject: [PATCH] Kernel: Make Render from buffer public tty function --- kernel/arch/i386/TTY.cpp | 20 +++++++++++++------- kernel/include/kernel/TTY.h | 13 +++++++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/kernel/arch/i386/TTY.cpp b/kernel/arch/i386/TTY.cpp index 847fa655..b80d2d64 100644 --- a/kernel/arch/i386/TTY.cpp +++ b/kernel/arch/i386/TTY.cpp @@ -35,7 +35,7 @@ TTY::TTY() void TTY::Clear() { - for (size_t i = 0; i < m_width * m_height; i++) + for (uint32_t i = 0; i < m_width * m_height; i++) m_buffer[i] = { .foreground = m_foreground, .background = m_background, .character = ' ' }; VESA::Clear(m_background); } @@ -239,7 +239,13 @@ void TTY::HandleAnsiEscape(uint16_t ch) } } -void TTY::PutCharAt(uint16_t ch, size_t x, size_t y) +void TTY::RenderFromBuffer(uint32_t x, uint32_t y) +{ + const auto& cell = m_buffer[y * m_width + x]; + VESA::PutCharAt(cell.character, x, y, cell.foreground, cell.background); +} + +void TTY::PutCharAt(uint16_t ch, uint32_t x, uint32_t y) { auto& cell = m_buffer[y * m_width + x]; cell.character = ch; @@ -301,12 +307,12 @@ void TTY::PutChar(char ch) memmove(m_buffer, m_buffer + m_width, m_width * (m_height - 1) * sizeof(Cell)); // Clear last line in buffer - for (size_t x = 0; x < m_width; x++) + for (uint32_t x = 0; x < m_width; x++) m_buffer[(m_height - 1) * m_width + x] = { .foreground = m_foreground, .background = m_background, .character = ' ' }; // Render the whole buffer to the screen - for (size_t y = 0; y < m_height; y++) - for (size_t x = 0; x < m_width; x++) + for (uint32_t y = 0; y < m_height; y++) + for (uint32_t x = 0; x < m_width; x++) RenderFromBuffer(x, y); m_column = 0; @@ -339,8 +345,8 @@ void TTY::PutCharCurrent(char ch) } else { - static size_t x = 0; - static size_t y = 0; + static uint32_t x = 0; + static uint32_t y = 0; switch (ch) { diff --git a/kernel/include/kernel/TTY.h b/kernel/include/kernel/TTY.h index 2a847a47..d481c70f 100644 --- a/kernel/include/kernel/TTY.h +++ b/kernel/include/kernel/TTY.h @@ -13,18 +13,19 @@ public: void WriteString(const char* data); void SetCursorPosition(uint32_t x, uint32_t y); + uint32_t Height() const { return m_height; } + uint32_t Width() const { return m_width; } + + void RenderFromBuffer(uint32_t x, uint32_t y); + + // for kprint static void PutCharCurrent(char ch); private: void ResetAnsiEscape(); void HandleAnsiSGR(); void HandleAnsiEscape(uint16_t ch); - void PutCharAt(uint16_t ch, size_t x, size_t y); - inline void RenderFromBuffer(size_t x, size_t y) - { - const auto& cell = m_buffer[y * m_width + x]; - VESA::PutCharAt(cell.character, x, y, cell.foreground, cell.background); - } + void PutCharAt(uint16_t ch, uint32_t x, uint32_t y); private: struct Cell