diff --git a/src/AREngine.cpp b/src/AREngine.cpp index 8ebf46c4..b47bcd49 100644 --- a/src/AREngine.cpp +++ b/src/AREngine.cpp @@ -19,6 +19,7 @@ #include #include #include "NDS.h" +#include "DSi.h" #include "AREngine.h" @@ -28,6 +29,13 @@ namespace AREngine // AR code file - frontend is responsible for managing this ARCodeFile* CodeFile; +u8 (*BusRead8)(u32 addr); +u16 (*BusRead16)(u32 addr); +u32 (*BusRead32)(u32 addr); +void (*BusWrite8)(u32 addr, u8 val); +void (*BusWrite16)(u32 addr, u16 val); +void (*BusWrite32)(u32 addr, u32 val); + bool Init() { @@ -43,6 +51,25 @@ void DeInit() void Reset() { CodeFile = nullptr; + + if (NDS::ConsoleType == 1) + { + BusRead8 = DSi::ARM7Read8; + BusRead16 = DSi::ARM7Read16; + BusRead32 = DSi::ARM7Read32; + BusWrite8 = DSi::ARM7Write8; + BusWrite16 = DSi::ARM7Write16; + BusWrite32 = DSi::ARM7Write32; + } + else + { + BusRead8 = NDS::ARM7Read8; + BusRead16 = NDS::ARM7Read16; + BusRead32 = NDS::ARM7Read32; + BusWrite8 = NDS::ARM7Write8; + BusWrite16 = NDS::ARM7Write16; + BusWrite32 = NDS::ARM7Write32; + } } @@ -102,15 +129,15 @@ void RunCheat(ARCode& arcode) switch (op) { case16(0x00): // 32-bit write - NDS::ARM7Write32((a & 0x0FFFFFFF) + offset, b); + BusWrite32((a & 0x0FFFFFFF) + offset, b); break; case16(0x10): // 16-bit write - NDS::ARM7Write16((a & 0x0FFFFFFF) + offset, b & 0xFFFF); + BusWrite16((a & 0x0FFFFFFF) + offset, b & 0xFFFF); break; case16(0x20): // 8-bit write - NDS::ARM7Write8((a & 0x0FFFFFFF) + offset, b & 0xFF); + BusWrite8((a & 0x0FFFFFFF) + offset, b & 0xFF); break; case16(0x30): // IF b > u32[a] @@ -118,7 +145,7 @@ void RunCheat(ARCode& arcode) condstack <<= 1; condstack |= cond; - u32 chk = NDS::ARM7Read32(a & 0x0FFFFFFF); + u32 chk = BusRead32(a & 0x0FFFFFFF); cond = (b > chk) ? 1:0; } @@ -129,7 +156,7 @@ void RunCheat(ARCode& arcode) condstack <<= 1; condstack |= cond; - u32 chk = NDS::ARM7Read32(a & 0x0FFFFFFF); + u32 chk = BusRead32(a & 0x0FFFFFFF); cond = (b < chk) ? 1:0; } @@ -140,7 +167,7 @@ void RunCheat(ARCode& arcode) condstack <<= 1; condstack |= cond; - u32 chk = NDS::ARM7Read32(a & 0x0FFFFFFF); + u32 chk = BusRead32(a & 0x0FFFFFFF); cond = (b == chk) ? 1:0; } @@ -151,7 +178,7 @@ void RunCheat(ARCode& arcode) condstack <<= 1; condstack |= cond; - u32 chk = NDS::ARM7Read32(a & 0x0FFFFFFF); + u32 chk = BusRead32(a & 0x0FFFFFFF); cond = (b != chk) ? 1:0; } @@ -162,7 +189,7 @@ void RunCheat(ARCode& arcode) condstack <<= 1; condstack |= cond; - u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF); + u16 val = BusRead16(a & 0x0FFFFFFF); u16 chk = ~(b >> 16); chk &= val; @@ -175,7 +202,7 @@ void RunCheat(ARCode& arcode) condstack <<= 1; condstack |= cond; - u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF); + u16 val = BusRead16(a & 0x0FFFFFFF); u16 chk = ~(b >> 16); chk &= val; @@ -188,7 +215,7 @@ void RunCheat(ARCode& arcode) condstack <<= 1; condstack |= cond; - u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF); + u16 val = BusRead16(a & 0x0FFFFFFF); u16 chk = ~(b >> 16); chk &= val; @@ -201,7 +228,7 @@ void RunCheat(ARCode& arcode) condstack <<= 1; condstack |= cond; - u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF); + u16 val = BusRead16(a & 0x0FFFFFFF); u16 chk = ~(b >> 16); chk &= val; @@ -210,7 +237,7 @@ void RunCheat(ARCode& arcode) break; case16(0xB0): // offset = u32[a + offset] - offset = NDS::ARM7Read32((a & 0x0FFFFFFF) + offset); + offset = BusRead32((a & 0x0FFFFFFF) + offset); break; case 0xC0: // FOR 0..b @@ -247,7 +274,7 @@ void RunCheat(ARCode& arcode) break; case 0xC6: // u32[b] = offset - NDS::ARM7Write32(b, offset); + BusWrite32(b, offset); break; case 0xD0: // ENDIF @@ -296,30 +323,30 @@ void RunCheat(ARCode& arcode) break; case 0xD6: // u32[b+offset] = datareg / offset += 4 - NDS::ARM7Write32(b + offset, datareg); + BusWrite32(b + offset, datareg); offset += 4; break; case 0xD7: // u16[b+offset] = datareg / offset += 2 - NDS::ARM7Write16(b + offset, datareg & 0xFFFF); + BusWrite16(b + offset, datareg & 0xFFFF); offset += 2; break; case 0xD8: // u8[b+offset] = datareg / offset += 1 - NDS::ARM7Write8(b + offset, datareg & 0xFF); + BusWrite8(b + offset, datareg & 0xFF); offset += 1; break; case 0xD9: // datareg = u32[b+offset] - datareg = NDS::ARM7Read32(b + offset); + datareg = BusRead32(b + offset); break; case 0xDA: // datareg = u16[b+offset] - datareg = NDS::ARM7Read16(b + offset); + datareg = BusRead16(b + offset); break; case 0xDB: // datareg = u8[b+offset] - datareg = NDS::ARM7Read8(b + offset); + datareg = BusRead8(b + offset); break; case 0xDC: // offset += b @@ -334,8 +361,8 @@ void RunCheat(ARCode& arcode) u32 bytesleft = b; while (bytesleft >= 8) { - NDS::ARM7Write32(dstaddr, *code++); dstaddr += 4; - NDS::ARM7Write32(dstaddr, *code++); dstaddr += 4; + BusWrite32(dstaddr, *code++); dstaddr += 4; + BusWrite32(dstaddr, *code++); dstaddr += 4; bytesleft -= 8; } if (bytesleft > 0) @@ -344,13 +371,13 @@ void RunCheat(ARCode& arcode) code += 2; if (bytesleft >= 4) { - NDS::ARM7Write32(dstaddr, *(u32*)leftover); dstaddr += 4; + BusWrite32(dstaddr, *(u32*)leftover); dstaddr += 4; leftover += 4; bytesleft -= 4; } while (bytesleft > 0) { - NDS::ARM7Write8(dstaddr, *leftover++); dstaddr++; + BusWrite8(dstaddr, *leftover++); dstaddr++; bytesleft--; } } @@ -366,14 +393,14 @@ void RunCheat(ARCode& arcode) u32 bytesleft = b; while (bytesleft >= 4) { - NDS::ARM7Write32(dstaddr, NDS::ARM7Read32(srcaddr)); + BusWrite32(dstaddr, BusRead32(srcaddr)); srcaddr += 4; dstaddr += 4; bytesleft -= 4; } while (bytesleft > 0) { - NDS::ARM7Write8(dstaddr, NDS::ARM7Read8(srcaddr)); + BusWrite8(dstaddr, BusRead8(srcaddr)); srcaddr++; dstaddr++; bytesleft--;