diff --git a/src/emu/cpu/m68000/m68000.h b/src/emu/cpu/m68000/m68000.h index b8d8eb77cb2..d8ef24c78ef 100644 --- a/src/emu/cpu/m68000/m68000.h +++ b/src/emu/cpu/m68000/m68000.h @@ -58,23 +58,13 @@ typedef struct _m68k_memory_interface m68k_memory_interface; struct _m68k_memory_interface { offs_t opcode_xor; // Address Calculation - UINT16 (*readimm16)(offs_t); // Immediate read 16 bit - UINT8 (*read8)(offs_t); // Normal read 8 bit - UINT16 (*read16)(offs_t); // Normal read 16 bit - UINT32 (*read32)(offs_t); // Normal read 32 bit - void (*write8)(offs_t, UINT8); // Write 8 bit - void (*write16)(offs_t, UINT16); // Write 16 bit - void (*write32)(offs_t, UINT32); // Write 32 bit - void (*changepc)(offs_t); // Change PC - - // For Encrypted Stuff - - UINT8 (*read8pc)(offs_t); // PC Relative read 8 bit - UINT16 (*read16pc)(offs_t); // PC Relative read 16 bit - UINT32 (*read32pc)(offs_t); // PC Relative read 32 bit - - UINT16 (*read16d)(offs_t); // Direct read 16 bit - UINT32 (*read32d)(offs_t); // Direct read 32 bit + UINT16 (*readimm16)(const address_space *, offs_t); // Immediate read 16 bit + UINT8 (*read8)(const address_space *, offs_t); // Normal read 8 bit + UINT16 (*read16)(const address_space *, offs_t); // Normal read 16 bit + UINT32 (*read32)(const address_space *, offs_t); // Normal read 32 bit + void (*write8)(const address_space *, offs_t, UINT8); // Write 8 bit + void (*write16)(const address_space *, offs_t, UINT16); // Write 16 bit + void (*write32)(const address_space *, offs_t, UINT32); // Write 32 bit }; diff --git a/src/emu/cpu/m68000/m68k.h b/src/emu/cpu/m68000/m68k.h index 1ab9edfd45d..9b02524a807 100644 --- a/src/emu/cpu/m68000/m68k.h +++ b/src/emu/cpu/m68000/m68k.h @@ -90,63 +90,6 @@ typedef enum _m68k_register_t m68k_register_t; -/* ======================================================================== */ -/* ====================== FUNCTIONS CALLED BY THE CPU ===================== */ -/* ======================================================================== */ - -/* You will have to implement these functions */ - -/* read/write functions called by the CPU to access memory. - * while values used are 32 bits, only the appropriate number - * of bits are relevant (i.e. in write_memory_8, only the lower 8 bits - * of value should be written to memory). - * - * NOTE: I have separated the immediate and PC-relative memory fetches - * from the other memory fetches because some systems require - * differentiation between PROGRAM and DATA fetches (usually - * for security setups such as encryption). - * This separation can either be achieved by setting - * M68K_SEPARATE_READS in m68kconf.h and defining - * the read functions, or by setting M68K_EMULATE_FC and - * making a function code callback function. - * Using the callback offers better emulation coverage - * because you can also monitor whether the CPU is in SYSTEM or - * USER mode, but it is also slower. - */ - -/* Read from anywhere */ -unsigned int m68k_read_memory_8(m68ki_cpu_core *m68k, unsigned int address); -unsigned int m68k_read_memory_16(m68ki_cpu_core *m68k, unsigned int address); -unsigned int m68k_read_memory_32(m68ki_cpu_core *m68k, unsigned int address); - -/* Read data immediately following the PC */ -unsigned int m68k_read_immediate_16(m68ki_cpu_core *m68k, unsigned int address); -unsigned int m68k_read_immediate_32(m68ki_cpu_core *m68k, unsigned int address); - -/* Read data relative to the PC */ -unsigned int m68k_read_pcrelative_8(m68ki_cpu_core *m68k, unsigned int address); -unsigned int m68k_read_pcrelative_16(m68ki_cpu_core *m68k, unsigned int address); -unsigned int m68k_read_pcrelative_32(m68ki_cpu_core *m68k, unsigned int address); - -/* Memory access for the disassembler */ -unsigned int m68k_read_disassembler_8 (unsigned int address); -unsigned int m68k_read_disassembler_16 (unsigned int address); -unsigned int m68k_read_disassembler_32 (unsigned int address); - -/* Write to anywhere */ -void m68k_write_memory_8(m68ki_cpu_core *m68k, unsigned int address, unsigned int value); -void m68k_write_memory_16(m68ki_cpu_core *m68k, unsigned int address, unsigned int value); -void m68k_write_memory_32(m68ki_cpu_core *m68k, unsigned int address, unsigned int value); - -/* Special call to simulate undocumented 68k behavior when move.l with a - * predecrement destination mode is executed. - * To simulate real 68k behavior, first write the high word to - * [address+2], and then write the low word to [address]. - */ -void m68k_write_memory_32_pd(m68ki_cpu_core *m68k, unsigned int address, unsigned int value); - - - /* ======================================================================== */ /* ============================== CALLBACKS =============================== */ /* ======================================================================== */ diff --git a/src/emu/cpu/m68000/m68k_in.c b/src/emu/cpu/m68000/m68k_in.c index 252ec1e6b47..ad4c154a354 100644 --- a/src/emu/cpu/m68000/m68k_in.c +++ b/src/emu/cpu/m68000/m68k_in.c @@ -3284,8 +3284,8 @@ M68KMAKE_OP(callm, 32, ., .) REG_PC += 2; (void)ea; /* just to avoid an 'unused variable' warning */ M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PC - 2), m68k->ir, - m68k_disassemble_quick(ADDRESS_68K(m68k, REG_PC - 2)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PC - 2, m68k->ir, + m68k_disassemble_quick(REG_PC - 2))); return; } m68ki_exception_illegal(m68k); @@ -4362,8 +4362,8 @@ M68KMAKE_OP(cpbcc, 32, ., .) if(CPU_TYPE_IS_EC020_PLUS(m68k->cpu_type)) { M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PC - 2), m68k->ir, - m68k_disassemble_quick(ADDRESS_68K(m68k, REG_PC - 2)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PC - 2, m68k->ir, + m68k_disassemble_quick(REG_PC - 2))); return; } m68ki_exception_1111(m68k); @@ -4375,8 +4375,8 @@ M68KMAKE_OP(cpdbcc, 32, ., .) if(CPU_TYPE_IS_EC020_PLUS(m68k->cpu_type)) { M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PC - 2), m68k->ir, - m68k_disassemble_quick(ADDRESS_68K(m68k, REG_PC - 2)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PC - 2, m68k->ir, + m68k_disassemble_quick(REG_PC - 2))); return; } m68ki_exception_1111(m68k); @@ -4388,8 +4388,8 @@ M68KMAKE_OP(cpgen, 32, ., .) if(CPU_TYPE_IS_EC020_PLUS(m68k->cpu_type)) { M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PC - 2), m68k->ir, - m68k_disassemble_quick(ADDRESS_68K(m68k, REG_PC - 2)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PC - 2, m68k->ir, + m68k_disassemble_quick(REG_PC - 2))); return; } m68ki_exception_1111(m68k); @@ -4401,8 +4401,8 @@ M68KMAKE_OP(cpscc, 32, ., .) if(CPU_TYPE_IS_EC020_PLUS(m68k->cpu_type)) { M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PC - 2), m68k->ir, - m68k_disassemble_quick(ADDRESS_68K(m68k, REG_PC - 2)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PC - 2, m68k->ir, + m68k_disassemble_quick(REG_PC - 2))); return; } m68ki_exception_1111(m68k); @@ -4414,8 +4414,8 @@ M68KMAKE_OP(cptrapcc, 32, ., .) if(CPU_TYPE_IS_EC020_PLUS(m68k->cpu_type)) { M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PC - 2), m68k->ir, - m68k_disassemble_quick(ADDRESS_68K(m68k, REG_PC - 2)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PC - 2, m68k->ir, + m68k_disassemble_quick(REG_PC - 2))); return; } m68ki_exception_1111(m68k); @@ -9326,8 +9326,8 @@ M68KMAKE_OP(rtm, 32, ., .) { m68ki_trace_t0(); /* auto-disable (see m68kcpu.h) */ M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PC - 2), m68k->ir, - m68k_disassemble_quick(ADDRESS_68K(m68k, REG_PC - 2)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PC - 2, m68k->ir, + m68k_disassemble_quick(REG_PC - 2))); return; } m68ki_exception_illegal(m68k); diff --git a/src/emu/cpu/m68000/m68kcpu.c b/src/emu/cpu/m68000/m68kcpu.c index c279a68a574..c004be60759 100644 --- a/src/emu/cpu/m68000/m68kcpu.c +++ b/src/emu/cpu/m68000/m68kcpu.c @@ -469,13 +469,6 @@ static int default_tas_instr_callback(void) return 1; // allow writeback } -/* Called when the program counter changed by a large value */ -static unsigned int default_pc_changed_callback_data; -static void default_pc_changed_callback(unsigned int new_pc) -{ - default_pc_changed_callback_data = new_pc; -} - /* Called every time there's bus activity (read/write to/from memory */ static unsigned int default_set_fc_callback_data; static void default_set_fc_callback(unsigned int new_fc) @@ -483,11 +476,6 @@ static void default_set_fc_callback(unsigned int new_fc) default_set_fc_callback_data = new_fc; } -/* Called every instruction cycle prior to execution */ -static void default_instr_hook_callback(unsigned int pc) -{ -} - /* ======================================================================== */ /* ================================= API ================================== */ @@ -636,21 +624,11 @@ void m68k_set_tas_instr_callback(m68ki_cpu_core *m68k, int (*callback)(void)) m68k->tas_instr_callback = callback ? callback : default_tas_instr_callback; } -void m68k_set_pc_changed_callback(m68ki_cpu_core *m68k, void (*callback)(unsigned int new_pc)) -{ - m68k->pc_changed_callback = callback ? callback : default_pc_changed_callback; -} - void m68k_set_fc_callback(m68ki_cpu_core *m68k, void (*callback)(unsigned int new_fc)) { m68k->set_fc_callback = callback ? callback : default_set_fc_callback; } -void m68k_set_instr_hook_callback(m68ki_cpu_core *m68k, void (*callback)(unsigned int pc)) -{ - m68k->instr_hook_callback = callback ? callback : default_instr_hook_callback; -} - #include /* Set the CPU type. */ void m68k_set_cpu_type(m68ki_cpu_core *m68k, unsigned int cpu_type) @@ -659,7 +637,6 @@ void m68k_set_cpu_type(m68ki_cpu_core *m68k, unsigned int cpu_type) { case M68K_CPU_TYPE_68000: m68k->cpu_type = CPU_TYPE_000; - m68k->address_mask = 0x00ffffff; m68k->sr_mask = 0xa71f; /* T1 -- S -- -- I2 I1 I0 -- -- -- X N Z V C */ m68k->cyc_instruction = m68ki_cycles[0]; m68k->cyc_exception = m68ki_exception_cycle_table[0]; @@ -675,7 +652,6 @@ void m68k_set_cpu_type(m68ki_cpu_core *m68k, unsigned int cpu_type) return; case M68K_CPU_TYPE_68008: m68k->cpu_type = CPU_TYPE_008; - m68k->address_mask = 0x003fffff; m68k->sr_mask = 0xa71f; /* T1 -- S -- -- I2 I1 I0 -- -- -- X N Z V C */ m68k->cyc_instruction = m68ki_cycles[0]; m68k->cyc_exception = m68ki_exception_cycle_table[0]; @@ -691,7 +667,6 @@ void m68k_set_cpu_type(m68ki_cpu_core *m68k, unsigned int cpu_type) return; case M68K_CPU_TYPE_68010: m68k->cpu_type = CPU_TYPE_010; - m68k->address_mask = 0x00ffffff; m68k->sr_mask = 0xa71f; /* T1 -- S -- -- I2 I1 I0 -- -- -- X N Z V C */ m68k->cyc_instruction = m68ki_cycles[1]; m68k->cyc_exception = m68ki_exception_cycle_table[1]; @@ -707,7 +682,6 @@ void m68k_set_cpu_type(m68ki_cpu_core *m68k, unsigned int cpu_type) return; case M68K_CPU_TYPE_68EC020: m68k->cpu_type = CPU_TYPE_EC020; - m68k->address_mask = 0x00ffffff; m68k->sr_mask = 0xf71f; /* T1 T0 S M -- I2 I1 I0 -- -- -- X N Z V C */ m68k->cyc_instruction = m68ki_cycles[2]; m68k->cyc_exception = m68ki_exception_cycle_table[2]; @@ -723,7 +697,6 @@ void m68k_set_cpu_type(m68ki_cpu_core *m68k, unsigned int cpu_type) return; case M68K_CPU_TYPE_68020: m68k->cpu_type = CPU_TYPE_020; - m68k->address_mask = 0xffffffff; m68k->sr_mask = 0xf71f; /* T1 T0 S M -- I2 I1 I0 -- -- -- X N Z V C */ m68k->cyc_instruction = m68ki_cycles[2]; m68k->cyc_exception = m68ki_exception_cycle_table[2]; @@ -739,7 +712,6 @@ void m68k_set_cpu_type(m68ki_cpu_core *m68k, unsigned int cpu_type) return; case M68K_CPU_TYPE_68040: // TODO: these values are not correct m68k->cpu_type = CPU_TYPE_040; - m68k->address_mask = 0xffffffff; m68k->sr_mask = 0xf71f; /* T1 T0 S M -- I2 I1 I0 -- -- -- X N Z V C */ m68k->cyc_instruction = m68ki_cycles[2]; m68k->cyc_exception = m68ki_exception_cycle_table[2]; @@ -887,9 +859,7 @@ void m68k_init(m68ki_cpu_core *m68k) m68k_set_cmpild_instr_callback(m68k, NULL); m68k_set_rte_instr_callback(m68k, NULL); m68k_set_tas_instr_callback(m68k, NULL); - m68k_set_pc_changed_callback(m68k, NULL); m68k_set_fc_callback(m68k, NULL); - m68k_set_instr_hook_callback(m68k, NULL); } /* Pulse the RESET line on the CPU */ diff --git a/src/emu/cpu/m68000/m68kcpu.h b/src/emu/cpu/m68000/m68kcpu.h index dff1bfdb01d..2637256cd1b 100644 --- a/src/emu/cpu/m68000/m68kcpu.h +++ b/src/emu/cpu/m68000/m68kcpu.h @@ -38,8 +38,6 @@ typedef struct _m68ki_cpu_core m68ki_cpu_core; /* ======================================================================== */ /* Check for > 32bit sizes */ -#define M68K_INT_GT_32_BIT 0 - #define MAKE_INT_8(A) (INT8)(A) #define MAKE_INT_16(A) (INT16)(A) #define MAKE_INT_32(A) (INT32)(A) @@ -159,7 +157,7 @@ typedef struct _m68ki_cpu_core m68ki_cpu_core; #define MASK_OUT_BELOW_16(A) ((A) & ~0xffff) /* No need to mask if we are 32 bit */ -#if M68K_INT_GT_32_BIT || M68K_USE_64_BIT +#if M68K_USE_64_BIT #define MASK_OUT_ABOVE_32(A) ((A) & 0xffffffff) #define MASK_OUT_BELOW_32(A) ((A) & ~0xffffffff) #else @@ -167,26 +165,15 @@ typedef struct _m68ki_cpu_core m68ki_cpu_core; #define MASK_OUT_BELOW_32(A) 0 #endif /* M68K_INT_GT_32_BIT || M68K_USE_64_BIT */ -/* Simulate address lines of 68k family */ -#define ADDRESS_68K(M, A) ((A) & (M)->address_mask) - - /* Shift & Rotate Macros. */ #define LSL(A, C) ((A) << (C)) #define LSR(A, C) ((A) >> (C)) -/* Some > 32-bit optimizations */ -#if M68K_INT_GT_32_BIT - /* Shift left and right */ - #define LSR_32(A, C) ((A) >> (C)) - #define LSL_32(A, C) ((A) << (C)) -#else - /* We have to do this because the morons at ANSI decided that shifts - * by >= data size are undefined. - */ - #define LSR_32(A, C) ((C) < 32 ? (A) >> (C) : 0) - #define LSL_32(A, C) ((C) < 32 ? (A) << (C) : 0) -#endif /* M68K_INT_GT_32_BIT */ +/* We have to do this because the morons at ANSI decided that shifts +* by >= data size are undefined. +*/ +#define LSR_32(A, C) ((C) < 32 ? (A) >> (C) : 0) +#define LSL_32(A, C) ((C) < 32 ? (A) << (C) : 0) #if M68K_USE_64_BIT #define LSL_32_64(A, C) ((A) << (C)) @@ -283,16 +270,6 @@ typedef struct _m68ki_cpu_core m68ki_cpu_core; #endif -#if !M68K_SEPARATE_READS -#define m68k_read_immediate_16(M, A) m68ki_read_program_16(M, A) -#define m68k_read_immediate_32(M, A) m68ki_read_program_32(M, A) - -#define m68k_read_pcrelative_8(M, A) m68ki_read_program_8(M, A) -#define m68k_read_pcrelative_16(M, A) m68ki_read_program_16(M, A) -#define m68k_read_pcrelative_32(M, A) m68ki_read_program_32(M, A) -#endif /* M68K_SEPARATE_READS */ - - /* Enable or disable function code emulation */ #if M68K_EMULATE_FC #if M68K_EMULATE_FC == OPT_SPECIFY_HANDLER @@ -447,13 +424,8 @@ typedef struct _m68ki_cpu_core m68ki_cpu_core; #define CFLAG_8(A) (A) #define CFLAG_16(A) ((A)>>8) -#if M68K_INT_GT_32_BIT - #define CFLAG_ADD_32(S, D, R) ((R)>>24) - #define CFLAG_SUB_32(S, D, R) ((R)>>24) -#else - #define CFLAG_ADD_32(S, D, R) (((S & D) | (~R & (S | D)))>>23) - #define CFLAG_SUB_32(S, D, R) (((S & R) | (~D & (S | R)))>>23) -#endif /* M68K_INT_GT_32_BIT */ +#define CFLAG_ADD_32(S, D, R) (((S & D) | (~R & (S | D)))>>23) +#define CFLAG_SUB_32(S, D, R) (((S & R) | (~D & (S | R)))>>23) #define VFLAG_ADD_8(S, D, R) ((S^R) & (D^R)) #define VFLAG_ADD_16(S, D, R) (((S^R) & (D^R))>>8) @@ -638,7 +610,6 @@ struct _m68ki_cpu_core UINT32 stopped; /* Stopped state */ UINT32 pref_addr; /* Last prefetch address */ UINT32 pref_data; /* Data in the prefetch queue */ - UINT32 address_mask; /* Available address pins */ UINT32 sr_mask; /* Implemented status register bits */ UINT32 instr_mode; /* Stores whether we are in instruction mode or group 0/1 exception mode */ UINT32 run_mode; /* Stores whether we are processing a reset, bus error, address error, or something else */ @@ -679,10 +650,13 @@ struct _m68ki_cpu_core void (*cmpild_instr_callback)(unsigned int, int); /* Called when a CMPI.L #v, Dn instruction is encountered */ void (*rte_instr_callback)(void); /* Called when a RTE instruction is encountered */ int (*tas_instr_callback)(void); /* Called when a TAS instruction is encountered, allows / disallows writeback */ - void (*pc_changed_callback)(unsigned int new_pc); /* Called when the PC changes by a large amount */ void (*set_fc_callback)(unsigned int new_fc); /* Called when the CPU function code changes */ - void (*instr_hook_callback)(unsigned int pc); /* Called every instruction cycle prior to execution */ + const device_config *device; + const address_space *program; + m68k_memory_interface memory; + offs_t encrypted_start; + offs_t encrypted_end; }; @@ -815,6 +789,48 @@ char* m68ki_disassemble_quick(unsigned int pc, unsigned int cpu_type); /* ======================================================================== */ +INLINE unsigned int m68k_read_immediate_32(m68ki_cpu_core *m68k, unsigned int address) +{ + return ((*m68k->memory.readimm16)(m68k->program, address) << 16) | (*m68k->memory.readimm16)(m68k->program, address + 2); +} + +INLINE unsigned int m68k_read_pcrelative_8(m68ki_cpu_core *m68k, unsigned int address) +{ + if (address >= m68k->encrypted_start && address < m68k->encrypted_end) + return (((*m68k->memory.readimm16)(m68k->program, address&~1)>>(8*(1-(address & 1))))&0xff); + else + return (*m68k->memory.read8)(m68k->program, address); +} + +INLINE unsigned int m68k_read_pcrelative_16(m68ki_cpu_core *m68k, unsigned int address) +{ + if (address >= m68k->encrypted_start && address < m68k->encrypted_end) + return (*m68k->memory.readimm16)(m68k->program, address); + else + return (*m68k->memory.read16)(m68k->program, address); +} + +INLINE unsigned int m68k_read_pcrelative_32(m68ki_cpu_core *m68k, unsigned int address) +{ + if (address >= m68k->encrypted_start && address < m68k->encrypted_end) + return m68k_read_immediate_32(m68k, address); + else + return (*m68k->memory.read32)(m68k->program, address); +} + + +/* Special call to simulate undocumented 68k behavior when move.l with a + * predecrement destination mode is executed. + * A real 68k first writes the high word to [address+2], and then writes the + * low word to [address]. + */ +INLINE void m68kx_write_memory_32_pd(m68ki_cpu_core *m68k, unsigned int address, unsigned int value) +{ + (m68k->memory.write16)(m68k->program, address+2, value>>16); + (m68k->memory.write16)(m68k->program, address, value&0xffff); +} + + /* ---------------------------- Read Immediate ---------------------------- */ /* Handles all immediate reads, does address error check, function code setting, @@ -830,12 +846,12 @@ INLINE UINT32 m68ki_read_imm_16(m68ki_cpu_core *m68k) if(REG_PC != m68k->pref_addr) { m68k->pref_addr = REG_PC; - m68k->pref_data = m68k_read_immediate_16(m68k, ADDRESS_68K(m68k, m68k->pref_addr)); + m68k->pref_data = (*m68k->memory.readimm16)(m68k->program, m68k->pref_addr); } result = MASK_OUT_ABOVE_16(m68k->pref_data); REG_PC += 2; m68k->pref_addr = REG_PC; - m68k->pref_data = m68k_read_immediate_16(m68k, ADDRESS_68K(m68k, m68k->pref_addr)); + m68k->pref_data = (*m68k->memory.readimm16)(m68k->program, m68k->pref_addr); return result; } @@ -849,17 +865,17 @@ INLINE UINT32 m68ki_read_imm_32(m68ki_cpu_core *m68k) if(REG_PC != m68k->pref_addr) { m68k->pref_addr = REG_PC; - m68k->pref_data = m68k_read_immediate_16(m68k, ADDRESS_68K(m68k, m68k->pref_addr)); + m68k->pref_data = (*m68k->memory.readimm16)(m68k->program, m68k->pref_addr); } temp_val = MASK_OUT_ABOVE_16(m68k->pref_data); REG_PC += 2; m68k->pref_addr = REG_PC; - m68k->pref_data = m68k_read_immediate_16(m68k, ADDRESS_68K(m68k, m68k->pref_addr)); + m68k->pref_data = (*m68k->memory.readimm16)(m68k->program, m68k->pref_addr); temp_val = MASK_OUT_ABOVE_32((temp_val << 16) | MASK_OUT_ABOVE_16(m68k->pref_data)); REG_PC += 2; m68k->pref_addr = REG_PC; - m68k->pref_data = m68k_read_immediate_16(m68k, ADDRESS_68K(m68k, m68k->pref_addr)); + m68k->pref_data = (*m68k->memory.readimm16)(m68k->program, m68k->pref_addr); return temp_val; } @@ -877,7 +893,7 @@ INLINE UINT32 m68ki_read_imm_32(m68ki_cpu_core *m68k) INLINE UINT32 m68ki_read_8_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc) { m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */ - return m68k_read_memory_8(m68k, ADDRESS_68K(m68k, address)); + return (*m68k->memory.read8)(m68k->program, address); } INLINE UINT32 m68ki_read_16_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc) { @@ -886,7 +902,7 @@ INLINE UINT32 m68ki_read_16_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc) { m68ki_check_address_error(m68k, address, MODE_READ, fc); } - return m68k_read_memory_16(m68k, ADDRESS_68K(m68k, address)); + return (*m68k->memory.read16)(m68k->program, address); } INLINE UINT32 m68ki_read_32_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc) { @@ -895,13 +911,13 @@ INLINE UINT32 m68ki_read_32_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc) { m68ki_check_address_error(m68k, address, MODE_READ, fc); } - return m68k_read_memory_32(m68k, ADDRESS_68K(m68k, address)); + return (*m68k->memory.read32)(m68k->program, address); } INLINE void m68ki_write_8_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc, UINT32 value) { m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */ - m68k_write_memory_8(m68k, ADDRESS_68K(m68k, address), value); + (*m68k->memory.write8)(m68k->program, address, value); } INLINE void m68ki_write_16_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc, UINT32 value) { @@ -910,7 +926,7 @@ INLINE void m68ki_write_16_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc, U { m68ki_check_address_error(m68k, address, MODE_WRITE, fc); } - m68k_write_memory_16(m68k, ADDRESS_68K(m68k, address), value); + (*m68k->memory.write16)(m68k->program, address, value); } INLINE void m68ki_write_32_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc, UINT32 value) { @@ -919,9 +935,14 @@ INLINE void m68ki_write_32_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc, U { m68ki_check_address_error(m68k, address, MODE_WRITE, fc); } - m68k_write_memory_32(m68k, ADDRESS_68K(m68k, address), value); + (*m68k->memory.write32)(m68k->program, address, value); } +/* Special call to simulate undocumented 68k behavior when move.l with a + * predecrement destination mode is executed. + * A real 68k first writes the high word to [address+2], and then writes the + * low word to [address]. + */ INLINE void m68ki_write_32_pd_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc, UINT32 value) { m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */ @@ -929,7 +950,8 @@ INLINE void m68ki_write_32_pd_fc(m68ki_cpu_core *m68k, UINT32 address, UINT32 fc { m68ki_check_address_error(m68k, address, MODE_WRITE, fc); } - m68k_write_memory_32_pd(m68k, ADDRESS_68K(m68k, address), value); + (*m68k->memory.write16)(m68k->program, address+2, value>>16); + (*m68k->memory.write16)(m68k->program, address, value&0xffff); } @@ -1178,14 +1200,14 @@ INLINE void m68ki_fake_pull_32(m68ki_cpu_core *m68k) INLINE void m68ki_jump(m68ki_cpu_core *m68k, UINT32 new_pc) { REG_PC = new_pc; - change_pc(ADDRESS_68K(m68k, REG_PC)); + change_pc(REG_PC); } INLINE void m68ki_jump_vector(m68ki_cpu_core *m68k, UINT32 vector) { REG_PC = (vector<<2) + m68k->vbr; REG_PC = m68ki_read_data_32(m68k, REG_PC); - change_pc(ADDRESS_68K(m68k, REG_PC)); + change_pc(REG_PC); } @@ -1207,7 +1229,7 @@ INLINE void m68ki_branch_16(m68ki_cpu_core *m68k, UINT32 offset) INLINE void m68ki_branch_32(m68ki_cpu_core *m68k, UINT32 offset) { REG_PC += offset; - change_pc(ADDRESS_68K(m68k, REG_PC)); + change_pc(REG_PC); } @@ -1625,8 +1647,8 @@ INLINE void m68ki_exception_1010(m68ki_cpu_core *m68k) UINT32 sr; #if M68K_LOG_1010_1111 == OPT_ON M68K_DO_LOG_EMU((M68K_LOG_FILEHANDLE "%s at %08x: called 1010 instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PPC), m68k->ir, - m68ki_disassemble_quick(ADDRESS_68K(m68k, REG_PPC)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PPC, m68k->ir, + m68ki_disassemble_quick(REG_PPC))); #endif sr = m68ki_init_exception(m68k); @@ -1644,8 +1666,8 @@ INLINE void m68ki_exception_1111(m68ki_cpu_core *m68k) #if M68K_LOG_1010_1111 == OPT_ON M68K_DO_LOG_EMU((M68K_LOG_FILEHANDLE "%s at %08x: called 1111 instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PPC), m68k->ir, - m68ki_disassemble_quick(ADDRESS_68K(m68k, REG_PPC)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PPC, m68k->ir, + m68ki_disassemble_quick(REG_PPC))); #endif sr = m68ki_init_exception(m68k); @@ -1662,8 +1684,8 @@ INLINE void m68ki_exception_illegal(m68ki_cpu_core *m68k) UINT32 sr; M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: illegal instruction %04x (%s)\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PPC), m68k->ir, - m68ki_disassemble_quick(ADDRESS_68K(m68k, REG_PPC)))); + m68ki_cpu_get_names[m68k->cpu_type], REG_PPC, m68k->ir, + m68ki_disassemble_quick(REG_PPC))); sr = m68ki_init_exception(m68k); @@ -1701,7 +1723,7 @@ INLINE void m68ki_exception_address_error(m68ki_cpu_core *m68k) */ if(m68k->run_mode == RUN_MODE_BERR_AERR_RESET) { - m68k_read_memory_8(m68k, 0x00ffff01); + (*m68k->memory.read8)(m68k->program, 0x00ffff01); m68k->stopped = STOP_LEVEL_HALT; return; } @@ -1749,7 +1771,7 @@ void m68ki_exception_interrupt(m68ki_cpu_core *m68k, UINT32 int_level) else if(vector > 255) { M68K_DO_LOG_EMU((M68K_LOG_FILEHANDLE "%s at %08x: Interrupt acknowledge returned invalid vector $%x\n", - m68ki_cpu_get_names[m68k->cpu_type], ADDRESS_68K(m68k, REG_PC), vector)); + m68ki_cpu_get_names[m68k->cpu_type], REG_PC, vector)); return; } diff --git a/src/emu/cpu/m68000/m68kdasm.c b/src/emu/cpu/m68000/m68kdasm.c index 4e52b50d276..4581058214a 100644 --- a/src/emu/cpu/m68000/m68kdasm.c +++ b/src/emu/cpu/m68000/m68kdasm.c @@ -192,9 +192,6 @@ static void (*g_instruction_table[0x10000])(void); /* Flag if disassembler initialized */ static int g_initialized = 0; -/* Address mask to simulate address lines */ -static unsigned int g_address_mask = 0xffffffff; - static char g_dasm_str[100]; /* string to hold disassembly */ static char g_helper_str[100]; /* string to hold helpful info */ static UINT32 g_cpu_pc; /* program counter */ @@ -245,10 +242,7 @@ static const char *const g_cpcc[64] = static UINT32 dasm_read_imm_8(UINT32 advance) { UINT32 result; -// if (g_rawop) - result = g_rawop[g_cpu_pc + 1 - g_rawbasepc]; -// else -// result = m68k_read_disassembler_16(g_cpu_pc & g_address_mask) & 0xff; + result = g_rawop[g_cpu_pc + 1 - g_rawbasepc]; g_cpu_pc += advance; return result; } @@ -256,11 +250,8 @@ static UINT32 dasm_read_imm_8(UINT32 advance) static UINT32 dasm_read_imm_16(UINT32 advance) { UINT32 result; -// if (g_rawop) - result = (g_rawop[g_cpu_pc + 0 - g_rawbasepc] << 8) | - g_rawop[g_cpu_pc + 1 - g_rawbasepc]; -// else -// result = m68k_read_disassembler_16(g_cpu_pc & g_address_mask) & 0xff; + result = (g_rawop[g_cpu_pc + 0 - g_rawbasepc] << 8) | + g_rawop[g_cpu_pc + 1 - g_rawbasepc]; g_cpu_pc += advance; return result; } @@ -268,13 +259,10 @@ static UINT32 dasm_read_imm_16(UINT32 advance) static UINT32 dasm_read_imm_32(UINT32 advance) { UINT32 result; -// if (g_rawop) - result = (g_rawop[g_cpu_pc + 0 - g_rawbasepc] << 24) | - (g_rawop[g_cpu_pc + 1 - g_rawbasepc] << 16) | - (g_rawop[g_cpu_pc + 2 - g_rawbasepc] << 8) | - g_rawop[g_cpu_pc + 3 - g_rawbasepc]; -// else -// result = m68k_read_disassembler_32(g_cpu_pc & g_address_mask) & 0xff; + result = (g_rawop[g_cpu_pc + 0 - g_rawbasepc] << 24) | + (g_rawop[g_cpu_pc + 1 - g_rawbasepc] << 16) | + (g_rawop[g_cpu_pc + 2 - g_rawbasepc] << 8) | + g_rawop[g_cpu_pc + 3 - g_rawbasepc]; g_cpu_pc += advance; return result; } @@ -3471,31 +3459,24 @@ unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_ { case M68K_CPU_TYPE_68000: g_cpu_type = TYPE_68000; - g_address_mask = 0x00ffffff; break; case M68K_CPU_TYPE_68008: g_cpu_type = TYPE_68008; - g_address_mask = 0x003fffff; break; case M68K_CPU_TYPE_68010: g_cpu_type = TYPE_68010; - g_address_mask = 0x00ffffff; break; case M68K_CPU_TYPE_68EC020: g_cpu_type = TYPE_68020; - g_address_mask = 0x00ffffff; break; case M68K_CPU_TYPE_68020: g_cpu_type = TYPE_68020; - g_address_mask = 0xffffffff; break; case M68K_CPU_TYPE_68030: g_cpu_type = TYPE_68030; - g_address_mask = 0xffffffff; break; case M68K_CPU_TYPE_68040: g_cpu_type = TYPE_68040; - g_address_mask = 0xffffffff; break; default: return 0; diff --git a/src/emu/cpu/m68000/m68kmame.c b/src/emu/cpu/m68000/m68kmame.c index 7121a5ad2b7..19885870550 100644 --- a/src/emu/cpu/m68000/m68kmame.c +++ b/src/emu/cpu/m68000/m68kmame.c @@ -5,22 +5,18 @@ /* global access */ -m68k_memory_interface m68k_memory_intf; -offs_t m68k_encrypted_opcode_start[MAX_CPU]; -offs_t m68k_encrypted_opcode_end[MAX_CPU]; - - -void m68k_set_encrypted_opcode_range(int cpunum, offs_t start, offs_t end) +void m68k_set_encrypted_opcode_range(const device_config *device, offs_t start, offs_t end) { - m68k_encrypted_opcode_start[cpunum] = start; - m68k_encrypted_opcode_end[cpunum] = end; + m68ki_cpu_core *m68k = device->token; + m68k->encrypted_start = start; + m68k->encrypted_end = end; } /**************************************************************************** * 8-bit data memory interface ****************************************************************************/ -static UINT16 m68008_read_immediate_16(offs_t address) +static UINT16 m68008_read_immediate_16(const address_space *space, offs_t address) { offs_t addr = address; return (cpu_readop(addr) << 8) | (cpu_readop(addr + 1)); @@ -31,34 +27,40 @@ static const m68k_memory_interface interface_d8 = { 0, m68008_read_immediate_16, - program_read_byte_8be, - program_read_word_8be, - program_read_dword_8be, - program_write_byte_8be, - program_write_word_8be, - program_write_dword_8be + memory_read_byte_8be, + memory_read_word_8be, + memory_read_dword_8be, + memory_write_byte_8be, + memory_write_word_8be, + memory_write_dword_8be }; /**************************************************************************** * 16-bit data memory interface ****************************************************************************/ -static UINT16 read_immediate_16(offs_t address) +static UINT16 read_immediate_16(const address_space *space, offs_t address) { - return cpu_readop16((address) ^ m68k_memory_intf.opcode_xor); + m68ki_cpu_core *m68k = space->cpu->token; + return cpu_readop16((address) ^ m68k->memory.opcode_xor); +} + +static UINT16 simple_read_immediate_16(const address_space *space, offs_t address) +{ + return cpu_readop16(address); } /* interface for 24-bit address bus, 16-bit data bus (68000, 68010) */ static const m68k_memory_interface interface_d16 = { 0, - cpu_readop16, - program_read_byte_16be, - program_read_word_16be, - program_read_dword_16be, - program_write_byte_16be, - program_write_word_16be, - program_write_dword_16be + simple_read_immediate_16, + memory_read_byte_16be, + memory_read_word_16be, + memory_read_dword_16be, + memory_write_byte_16be, + memory_write_word_16be, + memory_write_dword_16be }; /**************************************************************************** @@ -66,62 +68,62 @@ static const m68k_memory_interface interface_d16 = ****************************************************************************/ /* potentially misaligned 16-bit reads with a 32-bit data bus (and 24-bit address bus) */ -static UINT16 readword_d32(offs_t address) +static UINT16 readword_d32(const address_space *space, offs_t address) { UINT16 result; if (!(address & 1)) - return program_read_word_32be(address); - result = program_read_byte_32be(address) << 8; - return result | program_read_byte_32be(address + 1); + return memory_read_word_32be(space, address); + result = memory_read_byte_32be(space, address) << 8; + return result | memory_read_byte_32be(space, address + 1); } /* potentially misaligned 16-bit writes with a 32-bit data bus (and 24-bit address bus) */ -static void writeword_d32(offs_t address, UINT16 data) +static void writeword_d32(const address_space *space, offs_t address, UINT16 data) { if (!(address & 1)) { - program_write_word_32be(address, data); + memory_write_word_32be(space, address, data); return; } - program_write_byte_32be(address, data >> 8); - program_write_byte_32be(address + 1, data); + memory_write_byte_32be(space, address, data >> 8); + memory_write_byte_32be(space, address + 1, data); } /* potentially misaligned 32-bit reads with a 32-bit data bus (and 24-bit address bus) */ -static UINT32 readlong_d32(offs_t address) +static UINT32 readlong_d32(const address_space *space, offs_t address) { UINT32 result; if (!(address & 3)) - return program_read_dword_32be(address); + return memory_read_dword_32be(space, address); else if (!(address & 1)) { - result = program_read_word_32be(address) << 16; - return result | program_read_word_32be(address + 2); + result = memory_read_word_32be(space, address) << 16; + return result | memory_read_word_32be(space, address + 2); } - result = program_read_byte_32be(address) << 24; - result |= program_read_word_32be(address + 1) << 8; - return result | program_read_byte_32be(address + 3); + result = memory_read_byte_32be(space, address) << 24; + result |= memory_read_word_32be(space, address + 1) << 8; + return result | memory_read_byte_32be(space, address + 3); } /* potentially misaligned 32-bit writes with a 32-bit data bus (and 24-bit address bus) */ -static void writelong_d32(offs_t address, UINT32 data) +static void writelong_d32(const address_space *space, offs_t address, UINT32 data) { if (!(address & 3)) { - program_write_dword_32be(address, data); + memory_write_dword_32be(space, address, data); return; } else if (!(address & 1)) { - program_write_word_32be(address, data >> 16); - program_write_word_32be(address + 2, data); + memory_write_word_32be(space, address, data >> 16); + memory_write_word_32be(space, address + 2, data); return; } - program_write_byte_32be(address, data >> 24); - program_write_word_32be(address + 1, data >> 8); - program_write_byte_32be(address + 3, data); + memory_write_byte_32be(space, address, data >> 24); + memory_write_word_32be(space, address + 1, data >> 8); + memory_write_byte_32be(space, address + 3, data); } /* interface for 32-bit data bus (68EC020, 68020) */ @@ -129,10 +131,10 @@ static const m68k_memory_interface interface_d32 = { WORD_XOR_BE(0), read_immediate_16, - program_read_byte_32be, + memory_read_byte_32be, readword_d32, readlong_d32, - program_write_byte_32be, + memory_write_byte_32be, writeword_d32, writelong_d32 }; @@ -154,9 +156,11 @@ static void set_irq_line(m68ki_cpu_core *m68k, int irqline, int state) static CPU_INIT( m68000 ) { m68ki_cpu_core *m68k = device->token; + m68k->device = device; + m68k->program = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM); + m68k->memory = interface_d16; m68k_init(m68k); m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68000); - m68k_memory_intf = interface_d16; m68k_state_register(m68k, "m68000", index); m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback); } @@ -182,8 +186,6 @@ static CPU_GET_CONTEXT( m68000 ) static CPU_SET_CONTEXT( m68000 ) { - if (m68k_memory_intf.read8 != program_read_byte_16be) - m68k_memory_intf = interface_d16; } static CPU_DISASSEMBLE( m68000 ) @@ -199,9 +201,11 @@ static CPU_DISASSEMBLE( m68000 ) static CPU_INIT( m68008 ) { m68ki_cpu_core *m68k = device->token; + m68k->device = device; + m68k->program = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM); + m68k->memory = interface_d8; m68k_init(m68k); m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68008); - m68k_memory_intf = interface_d8; m68k_state_register(m68k, "m68008", index); m68k_set_int_ack_callback(m68k, (void *)device, irqcallback); } @@ -227,8 +231,6 @@ static CPU_GET_CONTEXT( m68008 ) static CPU_SET_CONTEXT( m68008 ) { - if (m68k_memory_intf.read8 != program_read_byte_8be) - m68k_memory_intf = interface_d8; } static CPU_DISASSEMBLE( m68008 ) @@ -246,9 +248,11 @@ static CPU_DISASSEMBLE( m68008 ) static CPU_INIT( m68010 ) { m68ki_cpu_core *m68k = device->token; + m68k->device = device; + m68k->program = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM); + m68k->memory = interface_d16; m68k_init(m68k); m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68010); - m68k_memory_intf = interface_d16; m68k_state_register(m68k, "m68010", index); m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback); } @@ -267,9 +271,11 @@ static CPU_DISASSEMBLE( m68010 ) static CPU_INIT( m68020 ) { m68ki_cpu_core *m68k = device->token; + m68k->device = device; + m68k->program = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM); + m68k->memory = interface_d32; m68k_init(m68k); m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68020); - m68k_memory_intf = interface_d32; m68k_state_register(m68k, "m68020", index); m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback); } @@ -295,8 +301,6 @@ static CPU_GET_CONTEXT( m68020 ) static CPU_SET_CONTEXT( m68020 ) { - if (m68k_memory_intf.read8 != program_read_byte_32be) - m68k_memory_intf = interface_d32; } static CPU_DISASSEMBLE( m68020 ) @@ -313,9 +317,11 @@ static CPU_DISASSEMBLE( m68020 ) static CPU_INIT( m68ec020 ) { m68ki_cpu_core *m68k = device->token; + m68k->device = device; + m68k->program = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM); + m68k->memory = interface_d32; m68k_init(m68k); m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68EC020); - m68k_memory_intf = interface_d32; m68k_state_register(m68k, "m68ec020", index); m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback); } @@ -335,9 +341,11 @@ static CPU_DISASSEMBLE( m68ec020 ) static CPU_INIT( m68040 ) { m68ki_cpu_core *m68k = device->token; + m68k->device = device; + m68k->program = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM); + m68k->memory = interface_d32; m68k_init(m68k); m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68040); - m68k_memory_intf = interface_d32; m68k_state_register(m68k, "m68040", index); m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback); } @@ -363,8 +371,6 @@ static CPU_GET_CONTEXT( m68040 ) static CPU_SET_CONTEXT( m68040 ) { - if (m68k_memory_intf.read8 != program_read_byte_32be) - m68k_memory_intf = interface_d32; } static CPU_DISASSEMBLE( m68040 ) diff --git a/src/emu/cpu/m68000/m68kmame.h b/src/emu/cpu/m68000/m68kmame.h index dc926f41e95..67f43550bcf 100644 --- a/src/emu/cpu/m68000/m68kmame.h +++ b/src/emu/cpu/m68000/m68kmame.h @@ -11,16 +11,10 @@ #include "deprecat.h" #include "m68000.h" -#ifndef __M68KCPU_H__ -#define m68ki_cpu_core void -#endif - #define OPT_ON 1 #define OPT_OFF 0 /* Configuration switches (see m68kconf.h for explanation) */ -#define M68K_SEPARATE_READS OPT_ON - #define M68K_EMULATE_TRACE OPT_OFF #define M68K_EMULATE_FC OPT_OFF @@ -33,82 +27,7 @@ #define M68K_USE_64_BIT OPT_OFF -extern m68k_memory_interface m68k_memory_intf; -extern offs_t m68k_encrypted_opcode_start[MAX_CPU]; -extern offs_t m68k_encrypted_opcode_end[MAX_CPU]; - -#define m68k_read_memory_8(M, A) (*m68k_memory_intf.read8)(A) -#define m68k_read_memory_16(M, A) (*m68k_memory_intf.read16)(A) -#define m68k_read_memory_32(M, A) (*m68k_memory_intf.read32)(A) - -#define m68k_read_immediate_16(M, A) (*m68k_memory_intf.readimm16)(A) -#define m68k_read_immediate_32(M, A) m68kx_read_immediate_32(M, A) -#define m68k_read_pcrelative_8(M, A) m68kx_read_pcrelative_8(M, A) -#define m68k_read_pcrelative_16(M, A) m68kx_read_pcrelative_16(M, A) -#define m68k_read_pcrelative_32(M, A) m68kx_read_pcrelative_32(M, A) - -#define m68k_read_disassembler_16(M, A) m68k_read_immediate_16(M, A) -#define m68k_read_disassembler_32(M, A) m68kx_read_immediate_32(M, A) - -#define m68k_write_memory_8(M, A, V) (*m68k_memory_intf.write8)(A, V) -#define m68k_write_memory_16(M, A, V) (*m68k_memory_intf.write16)(A, V) -#define m68k_write_memory_32(M, A, V) (*m68k_memory_intf.write32)(A, V) -#define m68k_write_memory_32_pd(M, A, V) m68kx_write_memory_32_pd(M, A, V) - - -INLINE unsigned int m68k_read_immediate_32(m68ki_cpu_core *m68k, unsigned int address); -INLINE unsigned int m68k_read_pcrelative_8(m68ki_cpu_core *m68k, unsigned int address); -INLINE unsigned int m68k_read_pcrelative_16(m68ki_cpu_core *m68k, unsigned int address); -INLINE unsigned int m68k_read_pcrelative_32(m68ki_cpu_core *m68k, unsigned int address); -INLINE void m68k_write_memory_32_pd(m68ki_cpu_core *m68k, unsigned int address, unsigned int value); - - -INLINE unsigned int m68kx_read_immediate_32(m68ki_cpu_core *m68k, unsigned int address) -{ - return ((m68k_read_immediate_16(m68k, address) << 16) | m68k_read_immediate_16(m68k, (address)+2)); -} - -INLINE unsigned int m68kx_read_pcrelative_8(m68ki_cpu_core *m68k, unsigned int address) -{ - if (address >= m68k_encrypted_opcode_start[cpunum_get_active()] && - address < m68k_encrypted_opcode_end[cpunum_get_active()]) - return ((m68k_read_immediate_16(m68k, address&~1)>>(8*(1-(address & 1))))&0xff); - else - return m68k_read_memory_8(m68k, address); -} - -INLINE unsigned int m68kx_read_pcrelative_16(m68ki_cpu_core *m68k, unsigned int address) -{ - if (address >= m68k_encrypted_opcode_start[cpunum_get_active()] && - address < m68k_encrypted_opcode_end[cpunum_get_active()]) - return m68k_read_immediate_16(m68k, address); - else - return m68k_read_memory_16(m68k, address); -} - -INLINE unsigned int m68kx_read_pcrelative_32(m68ki_cpu_core *m68k, unsigned int address) -{ - if (address >= m68k_encrypted_opcode_start[cpunum_get_active()] && - address < m68k_encrypted_opcode_end[cpunum_get_active()]) - return m68k_read_immediate_32(m68k, address); - else - return m68k_read_memory_32(m68k, address); -} - - -/* Special call to simulate undocumented 68k behavior when move.l with a - * predecrement destination mode is executed. - * A real 68k first writes the high word to [address+2], and then writes the - * low word to [address]. - */ -INLINE void m68kx_write_memory_32_pd(m68ki_cpu_core *m68k, unsigned int address, unsigned int value) -{ - (*m68k_memory_intf.write16)(address+2, value>>16); - (*m68k_memory_intf.write16)(address, value&0xffff); -} - - -void m68k_set_encrypted_opcode_range(int cpunum, offs_t start, offs_t end); +void m68k_set_encrypted_opcode_range(const device_config *device, offs_t start, offs_t end); /* ======================================================================== */ diff --git a/src/mame/drivers/cps2.c b/src/mame/drivers/cps2.c index 0e290212b40..c6d1f605939 100644 --- a/src/mame/drivers/cps2.c +++ b/src/mame/drivers/cps2.c @@ -808,28 +808,6 @@ static READ16_HANDLER( cps2_qsound_volume_r ) } -/************************************* - * - * ??? - * - *************************************/ - -static UINT8 cps2_read8(offs_t address) -{ - return m68k_read_pcrelative_8(NULL, address); -} - -static UINT16 cps2_read16(offs_t address) -{ - return m68k_read_pcrelative_16(NULL, address); -} - -static UINT32 cps2_read32(offs_t address) -{ - return m68k_read_pcrelative_32(NULL, address); -} - - /************************************* * * Read handlers @@ -1234,19 +1212,6 @@ static GFXDECODE_START( cps2 ) GFXDECODE_END -/************************************* - * - * M68K encryption interface - * - *************************************/ - -static const m68k_encryption_interface cps2_encryption = -{ - cps2_read8, cps2_read16, cps2_read32, - cps2_read16, cps2_read32 -}; - - /************************************* * * Machine driver @@ -1257,7 +1222,6 @@ static MACHINE_DRIVER_START( cps2 ) /* basic machine hardware */ MDRV_CPU_ADD("main", M68000, XTAL_16MHz) - MDRV_CPU_CONFIG(cps2_encryption) MDRV_CPU_PROGRAM_MAP(cps2_readmem,cps2_writemem) MDRV_CPU_VBLANK_INT_HACK(cps2_interrupt,259) // 262 /* ??? interrupts per frame */ diff --git a/src/mame/machine/cps2crpt.c b/src/mame/machine/cps2crpt.c index 3f097b45b64..35e61522e61 100644 --- a/src/mame/machine/cps2crpt.c +++ b/src/mame/machine/cps2crpt.c @@ -720,7 +720,7 @@ static void cps2_decrypt(running_machine *machine, const UINT32 *master_key, UIN } memory_set_decrypted_region(0, 0x000000, length - 1, dec); - m68k_set_encrypted_opcode_range(0,0,length); + m68k_set_encrypted_opcode_range(machine->cpu[0],0,length); } diff --git a/src/mame/machine/deco102.c b/src/mame/machine/deco102.c index e27883c55bf..f5de59b252a 100644 --- a/src/mame/machine/deco102.c +++ b/src/mame/machine/deco102.c @@ -58,7 +58,7 @@ void deco102_decrypt_cpu(running_machine *machine, const char *region, int addre memcpy(buf,rom,size); memory_set_decrypted_region(0, 0, size - 1, opcodes); - m68k_set_encrypted_opcode_range(0,0,size); + m68k_set_encrypted_opcode_range(machine->cpu[0],0,size); for (i = 0;i < size/2;i++) { diff --git a/src/mame/machine/s16fd.c b/src/mame/machine/s16fd.c index 42a909116d9..a23f7f98f42 100644 --- a/src/mame/machine/s16fd.c +++ b/src/mame/machine/s16fd.c @@ -78,7 +78,7 @@ static void fd1094_setstate_and_decrypt(int state) /* copy cached state */ fd1094_userregion=fd1094_cacheregion[i]; set_decrypted_region(); - m68k_set_encrypted_opcode_range(0,0,fd1094_cpuregionsize); + m68k_set_encrypted_opcode_range(Machine->cpu[0],0,fd1094_cpuregionsize); return; } @@ -97,7 +97,7 @@ static void fd1094_setstate_and_decrypt(int state) /* copy newly decrypted data to user region */ fd1094_userregion=fd1094_cacheregion[fd1094_current_cacheposition]; set_decrypted_region(); - m68k_set_encrypted_opcode_range(0,0,fd1094_cpuregionsize); + m68k_set_encrypted_opcode_range(Machine->cpu[0],0,fd1094_cpuregionsize); fd1094_current_cacheposition++; diff --git a/src/mame/machine/s24fd.c b/src/mame/machine/s24fd.c index 575dea15e9b..d17430f2f1b 100644 --- a/src/mame/machine/s24fd.c +++ b/src/mame/machine/s24fd.c @@ -58,7 +58,7 @@ static void s24_fd1094_setstate_and_decrypt(int state) /* copy cached state */ s24_fd1094_userregion=s24_fd1094_cacheregion[i]; memory_set_decrypted_region(1, 0, s24_fd1094_cpuregionsize - 1, s24_fd1094_userregion); - m68k_set_encrypted_opcode_range(1,0,s24_fd1094_cpuregionsize); + m68k_set_encrypted_opcode_range(Machine->cpu[1],0,s24_fd1094_cpuregionsize); return; } @@ -79,7 +79,7 @@ static void s24_fd1094_setstate_and_decrypt(int state) /* copy newly decrypted data to user region */ s24_fd1094_userregion=s24_fd1094_cacheregion[fd1094_current_cacheposition]; memory_set_decrypted_region(1, 0, s24_fd1094_cpuregionsize - 1, s24_fd1094_userregion); - m68k_set_encrypted_opcode_range(1,0,s24_fd1094_cpuregionsize); + m68k_set_encrypted_opcode_range(Machine->cpu[1],0,s24_fd1094_cpuregionsize); fd1094_current_cacheposition++;