musashi: run same amount of cycles as other cores
[picodrive.git] / cpu / musashi / m68kcpu.c
index e4212a8..38469f3 100644 (file)
@@ -5,9 +5,9 @@
 #if 0\r
 static const char* copyright_notice =\r
 "MUSASHI\n"\r
-"Version 3.3 (2001-01-29)\n"\r
+"Version 3.31 (2007-07-09)\n"\r
 "A portable Motorola M680x0 processor emulation engine.\n"\r
-"Copyright 1998-2001 Karl Stenerud.  All rights reserved.\n"\r
+"Copyright 1998-2007 Karl Stenerud.  All rights reserved.\n"\r
 "\n"\r
 "This code may be freely used for non-commercial purpooses as long as this\n"\r
 "copyright notice remains unaltered in the source code and any binary files\n"\r
@@ -32,15 +32,19 @@ static const char* copyright_notice =
 /* ================================ INCLUDES ============================== */\r
 /* ======================================================================== */\r
 \r
+extern void m68040_fpu_op0(void);\r
+extern void m68040_fpu_op1(void);\r
+\r
 #include "m68kops.h"\r
 #include "m68kcpu.h"\r
+//#include "m68kfpu.c"\r
 \r
 /* ======================================================================== */\r
 /* ================================= DATA ================================= */\r
 /* ======================================================================== */\r
 \r
-// int  m68ki_initial_cycles; // moved to m68k_execute() stack\r
-// int  m68ki_remaining_cycles = 0;                     /* Number of clocks remaining */\r
+int  m68ki_initial_cycles;\r
+//int  m68ki_remaining_cycles = 0;                     /* Number of clocks remaining */\r
 uint m68ki_tracing = 0;\r
 uint m68ki_address_space;\r
 \r
@@ -68,8 +72,9 @@ const char* m68ki_cpu_names[] =
 #endif /* M68K_LOG_ENABLE */\r
 \r
 /* The CPU core */\r
-// m68ki_cpu_core m68ki_cpu = {0};\r
+// notaz\r
 m68ki_cpu_core *m68ki_cpu_p = NULL;\r
+//m68ki_cpu_core m68ki_cpu = {0};\r
 \r
 \r
 #if M68K_EMULATE_ADDRESS_ERROR\r
@@ -477,6 +482,12 @@ static void default_rte_instr_callback(void)
 {\r
 }\r
 \r
+/* Called when a tas instruction is executed */\r
+static int default_tas_instr_callback(void)\r
+{\r
+       return 1; // allow writeback\r
+}\r
+\r
 /* Called when the program counter changed by a large value */\r
 static unsigned int default_pc_changed_callback_data;\r
 static void default_pc_changed_callback(unsigned int new_pc)\r
@@ -647,6 +658,11 @@ void m68k_set_rte_instr_callback(void  (*callback)(void))
        CALLBACK_RTE_INSTR = callback ? callback : default_rte_instr_callback;\r
 }\r
 \r
+void m68k_set_tas_instr_callback(int  (*callback)(void))\r
+{\r
+       CALLBACK_TAS_INSTR = callback ? callback : default_tas_instr_callback;\r
+}\r
+\r
 void m68k_set_pc_changed_callback(void  (*callback)(unsigned int new_pc))\r
 {\r
        CALLBACK_PC_CHANGED = callback ? callback : default_pc_changed_callback;\r
@@ -771,11 +787,12 @@ void m68k_set_cpu_type(unsigned int cpu_type)
 /* ASG: removed per-instruction interrupt checks */\r
 int m68k_execute(int num_cycles)\r
 {\r
-       int  m68ki_initial_cycles;\r
-\r
        /* Make sure we're not stopped */\r
        if(!CPU_STOPPED)\r
        {\r
+               // notaz\r
+               m68ki_check_interrupts();\r
+\r
                /* Set our pool of clock cycles available */\r
                SET_CYCLES(num_cycles);\r
                m68ki_initial_cycles = num_cycles;\r
@@ -788,10 +805,14 @@ int m68k_execute(int num_cycles)
                m68ki_set_address_error_trap(); /* auto-disable (see m68kcpu.h) */\r
 \r
                /* Main loop.  Keep going until we run out of clock cycles */\r
+               // notaz\r
+               m68ki_trace_t1();\r
+\r
                while(GET_CYCLES() > 0)\r
+//             do\r
                {\r
                        /* Set tracing accodring to T1. (T0 is done inside instruction) */\r
-                       m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */\r
+                       //m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */\r
 \r
                        /* Set the address space for reads */\r
                        m68ki_use_data_space(); /* auto-disable (see m68kcpu.h) */\r
@@ -805,11 +826,15 @@ int m68k_execute(int num_cycles)
                        /* Read an instruction and call its handler */\r
                        REG_IR = m68ki_read_imm_16();\r
                        m68ki_instruction_jump_table[REG_IR]();\r
-                       USE_CYCLES(CYC_INSTRUCTION[REG_IR]);\r
+                       USE_CYCLES(CYC_INSTRUCTION[REG_IR]); // moving this up may cause a deadlock\r
 \r
                        /* Trace m68k_exception, if necessary */\r
                        m68ki_exception_if_trace(); /* auto-disable (see m68kcpu.h) */\r
-               }\r
+\r
+                       m68ki_trace_t1(); /* notaz */\r
+\r
+                       m68ki_cpu_p->not_polling = 1;\r
+               } // while(GET_CYCLES() > 0); // notaz\r
 \r
                /* set previous PC to current PC for the next entry into the loop */\r
                REG_PPC = REG_PC;\r
@@ -829,19 +854,17 @@ int m68k_execute(int num_cycles)
        return num_cycles;\r
 }\r
 \r
-#if 0\r
+\r
 int m68k_cycles_run(void)\r
 {\r
        return m68ki_initial_cycles - GET_CYCLES();\r
 }\r
-#endif\r
 \r
 int m68k_cycles_remaining(void)\r
 {\r
        return GET_CYCLES();\r
 }\r
 \r
-#if 0\r
 /* Change the timeslice */\r
 void m68k_modify_timeslice(int cycles)\r
 {\r
@@ -855,7 +878,7 @@ void m68k_end_timeslice(void)
        m68ki_initial_cycles = GET_CYCLES();\r
        SET_CYCLES(0);\r
 }\r
-#endif\r
+\r
 \r
 /* ASG: rewrote so that the int_level is a mask of the IPL0/IPL1/IPL2 bits */\r
 /* KS: Modified so that IPL* bits match with mask positions in the SR\r
@@ -890,6 +913,7 @@ void m68k_init(void)
        m68k_set_reset_instr_callback(NULL);\r
        m68k_set_cmpild_instr_callback(NULL);\r
        m68k_set_rte_instr_callback(NULL);\r
+       m68k_set_tas_instr_callback(NULL);\r
        m68k_set_pc_changed_callback(NULL);\r
        m68k_set_fc_callback(NULL);\r
        m68k_set_instr_hook_callback(NULL);\r
@@ -943,17 +967,17 @@ unsigned int m68k_context_size()
        return sizeof(m68ki_cpu_core);\r
 }\r
 \r
-/*\r
 unsigned int m68k_get_context(void* dst)\r
 {\r
        if(dst) *(m68ki_cpu_core*)dst = m68ki_cpu;\r
        return sizeof(m68ki_cpu_core);\r
 }\r
-*/\r
 \r
 void m68k_set_context(void* src)\r
 {\r
+       // notaz\r
        if(src) m68ki_cpu_p = src;\r
+//     if(src) m68ki_cpu = *(m68ki_cpu_core*)src;\r
 }\r
 \r
 \r
@@ -964,8 +988,6 @@ void m68k_set_context(void* src)
 \r
 #if M68K_COMPILE_FOR_MAME == OPT_ON\r
 \r
-#include "state.h"\r
-\r
 static struct {\r
        UINT16 sr;\r
        UINT8 stopped;\r