Homebrew How can I put a "TIMER" so that later it executes an action

  • Thread starter Thread starter LoboNer
  • Start date Start date
  • Views Views 1,526
  • Replies Replies 4

LoboNer

New Member
Newbie
Joined
Jul 24, 2022
Messages
3
Reaction score
0
Trophies
0
Age
25
Location
Peru lmao
XP
70
Country
Peru
What I mean by "TIMER" is that after the time limit I gave to the timer it executes an action programmed in the code.

Something like I want to make a basic timer that counts as 6 seconds and after those 6 seconds pass it executes a code that I programmed like adding an image on screen etc.

Do you guys know how to do this? I am new to DS programming.

(I use libnds and the NightFox Lib)
 
Take a look at libnds/include/timers.h

The function `timerStart` last argument named `callback` receives a pointer to a function. This means you can do things like
```
void Add_Image_On_SeenBuff(void) {
// Do your things.
}
```
And then,

```
timerStart(arg1, arg2, arg3, Add_Image_On_SeenBuff)
```
I assume this works by issuing an interruption, so be careful about how long your code will take to run and possible race condititons by having a function interrupted in the middle of its execution.
 
never used timer class, but it's very useful, other way you can define timer variable and place in the mainloop synchronized to vblank (60times per sec) something like...
int timer = 360;
If (timer && timer-- == 1){
// call function or do sort of things
}
or something similar in dozens different ways.
 
never used timer class, but it's very useful, other way you can define timer variable and place in the mainloop synchronized to vblank (60times per sec) something like...
int timer = 360;
If (timer && timer-- == 1){
// call function or do sort of things
}
or something similar in dozens different ways.
If you do not need your timer to be precise, then using a counter attached to vblank interrupt is a very good alternative. You can then use the hardware timer on tasks that actually require more precision.
 
Timer stuff you definitely want to use hardware for that since it's precise and wastes minimal CPU resources, here's an example implementing count in milliseconds and microseconds (DS is too slow for us,microseconds anyway):

https://bitbucket.org/Coto88/toolch...4403/src/common/hardware/timerTGDS.h#lines-54

https://bitbucket.org/Coto88/toolch...3/src/common/libhardware/timerTGDS.c#lines-27


Games use count in milliseconds (from timer or vblank counts) to make the game engine live at a certain pace.
I use it to synchronize the videoplayback to framerate in ToolchainGenericDS-multimediaplayer
 

Site & Scene News

Popular threads in this forum