From 60acb37185f21046cd798729e0cccf92dbe796c0 Mon Sep 17 00:00:00 2001 From: beeanyew Date: Thu, 18 Feb 2021 05:29:59 +0100 Subject: [PATCH] Certified Musashi speed hax Probably requires a make clean due to things being in header files. --- m68k.h | 2 - m68kconf.h | 4 +- m68kcpu.c | 39 +++++++++++++++ m68kcpu.h | 48 +++++++++++++------ .../piscsi/device_driver_amiga/build.bat | 1 - 5 files changed, 74 insertions(+), 20 deletions(-) delete mode 100644 platforms/amiga/piscsi/device_driver_amiga/build.bat diff --git a/m68k.h b/m68k.h index eb360b7..3c6ee81 100644 --- a/m68k.h +++ b/m68k.h @@ -216,8 +216,6 @@ void m68k_add_rom_range(uint32_t addr, uint32_t upper, unsigned char *ptr); */ void m68k_write_memory_32_pd(unsigned int address, unsigned int value); - - /* ======================================================================== */ /* ============================== CALLBACKS =============================== */ /* ======================================================================== */ diff --git a/m68kconf.h b/m68kconf.h index 26ee063..bcfcb13 100644 --- a/m68kconf.h +++ b/m68kconf.h @@ -75,7 +75,7 @@ * and m68k_read_pcrelative_xx() for PC-relative addressing. * If off, all read requests from the CPU will be redirected to m68k_read_xx() */ -#define M68K_SEPARATE_READS OPT_OFF +#define M68K_SEPARATE_READS OPT_ON /* If ON, the CPU will call m68k_write_32_pd() when it executes move.l with a * predecrement destination EA mode instead of m68k_write_32(). @@ -166,7 +166,7 @@ /* If ON, the CPU will emulate the 4-byte prefetch queue of a real 68000 */ -#define M68K_EMULATE_PREFETCH OPT_ON +#define M68K_EMULATE_PREFETCH OPT_OFF /* If ON, the CPU will generate address error exceptions if it tries to diff --git a/m68kcpu.c b/m68kcpu.c index 0c03692..ecdf4dd 100644 --- a/m68kcpu.c +++ b/m68kcpu.c @@ -969,7 +969,9 @@ int m68k_execute(int num_cycles) /* Return point if we had an address error */ m68ki_set_address_error_trap(); /* auto-disable (see m68kcpu.h) */ +#ifdef M68K_BUSERR_THING m68ki_check_bus_error_trap(); +#endif /* Main loop. Keep going until we run out of clock cycles */ do @@ -1171,6 +1173,43 @@ void m68k_set_context(void* src) if(src) m68ki_cpu = *(m68ki_cpu_core*)src; } +/* Read data immediately following the PC */ +inline unsigned int m68k_read_immediate_16(unsigned int address) { + return m68k_read_memory_16(address); +} +inline unsigned int m68k_read_immediate_32(unsigned int address) { + return m68k_read_memory_32(address); +} + +/* Read data relative to the PC */ +inline unsigned int m68k_read_pcrelative_8(unsigned int address) { + for (int i = 0; i < read_ranges; i++) { + if(address >= read_addr[i] && address < read_upper[i]) { + return read_data[i][address - read_addr[i]]; + } + } + + return m68k_read_memory_8(address); +} +inline unsigned int m68k_read_pcrelative_16(unsigned int address) { + 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_memory_16(address); +} +inline unsigned int m68k_read_pcrelative_32(unsigned int address) { + for (int i = 0; i < read_ranges; i++) { + if(address >= read_addr[i] && address < read_upper[i]) { + return be32toh(((unsigned int *)(read_data[i] + (address - read_addr[i])))[0]); + } + } + + return m68k_read_memory_32(address); +} + void m68k_add_ram_range(uint32_t addr, uint32_t upper, unsigned char *ptr) { if ((addr == 0 && upper == 0) || upper < addr) diff --git a/m68kcpu.h b/m68kcpu.h index a6bea82..e1035c1 100644 --- a/m68kcpu.h +++ b/m68kcpu.h @@ -1035,6 +1035,15 @@ char* m68ki_disassemble_quick(unsigned int pc, unsigned int cpu_type); /* ---------------------------- Read Immediate ---------------------------- */ +extern unsigned char read_ranges; +extern unsigned int read_addr[8]; +extern unsigned int read_upper[8]; +extern unsigned char *read_data[8]; +extern unsigned char write_ranges; +extern unsigned int write_addr[8]; +extern unsigned int write_upper[8]; +extern unsigned char *write_data[8]; + extern uint pmmu_translate_addr(uint addr_in); /* Handles all immediate reads, does address error check, function code setting, @@ -1046,10 +1055,10 @@ static inline uint m68ki_read_imm_16(void) m68ki_check_address_error(REG_PC, MODE_READ, FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */ #if M68K_SEPARATE_READS -#if M68K_EMULATE_PMMU +/*#if M68K_EMULATE_PMMU if (PMMU_ENABLED) - address = pmmu_translate_addr(address); -#endif + address = pmmu_translate_addr(ADDRESS_68K(CPU_PREF_ADDR)); +#endif*/ #endif #if M68K_EMULATE_PREFETCH @@ -1067,7 +1076,16 @@ static inline uint m68ki_read_imm_16(void) 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_68K(REG_PC-2)); #endif /* M68K_EMULATE_PREFETCH */ } @@ -1081,14 +1099,15 @@ static inline uint m68ki_read_imm_8(void) static inline uint m68ki_read_imm_32(void) { #if M68K_SEPARATE_READS -#if M68K_EMULATE_PMMU +/*#if M68K_EMULATE_PMMU if (PMMU_ENABLED) - address = pmmu_translate_addr(address); -#endif + address = pmmu_translate_addr(ADDRESS_68K(CPU_PREF_ADDR)); +#endif*/ #endif #if M68K_EMULATE_PREFETCH uint temp_val; + uint32_t address = ADDRESS_68K(CPU_PREF_ADDR); m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */ m68ki_check_address_error(REG_PC, MODE_READ, FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */ @@ -1096,6 +1115,7 @@ static inline uint m68ki_read_imm_32(void) if(REG_PC != CPU_PREF_ADDR) { CPU_PREF_ADDR = REG_PC; + CPU_PREF_DATA = m68k_read_immediate_16(ADDRESS_68K(CPU_PREF_ADDR)); } temp_val = MASK_OUT_ABOVE_16(CPU_PREF_DATA); @@ -1112,7 +1132,14 @@ static inline uint m68ki_read_imm_32(void) #else m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */ m68ki_check_address_error(REG_PC, MODE_READ, FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */ + uint32_t address = ADDRESS_68K(REG_PC); REG_PC += 4; + for (int i = 0; i < read_ranges; i++) { + if(address >= read_addr[i] && address < read_upper[i]) { + return be32toh(((unsigned int *)(read_data[i] + (address - read_addr[i])))[0]); + } + } + return m68k_read_immediate_32(ADDRESS_68K(REG_PC-4)); #endif /* M68K_EMULATE_PREFETCH */ } @@ -1126,15 +1153,6 @@ static inline uint m68ki_read_imm_32(void) * code if they are enabled in m68kconf.h. */ -extern unsigned char read_ranges; -extern unsigned int read_addr[8]; -extern unsigned int read_upper[8]; -extern unsigned char *read_data[8]; -extern unsigned char write_ranges; -extern unsigned int write_addr[8]; -extern unsigned int write_upper[8]; -extern unsigned char *write_data[8]; - static inline uint m68ki_read_8_fc(uint address, uint fc) { (void)fc; diff --git a/platforms/amiga/piscsi/device_driver_amiga/build.bat b/platforms/amiga/piscsi/device_driver_amiga/build.bat deleted file mode 100644 index 7e20377..0000000 --- a/platforms/amiga/piscsi/device_driver_amiga/build.bat +++ /dev/null @@ -1 +0,0 @@ -vc +aos68k -nostdlib -I$VBCC/targets/m68k-amigaos/include2 -c99 -O2 -o pi-scsi.device piscsi-amiga.c -ldebug -lamiga -cpu=68020 -- 2.39.2