spu: get rid of bStop, clean up
[pcsx_rearmed.git] / plugins / dfsound / registers.c
index 730c753..bc99d9a 100644 (file)
@@ -21,6 +21,7 @@
 \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
@@ -47,8 +48,8 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
 {\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
@@ -110,7 +111,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
        break;\r
      //------------------------------------------------//\r
      case 14:                                          // loop?\r
-       s_chan[ch].pLoop=spuMemC+((val&~1)<<3);\r
+       s_chan[ch].pLoop=spu.spuMemC+((val&~1)<<3);\r
        goto upd_irq;\r
      //------------------------------------------------//\r
     }\r
@@ -121,26 +122,26 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
    {\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
+      spu.spuMem[spu.spuAddr>>1] = val;\r
+      spu.spuAddr+=2;\r
+      if(spu.spuAddr>0x7ffff) spu.spuAddr=0;\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
@@ -153,16 +154,12 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
          {\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
@@ -217,12 +214,12 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
       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
@@ -285,7 +282,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
  return;\r
 \r
 upd_irq:\r
- if (spuCtrl & CTRL_IRQ)\r
+ if (spu.spuCtrl & CTRL_IRQ)\r
   schedule_next_irq();\r
  return;\r
 \r
@@ -308,8 +305,8 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
      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
+       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
           !s_chan[ch].ADSRX.EnvelopeVol)\r
         return 1;\r
        return (unsigned short)(s_chan[ch].ADSRX.EnvelopeVol>>16);\r
@@ -318,7 +315,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
      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)((s_chan[ch].pLoop-spu.spuMemC)>>3);\r
       }\r
     }\r
   }\r
@@ -326,25 +323,22 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
  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=spu.spuMem[spu.spuAddr>>1];\r
+      spu.spuAddr+=2;\r
+      if(spu.spuAddr>0x7ffff) spu.spuAddr=0;\r
       return s;\r
      }\r
 \r
-    case H_SPUirqAddr:\r
-     return spuIrq;\r
-\r
     //case H_SPUIsOn1:\r
     // return IsSoundOn(0,16);\r
 \r
@@ -353,7 +347,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
  \r
   }\r
 \r
- return regArea[(r-0xc00)>>1];\r
+ return spu.regArea[(r-0xc00)>>1];\r
 }\r
  \r
 ////////////////////////////////////////////////////////////////////////\r
@@ -368,16 +362,9 @@ static void SoundOn(int start,int end,unsigned short val)
   {\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
+     s_chan[ch].pCurr=spu.spuMemC+((regAreaGet(ch,6)&~1)<<3); // must be block aligned\r
+     s_chan[ch].pLoop=spu.spuMemC+((regAreaGet(ch,14)&~1)<<3);\r
+     spu.dwNewChannel|=(1<<ch);\r
     }\r
   }\r
 }\r
@@ -391,13 +378,13 @@ static void SoundOff(int start,int end,unsigned short val)
  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
+     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
@@ -511,7 +498,7 @@ static void SetPitch(int ch,unsigned short val)               // SET PITCH
  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
+ if(spu_config.iUseInterpolation==1) s_chan[ch].SB[32]=1; // -> freq change in simple interpolation mode: set flag\r
 }\r
 \r
 ////////////////////////////////////////////////////////////////////////\r