summaryrefslogtreecommitdiff
path: root/arm9/source
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2024-11-22 16:04:33 +1300
committerBen Bridle <ben@derelict.engineering>2024-11-22 16:07:48 +1300
commitfcbc3968bd95e4d19b37d9fa4bca51b1db8596ff (patch)
tree333c6cf63f4b2aea513a9691b29c8f397e139c46 /arm9/source
parente05888d141bc64e92d81859af0d87627e6fbc477 (diff)
downloadbedrock-nds-fcbc3968bd95e4d19b37d9fa4bca51b1db8596ff.zip
Implement name and author ports in system device
Diffstat (limited to 'arm9/source')
-rw-r--r--arm9/source/core.c8
-rw-r--r--arm9/source/core.h2
-rw-r--r--arm9/source/devices/system.h4
-rw-r--r--arm9/source/main.c6
-rw-r--r--arm9/source/types/readbuf.c12
-rw-r--r--arm9/source/types/readbuf.h14
6 files changed, 42 insertions, 4 deletions
diff --git a/arm9/source/core.c b/arm9/source/core.c
index a1f9ec1..7136777 100644
--- a/arm9/source/core.c
+++ b/arm9/source/core.c
@@ -56,6 +56,8 @@ u8 dev_read(Bedrock *br, u8 port) {
switch(port) {
// SYSTEM DEVICE
// TODO: name and author
+ case 0x00: return rb_read(&br->sys.name);
+ case 0x01: return rb_read(&br->sys.authors);
case 0x02: return 0x00; // program memory size
case 0x03: return 0x00; // program memory size
case 0x04: return 0x00; // working stack size
@@ -143,8 +145,10 @@ u8 dev_read(Bedrock *br, u8 port) {
Signal dev_write(Bedrock *br, u8 port, u8 v) {
switch(port) {
// SYSTEM DEVICE
- case 0x08: SET_HIGH(br->sys.sleep,v); return 0;
- case 0x09: SET_LOW(br->sys.sleep,v); return SIG_SLEEP;
+ case 0x00: rb_reset(&br->sys.name); return 0;
+ case 0x01: rb_reset(&br->sys.authors); return 0;
+ case 0x08: SET_HIGH(br->sys.sleep,v); return 0;
+ case 0x09: SET_LOW(br->sys.sleep,v); return SIG_SLEEP;
// MEMORY DEVICE
case 0x10: mem_write1(&br->mem,v); return 0;
case 0x11: mem_write1(&br->mem,v); return 0;
diff --git a/arm9/source/core.h b/arm9/source/core.h
index 916806c..fde13a7 100644
--- a/arm9/source/core.h
+++ b/arm9/source/core.h
@@ -1,11 +1,11 @@
#ifndef CORE_H_
#define CORE_H_
+ #include "devices/system.h"
#include "devices/clock.h"
#include "devices/input.h"
#include "devices/math.h"
#include "devices/screen.h"
- #include "devices/system.h"
#include "devices/memory.h"
#define WST br->wst
diff --git a/arm9/source/devices/system.h b/arm9/source/devices/system.h
index b18b5a2..27619e3 100644
--- a/arm9/source/devices/system.h
+++ b/arm9/source/devices/system.h
@@ -1,7 +1,11 @@
+#include "../types/readbuf.h"
+
#ifndef SYSTEM_H_
#define SYSTEM_H_
typedef struct {
+ ReadBuf name;
+ ReadBuf authors;
u16 sleep; // device mask for waking
u8 wake; // ID of wake device
} SystemDevice;
diff --git a/arm9/source/main.c b/arm9/source/main.c
index 8bb78d8..ae983b3 100644
--- a/arm9/source/main.c
+++ b/arm9/source/main.c
@@ -14,6 +14,8 @@ Bedrock *br_main;
Bedrock *br_sub;
bool main_on_bottom = TRUE;
+char *system_name = "bedrock-nds, 0.1.0-alpha";
+char *system_authors = "Ben Bridle, 2024";
u8 main_program[] = {
#include "../include/cobalt.br.inc"
@@ -57,9 +59,11 @@ int main(void) {
#define AWAKE(br) (br && br->alive && br->awake)
#define ASLEEP(br) (br && br->alive && !br->awake)
- // Set memory identifiers.
+ // Set memory identifiers and system device strings.
for (int i=0; i<NUM_BR; i++) {
br[i].mem.id = i+1;
+ br[i].sys.name.mem = (u8*) &system_name[0];
+ br[i].sys.authors.mem = (u8*) &system_authors[0];
}
init_screens();
diff --git a/arm9/source/types/readbuf.c b/arm9/source/types/readbuf.c
new file mode 100644
index 0000000..eaee27a
--- /dev/null
+++ b/arm9/source/types/readbuf.c
@@ -0,0 +1,12 @@
+#include <nds.h>
+#include "readbuf.h"
+
+u8 rb_read(ReadBuf *buf) {
+ u8 output = buf->mem[buf->p];
+ if (output) buf->p++;
+ return output;
+}
+
+void rb_reset(ReadBuf *buf) {
+ buf->p = 0;
+}
diff --git a/arm9/source/types/readbuf.h b/arm9/source/types/readbuf.h
new file mode 100644
index 0000000..9077a69
--- /dev/null
+++ b/arm9/source/types/readbuf.h
@@ -0,0 +1,14 @@
+#include <nds.h>
+
+#ifndef READBUF_H_
+ #define READBUF_H_
+
+ typedef struct {
+ u8 *mem;
+ u8 p;
+ } ReadBuf;
+
+ u8 rb_read(ReadBuf *buf);
+ void rb_reset(ReadBuf *buf);
+
+#endif