Skip to content

Commit

Permalink
spu: implement some more irq details
Browse files Browse the repository at this point in the history
  • Loading branch information
notaz committed Nov 2, 2023
1 parent baad067 commit 5fa5979
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions plugins/dfsound/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions plugins/dfsound/externals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand Down
6 changes: 3 additions & 3 deletions plugins/dfsound/registers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//-------------------------------------------------//
Expand All @@ -144,16 +144,16 @@ 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();
}
spu.spuCtrl=val;
break;
//-------------------------------------------------//
case H_SPUstat:
spu.spuStat=val&0xf800;
//spu.spuStat=val&0xf800;
break;
//-------------------------------------------------//
case H_SPUReverbAddr:
Expand Down
23 changes: 17 additions & 6 deletions plugins/dfsound/spu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5fa5979

Please sign in to comment.