Merge pull request #292 from pcercuei/dfsound-big-endian
[pcsx_rearmed.git] / plugins / dfsound / registers.c
index cc72020..adc9c3a 100644 (file)
@@ -22,6 +22,7 @@
 #include "externals.h"\r
 #include "registers.h"\r
 #include "spu_config.h"\r
+#include "spu.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
@@ -127,7 +128,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
       break;\r
     //-------------------------------------------------//\r
     case H_SPUdata:\r
-      *(unsigned short *)(spu.spuMemC + spu.spuAddr) = val;\r
+      *(unsigned short *)(spu.spuMemC + spu.spuAddr) = HTOLE16(val);\r
       spu.spuAddr += 2;\r
       spu.spuAddr &= 0x7fffe;\r
       break;\r
@@ -149,6 +150,8 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
       goto rvbd;\r
     //-------------------------------------------------//\r
     case H_SPUirqAddr:\r
+      //if (val & 1)\r
+      //  log_unhandled("w irq with lsb: %08lx %04x\n", reg, val);\r
       spu.pSpuIrq=spu.spuMemC+(((unsigned long) val<<3)&~0xf);\r
       goto upd_irq;\r
     //-------------------------------------------------//\r
@@ -161,6 +164,17 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
       break;\r
     //-------------------------------------------------//\r
 \r
+    case H_SPUmvolL:\r
+    case H_SPUmvolR:\r
+      if (val & 0x8000)\r
+        log_unhandled("w master sweep: %08lx %04x\n", reg, val);\r
+      break;\r
+\r
+    case 0x0dac:\r
+     if (val != 4)\r
+       log_unhandled("1f801dac %04x\n", val);\r
+     break;\r
+\r
 /*\r
     case H_ExtLeft:\r
      //auxprintf("EL %d\n",val);\r
@@ -204,12 +218,12 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
       break;\r
     //-------------------------------------------------//\r
     case H_CDLeft:\r
-      spu.iLeftXAVol=val  & 0x7fff;\r
-      if(spu.cddavCallback) spu.cddavCallback(0,val);\r
+      spu.iLeftXAVol=(int16_t)val;\r
+      if(spu.cddavCallback) spu.cddavCallback(0,(int16_t)val);\r
       break;\r
     case H_CDRight:\r
-      spu.iRightXAVol=val & 0x7fff;\r
-      if(spu.cddavCallback) spu.cddavCallback(1,val);\r
+      spu.iRightXAVol=(int16_t)val;\r
+      if(spu.cddavCallback) spu.cddavCallback(1,(int16_t)val);\r
       break;\r
     //-------------------------------------------------//\r
     case H_FMod1:\r
@@ -296,7 +310,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
       {\r
        const int ch=(r>>4)-0xc0;\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
+       if((spu.dwChannelsAudible&(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)(spu.s_chan[ch].ADSRX.EnvelopeVol>>16);\r
@@ -323,7 +337,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
 \r
     case H_SPUdata:\r
      {\r
-      unsigned short s = *(unsigned short *)(spu.spuMemC + spu.spuAddr);\r
+      unsigned short s = LE16TOH(*(unsigned short *)(spu.spuMemC + spu.spuAddr));\r
       spu.spuAddr += 2;\r
       spu.spuAddr &= 0x7fffe;\r
       return s;\r
@@ -335,6 +349,10 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg)
     //case H_SPUIsOn2:\r
     // return IsSoundOn(16,24);\r
  \r
+    case H_SPUMute1:\r
+    case H_SPUMute2:\r
+     log_unhandled("r isOn: %08lx\n", reg);\r
+     break;\r
   }\r
 \r
  return spu.regArea[(r-0xc00)>>1];\r
@@ -350,7 +368,7 @@ static void SoundOn(int start,int end,unsigned short val)
 \r
  for(ch=start;ch<end;ch++,val>>=1)                     // loop channels\r
   {\r
-   if((val&1) && regAreaGet(ch,6))                     // mmm... start has to be set before key on !?!\r
+   if((val&1) && regAreaGetCh(ch, 6))                  // mmm... start has to be set before key on !?!\r
     {\r
      spu.s_chan[ch].bIgnoreLoop = 0;\r
      spu.dwNewChannel|=(1<<ch);\r
@@ -431,6 +449,7 @@ static void SetVolumeL(unsigned char ch,short vol)     // LEFT VOLUME
  if(vol&0x8000)                                        // sweep?\r
   {\r
    short sInc=1;                                       // -> sweep up?\r
+   log_unhandled("ch%d sweepl %04x\n", ch, vol);\r
    if(vol&0x2000) sInc=-1;                             // -> or down?\r
    if(vol&0x1000) vol^=0xffff;                         // -> mmm... phase inverted? have to investigate this\r
    vol=((vol&0x7f)+1)/2;                               // -> sweep: 0..127 -> 0..64\r
@@ -457,6 +476,7 @@ static void SetVolumeR(unsigned char ch,short vol)     // RIGHT VOLUME
  if(vol&0x8000)                                        // comments... see above :)\r
   {\r
    short sInc=1;\r
+   log_unhandled("ch%d sweepr %04x\n", ch, vol);\r
    if(vol&0x2000) sInc=-1;\r
    if(vol&0x1000) vol^=0xffff;\r
    vol=((vol&0x7f)+1)/2;        \r
@@ -484,11 +504,12 @@ static void SetPitch(int ch,unsigned short val)               // SET PITCH
  if(val>0x3fff) NP=0x3fff;                             // get pitch val\r
  else           NP=val;\r
 \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
+ spu.s_chan[ch].iRawPitch = NP;\r
+ spu.s_chan[ch].sinc = NP << 4;\r
+ spu.s_chan[ch].sinc_inv = 0;\r
+ spu.s_chan[ch].bNewPitch = 1;\r
+\r
+ // don't mess spu.dwChannelsAudible as adsr runs independently\r
 }\r
 \r
 ////////////////////////////////////////////////////////////////////////\r