summaryrefslogtreecommitdiff
path: root/arm9/source/core.h
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2024-11-18 14:57:19 +1300
committerBen Bridle <ben@derelict.engineering>2024-11-18 14:57:19 +1300
commit722d5509178fa5bdaa488fbbd9196f21377f8775 (patch)
tree112b39cd80cb8e074d9e71d1def4d8de33c9eefa /arm9/source/core.h
downloadbedrock-nds-722d5509178fa5bdaa488fbbd9196f21377f8775.zip
Initial commit
Diffstat (limited to 'arm9/source/core.h')
-rw-r--r--arm9/source/core.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/arm9/source/core.h b/arm9/source/core.h
new file mode 100644
index 0000000..e5494ca
--- /dev/null
+++ b/arm9/source/core.h
@@ -0,0 +1,85 @@
+#ifndef CORE_H_
+ #define CORE_H_
+
+ #include "devices/clock.h"
+ #include "devices/input.h"
+ #include "devices/math.h"
+ #include "devices/screen.h"
+ #include "devices/system.h"
+
+ #define WST br->wst
+ #define RST br->rst
+ #define MEM br->mem
+ #define PC br->pc
+
+ #define WSTV(i) WST.mem[WST.p+(i)]
+ #define RSTV(i) RST.mem[RST.p+(i)]
+
+ #define MLIT MEM[PC++]
+ #define MLIT1(x) x = MLIT;
+ #define MLIT2(x,y) x = MLIT; y = MLIT;
+ #define MLITD(d) d = (u16)(MEM[PC] << 8) | (u16)(MEM[PC+1]); PC+=2;
+
+ #define WPSH WST.mem[WST.p++]
+ #define RPSH RST.mem[RST.p++]
+ #define WPSH1(x) WPSH = (x);
+ #define RPSH1(x) RPSH = (x);
+ #define WPSH2(x,y) WPSH1(x); WPSH1(y);
+ #define RPSH2(x,y) RPSH1(x); RPSH1(y);
+ #define WPSHD(d) WPSH1(HIGH((d))); WPSH1(LOW((d)));
+ #define RPSHD(d) RPSH1(HIGH((d))); RPSH1(LOW((d)));
+
+ #define WPOP WST.mem[--WST.p]
+ #define RPOP RST.mem[--RST.p]
+ #define WPOP1(x) x = WPOP;
+ #define RPOP1(x) x = RPOP;
+ #define WPOP2(x,y) WPOP1(y); WPOP1(x);
+ #define RPOP2(x,y) RPOP1(y); RPOP1(x);
+ #define WPOPD(d) d = (u16)(WSTV(-2) << 8) | (u16)(WSTV(-1)); WST.p-=2;
+ #define RPOPD(d) d = (u16)(RSTV(-2) << 8) | (u16)(RSTV(-1)); RST.p-=2;
+
+ #define WGET1(x) x = WSTV(-1);
+ #define RGET1(x) x = RSTV(-1);
+ #define WGET2(x,y) x = WSTV(-2); y = WSTV(-1);
+ #define RGET2(x,y) x = RSTV(-2); y = RSTV(-1);
+ #define WGETD(x) x = DOUBLE(WSTV(-2),WSTV(-1));
+ #define RGETD(x) x = DOUBLE(RSTV(-2),RSTV(-1));
+
+ typedef enum {
+ SIG_NONE,
+ SIG_HALT,
+ SIG_SLEEP,
+ SIG_DB1,
+ SIG_DB2,
+ SIG_DB3,
+ SIG_DB4,
+ SIG_DB5,
+ SIG_DB6,
+ } Signal;
+
+ typedef struct {
+ u8 mem[256]; // stack memory
+ u8 p; // stack pointer
+ } Stack;
+
+ typedef struct {
+ bool alive; // true when program is loaded
+ bool awake; // true when program is not asleep
+ u8 mem[65536]; // program memory
+ u16 pc; // program counter
+ Stack wst, rst; // working and return stacks
+ SystemDevice sys;
+ MathDevice math;
+ ClockDevice clk;
+ InputDevice inp;
+ ScreenDevice scr;
+ } Bedrock;
+
+ void reset_br(Bedrock *br);
+ void start_br(Bedrock *br, u8 program[], int size);
+ void rouse_br(Bedrock *br);
+ u8 dev_read(Bedrock *br, u8 port);
+ Signal dev_write(Bedrock *br, u8 port, u8 val);
+ Signal evaluate( Bedrock *br, u16 count);
+
+#endif