[futurebasic] Re: [FB] [FB^3] Toolbox timing procedure

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 1999 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Thu, 23 Sep 1999 12:29:21 +1200
>Do you have a function that will delay a program in milliseconds?
>
> note that the above function should also accommodate different
>speed computers. In other words, it should have a standardized initial
>testing function to set the delay.

See below. For a delay in milliseconds, just call FN
DelayMicroSeconds(millisecs*1000). This works in 68K or PPC, and on a
machine of any speed. There's no need for an initial testing function,
since the Time Manager uses an internal fixed-rate clock.

Robert Purves


'--------------------------------------------------------
BEGIN RECORD microSecRecord
DIM microSecHi AS UNSIGNED LONG
DIM microSecLo AS UNSIGNED LONG
END RECORD

TOOLBOX Microseconds (LONG) `0xA193,0x225F,0x22C8,0x2280

LOCAL FN DelayMicroSeconds(delayMicrS&)
' waste time (up to _maxlong=2147483647 microseconds)
dim myMS1 as microSecRecord, myMS2 as microSecRecord
if delayMicrS&<=0 then exit fn
'calculate what time to wait until
FN Microseconds(@myMS1)
long if (myMS1.microSecLo + delayMicrS& < myMS1.microSecLo)
inc(myMS1.microSecHi) ' addition caused carry
end if
myMS1.microSecLo=myMS1.microSecLo + delayMicrS&

do 'waste time in this loop
FN Microseconds(@myMS2)
until (myMS2.microSecLo>=myMS1.microSecLo) ¬
       and (myMS2.microSecHi>=myMS1.microSecHi)
END FN

' demo main program
dim microSecsAsked&,ticksWas&, ticksNow&
window 1
microSecsAsked&=1000000
ticksWas&=FN TICKCOUNT
fn DelayMicroSeconds(microSecsAsked&)
ticksNow&=FN TICKCOUNT
print "Requested delay = " microSecsAsked&/16666 " ticks"
print "Measured delay = " ticksNow&-ticksWas&" ticks"
DO
HANDLEEVENTS
UNTIL FN BUTTON
'--------------------------------------------------------