make the AR engine use the correct bus funcs based on DS/DSi mode
This commit is contained in:
parent
13521211d2
commit
39af95e869
|
@ -19,6 +19,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "NDS.h"
|
#include "NDS.h"
|
||||||
|
#include "DSi.h"
|
||||||
#include "AREngine.h"
|
#include "AREngine.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +29,13 @@ namespace AREngine
|
||||||
// AR code file - frontend is responsible for managing this
|
// AR code file - frontend is responsible for managing this
|
||||||
ARCodeFile* CodeFile;
|
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()
|
bool Init()
|
||||||
{
|
{
|
||||||
|
@ -43,6 +51,25 @@ void DeInit()
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
CodeFile = nullptr;
|
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)
|
switch (op)
|
||||||
{
|
{
|
||||||
case16(0x00): // 32-bit write
|
case16(0x00): // 32-bit write
|
||||||
NDS::ARM7Write32((a & 0x0FFFFFFF) + offset, b);
|
BusWrite32((a & 0x0FFFFFFF) + offset, b);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case16(0x10): // 16-bit write
|
case16(0x10): // 16-bit write
|
||||||
NDS::ARM7Write16((a & 0x0FFFFFFF) + offset, b & 0xFFFF);
|
BusWrite16((a & 0x0FFFFFFF) + offset, b & 0xFFFF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case16(0x20): // 8-bit write
|
case16(0x20): // 8-bit write
|
||||||
NDS::ARM7Write8((a & 0x0FFFFFFF) + offset, b & 0xFF);
|
BusWrite8((a & 0x0FFFFFFF) + offset, b & 0xFF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case16(0x30): // IF b > u32[a]
|
case16(0x30): // IF b > u32[a]
|
||||||
|
@ -118,7 +145,7 @@ void RunCheat(ARCode& arcode)
|
||||||
condstack <<= 1;
|
condstack <<= 1;
|
||||||
condstack |= cond;
|
condstack |= cond;
|
||||||
|
|
||||||
u32 chk = NDS::ARM7Read32(a & 0x0FFFFFFF);
|
u32 chk = BusRead32(a & 0x0FFFFFFF);
|
||||||
|
|
||||||
cond = (b > chk) ? 1:0;
|
cond = (b > chk) ? 1:0;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +156,7 @@ void RunCheat(ARCode& arcode)
|
||||||
condstack <<= 1;
|
condstack <<= 1;
|
||||||
condstack |= cond;
|
condstack |= cond;
|
||||||
|
|
||||||
u32 chk = NDS::ARM7Read32(a & 0x0FFFFFFF);
|
u32 chk = BusRead32(a & 0x0FFFFFFF);
|
||||||
|
|
||||||
cond = (b < chk) ? 1:0;
|
cond = (b < chk) ? 1:0;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +167,7 @@ void RunCheat(ARCode& arcode)
|
||||||
condstack <<= 1;
|
condstack <<= 1;
|
||||||
condstack |= cond;
|
condstack |= cond;
|
||||||
|
|
||||||
u32 chk = NDS::ARM7Read32(a & 0x0FFFFFFF);
|
u32 chk = BusRead32(a & 0x0FFFFFFF);
|
||||||
|
|
||||||
cond = (b == chk) ? 1:0;
|
cond = (b == chk) ? 1:0;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +178,7 @@ void RunCheat(ARCode& arcode)
|
||||||
condstack <<= 1;
|
condstack <<= 1;
|
||||||
condstack |= cond;
|
condstack |= cond;
|
||||||
|
|
||||||
u32 chk = NDS::ARM7Read32(a & 0x0FFFFFFF);
|
u32 chk = BusRead32(a & 0x0FFFFFFF);
|
||||||
|
|
||||||
cond = (b != chk) ? 1:0;
|
cond = (b != chk) ? 1:0;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +189,7 @@ void RunCheat(ARCode& arcode)
|
||||||
condstack <<= 1;
|
condstack <<= 1;
|
||||||
condstack |= cond;
|
condstack |= cond;
|
||||||
|
|
||||||
u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF);
|
u16 val = BusRead16(a & 0x0FFFFFFF);
|
||||||
u16 chk = ~(b >> 16);
|
u16 chk = ~(b >> 16);
|
||||||
chk &= val;
|
chk &= val;
|
||||||
|
|
||||||
|
@ -175,7 +202,7 @@ void RunCheat(ARCode& arcode)
|
||||||
condstack <<= 1;
|
condstack <<= 1;
|
||||||
condstack |= cond;
|
condstack |= cond;
|
||||||
|
|
||||||
u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF);
|
u16 val = BusRead16(a & 0x0FFFFFFF);
|
||||||
u16 chk = ~(b >> 16);
|
u16 chk = ~(b >> 16);
|
||||||
chk &= val;
|
chk &= val;
|
||||||
|
|
||||||
|
@ -188,7 +215,7 @@ void RunCheat(ARCode& arcode)
|
||||||
condstack <<= 1;
|
condstack <<= 1;
|
||||||
condstack |= cond;
|
condstack |= cond;
|
||||||
|
|
||||||
u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF);
|
u16 val = BusRead16(a & 0x0FFFFFFF);
|
||||||
u16 chk = ~(b >> 16);
|
u16 chk = ~(b >> 16);
|
||||||
chk &= val;
|
chk &= val;
|
||||||
|
|
||||||
|
@ -201,7 +228,7 @@ void RunCheat(ARCode& arcode)
|
||||||
condstack <<= 1;
|
condstack <<= 1;
|
||||||
condstack |= cond;
|
condstack |= cond;
|
||||||
|
|
||||||
u16 val = NDS::ARM7Read16(a & 0x0FFFFFFF);
|
u16 val = BusRead16(a & 0x0FFFFFFF);
|
||||||
u16 chk = ~(b >> 16);
|
u16 chk = ~(b >> 16);
|
||||||
chk &= val;
|
chk &= val;
|
||||||
|
|
||||||
|
@ -210,7 +237,7 @@ void RunCheat(ARCode& arcode)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case16(0xB0): // offset = u32[a + offset]
|
case16(0xB0): // offset = u32[a + offset]
|
||||||
offset = NDS::ARM7Read32((a & 0x0FFFFFFF) + offset);
|
offset = BusRead32((a & 0x0FFFFFFF) + offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xC0: // FOR 0..b
|
case 0xC0: // FOR 0..b
|
||||||
|
@ -247,7 +274,7 @@ void RunCheat(ARCode& arcode)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xC6: // u32[b] = offset
|
case 0xC6: // u32[b] = offset
|
||||||
NDS::ARM7Write32(b, offset);
|
BusWrite32(b, offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xD0: // ENDIF
|
case 0xD0: // ENDIF
|
||||||
|
@ -296,30 +323,30 @@ void RunCheat(ARCode& arcode)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xD6: // u32[b+offset] = datareg / offset += 4
|
case 0xD6: // u32[b+offset] = datareg / offset += 4
|
||||||
NDS::ARM7Write32(b + offset, datareg);
|
BusWrite32(b + offset, datareg);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xD7: // u16[b+offset] = datareg / offset += 2
|
case 0xD7: // u16[b+offset] = datareg / offset += 2
|
||||||
NDS::ARM7Write16(b + offset, datareg & 0xFFFF);
|
BusWrite16(b + offset, datareg & 0xFFFF);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xD8: // u8[b+offset] = datareg / offset += 1
|
case 0xD8: // u8[b+offset] = datareg / offset += 1
|
||||||
NDS::ARM7Write8(b + offset, datareg & 0xFF);
|
BusWrite8(b + offset, datareg & 0xFF);
|
||||||
offset += 1;
|
offset += 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xD9: // datareg = u32[b+offset]
|
case 0xD9: // datareg = u32[b+offset]
|
||||||
datareg = NDS::ARM7Read32(b + offset);
|
datareg = BusRead32(b + offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xDA: // datareg = u16[b+offset]
|
case 0xDA: // datareg = u16[b+offset]
|
||||||
datareg = NDS::ARM7Read16(b + offset);
|
datareg = BusRead16(b + offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xDB: // datareg = u8[b+offset]
|
case 0xDB: // datareg = u8[b+offset]
|
||||||
datareg = NDS::ARM7Read8(b + offset);
|
datareg = BusRead8(b + offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xDC: // offset += b
|
case 0xDC: // offset += b
|
||||||
|
@ -334,8 +361,8 @@ void RunCheat(ARCode& arcode)
|
||||||
u32 bytesleft = b;
|
u32 bytesleft = b;
|
||||||
while (bytesleft >= 8)
|
while (bytesleft >= 8)
|
||||||
{
|
{
|
||||||
NDS::ARM7Write32(dstaddr, *code++); dstaddr += 4;
|
BusWrite32(dstaddr, *code++); dstaddr += 4;
|
||||||
NDS::ARM7Write32(dstaddr, *code++); dstaddr += 4;
|
BusWrite32(dstaddr, *code++); dstaddr += 4;
|
||||||
bytesleft -= 8;
|
bytesleft -= 8;
|
||||||
}
|
}
|
||||||
if (bytesleft > 0)
|
if (bytesleft > 0)
|
||||||
|
@ -344,13 +371,13 @@ void RunCheat(ARCode& arcode)
|
||||||
code += 2;
|
code += 2;
|
||||||
if (bytesleft >= 4)
|
if (bytesleft >= 4)
|
||||||
{
|
{
|
||||||
NDS::ARM7Write32(dstaddr, *(u32*)leftover); dstaddr += 4;
|
BusWrite32(dstaddr, *(u32*)leftover); dstaddr += 4;
|
||||||
leftover += 4;
|
leftover += 4;
|
||||||
bytesleft -= 4;
|
bytesleft -= 4;
|
||||||
}
|
}
|
||||||
while (bytesleft > 0)
|
while (bytesleft > 0)
|
||||||
{
|
{
|
||||||
NDS::ARM7Write8(dstaddr, *leftover++); dstaddr++;
|
BusWrite8(dstaddr, *leftover++); dstaddr++;
|
||||||
bytesleft--;
|
bytesleft--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,14 +393,14 @@ void RunCheat(ARCode& arcode)
|
||||||
u32 bytesleft = b;
|
u32 bytesleft = b;
|
||||||
while (bytesleft >= 4)
|
while (bytesleft >= 4)
|
||||||
{
|
{
|
||||||
NDS::ARM7Write32(dstaddr, NDS::ARM7Read32(srcaddr));
|
BusWrite32(dstaddr, BusRead32(srcaddr));
|
||||||
srcaddr += 4;
|
srcaddr += 4;
|
||||||
dstaddr += 4;
|
dstaddr += 4;
|
||||||
bytesleft -= 4;
|
bytesleft -= 4;
|
||||||
}
|
}
|
||||||
while (bytesleft > 0)
|
while (bytesleft > 0)
|
||||||
{
|
{
|
||||||
NDS::ARM7Write8(dstaddr, NDS::ARM7Read8(srcaddr));
|
BusWrite8(dstaddr, BusRead8(srcaddr));
|
||||||
srcaddr++;
|
srcaddr++;
|
||||||
dstaddr++;
|
dstaddr++;
|
||||||
bytesleft--;
|
bytesleft--;
|
||||||
|
|
Loading…
Reference in New Issue