I would like to learn how 'Timers' works on Amiga OS4.
I used Timers in other programming environments and i don't know if i can do (or how to do) the same things with the Amiga SDK in c or c++.
Just for example, in actionscript you can create a timer and program it to execute code at regular time or once.
You can also start, stop and change the update time at runtime.
How can i do this with Amiga OS?
If you want to execute code at regular intervals in a C program you can use the AmigaDOS Delay() command in a loop; unless you need extremely precise intervals. Refer to SDK:Documentation/Autodocs/dos.doc.
You can execute commands at regular intervals in an AmigaDOS script by using SYS:C/Wait in a loop.
X1000 - OS 4.1FE
Using the timer.device is very easy and allows more control than just using f.e. Delay() or usleep().
There is documentation and examples on how to use it here:
http://wiki.amigaos.net/index.php/Timer_Device
Thank you for the reply.
i already read the documentation, but i need other examples.
I would like to use a timer that call a function at regular time, asynchronously. Is this possible?
It is explained in the link I posted.
Generally you would do it something like this:
The StartTimer would set up the TimerRequest for the delay you want and then call IExec->SendIO() to start the timer request while AbortTimer() after the loop would just call IExec->AbortIO() and IExec->WaitIO() to stop and cleanup the remaining timer request so you can free the TimerRequest without worries later.
@AmigaBlitter
FWIW, I've been messing with Timers for the first time last
weekend.
In the process I believe I boiled down a good simple
timer.device example. I added it to the AmigaOS wiki page
as "Simple_Wait.c"...
http://wiki.amigaos.net/index.php/Timer_Device#Simple_Wait_Device_Example
Don't forget to keep track of opening and closing and
deallocating everything.
Good luck,
PJS
@PJS
I've started polishing the wiki timer examples a little. Got rid of ULONGs, initialized local pointers to NULL, declared main() as void (as per the C specification), made the return calls a bit more consistent, etc.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
Thank you all for the info.
Going to study...
Like the title. :-)
Also take a look at a timer.device interrupt in the wiki. That can execute code on a timer pulse. Which sounded like what you were after.
As an alternate, though not usually suggested, you could also try lowlevel.library. This allows you to setup and add timer code similar to timer,device but can be easier to use, especially for timer interrupts.