Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
z80ex.h
Go to the documentation of this file.
1 /*
2  * Z80Ex, ZILoG Z80 CPU emulator.
3  *
4  * by Pigmaker57 aka boo_boo [pigmaker57@kahoh57.info]
5  * modified by Gabor Lenart LGB [lgblgblgb@gmail.com] for Xep128
6  *
7  * contains some code from the FUSE project (http://fuse-emulator.sourceforge.net)
8  * Released under GNU GPL v2
9  *
10  */
11 
12 #ifndef _Z80EX_H_INCLUDED
13 #define _Z80EX_H_INCLUDED
14 
15 #ifdef Z80EX_USER_HEADER
16 #include Z80EX_USER_HEADER
17 #endif
18 
19 #ifdef Z80EX_TSTATE_CALLBACK_ALWAYS
20 # define IS_TSTATE_CB 1
21 # define Z80EX_TSTATE_CALLBACK
22 #else
23 # define IS_TSTATE_CB z80ex.tstate_cb
24 # ifdef Z80EX_TSTATE_CALLBACK
25 # define Z80EX_HAVE_TSTATE_CB_VAR
26 # endif
27 #endif
28 
29 #ifndef Z80EX_TYPES_DEFINED
30 #define Z80EX_TYPES_DEFINED
31 #warning "User did not define Z80EX types ..."
32 #if defined(__SYMBIAN32__)
33 typedef unsigned char Z80EX_BYTE;
34 typedef signed char Z80EX_SIGNED_BYTE;
35 typedef unsigned short Z80EX_WORD;
36 typedef unsigned int Z80EX_DWORD;
37 #elif defined(__GNUC__)
38 #include <stdint.h>
39 typedef uint8_t Z80EX_BYTE;
40 typedef int8_t Z80EX_SIGNED_BYTE;
41 typedef uint16_t Z80EX_WORD;
42 typedef uint32_t Z80EX_DWORD;
43 #elif defined(_MSC_VER)
44 typedef unsigned __int8 Z80EX_BYTE;
45 typedef signed __int8 Z80EX_SIGNED_BYTE;
46 typedef unsigned __int16 Z80EX_WORD;
47 typedef unsigned __int32 Z80EX_DWORD;
48 #else
49 typedef unsigned char Z80EX_BYTE;
50 typedef signed char Z80EX_SIGNED_BYTE;
51 typedef unsigned short Z80EX_WORD;
52 typedef unsigned int Z80EX_DWORD;
53 #endif
54 #endif
55 
56 /* Union allowing a register pair to be accessed as bytes or as a word */
57 typedef union {
58 #ifdef Z80EX_WORDS_BIG_ENDIAN
59  struct { Z80EX_BYTE h,l; } b;
60 #warning "Z80Ex big endian support is not tested with the modified Z80Ex by me!"
61 #else
62  struct { Z80EX_BYTE l,h; } b;
63 #endif
66 
67 typedef enum { IM0 = 0, IM1 = 1, IM2 = 2 } IM_MODE;
68 
69 /* Macros used for accessing the registers
70  This is the "external" set for the application.
71  Internally, z80ex uses its own ones from macros.h
72  but it would collide with some other stuff because
73  of being too generic names ... */
74 
75 #define Z80_A z80ex.af.b.h
76 #define Z80_F z80ex.af.b.l
77 #define Z80_AF z80ex.af.w
78 
79 #define Z80_B z80ex.bc.b.h
80 #define Z80_C z80ex.bc.b.l
81 #define Z80_BC z80ex.bc.w
82 
83 #define Z80_D z80ex.de.b.h
84 #define Z80_E z80ex.de.b.l
85 #define Z80_DE z80ex.de.w
86 
87 #define Z80_H z80ex.hl.b.h
88 #define Z80_L z80ex.hl.b.l
89 #define Z80_HL z80ex.hl.w
90 
91 #define Z80_A_ z80ex.af_.b.h
92 #define Z80_F_ z80ex.af_.b.l
93 #define Z80_AF_ z80ex.af_.w
94 
95 #define Z80_B_ z80ex.bc_.b.h
96 #define Z80_C_ z80ex.bc_.b.l
97 #define Z80_BC_ z80ex.bc_.w
98 
99 #define Z80_D_ z80ex.de_.b.h
100 #define Z80_E_ z80ex.de_.b.l
101 #define Z80_DE_ z80ex.de_.w
102 
103 #define Z80_H_ z80ex.hl_.b.h
104 #define Z80_L_ z80ex.hl_.b.l
105 #define Z80_HL_ z80ex.hl_.w
106 
107 #define Z80_IXH z80ex.ix.b.h
108 #define Z80_IXL z80ex.ix.b.l
109 #define Z80_IX z80ex.ix.w
110 
111 #define Z80_IYH z80ex.iy.b.h
112 #define Z80_IYL z80ex.iy.b.l
113 #define Z80_IY z80ex.iy.w
114 
115 #define Z80_SPH z80ex.sp.b.h
116 #define Z80_SPL z80ex.sp.b.l
117 #define Z80_SP z80ex.sp.w
118 
119 #define Z80_PCH z80ex.pc.b.h
120 #define Z80_PCL z80ex.pc.b.l
121 #define Z80_PC z80ex.pc.w
122 
123 #define Z80_I z80ex.i
124 #define Z80_R z80ex.r
125 #define Z80_R7 z80ex.r7
126 
127 #define Z80_IFF1 z80ex.iff1
128 #define Z80_IFF2 z80ex.iff2
129 #define Z80_IM z80ex.im
130 
131 /* The flags */
132 
133 #define Z80_FLAG_C 0x01
134 #define Z80_FLAG_N 0x02
135 #define Z80_FLAG_P 0x04
136 #define Z80_FLAG_V Z80_FLAG_P
137 #define Z80_FLAG_3 0x08
138 #define Z80_FLAG_H 0x10
139 #define Z80_FLAG_5 0x20
140 #define Z80_FLAG_Z 0x40
141 #define Z80_FLAG_S 0x80
142 
149  Z80EX_BYTE r7; /* The high bit of the R register */
151  Z80EX_BYTE iff1, iff2; /*interrupt flip-flops*/
152  Z80EX_REGPAIR_T memptr; /*undocumented internal register*/
154  int halted;
155 
156  unsigned long tstate; /*t-state clock of current/last step*/
157  unsigned char op_tstate; /*clean (without WAITs and such) t-state of currently executing instruction*/
158 
159  int noint_once; /*disable interrupts before next opcode?*/
160  int reset_PV_on_int; /*reset P/V flag on interrupt? (for LD A,R / LD A,I)*/
161  int doing_opcode; /*is there an opcode currently executing?*/
162  char int_vector_req; /*opcode must be fetched from IO device? (int vector read)*/
164 
165 #ifdef Z80EX_HAVE_TSTATE_CB_VAR
166  int tstate_cb; /* use tstate callback? */
167 #endif
168 
169  /*other stuff*/
174 
175  int nmos; /* NMOS Z80 mode if '1', CMOS if '0' */
176  /* Z180 related - LGB */
177 #ifdef Z80EX_Z180_SUPPORT
178  int z180;
179  int internal_int_disable;
180 #endif
181 };
182 
184 
185 extern Z80EX_CONTEXT z80ex;
186 
187 /* statically linked callbacks */
188 
189 #ifdef Z80EX_CALLBACK_PROTOTYPE
190 #ifdef Z80EX_TSTATE_CALLBACK
192 #endif
199 #ifdef Z80EX_ED_TRAPPING_SUPPORT
201 #endif
202 #ifdef Z80EX_Z180_SUPPORT
203 Z80EX_CALLBACK_PROTOTYPE void z80ex_z180_cb (Z80EX_WORD pc, Z80EX_BYTE prefix, Z80EX_BYTE series, Z80EX_BYTE opcode, Z80EX_BYTE itc76);
204 #endif
205 #endif
206 
207 /*create and initialize CPU*/
208 extern void z80ex_init(void);
209 
210 /*do next opcode (instruction or prefix), return number of T-states*/
211 extern int z80ex_step(void);
212 
213 /*returns type of the last opcode, processed with z80ex_step.
214 type will be 0 for complete instruction, or dd/fd/cb/ed for opcode prefix.*/
215 #define z80ex_last_op_type() z80ex.prefix
216 
217 /*maskable interrupt*/
218 /*returns number of T-states if interrupt was accepted, otherwise 0*/
219 extern int z80ex_int();
220 
221 /*non-maskable interrupt*/
222 /*returns number of T-states (11 if interrupt was accepted, or 0 if processor
223 is doing an instruction right now)*/
224 extern int z80ex_nmi();
225 
226 /*reset CPU*/
227 extern void z80ex_reset(void);
228 
229 extern void z80ex_init(void);
230 
231 /*returns 1 if CPU doing HALT instruction now*/
232 #define z80ex_doing_halt() z80ex.halted
233 
234 /*when called from callbacks, returns current T-state of the executing opcode (instruction or prefix),
235 else returns T-states taken by last opcode executed*/
236 #define z80ex_op_tstate() z80ex.tstate
237 
238 /*generate <w_states> Wait-states. (T-state callback will be called <w_states> times, when defined).
239 should be used to simulate WAIT signal or disabled CLK*/
240 extern void z80ex_w_states(unsigned w_states);
241 
242 /*spend one T-state doing nothing (often IO devices cannot handle data request on
243 the first T-state at which RD/WR goes active).
244 for I/O callbacks*/
245 extern void z80ex_next_t_state();
246 
247 /*returns 1 if maskable interrupts are possible in current z80 state*/
248 extern int z80ex_int_possible(void);
249 
250 /*returns 1 if non-maskable interrupts are possible in current z80 state*/
251 extern int z80ex_nmi_possible(void);
252 
253 #endif
z80ex_ed_cb
int z80ex_ed_cb(Z80EX_BYTE opcode)
Definition: cpu.c:586
_z80_cpu_context::tmpbyte_s
Z80EX_SIGNED_BYTE tmpbyte_s
Definition: z80ex.h:173
_z80_cpu_context::nmos
int nmos
Definition: z80ex.h:175
z80ex_int_possible
int z80ex_int_possible(void)
Definition: z80ex.c:327
pc
Uint16 pc
Definition: z8k1.c:127
z80ex_pwrite_cb
void z80ex_pwrite_cb(Z80EX_WORD port16, Z80EX_BYTE value)
Definition: cpu.c:396
_z80_cpu_context::hl_
Z80EX_REGPAIR_T hl_
Definition: z80ex.h:145
_z80_cpu_context::af_
Z80EX_REGPAIR_T af_
Definition: z80ex.h:145
_z80_cpu_context::i
Z80EX_BYTE i
Definition: z80ex.h:147
z80ex_nmi
int z80ex_nmi()
Definition: z80ex.c:192
z80ex_mwrite_cb
void z80ex_mwrite_cb(Z80EX_WORD addr, Z80EX_BYTE value)
Definition: cpu.c:278
_z80_cpu_context::af
Z80EX_REGPAIR_T af
Definition: z80ex.h:144
IM2
@ IM2
Definition: z80ex.h:67
z80ex_pread_cb
Z80EX_BYTE z80ex_pread_cb(Z80EX_WORD port16)
Definition: cpu.c:302
_z80_cpu_context::doing_opcode
int doing_opcode
Definition: z80ex.h:161
addr
int addr
Definition: dma65.c:81
_z80_cpu_context::tstate
unsigned long tstate
Definition: z80ex.h:156
z80ex
Z80EX_CONTEXT z80ex
Definition: primo.c:37
Z80EX_SIGNED_BYTE
signed char Z80EX_SIGNED_BYTE
Definition: z80ex.h:50
_z80_cpu_context::iy
Z80EX_REGPAIR_T iy
Definition: z80ex.h:146
Z80EX_WORD
unsigned short Z80EX_WORD
Definition: z80ex.h:51
_z80_cpu_context::hl
Z80EX_REGPAIR_T hl
Definition: z80ex.h:144
_z80_cpu_context
Definition: z80ex.h:143
z80ex_step
int z80ex_step(void)
Definition: z80ex.c:47
IM_MODE
IM_MODE
Definition: z80ex.h:67
_z80_cpu_context::sp
Z80EX_REGPAIR_T sp
Definition: z80ex.h:150
_z80_cpu_context::im
IM_MODE im
Definition: z80ex.h:153
Z80EX_REGPAIR_T::w
Z80EX_WORD w
Definition: z80ex.h:64
IM0
@ IM0
Definition: z80ex.h:67
_z80_cpu_context::halted
int halted
Definition: z80ex.h:154
_z80_cpu_context::reset_PV_on_int
int reset_PV_on_int
Definition: z80ex.h:160
Z80EX_BYTE
unsigned char Z80EX_BYTE
Definition: z80ex.h:49
z80ex_next_t_state
void z80ex_next_t_state()
Definition: z80ex.c:312
_z80_cpu_context::tmpbyte
Z80EX_BYTE tmpbyte
Definition: z80ex.h:172
z80ex_nmi_possible
int z80ex_nmi_possible(void)
Definition: z80ex.c:333
_z80_cpu_context::bc_
Z80EX_REGPAIR_T bc_
Definition: z80ex.h:145
z80ex_init
void z80ex_init(void)
Definition: z80ex.c:175
Z80EX_REGPAIR_T::l
Z80EX_BYTE l
Definition: z80ex.h:62
_z80_cpu_context::prefix
Z80EX_BYTE prefix
Definition: z80ex.h:163
_z80_cpu_context::de_
Z80EX_REGPAIR_T de_
Definition: z80ex.h:145
_z80_cpu_context::tmpword
Z80EX_REGPAIR_T tmpword
Definition: z80ex.h:170
_z80_cpu_context::ix
Z80EX_REGPAIR_T ix
Definition: z80ex.h:146
_z80_cpu_context::r
Z80EX_WORD r
Definition: z80ex.h:148
_z80_cpu_context::iff1
Z80EX_BYTE iff1
Definition: z80ex.h:151
_z80_cpu_context::int_vector_req
char int_vector_req
Definition: z80ex.h:162
_z80_cpu_context::r7
Z80EX_BYTE r7
Definition: z80ex.h:149
_z80_cpu_context::memptr
Z80EX_REGPAIR_T memptr
Definition: z80ex.h:152
z80ex_reti_cb
void z80ex_reti_cb(void)
Definition: cpu.c:582
_z80_cpu_context::iff2
Z80EX_BYTE iff2
Definition: z80ex.h:151
_z80_cpu_context::de
Z80EX_REGPAIR_T de
Definition: z80ex.h:144
_z80_cpu_context::bc
Z80EX_REGPAIR_T bc
Definition: z80ex.h:144
Z80EX_REGPAIR_T
Definition: z80ex.h:57
z80ex_reset
void z80ex_reset(void)
Definition: z80ex.c:156
z80ex_intread_cb
Z80EX_BYTE z80ex_intread_cb(void)
Definition: cpu.c:577
Z80EX_DWORD
unsigned int Z80EX_DWORD
Definition: z80ex.h:52
value
int value
Definition: dma65.c:90
Z80EX_CALLBACK_PROTOTYPE
#define Z80EX_CALLBACK_PROTOTYPE
Definition: xemu-target.h:10
_z80_cpu_context::op_tstate
unsigned char op_tstate
Definition: z80ex.h:157
IM1
@ IM1
Definition: z80ex.h:67
z80ex_w_states
void z80ex_w_states(unsigned w_states)
Definition: z80ex.c:307
z80ex_int
int z80ex_int()
Definition: z80ex.c:225
z80ex_mread_cb
Z80EX_BYTE z80ex_mread_cb(Z80EX_WORD addr, int m1_state)
Definition: cpu.c:240
_z80_cpu_context::tmpaddr
Z80EX_REGPAIR_T tmpaddr
Definition: z80ex.h:171
_z80_cpu_context::pc
Z80EX_REGPAIR_T pc
Definition: z80ex.h:150
_z80_cpu_context::noint_once
int noint_once
Definition: z80ex.h:159
z80ex_tstate_cb
void z80ex_tstate_cb(void)
Definition: spectrum.c:113