X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=plugins%2Fdfsound%2Fdma.c;h=fde1f835b54bbf60e0a4e7329ff9e3e68614e3c6;hb=HEAD;hp=eb85a7316d31b8eb55c0e3b272aa4e32c263a5f3;hpb=88b0dc1df1a0e7b6ec0a505bcb0c19061f8dab6e;p=pcsx_rearmed.git diff --git a/plugins/dfsound/dma.c b/plugins/dfsound/dma.c index eb85a731..fde1f835 100644 --- a/plugins/dfsound/dma.c +++ b/plugins/dfsound/dma.c @@ -22,18 +22,13 @@ #include "externals.h" #include "registers.h" -//////////////////////////////////////////////////////////////////////// -// READ DMA (one value) -//////////////////////////////////////////////////////////////////////// - -unsigned short CALLBACK SPUreadDMA(void) +static void set_dma_end(int iSize, unsigned int cycles) { - unsigned short s = *(unsigned short *)(spu.spuMemC + spu.spuAddr); - check_irq_io(spu.spuAddr); - spu.spuAddr += 2; - spu.spuAddr &= 0x7fffe; - - return s; + // this must be > psxdma.c dma irq + // Road Rash also wants a considerable delay, maybe because of fifo? + cycles += iSize * 20; // maybe + cycles |= 1; // indicates dma is active + spu.cycles_dma_end = cycles; } //////////////////////////////////////////////////////////////////////// @@ -44,10 +39,10 @@ void CALLBACK SPUreadDMAMem(unsigned short *pusPSXMem, int iSize, unsigned int cycles) { unsigned int addr = spu.spuAddr, irq_addr = regAreaGet(H_SPUirqAddr) << 3; - int i, irq; + int i, irq_after; - do_samples_if_needed(cycles, 1); - irq = addr <= irq_addr && irq_addr < addr + iSize*2; + do_samples_if_needed(cycles, 1, 2); + irq_after = (irq_addr - addr) & 0x7ffff; for(i = 0; i < iSize; i++) { @@ -55,27 +50,12 @@ void CALLBACK SPUreadDMAMem(unsigned short *pusPSXMem, int iSize, addr += 2; addr &= 0x7fffe; } - if (irq && (spu.spuCtrl & CTRL_IRQ)) - log_unhandled("rdma spu irq: %x/%x+%x\n", irq_addr, spu.spuAddr, iSize * 2); + if ((spu.spuCtrl & CTRL_IRQ) && irq_after < iSize * 2) { + log_unhandled("rdma spu irq: %x/%x-%x\n", irq_addr, spu.spuAddr, addr); + do_irq_io(irq_after); + } spu.spuAddr = addr; -} - -//////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -// WRITE DMA (one value) -//////////////////////////////////////////////////////////////////////// - -void CALLBACK SPUwriteDMA(unsigned short val) -{ - *(unsigned short *)(spu.spuMemC + spu.spuAddr) = val; - - check_irq_io(spu.spuAddr); - spu.spuAddr += 2; - spu.spuAddr &= 0x7fffe; - spu.bMemDirty = 1; + set_dma_end(iSize, cycles); } //////////////////////////////////////////////////////////////////////// @@ -86,11 +66,11 @@ void CALLBACK SPUwriteDMAMem(unsigned short *pusPSXMem, int iSize, unsigned int cycles) { unsigned int addr = spu.spuAddr, irq_addr = regAreaGet(H_SPUirqAddr) << 3; - int i, irq; + int i, irq_after; - do_samples_if_needed(cycles, 1); + do_samples_if_needed(cycles + iSize*2 * 4, 1, 2); + irq_after = (irq_addr - addr) & 0x7ffff; spu.bMemDirty = 1; - irq = addr <= irq_addr && irq_addr < addr + iSize*2; if (addr + iSize*2 < 0x80000) { @@ -99,7 +79,6 @@ void CALLBACK SPUwriteDMAMem(unsigned short *pusPSXMem, int iSize, } else { - irq |= irq_addr < ((addr + iSize*2) & 0x7ffff); for (i = 0; i < iSize; i++) { *(unsigned short *)(spu.spuMemC + addr) = *pusPSXMem++; @@ -107,9 +86,33 @@ void CALLBACK SPUwriteDMAMem(unsigned short *pusPSXMem, int iSize, addr &= 0x7fffe; } } - if (irq && (spu.spuCtrl & CTRL_IRQ)) // unhandled because need to implement delay - log_unhandled("wdma spu irq: %x/%x+%x\n", irq_addr, spu.spuAddr, iSize * 2); + if ((spu.spuCtrl & CTRL_IRQ) && irq_after < iSize * 2) { + 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 * 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); } //////////////////////////////////////////////////////////////////////// +// vim:shiftwidth=1:expandtab