diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-09-19 13:17:14 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-09-19 13:32:32 +1200 |
commit | bb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e (patch) | |
tree | b26d07ed58aaf7a5230fc3e28c103d616abfa9b8 /arm9/source/bang.h | |
parent | 9612c307f00c4313d73fe0c3a86c05c8d8cd514e (diff) | |
download | bedrock-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/bang.h')
-rw-r--r-- | arm9/source/bang.h | 52 |
1 files changed, 30 insertions, 22 deletions
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 <nds.h> - #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<y ? x : y) - u8 rev(u8 x); - u8 shc(u8 x, u8 y); - u16 shcd(u16 x, u8 y); + // Functions. + u8 ROL1(u8 v, u8 d); + u16 ROLD(u16 v, u8 d); + u8 ROR1(u8 v, u8 d); + u16 RORD(u16 v, u8 d); #endif |