Hi All,
Running in to a bit of trouble with the timer.device. I'm been able to build one of the examples on the AmigaOS dev wiki which runs with out issue. I'm trying to use the time is such a way that I can jump around my code while maintaining the timer state. Here's my code:
The code builds but crashes here: TimerMSG = IExec->GetMsg(bd->TimerMP);
Uncommenting the while loop in WaitforEvent (and commenting out the WaitPort stuff, will allow it to build and run but it crashes after exit. The crash is what I'm really after...
Any suggestion on what I'm doing wrong here?
Thanks!
Bill "tekmage" Borsari
//Test of My Timer functions #include <exec/types.h> #include <exec/memory.h> #include <devices/timer.h> #include <proto/dos.h> #include <proto/exec.h> struct BlankerData { struct MsgPort *TimerMP; struct TimeRequest *TimerIO; }; int PrepareTimer(struct BlankerData *bd) { uint32 error; int32 result_code = 0; IDOS->Printf( "--> PrepareTimer() Start\n" ); //Allocate the TimerMP, assigned in blanker.h to create ASOT if ( bd->TimerMP == NULL ) { IDOS->Printf( "--> PrepareTimer() AllocSysObjectTags bd->TimerMP\n" ); bd->TimerMP = IExec->AllocSysObjectTags(ASOT_PORT, TAG_END); } ///Setup the Timer device for high res control of the rendering if ( (bd->TimerIO == NULL) && (bd->TimerMP != NULL) ) { IDOS->Printf( "--> PrepareTimer() AllocSysObjectTags bd->TimerIO\n" ); bd->TimerIO = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size, sizeof(struct TimeRequest), ASOIOR_ReplyPort, bd->TimerMP, TAG_END); } if (bd->TimerIO != NULL ) { // Open the timer device error = IExec->OpenDevice( TIMERNAME, UNIT_VBLANK, (struct IORequest *) bd->TimerIO, 0L); if ( error != 0 ) { IDOS->Printf("--> PrepareTimer() Error: Could not OpenDevice %d\n", error); result_code = 1; } } return result_code; } int WaitForEvent(struct BlankerData *bd) { //Here we check to see if we get a signal from the timer or the blanker int32 return_code, loopcount = 0; int run = 0; IDOS->Printf("-->WaitForEvent() Enter\n"); IExec->WaitPort(bd->TimerMP); /* Get the reply message */ struct Message *TimerMSG; TimerMSG = IExec->GetMsg(bd->TimerMP); if (TimerMSG == (struct Message *)bd->TimerIO) { IDOS->Printf("Request finished\n"); } else { IDOS->Printf("Not our request, this is odd"); } // while (run == 0 ) // { // if ( (IExec->CheckIO( bd->TimerIO) ) != NULL ) // { // IDOS->Printf("-->WaitForEvent() CheckIO is NULL \n"); // run = 1; // return_code = 0; // } // if ( loopcount >= 30 ) // { // run = 1; // return_code = 2; // } // IDOS->Printf("-->WaitForEvent() Current Time %d\n", bd->TimerIO->Time.Seconds ); // IDOS->Delay( 50 ); // loopcount++; // } return 0; } void CleanForExit(struct BlankerData *bd) { if ( bd->TimerIO != NULL ) { IDOS->Printf("-->CleanForExit() Freeing TimerIO\n"); IExec->CloseDevice((struct IORequest *) bd->TimerIO); IExec->FreeSysObject(ASOT_IOREQUEST, bd->TimerIO); } if ( bd->TimerMP != NULL) { IDOS->Printf("-->CleanForExit() Freeing TimerMP\n"); IExec->FreeSysObject(ASOT_PORT, bd->TimerMP); } } int main() { struct BlankerData *bd; PrepareTimer(bd); //Set the timer for when to show the next photo bd->TimerIO->Request.io_Command = TR_ADDREQUEST; bd->TimerIO->Time.Seconds = 10; bd->TimerIO->Time.Microseconds = 0; IDOS->Printf("--> main() Initialized TimerIO \n"); IExec->SendIO((struct IORequest *)bd->TimerIO); WaitForEvent(bd); CleanForExit(bd); bd = NULL; return 0; }