aboutsummaryrefslogtreecommitdiff
path: root/arm9/source/types/wakequeue.c
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-09-19 13:17:14 +1200
committerBen Bridle <ben@derelict.engineering>2025-09-19 13:32:32 +1200
commitbb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e (patch)
treeb26d07ed58aaf7a5230fc3e28c103d616abfa9b8 /arm9/source/types/wakequeue.c
parent9612c307f00c4313d73fe0c3a86c05c8d8cd514e (diff)
downloadbedrock-nds-bb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e.zip
Massive rewrite
This commit rewrites the emulator halfway from scratch to make it easier to change and maintain in the future. The emulator core was rewritten to adhere to the released Bedrock specification (earlier versions implemented an older prototype specification, which is no longer relevant). This commit also adds proper support for running multiple concurrent Bedrock instances. This was previously supported in a limited manner for the on-screen keyboard, but now works for any regular program as well, with switching being performed by pressing the L or R bumper buttons. This is disabled by default, as programs will still need to be baked into the emulator and hand-loaded.
Diffstat (limited to 'arm9/source/types/wakequeue.c')
-rw-r--r--arm9/source/types/wakequeue.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/arm9/source/types/wakequeue.c b/arm9/source/types/wakequeue.c
new file mode 100644
index 0000000..8876123
--- /dev/null
+++ b/arm9/source/types/wakequeue.c
@@ -0,0 +1,30 @@
+#include "wakequeue.h"
+
+/*
+TODO: This is unused at the moment. It will eventually be used for keeping
+track of which device last woke a Bedrock instance, to optimally choose
+which device to use when waking from sleep.
+*/
+
+// Reset a wake queue.
+void wakequeue_reset(WakeQueue *queue) {
+ // Populate the queue with fifteen slot numbers. Slot zero is excluded,
+ // as it always comes last in the wake order.
+ for (int i=0; i<15; i++) queue->mem[i] = i+1;
+}
+
+// TODO: Not quite done yet.
+bool wakequeue_wake(WakeQueue *queue, u16 device_list) {
+ // Test each entry in the queue against the device list.
+ for (int i=0; i<15; i++) {
+ u8 slot_number = queue->mem[i];
+ if (TEST(device_list, 0x8000 >> slot_number)) {
+ // Move the matched entry to the back of the queue.
+ for (; i<14; i++) queue->mem[i] = queue->mem[i+1];
+ queue->mem[14] = slot_number;
+ return true;
+ }
+ }
+ // Test system device last.
+ return TEST(device_list, 0x8000);
+}