aboutsummaryrefslogtreecommitdiff
path: root/arm9/source/core.h
diff options
context:
space:
mode:
Diffstat (limited to 'arm9/source/core.h')
-rw-r--r--arm9/source/core.h104
1 files changed, 16 insertions, 88 deletions
diff --git a/arm9/source/core.h b/arm9/source/core.h
index 765be3b..2eccc0a 100644
--- a/arm9/source/core.h
+++ b/arm9/source/core.h
@@ -1,99 +1,27 @@
-#include <nds.h>
-#include "main.h"
-
#ifndef CORE_H_
#define CORE_H_
- #include "devices/system.h"
- #include "devices/memory.h"
- #include "devices/math.h"
- #include "devices/clock.h"
- #include "devices/input.h"
- #include "devices/screen.h"
- #include "devices/local.h"
- #include "devices/file.h"
-
- #define WST br->wst
- #define RST br->rst
- #define MEM br->prg.mem
- #define PC br->prg.p
-
- #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;
+ #include "bang.h"
+ #include "dev.h"
- #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 [65536];
- u16 p;
- } ProgramMemory;
typedef struct {
- u8 mem[256]; // stack memory
- u8 p; // stack pointer
- } StackMemory;
+ u8 mem[256];
+ u8 p;
+ } Stack;
typedef struct {
- bool alive; // true when program is loaded
- bool awake; // true when program is not asleep
- ProgramMemory prg; // program memory
- StackMemory wst, rst; // working and return stacks
-
- SystemDevice sys;
- MemoryDevice mem;
- MathDevice math;
- ClockDevice clk;
- InputDevice inp;
- ScreenDevice scr;
- FileDevice fs;
+ bool alive; // True when program is not halted
+ bool awake; // True when program is not asleep
+ u8 mem[65536]; // Program memory
+ u16 ip; // Instruction pointer
+ Stack wst, rst; // Working and return stacks
+ DeviceBus dev; // Device bus
} Bedrock;
- void reset_br(Bedrock *br);
- void start_br(Bedrock *br, u8 program[], int size);
- void run_br(Bedrock *br);
- 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);
-
+ // Methods.
+ void br_reset(Bedrock *br);
+ void br_load(Bedrock *br, u8 program[], int size);
+ void br_rouse(Bedrock *br);
+ void br_run(Bedrock *br);
#endif