Hi All,
I'm trying to induce a pause in an application that renders to the screen. Currently I'm using IDos->Delay(1) but I'd like to have more then 50'th of a second and I'd prefer not to use a Delay. I'd love some tips!
Cheers,
Bill
Hi All,
I'm trying to induce a pause in an application that renders to the screen. Currently I'm using IDos->Delay(1) but I'd like to have more then 50'th of a second and I'd prefer not to use a Delay. I'd love some tips!
Cheers,
Bill
You might try waiting for IDCMP_INTUITICK messages. Intuiticks are generated about every 1/10 of a second. The solution would require going into a Wait() IDCMP loop, counting the required number of intuiticks, and acting accordingly.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
Thanks Trixie,
I'll take a look at the docs for IDCMP_INTUITICK and see how that works.
Cheers,
Bill
Hi trixie,
Where are the new laws posted?
You could also use timer.device. Not as easy as a library but it is the standard Amiga way of doing it. We could use an alarm or timer function for OS4 right now!
You are right to look for a better way than Delay(). Internally this opens timer.device on every call so not very efficient! Still not fixed in OS4.
@tekimage
What laws??? :-)
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@tekmage
Open and close timer.device:
Start a timer request:
Then in your event loop:
Of course if you just need a more accurate version of IDOS->Delay() you can just use IExec->DoIO() (returns when the specified time has elapsed):
Thanks salass00.
AlexC had a simpler example:
To compile the above lib auto is used to open the device:
gcc -o microdelay microdelay.c -lauto
Stuck on trying to figure out the least amount of stuff to get the above to compile without libauto. Looking at timer.xml everything looks like a library but OpenLibrary does not seam to do it.
Don't use MicroDelay() in general code as it's polling (ties up the CPU while it waits). MicroDelay() should only ever be used for very small delays in places where multitasking is disabled or in interrupt code. As stated in the AutoDocs MicroDelay() is only really useful for driver writers that may need to use it for the simple reason that it doesn't need multitasking in order to work.
If you need an usleep() type function you can just use:
Or of course if you're not concerned about writing using AmigaOS API functions you can just use usleep() from newlib (works same as MicroDelay() only it doesn't use a polling loop, instead it uses timer.device in more or less the same way as I wrote above).
Does newlib usleep() also open up timer.device and required resources when it is called every time like Delay()O or is it cleaner?
@hypex
You do know that AmigaOS since version 1.0 caches libraries and devices so that they aren't reloaded every time there is an OpenDevice() or OpenLibrary()?
When a library or device is already in memory (timer.device is always in memory since it's in Kickstart) it's pretty much only a quick list lookup for "timer.device" and incrementing some open counters so there really isn't much overhead, plus opening/closing libraries/devices only when they are needed has the advantage that the OS can expunge them when they are not needed if it needs to create free memory for something else.
Yes I do know they are resident and maybe that's a big problem with AmigaOS. I have seen applcations call OS functions and use a snopping tool to watch hundreds of fonts being opened and devices. Delay() is one for this. It looks unnecessary and not very efficient to always allocate memory for these structures and open these resources when ever a function is called. Everything should be cached for futher use, not just a library.
I think this sort of thing would contribute to AmigaOS slowing down and in real use AmigaOS isn't fast any more. It can and will choke at a simple mouse move these days.