diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/AREngine.cpp | 97 |
1 files changed, 94 insertions, 3 deletions
diff --git a/src/AREngine.cpp b/src/AREngine.cpp index 9a87d5d..3049ecb 100644 --- a/src/AREngine.cpp +++ b/src/AREngine.cpp @@ -25,8 +25,16 @@ namespace AREngine { +typedef struct +{ + u32 Code[2 * 64]; // TODO: more sensible size for this? allocate on demand? + bool Enabled; + +} CheatEntry; + // TODO: more sensible size for this? allocate on demand? -u32 CheatCodes[2 * 1024]; +CheatEntry CheatCodes[64]; +u32 NumCheatCodes; bool Init() @@ -41,15 +49,98 @@ void DeInit() void Reset() { - memset(CheatCodes, 0, sizeof(u32)*2*1024); + memset(CheatCodes, 0, sizeof(CheatCodes)); + NumCheatCodes = 0; // TODO: acquire codes from a sensible source! + CheatEntry* entry = &CheatCodes[0]; + u32* ptr = &entry->Code[0]; +#define TEMP_PUTCODE(a, b) *ptr++ = a; *ptr++ = b; + // NSMBDS EUR - giant fucking Mario + TEMP_PUTCODE(0x1209DBD0, 0x0000027C); + TEMP_PUTCODE(0x2209DBC0, 0x00000003); + TEMP_PUTCODE(0x94000130, 0xFFFD0000); + TEMP_PUTCODE(0x1209DBD0, 0x00000000); + TEMP_PUTCODE(0x2209DBC0, 0x00000003); + entry->Enabled = true; + NumCheatCodes++; } +#define case16(x) \ + case ((x)+0x00): case ((x)+0x01): case ((x)+0x02): case ((x)+0x03): \ + case ((x)+0x04): case ((x)+0x05): case ((x)+0x06): case ((x)+0x07): \ + case ((x)+0x08): case ((x)+0x09): case ((x)+0x0A): case ((x)+0x0B): \ + case ((x)+0x0C): case ((x)+0x0D): case ((x)+0x0E): case ((x)+0x0F) + +void RunCheat(CheatEntry* entry) +{ + u32* code = &entry->Code[0]; + + u32 cond = 1; + u32 condstack = 0; + + for (;;) + { + u32 a = *code++; + u32 b = *code++; + if ((a|b) == 0) break; + + u8 op = a >> 24; + + if ((op < 0xD0 && op != 0xC5) || op > 0xD2) + { + if (!cond) + { + // TODO: skip parameters for opcode Ex + continue; + } + } + + switch (op) + { + case16(0x00): // 32-bit write + NDS::ARM7Write32(a & 0x0FFFFFFF, b); + break; + + case16(0x10): // 16-bit write + NDS::ARM7Write16(a & 0x0FFFFFFF, b & 0xFFFF); + break; + + case16(0x20): // 8-bit write + NDS::ARM7Write8(a & 0x0FFFFFFF, b & 0xFF); + break; + + case16(0x90): // IF b.l = ((~b.h) & u16[a]) + { + condstack <<= 1; + condstack |= cond; + + u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF); + u16 chk = ~(b >> 16); + chk &= val; + + cond = ((b & 0xFFFF) == chk) ? 1:0; + } + break; + + default: + printf("!! bad AR opcode %08X %08X\n", a, b); + return; + } + } +} + void RunCheats() { - // bahahah + // TODO: make it disableable in general + + for (u32 i = 0; i < NumCheatCodes; i++) + { + CheatEntry* entry = &CheatCodes[i]; + if (entry->Enabled) + RunCheat(entry); + } } } |