From 25f460eca64d55f980ab57851ffbd9fe58a5793c Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 2 Nov 2023 19:24:40 +0200 Subject: [PATCH] spu: implement some more irq details libretro/pcsx_rearmed#787 --- plugins/dfsound/dma.c | 4 ++-- plugins/dfsound/externals.h | 1 + plugins/dfsound/registers.c | 6 +++--- plugins/dfsound/spu.c | 23 +++++++++++++++++------ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/plugins/dfsound/dma.c b/plugins/dfsound/dma.c index 13f9c269..25a0aefd 100644 --- a/plugins/dfsound/dma.c +++ b/plugins/dfsound/dma.c @@ -52,7 +52,7 @@ void CALLBACK SPUreadDMAMem(unsigned short *pusPSXMem, int iSize, } if ((spu.spuCtrl & CTRL_IRQ) && irq_after < iSize * 2) { log_unhandled("rdma spu irq: %x/%x+%x\n", irq_addr, spu.spuAddr, iSize * 2); - spu.irqCallback(irq_after); + do_irq_io(irq_after); } spu.spuAddr = addr; set_dma_end(iSize, cycles); @@ -91,7 +91,7 @@ void CALLBACK SPUwriteDMAMem(unsigned short *pusPSXMem, int iSize, irq_addr, spu.spuAddr, iSize * 2, irq_after); // this should be consistent with psxdma.c timing // might also need more delay like in set_dma_end() - spu.irqCallback(irq_after); + do_irq_io(irq_after); } spu.spuAddr = addr; set_dma_end(iSize, cycles); diff --git a/plugins/dfsound/externals.h b/plugins/dfsound/externals.h index 4f48c65d..fef5f9cc 100644 --- a/plugins/dfsound/externals.h +++ b/plugins/dfsound/externals.h @@ -279,6 +279,7 @@ extern SPUInfo spu; void do_samples(unsigned int cycles_to, int do_sync); void schedule_next_irq(void); void check_irq_io(unsigned int addr); +void do_irq_io(int cycles_after); #define do_samples_if_needed(c, sync, samples) \ do { \ diff --git a/plugins/dfsound/registers.c b/plugins/dfsound/registers.c index 05968b61..5d79f251 100644 --- a/plugins/dfsound/registers.c +++ b/plugins/dfsound/registers.c @@ -132,7 +132,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, { //-------------------------------------------------// case H_SPUaddr: - spu.spuAddr = (unsigned long) val<<3; + spu.spuAddr = (unsigned int)val << 3; //check_irq_io(spu.spuAddr); break; //-------------------------------------------------// @@ -144,8 +144,8 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, break; //-------------------------------------------------// case H_SPUctrl: + spu.spuStat &= ~STAT_IRQ | val; if (!(spu.spuCtrl & CTRL_IRQ)) { - spu.spuStat&=~STAT_IRQ; if (val & CTRL_IRQ) schedule_next_irq(); } @@ -153,7 +153,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, break; //-------------------------------------------------// case H_SPUstat: - spu.spuStat=val&0xf800; + //spu.spuStat=val&0xf800; break; //-------------------------------------------------// case H_SPUReverbAddr: diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index 502567bd..f2023881 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -198,12 +198,15 @@ static void InterpolateDown(sample_buf *sb, int sinc) #include "gauss_i.h" #include "xa.c" -static void do_irq(void) +static void do_irq(int cycles_after) { - //if(!(spu.spuStat & STAT_IRQ)) + if (spu.spuStat & STAT_IRQ) + log_unhandled("spu: missed irq?\n"); + else { spu.spuStat |= STAT_IRQ; // asserted status? - if(spu.irqCallback) spu.irqCallback(0); + if (spu.irqCallback) + spu.irqCallback(cycles_after); } } @@ -212,7 +215,7 @@ static int check_irq(int ch, unsigned char *pos) if((spu.spuCtrl & (CTRL_ON|CTRL_IRQ)) == (CTRL_ON|CTRL_IRQ) && pos == spu.pSpuIrq) { //printf("ch%d irq %04zx\n", ch, pos - spu.spuMemC); - do_irq(); + do_irq(0); return 1; } return 0; @@ -225,7 +228,15 @@ void check_irq_io(unsigned int addr) if((spu.spuCtrl & (CTRL_ON|CTRL_IRQ)) == (CTRL_ON|CTRL_IRQ) && addr == irq_addr) { //printf("io irq %04x\n", irq_addr); - do_irq(); + do_irq(0); + } +} + +void do_irq_io(int cycles_after) +{ + if ((spu.spuCtrl & (CTRL_ON|CTRL_IRQ)) == (CTRL_ON|CTRL_IRQ)) + { + do_irq(cycles_after); } } @@ -1182,7 +1193,7 @@ void do_samples(unsigned int cycles_to, int do_direct) if (0 < left && left <= ns_to) { //xprintf("decoder irq %x\n", spu.decode_pos); - do_irq(); + do_irq(0); } } if (!spu.cycles_dma_end || (int)(spu.cycles_dma_end - cycles_to) < 0) { -- 2.39.5