Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!lll-tis!helios.ee.lbl.gov!ux1.lbl.gov!beard From: beard@ux1.lbl.gov (Patrick C Beard) Newsgroups: comp.sys.mac.programmer Subject: Re: How to use Time Manager Keywords: HELP WITH TIME MANAGER Message-ID: <1419@helios.ee.lbl.gov> Date: 9 Dec 88 19:10:45 GMT References: <829@drexel.UUCP> Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux1.lbl.gov (Patrick C Beard) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 78 In article <829@drexel.UUCP> menser@drexel.UUCP (Charles Menser) writes: > >Could someone please explain how you can use Time Manager "in place of >cycle-counting timming loops."(IM4) > >The text is very vague, at least to me, about actualy useing the manager >to pause a program's execution for a certain time. In my code, at present when Ineed a short delay, I use a for...do loop (MPW Pascal 2.0.2). How could I use >Time Manager instead? > >Thanks. > The answer: DON'T! If you just need a simple delay, then call: Delay(numTicks, finalTicks); which is documented in Inside Macintosh II-384. The Time Manager is for more sophisticated things, where you need to be able to specify that a routine get called after some number of milliseconds, at interrupt time. But, since you asked, here is how one could do a delay routine with the time manager: /* TMDelay.c - using the time manager to do a delay. by Patrick Beard beard@ux1.lbl.gov */ #include#include pascal void TMDelayInterrupt(); /* routine that gets called at interrupt time */ static Boolean DelayComplete=false; static TMTask DelayTask; TMDelay(msToDelay) long msToDelay; { DelayComplete=false; InstallInterrupt(TMDelayInterrupt, &DelayTask, msToDelay); while(!DelayComplete); /* could do something here like check for mouse */ RemoveInterrupt(&DelayTask); } pascal void TMDelayInterrupt() { SetUpA5(); /* so we can change a global */ /* note this doesn't work under multifinder! */ DelayComplete=true; RestoreA5(); } InstallInterrupt(IntRoutine, IntTask, msToDelay) ProcPtr IntRoutine; TMTask *IntTask; long msToDelay; { (*IntTask).qType=vType; (*IntTask).tmAddr=IntRoutine; InsTime(IntTask); PrimeTime(IntTask, msToDelay); } RemoveInterrupt(IntTask) TMTask *IntTask; { RmvTime(IntTask); } /* ---------- */ Patrick Beard Lawrence Berkeley Laboratory beard@ux1.lbl.gov