From: notaz Date: Wed, 27 Jul 2011 17:06:46 +0000 (+0300) Subject: spu: simplify irq and flag handling X-Git-Tag: r9~31 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fc2a4c27be8c8cd5f8cf53a0d56c263275b8501;p=pcsx_rearmed.git spu: simplify irq and flag handling shalma's recent work taken into account when working on this. NOT verified on read hardware. --- diff --git a/plugins/dfsound/externals.h b/plugins/dfsound/externals.h index 90e26cec..2ccc811d 100644 --- a/plugins/dfsound/externals.h +++ b/plugins/dfsound/externals.h @@ -222,6 +222,7 @@ extern int bThreadEnded; extern int bSpuInit; extern unsigned int dwNewChannel; extern unsigned int dwChannelOn; +extern unsigned int dwPendingChanOff; extern int SSumR[]; extern int SSumL[]; diff --git a/plugins/dfsound/freeze.c b/plugins/dfsound/freeze.c index cb0d75ec..39694695 100644 --- a/plugins/dfsound/freeze.c +++ b/plugins/dfsound/freeze.c @@ -172,9 +172,9 @@ static void load_channel(SPUCHAN *d, SPUCHAN_orig *s, int ch) d->spos = s->spos; d->sinc = s->sinc; memcpy(d->SB, s->SB, sizeof(d->SB)); - d->pStart = s->pStart; - d->pCurr = s->pCurr; - d->pLoop = s->pLoop; + d->pStart = (void *)((long)s->pStart & 0x7fff0); + d->pCurr = (void *)((long)s->pCurr & 0x7fff0); + d->pLoop = (void *)((long)s->pLoop & 0x7fff0); if (s->bOn) dwChannelOn |= 1<bStop = s->bStop; d->bReverb = s->bReverb; @@ -247,6 +247,9 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode,SPUFreeze_t * pF) pFO->spuAddr=spuAddr; if(pFO->spuAddr==0) pFO->spuAddr=0xbaadf00d; + dwChannelOn&=~dwPendingChanOff; + dwPendingChanOff=0; + for(i=0;is_chan[i],&s_chan[i],i); @@ -275,6 +278,7 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode,SPUFreeze_t * pF) SPUplayADPCMchannel(&pF->xaS); xapGlobal=0; + dwPendingChanOff=0; if(!strcmp(pF->szSPUName,"PBOSS") && pF->ulFreezeVersion==5) LoadStateV5(pF); @@ -311,7 +315,7 @@ void LoadStateV5(SPUFreeze_t * pF) pFO=(SPUOSSFreeze_t *)(pF+1); spuIrq = pFO->spuIrq; - if(pFO->pSpuIrq) pSpuIrq = pFO->pSpuIrq+spuMemC; else pSpuIrq=NULL; + if(pFO->pSpuIrq) pSpuIrq = spuMemC+((long)pFO->pSpuIrq&0x7fff0); else pSpuIrq=NULL; if(pFO->spuAddr) { diff --git a/plugins/dfsound/registers.c b/plugins/dfsound/registers.c index c36c27ea..ac495d63 100644 --- a/plugins/dfsound/registers.c +++ b/plugins/dfsound/registers.c @@ -191,6 +191,8 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) break; //-------------------------------------------------// case H_SPUctrl: + if(!(spuCtrl & CTRL_IRQ)) + spuStat&=~STAT_IRQ; spuCtrl=val; break; //-------------------------------------------------// @@ -214,7 +216,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) //-------------------------------------------------// case H_SPUirqAddr: spuIrq = val; - pSpuIrq=spuMemC+((unsigned long) val<<3); + pSpuIrq=spuMemC+(((unsigned long) val<<3)&~0xf); break; //-------------------------------------------------// case H_SPUrvolL: diff --git a/plugins/dfsound/registers.h b/plugins/dfsound/registers.h index f2a93970..204a669c 100644 --- a/plugins/dfsound/registers.h +++ b/plugins/dfsound/registers.h @@ -142,3 +142,11 @@ #define H_SPU_ADSRLevel22 0x0d68 #define H_SPU_ADSRLevel23 0x0d78 +#define CTRL_IRQ 0x40 +#define CTRL_REVERB 0x80 +#define CTRL_NOISE 0x3f00 +#define CTRL_MUTE 0x4000 +#define CTRL_ON 0x8000 + +#define STAT_IRQ 0x40 + diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index e289b861..f9c13d4b 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -20,6 +20,7 @@ #define _IN_SPU #include "externals.h" +#include "registers.h" #include "cfg.h" #include "dsoundoss.h" #include "regs.h" @@ -95,6 +96,7 @@ static pthread_t thread = (pthread_t)-1; // thread id (linux) unsigned long dwNewChannel=0; // flags for faster testing, if new channel starts unsigned long dwChannelOn=0; +unsigned long dwPendingChanOff=0; void (CALLBACK *irqCallback)(void)=0; // func of main emu, called on spu irq void (CALLBACK *cddavCallback)(unsigned short,unsigned short)=0; @@ -423,6 +425,15 @@ INLINE int iGetInterpolationVal(int ch) return fa; } +static void do_irq(void) +{ + if(!(spuStat & STAT_IRQ)) + { + spuStat |= STAT_IRQ; + if(irqCallback) irqCallback(); + } +} + static int decode_block(int ch) { unsigned char *start; @@ -434,15 +445,26 @@ static int decode_block(int ch) s_chan[ch].iSBPos=0; start=s_chan[ch].pCurr; // set up the current pos - if (start == (unsigned char*)-1) // special "stop" sign + if(start == (unsigned char*)-1 || // special "stop" sign + (dwPendingChanOff&(1< turn everything off + dwPendingChanOff&=~(1< and done for this channel } - //////////////////////////////////////////// spu irq handler here? mmm... do it later + //////////////////////////////////////////// irq check + + if(spuCtrl&CTRL_IRQ) + { + if(pSpuIrq == start) // irq address reached? + { + do_irq(); // -> call main emu + ret = 1; + } + } s_1=s_chan[ch].s_1; s_2=s_chan[ch].s_2; @@ -475,21 +497,6 @@ static int decode_block(int ch) s_chan[ch].SB[nSample++]=fa; } - //////////////////////////////////////////// irq check - - if(irqCallback && (spuCtrl&0x40)) // some callback and irq active? - { - if((pSpuIrq > start-16 && // irq address reached? - pSpuIrq <= start) || - ((flags&1) && // special: irq on looping addr, when stop/loop flag is set - (pSpuIrq > s_chan[ch].pLoop-16 && - pSpuIrq <= s_chan[ch].pLoop))) - { - irqCallback(); // -> call main emu - ret = 1; - } - } - //////////////////////////////////////////// flag handler if((flags&4) && (!s_chan[ch].bIgnoreLoop)) @@ -497,16 +504,10 @@ static int decode_block(int ch) if(flags&1) // 1: stop/loop { - // We play this block out first... - //if(!(flags&2)) // 1+2: do loop... otherwise: stop - if(flags!=3 && flags!=7) // PETE: if we don't check exactly for 3, loop hang ups will happen (DQ4, for example) - { - start = (unsigned char*)-1; - } - else - { - start = s_chan[ch].pLoop; - } + if(!(flags&2)) + dwPendingChanOff|=1<= 0x80000) @@ -720,7 +721,7 @@ ENDX: ; // an IRQ. Only problem: the "wait for cpu" option is kinda hard to do here // in some of Peops timer modes. So: we ignore this option here (for now). - if(pMixIrq && irqCallback) + if(pMixIrq) { for(ns=0;ns=pMixIrq+(ch*0x400) && pSpuIrqspuMemC+0x3ff) pMixIrq=spuMemC;