spu: patch up more savestate issues
authornotaz <notasas@gmail.com>
Thu, 16 Nov 2023 19:07:21 +0000 (21:07 +0200)
committernotaz <notasas@gmail.com>
Thu, 16 Nov 2023 19:07:21 +0000 (21:07 +0200)
notaz/pcsx_rearmed#329

plugins/dfsound/freeze.c
plugins/dfsound/registers.c
plugins/dfsound/reverb.c
plugins/dfsound/spu.c
plugins/dfsound/xa.c

index 8816a51..32c07db 100644 (file)
@@ -130,6 +130,14 @@ typedef struct
 \r
  SPUCHAN_orig s_chan[MAXCHAN];   \r
 \r
+ uint32_t   cycles_dma_end;\r
+ uint32_t   decode_dirty_ch;\r
+ uint32_t   dwNoiseVal;\r
+ uint32_t   dwNoiseCount;\r
+ uint32_t   XARepeat;\r
+ uint32_t   XALastVal;\r
+ uint32_t   last_keyon_cycles;\r
+\r
 } SPUOSSFreeze_t;\r
 \r
 ////////////////////////////////////////////////////////////////////////\r
@@ -250,6 +258,8 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode, SPUFreeze_t * pF,
 \r
    if(ulFreezeMode==2) return 1;                       // info mode? ok, bye\r
                                                        // save mode:\r
+   regAreaGet(H_SPUctrl) = spu.spuCtrl;\r
+   regAreaGet(H_SPUstat) = spu.spuStat;\r
    memcpy(pF->cSPURam,spu.spuMem,0x80000);             // copy common infos\r
    memcpy(pF->cSPUPort,spu.regArea,0x200);\r
 \r
@@ -312,6 +322,8 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode, SPUFreeze_t * pF,
  memcpy(spu.spuMem,pF->cSPURam,0x80000);               // get ram\r
  memcpy(spu.regArea,pF->cSPUPort,0x200);\r
  spu.bMemDirty = 1;\r
+ spu.spuCtrl = regAreaGet(H_SPUctrl);\r
+ spu.spuStat = regAreaGet(H_SPUstat);\r
 \r
  if (!strcmp(pF->szSPUName,"PBOSS") && pF->ulFreezeVersion==5)\r
    pFO = LoadStateV5(pF, cycles);\r
@@ -329,18 +341,35 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode, SPUFreeze_t * pF,
   FeedCDDA((void *)pF->xaS.pcm, pFO->cdda_left * 4);\r
  }\r
 \r
+ // not in old savestates\r
+ spu.cycles_dma_end = 0;\r
+ spu.decode_dirty_ch = spu.dwChannelsAudible & 0x0a;\r
+ spu.dwNoiseVal = 0;\r
+ spu.dwNoiseCount = 0;\r
+ spu.XARepeat = 0;\r
+ spu.XALastVal = 0;\r
+ spu.last_keyon_cycles = cycles - 16*786u;\r
+ if (pFO && pF->ulFreezeSize >= sizeof(*pF) + sizeof(*pFO)) {\r
+  spu.cycles_dma_end = pFO->cycles_dma_end;\r
+  spu.decode_dirty_ch = pFO->decode_dirty_ch;\r
+  spu.dwNoiseVal = pFO->dwNoiseVal;\r
+  spu.dwNoiseCount = pFO->dwNoiseCount;\r
+  spu.XARepeat = pFO->XARepeat;\r
+  spu.XALastVal = pFO->XALastVal;\r
+  spu.last_keyon_cycles = pFO->last_keyon_cycles;\r
+ }\r
+\r
  // repair some globals\r
  for(i=0;i<=62;i+=2)\r
   load_register(H_Reverb+i, cycles);\r
  load_register(H_SPUReverbAddr, cycles);\r
  load_register(H_SPUrvolL, cycles);\r
  load_register(H_SPUrvolR, cycles);\r
-\r
- load_register(H_SPUctrl, cycles);\r
- load_register(H_SPUstat, cycles);\r
  load_register(H_CDLeft, cycles);\r
  load_register(H_CDRight, cycles);\r
 \r
+ // reverb\r
+ spu.rvb->StartAddr = regAreaGet(H_SPUReverbAddr) << 2;\r
  if (spu.rvb->CurrAddr < spu.rvb->StartAddr)\r
   spu.rvb->CurrAddr = spu.rvb->StartAddr;\r
  // fix to prevent new interpolations from crashing\r
@@ -383,6 +412,7 @@ static SPUOSSFreeze_t * LoadStateV5(SPUFreeze_t * pF, uint32_t cycles)
    spu.s_chan[i].pCurr+=(uintptr_t)spu.spuMemC;\r
    spu.s_chan[i].pLoop+=(uintptr_t)spu.spuMemC;\r
   }\r
+\r
  return pFO;\r
 }\r
 \r
index 5d79f25..1e79c0e 100644 (file)
@@ -144,6 +144,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,
       break;\r
     //-------------------------------------------------//\r
     case H_SPUctrl:\r
+      spu.spuStat = (spu.spuStat & ~0x3f) | (val & 0x3f);\r
       spu.spuStat &= ~STAT_IRQ | val;\r
       if (!(spu.spuCtrl & CTRL_IRQ)) {\r
         if (val & CTRL_IRQ)\r
@@ -365,7 +366,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg, unsigned int cycles)
      return spu.spuCtrl;\r
 \r
     case H_SPUstat:\r
-     return (spu.spuStat & ~0x3F) | (spu.spuCtrl & 0x3F);\r
+     return spu.spuStat;\r
         \r
     case H_SPUaddr:\r
      return (unsigned short)(spu.spuAddr>>3);\r
index de9b804..c0ecea1 100644 (file)
@@ -177,7 +177,7 @@ static void REVERBPrep(void)
  REVERBInfo *rvb = spu.rvb;\r
  int space, t;\r
 \r
- t = spu.regArea[(H_SPUReverbAddr - 0xc00) >> 1];\r
+ t = regAreaGet(H_SPUReverbAddr);\r
  if (t == 0xFFFF || t <= 0x200)\r
   spu.rvb->StartAddr = spu.rvb->CurrAddr = 0;\r
  else if (spu.rvb->StartAddr != (t << 2))\r
index f202388..7501df8 100644 (file)
@@ -1147,7 +1147,7 @@ void do_samples(unsigned int cycles_to, int do_direct)
  cycle_diff = cycles_to - spu.cycles_played;
  if (cycle_diff < -2*1048576 || cycle_diff > 2*1048576)
   {
-   //xprintf("desync %u %d\n", cycles_to, cycle_diff);
+   log_unhandled("desync %u %d\n", cycles_to, cycle_diff);
    spu.cycles_played = cycles_to;
    return;
   }
@@ -1164,7 +1164,7 @@ void do_samples(unsigned int cycles_to, int do_direct)
  ns_to = (cycle_diff / 768 + 1) & ~1;
  if (ns_to > NSSIZE) {
   // should never happen
-  //xprintf("ns_to oflow %d %d\n", ns_to, NSSIZE);
+  log_unhandled("ns_to oflow %d %d\n", ns_to, NSSIZE);
   ns_to = NSSIZE;
  }
 
index 08afc00..b3ac01d 100644 (file)
@@ -413,8 +413,10 @@ void FeedCDDA(unsigned char *pcm, int nBytes)
 {
  int space;
  space=(spu.CDDAPlay-spu.CDDAFeed-1)*4 & (CDDA_BUFFER_SIZE - 1);
- if(space<nBytes)
+ if (space < nBytes) {
+  log_unhandled("FeedCDDA: %d/%d\n", nBytes, space);
   return;
+ }
 
  while(nBytes>0)
   {