this procedure is waiting for a retrace.its used for screen- synchronization.if u let ur programs run without it they will run too fast and look ugly.

the screen is showing u the pictureby shooting with his cathod- rayat the phosphor. it is doing thisfrom the left side to the right side,row by row. [code]-------------------------------------------------|-----------------------------> ||---------------------------> ||-------------------------------> ||... ... ... || || || || || ||... ... ... ... || || || || || ||----------------------------------> end here- >|-------------------------------------------------[/code]when the cathod- ray is finished doing this, it will return back from the right bottom cornerto the left upper corner:[code]-------------------------------------------------| _<- return back to first row || | || || || || || || || || || || || || || || || || || || || || || |-------------------------------------------------[/code]this is called the vertical- retrace.after this vertical- retrace the screen will start his work again and again ... ... .during the vertical- retrace no data is readfrom the videomemory. thus if u writeur data during the vertical- retrace to thevideomemeory there will be no conflicts betweenthe CPU and the VGA- card.all in all the vertical retrace is the best timefor writing data to Vram.if a vertical retrace is occuring the bit #3of the register 3DAh is set.the register should then look like this in binary00001000in decemal this equals to the number 8.the programmer here is first testing for the bit.if it is set then the sceen is finished. if notthen the screen is displaying data from the Vram.in the first loop he is waiting for the endof the vertical- retrace.in the last loop he is waiting for the start of the vertical- retrace. so after the CPU has left the procedure themonitor will be in a vertical- retrace andthe programmer can write to Vram withoutconflicts with the VGA- hardware.

in pascal it should be:[code]repeat until port[$3DA] and 8<>8;repeat until port[$3DA] and 8=8;[/code]i haven't tried it.

: this procedure is waiting for a retrace.: its used for screen- synchronization.: if u let ur programs run without it : they will run too fast and look ugly.: : the screen is showing u the picture: by shooting with his cathod- ray: at the phosphor. it is doing this: from the left side to the right side,: row by row. : [code]: -------------------------------------------------: |-----------------------------> |: |---------------------------> |: |-------------------------------> |: |... ... ... |: | |: | |: | |: | |: | |: |... ... ... ... |: | |: | |: | |: | |: | |: |----------------------------------> end here- >|: -------------------------------------------------: [/code]: when the cathod- ray is finished doing this, it : will return back from the right bottom corner: to the left upper corner:: [code]: -------------------------------------------------: | _<- return back to first row |: | | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: | |: -------------------------------------------------: [/code]: this is called the vertical- retrace.: after this vertical- retrace the screen : will start his work again and again ... ... .: during the vertical- retrace no data is read: from the videomemory. thus if u write: ur data during the vertical- retrace to the: videomemeory there will be no conflicts between: the CPU and the VGA- card.: all in all the vertical retrace is the best time: for writing data to Vram.: if a vertical retrace is occuring the bit #3: of the register 3DAh is set.: the register should then look like this in binary: 00001000: in decemal this equals to the number 8.: the programmer here is first testing for the bit.: if it is set then the sceen is finished. if not: then the screen is displaying data from the : Vram.: in the first loop he is waiting for the end: of the vertical- retrace.: in the last loop he is waiting for the : start of the vertical- retrace. so : after the CPU has left the procedure the: monitor will be in a vertical- retrace and: the programmer can write to Vram without: conflicts with the VGA- hardware.: : in pascal it should be:: [code]: repeat until port[$3DA] and 8<>8;: repeat until port[$3DA] and 8=8;: [/code]: i haven't tried it.:

Difference is in time delay. DELAY has FIXED (more or less) delay. If you call something like:

[code] DELAY(13);[/code]

your PC will wait about 13 miliseconds EVERY time.

The V_Sync procedure (the code you have posted) willwait and wait and wait until vertical sycronizationpulse is generated. This pulse is generated every10-15mSecond depending on the frame rate. For example if your graphic card is generating 75fps,one frame lasts about 13.33mSecond (1second/75). After some work, wiat for V_Sync:- If pulse is generated 0.1mSec later, delay is only 0.1mSec.- If pulse is generated 10mSec later, delay is 10mSec.

So the delay ADJUSTS itself to the speed of the computer.On a fast computer it will wait longer, on slow it will waitshorter. Only on really slow computers (or if your program is notoptimized or designed well) this will exceed frame time.If so V_Sync will still wait for sync pulse. However, sinceit missed one, it will wait till following one makinggame run really slow (half of the frame rates since every othersync pulse is skipped). Most nowdays games offer option toturn off vsync for that purpose (better to run little bittoo fast than a lot slower).

for me the main difference is that if uuse the vertical- retrace then ur graphicsanimations will look better. thats just myexperience. as i have already said if u usea delay(X) or just no delay then the CPUwill have conflicts with the VGA and theanimations will look ugly. for example i made a program that just moved a pixelacross the screen. with vertical- retrace itlooked smooth, with delay(x) it lookedlike the pixel is being moved and the pixel behind it was deleted after it movedaway, so it looked like there were two pixelson screen instead of one.