Starship/src/main/sys_timer.c
petrie911 af26374677
Match Matrix_Scale, change some file names (#52)
* stuff

* three whole files

* format

* format and such

* a switch in time

* merge prep

* nintendo switch

* format

* the great switch statement of our time

* 43AC0 matched

* stuff

* Enums everywhere

* oh god the switch

* knakyo

* new headers

* format

* fox

* everyone hates recursion

* format

* one more thing

* one more one more thing

* renames

* matches

* matrix scale why

* names and such

* cleanup

* name back
2023-12-15 17:09:49 -03:00

51 lines
1.1 KiB
C

#include "global.h"
TimerTask sTimerTasks[0x10];
TimerTask* Timer_AllocateTask(void) {
s32 i;
for (i = 0; i < 0x10; i++) {
if (!sTimerTasks[i].active) {
return &sTimerTasks[i];
}
}
return NULL;
}
s32 Timer_CreateTask(u64 time, TimerAction action, s32* address, s32 value) {
TimerTask* task = Timer_AllocateTask();
if (task == NULL) {
return -1;
}
task->active = true;
task->action = action;
task->address = address;
task->value = value;
return osSetTimer(&task->timer, time, 0, &gTimerTaskMsgQueue, task);
}
void Timer_Increment(s32* address, s32 value) {
*address += value;
}
void Timer_SetValue(s32* address, s32 value) {
*address = value;
}
void Timer_CompleteTask(TimerTask* task) {
if (task->action != NULL) {
task->action(task->address, task->value);
}
task->active = false;
}
void Timer_Wait(u64 time) {
OSTimer timer;
OSMesg dummy;
osSetTimer(&timer, time, 0, &gTimerWaitMsgQueue, NULL);
osRecvMesg(&gTimerWaitMsgQueue, &dummy, OS_MESG_BLOCK);
}