640x480x16 double buffer

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.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

640x480x16 double buffer

Post 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<
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
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:

Re: 640x480x16 double buffer

Post 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.
"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 ]
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: 640x480x16 double buffer

Post 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
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: 640x480x16 double buffer

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: 640x480x16 double buffer

Post 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 :(
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
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:

Re: 640x480x16 double buffer

Post by Combuster »

"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 ]
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: 640x480x16 double buffer

Post 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>
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
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:

Re: 640x480x16 double buffer

Post by Combuster »

"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 ]
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: 640x480x16 double buffer

Post by i586coder »

great ! where is it man
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
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:

Re: 640x480x16 double buffer

Post 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:
"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 ]
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: 640x480x16 double buffer

Post 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/
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: 640x480x16 double buffer

Post 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.
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Re: 640x480x16 double buffer

Post by codemastersnake »

check out some games development websites..... u'll find a lot of information over there...
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: 640x480x16 double buffer

Post 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. :?
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: 640x480x16 double buffer

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply