From bb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 19 Sep 2025 13:17:14 +1200 Subject: 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. --- arm9/source/bang.h | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'arm9/source/bang.h') diff --git a/arm9/source/bang.h b/arm9/source/bang.h index 110e243..b85e9cd 100644 --- a/arm9/source/bang.h +++ b/arm9/source/bang.h @@ -1,31 +1,39 @@ #ifndef BANG_H_ #define BANG_H_ - #define SET_HIGH(v,high) v = high << 8 | (v & 0x00ff) - #define SET_LOW(v,low) v = (v & 0xff00) | low - #define HIGH(v) (u8)((v) >> 8) - #define LOW(v) (u8)((v) ) + #include - #define SET_H_HIGH(v,high) v = high << 24 | (v & 0x00ffffff) - #define SET_H_LOW(v,low) v = low << 16 | (v & 0xff00ffff) - #define SET_L_HIGH(v,high) v = high << 8 | (v & 0xffff00ff) - #define SET_L_LOW(v,low) v = low | (v & 0xffffff00) - #define H_HIGH(v) (u8)((v) >> 24) - #define H_LOW(v) (u8)((v) >> 16) - #define L_HIGH(v) (u8)((v) >> 8) - #define L_LOW(v) (u8)((v) ) - #define LEFT(x) ((x) >> 4) - #define RIGHT(x) ((x) & 0xf) - - #define SHF(x,y) (x >> RIGHT(y) << LEFT(y)) - #define TAL(x) __builtin_popcount(x) - - #define TEST(x,m) ((x & m) == m) + // Read and write individual bytes from a 32-bit value. + #define SETHH(v,h) v = h << 24 | (v & 0x00ffffff) + #define SETHL(v,l) v = l << 16 | (v & 0xff00ffff) + #define SETLH(v,h) v = h << 8 | (v & 0xffff00ff) + #define SETLL(v,l) v = l | (v & 0xffffff00) + #define GETHH(v) (u8)((v) >> 24) + #define GETHL(v) (u8)((v) >> 16) + #define GETLH(v) (u8)((v) >> 8) + #define GETLL(v) (u8)((v) ) + // Aliases for use on 16-bit values. + #define SETH(v,h) SETLH(v,h) + #define SETL(v,l) SETLL(v,l) + #define GETH(v) GETLH(v) + #define GETL(v) GETLL(v) + // Test if all bits of a mask are set in a value. + #define TEST(v,m) ((v & m) == m) + // Convert a C-style boolean to a Bedrock-style boolean. #define BOOL(v) ((u8)-(v)) + // Merge two bytes together as a double. #define DOUBLE(h,l) ((u16)(h) << 8 | (u16)(l)) + // Extract the high and low bytes of a double. + #define HIGH(v) (u8)(v >> 8) + #define LOW(v) (u8)(v) + // Find the highest or lowest value of a pair. + #define MAX(x,y) (x>y ? x : y) + #define MIN(x,y) (x