#include "BasicRenderer.h" BasicRenderer* GlobalRenderer; BasicRenderer::BasicRenderer(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) { targetFramebuffer = framebuffer; PSF1_Font = psf1_Font; Colour = 0xFFFFFFFF; cursorPosition = {0,0}; } void BasicRenderer::PutChar(char chr, unsigned int xOff, unsigned int yOff) { unsigned int* pixPtr = (unsigned int*)targetFramebuffer->BaseAddress; char* fontPtr = (char*)PSF1_Font->glyphBuffer + (chr * PSF1_Font->psf1_Header->charsize); for (unsigned long y = yOff; y < yOff + 18; y++) { for (unsigned long x = xOff; x < xOff+8; x++) { if ((*fontPtr & (0b10000000 >> (x - xOff))) > 0) { *(unsigned int*)(pixPtr + x + (y * targetFramebuffer->PixelsPerScanline)) = Colour; } } fontPtr++; } } void BasicRenderer::Print(const char* str) { unsigned int x = 0; char* chr = (char*)str; while (*chr != 0) { PutChar(*chr, cursorPosition.x, cursorPosition.y); cursorPosition.x+=8; if (cursorPosition.x + 8 > targetFramebuffer->Width) { cursorPosition.x = 0; cursorPosition.y += 18; } chr++; } } void BasicRenderer::Clear(uint32_t colour) { uint64_t fbBase = (uint64_t)targetFramebuffer->BaseAddress; uint64_t bytesPerScanline = targetFramebuffer->PixelsPerScanline * 4; uint64_t fbHeight = targetFramebuffer->Height; uint64_t fbSize = targetFramebuffer->BufferSize; for (int verticalScanline = 0; verticalScanline < fbHeight; verticalScanline ++){ uint64_t pixPtrBase = fbBase + (bytesPerScanline * verticalScanline); for (uint32_t* pixPtr = (uint32_t*)pixPtrBase; pixPtr < (uint32_t*)(pixPtrBase + bytesPerScanline); pixPtr ++){ *pixPtr = colour; } } } void BasicRenderer::Next() { cursorPosition.x = 0; cursorPosition.y += 16; }