1 #ifndef M68KMAME__HEADER
2 #define M68KMAME__HEADER
3 
4 /* ======================================================================== */
5 /* ============================== MAME STUFF ============================== */
6 /* ======================================================================== */
7 
8 #include "cpuintrf.h"
9 #include "memory.h"
10 #include "mamedbg.h"
11 #include "m68000.h"
12 
13 /* Configuration switches (see m68kconf.h for explanation) */
14 #define M68K_SEPARATE_READS         OPT_ON
15 
16 #define M68K_SIMULATE_PD_WRITES     OPT_ON
17 
18 #define M68K_EMULATE_INT_ACK        OPT_ON
19 #define M68K_INT_ACK_CALLBACK(A)
20 
21 #define M68K_EMULATE_BKPT_ACK       OPT_OFF
22 #define M68K_BKPT_ACK_CALLBACK()
23 
24 #define M68K_EMULATE_TRACE          OPT_OFF
25 
26 #define M68K_EMULATE_RESET          OPT_ON
27 #define M68K_RESET_CALLBACK()
28 
29 #define M68K_EMULATE_FC             OPT_OFF
30 #define M68K_SET_FC_CALLBACK(A)
31 
32 #define M68K_MONITOR_PC             OPT_SPECIFY_HANDLER
33 #define M68K_SET_PC_CALLBACK(A)     (*m68k_memory_intf.changepc)(A)
34 
35 #define M68K_INSTRUCTION_HOOK       OPT_SPECIFY_HANDLER
36 #define M68K_INSTRUCTION_CALLBACK() CALL_MAME_DEBUG
37 
38 #define M68K_EMULATE_PREFETCH       OPT_ON
39 
40 #define M68K_LOG_ENABLE             OPT_OFF
41 #define M68K_LOG_1010_1111          OPT_OFF
42 #define M68K_LOG_FILEHANDLE         errorlog
43 
44 #define M68K_EMULATE_ADDRESS_ERROR  OPT_OFF
45 
46 #define M68K_USE_64_BIT             OPT_OFF
47 
48 
49 #define m68ki_remaining_cycles m68k_ICount
50 
51 
52 extern struct m68k_memory_interface m68k_memory_intf;
53 
54 #define m68k_read_memory_8(address)          (*m68k_memory_intf.read8)(address)
55 #define m68k_read_memory_16(address)         (*m68k_memory_intf.read16)(address)
56 #define m68k_read_memory_32(address)         (*m68k_memory_intf.read32)(address)
57 
58 #define m68k_read_immediate_16(address)      m68kx_read_immediate_16(address)
59 #define m68k_read_immediate_32(address)      m68kx_read_immediate_32(address)
60 #define m68k_read_pcrelative_8(address)      m68kx_read_pcrelative_8(address)
61 #define m68k_read_pcrelative_16(address)     m68kx_read_pcrelative_16(address)
62 #define m68k_read_pcrelative_32(address)     m68kx_read_pcrelative_32(address)
63 
64 #define m68k_read_disassembler_16(address)   m68kx_read_immediate_16(address)
65 #define m68k_read_disassembler_32(address)   m68kx_read_immediate_32(address)
66 
67 #define m68k_write_memory_8(address, value)  (*m68k_memory_intf.write8)(address, value)
68 #define m68k_write_memory_16(address, value) (*m68k_memory_intf.write16)(address, value)
69 #define m68k_write_memory_32(address, value) (*m68k_memory_intf.write32)(address, value)
70 #define m68k_write_memory_32_pd(address, value) m68kx_write_memory_32_pd(address, value)
71 
72 
73 static INLINE unsigned int m68k_read_immediate_16(unsigned int address);
74 static INLINE unsigned int m68k_read_immediate_32(unsigned int address);
75 static INLINE unsigned int m68k_read_pcrelative_8(unsigned int address);
76 static INLINE unsigned int m68k_read_pcrelative_16(unsigned int address);
77 static INLINE unsigned int m68k_read_pcrelative_32(unsigned int address);
78 static INLINE void m68k_write_memory_32_pd(unsigned int address, unsigned int value);
79 
80 
m68kx_read_immediate_16(unsigned int address)81 static INLINE unsigned int m68kx_read_immediate_16(unsigned int address)
82 {
83 	return cpu_readop16((address) ^ m68k_memory_intf.opcode_xor);
84 }
85 
m68kx_read_immediate_32(unsigned int address)86 static INLINE unsigned int m68kx_read_immediate_32(unsigned int address)
87 {
88 	return ((m68k_read_immediate_16(address) << 16) | m68k_read_immediate_16((address)+2));
89 }
90 
m68kx_read_pcrelative_8(unsigned int address)91 static INLINE unsigned int m68kx_read_pcrelative_8(unsigned int address)
92 {
93 	if (address >= encrypted_opcode_start[cpu_getactivecpu()] &&
94 			address < encrypted_opcode_end[cpu_getactivecpu()])
95 		return ((m68k_read_immediate_16(address&~1)>>(8*(1-(address & 1))))&0xff);
96 	else
97 		return m68k_read_memory_8(address);
98 }
99 
m68kx_read_pcrelative_16(unsigned int address)100 static INLINE unsigned int m68kx_read_pcrelative_16(unsigned int address)
101 {
102 	if (address >= encrypted_opcode_start[cpu_getactivecpu()] &&
103 			address < encrypted_opcode_end[cpu_getactivecpu()])
104 		return m68k_read_immediate_16(address);
105 	else
106 		return m68k_read_memory_16(address);
107 }
108 
m68kx_read_pcrelative_32(unsigned int address)109 static INLINE unsigned int m68kx_read_pcrelative_32(unsigned int address)
110 {
111 	if (address >= encrypted_opcode_start[cpu_getactivecpu()] &&
112 			address < encrypted_opcode_end[cpu_getactivecpu()])
113 		return m68k_read_immediate_32(address);
114 	else
115 		return m68k_read_memory_32(address);
116 }
117 
118 
119 /* Special call to simulate undocumented 68k behavior when move.l with a
120  * predecrement destination mode is executed.
121  * A real 68k first writes the high word to [address+2], and then writes the
122  * low word to [address].
123  */
m68kx_write_memory_32_pd(unsigned int address,unsigned int value)124 static INLINE void m68kx_write_memory_32_pd(unsigned int address, unsigned int value)
125 {
126 	(*m68k_memory_intf.write16)(address+2, value>>16);
127 	(*m68k_memory_intf.write16)(address, value&0xffff);
128 }
129 
130 
131 #ifdef A68K0
132 #define M68K_EMULATE_010            OPT_OFF
133 #else
134 /* M68K Variants */
135 #if HAS_M68010
136 #define M68K_EMULATE_010            OPT_ON
137 #else
138 #define M68K_EMULATE_010            OPT_OFF
139 #endif
140 
141 #endif	/* A68K0 */
142 
143 #ifdef A68K2
144 #define M68K_EMULATE_EC020          OPT_OFF
145 #define M68K_EMULATE_020            OPT_OFF
146 #else
147 #undef  M68K_EMULATE_010
148 #define M68K_EMULATE_010            OPT_ON
149 
150 #if HAS_M68EC020
151 #define M68K_EMULATE_EC020          OPT_ON
152 #else
153 #define M68K_EMULATE_EC020          OPT_OFF
154 #endif
155 
156 #if HAS_M68020
157 #define M68K_EMULATE_020            OPT_ON
158 #else
159 #define M68K_EMULATE_020            OPT_OFF
160 #endif
161 
162 #endif /* A68K2 */
163 
164 /* ======================================================================== */
165 /* ============================== END OF FILE ============================= */
166 /* ======================================================================== */
167 
168 #endif /* M68KMAME__HEADER */
169