GBACart: simulate open-bus decay roughly. fixes #1093

This commit is contained in:
Arisotura 2021-05-04 12:58:59 +02:00
parent b7d5a7db75
commit 50721719d2
3 changed files with 42 additions and 29 deletions

View File

@ -40,15 +40,15 @@ const char SOLAR_SENSOR_GAMECODES[10][5] =
bool CartInserted; bool CartInserted;
//bool HasSolarSensor;
u8* CartROM; u8* CartROM;
u32 CartROMSize; u32 CartROMSize;
u32 CartCRC; u32 CartCRC;
u32 CartID; u32 CartID;
//GPIO CartGPIO; // overridden GPIO parameters
CartCommon* Cart; CartCommon* Cart;
u16 OpenBusDecay;
CartCommon::CartCommon() CartCommon::CartCommon()
{ {
@ -631,6 +631,9 @@ void Reset()
// This allows resetting a DS game without losing GBA state, // This allows resetting a DS game without losing GBA state,
// and resetting to firmware without the slot being emptied. // and resetting to firmware without the slot being emptied.
// The Stop function will clear the cartridge state via Eject(). // The Stop function will clear the cartridge state via Eject().
// OpenBusDecay doesn't need to be reset, either, as it will be set
// through NDS::SetGBASlotTimings().
} }
void Eject() void Eject()
@ -795,11 +798,17 @@ int SetInput(int num, bool pressed)
} }
void SetOpenBusDecay(u16 val)
{
OpenBusDecay = val;
}
u16 ROMRead(u32 addr) u16 ROMRead(u32 addr)
{ {
if (Cart) return Cart->ROMRead(addr); if (Cart) return Cart->ROMRead(addr);
return (addr >> 1) & 0xFFFF; return ((addr >> 1) & 0xFFFF) | OpenBusDecay;
} }
void ROMWrite(u32 addr, u16 val) void ROMWrite(u32 addr, u16 val)

View File

@ -161,6 +161,8 @@ void RelocateSave(const char* path, bool write);
// TODO: make more flexible, support nonbinary inputs // TODO: make more flexible, support nonbinary inputs
int SetInput(int num, bool pressed); int SetInput(int num, bool pressed);
void SetOpenBusDecay(u16 val);
u16 ROMRead(u32 addr); u16 ROMRead(u32 addr);
void ROMWrite(u32 addr, u16 val); void ROMWrite(u32 addr, u16 val);

View File

@ -1242,33 +1242,35 @@ void SetWifiWaitCnt(u16 val)
void SetGBASlotTimings() void SetGBASlotTimings()
{ {
int curcpu = (ExMemCnt[0] >> 7) & 0x1;
const int ntimings[4] = {10, 8, 6, 18}; const int ntimings[4] = {10, 8, 6, 18};
const u16 openbus[4] = {0xFE08, 0x0000, 0x0000, 0xFFFF};
u16 curcnt = ExMemCnt[curcpu]; u16 curcnt;
int ramN = ntimings[curcnt & 0x3]; int ramN, romN, romS;
int romN = ntimings[(curcnt>>2) & 0x3];
int romS = (curcnt & 0x10) ? 4 : 6;
// TODO: PHI pin thing? curcnt = ExMemCnt[0];
ramN = ntimings[curcnt & 0x3];
romN = ntimings[(curcnt>>2) & 0x3];
romS = (curcnt & 0x10) ? 4 : 6;
if (curcpu == 0) SetARM9RegionTimings(0x08000000, 0x0A000000, 16, romN + 3, romS);
{ SetARM9RegionTimings(0x0A000000, 0x0B000000, 8, ramN + 3, ramN);
SetARM9RegionTimings(0x08000000, 0x0A000000, 16, romN + 3, romS);
SetARM9RegionTimings(0x0A000000, 0x0B000000, 8, ramN + 3, ramN);
SetARM7RegionTimings(0x08000000, 0x0A000000, 32, 1, 1); curcnt = ExMemCnt[1];
SetARM7RegionTimings(0x0A000000, 0x0B000000, 32, 1, 1); ramN = ntimings[curcnt & 0x3];
} romN = ntimings[(curcnt>>2) & 0x3];
else romS = (curcnt & 0x10) ? 4 : 6;
{
SetARM9RegionTimings(0x08000000, 0x0A000000, 32, 1, 1);
SetARM9RegionTimings(0x0A000000, 0x0B000000, 32, 1, 1);
SetARM7RegionTimings(0x08000000, 0x0A000000, 16, romN, romS); SetARM7RegionTimings(0x08000000, 0x0A000000, 16, romN, romS);
SetARM7RegionTimings(0x0A000000, 0x0B000000, 8, ramN, ramN); SetARM7RegionTimings(0x0A000000, 0x0B000000, 8, ramN, ramN);
}
// this open-bus implementation is a rough way of simulating the way values
// lingering on the bus decay after a while, which is visible at higher waitstates
// for example, the Cartridge Construction Kit relies on this to determine that
// the GBA slot is empty
curcnt = ExMemCnt[(ExMemCnt[0]>>7) & 0x1];
GBACart::SetOpenBusDecay(openbus[(curcnt>>2) & 0x3]);
} }
@ -1863,8 +1865,8 @@ void debug(u32 param)
//for (int i = 0; i < 9; i++) //for (int i = 0; i < 9; i++)
// printf("VRAM %c: %02X\n", 'A'+i, GPU::VRAMCNT[i]); // printf("VRAM %c: %02X\n", 'A'+i, GPU::VRAMCNT[i]);
/*FILE* FILE*
shit = fopen("debug/party.bin", "wb"); shit = fopen("debug/construct.bin", "wb");
fwrite(ARM9->ITCM, 0x8000, 1, shit); fwrite(ARM9->ITCM, 0x8000, 1, shit);
for (u32 i = 0x02000000; i < 0x02400000; i+=4) for (u32 i = 0x02000000; i < 0x02400000; i+=4)
{ {
@ -1876,9 +1878,9 @@ void debug(u32 param)
u32 val = ARM7Read32(i); u32 val = ARM7Read32(i);
fwrite(&val, 4, 1, shit); fwrite(&val, 4, 1, shit);
} }
fclose(shit);*/ fclose(shit);
FILE* /*FILE*
shit = fopen("debug/power9.bin", "wb"); shit = fopen("debug/power9.bin", "wb");
for (u32 i = 0x02000000; i < 0x04000000; i+=4) for (u32 i = 0x02000000; i < 0x04000000; i+=4)
{ {
@ -1892,7 +1894,7 @@ void debug(u32 param)
u32 val = DSi::ARM7Read32(i); u32 val = DSi::ARM7Read32(i);
fwrite(&val, 4, 1, shit); fwrite(&val, 4, 1, shit);
} }
fclose(shit); fclose(shit);*/
} }