home *** CD-ROM | disk | FTP | other *** search
- /* os_mac_eventchk.c */
-
- /* 18Jan95 e - a timer option for scheduling event checks */
-
- #include "os_mac.h"
-
- #if USE_EVENTCHK_TIMER
-
- #include "os_mac_eventchk.h"
- #include <Timer.h>
- #include <stdlib.h>
-
- extern int _atexit( void(*efun)(void) );
-
- #ifndef mSecsBetweenEventChecks
- #define mSecsBetweenEventChecks 100
- #endif
-
- #if GENERATINGPOWERPC
- #pragma options align=mac68k
- #endif
-
- typedef struct tinfoRec
- {
- TMTask TMTask;
- short filler;
- long *eventchk_ticks;
- } tinfoRec, *tinfoPtr;
-
- #if GENERATINGPOWERPC
- #pragma options align=reset
- #endif
-
- static tinfoRec gTimeInfo;
-
- static TimerUPP tmt_handlerUPP = NULL;
-
- #if powerc
- static pascal void tmt_handler(TMTaskPtr a1)
- {
- *((tinfoPtr )a1)->eventchk_ticks = 1;
- PrimeTime((QElemPtr )a1, mSecsBetweenEventChecks);
- }
- #else
- #ifndef __MWERKS__
- static pascal void tmt_handler(void)
- {
- asm
- {
- MOVEA.L tinfoRec.eventchk_ticks(A1), A0
- ADDQ.L #1, (A0)
- MOVE.L A1, A0
- MOVE.L #mSecsBetweenEventChecks, D0
- DC.W 0xA05A ; PrimeTime
- }
- }
- #else
- asm static pascal void tmt_handler(void)
- {
- MOVEA.L 0x18(A1), A0 // tinfoRec.eventchk_ticks(a1)
- ADDQ.L #1, (A0)
- MOVEA.L A1, A0
- MOVE.L #mSecsBetweenEventChecks, D0
- DC.W 0xA05A // PrimeTime
- RTS
- }
- #endif
- #endif
-
- void cancel_eck_timer(void)
- {
- if (gTimeInfo.TMTask.tmAddr != NULL && gTimeInfo.TMTask.qType < 0 )
- { RmvTime((QElemPtr )&gTimeInfo.TMTask);
- gTimeInfo.TMTask.tmAddr = NULL;
- }
- }
-
- void init_eck_timer(void)
- { if (tmt_handlerUPP == NULL) tmt_handlerUPP = NewTimerProc(tmt_handler);
- if (gTimeInfo.TMTask.tmAddr == NULL)
- { gTimeInfo.TMTask.tmAddr = tmt_handlerUPP;
- gTimeInfo.TMTask.tmWakeUp = 0;
- gTimeInfo.TMTask.tmReserved = 0;
- gTimeInfo.eventchk_ticks = &next_eventchk_ticks;
- next_eventchk_ticks = 0;
- InsTime((QElemPtr )&gTimeInfo.TMTask);
- _atexit(cancel_eck_timer);
- PrimeTime((QElemPtr )&gTimeInfo.TMTask, mSecsBetweenEventChecks);
- }
- }
-
- #endif
-