1 /*
2  * Z80Ex, ZILoG Z80 CPU emulator.
3  *
4  * by Pigmaker57 aka boo_boo [pigmaker57@kahoh57.info]
5  *
6  * contains some code from the FUSE project (http://fuse-emulator.sourceforge.net)
7  * Released under GNU GPL v2
8  *
9  */
10 
11 #ifndef _Z80EX_H_INCLUDED
12 #define _Z80EX_H_INCLUDED
13 
14 #include "z80ex_common.h"
15 
16 typedef
17 enum {regAF,regBC,regDE,regHL,regAF_,regBC_,regDE_,regHL_,regIX,regIY,regPC,regSP,regI,regR,regR7,regIM/*0,1 or 2*/,regIFF1,regIFF2}
18 Z80_REG_T;
19 
20 typedef struct {
21 	int API_revision;
22 	int major;
23 	int minor;
24 	char *release_type; /*e.g., "beta", "RC"*/
25 	char *as_string; /*full version string, e.g., "0.16.7beta"*/
26 } Z80EX_VERSION;
27 
28 #ifndef __Z80EX_SELF_INCLUDE
29 
30 struct _z80_cpu_context;
31 typedef struct _z80_cpu_context Z80EX_CONTEXT;
32 
33 #endif
34 
35 /*callback prototypes:*/
36 
37 /*to be called on each T-State [optional]*/
38 typedef void (*z80ex_tstate_cb)(Z80EX_CONTEXT *cpu, void *user_data);
39 
40 /*read byte from memory <addr> -- called when RD & MREQ goes active.
41 m1_state will be 1 if M1 signal is active*/
42 typedef Z80EX_BYTE (*z80ex_mread_cb)(Z80EX_CONTEXT *cpu, Z80EX_WORD addr, int m1_state, void *user_data);
43 
44 /*write <value> to memory <addr> -- called when WR & MREQ goes active*/
45 typedef void (*z80ex_mwrite_cb)(Z80EX_CONTEXT *cpu, Z80EX_WORD addr, Z80EX_BYTE value, void *user_data);
46 
47 /*read byte from <port> -- called when RD & IORQ goes active*/
48 typedef Z80EX_BYTE (*z80ex_pread_cb)(Z80EX_CONTEXT *cpu, Z80EX_WORD port, void *user_data);
49 
50 /*write <value> to <port> -- called when WR & IORQ goes active*/
51 typedef void (*z80ex_pwrite_cb)(Z80EX_CONTEXT *cpu, Z80EX_WORD port, Z80EX_BYTE value, void *user_data);
52 
53 /*read byte of interrupt vector -- called when M1 and IORQ goes active*/
54 typedef Z80EX_BYTE (*z80ex_intread_cb)(Z80EX_CONTEXT *cpu, void *user_data);
55 
56 /*called when the RETI instruction is executed (useful for emulating Z80 PIO/CTC and such)*/
57 typedef void (*z80ex_reti_cb)(Z80EX_CONTEXT *cpu, void *user_data);
58 
59 #ifndef __Z80EX_SELF_INCLUDE
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /*get version info*/
66 extern Z80EX_VERSION *z80ex_get_version();
67 
68 /*create and initialize CPU*/
69 extern Z80EX_CONTEXT *z80ex_create(z80ex_mread_cb mrcb_fn, void *mrcb_data,
70 	z80ex_mwrite_cb mwcb_fn, void *mwcb_data,
71 	z80ex_pread_cb prcb_fn, void *prcb_data,
72 	z80ex_pwrite_cb pwcb_fn, void *pwcb_data,
73 	z80ex_intread_cb ircb_fn, void *ircb_data);
74 
75 /*destroy CPU*/
76 extern void z80ex_destroy(Z80EX_CONTEXT *cpu);
77 
78 /*do next opcode (instruction or prefix), return number of T-states*/
79 extern int z80ex_step(Z80EX_CONTEXT *cpu);
80 
81 /*returns type of the last opcode, processed with z80ex_step.
82 type will be 0 for complete instruction, or dd/fd/cb/ed for opcode prefix.*/
83 extern Z80EX_BYTE z80ex_last_op_type(Z80EX_CONTEXT *cpu);
84 
85 /*set T-state callback*/
86 extern void z80ex_set_tstate_callback(Z80EX_CONTEXT *cpu, z80ex_tstate_cb cb_fn, void *user_data);
87 
88 /*set RETI callback*/
89 extern void z80ex_set_reti_callback(Z80EX_CONTEXT *cpu, z80ex_reti_cb cb_fn, void *user_data);
90 
91 /*set memory read callback*/
92 extern void z80ex_set_memread_callback(Z80EX_CONTEXT *cpu, z80ex_mread_cb mrcb_fn, void *mrcb_data);
93 
94 /*set memory write callback*/
95 extern void z80ex_set_memwrite_callback(Z80EX_CONTEXT *cpu, z80ex_mwrite_cb mwcb_fn, void *mwcb_data);
96 
97 /*set port read callback*/
98 extern void z80ex_set_portread_callback(Z80EX_CONTEXT *cpu, z80ex_pread_cb prcb_fn, void *prcb_data);
99 
100 /*set port write callback*/
101 extern void z80ex_set_portwrite_callback(Z80EX_CONTEXT *cpu, z80ex_pwrite_cb pwcb_fn, void *pwcb_data);
102 
103 /*set INT read callback*/
104 extern void z80ex_set_intread_callback(Z80EX_CONTEXT *cpu, z80ex_intread_cb ircb_fn, void *ircb_data);
105 
106 /*maskable interrupt*/
107 /*returns number of T-states if interrupt was accepted, otherwise 0*/
108 extern int z80ex_int(Z80EX_CONTEXT *cpu);
109 
110 /*non-maskable interrupt*/
111 /*returns number of T-states (11 if interrupt was accepted, or 0 if processor
112 is doing an instruction right now)*/
113 extern int z80ex_nmi(Z80EX_CONTEXT *cpu);
114 
115 /*reset CPU*/
116 extern void z80ex_reset(Z80EX_CONTEXT *cpu);
117 
118 /*get register value*/
119 extern Z80EX_WORD z80ex_get_reg(Z80EX_CONTEXT *cpu, Z80_REG_T reg);
120 
121 /*set register value (for 1-byte registers lower byte of <value> will be used)*/
122 extern void z80ex_set_reg(Z80EX_CONTEXT *cpu, Z80_REG_T reg, Z80EX_WORD value);
123 
124 /*returns 1 if CPU doing HALT instruction now*/
125 extern int z80ex_doing_halt(Z80EX_CONTEXT *cpu);
126 
127 /*when called from callbacks, returns current T-state of the executing opcode (instruction or prefix),
128 else returns T-states taken by last opcode executed*/
129 extern int z80ex_op_tstate(Z80EX_CONTEXT *cpu);
130 
131 /*generate <w_states> Wait-states. (T-state callback will be called <w_states> times, when defined).
132 should be used to simulate WAIT signal or disabled CLK*/
133 extern void z80ex_w_states(Z80EX_CONTEXT *cpu, unsigned w_states);
134 
135 /*spend one T-state doing nothing (often IO devices cannot handle data request on
136 the first T-state at which RD/WR goes active).
137 for I/O callbacks*/
138 extern void z80ex_next_t_state(Z80EX_CONTEXT *cpu);
139 
140 /*returns 1 if maskable interrupts are possible in current z80 state*/
141 extern int z80ex_int_possible(Z80EX_CONTEXT *cpu);
142 
143 /*returns 1 if non-maskable interrupts are possible in current z80 state*/
144 extern int z80ex_nmi_possible(Z80EX_CONTEXT *cpu);
145 
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 #endif
151 
152 #endif
153