#include "externals.h"\r
#include "registers.h"\r
\r
-/*\r
-// adsr time values (in ms) by James Higgs ... see the end of\r
-// the adsr.c source for details\r
-\r
-#define ATTACK_MS 514L\r
-#define DECAYHALF_MS 292L\r
-#define DECAY_MS 584L\r
-#define SUSTAIN_MS 450L\r
-#define RELEASE_MS 446L\r
-*/\r
-\r
-// we have a timebase of 1.020408f ms, not 1 ms... so adjust adsr defines\r
-#define ATTACK_MS 494L\r
-#define DECAYHALF_MS 286L\r
-#define DECAY_MS 572L\r
-#define SUSTAIN_MS 441L\r
-#define RELEASE_MS 437L\r
-\r
static void SoundOn(int start,int end,unsigned short val);\r
static void SoundOff(int start,int end,unsigned short val);\r
static void FModOn(int start,int end,unsigned short val);\r
// WRITE REGISTERS: called by main emu\r
////////////////////////////////////////////////////////////////////////\r
\r
-void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val)\r
+static const uint32_t ignore_dupe[8] = {\r
+ // ch 0-15 c40 c80 cc0\r
+ 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f,\r
+ // ch 16-24 d40 control reverb\r
+ 0x7f7f7f7f, 0x7f7f7f7f, 0xff05ff0f, 0xffffffff\r
+};\r
+\r
+void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,\r
+ unsigned int cycles)\r
{\r
- const unsigned long r=reg&0xfff;\r
- regArea[(r-0xc00)>>1] = val;\r
+ int r = reg & 0xfff;\r
+ int rofs = (r - 0xc00) >> 1;\r
+ int changed = regArea[rofs] != val;\r
+ regArea[rofs] = val;\r
+\r
+ if (!changed && (ignore_dupe[rofs >> 5] & (1 << (rofs & 0x1f))))\r
+ return;\r
+ // zero keyon/keyoff?\r
+ if (val == 0 && (r & 0xff8) == 0xd88)\r
+ return;\r
+\r
+ do_samples_if_needed(cycles);\r
\r
if(r>=0x0c00 && r<0x0d80) // some channel info?\r
{\r
//------------------------------------------------// pitch\r
case 4: \r
SetPitch(ch,val);\r
- break;\r
+ goto upd_irq;\r
//------------------------------------------------// start\r
case 6: \r
// taken from regArea later\r
s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f;\r
s_chan[ch].ADSRX.SustainLevel=lval & 0x000f;\r
//---------------------------------------------//\r
-#if 0\r
- if(!iDebugMode) break;\r
- //---------------------------------------------// stuff below is only for debug mode\r
-\r
- s_chan[ch].ADSR.AttackModeExp=(lval&0x8000)?1:0; //0x007f\r
-\r
- lx=(((lval>>8) & 0x007f)>>2); // attack time to run from 0 to 100% volume\r
- lx=min(31,lx); // no overflow on shift!\r
- if(lx) \r
- { \r
- lx = (1<<lx);\r
- if(lx<2147483) lx=(lx*ATTACK_MS)/10000L; // another overflow check\r
- else lx=(lx/10000L)*ATTACK_MS;\r
- if(!lx) lx=1;\r
- }\r
- s_chan[ch].ADSR.AttackTime=lx; \r
-\r
- s_chan[ch].ADSR.SustainLevel= // our adsr vol runs from 0 to 1024, so scale the sustain level\r
- (1024*((lval) & 0x000f))/15;\r
-\r
- lx=(lval>>4) & 0x000f; // decay:\r
- if(lx) // our const decay value is time it takes from 100% to 0% of volume\r
- {\r
- lx = ((1<<(lx))*DECAY_MS)/10000L;\r
- if(!lx) lx=1;\r
- }\r
- s_chan[ch].ADSR.DecayTime = // so calc how long does it take to run from 100% to the wanted sus level\r
- (lx*(1024-s_chan[ch].ADSR.SustainLevel))/1024;\r
-#endif\r
}\r
break;\r
//------------------------------------------------// adsr times with pre-calcs\r
s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0;\r
s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f;\r
//----------------------------------------------//\r
-#if 0\r
- if(!iDebugMode) break;\r
- //----------------------------------------------// stuff below is only for debug mode\r
-\r
- s_chan[ch].ADSR.SustainModeExp = (lval&0x8000)?1:0;\r
- s_chan[ch].ADSR.ReleaseModeExp = (lval&0x0020)?1:0;\r
- \r
- lx=((((lval>>6) & 0x007f)>>2)); // sustain time... often very high\r
- lx=min(31,lx); // values are used to hold the volume\r
- if(lx) // until a sound stop occurs\r
- { // the highest value we reach (due to \r
- lx = (1<<lx); // overflow checking) is: \r
- if(lx<2147483) lx=(lx*SUSTAIN_MS)/10000L; // 94704 seconds = 1578 minutes = 26 hours... \r
- else lx=(lx/10000L)*SUSTAIN_MS; // should be enuff... if the stop doesn't \r
- if(!lx) lx=1; // come in this time span, I don't care :)\r
- }\r
- s_chan[ch].ADSR.SustainTime = lx;\r
-\r
- lx=(lval & 0x001f);\r
- s_chan[ch].ADSR.ReleaseVal =lx;\r
- if(lx) // release time from 100% to 0%\r
- { // note: the release time will be\r
- lx = (1<<lx); // adjusted when a stop is coming,\r
- if(lx<2147483) lx=(lx*RELEASE_MS)/10000L; // so at this time the adsr vol will \r
- else lx=(lx/10000L)*RELEASE_MS; // run from (current volume) to 0%\r
- if(!lx) lx=1;\r
- }\r
- s_chan[ch].ADSR.ReleaseTime=lx;\r
-\r
- if(lval & 0x4000) // add/dec flag\r
- s_chan[ch].ADSR.SustainModeDec=-1;\r
- else s_chan[ch].ADSR.SustainModeDec=1;\r
-#endif\r
}\r
break;\r
//------------------------------------------------// adsr volume... mmm have to investigate this\r
//------------------------------------------------//\r
case 14: // loop?\r
s_chan[ch].pLoop=spuMemC+((val&~1)<<3);\r
- if(s_chan[ch].bJump)\r
- // real machine would be most likely still doing the last block and use new value for the jump;\r
- // but we decode ahead a bit and already did the jump part, so compensate for that now.\r
- s_chan[ch].pCurr=s_chan[ch].pLoop;\r
- break;\r
+ goto upd_irq;\r
//------------------------------------------------//\r
}\r
return;\r
break;\r
//-------------------------------------------------//\r
case H_SPUctrl:\r
- if(!(spuCtrl & CTRL_IRQ))\r
+ if (!(spuCtrl & CTRL_IRQ)) {\r
spuStat&=~STAT_IRQ;\r
+ if (val & CTRL_IRQ)\r
+ schedule_next_irq();\r
+ }\r
spuCtrl=val;\r
break;\r
//-------------------------------------------------//\r
{\r
rvb.StartAddr=(unsigned long)val<<2;\r
rvb.CurrAddr=rvb.StartAddr;\r
+ // sync-with-decode-buffers hack..\r
+ if(rvb.StartAddr==0x3ff00)\r
+ rvb.CurrAddr+=decode_pos/2;\r
}\r
}\r
- rvb.dirty = 1;\r
- break;\r
+ goto rvbd;\r
//-------------------------------------------------//\r
case H_SPUirqAddr:\r
spuIrq = val;\r
pSpuIrq=spuMemC+(((unsigned long) val<<3)&~0xf);\r
- break;\r
+ goto upd_irq;\r
//-------------------------------------------------//\r
case H_SPUrvolL:\r
rvb.VolLeft=val;\r
ReverbOn(16,24,val);\r
break;\r
//-------------------------------------------------//\r
- case H_Reverb+0 : rvb.FB_SRC_A=val*4; break;\r
- case H_Reverb+2 : rvb.FB_SRC_B=val*4; break;\r
- case H_Reverb+4 : rvb.IIR_ALPHA=(short)val; break;\r
- case H_Reverb+6 : rvb.ACC_COEF_A=(short)val; break;\r
- case H_Reverb+8 : rvb.ACC_COEF_B=(short)val; break;\r
- case H_Reverb+10 : rvb.ACC_COEF_C=(short)val; break;\r
- case H_Reverb+12 : rvb.ACC_COEF_D=(short)val; break;\r
- case H_Reverb+14 : rvb.IIR_COEF=(short)val; break;\r
- case H_Reverb+16 : rvb.FB_ALPHA=(short)val; break;\r
- case H_Reverb+18 : rvb.FB_X=(short)val; break;\r
- case H_Reverb+20 : rvb.IIR_DEST_A0=val*4; break;\r
- case H_Reverb+22 : rvb.IIR_DEST_A1=val*4; break;\r
- case H_Reverb+24 : rvb.ACC_SRC_A0=val*4; break;\r
- case H_Reverb+26 : rvb.ACC_SRC_A1=val*4; break;\r
- case H_Reverb+28 : rvb.ACC_SRC_B0=val*4; break;\r
- case H_Reverb+30 : rvb.ACC_SRC_B1=val*4; break;\r
- case H_Reverb+32 : rvb.IIR_SRC_A0=val*4; break;\r
- case H_Reverb+34 : rvb.IIR_SRC_A1=val*4; break;\r
- case H_Reverb+36 : rvb.IIR_DEST_B0=val*4; break;\r
- case H_Reverb+38 : rvb.IIR_DEST_B1=val*4; break;\r
- case H_Reverb+40 : rvb.ACC_SRC_C0=val*4; break;\r
- case H_Reverb+42 : rvb.ACC_SRC_C1=val*4; break;\r
- case H_Reverb+44 : rvb.ACC_SRC_D0=val*4; break;\r
- case H_Reverb+46 : rvb.ACC_SRC_D1=val*4; break;\r
- case H_Reverb+48 : rvb.IIR_SRC_B1=val*4; break;\r
- case H_Reverb+50 : rvb.IIR_SRC_B0=val*4; break;\r
- case H_Reverb+52 : rvb.MIX_DEST_A0=val*4; break;\r
- case H_Reverb+54 : rvb.MIX_DEST_A1=val*4; break;\r
- case H_Reverb+56 : rvb.MIX_DEST_B0=val*4; break;\r
- case H_Reverb+58 : rvb.MIX_DEST_B1=val*4; break;\r
- case H_Reverb+60 : rvb.IN_COEF_L=(short)val; break;\r
- case H_Reverb+62 : rvb.IN_COEF_R=(short)val; break;\r
+ case H_Reverb+0 : rvb.FB_SRC_A=val*4; goto rvbd;\r
+ case H_Reverb+2 : rvb.FB_SRC_B=val*4; goto rvbd;\r
+ case H_Reverb+4 : rvb.IIR_ALPHA=(short)val; goto rvbd;\r
+ case H_Reverb+6 : rvb.ACC_COEF_A=(short)val; goto rvbd;\r
+ case H_Reverb+8 : rvb.ACC_COEF_B=(short)val; goto rvbd;\r
+ case H_Reverb+10 : rvb.ACC_COEF_C=(short)val; goto rvbd;\r
+ case H_Reverb+12 : rvb.ACC_COEF_D=(short)val; goto rvbd;\r
+ case H_Reverb+14 : rvb.IIR_COEF=(short)val; goto rvbd;\r
+ case H_Reverb+16 : rvb.FB_ALPHA=(short)val; goto rvbd;\r
+ case H_Reverb+18 : rvb.FB_X=(short)val; goto rvbd;\r
+ case H_Reverb+20 : rvb.IIR_DEST_A0=val*4; goto rvbd;\r
+ case H_Reverb+22 : rvb.IIR_DEST_A1=val*4; goto rvbd;\r
+ case H_Reverb+24 : rvb.ACC_SRC_A0=val*4; goto rvbd;\r
+ case H_Reverb+26 : rvb.ACC_SRC_A1=val*4; goto rvbd;\r
+ case H_Reverb+28 : rvb.ACC_SRC_B0=val*4; goto rvbd;\r
+ case H_Reverb+30 : rvb.ACC_SRC_B1=val*4; goto rvbd;\r
+ case H_Reverb+32 : rvb.IIR_SRC_A0=val*4; goto rvbd;\r
+ case H_Reverb+34 : rvb.IIR_SRC_A1=val*4; goto rvbd;\r
+ case H_Reverb+36 : rvb.IIR_DEST_B0=val*4; goto rvbd;\r
+ case H_Reverb+38 : rvb.IIR_DEST_B1=val*4; goto rvbd;\r
+ case H_Reverb+40 : rvb.ACC_SRC_C0=val*4; goto rvbd;\r
+ case H_Reverb+42 : rvb.ACC_SRC_C1=val*4; goto rvbd;\r
+ case H_Reverb+44 : rvb.ACC_SRC_D0=val*4; goto rvbd;\r
+ case H_Reverb+46 : rvb.ACC_SRC_D1=val*4; goto rvbd;\r
+ case H_Reverb+48 : rvb.IIR_SRC_B1=val*4; goto rvbd;\r
+ case H_Reverb+50 : rvb.IIR_SRC_B0=val*4; goto rvbd;\r
+ case H_Reverb+52 : rvb.MIX_DEST_A0=val*4; goto rvbd;\r
+ case H_Reverb+54 : rvb.MIX_DEST_A1=val*4; goto rvbd;\r
+ case H_Reverb+56 : rvb.MIX_DEST_B0=val*4; goto rvbd;\r
+ case H_Reverb+58 : rvb.MIX_DEST_B1=val*4; goto rvbd;\r
+ case H_Reverb+60 : rvb.IN_COEF_L=(short)val; goto rvbd;\r
+ case H_Reverb+62 : rvb.IN_COEF_R=(short)val; goto rvbd;\r
}\r
+ return;\r
+\r
+upd_irq:\r
+ if (spuCtrl & CTRL_IRQ)\r
+ schedule_next_irq();\r
+ return;\r
\r
- if ((r & ~0x3f) == H_Reverb)\r
- rvb.dirty = 1; // recalculate on next update\r
+rvbd:\r
+ rvb.dirty = 1; // recalculate on next update\r
}\r
\r
////////////////////////////////////////////////////////////////////////\r
s_chan[ch].bStop=0;\r
s_chan[ch].pCurr=spuMemC+((regAreaGet(ch,6)&~1)<<3); // must be block aligned\r
s_chan[ch].pLoop=spuMemC+((regAreaGet(ch,14)&~1)<<3);\r
- s_chan[ch].bJump=0;\r
+ s_chan[ch].prevflags=2;\r
\r
dwNewChannel|=(1<<ch); // bitfield for faster testing\r
dwChannelOn|=1<<ch;\r
\r
s_chan[ch].iRawPitch=NP;\r
s_chan[ch].sinc=(NP<<4)|8;\r
+ s_chan[ch].sinc_inv=0;\r
if(iUseInterpolation==1) s_chan[ch].SB[32]=1; // -> freq change in simple interpolation mode: set flag\r
}\r
\r