Page 1 of 2

640x480x16 double buffer

Posted: Sat Sep 20, 2008 6:53 am
by i586coder
Hi, this is my first post in this forum
i want to know how to make double buffer for VGA 640x480x16
not VESA (screen mode 12h)
ThanX [-o<

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 7:21 am
by Combuster
Doublebuffering works the same for any graphics mode: you have one buffer in memory, then copy it over to video memory all at once.

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 7:38 am
by i586coder
thank you Combuster for replying :shock:

well, i tried your method like this:

screen(0x12);
while(!exit){
_memset((void*)DBuffer,0,DBufferSize);//clear buffer
:
_pset((void*)DBuffer,x,y,color); //plot pixel
:
_memcpy((void*)Dbuffer,0xA0000000L,DBufferSize);//copy buffer to video memory :)
}

and work ,but unexpected result,just like cut-off points
I think i need special _memcpy to work with 4-bit plane

ThanX again

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 8:11 am
by Brendan
Hi,

640 * 480 * 16 graphics mode is arranged as four separate 640 * 480 monochrome "banks", where one bit in each bank determines each pixel's color. Because of this you'd need to have 4 separate double buffers (one for each bank), then when you blit the buffer/s to display memory you'd select bank 0 (using VGA I/O ports) then copy the first bank to display memory at 0x000A0000, then select bank 1, then copy the second bank to display memory at 0x000A0000, then do the same for the other 2 banks.


Cheers,

Brendan

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 8:27 am
by i586coder
very nice Brendan

4 double buffer,...,what's about my
pixel plot function,how i can plot a pixel in 4 buffer to make color in specific location :(

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 8:36 am
by Combuster

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 8:42 am
by i586coder
my last question

is there around you guy's any tut.
or code sample for VGA regs.

and thanX for your interest =D>

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 8:43 am
by Combuster

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 8:46 am
by i586coder
great ! where is it man

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 9:02 am
by Combuster
There is one thing I'd make you aware of (since its part of the official forum rules). Good programmers should be self-sufficient enough to solve basic problems, and only ask when the are really stuck. That means they are able to
a) Try to write something
b) Experiment to attempt to discover the correct result
c) If that doesn't help, they use google or another search machine to find more information on the subject, then go back to a
d) If that doesn't help, they search the forums and go back to a
e) If that doesn't help, they search the wiki and go back to a
f) Only if you did not learn anything relevant within at least an hour, you can come here, explain your problem, and what you tried to do about it.
In other words. Ask smart questions.
Given the time spent between the questions you could not have possibly done your research to the extent where you could ask help.

Therefore, I point you once again to google.com. The answer is so readily available that if you can't find it then there would IMO be no hope for you.

So, I hereby invite you to do a little homework :wink:

Re: 640x480x16 double buffer

Posted: Sat Sep 20, 2008 9:42 am
by i586coder
ok, i have some things to tell you
a) I wrote too much
b) I used most search engine even altavista
c) I have my own OS,and i asked you about VGA 640x480x16 just to developed my OS GUI 320x200x256 multi-thraed triple buffer with
serial mouse driver

my OS is UNEXT/os --> you next/os
copy the image to floppy and look
this OS can run under dos||win9x||reboot machine with floppy

password: sfrot

to run gui with background
type in command line
exec system/xgui.exe system/wp1.bx3

note: the system under construction
8) 8) 8) 8)

http://code.google.com/p/unextos/

Re: 640x480x16 double buffer

Posted: Sun Sep 21, 2008 12:55 am
by pcmattman
Doesn't matter what you have, it's what you're asking that's the problem.

After a little bit of time on Google you could easily have found out that 640x480x16 is banked, and then more Googling takes you to information about the banks and how they work, a bit more Googling and you can find the VGA registers. Also look around - the Wiki has links to resources, that's why we have it.

If you've done all that and still can't get it to work, then it's time to ask around on the forums. Of course, before you ask, you should search and make sure your question isn't already solved.

Re: 640x480x16 double buffer

Posted: Mon Sep 22, 2008 2:31 am
by codemastersnake
check out some games development websites..... u'll find a lot of information over there...

Re: 640x480x16 double buffer

Posted: Tue Sep 23, 2008 5:40 am
by i586coder
greetings,

I found PASCAL code for plotting pixel in 640x480x16
& I translate it to C


typedef unsigned int word;
typedef unsigned char byte;

void plot_640x480x16(word x,word y,byte c){
asm{.386
MOV AX, 0xA000 //pointer to VGA
MOV ES, AX // memory
MOV DI, x
MOV CX, DI
SHR DI, 3
MOV AX, 80
MUL y
ADD DI, AX
AND CL, 0x07
MOV AH, 0x80
SHR AH, CL
MOV AL, 0x08
MOV DX, 0x03CE
OUT DX, AX
MOV AL, c
MOV AH, es:[DI]

MOV es:[DI], AL //plot _AL
}
}
//the bold red font need some explan
main(void){
_AX=0x12; asm int 0x10
plot_640x480x16(0,0,10);//must plot green pixel in aupper left corner
}

so, to make double buffer i think i need to copy pixel in buffer like this
plot_640x480x16(word x,word y,byte c,void* segment);
but to copy buffer segment to video segment 0xA000 directly the
same unexpected result returned. :?

Re: 640x480x16 double buffer

Posted: Tue Sep 23, 2008 12:29 pm
by Brendan
Hi,
AhmadTayseerDajani wrote:so, to make double buffer i think i need to copy pixel in buffer like this
plot_640x480x16(word x,word y,byte c,void* segment);
If one OUT instruction costs 1 us and each write to display memory costs 0.5 us, then (for 640*480) it's going to cost about 460.8 ms to blit a full frame from your buffer to display memory. That's almost half a second!

However, you could do 4 OUT instructions per frame (to select each plane), and write an average of 8 pixels per write (using 32-bit writes without write combining). In this case it'd take about 19.204 ms to blit a full frame from your buffer to display memory. That's almost 24 times faster!

Better yet, with write combining and/or MMX and/or SSE and/or long mode you could do 64-bit writes or 128-bit writes (instead of those 32-bit writes); which could make it about 50 or 100 times faster.

Note: Actual costs for OUTs and video display memory accesses will vary - values mentioned are examples only.

Basically what I'm saying is it doesn't matter if it works or not, because the algorithm needs to be changed anyway. The code you're using would be good if you only want to set one pixel in display memory because then you'd be doing one OUT instruction instead of four; but nobody in the history of the universe has ever wanted to only set one pixel in display memory - studies have shown that most GUIs and computer games usually change at least 6 pixels per frame.... :roll:


Cheers,

Brendan