#include "TimeManager.h" // James Davis - jedavis@cs.stanford.edu - Copyright 1996 // Define this structure so we can get at the A5 world for our app // Its a trick from NIM Processes 3-11 typedef struct { TMTask theTMTask; // its crucial that the task record is the first item long theA5World; TimerUPP theRealTask; } TMInfo, *TMInfoPtr; TMTaskPtr TM_RecentTask=NULL; // The most recently started task // Need this asm glue to get the task record and other stuffs tagging along // behind. asm TMInfoPtr TM_GetTaskRec(void); asm TMInfoPtr TM_GetTaskRec(void) { move.l A1,A0 // The taskrec is pointed to by A1 when the routine is first called // Pointers are returned in A0 so move it there... rts } // Our Stub routine to set up A5 and then call the real routine. pascal void TM_DummyRoutine(void); pascal void TM_DummyRoutine(void) { TMInfoPtr taskptr; long oldA5; // On entrance to a task manager callback the task record is pointed to by register A1 // We have to call this asm routine to get at it taskptr = TM_GetTaskRec(); oldA5 = SetA5(taskptr->theA5World); // Restore the application A5 if (TM_RecentTask!=NULL) DebugStr("\pWhy wasnt this null"); TM_RecentTask = (TMTaskPtr)taskptr; // Set this taskrec where we can get it // If one time manager routine can interupt another // we arent doing the right thing if (taskptr->theRealTask != NULL) taskptr->theRealTask(); // Call the task the user really wanted TM_RecentTask=NULL; oldA5 = SetA5(oldA5); // reset the calling A5 } // TMTaskPtr TM_InstallTask(TimerUPP taskProc) { TMInfoPtr tminfo=NULL; // Allocate space for the structure tminfo=(TMInfoPtr)NewPtr(sizeof(TMInfo)); if (tminfo==NULL) return NULL; // Init some fields tminfo->theTMTask.tmAddr=TM_DummyRoutine; // a front end routine tminfo->theTMTask.tmWakeUp =0; // You always set this to 0 tminfo->theTMTask.tmReserved = 0; // You always set this to 0 tminfo->theA5World = SetCurrentA5(); // Save the applications A5 tminfo->theRealTask = taskProc; // The routine we want to run InsTime((QElemPtr)tminfo); // Install the task return (TMTaskPtr)tminfo; } // long TM_RemoveTask(TMTaskPtr tmtask) { long remaining_count; RmvTime((QElemPtr)tmtask); // remove the task from the time manager remaining_count=tmtask->tmCount; // The remaining time till task execution DisposePtr((Ptr)tmtask); // Dispose the TMInfoPtr we allocated return remaining_count; } // void TM_ScheduleTask(TMTaskPtr task, long count) { PrimeTime((QElemPtr)task,count); }