'===========================================================================
' Subject: DELAY TIMERS                       Date: 11-06-95 (15:00)       
'  Author: Kurt Kuzba                         Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: DATETIME.ABC
'===========================================================================
'Someone wrote:

'>   Does anybody have a routine to pause a program for a
'>   certain amount of time before continuing?  Thankyou.
'>......................................................

'Kurt Kuzba Replied:

'   Generally, SLEEP is sufficient, but sometimes you need a
'finer resolution or the ability to ignore keypresses.
'   You may use the DOS internal clock, which allows a minimum
'delay of 0.054931641 seconds. The DOS clock increments at a
'rate of 18.20444444 times per second.
'   You may also use the vertical retrace, though I have been told
'that it is not recommended. This allows a more precise control.
'This allows increments of 0.0014285714 seconds. The Video Retrace
'usually occurs at a rate of 70 times per second, but may change
'due to use of different hardware on various systems.
'   You may also use the Programmable Interrupt Timer at hardware
'port (&H40), or 64 decimal, allowing an adjustable delay, which
'depends on the speed of your processor. The PIT calibration
'FUNCTION attempts to read the PIT based on the DOS clock and set
'the delay interval accordingly. It has not been tested and may
'lose accuracy at greater speeds with better processors, so it
'should only be used in personal use software on known systems,
'or require configuration to individual setups. I haven't the range
'of hardware to test for other processors and conditions.

'_|_|_|   QBDELAY.BAS
'_|_|_|   This program utilizes three different delay timers.
'_|_|_|   Each uses the same method but employs a different
'_|_|_|   measure. DOSDelay uses the internal DOS clock.
'_|_|_|   VRTDelay uses the VIDEO hardware interrupt retrace.
'_|_|_|   PITDelay uses the hardware interrupt Programmable
'_|_|_|   Interrupt Timer. Each will generate a 10 second delay.
'_|_|_|   Released to the   Public Domain   by Kurt Kuzba
DECLARE FUNCTION PITcal& ()
DECLARE SUB PITDelay (seconds!)
DECLARE SUB DOSDelay (seconds!)
DECLARE SUB VRTDelay (seconds!)
COLOR 2, 0: CLS : DIM SHARED PIT(1) AS LONG
PRINT "DOSDelay : "; TIME$: DOSDelay 10
PRINT "           "; TIME$: COLOR 9
PRINT "VRTDelay : "; TIME$: VRTDelay 10
PRINT "           "; TIME$: COLOR 15
PIT(0) = PITcal: COLOR 12
PRINT "PIT calibrated at"; PIT(0); "increments per second."
COLOR 14
PRINT "PITDelay : "; TIME$: PITDelay 10
PRINT "           "; TIME$
SUB DOSDelay (seconds!)
   DEF SEG = 0
   d& = FIX(seconds! * 18.20444444#)
   FOR t& = t& TO d&
     d% = PEEK(&H46C) AND 255
     WHILE d% = (PEEK(&H46C) AND 255): WEND
   NEXT
END SUB
FUNCTION PITcal&
   p& = 0: DEF SEG = 0: x% = (PEEK(&H46C) + 1) AND 255
   WHILE x% <> (PEEK(&H46C) AND 255): WEND
   WHILE x% = (PEEK(&H46C) AND 255)
      p& = p& + 33
      FOR t% = 1 TO 19: WAIT (64), 128, 128: WAIT (64), 128: NEXT
   WEND
   PITcal& = p& * 11.02
END FUNCTION
SUB PITDelay (seconds!)
   d& = FIX(seconds! * PIT(0))
   FOR t& = 0 TO d&: WAIT 64, 128: WAIT 64, 128, 128: NEXT
END SUB
SUB VRTDelay (seconds!)
   d& = FIX(seconds! * 70)
   FOR t& = 0 TO d&: WAIT (&H3DA), 8: WAIT (&H3DA), 8, 8: NEXT
END SUB
'_|_|_|   end QBDELAY.BAS
