From: notaz Date: Sun, 19 Nov 2023 21:45:55 +0000 (+0200) Subject: spu: adjust dma timing + a hack X-Git-Tag: r24~51 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f926a62f27a3a513b8a4594728a8d6ace65920a3;p=pcsx_rearmed.git spu: adjust dma timing + a hack libretro/pcsx_rearmed#799 --- diff --git a/libpcsxcore/psxdma.c b/libpcsxcore/psxdma.c index fa8f3394..e3655b5e 100644 --- a/libpcsxcore/psxdma.c +++ b/libpcsxcore/psxdma.c @@ -67,7 +67,7 @@ void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU // This should be much slower, like 12+ cycles/byte, it's like // that because the CPU runs too fast and fifo is not emulated. // See also set_dma_end(). - set_event(PSXINT_SPUDMA, words * 4); + set_event(PSXINT_SPUDMA, words * 4 * 4); return; case 0x01000200: //spu to cpu transfer @@ -78,7 +78,7 @@ void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU psxCpu->Clear(madr, words_copy); HW_DMA4_MADR = SWAPu32(madr + words_copy * 4); - set_event(PSXINT_SPUDMA, words * 4); + set_event(PSXINT_SPUDMA, words * 4 * 4); return; default: diff --git a/plugins/dfsound/dma.c b/plugins/dfsound/dma.c index 25a0aefd..fde1f835 100644 --- a/plugins/dfsound/dma.c +++ b/plugins/dfsound/dma.c @@ -51,7 +51,7 @@ void CALLBACK SPUreadDMAMem(unsigned short *pusPSXMem, int iSize, addr &= 0x7fffe; } if ((spu.spuCtrl & CTRL_IRQ) && irq_after < iSize * 2) { - log_unhandled("rdma spu irq: %x/%x+%x\n", irq_addr, spu.spuAddr, iSize * 2); + log_unhandled("rdma spu irq: %x/%x-%x\n", irq_addr, spu.spuAddr, addr); do_irq_io(irq_after); } spu.spuAddr = addr; @@ -68,7 +68,7 @@ void CALLBACK SPUwriteDMAMem(unsigned short *pusPSXMem, int iSize, unsigned int addr = spu.spuAddr, irq_addr = regAreaGet(H_SPUirqAddr) << 3; int i, irq_after; - do_samples_if_needed(cycles, 1, 2); + do_samples_if_needed(cycles + iSize*2 * 4, 1, 2); irq_after = (irq_addr - addr) & 0x7ffff; spu.bMemDirty = 1; @@ -87,11 +87,28 @@ void CALLBACK SPUwriteDMAMem(unsigned short *pusPSXMem, int iSize, } } if ((spu.spuCtrl & CTRL_IRQ) && irq_after < iSize * 2) { - log_unhandled("wdma spu irq: %x/%x+%x (%u)\n", - irq_addr, spu.spuAddr, iSize * 2, irq_after); + log_unhandled("%u wdma spu irq: %x/%x-%x (%u)\n", + cycles, irq_addr, spu.spuAddr, addr, irq_after); // this should be consistent with psxdma.c timing // might also need more delay like in set_dma_end() - do_irq_io(irq_after); + do_irq_io(irq_after * 4); + } + for (i = 0; i < 24; i++) { + size_t ediff, p = spu.s_chan[i].pCurr - spu.spuMemC; + if (spu.s_chan[i].ADSRX.State == ADSR_RELEASE && !spu.s_chan[i].ADSRX.EnvelopeVol) + continue; + ediff = addr - p; + if (spu.spuAddr < p && p < spu.spuAddr + iSize * 2) { + log_unhandled("%u spu ch%02d play %zx dma %x-%x (%zd)\n", + cycles, i, p, spu.spuAddr, addr, ediff); + //exit(1); + } + // a hack for the super annoying timing issues in The Emperor's New Groove + // (which is a game bug, but tends to trigger more here) + if (ediff <= 0x20u) { + spu.s_chan[i].pCurr += ediff; + break; + } } spu.spuAddr = addr; set_dma_end(iSize, cycles);