VGA Fonts In Graphics Mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
dannywrayuk
Posts: 6
Joined: Sat May 25, 2019 4:42 pm
Libera.chat IRC: danny

VGA Fonts In Graphics Mode

Post by dannywrayuk »

I'm currently trying to set up printing characters to the screen and I'm following the article on the wiki: https://wiki.osdev.org/VGA_Fonts

I can get the inefficient versions to work quit easily, that is, just calling the putpixel command several times. but I can't seem to get he optimised versions to work. I'm Specifically talking about the last piece of code in the article:

Code: Select all

void drawchar_transparent_8BPP(unsigned char c, int x, int y, int fgcolor)
{
	void *dest;
	uint32_t *dest32;
	unsigned char *src;
	int row;
	uint32_t fgcolor32;
 
	fgcolor32 = fgcolor | (fgcolor << 8) | (fgcolor << 16) | (fgcolor << 24);
	src = font + c * 16;
	dest = videoBuffer + y * bytes_per_line + x;
	for(row = 0; row < 16; row++) {
		if(*src != 0) {
			mask_low = mask_table[*src][0];
			mask_high = mask_table[*src][1];
			dest32 = dest;
			dest32[0] = (dest[0] & ~mask_low) | (fgcolor32 & mask_low);
			dest32[1] = (dest[1] & ~mask_high) | (fgcolor32 & mask_high);
		}
		src++;
		dest += bytes_per_line;
	}
}
I cant seem to get this code to work even after modifying it a fair bunch. There is also an example on the wiki in a slightly different article https://wiki.osdev.org/Drawing_In_Protected_Mode
(the last code section in the article) but i also cant get that one to work either. Can someone confirm is these pieces of code are actually correct? or if you have any alternate implementations?

cheers
danny
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: VGA Fonts In Graphics Mode

Post by MichaelPetch »

Out of curiosity is this a 32-bit kernel or 64-bit kernel? Using Multiboot or your own custom bootloader? Do you have a project available to look at? Building with optimizations on or off?
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: VGA Fonts In Graphics Mode

Post by bzt »

Hi,

I've written a font renderer that may help you. See "ssfn_putc()".

Cheers,
bzt
dannywrayuk
Posts: 6
Joined: Sat May 25, 2019 4:42 pm
Libera.chat IRC: danny

Re: VGA Fonts In Graphics Mode

Post by dannywrayuk »

Cheers bzt that helped quite a lot.
Turned out the issue was that the examples on wiki are only optimised for 8bpp and I was working in up to 32.
Solved the issue by reintroducing the inner for-loop and keeping the 'where' pointer outside of all the loops.
Post Reply