summaryrefslogtreecommitdiff
path: root/apps/plugins/zxbox/z80_op6.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/zxbox/z80_op6.c')
-rw-r--r--apps/plugins/zxbox/z80_op6.c437
1 files changed, 437 insertions, 0 deletions
diff --git a/apps/plugins/zxbox/z80_op6.c b/apps/plugins/zxbox/z80_op6.c
new file mode 100644
index 0000000000..7bab122263
--- /dev/null
+++ b/apps/plugins/zxbox/z80_op6.c
@@ -0,0 +1,437 @@
1/*
2 * Copyright (C) 1996-1998 Szeredi Miklos
3 * Email: mszeredi@inf.bme.hu
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. See the file COPYING.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 */
20
21#ifndef NO_OPDEF
22#include "z80_def.h"
23#include "z80_op6.h"
24#endif
25
26#define GHL DANM(cbaddr)
27
28#define B7(r) (((r) & 0x80) >> 7)
29#define B0(r) ((r) & 0x01)
30
31#define SHIFTROTL(r, mod) \
32{ \
33 register int carry; \
34 carry = B7(r); \
35 r = mod; \
36 RF = (RF & ~(AALLF)) | carry | \
37 TAB(orf_tbl)[(byte) r]; \
38}
39
40
41#define SHIFTROTR(r, mod) \
42{ \
43 register int carry; \
44 carry = B0(r); \
45 r = mod; \
46 RF = (RF & ~(AALLF)) | carry | \
47 TAB(orf_tbl)[(byte) r]; \
48}
49
50
51#define RLC(r) SHIFTROTL(r, (r << 1) | carry)
52#define RRC(r) SHIFTROTR(r, (r >> 1) | (carry << 7))
53#define RLN(r) SHIFTROTL(r, (r << 1) | (RF & CF))
54#define RRN(r) SHIFTROTR(r, (r >> 1) | ((RF & CF) << 7))
55#define SLA(r) SHIFTROTL(r, r << 1)
56#define SRA(r) SHIFTROTR(r, (byte) ((sbyte) r >> 1))
57#define SLL(r) SHIFTROTL(r, (r << 1) | 0x01)
58#define SRL(r) SHIFTROTR(r, r >> 1)
59
60
61#define SHRR(shrn, func, an, rn, r, n) \
62OPDEF(shrn ## _ ## rn, 0x00+an*8+n) \
63{ \
64 func(r); \
65 ENTIME(8); \
66}
67
68#define SHRIHL(shrn, func, an) \
69OPDEF(shrn ## _ihl, 0x06+an*8) \
70{ \
71 register byte btmp; \
72 btmp = READ(GHL); \
73 func(btmp); \
74 WRITE(GHL, btmp); \
75 ENTIME(15); \
76}
77
78#define RLC_R(rn, r, n) SHRR(rlc, RLC, 0, rn, r, n)
79#define RRC_R(rn, r, n) SHRR(rrc, RRC, 1, rn, r, n)
80#define RL_R(rn, r, n) SHRR(rl, RLN, 2, rn, r, n)
81#define RR_R(rn, r, n) SHRR(rr, RRN, 3, rn, r, n)
82#define SLA_R(rn, r, n) SHRR(sla, SLA, 4, rn, r, n)
83#define SRA_R(rn, r, n) SHRR(sra, SRA, 5, rn, r, n)
84#define SLL_R(rn, r, n) SHRR(sll, SLL, 6, rn, r, n)
85#define SRL_R(rn, r, n) SHRR(srl, SRL, 7, rn, r, n)
86
87RLC_R(b, RB, 0)
88RLC_R(c, RC, 1)
89RLC_R(d, RD, 2)
90RLC_R(e, RE, 3)
91RLC_R(h, RH, 4)
92RLC_R(l, RL, 5)
93RLC_R(a, RA, 7)
94
95RRC_R(b, RB, 0)
96RRC_R(c, RC, 1)
97RRC_R(d, RD, 2)
98RRC_R(e, RE, 3)
99RRC_R(h, RH, 4)
100RRC_R(l, RL, 5)
101RRC_R(a, RA, 7)
102
103RL_R(b, RB, 0)
104RL_R(c, RC, 1)
105RL_R(d, RD, 2)
106RL_R(e, RE, 3)
107RL_R(h, RH, 4)
108RL_R(l, RL, 5)
109RL_R(a, RA, 7)
110
111RR_R(b, RB, 0)
112RR_R(c, RC, 1)
113RR_R(d, RD, 2)
114RR_R(e, RE, 3)
115RR_R(h, RH, 4)
116RR_R(l, RL, 5)
117RR_R(a, RA, 7)
118
119SLA_R(b, RB, 0)
120SLA_R(c, RC, 1)
121SLA_R(d, RD, 2)
122SLA_R(e, RE, 3)
123SLA_R(h, RH, 4)
124SLA_R(l, RL, 5)
125SLA_R(a, RA, 7)
126
127SRA_R(b, RB, 0)
128SRA_R(c, RC, 1)
129SRA_R(d, RD, 2)
130SRA_R(e, RE, 3)
131SRA_R(h, RH, 4)
132SRA_R(l, RL, 5)
133SRA_R(a, RA, 7)
134
135SLL_R(b, RB, 0)
136SLL_R(c, RC, 1)
137SLL_R(d, RD, 2)
138SLL_R(e, RE, 3)
139SLL_R(h, RH, 4)
140SLL_R(l, RL, 5)
141SLL_R(a, RA, 7)
142
143SRL_R(b, RB, 0)
144SRL_R(c, RC, 1)
145SRL_R(d, RD, 2)
146SRL_R(e, RE, 3)
147SRL_R(h, RH, 4)
148SRL_R(l, RL, 5)
149SRL_R(a, RA, 7)
150
151SHRIHL(rlc, RLC, 0)
152SHRIHL(rrc, RRC, 1)
153SHRIHL(rl, RLN, 2)
154SHRIHL(rr, RRN, 3)
155SHRIHL(sla, SLA, 4)
156SHRIHL(sra, SRA, 5)
157SHRIHL(sll, SLL, 6)
158SHRIHL(srl, SRL, 7)
159
160#define BIT(r, n) \
161 RF = (RF & ~(SF | ZF | NF)) | (r & SF) | (((~r >> n) & 0x01) << 6)
162
163#define BIT_N_R(bn, rn, r, n) \
164OPDEF(bit_ ## bn ## _ ## rn, 0x40+bn*8+n) \
165{ \
166 BIT(r, bn); \
167 ENTIME(8); \
168}
169
170#define BIT_N_IHL(bn) \
171OPDEF(bit_ ## bn ## _ihl, 0x46+bn*8) \
172{ \
173 register byte btmp; \
174 btmp = READ(GHL); \
175 BIT(btmp, bn); \
176 ENTIME(12); \
177}
178
179BIT_N_R(0, b, RB, 0)
180BIT_N_R(0, c, RC, 1)
181BIT_N_R(0, d, RD, 2)
182BIT_N_R(0, e, RE, 3)
183BIT_N_R(0, h, RH, 4)
184BIT_N_R(0, l, RL, 5)
185BIT_N_R(0, a, RA, 7)
186
187BIT_N_R(1, b, RB, 0)
188BIT_N_R(1, c, RC, 1)
189BIT_N_R(1, d, RD, 2)
190BIT_N_R(1, e, RE, 3)
191BIT_N_R(1, h, RH, 4)
192BIT_N_R(1, l, RL, 5)
193BIT_N_R(1, a, RA, 7)
194
195BIT_N_R(2, b, RB, 0)
196BIT_N_R(2, c, RC, 1)
197BIT_N_R(2, d, RD, 2)
198BIT_N_R(2, e, RE, 3)
199BIT_N_R(2, h, RH, 4)
200BIT_N_R(2, l, RL, 5)
201BIT_N_R(2, a, RA, 7)
202
203BIT_N_R(3, b, RB, 0)
204BIT_N_R(3, c, RC, 1)
205BIT_N_R(3, d, RD, 2)
206BIT_N_R(3, e, RE, 3)
207BIT_N_R(3, h, RH, 4)
208BIT_N_R(3, l, RL, 5)
209BIT_N_R(3, a, RA, 7)
210
211BIT_N_R(4, b, RB, 0)
212BIT_N_R(4, c, RC, 1)
213BIT_N_R(4, d, RD, 2)
214BIT_N_R(4, e, RE, 3)
215BIT_N_R(4, h, RH, 4)
216BIT_N_R(4, l, RL, 5)
217BIT_N_R(4, a, RA, 7)
218
219BIT_N_R(5, b, RB, 0)
220BIT_N_R(5, c, RC, 1)
221BIT_N_R(5, d, RD, 2)
222BIT_N_R(5, e, RE, 3)
223BIT_N_R(5, h, RH, 4)
224BIT_N_R(5, l, RL, 5)
225BIT_N_R(5, a, RA, 7)
226
227BIT_N_R(6, b, RB, 0)
228BIT_N_R(6, c, RC, 1)
229BIT_N_R(6, d, RD, 2)
230BIT_N_R(6, e, RE, 3)
231BIT_N_R(6, h, RH, 4)
232BIT_N_R(6, l, RL, 5)
233BIT_N_R(6, a, RA, 7)
234
235BIT_N_R(7, b, RB, 0)
236BIT_N_R(7, c, RC, 1)
237BIT_N_R(7, d, RD, 2)
238BIT_N_R(7, e, RE, 3)
239BIT_N_R(7, h, RH, 4)
240BIT_N_R(7, l, RL, 5)
241BIT_N_R(7, a, RA, 7)
242
243BIT_N_IHL(0)
244BIT_N_IHL(1)
245BIT_N_IHL(2)
246BIT_N_IHL(3)
247BIT_N_IHL(4)
248BIT_N_IHL(5)
249BIT_N_IHL(6)
250BIT_N_IHL(7)
251
252#define RES(r, n) r &= ~(1 << n)
253
254#define RES_N_R(bn, rn, r, n) \
255OPDEF(res_ ## bn ## _ ## rn, 0x80+bn*8+n) \
256{ \
257 RES(r, bn); \
258 ENTIME(8); \
259}
260
261#define RES_N_IHL(bn) \
262OPDEF(res_ ## bn ## _ihl, 0x86+bn*8) \
263{ \
264 register byte btmp; \
265 btmp = READ(GHL); \
266 RES(btmp, bn); \
267 WRITE(GHL, btmp); \
268 ENTIME(15); \
269}
270
271
272RES_N_R(0, b, RB, 0)
273RES_N_R(0, c, RC, 1)
274RES_N_R(0, d, RD, 2)
275RES_N_R(0, e, RE, 3)
276RES_N_R(0, h, RH, 4)
277RES_N_R(0, l, RL, 5)
278RES_N_R(0, a, RA, 7)
279
280RES_N_R(1, b, RB, 0)
281RES_N_R(1, c, RC, 1)
282RES_N_R(1, d, RD, 2)
283RES_N_R(1, e, RE, 3)
284RES_N_R(1, h, RH, 4)
285RES_N_R(1, l, RL, 5)
286RES_N_R(1, a, RA, 7)
287
288RES_N_R(2, b, RB, 0)
289RES_N_R(2, c, RC, 1)
290RES_N_R(2, d, RD, 2)
291RES_N_R(2, e, RE, 3)
292RES_N_R(2, h, RH, 4)
293RES_N_R(2, l, RL, 5)
294RES_N_R(2, a, RA, 7)
295
296RES_N_R(3, b, RB, 0)
297RES_N_R(3, c, RC, 1)
298RES_N_R(3, d, RD, 2)
299RES_N_R(3, e, RE, 3)
300RES_N_R(3, h, RH, 4)
301RES_N_R(3, l, RL, 5)
302RES_N_R(3, a, RA, 7)
303
304RES_N_R(4, b, RB, 0)
305RES_N_R(4, c, RC, 1)
306RES_N_R(4, d, RD, 2)
307RES_N_R(4, e, RE, 3)
308RES_N_R(4, h, RH, 4)
309RES_N_R(4, l, RL, 5)
310RES_N_R(4, a, RA, 7)
311
312RES_N_R(5, b, RB, 0)
313RES_N_R(5, c, RC, 1)
314RES_N_R(5, d, RD, 2)
315RES_N_R(5, e, RE, 3)
316RES_N_R(5, h, RH, 4)
317RES_N_R(5, l, RL, 5)
318RES_N_R(5, a, RA, 7)
319
320RES_N_R(6, b, RB, 0)
321RES_N_R(6, c, RC, 1)
322RES_N_R(6, d, RD, 2)
323RES_N_R(6, e, RE, 3)
324RES_N_R(6, h, RH, 4)
325RES_N_R(6, l, RL, 5)
326RES_N_R(6, a, RA, 7)
327
328RES_N_R(7, b, RB, 0)
329RES_N_R(7, c, RC, 1)
330RES_N_R(7, d, RD, 2)
331RES_N_R(7, e, RE, 3)
332RES_N_R(7, h, RH, 4)
333RES_N_R(7, l, RL, 5)
334RES_N_R(7, a, RA, 7)
335
336RES_N_IHL(0)
337RES_N_IHL(1)
338RES_N_IHL(2)
339RES_N_IHL(3)
340RES_N_IHL(4)
341RES_N_IHL(5)
342RES_N_IHL(6)
343RES_N_IHL(7)
344
345
346#define SET(r, n) r |= (1 << n)
347
348#define SET_N_R(bn, rn, r, n) \
349OPDEF(set_ ## bn ## _ ## rn, 0xC0+bn*8+n) \
350{ \
351 SET(r, bn); \
352 ENTIME(8); \
353}
354
355#define SET_N_IHL(bn) \
356OPDEF(set_ ## bn ## _ihl, 0x86+bn*8) \
357{ \
358 register byte btmp; \
359 btmp = READ(GHL); \
360 SET(btmp, bn); \
361 WRITE(GHL, btmp); \
362 ENTIME(15); \
363}
364
365
366SET_N_R(0, b, RB, 0)
367SET_N_R(0, c, RC, 1)
368SET_N_R(0, d, RD, 2)
369SET_N_R(0, e, RE, 3)
370SET_N_R(0, h, RH, 4)
371SET_N_R(0, l, RL, 5)
372SET_N_R(0, a, RA, 7)
373
374SET_N_R(1, b, RB, 0)
375SET_N_R(1, c, RC, 1)
376SET_N_R(1, d, RD, 2)
377SET_N_R(1, e, RE, 3)
378SET_N_R(1, h, RH, 4)
379SET_N_R(1, l, RL, 5)
380SET_N_R(1, a, RA, 7)
381
382SET_N_R(2, b, RB, 0)
383SET_N_R(2, c, RC, 1)
384SET_N_R(2, d, RD, 2)
385SET_N_R(2, e, RE, 3)
386SET_N_R(2, h, RH, 4)
387SET_N_R(2, l, RL, 5)
388SET_N_R(2, a, RA, 7)
389
390SET_N_R(3, b, RB, 0)
391SET_N_R(3, c, RC, 1)
392SET_N_R(3, d, RD, 2)
393SET_N_R(3, e, RE, 3)
394SET_N_R(3, h, RH, 4)
395SET_N_R(3, l, RL, 5)
396SET_N_R(3, a, RA, 7)
397
398SET_N_R(4, b, RB, 0)
399SET_N_R(4, c, RC, 1)
400SET_N_R(4, d, RD, 2)
401SET_N_R(4, e, RE, 3)
402SET_N_R(4, h, RH, 4)
403SET_N_R(4, l, RL, 5)
404SET_N_R(4, a, RA, 7)
405
406SET_N_R(5, b, RB, 0)
407SET_N_R(5, c, RC, 1)
408SET_N_R(5, d, RD, 2)
409SET_N_R(5, e, RE, 3)
410SET_N_R(5, h, RH, 4)
411SET_N_R(5, l, RL, 5)
412SET_N_R(5, a, RA, 7)
413
414SET_N_R(6, b, RB, 0)
415SET_N_R(6, c, RC, 1)
416SET_N_R(6, d, RD, 2)
417SET_N_R(6, e, RE, 3)
418SET_N_R(6, h, RH, 4)
419SET_N_R(6, l, RL, 5)
420SET_N_R(6, a, RA, 7)
421
422SET_N_R(7, b, RB, 0)
423SET_N_R(7, c, RC, 1)
424SET_N_R(7, d, RD, 2)
425SET_N_R(7, e, RE, 3)
426SET_N_R(7, h, RH, 4)
427SET_N_R(7, l, RL, 5)
428SET_N_R(7, a, RA, 7)
429
430SET_N_IHL(0)
431SET_N_IHL(1)
432SET_N_IHL(2)
433SET_N_IHL(3)
434SET_N_IHL(4)
435SET_N_IHL(5)
436SET_N_IHL(6)
437SET_N_IHL(7)