mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 15:19:53 -06:00
don't hardcode numbers you derp
also add some extra safety
This commit is contained in:
@ -1231,15 +1231,18 @@ 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];
|
||||||
|
|
||||||
|
if (addr >= SRAMWindow && addr < (SRAMWindow+0x20000))
|
||||||
|
{
|
||||||
// the command is issued 4 times, each with the same address
|
// the command is issued 4 times, each with the same address
|
||||||
// seems they use the one from the first command (CHECKME)
|
// seems they use the one from the first command (CHECKME)
|
||||||
if (!SRAMAddr)
|
if (!SRAMAddr)
|
||||||
SRAMAddr = addr;
|
SRAMAddr = addr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
SRAMAddr = 0;
|
SRAMAddr = 0;
|
||||||
return 1;
|
return 1;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user