cd: rewrite pcm
[picodrive.git] / pico / cd / mcd.c
index 04c6156..8a84eb1 100644 (file)
@@ -41,6 +41,8 @@ PICO_INTERNAL void PicoPowerMCD(void)
   memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm));
   memset(&Pico_mcd->m, 0, sizeof(Pico_mcd->m));
 
+  Reset_CD();
+
   // cold reset state (tested)
   Pico_mcd->m.state_flags = PCD_ST_S68K_RST;
   Pico_mcd->m.busreq = 2;     // busreq on, s68k in reset
@@ -48,16 +50,25 @@ PICO_INTERNAL void PicoPowerMCD(void)
   memset(Pico_mcd->bios + 0x70, 0xff, 4);
 }
 
-PICO_INTERNAL int PicoResetMCD(void)
+void pcd_soft_reset(void)
 {
-  // ??
-  Reset_CD();
+  // Reset_CD(); // breaks Fahrenheit CD swap
+
   LC89510_Reset();
   gfx_cd_reset();
 #ifdef _ASM_CD_MEMORY_C
   //PicoMemResetCDdecode(1); // don't have to call this in 2M mode
 #endif
 
+  pcd_event_schedule_s68k(PCD_EVENT_CDC, 12500000/75);
+
+  // TODO: test if register state/timers change
+}
+
+PICO_INTERNAL int PicoResetMCD(void)
+{
+  // reset button doesn't affect MCD hardware
+
   // use SRam.data for RAM cart
   if (PicoOpt & POPT_EN_MCD_RAMCART) {
     if (SRam.data == NULL)
@@ -69,8 +80,6 @@ PICO_INTERNAL int PicoResetMCD(void)
   }
   SRam.start = SRam.end = 0; // unused
 
-  pcd_event_schedule(0, PCD_EVENT_CDC, 12500000/75);
-
   return 0;
 }
 
@@ -309,6 +318,10 @@ void pcd_state_loaded(void)
 
   pcd_state_loaded_mem();
 
+  memset(Pico_mcd->pcm_mixbuf, 0, sizeof(Pico_mcd->pcm_mixbuf));
+  Pico_mcd->pcm_mixbuf_dirty = 0;
+  Pico_mcd->pcm_mixpos = 0;
+
   // old savestates..
   cycles = pcd_cycles_m68k_to_s68k(SekCycleAim);
   diff = cycles - SekCycleAimS68k;
@@ -331,6 +344,8 @@ void pcd_state_loaded(void)
     if (Pico_mcd->scd.Status_CDC & 0x08)
            Update_CDC_TRansfer(Pico_mcd->s68k_regs[4] & 7);
   }
+  if (Pico_mcd->pcm.update_cycles == 0)
+    Pico_mcd->pcm.update_cycles = cycles;
 }
 
 // vim:shiftwidth=2:ts=2:expandtab