diff --git a/kernel/arch/i386/TTY.cpp b/kernel/arch/i386/TTY.cpp index b80d2d6455..3cfc9c72c1 100644 --- a/kernel/arch/i386/TTY.cpp +++ b/kernel/arch/i386/TTY.cpp @@ -241,6 +241,8 @@ void TTY::HandleAnsiEscape(uint16_t ch) void TTY::RenderFromBuffer(uint32_t x, uint32_t y) { + if (x >= m_width || y >= m_height) + Kernel::panic("invalid render from buffer, {} {}", x, y); const auto& cell = m_buffer[y * m_width + x]; VESA::PutCharAt(cell.character, x, y, cell.foreground, cell.background); } diff --git a/kernel/arch/i386/VESA.cpp b/kernel/arch/i386/VESA.cpp index 2f5832a8a9..d5a5dbb89a 100644 --- a/kernel/arch/i386/VESA.cpp +++ b/kernel/arch/i386/VESA.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,8 +7,6 @@ #include #include -#include "font.h" - #include #define MULTIBOOT_FLAGS_FRAMEBUFFER (1 << 12) @@ -35,6 +34,8 @@ namespace VESA static void (*ClearImpl)(Color) = nullptr; static void (*SetCursorPositionImpl)(uint32_t, uint32_t, Color) = nullptr; + static void GraphicsPutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg); + static void GraphicsPutBitmapAt(const uint8_t* bitmap, 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 GraphicsSetCursorPosition(uint32_t x, uint32_t y, Color fg); @@ -43,6 +44,17 @@ namespace VESA static void TextClear(Color color); static void TextSetCursorPosition(uint32_t x, uint32_t y, Color fg); + void PutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg) + { + if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS) + GraphicsPutBitmapAt(bitmap, x, y, fg); + } + void PutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg, Color bg) + { + if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS) + GraphicsPutBitmapAt(bitmap, x, y, fg, bg); + } + void PutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg) { if (x >= s_width || y >= s_height) @@ -154,6 +166,48 @@ namespace VESA } } + static void GraphicsPutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg) + { + uint32_t u32_fg = s_graphics_colors[(uint8_t)fg]; + + uint32_t fx = x * font.Width; + uint32_t fy = y * font.Height; + + uint32_t row_offset = (fy * s_pitch) + (fx * (s_bpp / 8)); + for (uint32_t gy = 0; gy < font.Height; gy++) + { + uint32_t pixel_offset = row_offset; + for (uint32_t gx = 0; gx < font.Width; gx++) + { + if (bitmap[gy] & (1 << (font.Width - gx - 1))) + GraphicsSetPixel(pixel_offset, u32_fg); + pixel_offset += s_bpp / 8; + } + row_offset += s_pitch; + } + } + + static void GraphicsPutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg, Color bg) + { + uint32_t u32_fg = s_graphics_colors[(uint8_t)fg]; + uint32_t u32_bg = s_graphics_colors[(uint8_t)bg]; + + uint32_t fx = x * font.Width; + uint32_t fy = y * font.Height; + + uint32_t row_offset = (fy * s_pitch) + (fx * (s_bpp / 8)); + for (uint32_t gy = 0; gy < font.Height; gy++) + { + uint32_t pixel_offset = row_offset; + for (uint32_t gx = 0; gx < font.Width; gx++) + { + GraphicsSetPixel(pixel_offset, (bitmap[gy] & (1 << (font.Width - gx - 1))) ? u32_fg : u32_bg); + pixel_offset += s_bpp / 8; + } + row_offset += s_pitch; + } + } + static void GraphicsPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg) { // find correct bitmap @@ -167,25 +221,9 @@ namespace VESA } } - const unsigned char* glyph = font.Bitmap + index * font.Height; + const uint8_t* glyph = font.Bitmap + index * font.Height; - uint32_t u32_fg = s_graphics_colors[(uint8_t)fg]; - uint32_t u32_bg = s_graphics_colors[(uint8_t)bg]; - - uint32_t fx = x * font.Width; - uint32_t fy = y * font.Height; - - uint32_t row_offset = (fy * s_pitch) + (fx * (s_bpp / 8)); - for (uint32_t gy = 0; gy < font.Height; gy++) - { - uint32_t pixel_offset = row_offset; - for (uint32_t gx = 0; gx < font.Width; gx++) - { - GraphicsSetPixel(pixel_offset, (glyph[gy] & (1 << (font.Width - gx - 1))) ? u32_fg : u32_bg); - pixel_offset += s_bpp / 8; - } - row_offset += s_pitch; - } + GraphicsPutBitmapAt(glyph, x, y, fg, bg); } static void GraphicsClear(Color color) @@ -237,23 +275,7 @@ namespace VESA ________, }; - uint32_t u32_fg = s_graphics_colors[(uint8_t)fg]; - - uint32_t fx = x * font.Width; - uint32_t fy = y * font.Height; - - uint32_t row_offset = (fy * s_pitch) + (fx * (s_bpp / 8)); - for (uint32_t gy = 0; gy < font.Height; gy++) - { - uint32_t pixel_offset = row_offset; - for (uint32_t gx = 0; gx < font.Width; gx++) - { - if (cursor[gy] & (1 << (font.Width - gx - 1))) - GraphicsSetPixel(pixel_offset, u32_fg); - pixel_offset += s_bpp / 8; - } - row_offset += s_pitch; - } + GraphicsPutBitmapAt(cursor, x, y, fg); } } diff --git a/kernel/arch/i386/font.c b/kernel/arch/i386/font.c index 689423b79e..28792d72e6 100644 --- a/kernel/arch/i386/font.c +++ b/kernel/arch/i386/font.c @@ -1,7 +1,7 @@ // Created from bdf2c Version 3, (c) 2009, 2010 by Lutz Sammer // License AGPLv3: GNU Affero General Public License version 3 -#include "font.h" +#include /// character bitmap for each encoding static const unsigned char __font_bitmap__[] = { diff --git a/kernel/include/kernel/VESA.h b/kernel/include/kernel/VESA.h index 5c6d173d5b..32ae48688b 100644 --- a/kernel/include/kernel/VESA.h +++ b/kernel/include/kernel/VESA.h @@ -26,6 +26,8 @@ namespace VESA }; bool Initialize(); + void PutBitmapAt(const uint8_t*, uint32_t, uint32_t, Color); + void PutBitmapAt(const uint8_t*, uint32_t, uint32_t, Color, Color); void PutCharAt(uint16_t, uint32_t, uint32_t, Color, Color); void Clear(Color); void SetCursorPosition(uint32_t, uint32_t, Color); diff --git a/kernel/arch/i386/font.h b/kernel/include/kernel/font.h similarity index 100% rename from kernel/arch/i386/font.h rename to kernel/include/kernel/font.h