moved everything to chookspace
This commit is contained in:
40
kernel/src/BasicRenderer.cpp
Normal file
40
kernel/src/BasicRenderer.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "BasicRenderer.h"
|
||||
|
||||
BasicRenderer::BasicRenderer(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) {
|
||||
targetFramebuffer = framebuffer;
|
||||
PSF1_Font = psf1_Font;
|
||||
cursorPosition = {0,0};
|
||||
}
|
||||
|
||||
void BasicRenderer::PutChar(unsigned int colour, 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(unsigned int colour, const char* str) {
|
||||
unsigned int x = 0;
|
||||
char* chr = (char*)str;
|
||||
|
||||
while (*chr != 0) {
|
||||
PutChar(colour, *chr, cursorPosition.x, cursorPosition.y);
|
||||
cursorPosition.x+=8;
|
||||
|
||||
if (cursorPosition.x + 8 > targetFramebuffer->Width) {
|
||||
cursorPosition.x = 0;
|
||||
cursorPosition.y += 18;
|
||||
}
|
||||
|
||||
chr++;
|
||||
}
|
||||
}
|
||||
14
kernel/src/BasicRenderer.h
Normal file
14
kernel/src/BasicRenderer.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "math.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "PSF1Font.h"
|
||||
|
||||
class BasicRenderer {
|
||||
public:
|
||||
BasicRenderer(Framebuffer* framebuffer, PSF1_FONT* psf1_Font);
|
||||
Point cursorPosition;
|
||||
Framebuffer* targetFramebuffer;
|
||||
PSF1_FONT* PSF1_Font;
|
||||
void Print(unsigned int colour, const char* str);
|
||||
void PutChar(unsigned int colour, char chr, unsigned int xOff, unsigned int yOff);
|
||||
};
|
||||
10
kernel/src/Framebuffer.h
Normal file
10
kernel/src/Framebuffer.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
|
||||
struct Framebuffer {
|
||||
void* BaseAddress;
|
||||
size_t BufferSize;
|
||||
unsigned int Width;
|
||||
unsigned int Height;
|
||||
unsigned int PixelsPerScanline;
|
||||
};
|
||||
12
kernel/src/PSF1Font.h
Normal file
12
kernel/src/PSF1Font.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
struct PSF1_HEADER {
|
||||
unsigned char magic[2];
|
||||
unsigned char mode;
|
||||
unsigned char charsize;
|
||||
};
|
||||
|
||||
struct PSF1_FONT {
|
||||
PSF1_HEADER* psf1_Header;
|
||||
void* glyphBuffer;
|
||||
};
|
||||
17
kernel/src/kernel.cpp
Normal file
17
kernel/src/kernel.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "BasicRenderer.h"
|
||||
|
||||
|
||||
// supposed to protect against stack smashing but we have no way to actually like
|
||||
// do anything when we detect it soooo...
|
||||
extern "C" void __stack_chk_fail(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
extern "C" void _start(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) {
|
||||
BasicRenderer newRenderer = BasicRenderer(framebuffer, psf1_Font);
|
||||
newRenderer.Print(0xFFFFFF, "Hello, World!");
|
||||
|
||||
return;
|
||||
}
|
||||
6
kernel/src/math.h
Normal file
6
kernel/src/math.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
struct Point {
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
};
|
||||
Reference in New Issue
Block a user