Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1088 | alone | 1 | #ifndef _Z80_DEFS_H_INCLUDED |
2 | #define _Z80_DEFS_H_INCLUDED |
||
3 | |||
4 | #include <stddef.h> |
||
5 | #include <stdint.h> |
||
6 | #include "../sysdefs.h" |
||
7 | struct Z80; |
||
8 | |||
9 | #define Z80FAST fastcall |
||
10 | |||
11 | #ifdef _MSC_VER |
||
12 | #define Z80INLINE forceinline // time-critical inlines |
||
13 | #else |
||
14 | #define Z80INLINE inline |
||
15 | #endif |
||
16 | |||
17 | typedef void (Z80FAST *STEPFUNC)(Z80*); |
||
18 | #define Z80OPCODE void Z80FAST |
||
19 | typedef unsigned char (Z80FAST *LOGICFUNC)(Z80*, unsigned char byte); |
||
20 | #define Z80LOGIC unsigned char Z80FAST |
||
21 | |||
22 | |||
23 | //============================================================================= |
||
24 | struct TZ80State |
||
25 | { |
||
26 | unsigned t; // ������� ���� ���������� ������ spectrum ����� [0..conf.frame) |
||
27 | /*------------------------------*/ |
||
28 | union |
||
29 | { |
||
30 | unsigned pc; |
||
31 | struct |
||
32 | { |
||
33 | unsigned char pcl; |
||
34 | unsigned char pch; |
||
35 | }; |
||
36 | }; |
||
37 | union |
||
38 | { |
||
39 | unsigned sp; |
||
40 | struct |
||
41 | { |
||
42 | unsigned char spl; |
||
43 | unsigned char sph; |
||
44 | }; |
||
45 | }; |
||
46 | union |
||
47 | { |
||
48 | unsigned ir_; |
||
49 | struct |
||
50 | { |
||
51 | unsigned char r_low; |
||
52 | unsigned char i; |
||
53 | }; |
||
54 | }; |
||
55 | union |
||
56 | { |
||
57 | unsigned int_flags; |
||
58 | struct |
||
59 | { |
||
60 | unsigned char r_hi; |
||
61 | unsigned char iff1; // int = 1 -> EI |
||
62 | // int = 0 -> DI |
||
63 | unsigned char iff2; // ��������� int �� ������ NMI |
||
64 | unsigned char halted; |
||
65 | }; |
||
66 | }; |
||
67 | /*------------------------------*/ |
||
68 | union |
||
69 | { |
||
70 | unsigned bc; //��� �� �� ���� ??????!!!!! |
||
71 | unsigned short bc16; //��� ��������� �� ���� � ����? [NS] |
||
72 | struct |
||
73 | { |
||
74 | unsigned char c; |
||
75 | unsigned char b; |
||
76 | u8 trash; |
||
77 | }; |
||
78 | }; |
||
79 | union |
||
80 | { |
||
81 | unsigned de; |
||
82 | struct |
||
83 | { |
||
84 | unsigned char e; |
||
85 | unsigned char d; |
||
86 | }; |
||
87 | }; |
||
88 | union |
||
89 | { |
||
90 | unsigned hl; |
||
91 | struct |
||
92 | { |
||
93 | unsigned char l; |
||
94 | unsigned char h; |
||
95 | }; |
||
96 | }; |
||
97 | union |
||
98 | { |
||
99 | unsigned af; |
||
100 | struct |
||
101 | { |
||
102 | unsigned char f; |
||
103 | unsigned char a; |
||
104 | }; |
||
105 | }; |
||
106 | /*------------------------------*/ |
||
107 | union |
||
108 | { |
||
109 | unsigned ix; |
||
110 | struct |
||
111 | { |
||
112 | unsigned char xl; |
||
113 | unsigned char xh; |
||
114 | }; |
||
115 | }; |
||
116 | union |
||
117 | { |
||
118 | unsigned iy; |
||
119 | struct |
||
120 | { |
||
121 | unsigned char yl; |
||
122 | unsigned char yh; |
||
123 | }; |
||
124 | }; |
||
125 | /*------------------------------*/ |
||
126 | struct //ALT |
||
127 | { |
||
128 | union |
||
129 | { |
||
130 | unsigned bc; //alt.bc |
||
131 | struct |
||
132 | { |
||
133 | unsigned char c; //alt.c |
||
134 | unsigned char b; //alt.b |
||
135 | }; |
||
136 | }; |
||
137 | union |
||
138 | { |
||
139 | unsigned de; //alt.de |
||
140 | struct |
||
141 | { |
||
142 | unsigned char e; //alt.e |
||
143 | unsigned char d; //alt.d |
||
144 | }; |
||
145 | }; |
||
146 | union |
||
147 | { |
||
148 | unsigned hl; //alt.hl |
||
149 | struct |
||
150 | { |
||
151 | unsigned char l; //alt.l |
||
152 | unsigned char h; //alt.h |
||
153 | }; |
||
154 | }; |
||
155 | union |
||
156 | { |
||
157 | unsigned af; //alt.af |
||
158 | struct |
||
159 | { |
||
160 | unsigned char f; //alt.f |
||
161 | unsigned char a; //alt.a |
||
162 | }; |
||
163 | }; |
||
164 | } alt; |
||
165 | union |
||
166 | { |
||
167 | unsigned memptr; // undocumented register |
||
168 | struct |
||
169 | { |
||
170 | unsigned char meml; |
||
171 | unsigned char memh; |
||
172 | }; |
||
173 | }; |
||
174 | unsigned eipos, haltpos; |
||
175 | /*------------------------------*/ |
||
176 | unsigned char im; |
||
177 | unsigned char nmi_in_progress; //NEDOREPO |
||
178 | // bool nmi_in_progress; //0.39.0 |
||
179 | }; |
||
180 | //============================================================================= |
||
181 | |||
182 | |||
183 | //============================================================================= |
||
184 | typedef u8 (__fastcall * TXm)(u32 addr); |
||
185 | typedef u8 (__fastcall * TRm)(u32 addr); |
||
186 | typedef void (__fastcall * TWm)(u32 addr, u8 val); |
||
187 | //============================================================================= |
||
188 | |||
189 | |||
190 | //============================================================================= |
||
191 | struct TMemIf |
||
192 | { |
||
193 | TXm xm; |
||
194 | TRm rm; |
||
195 | TWm wm; |
||
196 | }; |
||
197 | //============================================================================= |
||
198 | |||
199 | |||
200 | //============================================================================= |
||
201 | struct Z80 : public TZ80State |
||
202 | { |
||
203 | unsigned char tmp0, tmp1, tmp3; |
||
204 | unsigned short last_branch; |
||
205 | //------------------------------------------------------------------------- |
||
206 | // Trace Window |
||
207 | unsigned trace_curs; // ����� ������� |
||
208 | unsigned trace_top; // ����� ����� ������� ������ |
||
209 | int graph_trace_cursor_pos; // ����� ����������� ��������� ������� [NS] |
||
210 | unsigned trace_mode; // 0 - addr |
||
211 | // 1 - dump/labels |
||
212 | // 2 - disasm |
||
213 | //------------------------------------------------------------------------- |
||
214 | // Memory Viewer |
||
215 | unsigned mem_curs; // ����� ������� |
||
216 | unsigned mem_top; // ����� ������ ����� ������� ������� ������ |
||
217 | unsigned mem_second; // ����� �������������� ������� ����� |
||
218 | unsigned mem_addr_edit_mode; // ����� �������������� ������ [NS] |
||
219 | //------------------------------------------------------------------------- |
||
220 | unsigned pc_trflags; |
||
221 | unsigned nextpc; |
||
222 | //------------------------------------------------------------------------- |
||
223 | unsigned dbg_stophere; |
||
224 | unsigned dbg_stopsp; |
||
225 | unsigned dbg_loop_r1; |
||
226 | unsigned dbg_loop_r2; |
||
227 | unsigned char dbgchk; // ������� ������� �������� ����������� |
||
228 | bool int_pend; // �� ����� int ���� �������� ���������� |
||
229 | bool int_gate; // ���������� ������� ���������� |
||
230 | // 1 - ��������� |
||
231 | // 0 - ��������� |
||
232 | //------------------------------------------------------------------------- |
||
233 | #define MAX_CBP 16 |
||
234 | uintptr_t cbp[MAX_CBP][128]; // ������� ��� �������� ����������� |
||
235 | unsigned cbpn; |
||
236 | |||
237 | i64 debug_last_t; // used to find time delta |
||
238 | u32 tpi; // ����� ������ ����� ������������ |
||
239 | u32 trpc[40]; |
||
240 | |||
241 | // typedef u8 (__fastcall * TRmDbg)(u32 addr); |
||
242 | // typedef u8 *(__fastcall * TMemDbg)(u32 addr); |
||
243 | // typedef void (__fastcall * TWmDbg)(u32 addr, u8 val); |
||
244 | |||
245 | typedef void (__cdecl *TBankNames)(int i, char *Name); |
||
246 | typedef void (Z80FAST * TStep)(); |
||
247 | typedef i64 (__cdecl * TDelta)(); |
||
248 | typedef void (__cdecl * TSetLastT)(); |
||
249 | |||
250 | // TRmDbg DirectRm; // direct read memory in debuger |
||
251 | // TWmDbg DirectWm; // direct write memory in debuger |
||
252 | // TMemDbg DirectMem; // get direct memory pointer in debuger |
||
253 | |||
254 | u32 Idx; // ������ � ������� ����������� |
||
255 | TBankNames BankNames; |
||
256 | TStep Step; |
||
257 | TDelta Delta; |
||
258 | TSetLastT SetLastT; |
||
259 | u8 *membits; |
||
260 | u8 *io_bits; // [NS] |
||
261 | u8 *bp_disable_bits; // [NS] |
||
262 | u8 dbgbreak; |
||
263 | const TMemIf *FastMemIf; // ������� �������� ������ |
||
264 | const TMemIf *DbgMemIf; // ��������� ������ ��� ��������� ��������� (���������� �� ������ � ������) |
||
265 | const TMemIf *MemIf; // ������� �������� ��������� ������ |
||
266 | |||
267 | //------------------------------------------------------------------------- |
||
268 | void reset() |
||
269 | { |
||
270 | int_flags = 0; |
||
271 | ir_ = 0; |
||
272 | pc = 0; |
||
273 | im = 0; |
||
274 | last_branch = 0; |
||
275 | int_pend = false; |
||
276 | int_gate = true; |
||
277 | } |
||
278 | //------------------------------------------------------------------------- |
||
279 | |||
280 | //------------------------------------------------------------------------- |
||
281 | // ?????????? �� ��� �� �����������???? �_� |
||
282 | Z80( u32 Idx, |
||
283 | TBankNames BankNames, |
||
284 | TStep Step, |
||
285 | TDelta Delta, |
||
286 | TSetLastT SetLastT, |
||
287 | u8 *membits, |
||
288 | u8 *io_bits, // [NS] |
||
289 | u8 *bp_disable_bits, // [NS] |
||
290 | const TMemIf *FastMemIf, |
||
291 | const TMemIf *DbgMemIf) : |
||
292 | Idx( Idx), |
||
293 | BankNames( BankNames), |
||
294 | Step( Step), |
||
295 | Delta( Delta), |
||
296 | SetLastT( SetLastT), |
||
297 | membits( membits), |
||
298 | io_bits( io_bits), // [NS] |
||
299 | bp_disable_bits( bp_disable_bits), // [NS] |
||
300 | FastMemIf(FastMemIf), |
||
301 | DbgMemIf(DbgMemIf) |
||
302 | { |
||
303 | MemIf = FastMemIf; |
||
304 | tpi = 0; |
||
305 | dbgbreak = 0; |
||
306 | dbgchk = 0; |
||
307 | debug_last_t = 0; |
||
308 | trace_curs = trace_top = (unsigned)-1; trace_mode = 0; |
||
309 | mem_curs = mem_top = 0; |
||
310 | pc_trflags = nextpc = 0; |
||
311 | dbg_stophere = dbg_stopsp = (unsigned)-1; |
||
312 | dbg_loop_r1 = 0; |
||
313 | dbg_loop_r2 = 0xFFFF; |
||
314 | int_pend = false; |
||
315 | int_gate = true; |
||
316 | nmi_in_progress = false; |
||
317 | } |
||
318 | //------------------------------------------------------------------------- |
||
319 | |||
320 | virtual ~Z80() { } |
||
321 | |||
322 | //------------------------------------------------------------------------- |
||
323 | u32 GetIdx() const { return Idx; } |
||
324 | |||
325 | //��������� ����� ������ � ������ |
||
326 | void SetTpi(u32 Tpi) { tpi = Tpi; } |
||
327 | |||
328 | void SetFastMemIf() { MemIf = FastMemIf; } |
||
329 | void SetDbgMemIf() { MemIf = DbgMemIf; } |
||
330 | |||
331 | u8 DirectRm(unsigned addr) const { return *DirectMem(addr); } // direct read memory in debuger |
||
332 | void DirectWm(unsigned addr, u8 val) { *DirectMem(addr) = val; } // direct write memory in debuger |
||
333 | |||
334 | /* |
||
335 | virtual unsigned char rm(unsigned addr) = 0; |
||
336 | virtual void wm(unsigned addr, unsigned char val) = 0; |
||
337 | */ |
||
338 | virtual u8 *DirectMem(unsigned addr) const = 0; // get direct memory pointer in debuger |
||
339 | |||
340 | virtual unsigned char in(unsigned port) = 0; |
||
341 | virtual void out(unsigned port, unsigned char val) = 0; |
||
342 | virtual unsigned char m1_cycle() = 0; // [vv] �� ������� �� ���������� (������� � ����������) |
||
343 | virtual u8 IntVec() = 0; // ������� ������������ �������� ������� ���������� ��� im2 |
||
344 | virtual void CheckNextFrame() = 0; // �������� � ���������� �������� ������ � ������ ������ ���������� |
||
345 | virtual void retn() = 0; // ���������� � ����� ���������� retn (������ ���������� ���� nmi_in_progress � ��������� ��������� ������) |
||
346 | }; |
||
347 | //============================================================================= |
||
348 | |||
349 | |||
350 | //============================================================================= |
||
351 | #define CF 0x01 |
||
352 | #define NF 0x02 |
||
353 | #define PV 0x04 |
||
354 | #define F3 0x08 |
||
355 | #define HF 0x10 |
||
356 | #define F5 0x20 |
||
357 | #define ZF 0x40 |
||
358 | #define SF 0x80 |
||
359 | //============================================================================= |
||
360 | |||
361 | #endif // _Z80_DEFS_H_INCLUDED |