我用 C 代码制作了一个内核,并添加了一个自定义的 .psf 字体。不幸的是,该程序似乎没有检测到目录中的文件是有效的。这是实际加载字体并打印结果的代码:
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();
我认为该目录是正确的,因为程序从同一个地方加载文件(内核内的 bin 文件夹)。
“kernel.c”文件包含确定样式和光标位置的代码:
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;
}
编译器也不返回任何错误。我收到的唯一反馈来自我自己的程序,它决定了字体是否正确。