Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
114 user(s) are online (63 user(s) are browsing Forums)

Members: 0
Guests: 114

more...

Headlines

 
  Register To Post  

How to allocate TimeRequest
Just popping in
Just popping in


See User information
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_Sizesizeof(struct TimeRequest),
    
ASOIOR_ReplyPortNULL,
        
TAG_END);

  if (
tr != NULL)
  {
    if (!(
IExec->OpenDevice("timer.device"UNIT_VBLANK, (struct IORequest *)tr0) ))
    {
            
struct Library *TimerBase = (struct Library *) tr->Request.io_Device;
      
ITimer = (struct TimerIFace*)IExec->GetInterface(TimerBase"main"1NULL);

      if (
ITimer != NULL)
      {
        
struct TimeVal tv;
        
ITimer->GetSysTime(&tv);

        
IDOS->Printf("GetSysTime():\t%d %d\n"tv.Secondstv.Microseconds);

        
struct ClockData clockdata;
        
IUtility->Amiga2Date(tv.Seconds, &clockdata);

        
IDOS->Printf("Amiga2Date():  sec %d min %d hour %d\n",
          
clockdata.secclockdata.minclockdata.hour);

        
IDOS->Printf("               mday %d month %d year %d wday %d\n",
                    
clockdata.mdayclockdata.monthclockdata.yearclockdata.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_IOREQUESTtr);
    }
    else
    {
        
IDOS->Printf ("Failed to allocate TimeRequest\n");
    }

  return 
RETURN_OK;
}


Edited by billyfish on 2020/5/17 18:56:26
Go to top
Re: How to allocate TimeRequest
Home away from home
Home away from home


See User information
before TAG_END, you have "ASIOR", that must be edit error.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: How to allocate TimeRequest
Just can't stay away
Just can't stay away


See User information
@billyfish

You must provide a valid message port for ASOIOR_ReplyPort. If it's NULL the allocation will fail, same as with CreateIORequest().

Go to top
Re: How to allocate TimeRequest
Just popping in
Just popping in


See User information
@LiveForIt

Sorry, when i pasted ito my post I accidentally added the ASIOR bit. I've edited the post to remove that. It compiles fine, but the timerequest allocation fails and I get the printf statement confirming it.

If I switch to allocating it with

struct TimeRequest *tr IExec->AllocVecTags(sizeof(struct TimeRequest),
    
AVT_ClearWithValue0,
    
TAG_END);


and

IExec->FreeVec (tr);


it works fine. Anyone have any idea what I'm doing wrong with the AllocSysObjectTags() version?

cheers

billy

Go to top
Re: How to allocate TimeRequest
Home away from home
Home away from home


See User information
@billyfish

That how i allocate it in Odyssey (and it works of course):

https://github.com/kas1e/Odyssey/blob/ ... her/MorphOS/main.cpp#L392

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: How to allocate TimeRequest
Home away from home
Home away from home


See User information
@billyfish

this is wrong " ASOIOR_ReplyPort, NULL, "

you need to provide a message port.

Create a port using "ASOT_PORT"
see "sdk:documentation/autodocs/exec.doc"

replace "NULL" with Port you created.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: How to allocate TimeRequest
Just popping in
Just popping in


See User information
@LiveForIt, @salass00 and @Kas1e


Thanks guys, I'll update the code. So the page at https://wiki.amigaos.net/wiki/Date_Functions needs to have the example a2d.c code fixed I guess.

cheers

billy


Edited by billyfish on 2020/5/18 11:45:38
Go to top
Re: How to allocate TimeRequest
Just popping in
Just popping in


See User information
Watch out with using %d with IDOS->Printf(), it doesn't work.

All VARARGS68K arguments are padded to 32 bit wide and means
you should use (long) %ld formatter instead, no matter what the argument width is.

Same goes for even one byte arguments, you would use %lc instead of %c

Go to top
Re: How to allocate TimeRequest
Just popping in
Just popping in


See User information
@colinw

Thanks they're good bits to know. I'll post a bug report on Hyperion's forum so they can update the example at https://wiki.amigaos.net/wiki/Date_Functions.

cheers

billy

Go to top
Re: How to allocate TimeRequest
Quite a regular
Quite a regular


See User information
@billyfish

The code on the wiki site looks OK to me. Are you sure you copied it all and didn't leave out some stuff?

Especially the need to create your own MsgPort before you call AllocSysObject() ?


cheers
tony
Go to top
Re: How to allocate TimeRequest
Just can't stay away
Just can't stay away


See User information
@tonyw

Fredrik Wikstrom had updated the code before you looked

The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
Go to top
Re: How to allocate TimeRequest
Quite a regular
Quite a regular


See User information
How complicated is the current C, since I learned Turbo C++.

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project