don't hardcode numbers you derp

also add some extra safety
This commit is contained in:
Arisotura
2021-04-21 20:34:38 +02:00
parent 49fa1b5290
commit b5e4871930

View File

@ -1231,14 +1231,17 @@ int CartRetailNAND::ROMCommandStart(u8* cmd, u8* data, u32 len)
switch (cmd[0]) switch (cmd[0])
{ {
case 0x81: // write data case 0x81: // write data
if ((SRAMStatus & (1<<4)) && SRAMWindow >= SRAMBase && SRAMWindow < (SRAMBase+0x800000)) if ((SRAMStatus & (1<<4)) && SRAMWindow >= SRAMBase && SRAMWindow < (SRAMBase+SRAMLength))
{ {
u32 addr = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4]; u32 addr = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4];
// the command is issued 4 times, each with the same address if (addr >= SRAMWindow && addr < (SRAMWindow+0x20000))
// seems they use the one from the first command (CHECKME) {
if (!SRAMAddr) // the command is issued 4 times, each with the same address
SRAMAddr = addr; // seems they use the one from the first command (CHECKME)
if (!SRAMAddr)
SRAMAddr = addr;
}
} }
else else
SRAMAddr = 0; SRAMAddr = 0;
@ -1302,6 +1305,8 @@ int CartRetailNAND::ROMCommandStart(u8* cmd, u8* data, u32 len)
// window is 0x20000 bytes, address is aligned to that boundary // window is 0x20000 bytes, address is aligned to that boundary
// NAND remains stuck 'busy' forever if this is less than the starting SRAM address // NAND remains stuck 'busy' forever if this is less than the starting SRAM address
// TODO. // TODO.
if (addr < SRAMBase) printf("NAND: !! BAD ADDR %08X < %08X\n", addr, SRAMBase);
if (addr >= (SRAMBase+SRAMLength)) printf("NAND: !! BAD ADDR %08X > %08X\n", addr, SRAMBase+SRAMLength);
SRAMWindow = addr; SRAMWindow = addr;
} }