Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!purdue!mailrus!husc6!brauer!fry From: fry@brauer.harvard.edu (David Fry) Newsgroups: comp.sys.mac.programmer Subject: Re: How to use Time Manager Keywords: HELP WITH TIME MANAGER Message-ID: <795@husc6.harvard.edu> Date: 9 Dec 88 12:14:06 GMT References: <829@drexel.UUCP> Sender: news@husc6.harvard.edu Reply-To: fry@brauer.UUCP (David Fry) Organization: Harvard Math Department Lines: 71 Here's some code to measure a time interval accurate to 1 ms from inside an XCMD. It needs to use global variables, and since it will be called from within an XCMD, you'll need to perform some trick to use those globals. This example use Lightspeed C 3.0, which makes using globals referenced from A4 easy. As I said, this example will be accurate to 1 ms. But if you're going to be measuring ADB keyboard and mouse events, they can only be accurate to 5 ms at most, so you can save some processor load by replacing the PrimeTime(&mytask,1L) calls with PrimeTime(&mytask,5L) calls. Then the interrupt will get called 1/5th as often. Oh, and increment the variable by 5 each time. I hope this helps... ----------------------------cut here--------------------------- #include "EventMgr.h" #include "TimeMgr.h" #include "setupa4.h" /* to be used as part of an XCMD in LSC 3.0 */ long increment; TMTask mytask; pascal void MyInc() { SetUpA4(); /* SetUpA4() is necessary because MyInc will be called as an interrupt and register A4 could point anywhere */ increment += 1; PrimeTime(&mytask,1L); RestoreA4(); } time_something() { increment = 0; mytask.tmAddr = MyInc; InsTime(&mytask); PrimeTime(&mytask,1L); RememberA4(); do { /* do anything you want between the InsTime and RmvTime calls of course, you needn't stay in this function */ } while ( !Button() ); RmvTime(&mytask); /* increment now contains the # of milliseconds elapsed time */ } David Fry fry@huma1.harvard.EDU Department of Mathematics fry@huma1.bitnet Harvard University ...!harvard!huma1!fry Cambridge, MA 02138