[comp.sys.mac.programmer] HELP accessing time

ephraim@think.COM (ephraim vishniac) (03/04/88)

In article <243@eos.UUCP> lyman@eos.UUCP (Lyman Taylor) writes:

>I would like to know if it possible to get the Mac to return the time
>to subsecond accuracy.  I am trying to develop a program to record
>reaction times and need times accurate to about a hundreth of a
>second.  I know about the Mac's internal clock and how it can give me
>hrs:min:secs, but is there more?  If not, how do I go about keeping
>track of time myself (is this possible ? ) and how accurate is this?

For elapsed time with a resolution of 1/60th second, look at the Tick
Counter.  It's plainly visible in low memory, and (I think) there's
also a trap which returns the current value.  This counter shows the
number of ticks (60ths of a second) elapsed since you booted your Mac.

Another nice application of the tick counter (game programmers: are
you listening?) is to "pace" the action of games.  Some games on the
Mac adjust their speed by using counted loops to slow things down.
When you run these games on a Mac II or any accelerated Mac, they lose
big. (Actually, the user loses.  Quickly.)  A better way to pace a
game is to decide how long an event should take.  Before starting
processing of the event, store the tick count.  Process the event.
Check the current tick count against the stored one to see if enough
time has passed.  If not, idle watching the tick count until it
reaches the required value.  Now, your game will appear to run at the
same speed on any Mac.

For an example of this technique, download <info-mac>dali-clock.hqx
from sumex-aim.stanford.edu.  Full source code is included.  While
you're at it, fix the clock so that it's compatible with color.

Obviously, you don't want to do this for games like Flight Simulator,
where faster updates on a faster machine are a plus.  But it should be
done in games like Adventures of Snake or Brickles, which are
unplayable on a fast Mac.

Ephraim Vishniac					  ephraim@think.com
Thinking Machines Corporation / 245 First Street / Cambridge, MA 02142-1214

     On two occasions I have been asked, "Pray, Mr. Babbage, if you put
     into the machine wrong figures, will the right answers come out?"