Import Upstream version 1.23
[debian-dgen.git] / mz80.h
blob22b57559fd446975e418ba65c3e9ebe573d9f83f
1 /* Multi-Z80 32 Bit emulator */
3 /* Copyright 1996, Neil Bradley, All rights reserved
5 * License agreement:
7 * The mZ80 emulator may be distributed in unmodified form to any medium.
9 * mZ80 May not be sold, or sold as a part of a commercial package without
10 * the express written permission of Neil Bradley (neil@synthcom.com). This
11 * includes shareware.
13 * Modified versions of mZ80 may not be publicly redistributed without author
14 * approval (neil@synthcom.com). This includes distributing via a publicly
15 * accessible LAN. You may make your own source modifications and distribute
16 * mZ80 in object only form.
18 * mZ80 Licensing for commercial applications is available. Please email
19 * neil@synthcom.com for details.
21 * Synthcom Systems, Inc, and Neil Bradley will not be held responsible for
22 * any damage done by the use of mZ80. It is purely "as-is".
24 * If you use mZ80 in a freeware application, credit in the following text:
26 * "Multi-Z80 CPU emulator by Neil Bradley (neil@synthcom.com)"
28 * must accompany the freeware application within the application itself or
29 * in the documentation.
31 * Legal stuff aside:
33 * If you find problems with mZ80, please email the author so they can get
34 * resolved. If you find a bug and fix it, please also email the author so
35 * that those bug fixes can be propogated to the installed base of mZ80
36 * users. If you find performance improvements or problems with mZ80, please
37 * email the author with your changes/suggestions and they will be rolled in
38 * with subsequent releases of mZ80.
40 * The whole idea of this emulator is to have the fastest available 32 bit
41 * Multi-z80 emulator for the PC, giving maximum performance.
42 */
44 /* General z80 based defines */
46 #ifndef _MZ80_H_
47 #define _MZ80_H_
49 #ifndef UINT32
50 #define UINT32 unsigned long int
51 #endif
53 #ifndef UINT16
54 #define UINT16 unsigned short int
55 #endif
57 #ifndef UINT8
58 #define UINT8 unsigned char
59 #endif
61 #ifndef INT32
62 #define INT32 signed long int
63 #endif
65 #ifndef INT16
66 #define INT16 signed short int
67 #endif
69 #ifndef INT8
70 #define INT8 signed char
71 #endif
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
77 #ifndef _MEMORYREADWRITEBYTE_
78 #define _MEMORYREADWRITEBYTE_
80 struct MemoryWriteByte
82 UINT32 lowAddr;
83 UINT32 highAddr;
84 void (*memoryCall)(UINT32, UINT8, struct MemoryWriteByte *);
85 void *pUserArea;
86 };
88 struct MemoryReadByte
90 UINT32 lowAddr;
91 UINT32 highAddr;
92 UINT8 (*memoryCall)(UINT32, struct MemoryReadByte *);
93 void *pUserArea;
94 };
96 #endif // _MEMORYREADWRITEBYTE_
98 struct z80PortWrite
100 UINT16 lowIoAddr;
101 UINT16 highIoAddr;
102 void (*IOCall)(UINT16, UINT8, struct z80PortWrite *);
103 void *pUserArea;
106 struct z80PortRead
108 UINT16 lowIoAddr;
109 UINT16 highIoAddr;
110 UINT16 (*IOCall)(UINT16, struct z80PortRead *);
111 void *pUserArea;
114 struct z80TrapRec
116 UINT16 trapAddr;
117 UINT8 skipCnt;
118 UINT8 origIns;
121 typedef union
123 UINT32 af;
125 struct
127 #ifdef WORDS_BIGENDIAN
128 UINT16 wFiller;
129 UINT8 a;
130 UINT8 f;
131 #else
132 UINT8 f;
133 UINT8 a;
134 UINT16 wFiller;
135 #endif
136 } half;
137 } reg_af;
139 #define z80AF z80af.af
140 #define z80A z80af.half.a
141 #define z80F z80af.half.f
143 typedef union
145 UINT32 bc;
147 struct
149 #ifdef WORDS_BIGENDIAN
150 UINT16 wFiller;
151 UINT8 b;
152 UINT8 c;
153 #else
154 UINT8 c;
155 UINT8 b;
156 UINT16 wFiller;
157 #endif
158 } half;
159 } reg_bc;
161 #define z80BC z80bc.bc
162 #define z80B z80bc.half.b
163 #define z80C z80bc.half.c
165 typedef union
167 UINT32 de;
169 struct
171 #ifdef WORDS_BIGENDIAN
172 UINT16 wFiller;
173 UINT8 d;
174 UINT8 e;
175 #else
176 UINT8 e;
177 UINT8 d;
178 UINT16 wFiller;
179 #endif
180 } half;
181 } reg_de;
183 #define z80DE z80de.de
184 #define z80D z80de.half.d
185 #define z80E z80de.half.e
187 typedef union
189 UINT32 hl;
191 struct
193 #ifdef WORDS_BIGENDIAN
194 UINT16 wFiller;
195 UINT8 h;
196 UINT8 l;
197 #else
198 UINT8 l;
199 UINT8 h;
200 UINT16 wFiller;
201 #endif
202 } half;
203 } reg_hl;
205 #define z80HL z80hl.hl
206 #define z80H z80hl.half.h
207 #define z80L z80hl.half.l
209 #define z80SP z80sp.sp
211 typedef union
213 UINT32 ix;
215 struct
217 #ifdef WORDS_BIGENDIAN
218 UINT16 wFiller;
219 UINT8 xh;
220 UINT8 xl;
221 #else
222 UINT8 xl;
223 UINT8 xh;
224 UINT16 wFiller;
225 #endif
226 } half;
227 } reg_ix;
229 #define z80IX z80ix.ix
230 #define z80XH z80ix.half.xh
231 #define z80XL z80ix.half.xl
233 typedef union
235 UINT32 iy;
237 struct
239 #ifdef WORDS_BIGENDIAN
240 UINT16 wFiller;
241 UINT8 yh;
242 UINT8 yl;
243 #else
244 UINT8 yl;
245 UINT8 yh;
246 UINT16 wFiller;
247 #endif
248 } half;
249 } reg_iy;
251 #define z80IY z80iy.iy
252 #define z80YH z80iy.half.yh
253 #define z80YL z80iy.half.yl
255 struct mz80context
257 UINT8 *z80Base;
258 struct MemoryReadByte *z80MemRead;
259 struct MemoryWriteByte *z80MemWrite;
260 struct z80PortRead *z80IoRead;
261 struct z80PortWrite *z80IoWrite;
262 UINT32 z80clockticks;
263 UINT32 z80iff;
264 UINT32 z80interruptMode;
265 UINT32 z80halted;
267 reg_af z80af;
268 reg_bc z80bc;
269 reg_de z80de;
270 reg_hl z80hl;
271 UINT32 z80afprime;
272 UINT32 z80bcprime;
273 UINT32 z80deprime;
274 UINT32 z80hlprime;
275 reg_ix z80ix;
276 reg_iy z80iy;
277 UINT32 z80sp;
278 UINT32 z80pc;
279 UINT32 z80nmiAddr;
280 UINT32 z80intAddr;
281 UINT32 z80rCounter;
282 UINT8 z80i;
283 UINT8 z80r;
284 UINT8 z80intPending;
287 // These are the enumerations used for register access. DO NOT ALTER THEIR
288 // ORDER! It must match the same order as in the mz80.c/mz80.asm files!
290 enum
292 #ifndef CPUREG_PC
293 CPUREG_PC = 0,
294 #endif
295 CPUREG_Z80_AF = 1,
296 CPUREG_Z80_BC,
297 CPUREG_Z80_DE,
298 CPUREG_Z80_HL,
299 CPUREG_Z80_AFPRIME,
300 CPUREG_Z80_BCPRIME,
301 CPUREG_Z80_DEPRIME,
302 CPUREG_Z80_HLPRIME,
303 CPUREG_Z80_IX,
304 CPUREG_Z80_IY,
305 CPUREG_Z80_SP,
306 CPUREG_Z80_I,
307 CPUREG_Z80_R,
308 CPUREG_Z80_A,
309 CPUREG_Z80_B,
310 CPUREG_Z80_C,
311 CPUREG_Z80_D,
312 CPUREG_Z80_E,
313 CPUREG_Z80_H,
314 CPUREG_Z80_L,
315 CPUREG_Z80_F,
316 CPUREG_Z80_CARRY,
317 CPUREG_Z80_NEGATIVE,
318 CPUREG_Z80_PARITY,
319 CPUREG_Z80_OVERFLOW,
320 CPUREG_Z80_HALFCARRY,
321 CPUREG_Z80_ZERO,
322 CPUREG_Z80_SIGN,
323 CPUREG_Z80_IFF1,
324 CPUREG_Z80_IFF2,
326 // Leave this here!
328 CPUREG_Z80_MAX_INDEX
331 extern UINT32 mz80exec(UINT32);
332 extern UINT32 mz80GetContextSize(void);
333 extern UINT32 mz80GetElapsedTicks(UINT32);
334 extern void mz80ReleaseTimeslice(void);
335 extern void mz80GetContext(void *);
336 extern void mz80SetContext(void *);
337 extern void mz80reset(void);
338 extern void mz80ClearPendingInterrupt(void);
339 extern UINT32 mz80int(UINT32);
340 extern UINT32 mz80nmi(void);
341 extern void mz80init(void);
342 extern UINT32 z80intAddr;
343 extern UINT32 z80nmiAddr;
345 // Debugger useful routines
347 extern UINT8 mz80SetRegisterValue(void *, UINT32, UINT32);
348 extern UINT32 mz80GetRegisterValue(void *, UINT32);
349 extern UINT32 mz80GetRegisterTextValue(void *, UINT32, UINT8 *);
350 extern UINT8 *mz80GetRegisterName(UINT32);
352 // Memory/IO read/write commands
354 #ifndef VALUE_BYTE
355 #define VALUE_BYTE 0
356 #endif
358 #ifndef VALUE_WORD
359 #define VALUE_WORD 1
360 #endif
362 #ifndef VALUE_DWORD
363 #define VALUE_DWORD 2
364 #endif
366 #ifndef VALUE_IO
367 #define VALUE_IO 3
368 #endif
370 extern void mz80WriteValue(UINT8 bWhat, UINT32 dwAddr, UINT32 dwData);
371 extern UINT32 mz80ReadValue(UINT8 bWhat, UINT32 dwAddr);
373 // Flag definitions
375 #define Z80_FLAG_CARRY 0x01
376 #define Z80_FLAG_NEGATIVE 0x02
377 #define Z80_FLAG_OVERFLOW_PARITY 0x04
378 #define Z80_FLAG_UNDEFINED1 0x08
379 #define Z80_FLAG_HALF_CARRY 0x10
380 #define Z80_FLAG_UNDEFINED2 0x20
381 #define Z80_FLAG_ZERO 0x40
382 #define Z80_FLAG_SIGN 0x80
384 #define IFF1 0x01
385 #define IFF2 0x02
387 typedef struct mz80context CONTEXTMZ80;
389 #ifdef __cplusplus
391 #endif
393 #endif // _MZ80_H_