[futurebasic] Re: [FB] Toolbox timing procedure

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

From: Robert Purves <robert.purves@...>
Date: Mon, 20 Sep 1999 17:41:58 +1200
>>I would like to be able to measure time more precisely than in ticks.
>>The FB^3 help entry for TIMER refers to a MICROSECONDS procedure but
>>does not include an example. Could someone provide an example of the
>>proper syntax for MICROSECONDS?

>'=========================================
>'timing in microseconds
>LONG FN MicroSeconds&
>` dc.w $A193  ;  trap word
>END FN' returns low longword of 8-byte result
>'=========================================

Don't use the tiny FN above (for which I claim, or perhaps admit,
responsibility). It was devised for minimum overhead, and worked OK in FB2,
but for FB^3 you need something better.

The program below shows the proper syntax, allowing 68K, PPC or FAT.

Note that the components of the microSecRecord are defined as the new FB^3
type UNSIGNED LONG. The definition unfortunately reveals a bug in release 0
of FB^3: it cannot print variables of that type.

You can print them with the help of the STR$ function, but _another_ bug is
revealed: the UNSIGNED nature is lost. Since microSecLo counts MOD
4294967296, it has a period of 4294.967296s (about 71 minutes).
STR$(myMS.microSecLo) therefore displays as a positive number for 35
minutes then negative for 35 minutes. The UNS$ function correctly displays
myMS.microSecLo as always positive, but it shouldn't be necessary to use
UNS$ on an already UNSIGNED variable.


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

TOOLBOX Microseconds (LONG) `0xA193,0x225F,0x22C8,0x2280
/* what those 0x values mean in 68K
  dc.w $A193      ;0xA193
  move.l (sp)+,a1 ;0x225F
  move.l a0,(a1)+ ;0x22C8
  move.l d0,(a1)  ;0x2280
*/

LOCAL FN ShowTime
DIM myMS as microSecRecord
DEFSTR LONG
FN Microseconds(@myMS)
' Next line doesn't compile - comment it out
'PRINT myMS.microSecHi, myMS.microSecLo ' BUG
' STR$ should show unsigned values, but doesn't - another BUG
PRINT STR$(myMS.microSecHi), STR$(myMS.microSecLo)
' At last...a way to show the unsigned longs
PRINT UNS$(myMS.microSecHi), UNS$(myMS.microSecLo)
END FN

WINDOW 1
ON TIMER(1) FN ShowTime
DO
HANDLEEVENTS
UNTIL FN BUTTON
'----------------------------------------------------------

Robert Purves