home *** CD-ROM | disk | FTP | other *** search
- #include <exec/memory.h>
- #include <devices/timer.h>
- #include <clib/alib_protos.h>
- #ifdef __GNUC__
- #include <inline/exec.h>
- #else
- #include <clib/exec_protos.h>
- #endif
-
- struct PortIO
- {
- struct timerequest treq;
- struct MsgPort port;
- };
-
- extern inline void NewList(struct List *list)
- {
- LONG *p;
-
- list->lh_TailPred=(struct Node*)list;
- ((LONG *)list)++;
- p=(LONG *)list; *--p=(LONG)list;
- }
-
- LONG DoTimer(struct timeval *time, long unit, long command)
- {
- struct PortIO *portio;
- long ret=-1;
-
- if ((portio=(struct PortIO *)AllocMem(sizeof(struct PortIO),MEMF_CLEAR|MEMF_PUBLIC)))
- {
- portio->port.mp_Node.ln_Type=NT_MSGPORT;
- if ((BYTE)(portio->port.mp_SigBit=AllocSignal(-1))<0)
- {
- portio->port.mp_SigTask=FindTask(NULL);
- NewList(&portio->port.mp_MsgList);
-
- portio->treq.tr_node.io_Message.mn_Node.ln_Type=NT_MESSAGE;
- portio->treq.tr_node.io_Message.mn_ReplyPort=&portio->port;
- if (!(OpenDevice(TIMERNAME,unit,(struct IORequest *)&portio->treq,0)))
- {
- portio->treq.tr_node.io_Command=command;
- portio->treq.tr_time.tv_secs=time->tv_secs;
- portio->treq.tr_time.tv_micro=time->tv_micro;
- DoIO((struct IORequest *)&portio->treq);
- time->tv_secs=portio->treq.tr_time.tv_secs;
- time->tv_micro=portio->treq.tr_time.tv_micro;
- CloseDevice((struct IORequest *)&portio->treq);
- ret=0;
- }
- FreeSignal(portio->port.mp_SigBit);
- }
- FreeMem(portio,sizeof(struct PortIO));
- }
- return ret;
- }
-