32x: fix savestates
[picodrive.git] / pico / 32x / 32x.c
index 1b74c2d..cec05e8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * PicoDrive
- * (C) notaz, 2009,2010
+ * (C) notaz, 2009,2010,2013
  *
  * This work is licensed under the terms of MAME license.
  * See COPYING file in the top-level directory.
@@ -225,7 +225,7 @@ static void fillend_event(unsigned int now)
 
 typedef void (event_cb)(unsigned int now);
 
-static unsigned int event_times[P32X_EVENT_COUNT];
+unsigned int event_times[P32X_EVENT_COUNT];
 static unsigned int event_time_next;
 static event_cb *event_cbs[] = {
   [P32X_EVENT_PWM]      = pwm_irq_event,
@@ -301,8 +301,10 @@ void sync_sh2s_normal(unsigned int m68k_target)
 
   elprintf(EL_32X, "sh2 sync to %u", m68k_target);
 
-  if (!(Pico32x.regs[0] & P32XS_nRES))
+  if (!(Pico32x.regs[0] & P32XS_nRES)) {
+    msh2.m68krcycles_done = ssh2.m68krcycles_done = m68k_target;
     return; // rare
+  }
 
   now = msh2.m68krcycles_done;
   if (CYCLES_GT(now, ssh2.m68krcycles_done))
@@ -416,4 +418,18 @@ void Pico32xSetClocks(int msh2_hz, int ssh2_hz)
   }
 }
 
+void Pico32xStateLoaded(int is_early)
+{
+  if (is_early) {
+    Pico32xMemStateLoaded();
+    return;
+  }
+
+  sh2s[0].m68krcycles_done = sh2s[1].m68krcycles_done = SekCycleCntT;
+  p32x_update_irls(0);
+  p32x_poll_event(3, 0);
+  p32x_timers_recalc();
+  run_events(SekCycleCntT);
+}
+
 // vim:shiftwidth=2:ts=2:expandtab