In the Name of Allah ...

I am here again. I won't be long this time. The problem I want to present you here is the following one:

A friend of mine called me yesterday asking me to write a program which would draw an object on the screen (for example a rectangle) and redraw this object every time the screen is being redrawn by the CRT ray!
The first thing that felt on my mind was using a high-precision timer to synchronize the redrawing of this object with the redrawing of the screen. I know this is not the best solution, but I really didn't have the time to think about a better one.
This is the most interesting problem I've ever got as an assembly programmer.

So, if you have any idea how to solve this problem, please let me know!

Best regards!

Beg
Posted on 2001-10-14 09:57:21 by Beg
Under DOS, you could wait for the vertical retrace, or even the
horizontal retrace. This isn't possible under windows, though, because
it disallows direct port access (it might be possible under win9x,
but breaking winnt/win2k compatibility is *bad*).

The best solution, imho, is to use DirectDraw, and paint to a backbuffer... quoting MSDN: "The IDirectDrawSurface3::Flip
method will always be synchronized with the vertical blank".

For GDI and other non-fullscreen graphics, I don't think this will
matter much.

Under DOS, I believe most cards supported a retrace hardware
interrupt, which might be neat, but... forget about that under windows :).

Oh yes, could you pleeease stop doing that "in the name of Allah"?
We're supposed to keep this board free of all that pesky religion crap.
Posted on 2001-10-14 11:02:44 by f0dder
In DOS, you can do vertical retrace sync like so:


mov dx, 3DAh
@@vs: in al, dx
test al, 8
jz short @@vs
@@vsa: in al, dx
test al, 8
jnz short @@vsa

I am not sure why there are 2 loops though, but I've commented out the second one when I size-optimized and it worked. Most other sources use both loops though, so do that as well.
In Windows, vertical retrace synchronization can be done using DirectDraw WaitForVerticalBlank() which is a procedure of a DirectDraw object (created using either DirectDrawCreate() or DirectDrawCreateEx()).
Posted on 2001-10-15 19:37:48 by comrade
Hi comrade

The reason for the two loops are if you enter the loop at the end of the retrace you must wait for the next retrace.



_____ _________
!_____!
^
You enter loop here. Very little time to do your stuff.



KetilO
Posted on 2001-10-15 20:01:14 by KetilO
Thanks KetilO! I'll keep that in mind.
Posted on 2001-10-15 21:55:58 by comrade