Hi all
I'm trying to allocate a struct TimeRequest object and copying the code from the a2d.c example code from
here, yet it fails to allocate the object using AllocSysObjectTags(). Is it something stupid that I'm doing??? I'm basically just after getting the ITimer interface so is there another way to do it?
cheers
billy
// a2d.c
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/datetime.h>
#include <devices/timer.h>
// Note these three libraries are opened by newlib startup code.
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <proto/timer.h>
struct TimerIFace *ITimer = NULL;
int main()
{
struct TimeRequest *tr = IExec->AllocSysObjectTags(ASOT_IOREQUEST,
ASOIOR_Size, sizeof(struct TimeRequest),
ASOIOR_ReplyPort, NULL,
TAG_END);
if (tr != NULL)
{
if (!(IExec->OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)tr, 0) ))
{
struct Library *TimerBase = (struct Library *) tr->Request.io_Device;
ITimer = (struct TimerIFace*)IExec->GetInterface(TimerBase, "main", 1, NULL);
if (ITimer != NULL)
{
struct TimeVal tv;
ITimer->GetSysTime(&tv);
IDOS->Printf("GetSysTime():\t%d %d\n", tv.Seconds, tv.Microseconds);
struct ClockData clockdata;
IUtility->Amiga2Date(tv.Seconds, &clockdata);
IDOS->Printf("Amiga2Date(): sec %d min %d hour %d\n",
clockdata.sec, clockdata.min, clockdata.hour);
IDOS->Printf(" mday %d month %d year %d wday %d\n",
clockdata.mday, clockdata.month, clockdata.year, clockdata.wday);
int32 seconds = IUtility->CheckDate(&clockdata);
IDOS->Printf("CheckDate():\t%ld\n", seconds);
seconds = IUtility->Date2Amiga(&clockdata);
IDOS->Printf("Date2Amiga():\t%ld\n", seconds);
IExec->DropInterface((struct Interface*)ITimer);
}
IExec->CloseDevice((struct IORequest *)tr);
}
IExec->FreeSysObject(ASOT_IOREQUEST, tr);
}
else
{
IDOS->Printf ("Failed to allocate TimeRequest\n");
}
return RETURN_OK;
}
Edited by billyfish on 2020/5/17 18:56:26