TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: PAT PRIDGEN
from: MIKE ROSS
date: 2003-06-20 22:09:46
subject: delay routine vsync

"PAT PRIDGEN" wrote to "ALL" (20 Jun 03  16:23:00)
 --- on the topic of "delay routine"

 PP> Here's some delay code I picked up some time back.
 PP> I've got lots of code snippets on disk, the trouble is wading through
 PP> them to find them.

Excellent examples they are too. I tried to get better resolution than
the 18.2 bps in TIMER and came upon something that was a little out of
left field. It looks at the vga card status port which has a couple of
bits devoted to the sychronization signals. I have a couple of samples
from those experiments. The first example attempts to measure the
interval and the second example actually tries to show the waveform!
Requires: VGA and a 386 class machine. Press the F10 key to exit.

 Mike
 ****

-------- Sample 1 ---------

DEFINT A-Z
DECLARE FUNCTION Vsyncbench ()
ON KEY(10) GOSUB leave:
KEY(10) ON

 a = Vsyncbench
 tl! = 1 / 60 / a
 PRINT
 PRINT "Count per 1/60th sec:"; a, , "Loop time:"; tl!
* 1000000!; "uS"
 PRINT "Timer value per 1 sec. loop count:"

DO

FOR i = 1 TO 60
  c = -a
 DO: c = c + 1: d = INP(&H3DA) AND 1: LOOP WHILE c
NEXT i
PRINT TIMER;

LOOP

quit:
PRINT
KEY(10) OFF
END

leave:
RETURN quit:

FUNCTION Vsyncbench

 ' returns loop count of the complete Vertical video retrace 1/60 sec.

 c = 0

 WAIT &H3DA, 8, 8                               'detect Vsync falling edge

 WAIT &H3DA, 8                                  'detect Vsync rising edge

 DO: c = c + 1: LOOP WHILE INP(&H3DA) AND 8     'detect Vsync falling edge

 DO: c = c + 1: LOOP UNTIL INP(&H3DA) AND 8     'detect Vsync rising edge

 Vsyncbench = c

END FUNCTION


--------- Sample 2 ---------

DEFINT A-Z

ON KEY(10) GOSUB leave:
KEY(10) ON

SCREEN 0
CLS

DO

 WAIT &H3DA, 8, 8
 WAIT &H3DA, 8

 DO: PRINT "~"; : LOOP WHILE INP(&H3DA) AND 8
 DO UNTIL INP(&H3DA) AND 8: PRINT "_"; : LOOP
 IF CSRLIN > 10 THEN LOCATE 1, 1

LOOP

quit:
PRINT
KEY(10) OFF
END

leave:

RETURN quit:

--------------------- end -----------------

... A mind is a terrible thing to ...OOOH a new video game!
--- Blue Wave/DOS v2.30
* Origin: Juxtaposition BBS, Telnet:juxtaposition.dynip.com (1:167/133)
SEEN-BY: 633/267 270
@PATH: 167/133 379/1 106/1 2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.