new timing for main and cd
[picodrive.git] / pico / sek.c
index 2fe77cb..8dd7729 100644 (file)
@@ -11,9 +11,8 @@
 #include "memory.h"\r
 \r
 \r
-int SekCycleCnt=0; // cycles done in this frame\r
-int SekCycleAim=0; // cycle aim\r
-unsigned int SekCycleCntT=0;\r
+unsigned int SekCycleCnt;\r
+unsigned int SekCycleAim;\r
 \r
 \r
 /* context */\r
@@ -220,7 +219,8 @@ PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub)
 #endif\r
 \r
   *(unsigned int *)(cpu+0x40) = pc;\r
-  *(unsigned int *)(cpu+0x50) = SekCycleCntT;\r
+  *(unsigned int *)(cpu+0x50) =\r
+    is_sub ? SekCycleCntS68k : SekCycleCnt;\r
 }\r
 \r
 PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub)\r
@@ -257,7 +257,10 @@ PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub)
   context->execinfo &= ~FM68K_HALTED;\r
   if (cpu[0x4d]&1) context->execinfo |= FM68K_HALTED;\r
 #endif\r
-  SekCycleCntT = *(unsigned int *)(cpu+0x50);\r
+  if (is_sub)\r
+    SekCycleCntS68k = *(unsigned int *)(cpu+0x50);\r
+  else\r
+    SekCycleCnt = *(unsigned int *)(cpu+0x50);\r
 }\r
 \r
 \r
@@ -268,7 +271,7 @@ PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub)
 \r
 static unsigned short **idledet_ptrs = NULL;\r
 static int idledet_count = 0, idledet_bads = 0;\r
-int idledet_start_frame = 0;\r
+static int idledet_start_frame = 0;\r
 \r
 #if 0\r
 #define IDLE_STATS 1\r
@@ -312,6 +315,11 @@ void SekInitIdleDet(void)
 #endif\r
 }\r
 \r
+int SekIsIdleReady(void)\r
+{\r
+       return (Pico.m.frame_count >= idledet_start_frame);\r
+}\r
+\r
 int SekIsIdleCode(unsigned short *dst, int bytes)\r
 {\r
   // printf("SekIsIdleCode %04x %i\n", *dst, bytes);\r
@@ -322,11 +330,16 @@ int SekIsIdleCode(unsigned short *dst, int bytes)
         return 1;\r
       break;\r
     case 4:\r
-      if (  (*dst & 0xfff8) == 0x4a10 || // tst.b ($aX)      // there should be no need to wait\r
-            (*dst & 0xfff8) == 0x4a28 || // tst.b ($xxxx,a0) // for byte change anywhere\r
-            (*dst & 0xff3f) == 0x4a38 || // tst.x ($xxxx.w); tas ($xxxx.w)\r
-            (*dst & 0xc1ff) == 0x0038 || // move.x ($xxxx.w), dX\r
-            (*dst & 0xf13f) == 0xb038)   // cmp.x ($xxxx.w), dX\r
+      if ( (*dst & 0xff3f) == 0x4a38 || // tst.x ($xxxx.w); tas ($xxxx.w)\r
+           (*dst & 0xc1ff) == 0x0038 || // move.x ($xxxx.w), dX\r
+           (*dst & 0xf13f) == 0xb038)   // cmp.x ($xxxx.w), dX\r
+        return 1;\r
+      if (PicoAHW & (PAHW_MCD|PAHW_32X))\r
+        break;\r
+      // with no addons, there should be no need to wait\r
+      // for byte change anywhere\r
+      if ( (*dst & 0xfff8) == 0x4a10 || // tst.b ($aX)\r
+           (*dst & 0xfff8) == 0x4a28)   // tst.b ($xxxx,a0)\r
         return 1;\r
       break;\r
     case 6:\r
@@ -348,7 +361,9 @@ int SekIsIdleCode(unsigned short *dst, int bytes)
         return 1;\r
       break;\r
     case 12:\r
-       if ((*dst & 0xf1f8) == 0x3010 && // move.w (aX), dX\r
+      if (PicoAHW & (PAHW_MCD|PAHW_32X))\r
+        break;\r
+      if ( (*dst & 0xf1f8) == 0x3010 && // move.w (aX), dX\r
             (dst[1]&0xf100) == 0x0000 && // arithmetic\r
             (dst[3]&0xf100) == 0x0000)   // arithmetic\r
         return 1;\r
@@ -372,6 +387,7 @@ int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx)
   is_main68k = ctx == &PicoCpuFM68k;\r
 #endif\r
   pc &= ~0xff000000;\r
+  if (!(newop&0x200))\r
   elprintf(EL_IDLE, "idle: patch %06x %04x %04x %c %c #%i", pc, oldop, newop,\r
     (newop&0x200)?'n':'y', is_main68k?'m':'s', idledet_count);\r
 \r