Archived

This topic is now archived and is closed to further replies.

Den

vertical retrace - one more question

Recommended Posts

I've looked through the forum on this subj, but haven't got an answer. I have sprites of balls(16x16), moving across the screen and a simple background - just blue screen. In order to have smooth animation I decided to use page switching. The program is being designed for DOS and I set mode 320x240. The problem is that the following code doesn't work properly : ..... int active=1; while(!kbhit()){ setactivepage(active); clearpage(color); PutSprite(x,x); ...//other sprites while((inportb(0x3DA)&0x08));//wait for retrace while(!(inportb(0x3DA)&0x08)); setvisualpage(active); active=1-active;//switch between 0 and 1 x++; } ....... If you try this, you will see that the balls flash in spite of switching the page precisely during the v_retrace interval. I tried to modify the program as follows: .... PutSprite(x,x); ...//other sprites getch(); while((inportb(0x3DA)&0x08));//wait for retrace while(!(inportb(0x3DA)&0x08)); .... And when you press a key you can see the blinking - background is visible for the very short time and then sprite(or sprites) is put over it. So, it seems like the sprite is cashed somewhere! I should notice that I use my own procedures for switching, clearing and setting active pages, because the mode(320x240) isn't standard(I program VGA registers directly), but it's all OK with them. After a lot of experiments I've got the code that works, but I don't know why: ..... int active=1; while(!kbhit()){ setactivepage(active); clearpage(color); while((inportb(0x3DA)&0x08));//wait for retrace while(!(inportb(0x3DA)&0x08)); PutSprite(x,x); ...//other sprites setvisualpage(active); active=1-active;//switch between 0 and 1 x++; } ....... So, now sprites are put in coordination with v_retrace, but the page becomes visible at any time while the electronic ray scans the screen! I varied the number of sprites and the result was the same - everything moved smoothly without any jerking. I even placed "clearpage(color);" after waiting for retrace. So, the period from a beginning of frame before switching of page doesn't matter, at the same time the moment of drawing sprites in active(but invisible)page takes effect! May be someone knows the reason of this phenomenon? Your help will be highly appreciated! Thanks in advance. Edited by - Den on October 22, 2001 2:19:58 AM

Share this post


Link to post
Share on other sites