I am creating a game in C for the Casio PRIZM and I want to make a timer. I searched for the syscalls in the the WikiPrizm (https://prizm.cemetech.net/index.php?title=Category:Syscalls:Timers), but I didn't understand how to use this. Could sombody tell me how to make a timer correctly ?
The first step is to install (allocate) a timer. Once you get this, you can start and stop it for some time, and when you're done with it, you need to deinstall (free) it.

To obtain a timer that calls some function f after a delay d in millseconds, call Timer_Install(0, f, d). This returns the ID of your allocated timer (which can be -1 if none is available). The ID is used in all other functions.

You can then call Timer_Start(ID) and Timer_Stop(ID). When the timer is running, it calls f about every d milliseconds (the real resolution is about 40 ms according to the wiki, so you can think of d as being automatically rounded to a multiple of 40 ms). If you want to call f only once, you can call Timer_Stop(ID) within f.

Once you're done with the timer, you need to stop it and then call Timer_Deinstall() to free the resource.
Mind that storage memory and direct draw operations normally clash with timers - I think it could be a problem with games - maybe you can avoid timer and just incorporate checking time/elapsed time instead.
In fact anything non-reentrant clashes with timers, which also includes functions that use static or global variables and many small pieces of code that don't use the DMA. Thanks for the reminder!

In a game I would expect the timer function to either accomplish an exclusive task (eliminating the risk of reentrancy issues) or just mark some flags to control the timing of the program. I've never been fond of using RTC_GetTicks() which looks like a hack to me. The TMU is also much more precise as it goes under the microsecond.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement