]> git.sesse.net Git - pistorm/blobdiff - m68kcpu.c
Merge pull request #45 from mcgurk/wip-crap
[pistorm] / m68kcpu.c
index 4cc48c5f75044fc636e4da876bd9b0a55f939fcf..33bf016d8947372d2d8d81a9eef3db0792f3eb25 100644 (file)
--- a/m68kcpu.c
+++ b/m68kcpu.c
@@ -990,9 +990,6 @@ int m68k_execute(int num_cycles)
                /* Main loop.  Keep going until we run out of clock cycles */
                do
                {
-#ifdef M68K_BUSERR_THING
-                       int i;
-#endif
                        /* Set tracing accodring to T1. (T0 is done inside instruction) */
                        m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */
 
@@ -1006,8 +1003,9 @@ int m68k_execute(int num_cycles)
                        REG_PPC = REG_PC;
 
                        /* Record previous D/A register state (in case of bus error) */
+//#define M68K_BUSERR_THING
 #ifdef M68K_BUSERR_THING
-                       for (i = 15; i >= 0; i--){
+                       for (int i = 15; i >= 0; i--){
                                REG_DA_SAVE[i] = REG_DA[i];
                        }
 #endif
@@ -1213,7 +1211,7 @@ inline unsigned int  m68k_read_immediate_16(unsigned int address) {
                }
        }
 #endif
-       
+
        return m68k_read_memory_16(address);
 }
 inline unsigned int  m68k_read_immediate_32(unsigned int address) {
@@ -1235,7 +1233,7 @@ inline unsigned int  m68k_read_pcrelative_8(unsigned int address) {
                        return read_data[i][address - read_addr[i]];
                }
        }
-       
+
        return m68k_read_memory_8(address);
 }
 inline unsigned int  m68k_read_pcrelative_16(unsigned int address) {
@@ -1258,8 +1256,67 @@ inline unsigned int  m68k_read_pcrelative_32(unsigned int address) {
 }
 #endif
 
+
+uint m68ki_read_imm6_addr_slowpath(uint32_t pc, address_translation_cache *cache)
+{
+    uint32_t address = ADDRESS_68K(pc);
+    uint32_t pc_address_diff = pc - address;
+       for (int i = 0; i < read_ranges; i++) {
+               if(address >= read_addr[i] && address < read_upper[i]) {
+            cache->lower = read_addr[i] + pc_address_diff;
+            cache->upper = read_upper[i] + pc_address_diff;
+            cache->data = read_data[i];
+                       REG_PC += 2;
+                       return be16toh(((unsigned short *)(read_data[i] + (address - read_addr[i])))[0]);
+               }
+       }
+
+       m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */
+       m68ki_cpu.mmu_tmp_fc = FLAG_S | FUNCTION_CODE_USER_PROGRAM;
+       m68ki_cpu.mmu_tmp_rw = 1;
+       m68ki_cpu.mmu_tmp_sz = M68K_SZ_WORD;
+       m68ki_check_address_error(REG_PC, MODE_READ, FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */
+
+#if M68K_EMULATE_PREFETCH
+{
+       uint result;
+       if(REG_PC != CPU_PREF_ADDR)
+       {
+               CPU_PREF_DATA = m68ki_ic_readimm16(REG_PC);
+               CPU_PREF_ADDR = m68ki_cpu.mmu_tmp_buserror_occurred ? ((uint32)~0) : REG_PC;
+       }
+       result = MASK_OUT_ABOVE_16(CPU_PREF_DATA);
+       REG_PC += 2;
+       if (!m68ki_cpu.mmu_tmp_buserror_occurred) {
+               // prefetch only if no bus error occurred in opcode fetch
+               CPU_PREF_DATA = m68ki_ic_readimm16(REG_PC);
+               CPU_PREF_ADDR = m68ki_cpu.mmu_tmp_buserror_occurred ? ((uint32)~0) : REG_PC;
+               // ignore bus error on prefetch
+               m68ki_cpu.mmu_tmp_buserror_occurred = 0;
+       }
+       return result;
+}
+#else
+
+       uint32_t address = ADDRESS_68K(REG_PC);
+       REG_PC += 2;
+
+       for (int i = 0; i < read_ranges; i++) {
+               if(address >= read_addr[i] && address < read_upper[i]) {
+                       return be16toh(((unsigned short *)(read_data[i] + (address - read_addr[i])))[0]);
+               }
+       }
+
+       return m68k_read_immediate_16(address);
+#endif /* M68K_EMULATE_PREFETCH */
+}
+
+
+
 void m68k_add_ram_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
 {
+    code_translation_cache.lower = 0;
+    code_translation_cache.upper = 0;
        if ((addr == 0 && upper == 0) || upper < addr)
                return;
 
@@ -1305,6 +1362,8 @@ void m68k_add_ram_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
 
 void m68k_add_rom_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
 {
+    code_translation_cache.lower = 0;
+    code_translation_cache.upper = 0;
        if ((addr == 0 && upper == 0) || upper < addr)
                return;
 
@@ -1338,6 +1397,21 @@ void m68k_add_rom_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
        }
 }
 
+void m68k_clear_ranges()
+{
+       printf("[MUSASHI] Clearing all reads/write memory ranges.\n");
+       for (int i = 0; i < 8; i++) {
+               read_upper[i] = 0;
+               read_addr[i] = 0;
+               read_data[i] = NULL;
+               write_upper[i] = 0;
+               write_addr[i] = 0;
+               write_data[i] = NULL;
+       }
+       write_ranges = 0;
+       read_ranges = 0;
+}
+
 /* ======================================================================== */
 /* ============================== MAME STUFF ============================== */
 /* ======================================================================== */