VGA speed (and one other vga issue)

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
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

VGA speed (and one other vga issue)

Post by lukem95 »

I am currently using VGA mode 320x200x256 and plotting pixels takes forever (about two seconds to fill the screen in virtualpc, slightly less in bochs/qemu). Is this just cos of the VGA mode (will it increase with a better mode, such as a VESA mode), or is it just my method of plotting pixels.

I have a put_pixel function that uses pokeb to poke the data into the correct address space. Should i use double buffering? Is there much speed increase?

and finally, for plotting my font i read the background colour and use this so i don't overwrite it when nothing should be written (if that makes sense).

how do i read the pixel in 16 colour mode?
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Re: VGA speed (and one other vga issue)

Post by bluecode »

Is this just cos of the VGA mode (will it increase with a better mode, such as a VESA mode)
afaik it woun't improve with VESA
lukem_95 wrote:I have a put_pixel function that uses pokeb to poke the data into the correct address space
copy 4bytes at a time, that speeds it up tremendously (At least on emulators).
how do i read the pixel in 16 colour mode?
Where is the problem? There are bitwise operations, you just have to extract the bits you want to read/write...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

I am currently using VGA mode 320x200x256 and plotting pixels takes forever (about two seconds to fill the screen in virtualpc, slightly less in bochs/qemu). Is this just cos of the VGA mode (will it increase with a better mode, such as a VESA mode), or is it just my method of plotting pixels.
Enable AGP if applicable, perform larger writes, do not overdraw (if you have to, do consider doublebuffering), use MTRRs to enable write-combining if do you not intend to use the VGA read/write modes. Limit VGA register accesses to a minimum. Do not read from video memory. Use a real machine.
how do i read the pixel in 16 colour mode?
In VGA mode, use the VGA registers to select the correct plane you want to read from, and extract the corresponding bit.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: VGA speed (and one other vga issue)

Post by Ready4Dis »

lukem_95 wrote:I am currently using VGA mode 320x200x256 and plotting pixels takes forever (about two seconds to fill the screen in virtualpc, slightly less in bochs/qemu). Is this just cos of the VGA mode (will it increase with a better mode, such as a VESA mode), or is it just my method of plotting pixels.

I have a put_pixel function that uses pokeb to poke the data into the correct address space. Should i use double buffering? Is there much speed increase?

and finally, for plotting my font i read the background colour and use this so i don't overwrite it when nothing should be written (if that makes sense).

how do i read the pixel in 16 colour mode?
Use a double buffer, and try to avoid plotting single pixels. A single memory copy to vga memory is much faster than a ton of peek/poke calls even in an emulator. Easiest way is to implement a few different types and benchmark them to find out the fastest method, and try it on a real pc, not emulator for a real test.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: VGA speed (and one other vga issue)

Post by jal »

lukem_95 wrote:I have a put_pixel function that uses pokeb to poke the data into the correct address space.
put_pixel most likely calculates the destination address every time you put a pixel, right? That's a bit superfluous if you are writing contiguous pixels. Basic rule: never use a putpixel function unless you are actually writing random pixels.


JAL
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

wow... i am failing big time at both of these things :D

but i'm leaving speed optimisation till iv done some more GUI stuff, written a few drivers, and am ready to start making my GUI usable.

but for now, i put a pixel (in 16 colour mode) by using:

Code: Select all

void put_pixel_16(unsigned x, unsigned y, unsigned c)
{
	unsigned wd_in_bytes, off, mask, p, pmask;

	wd_in_bytes = g_wd / 8;
	off = wd_in_bytes * y + x / 8;
	x = (x & 7) * 1;
	mask = 0x80 >> x;
	pmask = 1;
	for(p = 0; p < 4; p++)
	{
		set_plane(p);
		if(pmask & c)
			vpokeb(off, vpeekb(off) | mask);
		else
			vpokeb(off, vpeekb(off) & ~mask);
		pmask <<= 1;
	}
}
now i'm ashamed to say i dont understand this code (well... i sort of do), but i cannot find a piece of text explaining how to plot pixels in 16 colour mode, so im having to use this.

Can somebody point me to something that explains what has to be done (with the bit masks etc), and then hopefully i'll understand how to read the pixel information at a certain offset.

thankyou, lukem
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

pixel-access is the slowest way of writing 16-color screens. Each bit in the pixel is located in a different bank. you choose the bank (set_plane), read the original value, then write the new value with the appropriate bit masked out.

There's a pdf version of a book available that goes into speed and vga matters. Enjoy the read: http://www.byte.com/abrash/
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

lukem_95 wrote:but i'm leaving speed optimisation till iv done some more GUI stuff, written a few drivers, and am ready to start making my GUI usable.

but for now, i put a pixel (in 16 colour mode) by using:
You started this thread complaining about slow performance in 256 colour mode. Now you say you do not want to optimize, and you are using 16 colour mode. That's slightly inconsistent!


JAL
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

thanks for the link, ill give it a read when the server is back up (im getting a java error atm)

and yeah, im really just fiddling with VGA at the moment, i have two modes that i switch between, a 256 colour and a 16 colour mode.

sorry about the inconsistencies, i always feels im spamming a forum if i have too many topics at once. But i guess its poor practise to go so OT :S
~ Lukem95 [ Cake ]
Release: 0.08b
Image
Post Reply