\r
#include "externals.h"\r
#include "registers.h"\r
+#include "spu_config.h"\r
\r
static void SoundOn(int start,int end,unsigned short val);\r
static void SoundOff(int start,int end,unsigned short val);\r
{\r
int r = reg & 0xfff;\r
int rofs = (r - 0xc00) >> 1;\r
- int changed = regArea[rofs] != val;\r
- regArea[rofs] = val;\r
+ int changed = spu.regArea[rofs] != val;\r
+ spu.regArea[rofs] = val;\r
\r
if (!changed && (ignore_dupe[rofs >> 5] & (1 << (rofs & 0x1f))))\r
return;\r
if (val == 0 && (r & 0xff8) == 0xd88)\r
return;\r
\r
- do_samples_if_needed(cycles);\r
+ do_samples_if_needed(cycles, 0);\r
\r
if(r>=0x0c00 && r<0x0d80) // some channel info?\r
{\r
{\r
const unsigned long lval=val;\r
//---------------------------------------------//\r
- s_chan[ch].ADSRX.AttackModeExp=(lval&0x8000)?1:0; \r
- s_chan[ch].ADSRX.AttackRate=(lval>>8) & 0x007f;\r
- s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f;\r
- s_chan[ch].ADSRX.SustainLevel=lval & 0x000f;\r
+ spu.s_chan[ch].ADSRX.AttackModeExp=(lval&0x8000)?1:0;\r
+ spu.s_chan[ch].ADSRX.AttackRate=(lval>>8) & 0x007f;\r
+ spu.s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f;\r
+ spu.s_chan[ch].ADSRX.SustainLevel=lval & 0x000f;\r
//---------------------------------------------//\r
}\r
break;\r
const unsigned long lval=val;\r
\r
//----------------------------------------------//\r
- s_chan[ch].ADSRX.SustainModeExp = (lval&0x8000)?1:0;\r
- s_chan[ch].ADSRX.SustainIncrease= (lval&0x4000)?0:1;\r
- s_chan[ch].ADSRX.SustainRate = (lval>>6) & 0x007f;\r
- s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0;\r
- s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f;\r
+ spu.s_chan[ch].ADSRX.SustainModeExp = (lval&0x8000)?1:0;\r
+ spu.s_chan[ch].ADSRX.SustainIncrease= (lval&0x4000)?0:1;\r
+ spu.s_chan[ch].ADSRX.SustainRate = (lval>>6) & 0x007f;\r
+ spu.s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0;\r
+ spu.s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f;\r
//----------------------------------------------//\r
}\r
break;\r
break;\r
//------------------------------------------------//\r
case 14: // loop?\r
- s_chan[ch].pLoop=spuMemC+((val&~1)<<3);\r
+ spu.s_chan[ch].pLoop=spu.spuMemC+((val&~1)<<3);\r
goto upd_irq;\r
//------------------------------------------------//\r
}\r
{\r
//-------------------------------------------------//\r
case H_SPUaddr:\r
- spuAddr = (unsigned long) val<<3;\r
+ spu.spuAddr = (unsigned long) val<<3;\r
break;\r
//-------------------------------------------------//\r
case H_SPUdata:\r
- spuMem[spuAddr>>1] = val;\r
- spuAddr+=2;\r
- if(spuAddr>0x7ffff) spuAddr=0;\r
+ *(unsigned short *)(spu.spuMemC + spu.spuAddr) = val;\r
+ spu.spuAddr += 2;\r
+ spu.spuAddr &= 0x7fffe;\r
break;\r
//-------------------------------------------------//\r
case H_SPUctrl:\r
- if (!(spuCtrl & CTRL_IRQ)) {\r
- spuStat&=~STAT_IRQ;\r
+ if (!(spu.spuCtrl & CTRL_IRQ)) {\r
+ spu.spuStat&=~STAT_IRQ;\r
if (val & CTRL_IRQ)\r
schedule_next_irq();\r
}\r
- spuCtrl=val;\r
+ spu.spuCtrl=val;\r
break;\r
//-------------------------------------------------//\r
case H_SPUstat:\r
- spuStat=val & 0xf800;\r
+ spu.spuStat=val&0xf800;\r
break;\r
//-------------------------------------------------//\r
case H_SPUReverbAddr:\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
goto rvbd;\r
//-------------------------------------------------//\r
case H_SPUirqAddr:\r
- spuIrq = val;\r
- pSpuIrq=spuMemC+(((unsigned long) val<<3)&~0xf);\r
+ spu.pSpuIrq=spu.spuMemC+(((unsigned long) val<<3)&~0xf);\r
goto upd_irq;\r
//-------------------------------------------------//\r
case H_SPUrvolL:\r
break;\r
//-------------------------------------------------//\r
case H_CDLeft:\r
- iLeftXAVol=val & 0x7fff;\r
- if(cddavCallback) cddavCallback(0,val);\r
+ spu.iLeftXAVol=val & 0x7fff;\r
+ if(spu.cddavCallback) spu.cddavCallback(0,val);\r
break;\r
case H_CDRight:\r
- iRightXAVol=val & 0x7fff;\r
- if(cddavCallback) cddavCallback(1,val);\r
+ spu.iRightXAVol=val & 0x7fff;\r
+ if(spu.cddavCallback) spu.cddavCallback(1,val);\r
break;\r
//-------------------------------------------------//\r
case H_FMod1:\r
return;\r
\r
upd_irq:\r
- if (spuCtrl & CTRL_IRQ)\r
+ if (spu.spuCtrl & CTRL_IRQ)\r
schedule_next_irq();\r
return;\r
\r
case 12: // get adsr vol\r
{\r
const int ch=(r>>4)-0xc0;\r
- if(dwNewChannel&(1<<ch)) return 1; // we are started, but not processed? return 1\r
- if((dwChannelOn&(1<<ch)) && // same here... we haven't decoded one sample yet, so no envelope yet. return 1 as well\r
- !s_chan[ch].ADSRX.EnvelopeVol)\r
+ if(spu.dwNewChannel&(1<<ch)) return 1; // we are started, but not processed? return 1\r
+ if((spu.dwChannelOn&(1<<ch)) && // same here... we haven't decoded one sample yet, so no envelope yet. return 1 as well\r
+ !spu.s_chan[ch].ADSRX.EnvelopeVol)\r
return 1;\r
- return (unsigned short)(s_chan[ch].ADSRX.EnvelopeVol>>16);\r
+ return (unsigned short)(spu.s_chan[ch].ADSRX.EnvelopeVol>>16);\r
}\r
\r
case 14: // get loop address\r
{\r
const int ch=(r>>4)-0xc0;\r
- return (unsigned short)((s_chan[ch].pLoop-spuMemC)>>3);\r
+ return (unsigned short)((spu.s_chan[ch].pLoop-spu.spuMemC)>>3);\r
}\r
}\r
}\r
switch(r)\r
{\r
case H_SPUctrl:\r
- return spuCtrl;\r
+ return spu.spuCtrl;\r
\r
case H_SPUstat:\r
- return spuStat;\r
+ return spu.spuStat;\r
\r
case H_SPUaddr:\r
- return (unsigned short)(spuAddr>>3);\r
+ return (unsigned short)(spu.spuAddr>>3);\r
\r
case H_SPUdata:\r
{\r
- unsigned short s=spuMem[spuAddr>>1];\r
- spuAddr+=2;\r
- if(spuAddr>0x7ffff) spuAddr=0;\r
+ unsigned short s = *(unsigned short *)(spu.spuMemC + spu.spuAddr);\r
+ spu.spuAddr += 2;\r
+ spu.spuAddr &= 0x7fffe;\r
return s;\r
}\r
\r
- case H_SPUirqAddr:\r
- return spuIrq;\r
-\r
//case H_SPUIsOn1:\r
// return IsSoundOn(0,16);\r
\r
\r
}\r
\r
- return regArea[(r-0xc00)>>1];\r
+ return spu.regArea[(r-0xc00)>>1];\r
}\r
\r
////////////////////////////////////////////////////////////////////////\r
{\r
if((val&1) && regAreaGet(ch,6)) // mmm... start has to be set before key on !?!\r
{\r
- // do this here, not in StartSound\r
- // - fixes fussy timing issues\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].prevflags=2;\r
-\r
- dwNewChannel|=(1<<ch); // bitfield for faster testing\r
- dwChannelOn|=1<<ch;\r
- dwChannelDead&=~(1<<ch);\r
+ spu.s_chan[ch].pCurr=spu.spuMemC+((regAreaGet(ch,6)&~1)<<3); // must be block aligned\r
+ spu.s_chan[ch].pLoop=spu.spuMemC+((regAreaGet(ch,14)&~1)<<3);\r
+ spu.dwNewChannel|=(1<<ch);\r
}\r
}\r
}\r
int ch;\r
for(ch=start;ch<end;ch++,val>>=1) // loop channels\r
{\r
- if(val&1) // && s_chan[i].bOn) mmm...\r
+ if(val&1)\r
{\r
- s_chan[ch].bStop=1;\r
+ spu.s_chan[ch].ADSRX.State = ADSR_RELEASE;\r
\r
// Jungle Book - Rhythm 'n Groove\r
// - turns off buzzing sound (loop hangs)\r
- dwNewChannel &= ~(1<<ch);\r
+ spu.dwNewChannel &= ~(1<<ch);\r
} \r
}\r
}\r
{\r
if(ch>0) \r
{\r
- s_chan[ch].bFMod=1; // --> sound channel\r
- s_chan[ch-1].bFMod=2; // --> freq channel\r
+ spu.s_chan[ch].bFMod=1; // --> sound channel\r
+ spu.s_chan[ch-1].bFMod=2; // --> freq channel\r
}\r
}\r
else\r
{\r
- s_chan[ch].bFMod=0; // --> turn off fmod\r
- if(ch>0&&s_chan[ch-1].bFMod==2)\r
- s_chan[ch-1].bFMod=0;\r
+ spu.s_chan[ch].bFMod=0; // --> turn off fmod\r
+ if(ch>0&&spu.s_chan[ch-1].bFMod==2)\r
+ spu.s_chan[ch-1].bFMod=0;\r
}\r
}\r
}\r
\r
for(ch=start;ch<end;ch++,val>>=1) // loop channels\r
{\r
- s_chan[ch].bNoise=val&1; // -> noise on/off\r
+ spu.s_chan[ch].bNoise=val&1; // -> noise on/off\r
}\r
}\r
\r
}\r
\r
vol&=0x3fff;\r
- s_chan[ch].iLeftVolume=vol; // store volume\r
+ spu.s_chan[ch].iLeftVolume=vol; // store volume\r
}\r
\r
////////////////////////////////////////////////////////////////////////\r
\r
vol&=0x3fff;\r
\r
- s_chan[ch].iRightVolume=vol;\r
+ spu.s_chan[ch].iRightVolume=vol;\r
}\r
\r
////////////////////////////////////////////////////////////////////////\r
if(val>0x3fff) NP=0x3fff; // get pitch val\r
else NP=val;\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
+ spu.s_chan[ch].iRawPitch=NP;\r
+ spu.s_chan[ch].sinc=(NP<<4)|8;\r
+ spu.s_chan[ch].sinc_inv=0;\r
+ if (spu_config.iUseInterpolation == 1)\r
+ spu.SB[ch * SB_SIZE + 32] = 1; // -> freq change in simple interpolation mode: set flag\r
}\r
\r
////////////////////////////////////////////////////////////////////////\r
\r
for(ch=start;ch<end;ch++,val>>=1) // loop channels\r
{\r
- s_chan[ch].bReverb=val&1; // -> reverb on/off\r
+ spu.s_chan[ch].bReverb=val&1; // -> reverb on/off\r
}\r
}\r