spu: try keyoff ignore
authornotaz <notasas@gmail.com>
Tue, 10 Oct 2023 23:11:51 +0000 (02:11 +0300)
committernotaz <notasas@gmail.com>
Wed, 11 Oct 2023 17:53:53 +0000 (20:53 +0300)
unclear if that's what's supposed to happen
notaz/pcsx_rearmed#315

plugins/dfsound/externals.h
plugins/dfsound/registers.c

index 4e1a40b..fca387d 100644 (file)
@@ -225,6 +225,8 @@ typedef struct
  int             iLeftXAVol;\r
  int             iRightXAVol;\r
 \r
+ unsigned int    last_keyon_cycles;\r
+\r
  union {\r
   unsigned char  *spuMemC;\r
   unsigned short *spuMem;\r
index 1e3767a..6f06ffc 100644 (file)
@@ -213,20 +213,32 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
 */\r
     //-------------------------------------------------//\r
     case H_SPUon1:\r
+      spu.last_keyon_cycles = cycles;\r
       do_samples_if_needed(cycles, 0, 2);\r
       SoundOn(0,16,val);\r
       break;\r
     //-------------------------------------------------//\r
     case H_SPUon2:\r
+      spu.last_keyon_cycles = cycles;\r
       do_samples_if_needed(cycles, 0, 2);\r
       SoundOn(16,24,val);\r
       break;\r
     //-------------------------------------------------//\r
     case H_SPUoff1:\r
+      if (cycles - spu.last_keyon_cycles < 786u) {\r
+       if (val & regAreaGet(H_SPUon1))\r
+        log_unhandled("koff1 %04x %d\n", val, cycles - spu.last_keyon_cycles);\r
+       val &= ~regAreaGet(H_SPUon1);\r
+      }\r
       SoundOff(0,16,val);\r
       break;\r
     //-------------------------------------------------//\r
     case H_SPUoff2:\r
+      if (cycles - spu.last_keyon_cycles < 786u) {\r
+       if (val & regAreaGet(H_SPUon1))\r
+        log_unhandled("koff2 %04x %d\n", val, cycles - spu.last_keyon_cycles);\r
+       val &= ~regAreaGet(H_SPUon2);\r
+      }\r
       SoundOff(16,24,val);\r
       break;\r
     //-------------------------------------------------//\r
@@ -420,7 +432,7 @@ static void SoundOn(int start,int end,unsigned short val)
 static void SoundOff(int start,int end,unsigned short val)\r
 {\r
  int ch;\r
- for(ch=start;ch<end;ch++,val>>=1)                     // loop channels\r
+ for (ch = start; val && ch < end; ch++, val >>= 1)    // loop channels\r
   {\r
    if(val&1)\r
     {\r
@@ -563,3 +575,5 @@ static void ReverbOn(int start,int end,unsigned short val)
    spu.s_chan[ch].bReverb=val&1;                       // -> reverb on/off\r
   }\r
 }\r
+\r
+// vim:shiftwidth=1:expandtab\r