File: mz80.h

package info (click to toggle)
dgen 1.23-9
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 2,168 kB
  • ctags: 3,087
  • sloc: ansic: 45,403; cpp: 4,405; sh: 1,960; makefile: 116
file content (393 lines) | stat: -rw-r--r-- 7,642 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/* Multi-Z80 32 Bit emulator */

/* Copyright 1996, Neil Bradley, All rights reserved
 *
 * License agreement:
 *
 * The mZ80 emulator may be distributed in unmodified form to any medium.
 *
 * mZ80 May not be sold, or sold as a part of a commercial package without
 * the express written permission of Neil Bradley (neil@synthcom.com). This
 * includes shareware.
 *
 * Modified versions of mZ80 may not be publicly redistributed without author
 * approval (neil@synthcom.com). This includes distributing via a publicly
 * accessible LAN. You may make your own source modifications and distribute
 * mZ80 in object only form.
 *
 * mZ80 Licensing for commercial applications is available. Please email
 * neil@synthcom.com for details.
 *
 * Synthcom Systems, Inc, and Neil Bradley will not be held responsible for
 * any damage done by the use of mZ80. It is purely "as-is".
 *
 * If you use mZ80 in a freeware application, credit in the following text:
 *
 * "Multi-Z80 CPU emulator by Neil Bradley (neil@synthcom.com)"
 *
 * must accompany the freeware application within the application itself or
 * in the documentation.
 *
 * Legal stuff aside:
 *
 * If you find problems with mZ80, please email the author so they can get
 * resolved. If you find a bug and fix it, please also email the author so
 * that those bug fixes can be propogated to the installed base of mZ80
 * users. If you find performance improvements or problems with mZ80, please
 * email the author with your changes/suggestions and they will be rolled in
 * with subsequent releases of mZ80.
 *
 * The whole idea of this emulator is to have the fastest available 32 bit
 * Multi-z80 emulator for the PC, giving maximum performance. 
 */ 

/* General z80 based defines */

#ifndef	_MZ80_H_
#define	_MZ80_H_

#ifndef UINT32
#define UINT32  unsigned long int
#endif

#ifndef UINT16
#define UINT16  unsigned short int
#endif

#ifndef UINT8
#define UINT8   unsigned char
#endif

#ifndef INT32
#define INT32  signed long int
#endif

#ifndef INT16
#define INT16  signed short int
#endif

#ifndef INT8
#define INT8   signed char
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifndef _MEMORYREADWRITEBYTE_
#define _MEMORYREADWRITEBYTE_

struct MemoryWriteByte
{
	UINT32 lowAddr;
	UINT32 highAddr;
	void (*memoryCall)(UINT32, UINT8, struct MemoryWriteByte *);
	void *pUserArea;
};      

struct MemoryReadByte
{
	UINT32 lowAddr;
	UINT32 highAddr;
	UINT8 (*memoryCall)(UINT32, struct MemoryReadByte *);
	void *pUserArea;
};      

#endif // _MEMORYREADWRITEBYTE_

struct z80PortWrite
{
	UINT16 lowIoAddr;
	UINT16 highIoAddr;
	void (*IOCall)(UINT16, UINT8, struct z80PortWrite *);
	void *pUserArea;
};

struct z80PortRead
{
	UINT16 lowIoAddr;
	UINT16 highIoAddr;
	UINT16 (*IOCall)(UINT16, struct z80PortRead *);
	void *pUserArea;
};	

struct z80TrapRec
{
  	UINT16 trapAddr;
	UINT8  skipCnt;
	UINT8  origIns;
};

typedef union
{
	UINT32 af;

	struct
	{
#ifdef WORDS_BIGENDIAN
		UINT16 wFiller;
		UINT8 a;
		UINT8 f;
#else
		UINT8 f;
		UINT8 a;
		UINT16 wFiller;
#endif
	} half;
} reg_af;

#define	z80AF	z80af.af
#define	z80A	z80af.half.a
#define	z80F	z80af.half.f

typedef union
{
	UINT32 bc;

	struct
	{
#ifdef WORDS_BIGENDIAN
		UINT16 wFiller;
		UINT8 b;
		UINT8 c;
#else
		UINT8 c;
		UINT8 b;
		UINT16 wFiller;
#endif
	} half;
} reg_bc;

#define	z80BC	z80bc.bc
#define	z80B	z80bc.half.b
#define	z80C	z80bc.half.c

typedef union
{
	UINT32 de;

	struct
	{
#ifdef WORDS_BIGENDIAN
		UINT16 wFiller;
		UINT8 d;
		UINT8 e;
#else
		UINT8 e;
		UINT8 d;
		UINT16 wFiller;
#endif
	} half;
} reg_de;

#define	z80DE	z80de.de
#define	z80D	z80de.half.d
#define	z80E	z80de.half.e

typedef union
{
	UINT32 hl;

	struct
	{
#ifdef WORDS_BIGENDIAN
		UINT16 wFiller;
		UINT8 h;
		UINT8 l;
#else
		UINT8 l;
		UINT8 h;
		UINT16 wFiller;
#endif
	} half;
} reg_hl;

#define	z80HL	z80hl.hl
#define	z80H	z80hl.half.h
#define	z80L	z80hl.half.l

#define	z80SP	z80sp.sp

typedef union
{
	UINT32 ix;

	struct
	{
#ifdef WORDS_BIGENDIAN
		UINT16 wFiller;
		UINT8 xh;
		UINT8 xl;
#else
		UINT8 xl;
		UINT8 xh;
		UINT16 wFiller;
#endif
	} half;
} reg_ix;

#define	z80IX	z80ix.ix
#define	z80XH	z80ix.half.xh
#define	z80XL	z80ix.half.xl

typedef union
{
	UINT32 iy;

	struct
	{
#ifdef WORDS_BIGENDIAN
		UINT16 wFiller;
		UINT8 yh;
		UINT8 yl;
#else
		UINT8 yl;
		UINT8 yh;
		UINT16 wFiller;
#endif
	} half;
} reg_iy;

#define	z80IY	z80iy.iy
#define	z80YH	z80iy.half.yh
#define	z80YL	z80iy.half.yl

struct mz80context
{
	UINT8 *z80Base;
	struct MemoryReadByte *z80MemRead;
	struct MemoryWriteByte *z80MemWrite;
	struct z80PortRead *z80IoRead;
	struct z80PortWrite *z80IoWrite;
	UINT32 z80clockticks;
	UINT32 z80iff;
	UINT32 z80interruptMode;
	UINT32 z80halted;

	reg_af z80af;
	reg_bc z80bc;
	reg_de z80de;
	reg_hl z80hl;
	UINT32 z80afprime;
	UINT32 z80bcprime;
	UINT32 z80deprime;
	UINT32 z80hlprime;
	reg_ix z80ix;
	reg_iy z80iy;
	UINT32 z80sp;
	UINT32 z80pc;
	UINT32 z80nmiAddr;
	UINT32 z80intAddr;
	UINT32 z80rCounter;
	UINT8 z80i;
	UINT8 z80r;
	UINT8 z80intPending;
}; 

// These are the enumerations used for register access. DO NOT ALTER THEIR
// ORDER! It must match the same order as in the mz80.c/mz80.asm files!

enum
{
#ifndef CPUREG_PC
	CPUREG_PC = 0,
#endif
	CPUREG_Z80_AF = 1,
	CPUREG_Z80_BC,
	CPUREG_Z80_DE,
	CPUREG_Z80_HL,
	CPUREG_Z80_AFPRIME,
	CPUREG_Z80_BCPRIME,
	CPUREG_Z80_DEPRIME,
	CPUREG_Z80_HLPRIME,
	CPUREG_Z80_IX,
	CPUREG_Z80_IY,
	CPUREG_Z80_SP,
	CPUREG_Z80_I,
	CPUREG_Z80_R,
	CPUREG_Z80_A,
	CPUREG_Z80_B,
	CPUREG_Z80_C,
	CPUREG_Z80_D,
	CPUREG_Z80_E,
	CPUREG_Z80_H,
	CPUREG_Z80_L,
	CPUREG_Z80_F,
	CPUREG_Z80_CARRY,
	CPUREG_Z80_NEGATIVE,
	CPUREG_Z80_PARITY,
	CPUREG_Z80_OVERFLOW,
	CPUREG_Z80_HALFCARRY,
	CPUREG_Z80_ZERO,
	CPUREG_Z80_SIGN,
	CPUREG_Z80_IFF1,
	CPUREG_Z80_IFF2,

	// Leave this here!

	CPUREG_Z80_MAX_INDEX
};

extern UINT32 mz80exec(UINT32);
extern UINT32 mz80GetContextSize(void);
extern UINT32 mz80GetElapsedTicks(UINT32);
extern void mz80ReleaseTimeslice(void);
extern void mz80GetContext(void *);
extern void mz80SetContext(void *);
extern void mz80reset(void);
extern void mz80ClearPendingInterrupt(void);
extern UINT32 mz80int(UINT32);
extern UINT32 mz80nmi(void);
extern void mz80init(void);
extern UINT32 z80intAddr;
extern UINT32 z80nmiAddr;

// Debugger useful routines

extern UINT8 mz80SetRegisterValue(void *, UINT32, UINT32);
extern UINT32 mz80GetRegisterValue(void *, UINT32);
extern UINT32 mz80GetRegisterTextValue(void *, UINT32, UINT8 *);
extern UINT8 *mz80GetRegisterName(UINT32);

// Memory/IO read/write commands

#ifndef VALUE_BYTE
#define	VALUE_BYTE	0
#endif

#ifndef VALUE_WORD
#define	VALUE_WORD	1
#endif

#ifndef VALUE_DWORD
#define	VALUE_DWORD	2
#endif

#ifndef VALUE_IO
#define	VALUE_IO	3
#endif

extern void mz80WriteValue(UINT8 bWhat, UINT32 dwAddr, UINT32 dwData);
extern UINT32 mz80ReadValue(UINT8 bWhat, UINT32 dwAddr);

// Flag definitions

#define	Z80_FLAG_CARRY					0x01
#define	Z80_FLAG_NEGATIVE				0x02
#define	Z80_FLAG_OVERFLOW_PARITY	0x04
#define	Z80_FLAG_UNDEFINED1			0x08
#define	Z80_FLAG_HALF_CARRY			0x10
#define	Z80_FLAG_UNDEFINED2			0x20
#define	Z80_FLAG_ZERO					0x40
#define	Z80_FLAG_SIGN					0x80

#define	IFF1			0x01
#define	IFF2			0x02

typedef struct mz80context CONTEXTMZ80;

#ifdef __cplusplus
};
#endif

#endif	// _MZ80_H_