2026-01-28 09:13:12 +11:00
|
|
|
#include "BasicRenderer.h"
|
|
|
|
|
|
|
|
|
|
BasicRenderer::BasicRenderer(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) {
|
|
|
|
|
targetFramebuffer = framebuffer;
|
|
|
|
|
PSF1_Font = psf1_Font;
|
2026-01-28 19:34:59 +11:00
|
|
|
Colour = 0xFFFFFFFF;
|
2026-01-28 09:13:12 +11:00
|
|
|
cursorPosition = {0,0};
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 19:34:59 +11:00
|
|
|
void BasicRenderer::PutChar(char chr, unsigned int xOff, unsigned int yOff) {
|
2026-01-28 09:13:12 +11:00
|
|
|
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) {
|
2026-01-28 19:34:59 +11:00
|
|
|
*(unsigned int*)(pixPtr + x + (y * targetFramebuffer->PixelsPerScanline)) = Colour;
|
2026-01-28 09:13:12 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fontPtr++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 19:34:59 +11:00
|
|
|
void BasicRenderer::Print(const char* str) {
|
2026-01-28 09:13:12 +11:00
|
|
|
unsigned int x = 0;
|
|
|
|
|
char* chr = (char*)str;
|
|
|
|
|
|
|
|
|
|
while (*chr != 0) {
|
2026-01-28 19:34:59 +11:00
|
|
|
PutChar(*chr, cursorPosition.x, cursorPosition.y);
|
2026-01-28 09:13:12 +11:00
|
|
|
cursorPosition.x+=8;
|
|
|
|
|
|
|
|
|
|
if (cursorPosition.x + 8 > targetFramebuffer->Width) {
|
|
|
|
|
cursorPosition.x = 0;
|
|
|
|
|
cursorPosition.y += 18;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chr++;
|
|
|
|
|
}
|
|
|
|
|
}
|