Kernel: Restructure terminal initialization

This is still very ugly and will be rewritten in the future :D
This commit is contained in:
2025-04-18 01:19:59 +03:00
parent 439fb57d88
commit 554b13ac50
11 changed files with 85 additions and 53 deletions
+21 -18
View File
@@ -3,39 +3,42 @@
namespace Kernel
{
FramebufferTerminalDriver* FramebufferTerminalDriver::create(BAN::RefPtr<FramebufferDevice> framebuffer_device)
BAN::ErrorOr<BAN::RefPtr<FramebufferTerminalDriver>> FramebufferTerminalDriver::create(BAN::RefPtr<FramebufferDevice> framebuffer_device)
{
auto font = TRY(LibFont::Font::prefs());;
auto* driver = new FramebufferTerminalDriver(framebuffer_device);
if (driver == nullptr)
return nullptr;
return BAN::Error::from_errno(ENOMEM);
driver->m_font = BAN::move(font);
driver->set_cursor_position(0, 0);
driver->clear(TerminalColor::BLACK);
return driver;
return BAN::RefPtr<FramebufferTerminalDriver>::adopt(driver);
}
void FramebufferTerminalDriver::putchar_at(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg)
{
const uint8_t* glyph = font().has_glyph(ch) ? font().glyph(ch) : font().glyph('?');
const uint8_t* glyph = m_font.has_glyph(ch) ? m_font.glyph(ch) : m_font.glyph('?');
x *= font().width();
y *= font().height();
x *= m_font.width();
y *= m_font.height();
for (uint32_t dy = 0; dy < font().height() && y + dy < m_framebuffer_device->height(); dy++)
for (uint32_t dy = 0; dy < m_font.height() && y + dy < m_framebuffer_device->height(); dy++)
{
for (uint32_t dx = 0; dx < font().width() && x + dx < m_framebuffer_device->width(); dx++)
for (uint32_t dx = 0; dx < m_font.width() && x + dx < m_framebuffer_device->width(); dx++)
{
const uint8_t bitmask = 1 << (font().width() - dx - 1);
const auto color = glyph[dy * font().pitch()] & bitmask ? fg : bg;
const uint8_t bitmask = 1 << (m_font.width() - dx - 1);
const auto color = glyph[dy * m_font.pitch()] & bitmask ? fg : bg;
m_framebuffer_device->set_pixel(x + dx, y + dy, color.rgb);
}
}
m_framebuffer_device->sync_pixels_rectangle(x, y, font().width(), font().height());
m_framebuffer_device->sync_pixels_rectangle(x, y, m_font.width(), m_font.height());
}
bool FramebufferTerminalDriver::scroll(Color color)
{
m_framebuffer_device->scroll(font().height(), color.rgb);
m_framebuffer_device->scroll(m_font.height(), color.rgb);
m_framebuffer_device->sync_pixels_full();
return true;
}
@@ -50,16 +53,16 @@ namespace Kernel
void FramebufferTerminalDriver::set_cursor_position(uint32_t x, uint32_t y)
{
const uint32_t cursor_h = font().height() / 8;
const uint32_t cursor_top = font().height() * 13 / 16;
const uint32_t cursor_h = m_font.height() / 8;
const uint32_t cursor_top = m_font.height() * 13 / 16;
x *= font().width();
y *= font().height();
x *= m_font.width();
y *= m_font.height();
for (uint32_t dy = 0; dy < cursor_h; dy++)
for (uint32_t dx = 0; dx < font().width(); dx++)
for (uint32_t dx = 0; dx < m_font.width(); dx++)
m_framebuffer_device->set_pixel(x + dx, y + cursor_top + dy, s_cursor_color.rgb);
m_framebuffer_device->sync_pixels_rectangle(x, y + cursor_top, font().width(), cursor_h);
m_framebuffer_device->sync_pixels_rectangle(x, y + cursor_top, m_font.width(), cursor_h);
}
}