bugfixes, famec tuning
authornotaz <notasas@gmail.com>
Tue, 30 Oct 2007 21:49:39 +0000 (21:49 +0000)
committernotaz <notasas@gmail.com>
Tue, 30 Oct 2007 21:49:39 +0000 (21:49 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@287 be3aeb3a-fb24-0410-a615-afba39da0efa

Pico/Cart.c
cpu/fame/famec.c
cpu/fame/famec_opcodes.h

index cf33580..cf16951 100644 (file)
@@ -48,7 +48,7 @@ pm_file *pm_open(const char *path)
 \r
         ext = zipentry->name+strlen(zipentry->name)-3;\r
         for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)\r
-          if (!strcasecmp(ext, rom_exts[i]) == 0) goto found_rom_zip;\r
+          if (strcasecmp(ext, rom_exts[i]) == 0) goto found_rom_zip;\r
       }\r
 \r
       /* zipfile given, but nothing found suitable for us inside */\r
index 76965fa..11d2cb2 100644 (file)
 // Options //\r
 #define FAMEC_ROLL_INLINE\r
 #define FAMEC_EMULATE_TRACE\r
-#define FAMEC_IRQ_CYCLES\r
 #define FAMEC_CHECK_BRANCHES\r
-// #define FAMEC_USE_DATA_BANKS\r
-// #define FAMEC_EXTRA_INLINE\r
+#define FAMEC_EXTRA_INLINE\r
 // #define FAMEC_DEBUG\r
-#define FAMEC_NO_GOTOS\r
+//#define FAMEC_NO_GOTOS\r
 #define FAMEC_ADR_BITS  24\r
 // #define FAMEC_FETCHBITS 8\r
 #define FAMEC_DATABITS  8\r
@@ -41,6 +39,7 @@
 #ifndef FAMEC_EXTRA_INLINE\r
 #define FAMEC_EXTRA_INLINE\r
 #else\r
+#undef FAMEC_EXTRA_INLINE\r
 #define FAMEC_EXTRA_INLINE INLINE\r
 #endif\r
 \r
@@ -84,17 +83,6 @@ typedef unsigned int u32;
 typedef signed int     s32;\r
 */\r
 \r
-#ifdef FAMEC_EMULATE_TRACE\r
-static u32 flag_T;\r
-#endif\r
-static u32 flag_C;\r
-static u32 flag_V;\r
-static u32 flag_NotZ;\r
-static u32 flag_N;\r
-static u32 flag_X;         // 16 bytes aligned\r
-static u32 flag_S;\r
-static u32 flag_I;\r
-\r
 #ifndef M68K_OK\r
     #define M68K_OK 0\r
 #endif\r
@@ -288,22 +276,27 @@ static u32 flag_I;
 #define M68K_PPL (m68kcontext.sr >> 8) & 7\r
 \r
 #define GET_PC                  \\r
-       (u32)PC - BasePC;\r
+       ((u32)PC - BasePC)\r
 \r
 \r
 #ifndef FAMEC_32BIT_PC\r
 \r
 #define SET_PC(A)               \\r
-    BasePC = g_m68kcontext->Fetch[((A) >> M68K_FETCHSFT) & M68K_FETCHMASK];    \\r
-   /*  BasePC -= (A) & 0xFF000000; */   \\r
-    PC = (u16*)(((A) & M68K_ADR_MASK) + BasePC);\r
+{ \\r
+    u32 pc = A; \\r
+    BasePC = m68kcontext.Fetch[(pc >> M68K_FETCHSFT) & M68K_FETCHMASK];    \\r
+    PC = (u16*)((pc & M68K_ADR_MASK) + BasePC);        \\r
+}\r
 \r
 #else\r
 \r
 #define SET_PC(A)               \\r
-    BasePC = g_m68kcontext->Fetch[((A) >> M68K_FETCHSFT) & M68K_FETCHMASK];    \\r
-    BasePC -= (A) & 0xFF000000;    \\r
-    PC = (u16*)((A) + BasePC);\r
+{ \\r
+    u32 pc = A; \\r
+    BasePC = m68kcontext.Fetch[(pc >> M68K_FETCHSFT) & M68K_FETCHMASK];    \\r
+    BasePC -= pc & 0xFF000000;    \\r
+    PC = (u16*)(pc + BasePC); \\r
+}\r
 \r
 #endif\r
 \r
@@ -473,7 +466,7 @@ static u32 flag_I;
        if (interrupt_chk__()) \\r
        { \\r
                cycles_needed=m68kcontext.io_cycle_counter-(CLK); \\r
-               m68kcontext.io_cycle_counter= (CLK);  \\r
+               m68kcontext.io_cycle_counter=(CLK);  \\r
        }\r
 \r
 \r
@@ -488,9 +481,10 @@ static u32 flag_I;
 #define CHECK_BRANCH_EXCEPTION(_PC_) \\r
        if ((_PC_)&1) \\r
        { \\r
-               u32 pr_PC=GET_PC; \\r
+               u32 new_PC, pr_PC=GET_PC; \\r
                m68kcontext.execinfo |= FM68K_EMULATE_GROUP_0; \\r
-               execute_exception_group_0(M68K_ADDRESS_ERROR_EX, 0, pr_PC, 0x12 ); \\r
+               new_PC = execute_exception_group_0(M68K_ADDRESS_ERROR_EX, 0, pr_PC, 0x12 ); \\r
+               SET_PC(new_PC); \\r
                CHECK_BRANCH_EXCEPTION_GOTO_END \\r
        }\r
 #else\r
@@ -500,9 +494,6 @@ static u32 flag_I;
 \r
 static int init_jump_table(void);\r
 \r
-/* Custom function handler */\r
-typedef void (*icust_handler_func)(u32 vector);\r
-\r
 // global variable\r
 ///////////////////\r
 \r
@@ -510,20 +501,30 @@ typedef void (*icust_handler_func)(u32 vector);
 M68K_CONTEXT *g_m68kcontext;\r
 #define m68kcontext (*g_m68kcontext)\r
 \r
-/* static s32 io_cycle_counter; */\r
-static s32 cycles_needed=0;\r
+#ifdef FAMEC_NO_GOTOS\r
+static u32 Opcode;\r
+static s32 cycles_needed;\r
 static u16 *PC;\r
 static u32 BasePC;\r
-// static u32 Fetch[M68K_FETCHBANK];\r
+static u32 flag_V;\r
+static u32 flag_NotZ;\r
+static u32 flag_N;\r
+static u32 flag_X;\r
+#endif\r
+\r
+#ifdef FAMEC_EMULATE_TRACE\r
+static u32 flag_T;\r
+#endif\r
+static u32 flag_S;\r
+static u32 flag_I;\r
+\r
+static u32 initialised = 0;\r
 \r
 /* Custom function handler */\r
 typedef void (*opcode_func)(void);\r
 \r
 static opcode_func JumpTable[0x10000];\r
 \r
-\r
-static u32 initialised = 0;\r
-\r
 // exception cycle table (taken from musashi core)\r
 static const s32 exception_cycle_table[256] =\r
 {\r
@@ -673,7 +674,11 @@ int fm68k_reset(void)
 /****************************************************************************/\r
 u32 fm68k_get_pc(M68K_CONTEXT *context)\r
 {\r
+#ifdef FAMEC_NO_GOTOS\r
        return (context->execinfo & M68K_RUNNING)?(u32)PC-BasePC:context->pc;\r
+#else\r
+       return context->pc; // approximate PC in this mode\r
+#endif\r
 }\r
 \r
 \r
@@ -692,64 +697,62 @@ int fm68k_would_interrupt(void)
        return interrupt_chk__();\r
 }\r
 \r
-static FAMEC_EXTRA_INLINE void execute_exception(s32 vect)\r
+static FAMEC_EXTRA_INLINE u32 execute_exception(s32 vect, u32 oldPC, u32 oldSR)\r
 {\r
-       extern u32 flag_S;\r
-#ifndef FAMEC_IRQ_CYCLES\r
-       if ((vect<24)||(vect>31))\r
-#endif\r
+       u32 newPC;\r
+       //u32 oldSR = GET_SR;\r
+\r
         m68kcontext.io_cycle_counter -= exception_cycle_table[vect];\r
-       {\r
-               u32 newPC;\r
-               u32 oldPC;\r
-               u32 oldSR = GET_SR;\r
 \r
-               PRE_IO\r
+       PRE_IO\r
 \r
-               READ_LONG_F(vect * 4, newPC)\r
+       READ_LONG_F(vect * 4, newPC)\r
 \r
-               /* swap A7 and USP */\r
-               if (!flag_S)\r
-               {\r
-                       u32 tmpSP;\r
+       /* swap A7 and USP */\r
+       if (!flag_S)\r
+       {\r
+               u32 tmpSP;\r
 \r
-                       tmpSP = ASP;\r
-                       ASP = AREG(7);\r
-                       AREG(7) = tmpSP;\r
-               }\r
+               tmpSP = ASP;\r
+               ASP = AREG(7);\r
+               AREG(7) = tmpSP;\r
+       }\r
 \r
-               oldPC = (u32)(PC) - BasePC;\r
-               PUSH_32_F(oldPC)\r
-               PUSH_16_F(oldSR)\r
+       //oldPC = GET_PC;\r
+       PUSH_32_F(oldPC)\r
+       PUSH_16_F(oldSR)\r
 \r
-               /* adjust SR */\r
-               flag_S = M68K_SR_S;\r
+       /* adjust SR */\r
+       flag_S = M68K_SR_S;\r
 \r
 #ifndef FAMEC_32BIT_PC\r
-               newPC&=M68K_ADR_MASK\r
+       newPC&=M68K_ADR_MASK\r
 #endif\r
-               newPC&=~1; // don't crash on games with bad vector tables\r
+       newPC&=~1; // don't crash on games with bad vector tables\r
 \r
-               SET_PC(newPC)\r
+       // SET_PC(newPC)\r
 \r
-               POST_IO\r
-       }\r
+       POST_IO\r
+\r
+       return newPC;\r
 }\r
 \r
-static FAMEC_EXTRA_INLINE void execute_exception_group_0(s32 vect, u16 inst_reg, s32 addr, u16 spec_info)\r
+static FAMEC_EXTRA_INLINE u32 execute_exception_group_0(s32 vect, s32 addr, u16 spec_info, u32 oldSR)\r
 {\r
-       execute_exception(vect);\r
+       u32 newPC;\r
+       u16 inst_reg = 0;\r
+       newPC = execute_exception(vect, addr, oldSR);\r
        //if (!(m68kcontext.icust_handler && m68kcontext.icust_handler[vect]))\r
        {\r
                PUSH_16_F(inst_reg);\r
                PUSH_32_F(addr);\r
                PUSH_16_F(spec_info);\r
        }\r
+       return newPC;\r
 }\r
 \r
 \r
 static void setup_jumptable(void);\r
-static u32 Opcode;\r
 \r
 #ifdef FAMEC_NO_GOTOS\r
 \r
@@ -764,6 +767,18 @@ static u32 Opcode;
 \r
 int fm68k_emulate(s32 cycles)\r
 {\r
+#ifndef FAMEC_NO_GOTOS\r
+       u32 Opcode;\r
+       s32 cycles_needed;\r
+       u16 *PC;\r
+       u32 BasePC;\r
+       u32 flag_C;\r
+       u32 flag_V;\r
+       u32 flag_NotZ;\r
+       u32 flag_N;\r
+       u32 flag_X;\r
+#endif\r
+\r
        if (!initialised)\r
        {\r
 #ifdef FAMEC_NO_GOTOS\r
@@ -824,7 +839,7 @@ int fm68k_emulate(s32 cycles)
                        else\r
                                m68kcontext.interrupts[0] = 0;\r
 \r
-                       execute_exception(line + 0x18);\r
+                       SET_PC(execute_exception(line + 0x18, GET_PC, GET_SR));\r
                        flag_I = (u32)line;\r
                        if (m68kcontext.io_cycle_counter <= 0) goto famec_End;\r
                }\r
@@ -833,7 +848,7 @@ int fm68k_emulate(s32 cycles)
                        if  (flag_T)\r
                        {\r
                                m68kcontext.execinfo |= FM68K_EMULATE_TRACE;\r
-                               cycles_needed= m68kcontext.io_cycle_counter;\r
+                               cycles_needed = m68kcontext.io_cycle_counter;\r
                                m68kcontext.io_cycle_counter=0;\r
                        }\r
 #endif\r
@@ -862,22 +877,25 @@ famec_Exec:
 #ifdef FAMEC_EMULATE_TRACE\r
        if (m68kcontext.execinfo & FM68K_EMULATE_TRACE)\r
        {\r
-               m68kcontext.io_cycle_counter= cycles_needed;\r
+               m68kcontext.io_cycle_counter = cycles_needed;\r
+               cycles_needed = 0;\r
                m68kcontext.execinfo &= ~FM68K_EMULATE_TRACE;\r
                m68kcontext.execinfo |= FM68K_DO_TRACE;\r
-               execute_exception(M68K_TRACE_EX);\r
+               SET_PC(execute_exception(M68K_TRACE_EX, GET_PC, GET_SR));\r
                flag_T=0;\r
                if (m68kcontext.io_cycle_counter > 0)\r
                {\r
-                       NEXT\r
+                       //NEXT\r
+                       goto famec_Exec;\r
                }\r
        }\r
        else\r
 #endif\r
                if (cycles_needed != 0)\r
                {\r
+                       m68kcontext.io_cycle_counter = cycles_needed;\r
+                       cycles_needed = 0;\r
                        s32 line=interrupt_chk__();\r
-                       m68kcontext.io_cycle_counter= cycles_needed;\r
                        if (line>0)\r
                        {\r
                                if (m68kcontext.iack_handler != NULL)\r
@@ -885,11 +903,11 @@ famec_Exec:
                                else\r
                                        m68kcontext.interrupts[0] = 0;\r
 \r
-                               execute_exception(line + 0x18);\r
+                               SET_PC(execute_exception(line + 0x18, GET_PC, GET_SR));\r
                                flag_I = (u32)line;\r
                        }\r
 #ifdef FAMEC_EMULATE_TRACE\r
-                       else if (!(flag_T))\r
+                       if (!(flag_T))\r
 #endif\r
                        if (m68kcontext.io_cycle_counter > 0)\r
                        {\r
index eeb3c2b..8586603 100644 (file)
@@ -638,9 +638,7 @@ OPCODE(0x007C)
        }
        else
        {
-               u32 newPC = (u32)(PC) - BasePC;
-               SET_PC(newPC-2);
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
 #ifdef USE_CYCLONE_TIMING
                RET(0)
 #else
@@ -1298,9 +1296,7 @@ OPCODE(0x027C)
        }
        else
        {
-               u32 newPC = (u32)(PC) - BasePC;
-               SET_PC(newPC-2);
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(20)
@@ -1950,9 +1946,7 @@ OPCODE(0x0A7C)
        }
        else
        {
-               u32 newPC = (u32)(PC) - BasePC;
-               SET_PC(newPC-2);
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(0)
        }
 RET(20)
@@ -16570,9 +16564,7 @@ OPCODE(0x46C0)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(12)
@@ -16601,9 +16593,7 @@ OPCODE(0x46D0)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(16)
@@ -16633,9 +16623,7 @@ OPCODE(0x46D8)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(16)
@@ -16665,9 +16653,7 @@ OPCODE(0x46E0)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(18)
@@ -16697,9 +16683,7 @@ OPCODE(0x46E8)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(20)
@@ -16729,9 +16713,7 @@ OPCODE(0x46F0)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(22)
@@ -16761,9 +16743,7 @@ OPCODE(0x46F8)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(20)
@@ -16792,9 +16772,7 @@ OPCODE(0x46F9)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(24)
@@ -16820,13 +16798,11 @@ OPCODE(0x46FA)
                        ASP = res;
                }
                POST_IO
-               CHECK_INT_TO_JUMP(24)
+               CHECK_INT_TO_JUMP(20)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(20)
@@ -16856,9 +16832,7 @@ OPCODE(0x46FB)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(22)
@@ -16884,9 +16858,7 @@ OPCODE(0x46FC)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(16)
@@ -16916,9 +16888,7 @@ OPCODE(0x46DF)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(16)
@@ -16948,9 +16918,7 @@ OPCODE(0x46E7)
        }
        else
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
 RET(18)
@@ -18473,27 +18441,21 @@ RET(10)
 // ILLEGAL
 OPCODE(0x4AFC)
 {
-       u32 oldPC=GET_PC;
-       SET_PC(oldPC-2)
-       execute_exception(M68K_ILLEGAL_INSTRUCTION_EX);
+       SET_PC(execute_exception(M68K_ILLEGAL_INSTRUCTION_EX, GET_PC-2, GET_SR));
 RET(0)
 }
 
 // ILLEGAL A000-AFFF
 OPCODE(0xA000)
 {
-       u32 oldPC=GET_PC;
-       SET_PC(oldPC-2)
-       execute_exception(M68K_1010_EX);
+       SET_PC(execute_exception(M68K_1010_EX, GET_PC-2, GET_SR));
 RET(0)
 }
 
 // ILLEGAL F000-FFFF
 OPCODE(0xF000)
 {
-       u32 oldPC=GET_PC;
-       SET_PC(oldPC-2)
-       execute_exception(M68K_1111_EX);
+       SET_PC(execute_exception(M68K_1111_EX, GET_PC-2, GET_SR));
 RET(0) // 4 already taken by exc. handler
 }
 
@@ -19054,7 +19016,7 @@ RET(12)
 // TRAP
 OPCODE(0x4E40)
 {
-       execute_exception(M68K_TRAP_BASE_EX + (Opcode & 0xF));
+       SET_PC(execute_exception(M68K_TRAP_BASE_EX + (Opcode & 0xF), GET_PC, GET_SR));
 RET(4)
 }
 
@@ -19125,9 +19087,7 @@ OPCODE(0x4E60)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
        res = AREGu32((Opcode >> 0) & 7);
@@ -19143,9 +19103,7 @@ OPCODE(0x4E68)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
        res = ASP;
@@ -19161,9 +19119,7 @@ OPCODE(0x4E70)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
        PRE_IO
@@ -19187,9 +19143,7 @@ OPCODE(0x4E72)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
        FETCH_WORD(res);
@@ -19214,9 +19168,7 @@ OPCODE(0x4E73)
 
        if (!flag_S)
        {
-               u32 oldPC=GET_PC;
-               SET_PC(oldPC-2)
-               execute_exception(M68K_PRIVILEGE_VIOLATION_EX);
+               SET_PC(execute_exception(M68K_PRIVILEGE_VIOLATION_EX, GET_PC-2, GET_SR));
                RET(4)
        }
        PRE_IO
@@ -19254,7 +19206,7 @@ RET(16)
 OPCODE(0x4E76)
 {
        if (flag_V & 0x80)
-               execute_exception(M68K_TRAPV_EX);
+               SET_PC(execute_exception(M68K_TRAPV_EX, GET_PC, GET_SR));
 RET(4)
 }
 
@@ -19517,7 +19469,7 @@ OPCODE(0x4180)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
 RET(10)
 }
@@ -19535,7 +19487,7 @@ OPCODE(0x4190)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(14)
@@ -19555,7 +19507,7 @@ OPCODE(0x4198)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(14)
@@ -19575,7 +19527,7 @@ OPCODE(0x41A0)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(16)
@@ -19595,7 +19547,7 @@ OPCODE(0x41A8)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(18)
@@ -19615,7 +19567,7 @@ OPCODE(0x41B0)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(20)
@@ -19634,7 +19586,7 @@ OPCODE(0x41B8)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(18)
@@ -19653,7 +19605,7 @@ OPCODE(0x41B9)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(22)
@@ -19673,7 +19625,7 @@ OPCODE(0x41BA)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(18)
@@ -19693,7 +19645,7 @@ OPCODE(0x41BB)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(20)
@@ -19710,7 +19662,7 @@ OPCODE(0x41BC)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(14)
@@ -19730,7 +19682,7 @@ OPCODE(0x419F)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(14)
@@ -19750,7 +19702,7 @@ OPCODE(0x41A7)
        if (((s32)res < 0) || (res > src))
        {
                flag_N = res >> 8;
-               execute_exception(M68K_CHK_EX);
+               SET_PC(execute_exception(M68K_CHK_EX, GET_PC, GET_SR));
        }
        POST_IO
 RET(16)
@@ -26983,7 +26935,7 @@ OPCODE(0x80C0)
        src = DREGu16((Opcode >> 0) & 7);
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(140)
 #else
@@ -27031,7 +26983,7 @@ OPCODE(0x80D0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(144)
 #else
@@ -27080,7 +27032,7 @@ OPCODE(0x80D8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(144)
 #else
@@ -27129,7 +27081,7 @@ OPCODE(0x80E0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(146)
 #else
@@ -27178,7 +27130,7 @@ OPCODE(0x80E8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(148)
 #else
@@ -27227,7 +27179,7 @@ OPCODE(0x80F0)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(150)
 #else
@@ -27275,7 +27227,7 @@ OPCODE(0x80F8)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(148)
 #else
@@ -27323,7 +27275,7 @@ OPCODE(0x80F9)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(162)
 #else
@@ -27372,7 +27324,7 @@ OPCODE(0x80FA)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(148)
 #else
@@ -27421,7 +27373,7 @@ OPCODE(0x80FB)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(160)
 #else
@@ -27467,7 +27419,7 @@ OPCODE(0x80FC)
        FETCH_WORD(src);
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(144)
 #else
@@ -27516,7 +27468,7 @@ OPCODE(0x80DF)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(144)
 #else
@@ -27565,7 +27517,7 @@ OPCODE(0x80E7)
        READ_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 RET(146)
 #else
@@ -27611,7 +27563,7 @@ OPCODE(0x81C0)
        src = (s32)DREGs16((Opcode >> 0) & 7);
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81C0;
 #endif
@@ -27667,7 +27619,7 @@ OPCODE(0x81D0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81D0;
 #endif
@@ -27724,7 +27676,7 @@ OPCODE(0x81D8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81D8;
 #endif
@@ -27781,7 +27733,7 @@ OPCODE(0x81E0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81E0;
 #endif
@@ -27838,7 +27790,7 @@ OPCODE(0x81E8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81E8;
 #endif
@@ -27895,7 +27847,7 @@ OPCODE(0x81F0)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81F0;
 #endif
@@ -27951,7 +27903,7 @@ OPCODE(0x81F8)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81F8;
 #endif
@@ -28007,7 +27959,7 @@ OPCODE(0x81F9)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81F9;
 #endif
@@ -28064,7 +28016,7 @@ OPCODE(0x81FA)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81FA;
 #endif
@@ -28121,7 +28073,7 @@ OPCODE(0x81FB)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81FB;
 #endif
@@ -28175,7 +28127,7 @@ OPCODE(0x81FC)
        FETCH_SWORD(src);
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81FC;
 #endif
@@ -28232,7 +28184,7 @@ OPCODE(0x81DF)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81DF;
 #endif
@@ -28289,7 +28241,7 @@ OPCODE(0x81E7)
        READSX_WORD_F(adr, src)
        if (src == 0)
        {
-               execute_exception(M68K_ZERO_DIVIDE_EX);
+               SET_PC(execute_exception(M68K_ZERO_DIVIDE_EX, GET_PC, GET_SR));
 #ifdef USE_CYCLONE_TIMING_DIV
 goto end81E7;
 #endif