The TIMER function returns a value which changes precisely 1193181 times every 65536 seconds -- that is to say, roughly 18.2 times per second. You can use this to do sub-second delays:
[tt]
SUB delay(numTicks%)
FOR i% = 1 TO numTicks%
st# = TIMER
WHILE TIMER = st#: WEND 'TIMER will change 1/18.2 of a second after the previous line
NEXT i%
END SUB
[/tt]
If you want better precision than this, you can modify the timer frequency with a couple of hardware I/O calls:
[tt]
SUB setTimerFrequency(ticksPerSec&)
IF (ticksPerSec& < 1) OR (ticksPerSec& > 1193181) THEN ERROR 5 'Illegal function call
clocksPerTick& = 1193181 \ ticksPerSec&
OUT &H43, &H34
OUT &H40, clocksPerTick& AND 255
OUT &H40, clocksPerTick& \ 256
END SUB
SUB resetTimerFrequency()
OUT &H43, &H34
OUT &H40, 0
OUT &H40, 0
END SUB
[/tt]
Be sure to call resetTimerFrequency before your program exits. This code will cause the system timer to run fast in some situations (dependant on operating system). However, the clock will be reset in these cases to an accurate value on the next reboot.