platform ps2, handle audio similar to psp
[picodrive.git] / cpu / fame / famec_opcodes.h
index c690b45..7a7832c 100644 (file)
@@ -1,6 +1,6 @@
 
 #ifdef PICODRIVE_HACK
-#define NOT_POLLING g_m68kcontext->not_polling = 1;
+#define NOT_POLLING ctx->not_polling = 1;
 #else
 #define NOT_POLLING
 #endif
@@ -644,7 +644,7 @@ OPCODE(0x007C)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
 #ifdef USE_CYCLONE_TIMING
                RET(0)
 #else
@@ -1074,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
@@ -1302,8 +1298,12 @@ OPCODE(0x027C)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -1952,8 +1952,12 @@ OPCODE(0x0A7C)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -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
@@ -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;
@@ -16570,8 +16604,12 @@ OPCODE(0x46C0)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16599,8 +16637,12 @@ OPCODE(0x46D0)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16629,8 +16671,12 @@ OPCODE(0x46D8)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16659,8 +16705,12 @@ OPCODE(0x46E0)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16689,8 +16739,12 @@ OPCODE(0x46E8)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16719,8 +16773,12 @@ OPCODE(0x46F0)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16749,8 +16807,12 @@ OPCODE(0x46F8)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16778,8 +16840,12 @@ OPCODE(0x46F9)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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,8 +16874,12 @@ OPCODE(0x46FA)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16838,8 +16908,12 @@ OPCODE(0x46FB)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16864,8 +16938,12 @@ OPCODE(0x46FC)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16894,8 +16972,12 @@ OPCODE(0x46DF)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16924,8 +17006,12 @@ OPCODE(0x46E7)
        }
        else
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
 }
@@ -16936,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)
 }
@@ -16960,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)
@@ -16986,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)
@@ -17012,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)
@@ -17038,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)
@@ -17064,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)
@@ -17089,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)
@@ -17114,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)
@@ -17140,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)
@@ -17166,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)
@@ -17317,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
@@ -17349,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)
 }
 
@@ -17377,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
@@ -17409,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
@@ -17440,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
@@ -17471,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
@@ -17503,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)
 }
 
@@ -17530,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
@@ -17562,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)
 }
 
@@ -17590,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
@@ -17622,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
@@ -17653,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
@@ -17684,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
@@ -17716,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)
 }
 
@@ -18299,7 +18405,7 @@ OPCODE(0x4AD0)
        flag_NotZ = res;
        flag_N = res;
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18307,7 +18413,7 @@ OPCODE(0x4AD0)
 
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(18)
+RET(14)
 #else
 RET(8)
 #endif
@@ -18329,7 +18435,7 @@ OPCODE(0x4AD8)
        flag_N = res;
 
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18337,7 +18443,7 @@ OPCODE(0x4AD8)
 
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(18)
+RET(14)
 #else
 RET(8)
 #endif
@@ -18359,7 +18465,7 @@ OPCODE(0x4AE0)
        flag_N = res;
 
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18367,7 +18473,7 @@ OPCODE(0x4AE0)
 
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(20)
+RET(16)
 #else
 RET(10)
 #endif
@@ -18389,7 +18495,7 @@ OPCODE(0x4AE8)
        flag_N = res;
 
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18397,7 +18503,7 @@ OPCODE(0x4AE8)
 
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(22)
+RET(18)
 #else
 RET(12)
 #endif
@@ -18419,7 +18525,7 @@ OPCODE(0x4AF0)
        flag_N = res;
 
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18427,7 +18533,7 @@ OPCODE(0x4AF0)
 
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(24)
+RET(20)
 #else
 RET(14)
 #endif
@@ -18448,7 +18554,7 @@ OPCODE(0x4AF8)
        flag_N = res;
 
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18456,7 +18562,7 @@ OPCODE(0x4AF8)
 
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(22)
+RET(18)
 #else
 RET(12)
 #endif
@@ -18477,7 +18583,7 @@ OPCODE(0x4AF9)
        flag_N = res;
 
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18485,7 +18591,7 @@ OPCODE(0x4AF9)
 
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(26)
+RET(22)
 #else
 RET(16)
 #endif
@@ -18507,7 +18613,7 @@ OPCODE(0x4ADF)
        flag_N = res;
 
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18515,7 +18621,7 @@ OPCODE(0x4ADF)
 
        POST_IO
 #ifdef USE_CYCLONE_TIMING
-RET(18)
+RET(14)
 #else
 RET(8)
 #endif
@@ -18537,7 +18643,7 @@ OPCODE(0x4AE7)
        flag_N = res;
 
 #ifdef PICODRIVE_HACK
-       if (g_m68kcontext == &PicoCpuFS68k) {
+       if (ctx == &PicoCpuFS68k) {
                res |= 0x80;
                WRITE_BYTE_F(adr, res);
        }
@@ -18554,22 +18660,26 @@ RET(8)
 // ILLEGAL
 OPCODE(0x4AFC)
 {
-       SET_PC(execute_exception(M68K_ILLEGAL_INSTRUCTION_EX, GET_PC-2, GET_SR));
+#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)
 {
-       SET_PC(execute_exception(M68K_1010_EX, GET_PC-2, GET_SR));
+       SET_PC(execute_exception(ctx, M68K_1010_EX, GET_PC-2, GET_SR));
 RET(0)
 }
 
 // ILLEGAL F000-FFFF
 OPCODE(0xF000)
 {
-       SET_PC(execute_exception(M68K_1111_EX, GET_PC-2, GET_SR));
-RET(0) // 4 already taken by exc. handler
+       SET_PC(execute_exception(ctx, M68K_1111_EX, GET_PC-2, GET_SR));
+RET(0) 
 }
 
 // MOVEMaR
@@ -18595,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
@@ -18627,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)
 }
 
@@ -18655,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
@@ -18687,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
@@ -18718,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
@@ -18749,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
@@ -18781,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
@@ -18813,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
@@ -18845,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)
 }
 
@@ -18872,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
@@ -18904,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)
 }
 
@@ -18932,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
@@ -18964,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
@@ -18995,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
@@ -19026,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
@@ -19058,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
@@ -19090,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
@@ -19122,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)
 {
-       SET_PC(execute_exception(M68K_TRAP_BASE_EX + (Opcode & 0xF), GET_PC, GET_SR));
+       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
@@ -19200,8 +19314,12 @@ OPCODE(0x4E60)
 
        if (!flag_S)
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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;
@@ -19216,8 +19334,12 @@ OPCODE(0x4E68)
 
        if (!flag_S)
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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;
@@ -19232,11 +19354,15 @@ OPCODE(0x4E70)
 
        if (!flag_S)
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
@@ -19256,8 +19382,12 @@ OPCODE(0x4E72)
 
        if (!flag_S)
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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;
@@ -19268,7 +19398,7 @@ OPCODE(0x4E72)
                AREG(7) = ASP;
                ASP = res;
        }
-       m68kcontext.execinfo |= FM68K_HALTED;
+       ctx->execinfo |= FM68K_HALTED;
 RET0()
 }
 
@@ -19280,8 +19410,12 @@ OPCODE(0x4E73)
 
        if (!flag_S)
        {
-               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
+               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)
@@ -19294,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)
 }
@@ -19317,8 +19452,12 @@ RET(16)
 // TRAPV
 OPCODE(0x4E76)
 {
-       if (flag_V & 0x80)
-               SET_PC(execute_exception(M68K_TRAPV_EX, GET_PC, GET_SR));
+       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)
 }
 
@@ -19573,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(4)
        }
 RET(10)
 }
@@ -19589,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(8)
        }
        POST_IO
 RET(14)
@@ -19608,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(8)
        }
        POST_IO
 RET(14)
@@ -19628,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(10)
        }
        POST_IO
 RET(16)
@@ -19648,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(12)
        }
        POST_IO
 RET(18)
@@ -19668,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(14)
        }
        POST_IO
 RET(20)
@@ -19688,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(12)
        }
        POST_IO
 RET(18)
@@ -19707,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(16)
        }
        POST_IO
 RET(22)
@@ -19726,18 +19872,19 @@ RET(22)
 // CHK
 OPCODE(0x41BA)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(12)
        }
        POST_IO
 RET(18)
@@ -19746,18 +19893,19 @@ RET(18)
 // CHK
 OPCODE(0x41BB)
 {
-       u32 adr, res;
-       u32 src, dst;
+       s32 src, res;
+       u32 adr;
 
        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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(14)
        }
        POST_IO
 RET(20)
@@ -19766,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(8)
        }
        POST_IO
 RET(14)
@@ -19783,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(8)
        }
        POST_IO
 RET(14)
@@ -19803,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;
-               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
+               SET_PC(execute_exception(ctx, M68K_CHK_EX, GET_PC, GET_SR));
+RET(10)
        }
        POST_IO
 RET(16)
@@ -24004,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
@@ -25028,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)
 }
@@ -25042,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)
 }
@@ -25056,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)
 }
@@ -25070,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)
 }
@@ -25084,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)
 }
@@ -25098,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)
 }
@@ -25112,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)
 }
@@ -25126,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)
 }
@@ -25140,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)
 }
@@ -25154,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)
 }
@@ -25168,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)
 }
@@ -25182,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)
 }
@@ -25196,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)
 }
@@ -25210,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)
 }
@@ -26934,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)
@@ -26957,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;
@@ -26966,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
@@ -26986,6 +27133,7 @@ OPCODE(0x810F)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
@@ -26995,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
@@ -27015,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;
@@ -27024,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
@@ -27044,6 +27191,7 @@ OPCODE(0x8F0F)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
@@ -27053,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
@@ -27077,11 +27224,11 @@ OPCODE(0x80C0)
        src = DREGu16((Opcode >> 0) & 7);
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27095,7 +27242,7 @@ RET(10)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(140)
+RET(10)
 #else
 RET(70)
 #endif
@@ -27106,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
@@ -27125,11 +27272,11 @@ OPCODE(0x80D0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27143,7 +27290,7 @@ RET(14)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(14)
 #else
        RET(74)
 #endif
@@ -27154,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
@@ -27174,11 +27321,11 @@ OPCODE(0x80D8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27192,7 +27339,7 @@ RET(14)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(14)
 #else
        RET(74)
 #endif
@@ -27203,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
@@ -27223,11 +27370,11 @@ OPCODE(0x80E0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27241,7 +27388,7 @@ RET(16)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(146)
+RET(16)
 #else
        RET(76)
 #endif
@@ -27252,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
@@ -27272,11 +27419,11 @@ OPCODE(0x80E8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27290,7 +27437,7 @@ RET(18)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(18)
 #else
        RET(78)
 #endif
@@ -27301,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
@@ -27321,11 +27468,11 @@ OPCODE(0x80F0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27339,7 +27486,7 @@ RET(20)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(150)
+RET(20)
 #else
        RET(80)
 #endif
@@ -27350,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
@@ -27369,11 +27516,11 @@ OPCODE(0x80F8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27387,7 +27534,7 @@ RET(18)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(18)
 #else
        RET(78)
 #endif
@@ -27398,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
@@ -27417,11 +27564,11 @@ OPCODE(0x80F9)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27435,7 +27582,7 @@ RET(22)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(162)
+RET(22)
 #else
        RET(82)
 #endif
@@ -27446,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
@@ -27466,11 +27613,11 @@ OPCODE(0x80FA)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27484,7 +27631,7 @@ RET(18)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(148)
+RET(18)
 #else
        RET(78)
 #endif
@@ -27495,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
@@ -27515,11 +27662,11 @@ OPCODE(0x80FB)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27533,7 +27680,7 @@ RET(20)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(160)
+RET(20)
 #else
        RET(80)
 #endif
@@ -27544,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
@@ -27561,11 +27708,11 @@ OPCODE(0x80FC)
        FETCH_WORD(src);
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27579,7 +27726,7 @@ RET(14)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(14)
 #else
        RET(74)
 #endif
@@ -27590,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
@@ -27610,11 +27757,11 @@ OPCODE(0x80DF)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27628,7 +27775,7 @@ RET(14)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(144)
+RET(14)
 #else
        RET(74)
 #endif
@@ -27639,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
@@ -27659,11 +27806,11 @@ OPCODE(0x80E7)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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);
@@ -27677,7 +27824,7 @@ RET(16)
                {
                        flag_V = M68K_SR_V;
 #ifdef USE_CYCLONE_TIMING_DIV
-RET(146)
+RET(16)
 #else
        RET(76)
 #endif
@@ -27688,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
@@ -27705,11 +27852,12 @@ OPCODE(0x81C0)
        src = (s32)DREGs16((Opcode >> 0) & 7);
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -27719,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;
@@ -27733,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;
@@ -27743,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
@@ -27761,11 +27914,12 @@ OPCODE(0x81D0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -27775,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;
@@ -27789,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;
@@ -27799,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
@@ -27818,11 +27977,12 @@ OPCODE(0x81D8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -27832,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;
@@ -27846,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;
@@ -27856,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
@@ -27875,11 +28040,12 @@ OPCODE(0x81E0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -27889,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;
@@ -27903,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;
@@ -27913,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
@@ -27932,11 +28103,12 @@ OPCODE(0x81E8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -27946,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;
@@ -27960,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;
@@ -27970,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
@@ -27989,11 +28166,12 @@ OPCODE(0x81F0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -28003,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;
@@ -28017,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;
@@ -28027,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
@@ -28045,11 +28228,12 @@ OPCODE(0x81F8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -28059,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;
@@ -28073,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;
@@ -28083,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
@@ -28101,11 +28290,12 @@ OPCODE(0x81F9)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -28115,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;
@@ -28129,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;
@@ -28139,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
@@ -28158,11 +28353,12 @@ OPCODE(0x81FA)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -28172,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;
@@ -28186,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;
@@ -28196,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
@@ -28215,11 +28416,12 @@ OPCODE(0x81FB)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -28229,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;
@@ -28243,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;
@@ -28253,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
@@ -28269,11 +28476,12 @@ OPCODE(0x81FC)
        FETCH_SWORD(src);
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -28283,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;
@@ -28297,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;
@@ -28307,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
@@ -28326,11 +28539,12 @@ OPCODE(0x81DF)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -28340,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;
@@ -28354,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;
@@ -28364,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
@@ -28383,11 +28602,12 @@ OPCODE(0x81E7)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
+               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))
@@ -28397,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;
@@ -28411,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;
@@ -28421,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
@@ -28452,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);
@@ -30626,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);
@@ -34121,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;
@@ -34144,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;
@@ -34153,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)
@@ -34173,6 +34406,7 @@ OPCODE(0xC10F)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
@@ -34182,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)
@@ -34202,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;
@@ -34211,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)
@@ -34231,6 +34472,7 @@ OPCODE(0xCF0F)
 {
        u32 adr, res;
        u32 src, dst;
+       u32 corf = 0;
 
        adr = AREG(7) - 2;
        AREG(7) = adr;
@@ -34240,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)
@@ -34269,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
@@ -34292,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
@@ -34316,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
@@ -34340,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
@@ -34364,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
@@ -34388,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
@@ -34411,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
@@ -34434,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
@@ -34458,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
@@ -34482,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
@@ -34502,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
@@ -34526,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
@@ -34550,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
@@ -34570,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
@@ -34593,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
@@ -34617,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
@@ -34641,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
@@ -34665,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
@@ -34689,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
@@ -34712,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
@@ -34735,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
@@ -34759,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
@@ -34783,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
@@ -34803,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
@@ -34827,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
@@ -34851,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
@@ -34923,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);
@@ -37083,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);
@@ -37103,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);
@@ -37123,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);
@@ -37143,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);
@@ -37162,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);
@@ -37181,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);
@@ -37200,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));
@@ -37221,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));
@@ -37242,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)));
@@ -37264,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);
@@ -37284,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);
@@ -37304,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);
@@ -37324,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)
        {
@@ -37363,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;
@@ -37388,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;
@@ -37413,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);
@@ -37433,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);
@@ -37453,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);
@@ -37473,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));
@@ -37494,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));
@@ -37515,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));
@@ -37537,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);
@@ -37557,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);
@@ -37577,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);
@@ -37600,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;
@@ -37653,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;
@@ -37711,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;
@@ -37765,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;
@@ -37804,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;
@@ -37848,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;
@@ -37890,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;
@@ -37922,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;
@@ -37959,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;
@@ -37997,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));
@@ -38028,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;
@@ -38064,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;
@@ -38096,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;
@@ -38144,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;
@@ -38197,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;
@@ -38246,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;
@@ -38286,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;
@@ -38331,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;
@@ -38374,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;
@@ -38406,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;
@@ -38443,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)
@@ -38481,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;
@@ -38519,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;
@@ -38562,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;
@@ -40069,7 +40314,7 @@ OPCODE(idle_detector_bcc8)
        if (  Opcode & 0x0100)  newop |= 0x400; // beq
        if (!(Opcode & 0x0f00)) newop |= 0xc00; // bra
 
-       ret = SekRegisterIdlePatch(GET_PC - 2, Opcode, newop, &m68kcontext);
+       ret = SekRegisterIdlePatch(GET_PC - 2, Opcode, newop, ctx);
        switch (ret)
        {
                case 0: PC[-1] = newop; break;
@@ -40085,7 +40330,7 @@ end:
        if (cond_true)
        {
                PC = dest_pc;
-               m68kcontext.io_cycle_counter -= 2;
+               ctx->io_cycle_counter -= 2;
        }
 RET(8)
 }