forked from Bananymous/banan-os
Kernel: Clean code in tty and vesa
This commit is contained in:
parent
2535eb1c4c
commit
5ae1fc58e9
|
@ -250,7 +250,7 @@ void TTY::PutCharAt(uint16_t ch, size_t x, size_t y)
|
||||||
cell.character = ch;
|
cell.character = ch;
|
||||||
cell.foreground = m_foreground;
|
cell.foreground = m_foreground;
|
||||||
cell.background = m_background;
|
cell.background = m_background;
|
||||||
VESA::PutEntryAt(ch, x, y, m_foreground, m_background);
|
VESA::PutCharAt(ch, x, y, m_foreground, m_background);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TTY::PutChar(char ch)
|
void TTY::PutChar(char ch)
|
||||||
|
@ -356,7 +356,7 @@ void TTY::PutCharCurrent(char ch)
|
||||||
y++;
|
y++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
VESA::PutEntryAt(ch, x, y, VESA::Color::BRIGHT_WHITE, VESA::Color::BLACK);
|
VESA::PutCharAt(ch, x, y, VESA::Color::BRIGHT_WHITE, VESA::Color::BLACK);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,48 +26,38 @@ namespace VESA
|
||||||
static uint32_t s_height = 0;
|
static uint32_t s_height = 0;
|
||||||
static uint8_t s_mode = 0;
|
static uint8_t s_mode = 0;
|
||||||
|
|
||||||
|
static uint32_t s_terminal_width = 0;
|
||||||
|
static uint32_t s_terminal_height = 0;
|
||||||
|
|
||||||
|
static void (*PutCharAtImpl)(uint16_t, uint32_t, uint32_t, Color, Color) = nullptr;
|
||||||
|
static void (*ClearImpl)(Color) = nullptr;
|
||||||
|
|
||||||
static void GraphicsPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg);
|
static void GraphicsPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg);
|
||||||
static void GraphicsClear(Color color);
|
static void GraphicsClear(Color color);
|
||||||
|
|
||||||
static void TextPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg);
|
static void TextPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg);
|
||||||
static void TextClear(Color color);
|
static void TextClear(Color color);
|
||||||
|
|
||||||
void PutEntryAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg)
|
void PutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg)
|
||||||
{
|
{
|
||||||
if (x >= s_width)
|
if (x >= s_width || y >= s_height)
|
||||||
return;
|
return;
|
||||||
if (y >= s_height)
|
PutCharAtImpl(ch, x, y, fg, bg);
|
||||||
return;
|
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS)
|
|
||||||
return GraphicsPutCharAt(ch, x, y, fg, bg);
|
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_TEXT)
|
|
||||||
return TextPutCharAt(ch, x, y, fg, bg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear(Color color)
|
void Clear(Color color)
|
||||||
{
|
{
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS)
|
ClearImpl(color);
|
||||||
return GraphicsClear(color);
|
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_TEXT)
|
|
||||||
return TextClear(color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GetTerminalWidth()
|
uint32_t GetTerminalWidth()
|
||||||
{
|
{
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS)
|
return s_terminal_width;
|
||||||
return s_width / font.Width;
|
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_TEXT)
|
|
||||||
return s_width;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GetTerminalHeight()
|
uint32_t GetTerminalHeight()
|
||||||
{
|
{
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS)
|
return s_terminal_height;
|
||||||
return s_height / font.Height;
|
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_TEXT)
|
|
||||||
return s_height;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Initialize()
|
bool Initialize()
|
||||||
|
@ -91,18 +81,26 @@ namespace VESA
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsClear(Color::BLACK);
|
PutCharAtImpl = GraphicsPutCharAt;
|
||||||
return true;
|
ClearImpl = GraphicsClear;
|
||||||
|
s_terminal_width = s_width / font.Width;
|
||||||
|
s_terminal_height = s_height / font.Height;
|
||||||
}
|
}
|
||||||
|
else if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_TEXT)
|
||||||
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_TEXT)
|
|
||||||
{
|
{
|
||||||
TextClear(Color::BLACK);
|
PutCharAtImpl = TextPutCharAt;
|
||||||
return true;
|
ClearImpl = TextClear;
|
||||||
|
s_terminal_width = s_width;
|
||||||
|
s_terminal_height = s_height;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
dprintln("Unsupported type for VESA framebuffer");
|
{
|
||||||
return false;
|
dprintln("Unsupported type for VESA framebuffer");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClearImpl(Color::BLACK);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t s_graphics_colors[]
|
static uint32_t s_graphics_colors[]
|
||||||
|
|
|
@ -23,7 +23,7 @@ private:
|
||||||
inline void RenderFromBuffer(size_t x, size_t y)
|
inline void RenderFromBuffer(size_t x, size_t y)
|
||||||
{
|
{
|
||||||
const auto& cell = m_buffer[y * m_width + x];
|
const auto& cell = m_buffer[y * m_width + x];
|
||||||
VESA::PutEntryAt(cell.character, x, y, cell.foreground, cell.background);
|
VESA::PutCharAt(cell.character, x, y, cell.foreground, cell.background);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace VESA
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
void PutEntryAt(uint16_t, uint32_t, uint32_t, Color, Color);
|
void PutCharAt(uint16_t, uint32_t, uint32_t, Color, Color);
|
||||||
void Clear(Color);
|
void Clear(Color);
|
||||||
|
|
||||||
uint32_t GetTerminalWidth();
|
uint32_t GetTerminalWidth();
|
||||||
|
|
Loading…
Reference in New Issue