I was able to read the info in the psf header very well, and now I need to display some characters.
The problem with the wiki tutorial (https://wiki.osdev.org/PC_Screen_Font) is that it only deals with 8-bit wide fonts, while I would like to be able to support any psf font.
I came across this post: viewtopic.php?f=1&t=41549&start=0. It describes my problem quite well, but even adapting my code with the remarks made there nothing works.
I also want to mention that I use a 12x24 font, and absolutely NOTHING appears on the screen when I try my putchar function (or I don't see it?)
Here is my code:
Code: Select all
void fb_putchar(char c) {
if (c == '\n')
goto newline;
int line;
int bytesperline = font->width/32;
int offset = (y_pos * font->height * pitch) +
(x_pos * (font->width+1) * 4);
u8 *glyph = (u8 *)&_binary_font_psf_start + font->headersize +
c * font->bytesperglyph;
serial_print("%x\n", glyph);
for (u32 y = 0; y < font->height; y++) {
line = offset;
for (u32 x = 0; x < font->width; x++) {
*((u32 *)(fb + line)) =
glyph[x / 8] & (0x80 >> (x & 7)) ? fg_color : bg_color;
line += 4;
}
glyph += bytesperline;
offset += pitch;
}
x_pos++;
if (x_pos >= width / 8) {
newline:
y_pos++;
x_pos = 0;
fb_putchar(' ');
}
}
Thank you very much, and I hope my post is correct, since it's the first one I'm doing here.