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