I have made a kernel in C code, and added a custom .psf font. Unfortunately, the program doesn't seem to detect the file in the directory as valid. Here's the code that actually loads the font and prints the result:
void (*KernelStart)(Framebuffer*) = ((__attribute__((sysv_abi)) void (*)(Framebuffer*) ) header.e_entry);
PSF1_FONT* newFont = LoadPSF1Font(NULL, L"zap-light16.psf", ImageHandle, SystemTable);
if (newFont == NULL){
Print(L"Font is not valid or is not found...\r\n");
}
else
{
Print(L"Font found. char size = %d\r\n", newFont->psf1_Header->charsize);
}
Framebuffer* newBuffer = InitializeGOP();
I think the directory is the correct one, since the program loads files from the same place (bin folder inside the kernel).
The "kernel.c" file has code that determines the style and cursor position:
void putChar(Framebuffer* framebuffer, PSF1_FONT* psf1_font, unsigned int colour, char chr, unsigned int xOff, unsigned int yOff)
{
unsigned int* pixPtr = (unsigned int*)framebuffer->BaseAddress;
char* fontPtr = psf1_font->glyphBuffer + (chr * psf1_font->psf1_Header->charsize);
for(unsigned long y = yOff; y < yOff + 16; y++){
for (unsigned long x= xOff; x < xOff + 8; x++)
if((*fontPtr & (0b10000000 >> (x - xOff))) > 0){
*(unsigned int*)(pixPtr + x + (y * framebuffer->PixelsPerScanLine)) = colour;
}
}
fontPtr++;
}
Point CursorPosition;
void Print(Framebuffer* framebuffer, PSF1_FONT* psf1_font, unsigned int colour, char* str)
{
char* chr = str;
while(*chr != 0){
putChar(framebuffer, psf1_font, colour, *chr, CursorPosition.X, CursorPosition.Y);
CursorPosition.X+=8;
if(CursorPosition.X + 8 > framebuffer->Width)
{
CursorPosition.X = 0;
CursorPosition.Y += 16;
}
chr++;
}
}
void _start(Framebuffer* framebuffer, PSF1_FONT* psf1_font){
CursorPosition.X = 50;
CursorPosition.Y = 120;
for (int t = 0; t < 50; t+=1){
Print(framebuffer, psf1_font, 0xffffffff, "Hello Kernel :)");
}
return;
}
Compiler doesn't return any error either. The only feedback I receive is from my own program, which determines whether the font is correct or not.