
Timer, accuracy in millisecs!
-----BEGIN PGP SIGNED MESSAGE-----
I saw a post, asking for wait-loops for a specific
time. But one used only the TIMER-function.
I've made a SUB that will wait for a specified
interval of a number of millisecs, using interrupt 15h
(with AH=83h).
It will follow, shortly after my .sig...
Kind regards,
Steven de Brouwer
May the source be with you!
PGP PubKey (0x618011B1) available on KeyServers!
8C C6 0C 0B F8 7B 35 E8 BC 9D 80 6B E1 69 A6 A5
- - -
DECLARE SUB delay (ms%)
'$INCLUDE: 'qb.bi'
DIM SHARED regs AS RegTypeX
DEFINT A-Z
'
' Bug-reports to:
' Steven de Brouwer
' May the source be with you!
'
' PGP PubKey (0x618011B1) available on KeyServers!
' 8C C6 0C 0B F8 7B 35 E8 BC 9D 80 6B E1 69 A6 A5
'
CLS
INPUT "How many milliseconds to wait "; ms
PRINT "Oke, please wait..."
PRINT "Start-timer:"; TIMER; "sec."
CALL delay(ms)
PRINT "End-timer: "; TIMER; "sec."
END
SUB delay (msec)
'
' This SUB sets a wait interval, length 'msec' milli-seconds.
' Although irq 15h/83h waits a number of microseconds,
' the resolution is in millisecs.
' This won't run using QBasic in a Windows-DOS-box.
'
DIM ready AS INTEGER
'
regs.ax = &H8301 'Cancel Previous Wait Interval
CALL INTERRUPTX(&H15, regs, regs)
'
ready = 0
'
msH = INT(1! * msec / 65.536) 'Convert msec to usec
msLh& = INT((500& * msec) MOD 32767) * 2
IF msLh& >= 32768 THEN msL = msLh& - 65536 ELSE msL = msLh&
' * There is too much truncating here. *
' * Does anybody have a better way? *
'
regs.cx = msH: regs.dx = msL
regs.ax = &H8300 'Set Wait Interval
regs.es = VARSEG(ready): regs.bx = VARPTR(ready)
'
CALL INTERRUPTX(&H15, regs, regs)
'
IF regs.flags AND &H1 THEN
BEEP
IF regs.ax = &H8000 THEN PRINT "Invalid Command."
IF regs.ax = &H8600 THEN PRINT "Function not supported."
EXIT SUB
END IF
DO
'k$ = INKEY$ :rem Remove the ' to enable
LOOP UNTIL ready 'OR (k$ <> "") :rem the user to break the waiting
'
END SUB
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: cp850
iQCVAwUBMhcbCCIfFbRhgBGxAQE6eAQAgvSp7ZyDHlsJhirLcBBEQ+2RnQ1hL8uw
4W9Zq8FxTiDOc6k3NdfFtFTFtysnCePYbPymRrRkXWRlv6y6Ye12Sbo4xLRS2TO+
d/MpuC3ER8ywRoRU/KN22NY47zY3eaeArRgJTw61QpqMyyom+q5S/c1DD8XC6atc
aQlE9ut9u1Y=
=qwpz
-----END PGP SIGNATURE-----