fixes for idle and other stuff
[picodrive.git] / pico / sek.c
index 2fe77cb..5a7b707 100644 (file)
@@ -268,7 +268,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 +312,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 +327,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 +358,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 +384,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