| 1 | #include <manip.h> | 
|---|
| 2 | #include "montimer.h" | 
|---|
| 3 |  | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef powerc | 
|---|
| 6 | //$$#include <A4Stuff.h> | 
|---|
| 7 | #endif | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | //Globals | 
|---|
| 13 |  | 
|---|
| 14 |  | 
|---|
| 15 | #ifndef powerc | 
|---|
| 16 | void montimer(void); | 
|---|
| 17 | #else | 
|---|
| 18 | void montimer(TMInfoPtr recPtr); | 
|---|
| 19 | #endif | 
|---|
| 20 |  | 
|---|
| 21 | TMInfo                          myTMInfo; | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 24 | TMInfoPtr setuptimer(long delai,void (*execute)(void*),void * mastructure) | 
|---|
| 25 | { | 
|---|
| 26 | TMInfoPtr       myTMInfopt=malloc(sizeof(TMInfo)); | 
|---|
| 27 |  | 
|---|
| 28 | //This statement will work with 68K or PPC | 
|---|
| 29 |  | 
|---|
| 30 | myTMInfopt->atmTask.tmAddr =  NewTimerProc(montimer); | 
|---|
| 31 | myTMInfopt->atmTask.qLink = NULL; | 
|---|
| 32 | myTMInfopt->atmTask.qType = 0; | 
|---|
| 33 | myTMInfopt->atmTask.tmCount = 0L; | 
|---|
| 34 | myTMInfopt->atmTask.tmWakeUp = 0L; | 
|---|
| 35 | myTMInfopt->atmTask.tmReserved = 0L; | 
|---|
| 36 | myTMInfopt->mastructure = mastructure; | 
|---|
| 37 | myTMInfopt->delai=delai; | 
|---|
| 38 | myTMInfopt->execute=execute; | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | #ifdef  powerc | 
|---|
| 42 | //You don't need to do anything.  We will ignore the tmRefCon field. | 
|---|
| 43 | #else | 
|---|
| 44 | //Store A4 into the TMInfo struct | 
|---|
| 45 | //This is the best way in this situation | 
|---|
| 46 | //$$    myTMInfopt->tmRefCon = GetCurrentA4(); | 
|---|
| 47 | myTMInfopt->A5=SetCurrentA5(); | 
|---|
| 48 | #endif //powerc | 
|---|
| 49 |  | 
|---|
| 50 | InsXTime((QElemPtr)myTMInfopt); | 
|---|
| 51 | PrimeTime((QElemPtr)myTMInfopt, delai); | 
|---|
| 52 | return(myTMInfopt); | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 |  | 
|---|
| 57 | void supprimetimer(TMInfoPtr  myTMInfopt) | 
|---|
| 58 | { | 
|---|
| 59 | if(myTMInfopt) | 
|---|
| 60 | { | 
|---|
| 61 | TimerUPP tt=myTMInfopt->atmTask.tmAddr; | 
|---|
| 62 | DisposeRoutineDescriptor(tt); | 
|---|
| 63 | RmvTime((QElemPtr)myTMInfopt); | 
|---|
| 64 | free(myTMInfopt); | 
|---|
| 65 | myTMInfopt=0; | 
|---|
| 66 | } | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | void stoptimer(TMInfoPtr  myTMInfopt) | 
|---|
| 72 | { | 
|---|
| 73 | if(myTMInfopt)  myTMInfopt->delai=0; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | void redemarretimer(TMInfoPtr  myTMInfopt,long delai) | 
|---|
| 77 | { | 
|---|
| 78 | if(myTMInfopt) | 
|---|
| 79 | { | 
|---|
| 80 | myTMInfopt->delai=delai; | 
|---|
| 81 | PrimeTime((QElemPtr)myTMInfopt,myTMInfopt->delai); | 
|---|
| 82 | } | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 |  | 
|---|
| 86 | /*-----------------   prog interruption   -----------------------*/ | 
|---|
| 87 |  | 
|---|
| 88 |  | 
|---|
| 89 | #ifndef powerc | 
|---|
| 90 |  | 
|---|
| 91 | //The 68K resource needs this glue to move the TMInfo pointer from A1 to A0 where | 
|---|
| 92 | //the Toolbox put it.  N.B. This is very different from the pascal glue provided in | 
|---|
| 93 | //IM 6 TimeManager chapter, but then Pascal is very different from C. | 
|---|
| 94 |  | 
|---|
| 95 | asm  inline TMInfoPtr GetTMInfo( void ) | 
|---|
| 96 | { | 
|---|
| 97 | move.l A1, A0; | 
|---|
| 98 | rts; | 
|---|
| 99 | } | 
|---|
| 100 |  | 
|---|
| 101 |  | 
|---|
| 102 | //This function is being called at interrupt time so we can't move memory.  All we can | 
|---|
| 103 | // do is to set a global flag which our Drawing proc will detect. | 
|---|
| 104 | void montimer(void) | 
|---|
| 105 | { | 
|---|
| 106 | //Get a pointer to our TMInfo so we can prime it again | 
|---|
| 107 | TMInfoPtr       recPtr = GetTMInfo(); | 
|---|
| 108 | long            myDelay = 1000; //one sec. | 
|---|
| 109 |  | 
|---|
| 110 | //Sets A4 to the value in tmRefCon which was set to point to A4 at non-interrupt time. | 
|---|
| 111 | //$$    long            oldA4 = SetA4(recPtr->tmRefCon); | 
|---|
| 112 | long            oldA5 =  SetA5(recPtr->A5);                     /*A5 du programme*/ | 
|---|
| 113 |  | 
|---|
| 114 | (recPtr->execute)(recPtr->mastructure); | 
|---|
| 115 | PrimeTime((QElemPtr)recPtr,recPtr->delai); | 
|---|
| 116 |  | 
|---|
| 117 | //Restore the register state | 
|---|
| 118 | //$$    (void)SetA4(oldA4); | 
|---|
| 119 | SetA5(oldA5);                                   /*restore A5*/ | 
|---|
| 120 |  | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 |  | 
|---|
| 125 | #else | 
|---|
| 126 |  | 
|---|
| 127 | //The PowerPC version of a TimerUPP has the TMInfo pointer as a parameter.  Whew! No glue. | 
|---|
| 128 | //In fact, no need to set up global space either! | 
|---|
| 129 | void montimer(TMInfoPtr recPtr) | 
|---|
| 130 | { | 
|---|
| 131 |  | 
|---|
| 132 | (recPtr->execute)(recPtr->mastructure); | 
|---|
| 133 | if(recPtr->delai) PrimeTime((QElemPtr)recPtr,recPtr->delai); | 
|---|
| 134 |  | 
|---|
| 135 | } | 
|---|
| 136 | #endif //powerc | 
|---|
| 137 |  | 
|---|
| 138 |  | 
|---|
| 139 |  | 
|---|
| 140 |  | 
|---|
| 141 |  | 
|---|