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