aboutsummaryrefslogtreecommitdiff
path: root/plugins/dfsound/registers.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/dfsound/registers.c')
-rw-r--r--plugins/dfsound/registers.c160
1 files changed, 77 insertions, 83 deletions
diff --git a/plugins/dfsound/registers.c b/plugins/dfsound/registers.c
index 210adb2..4588fa7 100644
--- a/plugins/dfsound/registers.c
+++ b/plugins/dfsound/registers.c
@@ -57,7 +57,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
if (val == 0 && (r & 0xff8) == 0xd88)
return;
- do_samples_if_needed(cycles);
+ do_samples_if_needed(cycles, 0);
if(r>=0x0c00 && r<0x0d80) // some channel info?
{
@@ -85,10 +85,10 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
{
const unsigned long lval=val;
//---------------------------------------------//
- s_chan[ch].ADSRX.AttackModeExp=(lval&0x8000)?1:0;
- s_chan[ch].ADSRX.AttackRate=(lval>>8) & 0x007f;
- s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f;
- s_chan[ch].ADSRX.SustainLevel=lval & 0x000f;
+ spu.s_chan[ch].ADSRX.AttackModeExp=(lval&0x8000)?1:0;
+ spu.s_chan[ch].ADSRX.AttackRate=(lval>>8) & 0x007f;
+ spu.s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f;
+ spu.s_chan[ch].ADSRX.SustainLevel=lval & 0x000f;
//---------------------------------------------//
}
break;
@@ -98,11 +98,11 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
const unsigned long lval=val;
//----------------------------------------------//
- s_chan[ch].ADSRX.SustainModeExp = (lval&0x8000)?1:0;
- s_chan[ch].ADSRX.SustainIncrease= (lval&0x4000)?0:1;
- s_chan[ch].ADSRX.SustainRate = (lval>>6) & 0x007f;
- s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0;
- s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f;
+ spu.s_chan[ch].ADSRX.SustainModeExp = (lval&0x8000)?1:0;
+ spu.s_chan[ch].ADSRX.SustainIncrease= (lval&0x4000)?0:1;
+ spu.s_chan[ch].ADSRX.SustainRate = (lval>>6) & 0x007f;
+ spu.s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0;
+ spu.s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f;
//----------------------------------------------//
}
break;
@@ -111,7 +111,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
break;
//------------------------------------------------//
case 14: // loop?
- s_chan[ch].pLoop=spu.spuMemC+((val&~1)<<3);
+ spu.s_chan[ch].pLoop=spu.spuMemC+((val&~1)<<3);
goto upd_irq;
//------------------------------------------------//
}
@@ -126,9 +126,9 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
break;
//-------------------------------------------------//
case H_SPUdata:
- spu.spuMem[spu.spuAddr>>1] = val;
- spu.spuAddr+=2;
- if(spu.spuAddr>0x7ffff) spu.spuAddr=0;
+ *(unsigned short *)(spu.spuMemC + spu.spuAddr) = val;
+ spu.spuAddr += 2;
+ spu.spuAddr &= 0x7fffe;
break;
//-------------------------------------------------//
case H_SPUctrl:
@@ -146,14 +146,14 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
//-------------------------------------------------//
case H_SPUReverbAddr:
if(val==0xFFFF || val<=0x200)
- {rvb.StartAddr=rvb.CurrAddr=0;}
+ {spu.rvb->StartAddr=spu.rvb->CurrAddr=0;}
else
{
const long iv=(unsigned long)val<<2;
- if(rvb.StartAddr!=iv)
+ if(spu.rvb->StartAddr!=iv)
{
- rvb.StartAddr=(unsigned long)val<<2;
- rvb.CurrAddr=rvb.StartAddr;
+ spu.rvb->StartAddr=(unsigned long)val<<2;
+ spu.rvb->CurrAddr=spu.rvb->StartAddr;
}
}
goto rvbd;
@@ -163,11 +163,11 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
goto upd_irq;
//-------------------------------------------------//
case H_SPUrvolL:
- rvb.VolLeft=val;
+ spu.rvb->VolLeft=val;
break;
//-------------------------------------------------//
case H_SPUrvolR:
- rvb.VolRight=val;
+ spu.rvb->VolRight=val;
break;
//-------------------------------------------------//
@@ -246,38 +246,38 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
ReverbOn(16,24,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;
+ case H_Reverb+0 : spu.rvb->FB_SRC_A=val*4; goto rvbd;
+ case H_Reverb+2 : spu.rvb->FB_SRC_B=val*4; goto rvbd;
+ case H_Reverb+4 : spu.rvb->IIR_ALPHA=(short)val; goto rvbd;
+ case H_Reverb+6 : spu.rvb->ACC_COEF_A=(short)val; goto rvbd;
+ case H_Reverb+8 : spu.rvb->ACC_COEF_B=(short)val; goto rvbd;
+ case H_Reverb+10 : spu.rvb->ACC_COEF_C=(short)val; goto rvbd;
+ case H_Reverb+12 : spu.rvb->ACC_COEF_D=(short)val; goto rvbd;
+ case H_Reverb+14 : spu.rvb->IIR_COEF=(short)val; goto rvbd;
+ case H_Reverb+16 : spu.rvb->FB_ALPHA=(short)val; goto rvbd;
+ case H_Reverb+18 : spu.rvb->FB_X=(short)val; goto rvbd;
+ case H_Reverb+20 : spu.rvb->IIR_DEST_A0=val*4; goto rvbd;
+ case H_Reverb+22 : spu.rvb->IIR_DEST_A1=val*4; goto rvbd;
+ case H_Reverb+24 : spu.rvb->ACC_SRC_A0=val*4; goto rvbd;
+ case H_Reverb+26 : spu.rvb->ACC_SRC_A1=val*4; goto rvbd;
+ case H_Reverb+28 : spu.rvb->ACC_SRC_B0=val*4; goto rvbd;
+ case H_Reverb+30 : spu.rvb->ACC_SRC_B1=val*4; goto rvbd;
+ case H_Reverb+32 : spu.rvb->IIR_SRC_A0=val*4; goto rvbd;
+ case H_Reverb+34 : spu.rvb->IIR_SRC_A1=val*4; goto rvbd;
+ case H_Reverb+36 : spu.rvb->IIR_DEST_B0=val*4; goto rvbd;
+ case H_Reverb+38 : spu.rvb->IIR_DEST_B1=val*4; goto rvbd;
+ case H_Reverb+40 : spu.rvb->ACC_SRC_C0=val*4; goto rvbd;
+ case H_Reverb+42 : spu.rvb->ACC_SRC_C1=val*4; goto rvbd;
+ case H_Reverb+44 : spu.rvb->ACC_SRC_D0=val*4; goto rvbd;
+ case H_Reverb+46 : spu.rvb->ACC_SRC_D1=val*4; goto rvbd;
+ case H_Reverb+48 : spu.rvb->IIR_SRC_B1=val*4; goto rvbd;
+ case H_Reverb+50 : spu.rvb->IIR_SRC_B0=val*4; goto rvbd;
+ case H_Reverb+52 : spu.rvb->MIX_DEST_A0=val*4; goto rvbd;
+ case H_Reverb+54 : spu.rvb->MIX_DEST_A1=val*4; goto rvbd;
+ case H_Reverb+56 : spu.rvb->MIX_DEST_B0=val*4; goto rvbd;
+ case H_Reverb+58 : spu.rvb->MIX_DEST_B1=val*4; goto rvbd;
+ case H_Reverb+60 : spu.rvb->IN_COEF_L=(short)val; goto rvbd;
+ case H_Reverb+62 : spu.rvb->IN_COEF_R=(short)val; goto rvbd;
}
return;
@@ -287,7 +287,7 @@ upd_irq:
return;
rvbd:
- rvb.dirty = 1; // recalculate on next update
+ spu.rvb->dirty = 1; // recalculate on next update
}
////////////////////////////////////////////////////////////////////////
@@ -307,15 +307,15 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
const int ch=(r>>4)-0xc0;
if(spu.dwNewChannel&(1<<ch)) return 1; // we are started, but not processed? return 1
if((spu.dwChannelOn&(1<<ch)) && // same here... we haven't decoded one sample yet, so no envelope yet. return 1 as well
- !s_chan[ch].ADSRX.EnvelopeVol)
+ !spu.s_chan[ch].ADSRX.EnvelopeVol)
return 1;
- return (unsigned short)(s_chan[ch].ADSRX.EnvelopeVol>>16);
+ return (unsigned short)(spu.s_chan[ch].ADSRX.EnvelopeVol>>16);
}
case 14: // get loop address
{
const int ch=(r>>4)-0xc0;
- return (unsigned short)((s_chan[ch].pLoop-spu.spuMemC)>>3);
+ return (unsigned short)((spu.s_chan[ch].pLoop-spu.spuMemC)>>3);
}
}
}
@@ -333,9 +333,9 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
case H_SPUdata:
{
- unsigned short s=spu.spuMem[spu.spuAddr>>1];
- spu.spuAddr+=2;
- if(spu.spuAddr>0x7ffff) spu.spuAddr=0;
+ unsigned short s = *(unsigned short *)(spu.spuMemC + spu.spuAddr);
+ spu.spuAddr += 2;
+ spu.spuAddr &= 0x7fffe;
return s;
}
@@ -362,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=spu.spuMemC+((regAreaGet(ch,6)&~1)<<3); // must be block aligned
- s_chan[ch].pLoop=spu.spuMemC+((regAreaGet(ch,14)&~1)<<3);
- s_chan[ch].prevflags=2;
-
+ spu.s_chan[ch].pCurr=spu.spuMemC+((regAreaGet(ch,6)&~1)<<3); // must be block aligned
+ spu.s_chan[ch].pLoop=spu.spuMemC+((regAreaGet(ch,14)&~1)<<3);
spu.dwNewChannel|=(1<<ch);
- spu.dwChannelOn|=1<<ch;
- spu.dwChannelDead&=~(1<<ch);
}
}
}
@@ -385,9 +378,9 @@ static void SoundOff(int start,int end,unsigned short val)
int ch;
for(ch=start;ch<end;ch++,val>>=1) // loop channels
{
- if(val&1) // && s_chan[i].bOn) mmm...
+ if(val&1)
{
- s_chan[ch].bStop=1;
+ spu.s_chan[ch].ADSRX.State = ADSR_RELEASE;
// Jungle Book - Rhythm 'n Groove
// - turns off buzzing sound (loop hangs)
@@ -410,15 +403,15 @@ static void FModOn(int start,int end,unsigned short val)
{
if(ch>0)
{
- s_chan[ch].bFMod=1; // --> sound channel
- s_chan[ch-1].bFMod=2; // --> freq channel
+ spu.s_chan[ch].bFMod=1; // --> sound channel
+ spu.s_chan[ch-1].bFMod=2; // --> freq channel
}
}
else
{
- s_chan[ch].bFMod=0; // --> turn off fmod
- if(ch>0&&s_chan[ch-1].bFMod==2)
- s_chan[ch-1].bFMod=0;
+ spu.s_chan[ch].bFMod=0; // --> turn off fmod
+ if(ch>0&&spu.s_chan[ch-1].bFMod==2)
+ spu.s_chan[ch-1].bFMod=0;
}
}
}
@@ -433,7 +426,7 @@ static void NoiseOn(int start,int end,unsigned short val)
for(ch=start;ch<end;ch++,val>>=1) // loop channels
{
- s_chan[ch].bNoise=val&1; // -> noise on/off
+ spu.s_chan[ch].bNoise=val&1; // -> noise on/off
}
}
@@ -463,7 +456,7 @@ static void SetVolumeL(unsigned char ch,short vol) // LEFT VOLUME
}
vol&=0x3fff;
- s_chan[ch].iLeftVolume=vol; // store volume
+ spu.s_chan[ch].iLeftVolume=vol; // store volume
}
////////////////////////////////////////////////////////////////////////
@@ -489,7 +482,7 @@ static void SetVolumeR(unsigned char ch,short vol) // RIGHT VOLUME
vol&=0x3fff;
- s_chan[ch].iRightVolume=vol;
+ spu.s_chan[ch].iRightVolume=vol;
}
////////////////////////////////////////////////////////////////////////
@@ -502,10 +495,11 @@ static void SetPitch(int ch,unsigned short val) // SET PITCH
if(val>0x3fff) NP=0x3fff; // get pitch val
else NP=val;
- s_chan[ch].iRawPitch=NP;
- s_chan[ch].sinc=(NP<<4)|8;
- 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
+ spu.s_chan[ch].iRawPitch=NP;
+ spu.s_chan[ch].sinc=(NP<<4)|8;
+ spu.s_chan[ch].sinc_inv=0;
+ if (spu_config.iUseInterpolation == 1)
+ spu.SB[ch * SB_SIZE + 32] = 1; // -> freq change in simple interpolation mode: set flag
}
////////////////////////////////////////////////////////////////////////
@@ -518,6 +512,6 @@ static void ReverbOn(int start,int end,unsigned short val)
for(ch=start;ch<end;ch++,val>>=1) // loop channels
{
- s_chan[ch].bReverb=val&1; // -> reverb on/off
+ spu.s_chan[ch].bReverb=val&1; // -> reverb on/off
}
}