-
Notifications
You must be signed in to change notification settings - Fork 6
/
Z80.h
154 lines (135 loc) · 6.73 KB
/
Z80.h
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
/*** Z80Em: Portable Z80 emulator *******************************************/
/*** ***/
/*** Z80.h ***/
/*** ***/
/*** This file contains the function prototypes and variable declarations ***/
/*** ***/
/*** Copyright (C) Marcel de Kogel 1996,1997 ***/
/*** You are not allowed to distribute this software commercially ***/
/*** Please, notify me, if you make any changes to this file ***/
/****************************************************************************/
#ifndef _Z80_H
#define _Z80_H
#include "arduino.h"
/****************************************************************************/
/*** Machine dependent definitions ***/
/****************************************************************************/
//#define DEBUG /* Compile debugging version */
/* #define X86_ASM */ /* Compile optimised GCC/x86 version */
#define LSB_FIRST /* Compile for low-endian CPU */
/* #define __64BIT__ */ /* Compile for 64 bit machines */
/* #define __128BIT__ */ /* Compile for 128 bit machines */
#ifdef DEBUG // enable TRACE with DEBUG
#define TRACE
#endif
/****************************************************************************/
/* If your compiler doesn't know about inlined functions, uncomment this */
/****************************************************************************/
/* #define INLINE static */
#ifndef EMU_TYPES
#define EMU_TYPES
/****************************************************************************/
/* sizeof(byte)=1, sizeof(word)=2, sizeof(dword)>=4 */
/****************************************************************************/
//typedef unsigned char byte;
//typedef unsigned short word;
typedef unsigned long dword;
typedef signed char offset;
/****************************************************************************/
/* Define a Z80 word. Upper bytes are always zero */
/****************************************************************************/
typedef union
{
#ifdef __128BIT__
#ifdef LSB_FIRST
struct { byte l,h,h2,h3,h4,h5,h6,h7,
h8,h9,h10,h11,h12,h13,h14,h15; } B;
struct { word l,h,h2,h3,h4,h5,h6,h7; } W;
dword D;
#else
struct { byte h15,h14,h13,h12,h11,h10,h9,h8,
h7,h6,h5,h4,h3,h2,h,l; } B;
struct { word h7,h6,h5,h4,h3,h2,h,l; } W;
dword D;
#endif
#elif __64BIT__
#ifdef LSB_FIRST
struct { byte l,h,h2,h3,h4,h5,h6,h7; } B;
struct { word l,h,h2,h3; } W;
dword D;
#else
struct { byte h7,h6,h5,h4,h3,h2,h,l; } B;
struct { word h3,h2,h,l; } W;
dword D;
#endif
#else
#ifdef LSB_FIRST
struct { byte l,h,h2,h3; } B;
struct { word l,h; } W;
dword D;
#else
struct { byte h3,h2,h,l; } B;
struct { word h,l; } W;
dword D;
#endif
#endif
} pair;
#endif /* EMU_TYPES */
/****************************************************************************/
/*** End of machine dependent definitions ***/
/****************************************************************************/
#ifndef INLINE
#define INLINE static inline
#endif
/****************************************************************************/
/* The Z80 registers. HALT is set to 1 when the CPU is halted, the refresh */
/* register is calculated as follows: refresh=(Regs.R&127)|(Regs.R2&128) */
/****************************************************************************/
typedef struct
{
pair AF,BC,DE,HL,IX,IY,PC,SP;
pair AF2,BC2,DE2,HL2;
unsigned IFF1,IFF2,HALT,IM,I,R,R2;
} Z80_Regs;
/****************************************************************************/
/* Set Z80_Trace to 1 when PC==Z80_Trap. When trace is on, Z80_Debug() is */
/* called after every instruction */
/****************************************************************************/
#ifdef DEBUG
extern int Z80_Trace;
extern int Z80_Trap;
void Z80_Debug(Z80_Regs *R);
#endif
extern int Z80_Running; /* When 0, emulation terminates */
extern int Z80_IPeriod; /* Number of T-states per interrupt */
extern int Z80_ICount; /* T-state count */
extern int Z80_IRQ; /* Current IRQ status. Checked after EI occurs */
#define Z80_IGNORE_INT -1 /* Ignore interrupt */
#define Z80_NMI_INT -2 /* Execute NMI */
unsigned Z80_GetPC (void); /* Get program counter */
void Z80_GetRegs (Z80_Regs *Regs); /* Get registers */
void Z80_SetRegs (Z80_Regs *Regs); /* Set registers */
void Z80_Reset (void); /* Reset registers to the initial values */
int Z80_Execute (void); /* Execute IPeriod T-States */
word Z80 (void); /* Execute until Z80_Running==0 */
void Z80_RegisterDump (void); /* Prints a dump to stdout */
void Z80_SetWaitStates (int n); /* Set number of memory wait states. */
/* This only affects opcode fetching, so */
/* wait state adjustment is still */
/* necessary in Z80_RDMEM, Z80_RDOP_ARG, */
/* Z80_RDSTACK and Z80_WRSTACK */
void Z80_Patch (Z80_Regs *Regs); /* Called when ED FE occurs. Can be used */
/* to emulate disk access etc. */
int Z80_Interrupt(void); /* This is called after IPeriod T-States */
/* have been executed. It should return */
/* Z80_IGNORE_INT, Z80_NMI_INT or a byte */
/* identifying the device (most often */
/* 0xFF) */
void Z80_Reti (void); /* Called when RETI occurs */
void Z80_Retn (void); /* Called when RETN occurs */
/****************************************************************************/
/* Definitions of functions to read/write memory and I/O ports */
/* You can replace these with your own, inlined if necessary */
/****************************************************************************/
#include "Z80IO.h"
#endif /* _Z80_H */