Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
45 user(s) are online (29 user(s) are browsing Forums)

Members: 0
Guests: 45

more...

Support us!

Headlines






How to allocate TimeRequest
Just popping in
Joined:
2011/7/20 20:01
Posts: 68
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 %dn"tv.Secondstv.Microseconds);

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

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

        
IDOS->Printf("               mday %d month %d year %d wday %dn",
                    
clockdata.mdayclockdata.monthclockdata.yearclockdata.wday);

        
int32 seconds IUtility->CheckDate(&clockdata);

        
IDOS->Printf("CheckDate():t%ldn"seconds);

        
seconds IUtility->Date2Amiga(&clockdata);

        
IDOS->Printf("Date2Amiga():t%ldn"seconds);

                
IExec->DropInterface((struct Interface*)ITimer);
      }

      
IExec->CloseDevice((struct IORequest *)tr);
    }

        
IExec->FreeSysObject(ASOT_IOREQUESTtr);
    }
    else
    {
        
IDOS->Printf ("Failed to allocate TimeRequestn");
    }

  return 
RETURN_OK;
}


Edited by billyfish on 2020/5/17 18:56:26
   Report Go to top

Re: How to allocate TimeRequest
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 2824
before TAG_END, you have "ASIOR", that must be edit error.

_________________
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
   Report Go to top

Re: How to allocate TimeRequest
Just can't stay away
Joined:
2006/11/30 11:30
From Finland
Posts: 1740
@billyfish

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

   Report Go to top

Re: How to allocate TimeRequest
Just popping in
Joined:
2011/7/20 20:01
Posts: 68
@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

   Report Go to top

Re: How to allocate TimeRequest
Home away from home
Joined:
2007/9/11 12:31
From Russia
Posts: 6444
@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!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: How to allocate TimeRequest
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 2824
@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.
   Report Go to top

Re: How to allocate TimeRequest
Just popping in
Joined:
2011/7/20 20:01
Posts: 68
@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
   Report Go to top

Re: How to allocate TimeRequest
Just popping in
Joined:
2007/6/5 14:51
From Brisbane, AUSTRALIA
Posts: 103
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

   Report Go to top

Re: How to allocate TimeRequest
Just popping in
Joined:
2011/7/20 20:01
Posts: 68
@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

   Report Go to top

Re: How to allocate TimeRequest
Quite a regular
Joined:
2006/12/2 0:35
From Sydney
Posts: 695
@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
   Report Go to top

Re: How to allocate TimeRequest
Just can't stay away
Joined:
2009/5/1 18:57
From Czech Republic
Posts: 1167
@tonyw

Fredrik Wikstrom had updated the code before you looked

_________________
Smoke me a kipper, I'll be back for breakfast!

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
   Report Go to top

Re: How to allocate TimeRequest
Quite a regular
Joined:
2010/3/28 15:03
From None
Posts: 688
How complicated is the current C, since I learned Turbo C++.

_________________
Free programs&games:
http://www.morguesoft.eu
   Report Go to top





[Advanced Search]



Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project