#include "video/Framebuffer.h" #include "boot/bootboot.h" static u8* g_fb_ptr = nullptr; static u32 g_fb_size; static u32 g_fb_width; static u32 g_fb_height; static u32 g_fb_scanline; extern const BOOTBOOT bootboot; extern u8 fb[1]; namespace Framebuffer { void init() { update(fb, bootboot.fb_size, bootboot.fb_width, bootboot.fb_height, bootboot.fb_scanline); } void update(u8* ptr, u32 size, u32 width, u32 height, u32 scanline) { g_fb_ptr = ptr; g_fb_size = size; g_fb_width = width; g_fb_height = height; g_fb_scanline = scanline; } void pixel(u32 x, u32 y, u32 color) { if (!g_fb_ptr) [[unlikely]] return; *(u32*)(g_fb_ptr + g_fb_scanline * y + x * 4) = color; } void rect(u32 x, u32 y, u32 w, u32 h, u32 color) { if (!g_fb_ptr) [[unlikely]] return; for (u32 i = y; i < (y + h); i++) { u32* addr = (u32*)(g_fb_ptr + (g_fb_scanline * i) + (x * sizeof(u32))); for (u32* it = addr; it < (addr + w); it++) *it = color; } } void rect(u32 x, u32 y, u32 w, u32 h, u32* colors) { if (!g_fb_ptr) [[unlikely]] return; u32 j = 0; for (u32 i = y; i < (y + h); i++) { u32* addr = (u32*)(g_fb_ptr + (g_fb_scanline * i) + (x * sizeof(u32))); for (u32* it = addr; it < (addr + w); it++, j++) *it = colors[j]; } } u8* ptr() { return g_fb_ptr; } u32 size() { return g_fb_size; } u32 width() { return g_fb_width; } u32 height() { return g_fb_height; } u32 scanline() { return g_fb_scanline; } }