X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=m68kcpu.h;fp=m68kcpu.h;h=ef25ad1b156343911527f76d189f0f8e9c4a73f9;hb=62d18f9f13989b4625a00c1eb050301f8470cf94;hp=d087d6260c09ce93622c7eedd60522d8d64ec391;hpb=f4de6907c13af4aab6784aaf1e95f7f2c28c06c3;p=pistorm diff --git a/m68kcpu.h b/m68kcpu.h index d087d62..ef25ad1 100644 --- a/m68kcpu.h +++ b/m68kcpu.h @@ -1075,6 +1075,13 @@ char* m68ki_disassemble_quick(unsigned int pc, unsigned int cpu_type); /* ---------------------------- Read Immediate ---------------------------- */ +typedef struct +{ + unsigned int lower; + unsigned int upper; + unsigned char *data; +} address_translation_cache; + extern unsigned char read_ranges; extern unsigned int read_addr[8]; @@ -1085,6 +1092,8 @@ extern unsigned int write_addr[8]; extern unsigned int write_upper[8]; extern unsigned char *write_data[8]; +extern address_translation_cache code_translation_cache; + // clear the instruction cache inline void m68ki_ic_clear() { @@ -1152,46 +1161,21 @@ static inline uint32 m68ki_ic_readimm16(uint32 address) /* Handles all immediate reads, does address error check, function code setting, * and prefetching if they are enabled in m68kconf.h */ -static inline uint m68ki_read_imm_16(void) -{ - uint32_t address = ADDRESS_68K(REG_PC); - for (int i = 0; i < read_ranges; i++) { - if(address >= read_addr[i] && address < read_upper[i]) { - REG_PC += 2; - return be16toh(((unsigned short *)(read_data[i] + (address - read_addr[i])))[0]); - } - } +uint m68ki_read_imm6_addr_slowpath(uint32_t pc, address_translation_cache *cache); - 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 - REG_PC += 2; - return m68k_read_immediate_16(address); -#endif /* M68K_EMULATE_PREFETCH */ +static inline uint m68ki_read_imm_16(void) +{ + uint32_t pc = REG_PC; + + address_translation_cache *cache = &code_translation_cache; + if(pc >= cache->lower && pc < cache->upper) + { + REG_PC += 2; + return be16toh(((unsigned short *)(cache->data + (pc - cache->lower)))[0]); + } + return m68ki_read_imm6_addr_slowpath(pc, cache); } static inline uint m68ki_read_imm_8(void)