idle loop hack, psp bugfix, plat debug str
[picodrive.git] / cpu / fame / famec_opcodes.h
index 03a64de..551d757 100644 (file)
@@ -19263,8 +19263,7 @@ OPCODE(0x4E72)
                ASP = res;
        }
        m68kcontext.execinfo |= FM68K_HALTED;
-       m68kcontext.io_cycle_counter = 0;
-RET(4)
+RET0()
 }
 
 // RTE
@@ -39961,3 +39960,100 @@ OPCODE(0xE7E7)
 RET(14)
 }
 
+#ifdef PICODRIVE_HACK
+#if 0
+#define UPDATE_IDLE_COUNT { \
+       extern int idle_hit_counter; \
+       idle_hit_counter++; \
+}
+#else
+#define UPDATE_IDLE_COUNT
+#endif
+
+// BRA
+OPCODE(0x6001_idle)
+{
+#ifdef FAMEC_CHECK_BRANCHES
+       u32 newPC = (u32)(PC) - BasePC;
+       s8 offs=Opcode;
+       newPC += offs;
+       SET_PC(newPC);
+       CHECK_BRANCH_EXCEPTION(offs)
+#else
+       PC += ((s8)(Opcode & 0xFE)) >> 1;
+#endif
+       UPDATE_IDLE_COUNT
+RET0()
+}
+
+// BCC
+OPCODE(0x6601_idle)
+{
+       if (flag_NotZ)
+       {
+               UPDATE_IDLE_COUNT
+               PC += ((s8)(Opcode & 0xFE)) >> 1;
+               //if (idle_hit)
+               RET0()
+       }
+RET(8)
+}
+
+OPCODE(0x6701_idle)
+{
+       if (!flag_NotZ)
+       {
+               UPDATE_IDLE_COUNT
+               PC += ((s8)(Opcode & 0xFE)) >> 1;
+               //if (idle_hit)
+               RET0()
+       }
+RET(8)
+}
+
+
+extern int SekIsIdleCode(unsigned short *dst, int bytes);
+extern int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx);
+
+OPCODE(idle_detector_bcc8)
+{
+       extern int idledet_start_frame;
+       extern char Pico[];
+       int frame_count, cond_true, bytes, ret, newop;
+       u16 *dest_pc;
+
+       dest_pc = PC + (((s8)(Opcode & 0xFE)) >> 1);
+
+       frame_count = *(int *)(Pico+0x22208+0x1c); // Pico.m.frame_count
+       if (frame_count < idledet_start_frame)
+               goto end;
+
+       bytes = 0 - (s8)(Opcode & 0xFE) - 2;
+       ret = SekIsIdleCode(dest_pc, bytes);
+       newop = (Opcode & 0xfe) | 0x7100;
+       if (!ret) newop |= 0x200;
+       if (  Opcode & 0x0100)  newop |= 0x400; // beq
+       if (!(Opcode & 0x0f00)) newop |= 0xc00; // bra
+
+       ret = SekRegisterIdlePatch(GET_PC - 2, Opcode, newop, &m68kcontext);
+       switch (ret)
+       {
+               case 0: PC[-1] = newop; break;
+               case 1: break;
+               case 2: JumpTable[Opcode] = (Opcode & 0x0f00) ?
+                               ((Opcode & 0x0100) ? CAST_OP(0x6701) : CAST_OP(0x6601)) :
+                               CAST_OP(0x6001); break;
+       }
+
+end:
+       if ((Opcode & 0xff00) == 0x6000) cond_true = 1;
+       else cond_true = (Opcode & 0x0100) ? !flag_NotZ : flag_NotZ; // beq?
+       if (cond_true)
+       {
+               PC = dest_pc;
+               m68kcontext.io_cycle_counter -= 2;
+       }
+RET(8)
+}
+
+#endif // PICODRIVE_HACK