dmac: wrap source address to remain in 16K

Add some assertions of memcpy that overflow (need to be wrapped)
This commit is contained in:
Gregory Hainaut 2016-01-27 22:37:17 +01:00
parent c959424957
commit 5d1e5df205
2 changed files with 32 additions and 22 deletions

View File

@ -87,6 +87,7 @@ int _SPR0chain()
spr0ch.madr += partialqwc << 4;
spr0ch.madr = dmacRegs.rbor.ADDR + (spr0ch.madr & dmacRegs.rbsr.RMSK);
spr0ch.sadr += partialqwc << 4;
spr0ch.sadr &= 0x3FFF; // Limited to 16K
spr0ch.qwc -= partialqwc;
spr0finished = true;
@ -97,6 +98,7 @@ int _SPR0chain()
//Taking an arbitary small value for games which like to check the QWC/MADR instead of STR, so get most of
//the cycle delay out of the way before the end.
partialqwc = spr0ch.qwc;
pxAssertMsg((spr0ch.sadr + partialqwc*16) < 0x4000, "TODO: Copy must be wrapped");
memcpy(pMem, &psSu128(spr0ch.sadr), partialqwc*16);
// clear VU mem also!
@ -104,6 +106,7 @@ int _SPR0chain()
spr0ch.madr += partialqwc << 4;
spr0ch.sadr += partialqwc << 4;
spr0ch.sadr &= 0x3FFF; // Limited to 16K
spr0ch.qwc -= partialqwc;
}
@ -151,10 +154,12 @@ void _SPR0interleave()
case MFD_RESERVED:
// clear VU mem also!
TestClearVUs(spr0ch.madr, spr0ch.qwc, true);
pxAssertMsg((spr0ch.sadr + spr0ch.qwc*16) < 0x4000, "TODO: Copy must be wrapped");
memcpy(pMem, &psSu128(spr0ch.sadr), spr0ch.qwc*16);
break;
}
spr0ch.sadr += spr0ch.qwc * 16;
spr0ch.sadr &= 0x3FFF; // Limited to 16K
spr0ch.madr += (sqwc + spr0ch.qwc) * 16;
}
@ -194,6 +199,7 @@ static __fi void _dmaSPR0()
// Destination Chain Mode
ptag = (tDMA_TAG*)&psSu32(spr0ch.sadr);
spr0ch.sadr += 16;
spr0ch.sadr &= 0x3FFF; // Limited to 16K
spr0ch.unsafeTransfer(ptag);
@ -322,8 +328,10 @@ __fi static void SPR1transfer(const void* data, int qwc)
TestClearVUs(spr1ch.madr, spr1ch.qwc, false);
}
pxAssertMsg((spr1ch.sadr + qwc*16) < 0x4000, "TODO: Copy must be wrapped");
memcpy(&psSu128(spr1ch.sadr), data, qwc*16);
spr1ch.sadr += qwc * 16;
spr1ch.sadr &= 0x3FFF; // Limited to 16K
}
@ -381,8 +389,10 @@ void _SPR1interleave()
spr1ch.qwc = std::min(tqwc, qwc);
qwc -= spr1ch.qwc;
pMem = SPRdmaGetAddr(spr1ch.madr, false);
pxAssertMsg((spr1ch.sadr + spr1ch.qwc*16) < 0x4000, "TODO: Copy must be wrapped");
memcpy(&psSu128(spr1ch.sadr), pMem, spr1ch.qwc*16);
spr1ch.sadr += spr1ch.qwc * 16;
spr1ch.sadr &= 0x3FFF; // Limited to 16K
spr1ch.madr += (sqwc + spr1ch.qwc) * 16;
}