1 /******************************************************************************
\r
3 * CZ80 (Z80 CPU emulator) version 0.9
\r
4 * Compiled with Dev-C++
\r
5 * Copyright 2004-2005 Stéphane Dallongeville
\r
9 *****************************************************************************/
\r
18 /******************************/
\r
19 /* Compiler dependant defines */
\r
20 /******************************/
\r
23 #define UINT8 unsigned char
\r
31 #define UINT16 unsigned short
\r
39 #define UINT32 unsigned int
\r
46 /*************************************/
\r
47 /* Z80 core Structures & definitions */
\r
48 /*************************************/
\r
50 #define CZ80_FETCH_BITS 4 // [4-12] default = 8
\r
52 #define CZ80_FETCH_SFT (16 - CZ80_FETCH_BITS)
\r
53 #define CZ80_FETCH_BANK (1 << CZ80_FETCH_BITS)
\r
55 #define PICODRIVE_HACKS 1
\r
56 #define CZ80_LITTLE_ENDIAN 1
\r
57 #define CZ80_USE_JUMPTABLE 1
\r
58 #define CZ80_BIG_FLAGS_ARRAY 1
\r
59 //#ifdef BUILD_CPS1PSP
\r
60 //#define CZ80_ENCRYPTED_ROM 1
\r
62 #define CZ80_ENCRYPTED_ROM 0
\r
64 #define CZ80_EMULATE_R_EXACTLY 0
\r
66 #define zR8(A) (*CPU->pzR8[A])
\r
67 #define zR16(A) (CPU->pzR16[A]->W)
\r
69 #define pzAF &(CPU->AF)
\r
70 #define zAF CPU->AF.W
\r
71 #define zlAF CPU->AF.B.L
\r
72 #define zhAF CPU->AF.B.H
\r
76 #define pzBC &(CPU->BC)
\r
77 #define zBC CPU->BC.W
\r
78 #define zlBC CPU->BC.B.L
\r
79 #define zhBC CPU->BC.B.H
\r
83 #define pzDE &(CPU->DE)
\r
84 #define zDE CPU->DE.W
\r
85 #define zlDE CPU->DE.B.L
\r
86 #define zhDE CPU->DE.B.H
\r
90 #define pzHL &(CPU->HL)
\r
91 #define zHL CPU->HL.W
\r
92 #define zlHL CPU->HL.B.L
\r
93 #define zhHL CPU->HL.B.H
\r
97 #define zAF2 CPU->AF2.W
\r
98 #define zlAF2 CPU->AF2.B.L
\r
99 #define zhAF2 CPU->AF2.B.H
\r
103 #define zBC2 CPU->BC2.W
\r
104 #define zDE2 CPU->DE2.W
\r
105 #define zHL2 CPU->HL2.W
\r
107 #define pzIX &(CPU->IX)
\r
108 #define zIX CPU->IX.W
\r
109 #define zlIX CPU->IX.B.L
\r
110 #define zhIX CPU->IX.B.H
\r
112 #define pzIY &(CPU->IY)
\r
113 #define zIY CPU->IY.W
\r
114 #define zlIY CPU->IY.B.L
\r
115 #define zhIY CPU->IY.B.H
\r
117 #define pzSP &(CPU->SP)
\r
118 #define zSP CPU->SP.W
\r
119 #define zlSP CPU->SP.B.L
\r
120 #define zhSP CPU->SP.B.H
\r
122 #define zRealPC (PC - CPU->BasePC)
\r
126 #define zIM CPU->IM
\r
128 #define zwR CPU->R.W
\r
129 #define zR1 CPU->R.B.L
\r
130 #define zR2 CPU->R.B.H
\r
133 #define zIFF CPU->IFF.W
\r
134 #define zIFF1 CPU->IFF.B.L
\r
135 #define zIFF2 CPU->IFF.B.H
\r
137 #define CZ80_SF_SFT 7
\r
138 #define CZ80_ZF_SFT 6
\r
139 #define CZ80_YF_SFT 5
\r
140 #define CZ80_HF_SFT 4
\r
141 #define CZ80_XF_SFT 3
\r
142 #define CZ80_PF_SFT 2
\r
143 #define CZ80_VF_SFT 2
\r
144 #define CZ80_NF_SFT 1
\r
145 #define CZ80_CF_SFT 0
\r
147 #define CZ80_SF (1 << CZ80_SF_SFT)
\r
148 #define CZ80_ZF (1 << CZ80_ZF_SFT)
\r
149 #define CZ80_YF (1 << CZ80_YF_SFT)
\r
150 #define CZ80_HF (1 << CZ80_HF_SFT)
\r
151 #define CZ80_XF (1 << CZ80_XF_SFT)
\r
152 #define CZ80_PF (1 << CZ80_PF_SFT)
\r
153 #define CZ80_VF (1 << CZ80_VF_SFT)
\r
154 #define CZ80_NF (1 << CZ80_NF_SFT)
\r
155 #define CZ80_CF (1 << CZ80_CF_SFT)
\r
157 #define CZ80_IFF_SFT CZ80_PF_SFT
\r
158 #define CZ80_IFF CZ80_PF
\r
160 #ifndef IRQ_LINE_STATE
\r
161 #define IRQ_LINE_STATE
\r
162 #define CLEAR_LINE 0 /* clear (a fired, held or pulsed) line */
\r
163 #define ASSERT_LINE 1 /* assert an interrupt immediately */
\r
164 #define HOLD_LINE 2 /* hold interrupt line until acknowledged */
\r
165 #define PULSE_LINE 3 /* pulse interrupt line for one instruction */
\r
166 #define IRQ_LINE_NMI 127 /* IRQ line for NMIs */
\r
196 #if CZ80_LITTLE_ENDIAN
\r
207 typedef struct cz80_t
\r
246 UINT32 Fetch[CZ80_FETCH_BANK];
\r
247 #if CZ80_ENCRYPTED_ROM
\r
249 INT32 OPFetch[CZ80_FETCH_BANK];
\r
255 UINT8 (*Read_Byte)(UINT32 address);
\r
256 void (*Write_Byte)(UINT32 address, UINT8 data);
\r
258 UINT8 (*IN_Port)(UINT16 port);
\r
259 void (*OUT_Port)(UINT16 port, UINT8 value);
\r
261 INT32 (*Interrupt_Callback)(INT32 irqline);
\r
266 /*************************/
\r
267 /* Publics Z80 variables */
\r
268 /*************************/
\r
270 extern cz80_struc CZ80;
\r
272 /*************************/
\r
273 /* Publics Z80 functions */
\r
274 /*************************/
\r
276 void Cz80_Init(cz80_struc *CPU);
\r
278 void Cz80_Reset(cz80_struc *CPU);
\r
280 INT32 Cz80_Exec(cz80_struc *CPU, INT32 cycles);
\r
282 void Cz80_Set_IRQ(cz80_struc *CPU, INT32 line, INT32 state);
\r
284 UINT32 Cz80_Get_Reg(cz80_struc *CPU, INT32 regnum);
\r
285 void Cz80_Set_Reg(cz80_struc *CPU, INT32 regnum, UINT32 value);
\r
287 void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 fetch_adr);
\r
288 #if CZ80_ENCRYPTED_ROM
\r
289 void Cz80_Set_Encrypt_Range(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 decrypted_rom);
\r
292 void Cz80_Set_ReadB(cz80_struc *CPU, UINT8 (*Func)(UINT32 address));
\r
293 void Cz80_Set_WriteB(cz80_struc *CPU, void (*Func)(UINT32 address, UINT8 data));
\r
295 void Cz80_Set_INPort(cz80_struc *CPU, UINT8 (*Func)(UINT16 port));
\r
296 void Cz80_Set_OUTPort(cz80_struc *CPU, void (*Func)(UINT16 port, UINT8 value));
\r
298 void Cz80_Set_IRQ_Callback(cz80_struc *CPU, INT32 (*Func)(INT32 irqline));
\r
304 #endif /* CZ80_H */
\r