platform ps2, handle audio similar to psp
[picodrive.git] / cpu / fame / famec_opcodes.h
index eeb3c2b..7a7832c 100644 (file)
@@ -1,4 +1,10 @@
 
+#ifdef PICODRIVE_HACK
+#define NOT_POLLING ctx->not_polling = 1;
+#else
+#define NOT_POLLING
+#endif
+
 // ORI
 OPCODE(0x0000)
 {
@@ -638,9 +644,7 @@ OPCODE(0x007C)
        }
        else
        {
-               u32 newPC = (u32)(PC) - BasePC;
-               SET_PC(newPC-2);
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
 #ifdef USE_CYCLONE_TIMING
                RET(0)
 #else
@@ -1070,11 +1074,7 @@ OPCODE(0x0280)
        flag_NotZ = res;
        flag_N = res >> 24;
        DREGu32((Opcode >> 0) & 7) = res;
-#ifdef USE_CYCLONE_TIMING
-RET(14)
-#else
 RET(16)
-#endif
 }
 
 // ANDI
@@ -1298,10 +1298,12 @@ OPCODE(0x027C)
        }
        else
        {
-               u32 newPC = (u32)(PC) - BasePC;
-               SET_PC(newPC-2);
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(20)
 }
@@ -1950,10 +1952,12 @@ OPCODE(0x0A7C)
        }
        else
        {
-               u32 newPC = (u32)(PC) - BasePC;
-               SET_PC(newPC-2);
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
                RET(0)
+#else
+               RET(4)
+#endif
        }
 RET(20)
 }
@@ -3832,7 +3836,7 @@ OPCODE(0x083A)
 
        FETCH_BYTE(src);
        src = 1 << (src & 7);
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -3849,7 +3853,7 @@ OPCODE(0x083B)
 
        FETCH_BYTE(src);
        src = 1 << (src & 7);
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -3904,7 +3908,12 @@ OPCODE(0x0840)
        flag_NotZ = res & src;
        res ^= src;
        DREGu32((Opcode >> 0) & 7) = res;
+#ifdef USE_CYCLONE_TIMING
+       if (src >> 16) ctx->io_cycle_counter -= 2;
+RET(10)
+#else
 RET(12)
+#endif
 }
 
 // BCHGn
@@ -4087,7 +4096,12 @@ OPCODE(0x0880)
        flag_NotZ = res & src;
        res &= ~src;
        DREGu32((Opcode >> 0) & 7) = res;
+#ifdef USE_CYCLONE_TIMING
+       if (src >> 16) ctx->io_cycle_counter -= 2;
+RET(12)
+#else
 RET(14)
+#endif
 }
 
 // BCLRn
@@ -4270,7 +4284,12 @@ OPCODE(0x08C0)
        flag_NotZ = res & src;
        res |= src;
        DREGu32((Opcode >> 0) & 7) = res;
+#ifdef USE_CYCLONE_TIMING
+       if (src >> 16) ctx->io_cycle_counter -= 2;
+RET(10)
+#else
 RET(12)
+#endif
 }
 
 // BSETn
@@ -4578,7 +4597,7 @@ OPCODE(0x013A)
 
        src = DREGu8((Opcode >> 9) & 7);
        src = 1 << (src & 7);
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -4595,7 +4614,7 @@ OPCODE(0x013B)
 
        src = DREGu8((Opcode >> 9) & 7);
        src = 1 << (src & 7);
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -4614,7 +4633,7 @@ OPCODE(0x013C)
        src = 1 << (src & 7);
        FETCH_BYTE(res);
        flag_NotZ = res & src;
-RET(8)
+RET(10)
 }
 
 // BTST
@@ -4663,7 +4682,12 @@ OPCODE(0x0140)
        flag_NotZ = res & src;
        res ^= src;
        DREGu32((Opcode >> 0) & 7) = res;
+#ifdef USE_CYCLONE_TIMING
+       if (src >> 16) ctx->io_cycle_counter -= 2;
+RET(6)
+#else
 RET(8)
+#endif
 }
 
 // BCHG
@@ -4846,7 +4870,12 @@ OPCODE(0x0180)
        flag_NotZ = res & src;
        res &= ~src;
        DREGu32((Opcode >> 0) & 7) = res;
+#ifdef USE_CYCLONE_TIMING
+       if (src >> 16) ctx->io_cycle_counter -= 2;
+RET(8)
+#else
 RET(10)
+#endif
 }
 
 // BCLR
@@ -5029,7 +5058,12 @@ OPCODE(0x01C0)
        flag_NotZ = res & src;
        res |= src;
        DREGu32((Opcode >> 0) & 7) = res;
+#ifdef USE_CYCLONE_TIMING
+       if (src >> 16) ctx->io_cycle_counter -= 2;
+RET(6)
+#else
 RET(8)
+#endif
 }
 
 // BSET
@@ -5484,8 +5518,8 @@ OPCODE(0x1008)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5504,8 +5538,8 @@ OPCODE(0x1088)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5527,8 +5561,8 @@ OPCODE(0x10C8)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5551,8 +5585,8 @@ OPCODE(0x1108)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5575,8 +5609,8 @@ OPCODE(0x1148)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5599,8 +5633,8 @@ OPCODE(0x1188)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5623,8 +5657,8 @@ OPCODE(0x11C8)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5646,8 +5680,8 @@ OPCODE(0x13C8)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5669,8 +5703,8 @@ OPCODE(0x1EC8)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -5693,8 +5727,8 @@ OPCODE(0x1F08)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        flag_C = 0;
@@ -7122,7 +7156,7 @@ OPCODE(0x103A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7141,7 +7175,7 @@ OPCODE(0x10BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7161,7 +7195,7 @@ OPCODE(0x10FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7182,7 +7216,7 @@ OPCODE(0x113A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7203,7 +7237,7 @@ OPCODE(0x117A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7224,7 +7258,7 @@ OPCODE(0x11BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7245,7 +7279,7 @@ OPCODE(0x11FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7265,7 +7299,7 @@ OPCODE(0x13FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7285,7 +7319,7 @@ OPCODE(0x1EFA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7306,7 +7340,7 @@ OPCODE(0x1F3A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7327,7 +7361,7 @@ OPCODE(0x103B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7346,7 +7380,7 @@ OPCODE(0x10BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7366,7 +7400,7 @@ OPCODE(0x10FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7387,7 +7421,7 @@ OPCODE(0x113B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7408,7 +7442,7 @@ OPCODE(0x117B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7429,7 +7463,7 @@ OPCODE(0x11BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7450,7 +7484,7 @@ OPCODE(0x11FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7470,7 +7504,7 @@ OPCODE(0x13FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7490,7 +7524,7 @@ OPCODE(0x1EFB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -7511,7 +7545,7 @@ OPCODE(0x1F3B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = (uptr)(PC) - BasePC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, res)
@@ -9896,7 +9930,7 @@ OPCODE(0x203A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -9915,7 +9949,7 @@ OPCODE(0x20BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -9935,7 +9969,7 @@ OPCODE(0x20FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -9956,7 +9990,7 @@ OPCODE(0x213A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -9977,7 +10011,7 @@ OPCODE(0x217A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -9998,7 +10032,7 @@ OPCODE(0x21BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10019,7 +10053,7 @@ OPCODE(0x21FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10039,7 +10073,7 @@ OPCODE(0x23FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10059,7 +10093,7 @@ OPCODE(0x2EFA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10080,7 +10114,7 @@ OPCODE(0x2F3A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10101,7 +10135,7 @@ OPCODE(0x203B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10120,7 +10154,7 @@ OPCODE(0x20BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10140,7 +10174,7 @@ OPCODE(0x20FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10161,7 +10195,7 @@ OPCODE(0x213B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10182,7 +10216,7 @@ OPCODE(0x217B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10203,7 +10237,7 @@ OPCODE(0x21BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10224,7 +10258,7 @@ OPCODE(0x21FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10244,7 +10278,7 @@ OPCODE(0x23FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10264,7 +10298,7 @@ OPCODE(0x2EFB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -10285,7 +10319,7 @@ OPCODE(0x2F3B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, res)
@@ -11023,7 +11057,7 @@ OPCODE(0x207A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_LONG_F(adr, res)
@@ -11038,7 +11072,7 @@ OPCODE(0x207B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_LONG_F(adr, res)
@@ -12865,7 +12899,7 @@ OPCODE(0x303A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -12884,7 +12918,7 @@ OPCODE(0x30BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -12904,7 +12938,7 @@ OPCODE(0x30FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -12925,7 +12959,7 @@ OPCODE(0x313A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -12946,7 +12980,7 @@ OPCODE(0x317A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -12967,7 +13001,7 @@ OPCODE(0x31BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -12988,7 +13022,7 @@ OPCODE(0x31FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13008,7 +13042,7 @@ OPCODE(0x33FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13028,7 +13062,7 @@ OPCODE(0x3EFA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13049,7 +13083,7 @@ OPCODE(0x3F3A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13070,7 +13104,7 @@ OPCODE(0x303B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13089,7 +13123,7 @@ OPCODE(0x30BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13109,7 +13143,7 @@ OPCODE(0x30FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13130,7 +13164,7 @@ OPCODE(0x313B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13151,7 +13185,7 @@ OPCODE(0x317B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13172,7 +13206,7 @@ OPCODE(0x31BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13193,7 +13227,7 @@ OPCODE(0x31FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13213,7 +13247,7 @@ OPCODE(0x33FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13233,7 +13267,7 @@ OPCODE(0x3EFB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13254,7 +13288,7 @@ OPCODE(0x3F3B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -13992,7 +14026,7 @@ OPCODE(0x307A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_WORD_F(adr, res)
@@ -14007,7 +14041,7 @@ OPCODE(0x307B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_WORD_F(adr, res)
@@ -16485,7 +16519,7 @@ OPCODE(0x44FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, res)
@@ -16500,7 +16534,7 @@ OPCODE(0x44FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, res)
@@ -16570,10 +16604,12 @@ OPCODE(0x46C0)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(12)
 }
@@ -16601,10 +16637,12 @@ OPCODE(0x46D0)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(16)
 }
@@ -16633,10 +16671,12 @@ OPCODE(0x46D8)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(16)
 }
@@ -16665,10 +16705,12 @@ OPCODE(0x46E0)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(18)
 }
@@ -16697,10 +16739,12 @@ OPCODE(0x46E8)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(20)
 }
@@ -16729,10 +16773,12 @@ OPCODE(0x46F0)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(22)
 }
@@ -16761,10 +16807,12 @@ OPCODE(0x46F8)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(20)
 }
@@ -16792,10 +16840,12 @@ OPCODE(0x46F9)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(24)
 }
@@ -16808,7 +16858,7 @@ OPCODE(0x46FA)
 
        if (flag_S)
        {
-               adr = GET_SWORD + ((u32)(PC) - BasePC);
+               adr = GET_SWORD + GET_PC;
                PC++;
                PRE_IO
                READ_WORD_F(adr, res)
@@ -16820,14 +16870,16 @@ OPCODE(0x46FA)
                        ASP = res;
                }
                POST_IO
-               CHECK_INT_TO_JUMP(24)
+               CHECK_INT_TO_JUMP(20)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(20)
 }
@@ -16840,7 +16892,7 @@ OPCODE(0x46FB)
 
        if (flag_S)
        {
-               adr = (u32)(PC) - BasePC;
+               adr = GET_PC;
                DECODE_EXT_WORD
                PRE_IO
                READ_WORD_F(adr, res)
@@ -16856,10 +16908,12 @@ OPCODE(0x46FB)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(22)
 }
@@ -16884,10 +16938,12 @@ OPCODE(0x46FC)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(16)
 }
@@ -16916,10 +16972,12 @@ OPCODE(0x46DF)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(16)
 }
@@ -16948,10 +17006,12 @@ OPCODE(0x46E7)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+               RET(0)
+#else
                RET(4)
+#endif
        }
 RET(18)
 }
@@ -16962,18 +17022,20 @@ OPCODE(0x4800)
        u32 adr, res;
        u32 src, dst;
 
-       res = DREGu8((Opcode >> 0) & 7);
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       dst = DREGu8((Opcode >> 0) & 7);
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       DREGu8((Opcode >> 0) & 7) = res;
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               DREGu8((Opcode >> 0) & 7) = res;
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
 RET(6)
 }
@@ -16986,18 +17048,20 @@ OPCODE(0x4810)
 
        adr = AREG((Opcode >> 0) & 7);
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(12)
@@ -17012,18 +17076,20 @@ OPCODE(0x4818)
        adr = AREG((Opcode >> 0) & 7);
        AREG((Opcode >> 0) & 7) += 1;
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(12)
@@ -17038,18 +17104,20 @@ OPCODE(0x4820)
        adr = AREG((Opcode >> 0) & 7) - 1;
        AREG((Opcode >> 0) & 7) = adr;
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(14)
@@ -17064,18 +17132,20 @@ OPCODE(0x4828)
        FETCH_SWORD(adr);
        adr += AREG((Opcode >> 0) & 7);
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(16)
@@ -17090,18 +17160,20 @@ OPCODE(0x4830)
        adr = AREG((Opcode >> 0) & 7);
        DECODE_EXT_WORD
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(18)
@@ -17115,18 +17187,20 @@ OPCODE(0x4838)
 
        FETCH_SWORD(adr);
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(16)
@@ -17140,18 +17214,20 @@ OPCODE(0x4839)
 
        FETCH_LONG(adr);
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(20)
@@ -17166,18 +17242,20 @@ OPCODE(0x481F)
        adr = AREG(7);
        AREG(7) += 2;
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(12)
@@ -17192,18 +17270,20 @@ OPCODE(0x4827)
        adr = AREG(7) - 2;
        AREG(7) = adr;
        PRE_IO
-       READ_BYTE_F(adr, res)
-       res = 0x9a - res - ((flag_X >> M68K_SR_X_SFT) & 1);
+       READ_BYTE_F(adr, dst)
+       res = -dst - ((flag_X >> M68K_SR_X_SFT) & 1);
 
-       if (res != 0x9a)
+       if (res != 0)
        {
-               if ((res & 0x0f) == 0xa) res = (res & 0xf0) + 0x10;
-               res &= 0xFF;
-       WRITE_BYTE_F(adr, res)
+               flag_V = res;
+               if (((res|dst) & 0x0f) == 0) res = (res & 0xf0) + 6;
+               res = (res + 0x9a) & 0xFF;
+               WRITE_BYTE_F(adr, res)
+               flag_V &= ~res;
                flag_NotZ |= res;
                flag_X = flag_C = M68K_SR_C;
        }
-       else flag_X = flag_C = 0;
+       else flag_V = flag_X = flag_C = 0;
        flag_N = res;
        POST_IO
 RET(14)
@@ -17282,7 +17362,7 @@ OPCODE(0x487A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        PUSH_32_F(adr)
@@ -17296,7 +17376,7 @@ OPCODE(0x487B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        PUSH_32_F(adr)
@@ -17343,7 +17423,7 @@ OPCODE(0x4890)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(8)
 #else
@@ -17375,7 +17455,7 @@ OPCODE(0x48A0)
        } while (res >>= 1);
        AREG((Opcode >> 0) & 7) = adr;
        POST_IO
-       m68kcontext.io_cycle_counter -= (dst - adr) * 2;
+       ctx->io_cycle_counter -= (dst - adr) * 2;
 RET(8)
 }
 
@@ -17403,7 +17483,7 @@ OPCODE(0x48A8)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(12)
 #else
@@ -17435,7 +17515,7 @@ OPCODE(0x48B0)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(14)
 #else
@@ -17466,7 +17546,7 @@ OPCODE(0x48B8)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(12)
 #else
@@ -17497,7 +17577,7 @@ OPCODE(0x48B9)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(16)
 #else
@@ -17529,7 +17609,7 @@ OPCODE(0x48A7)
        } while (res >>= 1);
        AREG(7) = adr;
        POST_IO
-       m68kcontext.io_cycle_counter -= (dst - adr) * 2;
+       ctx->io_cycle_counter -= (dst - adr) * 2;
 RET(8)
 }
 
@@ -17556,7 +17636,7 @@ OPCODE(0x48D0)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(8)
 #else
@@ -17588,7 +17668,7 @@ OPCODE(0x48E0)
        } while (res >>= 1);
        AREG((Opcode >> 0) & 7) = adr;
        POST_IO
-       m68kcontext.io_cycle_counter -= (dst - adr) * 2;
+       ctx->io_cycle_counter -= (dst - adr) * 2;
 RET(8)
 }
 
@@ -17616,7 +17696,7 @@ OPCODE(0x48E8)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(12)
 #else
@@ -17648,7 +17728,7 @@ OPCODE(0x48F0)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(14)
 #else
@@ -17679,7 +17759,7 @@ OPCODE(0x48F8)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(12)
 #else
@@ -17710,7 +17790,7 @@ OPCODE(0x48F9)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(16)
 #else
@@ -17742,7 +17822,7 @@ OPCODE(0x48E7)
        } while (res >>= 1);
        AREG(7) = adr;
        POST_IO
-       m68kcontext.io_cycle_counter -= (dst - adr) * 2;
+       ctx->io_cycle_counter -= (dst - adr) * 2;
 RET(8)
 }
 
@@ -18324,8 +18404,19 @@ OPCODE(0x4AD0)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
+#ifdef USE_CYCLONE_TIMING
+RET(14)
+#else
 RET(8)
+#endif
 }
 
 // TAS
@@ -18342,8 +18433,20 @@ OPCODE(0x4AD8)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
+#ifdef USE_CYCLONE_TIMING
+RET(14)
+#else
 RET(8)
+#endif
 }
 
 // TAS
@@ -18360,8 +18463,20 @@ OPCODE(0x4AE0)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
+#ifdef USE_CYCLONE_TIMING
+RET(16)
+#else
 RET(10)
+#endif
 }
 
 // TAS
@@ -18378,8 +18493,20 @@ OPCODE(0x4AE8)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
+#ifdef USE_CYCLONE_TIMING
+RET(18)
+#else
 RET(12)
+#endif
 }
 
 // TAS
@@ -18396,8 +18523,20 @@ OPCODE(0x4AF0)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
+#ifdef USE_CYCLONE_TIMING
+RET(20)
+#else
 RET(14)
+#endif
 }
 
 // TAS
@@ -18413,8 +18552,20 @@ OPCODE(0x4AF8)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
+#ifdef USE_CYCLONE_TIMING
+RET(18)
+#else
 RET(12)
+#endif
 }
 
 // TAS
@@ -18430,8 +18581,20 @@ OPCODE(0x4AF9)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
+#ifdef USE_CYCLONE_TIMING
+RET(22)
+#else
 RET(16)
+#endif
 }
 
 // TAS
@@ -18448,8 +18611,20 @@ OPCODE(0x4ADF)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
+#ifdef USE_CYCLONE_TIMING
+RET(14)
+#else
 RET(8)
+#endif
 }
 
 // TAS
@@ -18466,35 +18641,45 @@ OPCODE(0x4AE7)
        flag_V = 0;
        flag_NotZ = res;
        flag_N = res;
+
+#ifdef PICODRIVE_HACK
+       if (ctx == &PicoCpuFS68k) {
+               res |= 0x80;
+               WRITE_BYTE_F(adr, res);
+       }
+#endif
+
        POST_IO
-RET(10)
+#ifdef USE_CYCLONE_TIMING
+RET(20)
+#else
+RET(8)
+#endif
 }
 
 // ILLEGAL
 OPCODE(0x4AFC)
 {
-       u32 oldPC=GET_PC;
-       SET_PC(oldPC-2)
-       execute_exception(M68K_ILLEGAL_INSTRUCTION_EX);
+#ifdef PICODRIVE_HACK
+       extern void SekFinishIdleDet(void);
+       SekFinishIdleDet();
+#endif
+       SET_PC(execute_exception(ctx, M68K_ILLEGAL_INSTRUCTION_EX, GET_PC-2, GET_SR));
 RET(0)
 }
 
 // ILLEGAL A000-AFFF
 OPCODE(0xA000)
 {
-       u32 oldPC=GET_PC;
-       SET_PC(oldPC-2)
-       execute_exception(M68K_1010_EX);
+       SET_PC(execute_exception(ctx, M68K_1010_EX, GET_PC-2, GET_SR));
 RET(0)
 }
 
 // ILLEGAL F000-FFFF
 OPCODE(0xF000)
 {
-       u32 oldPC=GET_PC;
-       SET_PC(oldPC-2)
-       execute_exception(M68K_1111_EX);
-RET(0) // 4 already taken by exc. handler
+       SET_PC(execute_exception(ctx, M68K_1111_EX, GET_PC-2, GET_SR));
+RET(0) 
 }
 
 // MOVEMaR
@@ -18520,7 +18705,7 @@ OPCODE(0x4C90)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(12)
 #else
@@ -18552,7 +18737,7 @@ OPCODE(0x4C98)
        } while (res >>= 1);
        AREG((Opcode >> 0) & 7) = adr;
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 RET(12)
 }
 
@@ -18580,7 +18765,7 @@ OPCODE(0x4CA8)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(16)
 #else
@@ -18612,7 +18797,7 @@ OPCODE(0x4CB0)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(18)
 #else
@@ -18643,7 +18828,7 @@ OPCODE(0x4CB8)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(16)
 #else
@@ -18674,7 +18859,7 @@ OPCODE(0x4CB9)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(20)
 #else
@@ -18691,7 +18876,7 @@ OPCODE(0x4CBA)
        s32 *psrc;
 
        FETCH_WORD(res);
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        psrc = &DREGs32(0);
        dst = adr;
@@ -18706,7 +18891,7 @@ OPCODE(0x4CBA)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(16)
 #else
@@ -18723,7 +18908,7 @@ OPCODE(0x4CBB)
        s32 *psrc;
 
        FETCH_WORD(res);
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        psrc = &DREGs32(0);
        dst = adr;
@@ -18738,7 +18923,7 @@ OPCODE(0x4CBB)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(18)
 #else
@@ -18770,7 +18955,7 @@ OPCODE(0x4C9F)
        } while (res >>= 1);
        AREG(7) = adr;
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 RET(12)
 }
 
@@ -18797,7 +18982,7 @@ OPCODE(0x4CD0)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(12)
 #else
@@ -18829,7 +19014,7 @@ OPCODE(0x4CD8)
        } while (res >>= 1);
        AREG((Opcode >> 0) & 7) = adr;
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 RET(12)
 }
 
@@ -18857,7 +19042,7 @@ OPCODE(0x4CE8)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(16)
 #else
@@ -18889,7 +19074,7 @@ OPCODE(0x4CF0)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(18)
 #else
@@ -18920,7 +19105,7 @@ OPCODE(0x4CF8)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(16)
 #else
@@ -18951,7 +19136,7 @@ OPCODE(0x4CF9)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(20)
 #else
@@ -18968,7 +19153,7 @@ OPCODE(0x4CFA)
        u32 *psrc;
 
        FETCH_WORD(res);
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        psrc = &DREGu32(0);
        dst = adr;
@@ -18983,7 +19168,7 @@ OPCODE(0x4CFA)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(16)
 #else
@@ -19000,7 +19185,7 @@ OPCODE(0x4CFB)
        u32 *psrc;
 
        FETCH_WORD(res);
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        psrc = &DREGu32(0);
        dst = adr;
@@ -19015,7 +19200,7 @@ OPCODE(0x4CFB)
                psrc++;
        } while (res >>= 1);
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 #ifdef USE_CYCLONE_TIMING
 RET(18)
 #else
@@ -19047,15 +19232,19 @@ OPCODE(0x4CDF)
        } while (res >>= 1);
        AREG(7) = adr;
        POST_IO
-       m68kcontext.io_cycle_counter -= (adr - dst) * 2;
+       ctx->io_cycle_counter -= (adr - dst) * 2;
 RET(12)
 }
 
 // TRAP
 OPCODE(0x4E40)
 {
-       execute_exception(M68K_TRAP_BASE_EX + (Opcode & 0xF));
+       SET_PC(execute_exception(ctx, M68K_TRAP_BASE_EX + (Opcode & 0xF), GET_PC, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+RET(0)
+#else
 RET(4)
+#endif
 }
 
 // LINK
@@ -19125,10 +19314,12 @@ OPCODE(0x4E60)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+RET(0)
+#else
                RET(4)
+#endif
        }
        res = AREGu32((Opcode >> 0) & 7);
        ASP = res;
@@ -19143,10 +19334,12 @@ OPCODE(0x4E68)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+RET(0)
+#else
                RET(4)
+#endif
        }
        res = ASP;
        AREG((Opcode >> 0) & 7) = res;
@@ -19161,13 +19354,15 @@ OPCODE(0x4E70)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+RET(0)
+#else
                RET(4)
+#endif
        }
        PRE_IO
-       if (m68kcontext.reset_handler) m68kcontext.reset_handler();
+       if (ctx->reset_handler) ctx->reset_handler();
 //     CPU->Reset_CallBack();
        POST_IO
 RET(132)
@@ -19187,10 +19382,12 @@ OPCODE(0x4E72)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+RET(0)
+#else
                RET(4)
+#endif
        }
        FETCH_WORD(res);
        res &= M68K_SR_MASK;
@@ -19201,9 +19398,8 @@ OPCODE(0x4E72)
                AREG(7) = ASP;
                ASP = res;
        }
-       m68kcontext.execinfo |= FM68K_HALTED;
-       m68kcontext.io_cycle_counter = 0;
-RET(4)
+       ctx->execinfo |= FM68K_HALTED;
+RET0()
 }
 
 // RTE
@@ -19214,10 +19410,12 @@ OPCODE(0x4E73)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+RET(0)
+#else
                RET(4)
+#endif
        }
        PRE_IO
        POP_16_F(res)
@@ -19230,8 +19428,9 @@ OPCODE(0x4E73)
                AREG(7) = ASP;
                ASP = res;
        }
+       CHECK_BRANCH_EXCEPTION(res)
        POST_IO
-       m68kcontext.execinfo &= ~(FM68K_EMULATE_GROUP_0|FM68K_EMULATE_TRACE|FM68K_DO_TRACE);
+       ctx->execinfo &= ~(FM68K_EMULATE_GROUP_0|FM68K_EMULATE_TRACE|FM68K_DO_TRACE);
        CHECK_INT_TO_JUMP(20)
 RET(20)
 }
@@ -19253,8 +19452,12 @@ RET(16)
 // TRAPV
 OPCODE(0x4E76)
 {
-       if (flag_V & 0x80)
-               execute_exception(M68K_TRAPV_EX);
+       if (flag_V & 0x80) {
+               SET_PC(execute_exception(ctx, M68K_TRAPV_EX, GET_PC, GET_SR));
+#ifdef USE_CYCLONE_TIMING
+RET(0)
+#endif
+       }
 RET(4)
 }
 
@@ -19284,7 +19487,7 @@ OPCODE(0x4E90)
        {
                u32 oldPC;
 
-               oldPC = (u32)(PC) - BasePC;
+               oldPC = GET_PC;
        PRE_IO
                PUSH_32_F(oldPC)
        }
@@ -19305,7 +19508,7 @@ OPCODE(0x4EA8)
        {
                u32 oldPC;
 
-               oldPC = (u32)(PC) - BasePC;
+               oldPC = GET_PC;
        PRE_IO
                PUSH_32_F(oldPC)
        }
@@ -19326,7 +19529,7 @@ OPCODE(0x4EB0)
        {
                u32 oldPC;
 
-               oldPC = (u32)(PC) - BasePC;
+               oldPC = GET_PC;
        PRE_IO
                PUSH_32_F(oldPC)
        }
@@ -19346,7 +19549,7 @@ OPCODE(0x4EB8)
        {
                u32 oldPC;
 
-               oldPC = (u32)(PC) - BasePC;
+               oldPC = GET_PC;
        PRE_IO
                PUSH_32_F(oldPC)
        }
@@ -19366,7 +19569,7 @@ OPCODE(0x4EB9)
        {
                u32 oldPC;
 
-               oldPC = (u32)(PC) - BasePC;
+               oldPC = GET_PC;
        PRE_IO
                PUSH_32_F(oldPC)
        }
@@ -19382,12 +19585,12 @@ OPCODE(0x4EBA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        {
                u32 oldPC;
 
-               oldPC = (u32)(PC) - BasePC;
+               oldPC = GET_PC;
        PRE_IO
                PUSH_32_F(oldPC)
        }
@@ -19403,12 +19606,12 @@ OPCODE(0x4EBB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        {
                u32 oldPC;
 
-               oldPC = (u32)(PC) - BasePC;
+               oldPC = GET_PC;
        PRE_IO
                PUSH_32_F(oldPC)
        }
@@ -19486,7 +19689,7 @@ OPCODE(0x4EFA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        SET_PC(adr)
        CHECK_BRANCH_EXCEPTION(adr)
@@ -19499,7 +19702,7 @@ OPCODE(0x4EFB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        SET_PC(adr)
        CHECK_BRANCH_EXCEPTION(adr)
@@ -19509,15 +19712,15 @@ RET(14)
 // CHK
 OPCODE(0x4180)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
 
-       src = DREGu16((Opcode >> 0) & 7);
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       src = DREGs16((Opcode >> 0) & 7);
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(4)
        }
 RET(10)
 }
@@ -19525,17 +19728,18 @@ RET(10)
 // CHK
 OPCODE(0x4190)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        adr = AREG((Opcode >> 0) & 7);
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(8)
        }
        POST_IO
 RET(14)
@@ -19544,18 +19748,19 @@ RET(14)
 // CHK
 OPCODE(0x4198)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        adr = AREG((Opcode >> 0) & 7);
        AREG((Opcode >> 0) & 7) += 2;
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(8)
        }
        POST_IO
 RET(14)
@@ -19564,18 +19769,19 @@ RET(14)
 // CHK
 OPCODE(0x41A0)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        adr = AREG((Opcode >> 0) & 7) - 2;
        AREG((Opcode >> 0) & 7) = adr;
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(10)
        }
        POST_IO
 RET(16)
@@ -19584,18 +19790,19 @@ RET(16)
 // CHK
 OPCODE(0x41A8)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        FETCH_SWORD(adr);
        adr += AREG((Opcode >> 0) & 7);
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(12)
        }
        POST_IO
 RET(18)
@@ -19604,18 +19811,19 @@ RET(18)
 // CHK
 OPCODE(0x41B0)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        adr = AREG((Opcode >> 0) & 7);
        DECODE_EXT_WORD
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(14)
        }
        POST_IO
 RET(20)
@@ -19624,17 +19832,18 @@ RET(20)
 // CHK
 OPCODE(0x41B8)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        FETCH_SWORD(adr);
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(12)
        }
        POST_IO
 RET(18)
@@ -19643,17 +19852,18 @@ RET(18)
 // CHK
 OPCODE(0x41B9)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        FETCH_LONG(adr);
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(16)
        }
        POST_IO
 RET(22)
@@ -19662,18 +19872,19 @@ RET(22)
 // CHK
 OPCODE(0x41BA)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(12)
        }
        POST_IO
 RET(18)
@@ -19682,18 +19893,19 @@ RET(18)
 // CHK
 OPCODE(0x41BB)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(14)
        }
        POST_IO
 RET(20)
@@ -19702,15 +19914,16 @@ RET(20)
 // CHK
 OPCODE(0x41BC)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
-       FETCH_WORD(src);
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       FETCH_SWORD(src);
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(8)
        }
        POST_IO
 RET(14)
@@ -19719,18 +19932,19 @@ RET(14)
 // CHK
 OPCODE(0x419F)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        adr = AREG(7);
        AREG(7) += 2;
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(8)
        }
        POST_IO
 RET(14)
@@ -19739,18 +19953,19 @@ RET(14)
 // CHK
 OPCODE(0x41A7)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
        PRE_IO
-       READ_WORD_F(adr, src)
-       res = DREGu16((Opcode >> 9) & 7);
-       if (((s32)res < 0) || (res > src))
+       READSX_WORD_F(adr, src)
+       res = DREGs16((Opcode >> 9) & 7);
+       if ((res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(10)
        }
        POST_IO
 RET(16)
@@ -19824,7 +20039,7 @@ OPCODE(0x41FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        res = adr;
        AREG((Opcode >> 9) & 7) = res;
@@ -19837,7 +20052,7 @@ OPCODE(0x41FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        res = adr;
        AREG((Opcode >> 9) & 7) = res;
@@ -23240,6 +23455,8 @@ OPCODE(0x51C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        res = DREGu16((Opcode >> 0) & 7);
        res--;
        DREGu16((Opcode >> 0) & 7) = res;
@@ -23247,7 +23464,7 @@ OPCODE(0x51C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23263,6 +23480,8 @@ OPCODE(0x52C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if ((!flag_NotZ) || (flag_C & 0x100))
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23272,7 +23491,7 @@ OPCODE(0x52C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23294,6 +23513,8 @@ OPCODE(0x53C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (flag_NotZ && (!(flag_C & 0x100)))
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23303,7 +23524,7 @@ OPCODE(0x53C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23325,6 +23546,8 @@ OPCODE(0x54C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (flag_C & 0x100)
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23334,7 +23557,7 @@ OPCODE(0x54C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23356,6 +23579,8 @@ OPCODE(0x55C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (!(flag_C & 0x100))
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23365,7 +23590,7 @@ OPCODE(0x55C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23387,6 +23612,8 @@ OPCODE(0x56C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (!flag_NotZ)
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23396,7 +23623,7 @@ OPCODE(0x56C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23418,6 +23645,8 @@ OPCODE(0x57C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (flag_NotZ)
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23427,7 +23656,7 @@ OPCODE(0x57C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23449,6 +23678,8 @@ OPCODE(0x58C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (flag_V & 0x80)
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23458,7 +23689,7 @@ OPCODE(0x58C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23480,6 +23711,8 @@ OPCODE(0x59C8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (!(flag_V & 0x80))
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23489,7 +23722,7 @@ OPCODE(0x59C8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23511,6 +23744,8 @@ OPCODE(0x5AC8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (flag_N & 0x80)
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23520,7 +23755,7 @@ OPCODE(0x5AC8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23542,6 +23777,8 @@ OPCODE(0x5BC8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (!(flag_N & 0x80))
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23551,7 +23788,7 @@ OPCODE(0x5BC8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23573,6 +23810,8 @@ OPCODE(0x5CC8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if ((flag_N ^ flag_V) & 0x80)
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23582,7 +23821,7 @@ OPCODE(0x5CC8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23604,6 +23843,8 @@ OPCODE(0x5DC8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (!((flag_N ^ flag_V) & 0x80))
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23613,7 +23854,7 @@ OPCODE(0x5DC8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23635,6 +23876,8 @@ OPCODE(0x5EC8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if ((!flag_NotZ) || ((flag_N ^ flag_V) & 0x80))
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23644,7 +23887,7 @@ OPCODE(0x5EC8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23666,6 +23909,8 @@ OPCODE(0x5FC8)
        u32 adr, res;
        u32 src, dst;
 
+       NOT_POLLING
+
        if (flag_NotZ && (!((flag_N ^ flag_V) & 0x80)))
        {
        res = DREGu16((Opcode >> 0) & 7);
@@ -23675,7 +23920,7 @@ OPCODE(0x5FC8)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -23910,11 +24155,7 @@ OPCODE(0x5048)
        dst = AREGu32((Opcode >> 0) & 7);
        res = dst + src;
        AREG((Opcode >> 0) & 7) = res;
-#ifdef USE_CYCLONE_TIMING
-RET(4)
-#else
 RET(8)
-#endif
 }
 
 // ADDQ
@@ -24934,7 +25175,7 @@ OPCODE(0x6201)
        if (flag_NotZ && (!(flag_C & 0x100)))
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -24948,7 +25189,7 @@ OPCODE(0x6301)
        if ((!flag_NotZ) || (flag_C & 0x100))
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -24962,7 +25203,7 @@ OPCODE(0x6401)
        if (!(flag_C & 0x100))
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -24976,7 +25217,7 @@ OPCODE(0x6501)
        if (flag_C & 0x100)
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -24990,7 +25231,7 @@ OPCODE(0x6601)
        if (flag_NotZ)
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25004,7 +25245,7 @@ OPCODE(0x6701)
        if (!flag_NotZ)
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25018,7 +25259,7 @@ OPCODE(0x6801)
        if (!(flag_V & 0x80))
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25032,7 +25273,7 @@ OPCODE(0x6901)
        if (flag_V & 0x80)
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25046,7 +25287,7 @@ OPCODE(0x6A01)
        if (!(flag_N & 0x80))
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25060,7 +25301,7 @@ OPCODE(0x6B01)
        if (flag_N & 0x80)
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25074,7 +25315,7 @@ OPCODE(0x6C01)
        if (!((flag_N ^ flag_V) & 0x80))
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25088,7 +25329,7 @@ OPCODE(0x6D01)
        if ((flag_N ^ flag_V) & 0x80)
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25102,7 +25343,7 @@ OPCODE(0x6E01)
        if (flag_NotZ && (!((flag_N ^ flag_V) & 0x80)))
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25116,7 +25357,7 @@ OPCODE(0x6F01)
        if ((!flag_NotZ) || ((flag_N ^ flag_V) & 0x80))
        {
                PC += ((s8)(Opcode & 0xFE)) >> 1;
-       m68kcontext.io_cycle_counter -= 2;
+       ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }
@@ -25131,7 +25372,7 @@ OPCODE(0x6200)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25151,7 +25392,7 @@ OPCODE(0x6300)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25171,7 +25412,7 @@ OPCODE(0x6400)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25191,7 +25432,7 @@ OPCODE(0x6500)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25211,7 +25452,7 @@ OPCODE(0x6600)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25231,7 +25472,7 @@ OPCODE(0x6700)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25251,7 +25492,7 @@ OPCODE(0x6800)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25271,7 +25512,7 @@ OPCODE(0x6900)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25291,7 +25532,7 @@ OPCODE(0x6A00)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25311,7 +25552,7 @@ OPCODE(0x6B00)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25331,7 +25572,7 @@ OPCODE(0x6C00)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25351,7 +25592,7 @@ OPCODE(0x6D00)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25371,7 +25612,7 @@ OPCODE(0x6E00)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25391,7 +25632,7 @@ OPCODE(0x6F00)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25405,7 +25646,7 @@ RET(12)
 OPCODE(0x6001)
 {
 #ifdef FAMEC_CHECK_BRANCHES
-       u32 newPC = (u32)(PC) - BasePC;
+       u32 newPC = GET_PC;
        s8 offs=Opcode;
        newPC += offs;
        SET_PC(newPC);
@@ -25425,7 +25666,7 @@ OPCODE(0x6000)
        {
                u32 newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                newPC += GET_SWORD;
                SET_PC(newPC);
                CHECK_BRANCH_EXCEPTION(newPC)
@@ -25443,7 +25684,7 @@ OPCODE(0x6101)
 
        PRE_IO
 
-       oldPC = (u32)(PC) - BasePC;
+       oldPC = GET_PC;
        PUSH_32_F(oldPC)
 #ifdef FAMEC_CHECK_BRANCHES
        offs = Opcode;
@@ -25467,7 +25708,7 @@ OPCODE(0x6100)
        {
                u32 oldPC, newPC;
 
-               newPC = (u32)(PC) - BasePC;
+               newPC = GET_PC;
                oldPC = newPC + 2;
                PUSH_32_F(oldPC)
                newPC += GET_SWORD;
@@ -25658,7 +25899,7 @@ OPCODE(0x803A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -25679,7 +25920,7 @@ OPCODE(0x803B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -25920,7 +26161,7 @@ OPCODE(0x807A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, src)
@@ -25941,7 +26182,7 @@ OPCODE(0x807B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, src)
@@ -26182,7 +26423,7 @@ OPCODE(0x80BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, src)
@@ -26203,7 +26444,7 @@ OPCODE(0x80BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, src)
@@ -26840,19 +27081,19 @@ OPCODE(0x8100)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        src = DREGu8((Opcode >> 0) & 7);
        dst = DREGu8((Opcode >> 9) & 7);
        res = (dst & 0xF) - (src & 0xF) - ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res -= 6;
+       if (res > 0xF) corf = 6;
        res += (dst & 0xF0) - (src & 0xF0);
-       if (res > 0x99)
-       {
-               res += 0xA0;
-               flag_X = flag_C = M68K_SR_C;
-       }
-       else flag_X = flag_C = 0;
-       flag_NotZ |= res & 0xFF;
+       flag_V = res;
+       flag_X = flag_C = (s32)res < (s32)corf ? M68K_SR_C : 0;
+       if (res > 0xff) res += 0xA0;
+       res = (res - corf) & 0xFF;
+       flag_V &= ~res;
+       flag_NotZ |= res;
        flag_N = res;
        DREGu8((Opcode >> 9) & 7) = res;
 RET(6)
@@ -26863,6 +27104,7 @@ OPCODE(0x8108)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG((Opcode >> 0) & 7) - 1;
        AREG((Opcode >> 0) & 7) = adr;
@@ -26872,15 +27114,14 @@ OPCODE(0x8108)
        AREG((Opcode >> 9) & 7) = adr;
        READ_BYTE_F(adr, dst)
        res = (dst & 0xF) - (src & 0xF) - ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res -= 6;
+       if (res > 0xF) corf = 6;
        res += (dst & 0xF0) - (src & 0xF0);
-       if (res > 0x99)
-       {
-               res += 0xA0;
-               flag_X = flag_C = M68K_SR_C;
-       }
-       else flag_X = flag_C = 0;
-       flag_NotZ |= res & 0xFF;
+       flag_V = res;
+       flag_X = flag_C = (s32)res < (s32)corf ? M68K_SR_C : 0;
+       if (res > 0xff) res += 0xA0;
+       res = (res - corf) & 0xFF;
+       flag_V &= ~res;
+       flag_NotZ |= res;
        flag_N = res;
        WRITE_BYTE_F(adr, res)
        POST_IO
@@ -26892,6 +27133,7 @@ OPCODE(0x810F)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
@@ -26901,15 +27143,14 @@ OPCODE(0x810F)
        AREG((Opcode >> 9) & 7) = adr;
        READ_BYTE_F(adr, dst)
        res = (dst & 0xF) - (src & 0xF) - ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res -= 6;
+       if (res > 0xF) corf = 6;
        res += (dst & 0xF0) - (src & 0xF0);
-       if (res > 0x99)
-       {
-               res += 0xA0;
-               flag_X = flag_C = M68K_SR_C;
-       }
-       else flag_X = flag_C = 0;
-       flag_NotZ |= res & 0xFF;
+       flag_V = res;
+       flag_X = flag_C = (s32)res < (s32)corf ? M68K_SR_C : 0;
+       if (res > 0xff) res += 0xA0;
+       res = (res - corf) & 0xFF;
+       flag_V &= ~res;
+       flag_NotZ |= res;
        flag_N = res;
        WRITE_BYTE_F(adr, res)
        POST_IO
@@ -26921,6 +27162,7 @@ OPCODE(0x8F08)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG((Opcode >> 0) & 7) - 1;
        AREG((Opcode >> 0) & 7) = adr;
@@ -26930,15 +27172,14 @@ OPCODE(0x8F08)
        AREG(7) = adr;
        READ_BYTE_F(adr, dst)
        res = (dst & 0xF) - (src & 0xF) - ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res -= 6;
+       if (res > 0xF) corf = 6;
        res += (dst & 0xF0) - (src & 0xF0);
-       if (res > 0x99)
-       {
-               res += 0xA0;
-               flag_X = flag_C = M68K_SR_C;
-       }
-       else flag_X = flag_C = 0;
-       flag_NotZ |= res & 0xFF;
+       flag_V = res;
+       flag_X = flag_C = (s32)res < (s32)corf ? M68K_SR_C : 0;
+       if (res > 0xff) res += 0xA0;
+       res = (res - corf) & 0xFF;
+       flag_V &= ~res;
+       flag_NotZ |= res;
        flag_N = res;
        WRITE_BYTE_F(adr, res)
        POST_IO
@@ -26950,6 +27191,7 @@ OPCODE(0x8F0F)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
@@ -26959,15 +27201,14 @@ OPCODE(0x8F0F)
        AREG(7) = adr;
        READ_BYTE_F(adr, dst)
        res = (dst & 0xF) - (src & 0xF) - ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res -= 6;
+       if (res > 0xF) corf = 6;
        res += (dst & 0xF0) - (src & 0xF0);
-       if (res > 0x99)
-       {
-               res += 0xA0;
-               flag_X = flag_C = M68K_SR_C;
-       }
-       else flag_X = flag_C = 0;
-       flag_NotZ |= res & 0xFF;
+       flag_V = res;
+       flag_X = flag_C = (s32)res < (s32)corf ? M68K_SR_C : 0;
+       if (res > 0xff) res += 0xA0;
+       res = (res - corf) & 0xFF;
+       flag_V &= ~res;
+       flag_NotZ |= res;
        flag_N = res;
        WRITE_BYTE_F(adr, res)
        POST_IO
@@ -26983,11 +27224,11 @@ OPCODE(0x80C0)
        src = DREGu16((Opcode >> 0) & 7);
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(140)
+RET(4)
 #else
-RET(10)
+RET(14)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27001,7 +27242,7 @@ RET(10)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(140)
+RET(10)
 #else
 RET(70)
 #endif
@@ -27012,12 +27253,12 @@ RET(70)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(140)
+RET(138-BITCOUNT(res,q)*2)
 #else
 RET(90)
 #endif
+       }
 }
 
 // DIVU
@@ -27031,11 +27272,11 @@ OPCODE(0x80D0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(8)
 #else
-RET(14)
+RET(18)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27049,7 +27290,7 @@ RET(14)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(14)
 #else
        RET(74)
 #endif
@@ -27060,12 +27301,12 @@ RET(144)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(142-BITCOUNT(res,q)*2)
 #else
 RET(94)
 #endif
+       }
 }
 
 // DIVU
@@ -27080,11 +27321,11 @@ OPCODE(0x80D8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(8)
 #else
-RET(14)
+RET(18)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27098,7 +27339,7 @@ RET(14)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(14)
 #else
        RET(74)
 #endif
@@ -27109,12 +27350,12 @@ RET(144)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(142-BITCOUNT(res,q)*2)
 #else
 RET(94)
 #endif
+       }
 }
 
 // DIVU
@@ -27129,11 +27370,11 @@ OPCODE(0x80E0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(146)
+RET(10)
 #else
-RET(16)
+RET(20)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27147,7 +27388,7 @@ RET(16)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(146)
+RET(16)
 #else
        RET(76)
 #endif
@@ -27158,12 +27399,12 @@ RET(146)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(146)
+RET(144-BITCOUNT(res,q)*2)
 #else
 RET(96)
 #endif
+       }
 }
 
 // DIVU
@@ -27178,11 +27419,11 @@ OPCODE(0x80E8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(12)
 #else
-RET(18)
+RET(22)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27196,7 +27437,7 @@ RET(18)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(18)
 #else
        RET(78)
 #endif
@@ -27207,12 +27448,12 @@ RET(148)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(146-BITCOUNT(res,q)*2)
 #else
 RET(98)
 #endif
+       }
 }
 
 // DIVU
@@ -27227,11 +27468,11 @@ OPCODE(0x80F0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(150)
+RET(14)
 #else
-RET(20)
+RET(24)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27245,7 +27486,7 @@ RET(20)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(150)
+RET(20)
 #else
        RET(80)
 #endif
@@ -27256,12 +27497,12 @@ RET(150)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(150)
+RET(148-BITCOUNT(res,q)*2)
 #else
 RET(100)
 #endif
+       }
 }
 
 // DIVU
@@ -27275,11 +27516,11 @@ OPCODE(0x80F8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(12)
 #else
-RET(18)
+RET(22)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27293,7 +27534,7 @@ RET(18)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(18)
 #else
        RET(78)
 #endif
@@ -27304,12 +27545,12 @@ RET(148)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(146-BITCOUNT(res,q)*2)
 #else
 RET(98)
 #endif
+       }
 }
 
 // DIVU
@@ -27323,11 +27564,11 @@ OPCODE(0x80F9)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(162)
+RET(16)
 #else
-RET(22)
+RET(26)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27341,7 +27582,7 @@ RET(22)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(162)
+RET(22)
 #else
        RET(82)
 #endif
@@ -27352,12 +27593,12 @@ RET(162)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(162)
+RET(150-BITCOUNT(res,q)*2)
 #else
 RET(102)
 #endif
+       }
 }
 
 // DIVU
@@ -27366,17 +27607,17 @@ OPCODE(0x80FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(12)
 #else
-RET(18)
+RET(22)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27390,7 +27631,7 @@ RET(18)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(18)
 #else
        RET(78)
 #endif
@@ -27401,12 +27642,12 @@ RET(148)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(146-BITCOUNT(res,q)*2)
 #else
 RET(98)
 #endif
+       }
 }
 
 // DIVU
@@ -27415,17 +27656,17 @@ OPCODE(0x80FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(160)
+RET(14)
 #else
-RET(20)
+RET(24)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27439,7 +27680,7 @@ RET(20)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(160)
+RET(20)
 #else
        RET(80)
 #endif
@@ -27450,12 +27691,12 @@ RET(160)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(160)
+RET(148-BITCOUNT(res,q)*2)
 #else
 RET(100)
 #endif
+       }
 }
 
 // DIVU
@@ -27467,11 +27708,11 @@ OPCODE(0x80FC)
        FETCH_WORD(src);
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(8)
 #else
-RET(14)
+RET(18)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27485,7 +27726,7 @@ RET(14)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(14)
 #else
        RET(74)
 #endif
@@ -27496,12 +27737,12 @@ RET(144)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(142-BITCOUNT(res,q)*2)
 #else
 RET(94)
 #endif
+       }
 }
 
 // DIVU
@@ -27516,11 +27757,11 @@ OPCODE(0x80DF)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(8)
 #else
-RET(14)
+RET(18)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27534,7 +27775,7 @@ RET(14)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(14)
 #else
        RET(74)
 #endif
@@ -27545,12 +27786,12 @@ RET(144)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(142-BITCOUNT(res,q)*2)
 #else
 RET(94)
 #endif
+       }
 }
 
 // DIVU
@@ -27565,11 +27806,11 @@ OPCODE(0x80E7)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(146)
+RET(10)
 #else
-RET(16)
+RET(20)
 #endif
        }
        dst = DREGu32((Opcode >> 9) & 7);
@@ -27583,7 +27824,7 @@ RET(16)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(146)
+RET(16)
 #else
        RET(76)
 #endif
@@ -27594,12 +27835,12 @@ RET(146)
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(146)
+RET(144-BITCOUNT(res,q)*2)
 #else
 RET(96)
 #endif
+       }
 }
 
 // DIVS
@@ -27611,11 +27852,12 @@ OPCODE(0x81C0)
        src = (s32)DREGs16((Opcode >> 0) & 7);
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81C0;
+RET(4)
+#else
+               RET(14)
 #endif
-               RET(10)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -27625,9 +27867,10 @@ goto end81C0;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81C0;
-#endif
+RET(16+(dst>>31)*2)
+#else
        RET(50)
+#endif
        }
        {
                s32 q, r;
@@ -27639,9 +27882,12 @@ goto end81C0;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81C0;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(16+(dst>>31)*2)
+} else RET(152+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(80)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -27649,11 +27895,12 @@ goto end81C0;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81C0: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(152+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(108)
+#endif
+       }
 }
 
 // DIVS
@@ -27667,11 +27914,12 @@ OPCODE(0x81D0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81D0;
+RET(8)
+#else
+               RET(18)
 #endif
-               RET(14)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -27681,9 +27929,10 @@ goto end81D0;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81D0;
-#endif
+RET(20+(dst>>31)*2)
+#else
        RET(54)
+#endif
        }
        {
                s32 q, r;
@@ -27695,9 +27944,12 @@ goto end81D0;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81D0;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(20+(dst>>31)*2)
+} else RET(156+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(84)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -27705,11 +27957,12 @@ goto end81D0;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81D0: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(156+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(112)
+#endif
+       }
 }
 
 // DIVS
@@ -27724,11 +27977,12 @@ OPCODE(0x81D8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81D8;
+RET(8)
+#else
+               RET(18)
 #endif
-               RET(14)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -27738,9 +27992,10 @@ goto end81D8;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81D8;
-#endif
+RET(20+(dst>>31)*2)
+#else
        RET(54)
+#endif
        }
        {
                s32 q, r;
@@ -27752,9 +28007,12 @@ goto end81D8;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81D8;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(20+(dst>>31)*2)
+} else RET(156+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(84)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -27762,11 +28020,12 @@ goto end81D8;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81D8: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(156+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(112)
+#endif
+       }
 }
 
 // DIVS
@@ -27781,11 +28040,12 @@ OPCODE(0x81E0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E0;
+RET(10)
+#else
+               RET(20)
 #endif
-               RET(16)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -27795,9 +28055,10 @@ goto end81E0;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E0;
-#endif
+RET(22+(dst>>31)*2)
+#else
        RET(56)
+#endif
        }
        {
                s32 q, r;
@@ -27809,9 +28070,12 @@ goto end81E0;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E0;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(22+(dst>>31)*2)
+} else RET(158+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(86)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -27819,11 +28083,12 @@ goto end81E0;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81E0: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(158+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(114)
+#endif
+       }
 }
 
 // DIVS
@@ -27838,11 +28103,12 @@ OPCODE(0x81E8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E8;
+RET(12)
+#else
+               RET(22)
 #endif
-               RET(18)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -27852,9 +28118,10 @@ goto end81E8;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E8;
-#endif
+RET(24+(dst>>31)*2)
+#else
        RET(58)
+#endif
        }
        {
                s32 q, r;
@@ -27866,9 +28133,12 @@ goto end81E8;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E8;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(24+(dst>>31)*2)
+} else RET(160+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(88)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -27876,11 +28146,12 @@ goto end81E8;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81E8: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(160+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(116)
+#endif
+       }
 }
 
 // DIVS
@@ -27895,11 +28166,12 @@ OPCODE(0x81F0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F0;
+RET(14)
+#else
+               RET(24)
 #endif
-               RET(20)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -27909,9 +28181,10 @@ goto end81F0;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F0;
-#endif
+RET(26+(dst>>31)*2)
+#else
        RET(60)
+#endif
        }
        {
                s32 q, r;
@@ -27923,9 +28196,12 @@ goto end81F0;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F0;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(26+(dst>>31)*2)
+} else RET(162+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(90)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -27933,11 +28209,12 @@ goto end81F0;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81F0: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(162+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(118)
+#endif
+       }
 }
 
 // DIVS
@@ -27951,11 +28228,12 @@ OPCODE(0x81F8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F8;
+RET(12)
+#else
+               RET(22)
 #endif
-               RET(18)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -27965,9 +28243,10 @@ goto end81F8;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F8;
-#endif
+RET(24+(dst>>31)*2)
+#else
        RET(58)
+#endif
        }
        {
                s32 q, r;
@@ -27979,9 +28258,12 @@ goto end81F8;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F8;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(24+(dst>>31)*2)
+} else RET(160+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(88)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -27989,11 +28271,12 @@ goto end81F8;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81F8: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(160+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(116)
+#endif
+       }
 }
 
 // DIVS
@@ -28007,11 +28290,12 @@ OPCODE(0x81F9)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F9;
+RET(16)
+#else
+               RET(26)
 #endif
-               RET(22)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -28021,9 +28305,10 @@ goto end81F9;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F9;
-#endif
+RET(28+(dst>>31)*2)
+#else
        RET(62)
+#endif
        }
        {
                s32 q, r;
@@ -28035,9 +28320,12 @@ goto end81F9;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81F9;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(28+(dst>>31)*2)
+} else RET(164+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(92)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -28045,11 +28333,12 @@ goto end81F9;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81F9: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(164+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(120)
+#endif
+       }
 }
 
 // DIVS
@@ -28058,17 +28347,18 @@ OPCODE(0x81FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FA;
+RET(12)
+#else
+               RET(22)
 #endif
-               RET(18)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -28078,9 +28368,10 @@ goto end81FA;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FA;
-#endif
+RET(24+(dst>>31)*2)
+#else
        RET(58)
+#endif
        }
        {
                s32 q, r;
@@ -28092,9 +28383,12 @@ goto end81FA;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FA;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(24+(dst>>31)*2)
+} else RET(160+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(88)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -28102,11 +28396,12 @@ goto end81FA;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81FA: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(160+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(116)
+#endif
+       }
 }
 
 // DIVS
@@ -28115,17 +28410,18 @@ OPCODE(0x81FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FB;
+RET(14)
+#else
+               RET(24)
 #endif
-               RET(20)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -28135,9 +28431,10 @@ goto end81FB;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FB;
-#endif
+RET(26+(dst>>31)*2)
+#else
        RET(60)
+#endif
        }
        {
                s32 q, r;
@@ -28149,9 +28446,12 @@ goto end81FB;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FB;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(26+(dst>>31)*2)
+} else RET(162+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(90)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -28159,11 +28459,12 @@ goto end81FB;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81FB: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(162+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(118)
+#endif
+       }
 }
 
 // DIVS
@@ -28175,11 +28476,12 @@ OPCODE(0x81FC)
        FETCH_SWORD(src);
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FC;
+RET(8)
+#else
+               RET(18)
 #endif
-               RET(14)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -28189,9 +28491,10 @@ goto end81FC;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FC;
-#endif
+RET(20+(dst>>31)*2)
+#else
        RET(54)
+#endif
        }
        {
                s32 q, r;
@@ -28203,9 +28506,12 @@ goto end81FC;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81FC;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(20+(dst>>31)*2)
+} else RET(156+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(84)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -28213,11 +28519,12 @@ goto end81FC;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81FC: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(156+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(112)
+#endif
+       }
 }
 
 // DIVS
@@ -28232,11 +28539,12 @@ OPCODE(0x81DF)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81DF;
+RET(8)
+#else
+               RET(18)
 #endif
-               RET(14)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -28246,9 +28554,10 @@ goto end81DF;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81DF;
-#endif
+RET(20+(dst>>31)*2)
+#else
        RET(54)
+#endif
        }
        {
                s32 q, r;
@@ -28260,9 +28569,12 @@ goto end81DF;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81DF;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(20+(dst>>31)*2)
+} else RET(156+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(84)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -28270,11 +28582,12 @@ goto end81DF;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81DF: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(156+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(112)
+#endif
+       }
 }
 
 // DIVS
@@ -28289,11 +28602,12 @@ OPCODE(0x81E7)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(ctx, M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E7;
+RET(10)
+#else
+               RET(20)
 #endif
-               RET(16)
        }
        dst = DREGu32((Opcode >> 9) & 7);
        if ((dst == 0x80000000) && (src == (u32)-1))
@@ -28303,9 +28617,10 @@ goto end81E7;
                res = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E7;
-#endif
+RET(22+(dst>>31)*2)
+#else
        RET(56)
+#endif
        }
        {
                s32 q, r;
@@ -28317,9 +28632,12 @@ goto end81E7;
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-goto end81E7;
-#endif
+if (q > 0xFFFF || q < -0x10000) {
+       RET(22+(dst>>31)*2)
+} else RET(158+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
        RET(86)
+#endif
                }
                q &= 0x0000FFFF;
                flag_NotZ = q;
@@ -28327,11 +28645,12 @@ goto end81E7;
                flag_V = flag_C = 0;
                res = q | (r << 16);
        DREGu32((Opcode >> 9) & 7) = res;
-       }
 #ifdef USE_CYCLONE_TIMING_DIV
-end81E7: m68kcontext.io_cycle_counter -= 50;
-#endif
+RET(158+(dst>>31)*4-(q>>31)*2-BITCOUNT(res,abs(q))*2)
+#else
 RET(114)
+#endif
+       }
 }
 
 // SUBaD
@@ -28358,8 +28677,8 @@ OPCODE(0x9008)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        dst = DREGu8((Opcode >> 9) & 7);
@@ -28516,7 +28835,7 @@ OPCODE(0x903A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -28536,7 +28855,7 @@ OPCODE(0x903B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -28781,7 +29100,7 @@ OPCODE(0x907A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, src)
@@ -28801,7 +29120,7 @@ OPCODE(0x907B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, src)
@@ -29055,7 +29374,7 @@ OPCODE(0x90BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, src)
@@ -29076,7 +29395,7 @@ OPCODE(0x90BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, src)
@@ -30183,7 +30502,7 @@ OPCODE(0x90FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_WORD_F(adr, src)
@@ -30204,7 +30523,7 @@ OPCODE(0x90FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_WORD_F(adr, src)
@@ -30430,7 +30749,7 @@ OPCODE(0x91FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_LONG_F(adr, src)
@@ -30447,7 +30766,7 @@ OPCODE(0x91FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_LONG_F(adr, src)
@@ -30532,8 +30851,8 @@ OPCODE(0xB008)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        dst = DREGu8((Opcode >> 9) & 7);
@@ -30682,7 +31001,7 @@ OPCODE(0xB03A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -30701,7 +31020,7 @@ OPCODE(0xB03B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -30933,7 +31252,7 @@ OPCODE(0xB07A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, src)
@@ -30952,7 +31271,7 @@ OPCODE(0xB07B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, src)
@@ -31193,7 +31512,7 @@ OPCODE(0xB0BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, src)
@@ -31213,7 +31532,7 @@ OPCODE(0xB0BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, src)
@@ -32323,7 +32642,7 @@ OPCODE(0xB0FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_WORD_F(adr, src)
@@ -32343,7 +32662,7 @@ OPCODE(0xB0FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_WORD_F(adr, src)
@@ -32588,7 +32907,7 @@ OPCODE(0xB1FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_LONG_F(adr, src)
@@ -32608,7 +32927,7 @@ OPCODE(0xB1FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_LONG_F(adr, src)
@@ -32845,7 +33164,7 @@ OPCODE(0xC03A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -32866,7 +33185,7 @@ OPCODE(0xC03B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -33107,7 +33426,7 @@ OPCODE(0xC07A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, src)
@@ -33128,7 +33447,7 @@ OPCODE(0xC07B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, src)
@@ -33369,7 +33688,7 @@ OPCODE(0xC0BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, src)
@@ -33390,7 +33709,7 @@ OPCODE(0xC0BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, src)
@@ -34027,18 +34346,22 @@ OPCODE(0xC100)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        src = DREGu8((Opcode >> 0) & 7);
        dst = DREGu8((Opcode >> 9) & 7);
        res = (dst & 0xF) + (src & 0xF) + ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res += 6;
+       if (res > 9) corf = 6;
        res += (dst & 0xF0) + (src & 0xF0);
-       if (res > 0x99)
+       flag_V = ~res;
+       res += corf;
+       if (res > 0x9F)
        {
                res -= 0xA0;
                flag_X = flag_C = M68K_SR_C;
        }
        else flag_X = flag_C = 0;
+       flag_V &= res;
        flag_NotZ |= res & 0xFF;
        flag_N = res;
        DREGu8((Opcode >> 9) & 7) = res;
@@ -34050,6 +34373,7 @@ OPCODE(0xC108)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG((Opcode >> 0) & 7) - 1;
        AREG((Opcode >> 0) & 7) = adr;
@@ -34059,14 +34383,17 @@ OPCODE(0xC108)
        AREG((Opcode >> 9) & 7) = adr;
        READ_BYTE_F(adr, dst)
        res = (dst & 0xF) + (src & 0xF) + ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res += 6;
+       if (res > 9) corf = 6;
        res += (dst & 0xF0) + (src & 0xF0);
-       if (res > 0x99)
+       flag_V = ~res;
+       res += corf;
+       if (res > 0x9F)
        {
                res -= 0xA0;
                flag_X = flag_C = M68K_SR_C;
        }
        else flag_X = flag_C = 0;
+       flag_V &= res;
        flag_NotZ |= res & 0xFF;
        flag_N = res;
        WRITE_BYTE_F(adr, res)
@@ -34079,6 +34406,7 @@ OPCODE(0xC10F)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
@@ -34088,14 +34416,17 @@ OPCODE(0xC10F)
        AREG((Opcode >> 9) & 7) = adr;
        READ_BYTE_F(adr, dst)
        res = (dst & 0xF) + (src & 0xF) + ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res += 6;
+       if (res > 9) corf = 6;
        res += (dst & 0xF0) + (src & 0xF0);
-       if (res > 0x99)
+       flag_V = ~res;
+       res += corf;
+       if (res > 0x9F)
        {
                res -= 0xA0;
                flag_X = flag_C = M68K_SR_C;
        }
        else flag_X = flag_C = 0;
+       flag_V &= res;
        flag_NotZ |= res & 0xFF;
        flag_N = res;
        WRITE_BYTE_F(adr, res)
@@ -34108,6 +34439,7 @@ OPCODE(0xCF08)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG((Opcode >> 0) & 7) - 1;
        AREG((Opcode >> 0) & 7) = adr;
@@ -34117,14 +34449,17 @@ OPCODE(0xCF08)
        AREG(7) = adr;
        READ_BYTE_F(adr, dst)
        res = (dst & 0xF) + (src & 0xF) + ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res += 6;
+       if (res > 9) corf = 6;
        res += (dst & 0xF0) + (src & 0xF0);
-       if (res > 0x99)
+       flag_V = ~res;
+       res += corf;
+       if (res > 0x9F)
        {
                res -= 0xA0;
                flag_X = flag_C = M68K_SR_C;
        }
        else flag_X = flag_C = 0;
+       flag_V &= res;
        flag_NotZ |= res & 0xFF;
        flag_N = res;
        WRITE_BYTE_F(adr, res)
@@ -34137,6 +34472,7 @@ OPCODE(0xCF0F)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
@@ -34146,14 +34482,17 @@ OPCODE(0xCF0F)
        AREG(7) = adr;
        READ_BYTE_F(adr, dst)
        res = (dst & 0xF) + (src & 0xF) + ((flag_X >> M68K_SR_X_SFT) & 1);
-       if (res > 9) res += 6;
+       if (res > 9) corf = 6;
        res += (dst & 0xF0) + (src & 0xF0);
-       if (res > 0x99)
+       flag_V = ~res;
+       res += corf;
+       if (res > 0x9F)
        {
                res -= 0xA0;
                flag_X = flag_C = M68K_SR_C;
        }
        else flag_X = flag_C = 0;
+       flag_V &= res;
        flag_NotZ |= res & 0xFF;
        flag_N = res;
        WRITE_BYTE_F(adr, res)
@@ -34175,7 +34514,7 @@ OPCODE(0xC0C0)
        flag_V = flag_C = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING
-RET(54)
+RET(38+BITCOUNT(res,src)*2)
 #else
 RET(50)
 #endif
@@ -34198,7 +34537,7 @@ OPCODE(0xC0D0)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(58)
+RET(42+BITCOUNT(res,src)*2)
 #else
 RET(54)
 #endif
@@ -34222,7 +34561,7 @@ OPCODE(0xC0D8)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(58)
+RET(42+BITCOUNT(res,src)*2)
 #else
 RET(54)
 #endif
@@ -34246,7 +34585,7 @@ OPCODE(0xC0E0)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(60)
+RET(44+BITCOUNT(res,src)*2)
 #else
 RET(56)
 #endif
@@ -34270,7 +34609,7 @@ OPCODE(0xC0E8)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(62)
+RET(46+BITCOUNT(res,src)*2)
 #else
 RET(58)
 #endif
@@ -34294,7 +34633,7 @@ OPCODE(0xC0F0)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(64)
+RET(48+BITCOUNT(res,src)*2)
 #else
 RET(60)
 #endif
@@ -34317,7 +34656,7 @@ OPCODE(0xC0F8)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(62)
+RET(46+BITCOUNT(res,src)*2)
 #else
 RET(58)
 #endif
@@ -34340,7 +34679,7 @@ OPCODE(0xC0F9)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(66)
+RET(50+BITCOUNT(res,src)*2)
 #else
 RET(62)
 #endif
@@ -34352,7 +34691,7 @@ OPCODE(0xC0FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, src)
@@ -34364,7 +34703,7 @@ OPCODE(0xC0FA)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(62)
+RET(46+BITCOUNT(res,src)*2)
 #else
 RET(58)
 #endif
@@ -34376,7 +34715,7 @@ OPCODE(0xC0FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, src)
@@ -34388,7 +34727,7 @@ OPCODE(0xC0FB)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(64)
+RET(48+BITCOUNT(res,src)*2)
 #else
 RET(60)
 #endif
@@ -34408,7 +34747,7 @@ OPCODE(0xC0FC)
        flag_V = flag_C = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING
-RET(58)
+RET(42+BITCOUNT(res,src)*2)
 #else
 RET(54)
 #endif
@@ -34432,7 +34771,7 @@ OPCODE(0xC0DF)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(58)
+RET(42+BITCOUNT(res,src)*2)
 #else
 RET(54)
 #endif
@@ -34456,7 +34795,7 @@ OPCODE(0xC0E7)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(60)
+RET(44+BITCOUNT(res,src)*2)
 #else
 RET(56)
 #endif
@@ -34476,7 +34815,7 @@ OPCODE(0xC1C0)
        flag_V = flag_C = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING
-RET(54)
+RET(38+BITCOUNT(res,src^(src<<1)))
 #else
 RET(50)
 #endif
@@ -34499,7 +34838,7 @@ OPCODE(0xC1D0)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(58)
+RET(42+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(54)
 #endif
@@ -34523,7 +34862,7 @@ OPCODE(0xC1D8)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(58)
+RET(42+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(54)
 #endif
@@ -34547,7 +34886,7 @@ OPCODE(0xC1E0)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(60)
+RET(44+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(56)
 #endif
@@ -34571,7 +34910,7 @@ OPCODE(0xC1E8)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(62)
+RET(46+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(58)
 #endif
@@ -34595,7 +34934,7 @@ OPCODE(0xC1F0)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(64)
+RET(48+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(60)
 #endif
@@ -34618,7 +34957,7 @@ OPCODE(0xC1F8)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(62)
+RET(46+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(58)
 #endif
@@ -34641,7 +34980,7 @@ OPCODE(0xC1F9)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(66)
+RET(50+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(62)
 #endif
@@ -34653,7 +34992,7 @@ OPCODE(0xC1FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_WORD_F(adr, src)
@@ -34665,7 +35004,7 @@ OPCODE(0xC1FA)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(62)
+RET(46+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(58)
 #endif
@@ -34677,7 +35016,7 @@ OPCODE(0xC1FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_WORD_F(adr, src)
@@ -34689,7 +35028,7 @@ OPCODE(0xC1FB)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(64)
+RET(48+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(60)
 #endif
@@ -34709,7 +35048,7 @@ OPCODE(0xC1FC)
        flag_V = flag_C = 0;
        DREGu32((Opcode >> 9) & 7) = res;
 #ifdef USE_CYCLONE_TIMING
-RET(58)
+RET(42+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(54)
 #endif
@@ -34733,7 +35072,7 @@ OPCODE(0xC1DF)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(58)
+RET(42+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(54)
 #endif
@@ -34757,7 +35096,7 @@ OPCODE(0xC1E7)
        DREGu32((Opcode >> 9) & 7) = res;
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(60)
+RET(44+BITCOUNT(res,src^(src<<1))*2)
 #else
 RET(56)
 #endif
@@ -34829,8 +35168,8 @@ OPCODE(0xD008)
        u32 src, dst;
 
        // can't read byte from Ax registers !
-       m68kcontext.execinfo |= M68K_FAULTED;
-       m68kcontext.io_cycle_counter = 0;
+       ctx->execinfo |= M68K_FAULTED;
+       ctx->io_cycle_counter = 0;
 /*
        goto famec_Exec_End;
        dst = DREGu8((Opcode >> 9) & 7);
@@ -34987,7 +35326,7 @@ OPCODE(0xD03A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -35007,7 +35346,7 @@ OPCODE(0xD03B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_BYTE_F(adr, src)
@@ -35252,7 +35591,7 @@ OPCODE(0xD07A)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_WORD_F(adr, src)
@@ -35272,7 +35611,7 @@ OPCODE(0xD07B)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_WORD_F(adr, src)
@@ -35526,7 +35865,7 @@ OPCODE(0xD0BA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READ_LONG_F(adr, src)
@@ -35547,7 +35886,7 @@ OPCODE(0xD0BB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READ_LONG_F(adr, src)
@@ -36654,7 +36993,7 @@ OPCODE(0xD0FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_WORD_F(adr, src)
@@ -36675,7 +37014,7 @@ OPCODE(0xD0FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_WORD_F(adr, src)
@@ -36901,7 +37240,7 @@ OPCODE(0xD1FA)
        u32 adr, res;
        u32 src, dst;
 
-       adr = GET_SWORD + ((u32)(PC) - BasePC);
+       adr = GET_SWORD + GET_PC;
        PC++;
        PRE_IO
        READSX_LONG_F(adr, src)
@@ -36918,7 +37257,7 @@ OPCODE(0xD1FB)
        u32 adr, res;
        u32 src, dst;
 
-       adr = (u32)(PC) - BasePC;
+       adr = GET_PC;
        DECODE_EXT_WORD
        PRE_IO
        READSX_LONG_F(adr, src)
@@ -36989,7 +37328,7 @@ OPCODE(0xE000)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = (s32)DREGs8((Opcode >> 0) & 7);
        flag_V = 0;
        flag_X = flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37009,7 +37348,7 @@ OPCODE(0xE040)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = (s32)DREGs16((Opcode >> 0) & 7);
        flag_V = 0;
        flag_X = flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37029,7 +37368,7 @@ OPCODE(0xE080)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = (s32)DREGs32((Opcode >> 0) & 7);
        flag_V = 0;
        flag_X = flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37049,7 +37388,7 @@ OPCODE(0xE008)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu8((Opcode >> 0) & 7);
        flag_N = flag_V = 0;
        flag_X = flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37068,7 +37407,7 @@ OPCODE(0xE048)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu16((Opcode >> 0) & 7);
        flag_N = flag_V = 0;
        flag_X = flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37087,7 +37426,7 @@ OPCODE(0xE088)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu32((Opcode >> 0) & 7);
        flag_N = flag_V = 0;
        flag_X = flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37106,7 +37445,7 @@ OPCODE(0xE010)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu8((Opcode >> 0) & 7);
        src |= (flag_X & M68K_SR_X) << 0;
        res = (src >> sft) | (src << (9 - sft));
@@ -37127,7 +37466,7 @@ OPCODE(0xE050)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu16((Opcode >> 0) & 7);
        src |= (flag_X & M68K_SR_X) << 8;
        res = (src >> sft) | (src << (17 - sft));
@@ -37148,7 +37487,7 @@ OPCODE(0xE090)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu32((Opcode >> 0) & 7);
        flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
        if (sft == 1) res = (src >> 1) | ((flag_X & M68K_SR_X) << (32 - (M68K_SR_X_SFT + 1)));
@@ -37170,7 +37509,7 @@ OPCODE(0xE018)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu8((Opcode >> 0) & 7);
        flag_V = 0;
        flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37190,7 +37529,7 @@ OPCODE(0xE058)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu16((Opcode >> 0) & 7);
        flag_V = 0;
        flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37210,7 +37549,7 @@ OPCODE(0xE098)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu32((Opcode >> 0) & 7);
        flag_V = 0;
        flag_C = src << ((M68K_SR_C_SFT + 1) - sft);
@@ -37230,7 +37569,7 @@ OPCODE(0xE100)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu8((Opcode >> 0) & 7);
        if (sft < 8)
        {
@@ -37269,7 +37608,7 @@ OPCODE(0xE140)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu16((Opcode >> 0) & 7);
                flag_X = flag_C = src >> (8 - sft);
                res = src << sft;
@@ -37294,7 +37633,7 @@ OPCODE(0xE180)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu32((Opcode >> 0) & 7);
                flag_X = flag_C = src >> (24 - sft);
                res = src << sft;
@@ -37319,7 +37658,7 @@ OPCODE(0xE108)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu8((Opcode >> 0) & 7);
        flag_V = 0;
        flag_X = flag_C = src << (0 + sft);
@@ -37339,7 +37678,7 @@ OPCODE(0xE148)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu16((Opcode >> 0) & 7);
        flag_V = 0;
        flag_X = flag_C = src >> (8 - sft);
@@ -37359,7 +37698,7 @@ OPCODE(0xE188)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu32((Opcode >> 0) & 7);
        flag_V = 0;
        flag_X = flag_C = src >> (24 - sft);
@@ -37379,7 +37718,7 @@ OPCODE(0xE110)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu8((Opcode >> 0) & 7);
        src |= (flag_X & M68K_SR_X) << 0;
        res = (src << sft) | (src >> (9 - sft));
@@ -37400,7 +37739,7 @@ OPCODE(0xE150)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu16((Opcode >> 0) & 7);
        src |= (flag_X & M68K_SR_X) << 8;
        res = (src << sft) | (src >> (17 - sft));
@@ -37421,7 +37760,7 @@ OPCODE(0xE190)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu32((Opcode >> 0) & 7);
        flag_C = src >> ((32 - M68K_SR_C_SFT) - sft);
        if (sft == 1) res = (src << 1) | ((flag_X & M68K_SR_X) >> ((M68K_SR_X_SFT + 1) - 1));
@@ -37443,7 +37782,7 @@ OPCODE(0xE118)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu8((Opcode >> 0) & 7);
        flag_V = 0;
        flag_C = src << (0 + sft);
@@ -37463,7 +37802,7 @@ OPCODE(0xE158)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu16((Opcode >> 0) & 7);
        flag_V = 0;
        flag_C = src >> (8 - sft);
@@ -37483,7 +37822,7 @@ OPCODE(0xE198)
        u32 sft;
 
        sft = (((Opcode >> 9) - 1) & 7) + 1;
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
        src = DREGu32((Opcode >> 0) & 7);
        flag_V = 0;
        flag_C = src >> (24 - sft);
@@ -37506,7 +37845,7 @@ OPCODE(0xE020)
        src = (s32)DREGs8((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft < 8)
                {
                        flag_V = 0;
@@ -37559,7 +37898,7 @@ OPCODE(0xE060)
        src = (s32)DREGs16((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft < 16)
                {
                        flag_V = 0;
@@ -37617,7 +37956,7 @@ OPCODE(0xE0A0)
        src = (s32)DREGs32((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft < 32)
                {
                        flag_V = 0;
@@ -37671,7 +38010,7 @@ OPCODE(0xE028)
        src = DREGu8((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft <= 8)
                {
                        flag_N = flag_V = 0;
@@ -37710,7 +38049,7 @@ OPCODE(0xE068)
        src = DREGu16((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft <= 16)
                {
                        flag_N = flag_V = 0;
@@ -37754,7 +38093,7 @@ OPCODE(0xE0A8)
        src = DREGu32((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft < 32)
                {
                        flag_N = flag_V = 0;
@@ -37796,7 +38135,7 @@ OPCODE(0xE030)
        src = DREGu8((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft %= 9;
 
                src |= (flag_X & M68K_SR_X) << 0;
@@ -37828,7 +38167,7 @@ OPCODE(0xE070)
        src = DREGu16((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft %= 17;
 
                src |= (flag_X & M68K_SR_X) << 8;
@@ -37865,14 +38204,14 @@ OPCODE(0xE0B0)
        src = DREGu32((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft %= 33;
 
                if (sft != 0)
                {
                        if (sft == 1) res = (src >> 1) | ((flag_X & M68K_SR_X) << (32 - (M68K_SR_X_SFT + 1)));
                        else res = (src >> sft) | (src << (33 - sft)) | (((flag_X & M68K_SR_X) << (32 - (M68K_SR_X_SFT + 1))) >> (sft - 1));
-                       flag_X = (src >> (32 - sft)) << M68K_SR_X_SFT;
+                       flag_X = (src >> (sft - 1)) << M68K_SR_X_SFT;
                }
                else res = src;
                flag_C = flag_X;
@@ -37903,7 +38242,7 @@ OPCODE(0xE038)
        src = DREGu8((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft &= 0x07;
 
                flag_C = src << (M68K_SR_C_SFT - ((sft - 1) & 7));
@@ -37934,7 +38273,7 @@ OPCODE(0xE078)
        src = DREGu16((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft &= 0x0F;
 
                flag_C = (src >> ((sft - 1) & 15)) << M68K_SR_C_SFT;
@@ -37970,7 +38309,7 @@ OPCODE(0xE0B8)
        src = DREGu32((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft &= 0x1F;
 
                flag_C = (src >> ((sft - 1) & 31)) << M68K_SR_C_SFT;
@@ -38002,7 +38341,7 @@ OPCODE(0xE120)
        src = DREGu8((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft < 8)
                {
                        flag_X = flag_C = (src << sft) >> 0;
@@ -38050,7 +38389,7 @@ OPCODE(0xE160)
        src = DREGu16((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft < 16)
                {
                        flag_X = flag_C = (src << sft) >> 8;
@@ -38103,7 +38442,7 @@ OPCODE(0xE1A0)
        src = DREGu32((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft < 32)
                {
                        flag_X = flag_C = (src >> (32 - sft)) << M68K_SR_C_SFT;
@@ -38152,7 +38491,7 @@ OPCODE(0xE128)
        src = DREGu8((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft <= 8)
                {
                        flag_X = flag_C = (src << sft) >> 0;
@@ -38192,7 +38531,7 @@ OPCODE(0xE168)
        src = DREGu16((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft <= 16)
                {
                        flag_X = flag_C = (src << sft) >> 8;
@@ -38237,7 +38576,7 @@ OPCODE(0xE1A8)
        src = DREGu32((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft < 32)
                {
                        flag_X = flag_C = (src >> (32 - sft)) << M68K_SR_C_SFT;
@@ -38280,7 +38619,7 @@ OPCODE(0xE130)
        src = DREGu8((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft %= 9;
 
                src |= (flag_X & M68K_SR_X) << 0;
@@ -38312,7 +38651,7 @@ OPCODE(0xE170)
        src = DREGu16((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft %= 17;
 
                src |= (flag_X & M68K_SR_X) << 8;
@@ -38349,7 +38688,7 @@ OPCODE(0xE1B0)
        src = DREGu32((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                sft %= 33;
 
                if (sft != 0)
@@ -38387,7 +38726,7 @@ OPCODE(0xE138)
        src = DREGu8((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft &= 0x07)
                {
                        flag_C = (src << sft) >> 0;
@@ -38425,7 +38764,7 @@ OPCODE(0xE178)
        src = DREGu16((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft &= 0x0F)
                {
                        flag_C = (src << sft) >> 8;
@@ -38468,7 +38807,7 @@ OPCODE(0xE1B8)
        src = DREGu32((Opcode >> 0) & 7);
        if (sft)
        {
-       m68kcontext.io_cycle_counter -= sft * 2;
+       ctx->io_cycle_counter -= sft * 2;
                if (sft &= 0x1F)
                {
                        flag_C = (src >> (32 - sft)) << M68K_SR_C_SFT;
@@ -39902,3 +40241,98 @@ 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 = GET_PC;
+       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 SekIsIdleReady(void);
+extern int SekIsIdleCode(unsigned short *dst, int bytes);
+extern int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx);
+
+OPCODE(idle_detector_bcc8)
+{
+       int frame_count, cond_true, bytes, ret, newop;
+       u16 *dest_pc;
+
+       dest_pc = PC + (((s8)(Opcode & 0xFE)) >> 1);
+
+       if (!SekIsIdleReady())
+               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, ctx);
+       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;
+               ctx->io_cycle_counter -= 2;
+       }
+RET(8)
+}
+
+#endif // PICODRIVE_HACK