X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fdfsound%2Fregisters.c;h=bc99d9ac8a4a2491e4d5d2124ad0a83fbd4fe4e4;hp=669c70f736004cc781b81760a4e436010669121b;hb=9ad8abfa940cd5c13eb0653639ea86736b65a2c4;hpb=be1cb678c445cb8d9a4d707c698f0dc600a490ea diff --git a/plugins/dfsound/registers.c b/plugins/dfsound/registers.c index 669c70f7..bc99d9ac 100644 --- a/plugins/dfsound/registers.c +++ b/plugins/dfsound/registers.c @@ -21,24 +21,7 @@ #include "externals.h" #include "registers.h" - -/* -// adsr time values (in ms) by James Higgs ... see the end of -// the adsr.c source for details - -#define ATTACK_MS 514L -#define DECAYHALF_MS 292L -#define DECAY_MS 584L -#define SUSTAIN_MS 450L -#define RELEASE_MS 446L -*/ - -// we have a timebase of 1.020408f ms, not 1 ms... so adjust adsr defines -#define ATTACK_MS 494L -#define DECAYHALF_MS 286L -#define DECAY_MS 572L -#define SUSTAIN_MS 441L -#define RELEASE_MS 437L +#include "spu_config.h" static void SoundOn(int start,int end,unsigned short val); static void SoundOff(int start,int end,unsigned short val); @@ -53,10 +36,28 @@ static void ReverbOn(int start,int end,unsigned short val); // WRITE REGISTERS: called by main emu //////////////////////////////////////////////////////////////////////// -void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) +static const uint32_t ignore_dupe[8] = { + // ch 0-15 c40 c80 cc0 + 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, + // ch 16-24 d40 control reverb + 0x7f7f7f7f, 0x7f7f7f7f, 0xff05ff0f, 0xffffffff +}; + +void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, + unsigned int cycles) { - const unsigned long r=reg&0xfff; - regArea[(r-0xc00)>>1] = val; + int r = reg & 0xfff; + int rofs = (r - 0xc00) >> 1; + int changed = spu.regArea[rofs] != val; + spu.regArea[rofs] = val; + + if (!changed && (ignore_dupe[rofs >> 5] & (1 << (rofs & 0x1f)))) + return; + // zero keyon/keyoff? + if (val == 0 && (r & 0xff8) == 0xd88) + return; + + do_samples_if_needed(cycles); if(r>=0x0c00 && r<0x0d80) // some channel info? { @@ -74,7 +75,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) //------------------------------------------------// pitch case 4: SetPitch(ch,val); - break; + goto upd_irq; //------------------------------------------------// start case 6: // taken from regArea later @@ -89,35 +90,6 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f; s_chan[ch].ADSRX.SustainLevel=lval & 0x000f; //---------------------------------------------// -#if 0 - if(!iDebugMode) break; - //---------------------------------------------// stuff below is only for debug mode - - s_chan[ch].ADSR.AttackModeExp=(lval&0x8000)?1:0; //0x007f - - lx=(((lval>>8) & 0x007f)>>2); // attack time to run from 0 to 100% volume - lx=min(31,lx); // no overflow on shift! - if(lx) - { - lx = (1<>4) & 0x000f; // decay: - if(lx) // our const decay value is time it takes from 100% to 0% of volume - { - lx = ((1<<(lx))*DECAY_MS)/10000L; - if(!lx) lx=1; - } - s_chan[ch].ADSR.DecayTime = // so calc how long does it take to run from 100% to the wanted sus level - (lx*(1024-s_chan[ch].ADSR.SustainLevel))/1024; -#endif } break; //------------------------------------------------// adsr times with pre-calcs @@ -132,39 +104,6 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0; s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f; //----------------------------------------------// -#if 0 - if(!iDebugMode) break; - //----------------------------------------------// stuff below is only for debug mode - - s_chan[ch].ADSR.SustainModeExp = (lval&0x8000)?1:0; - s_chan[ch].ADSR.ReleaseModeExp = (lval&0x0020)?1:0; - - lx=((((lval>>6) & 0x007f)>>2)); // sustain time... often very high - lx=min(31,lx); // values are used to hold the volume - if(lx) // until a sound stop occurs - { // the highest value we reach (due to - lx = (1<>1] = val; - spuAddr+=2; - if(spuAddr>0x7ffff) spuAddr=0; + spu.spuMem[spu.spuAddr>>1] = val; + spu.spuAddr+=2; + if(spu.spuAddr>0x7ffff) spu.spuAddr=0; break; //-------------------------------------------------// case H_SPUctrl: - if(!(spuCtrl & CTRL_IRQ)) - spuStat&=~STAT_IRQ; - spuCtrl=val; + if (!(spu.spuCtrl & CTRL_IRQ)) { + spu.spuStat&=~STAT_IRQ; + if (val & CTRL_IRQ) + schedule_next_irq(); + } + spu.spuCtrl=val; break; //-------------------------------------------------// case H_SPUstat: - spuStat=val & 0xf800; + spu.spuStat=val&0xf800; break; //-------------------------------------------------// case H_SPUReverbAddr: @@ -219,13 +156,11 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) rvb.CurrAddr=rvb.StartAddr; } } - rvb.dirty = 1; - break; + goto rvbd; //-------------------------------------------------// case H_SPUirqAddr: - spuIrq = val; - pSpuIrq=spuMemC+(((unsigned long) val<<3)&~0xf); - break; + spu.pSpuIrq=spu.spuMemC+(((unsigned long) val<<3)&~0xf); + goto upd_irq; //-------------------------------------------------// case H_SPUrvolL: rvb.VolLeft=val; @@ -279,12 +214,12 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) break; //-------------------------------------------------// case H_CDLeft: - iLeftXAVol=val & 0x7fff; - if(cddavCallback) cddavCallback(0,val); + spu.iLeftXAVol=val & 0x7fff; + if(spu.cddavCallback) spu.cddavCallback(0,val); break; case H_CDRight: - iRightXAVol=val & 0x7fff; - if(cddavCallback) cddavCallback(1,val); + spu.iRightXAVol=val & 0x7fff; + if(spu.cddavCallback) spu.cddavCallback(1,val); break; //-------------------------------------------------// case H_FMod1: @@ -311,44 +246,48 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) ReverbOn(16,24,val); break; //-------------------------------------------------// - case H_Reverb+0 : rvb.FB_SRC_A=val*4; break; - case H_Reverb+2 : rvb.FB_SRC_B=val*4; break; - case H_Reverb+4 : rvb.IIR_ALPHA=(short)val; break; - case H_Reverb+6 : rvb.ACC_COEF_A=(short)val; break; - case H_Reverb+8 : rvb.ACC_COEF_B=(short)val; break; - case H_Reverb+10 : rvb.ACC_COEF_C=(short)val; break; - case H_Reverb+12 : rvb.ACC_COEF_D=(short)val; break; - case H_Reverb+14 : rvb.IIR_COEF=(short)val; break; - case H_Reverb+16 : rvb.FB_ALPHA=(short)val; break; - case H_Reverb+18 : rvb.FB_X=(short)val; break; - case H_Reverb+20 : rvb.IIR_DEST_A0=val*4; break; - case H_Reverb+22 : rvb.IIR_DEST_A1=val*4; break; - case H_Reverb+24 : rvb.ACC_SRC_A0=val*4; break; - case H_Reverb+26 : rvb.ACC_SRC_A1=val*4; break; - case H_Reverb+28 : rvb.ACC_SRC_B0=val*4; break; - case H_Reverb+30 : rvb.ACC_SRC_B1=val*4; break; - case H_Reverb+32 : rvb.IIR_SRC_A0=val*4; break; - case H_Reverb+34 : rvb.IIR_SRC_A1=val*4; break; - case H_Reverb+36 : rvb.IIR_DEST_B0=val*4; break; - case H_Reverb+38 : rvb.IIR_DEST_B1=val*4; break; - case H_Reverb+40 : rvb.ACC_SRC_C0=val*4; break; - case H_Reverb+42 : rvb.ACC_SRC_C1=val*4; break; - case H_Reverb+44 : rvb.ACC_SRC_D0=val*4; break; - case H_Reverb+46 : rvb.ACC_SRC_D1=val*4; break; - case H_Reverb+48 : rvb.IIR_SRC_B1=val*4; break; - case H_Reverb+50 : rvb.IIR_SRC_B0=val*4; break; - case H_Reverb+52 : rvb.MIX_DEST_A0=val*4; break; - case H_Reverb+54 : rvb.MIX_DEST_A1=val*4; break; - case H_Reverb+56 : rvb.MIX_DEST_B0=val*4; break; - case H_Reverb+58 : rvb.MIX_DEST_B1=val*4; break; - case H_Reverb+60 : rvb.IN_COEF_L=(short)val; break; - case H_Reverb+62 : rvb.IN_COEF_R=(short)val; break; + case H_Reverb+0 : rvb.FB_SRC_A=val*4; goto rvbd; + case H_Reverb+2 : rvb.FB_SRC_B=val*4; goto rvbd; + case H_Reverb+4 : rvb.IIR_ALPHA=(short)val; goto rvbd; + case H_Reverb+6 : rvb.ACC_COEF_A=(short)val; goto rvbd; + case H_Reverb+8 : rvb.ACC_COEF_B=(short)val; goto rvbd; + case H_Reverb+10 : rvb.ACC_COEF_C=(short)val; goto rvbd; + case H_Reverb+12 : rvb.ACC_COEF_D=(short)val; goto rvbd; + case H_Reverb+14 : rvb.IIR_COEF=(short)val; goto rvbd; + case H_Reverb+16 : rvb.FB_ALPHA=(short)val; goto rvbd; + case H_Reverb+18 : rvb.FB_X=(short)val; goto rvbd; + case H_Reverb+20 : rvb.IIR_DEST_A0=val*4; goto rvbd; + case H_Reverb+22 : rvb.IIR_DEST_A1=val*4; goto rvbd; + case H_Reverb+24 : rvb.ACC_SRC_A0=val*4; goto rvbd; + case H_Reverb+26 : rvb.ACC_SRC_A1=val*4; goto rvbd; + case H_Reverb+28 : rvb.ACC_SRC_B0=val*4; goto rvbd; + case H_Reverb+30 : rvb.ACC_SRC_B1=val*4; goto rvbd; + case H_Reverb+32 : rvb.IIR_SRC_A0=val*4; goto rvbd; + case H_Reverb+34 : rvb.IIR_SRC_A1=val*4; goto rvbd; + case H_Reverb+36 : rvb.IIR_DEST_B0=val*4; goto rvbd; + case H_Reverb+38 : rvb.IIR_DEST_B1=val*4; goto rvbd; + case H_Reverb+40 : rvb.ACC_SRC_C0=val*4; goto rvbd; + case H_Reverb+42 : rvb.ACC_SRC_C1=val*4; goto rvbd; + case H_Reverb+44 : rvb.ACC_SRC_D0=val*4; goto rvbd; + case H_Reverb+46 : rvb.ACC_SRC_D1=val*4; goto rvbd; + case H_Reverb+48 : rvb.IIR_SRC_B1=val*4; goto rvbd; + case H_Reverb+50 : rvb.IIR_SRC_B0=val*4; goto rvbd; + case H_Reverb+52 : rvb.MIX_DEST_A0=val*4; goto rvbd; + case H_Reverb+54 : rvb.MIX_DEST_A1=val*4; goto rvbd; + case H_Reverb+56 : rvb.MIX_DEST_B0=val*4; goto rvbd; + case H_Reverb+58 : rvb.MIX_DEST_B1=val*4; goto rvbd; + case H_Reverb+60 : rvb.IN_COEF_L=(short)val; goto rvbd; + case H_Reverb+62 : rvb.IN_COEF_R=(short)val; goto rvbd; } + return; - if ((r & ~0x3f) == H_Reverb) - rvb.dirty = 1; // recalculate on next update +upd_irq: + if (spu.spuCtrl & CTRL_IRQ) + schedule_next_irq(); + return; - iSpuAsyncWait=0; +rvbd: + rvb.dirty = 1; // recalculate on next update } //////////////////////////////////////////////////////////////////////// @@ -359,8 +298,6 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) { const unsigned long r=reg&0xfff; - iSpuAsyncWait=0; - if(r>=0x0c00 && r<0x0d80) { switch(r&0x0f) @@ -368,8 +305,8 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) case 12: // get adsr vol { const int ch=(r>>4)-0xc0; - if(dwNewChannel&(1<>16); @@ -378,7 +315,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) case 14: // get loop address { const int ch=(r>>4)-0xc0; - return (unsigned short)((s_chan[ch].pLoop-spuMemC)>>3); + return (unsigned short)((s_chan[ch].pLoop-spu.spuMemC)>>3); } } } @@ -386,25 +323,22 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) switch(r) { case H_SPUctrl: - return spuCtrl; + return spu.spuCtrl; case H_SPUstat: - return spuStat; + return spu.spuStat; case H_SPUaddr: - return (unsigned short)(spuAddr>>3); + return (unsigned short)(spu.spuAddr>>3); case H_SPUdata: { - unsigned short s=spuMem[spuAddr>>1]; - spuAddr+=2; - if(spuAddr>0x7ffff) spuAddr=0; + unsigned short s=spu.spuMem[spu.spuAddr>>1]; + spu.spuAddr+=2; + if(spu.spuAddr>0x7ffff) spu.spuAddr=0; return s; } - case H_SPUirqAddr: - return spuIrq; - //case H_SPUIsOn1: // return IsSoundOn(0,16); @@ -413,7 +347,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) } - return regArea[(r-0xc00)>>1]; + return spu.regArea[(r-0xc00)>>1]; } //////////////////////////////////////////////////////////////////////// @@ -428,16 +362,9 @@ static void SoundOn(int start,int end,unsigned short val) { if((val&1) && regAreaGet(ch,6)) // mmm... start has to be set before key on !?! { - // do this here, not in StartSound - // - fixes fussy timing issues - s_chan[ch].bStop=0; - s_chan[ch].pCurr=spuMemC+((regAreaGet(ch,6)&~1)<<3); // must be block aligned - s_chan[ch].pLoop=spuMemC+((regAreaGet(ch,14)&~1)<<3); - s_chan[ch].bJump=0; - - dwNewChannel|=(1<>=1) // loop channels { - if(val&1) // && s_chan[i].bOn) mmm... + if(val&1) { - s_chan[ch].bStop=1; + s_chan[ch].ADSRX.State = ADSR_RELEASE; // Jungle Book - Rhythm 'n Groove // - turns off buzzing sound (loop hangs) - dwNewChannel &= ~(1< freq change in simple interpolation mode: set flag + s_chan[ch].sinc_inv=0; + if(spu_config.iUseInterpolation==1) s_chan[ch].SB[32]=1; // -> freq change in simple interpolation mode: set flag } ////////////////////////////////////////////////////////////////////////