summaryrefslogtreecommitdiff
path: root/src/main/timer.c
diff options
context:
space:
mode:
authorpetrie911 <69443847+petrie911@users.noreply.github.com>2023-11-24 13:11:20 -0600
committerGitHub <noreply@github.com>2023-11-24 16:11:20 -0300
commitd32854ced18eb334bbba4e2e67074bae641688c2 (patch)
tree87f70b39674f4c4587b5e51888fd5cf6738ef10e /src/main/timer.c
parente0cc3dbc0eca3f2b21c948fad3581a4adade713e (diff)
Proposed names for library stuff (#29)
* get this started * linker scripts fixed * oh god what now * names * the blue pill * names, perhaps * save * clean out structs * save for later again * more names * save, again
Diffstat (limited to 'src/main/timer.c')
-rw-r--r--src/main/timer.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main/timer.c b/src/main/timer.c
new file mode 100644
index 00000000..fa5ab6e0
--- /dev/null
+++ b/src/main/timer.c
@@ -0,0 +1,50 @@
+#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);
+}