Add Boomshine to the games category
[kugel-rb.git] / apps / plugins / zxbox / z80_op5.c
blob3edea79e3d0b68e392c2f95c9841e14786686187
1 /*
2 * Copyright (C) 1996-1998 Szeredi Miklos
3 * Email: mszeredi@inf.bme.hu
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.
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.
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.
21 #ifndef NO_OPDEF
22 #include "z80_def.h"
23 #include "z80_op5.h"
24 #endif
26 OPDEF(ill_ed, 0x00)
28 #ifdef DEBUG_Z80
29 printf("ILL_ED: %04X - %02X\n", (dbyte) (PC-1), DANM(mem)[(dbyte) (PC-1)]);
30 #endif
32 ENTIME(8);
35 #define IN_R_IC(rn, r, n) \
36 OPDEF(in_ ## rn ## _ic, 0x40+8*n) \
37 { \
38 register byte res, flag; \
39 IN(RB, RC, res); \
40 r = res; \
41 flag = (RF & ~(ABUTCF)) | \
42 TAB(orf_tbl)[res]; \
43 RF = flag; \
44 ENTIME(12); \
47 IN_R_IC(b, RB, 0)
48 IN_R_IC(c, RC, 1)
49 IN_R_IC(d, RD, 2)
50 IN_R_IC(e, RE, 3)
51 IN_R_IC(h, RH, 4)
52 IN_R_IC(l, RL, 5)
53 IN_R_IC(f, res, 6)
54 IN_R_IC(a, RA, 7)
57 #define OUT_IC_R(rn, r, n) \
58 OPDEF(out_ic_ ## rn, 0x41+8*n) \
59 { \
60 OUT(RB, RC, r); \
61 ENTIME(12); \
64 OUT_IC_R(b, RB, 0)
65 OUT_IC_R(c, RC, 1)
66 OUT_IC_R(d, RD, 2)
67 OUT_IC_R(e, RE, 3)
68 OUT_IC_R(h, RH, 4)
69 OUT_IC_R(l, RL, 5)
70 OUT_IC_R(0, 0, 6)
71 OUT_IC_R(a, RA, 7)
75 #define SBC_HL_RR(rrn, rr, n) \
76 OPDEF(sbc_hl_ ## rrn, 0x42+0x10*n) \
77 { \
78 register dbyte res; \
79 register int idx, flag; \
80 flag = RF; \
81 res = HL - rr - (flag & CF); \
82 idx = DIDXCALC(HL, rr, res); \
83 HL = res; \
84 flag = (RF & ~(ALLF)) | \
85 (TAB(subf_tbl)[idx] & ALLF); \
86 if(!res) flag |= ZF; \
87 RF = flag; \
88 ENTIME(15); \
91 SBC_HL_RR(bc, BC, 0)
92 SBC_HL_RR(de, DE, 1)
93 SBC_HL_RR(hl, HL, 2)
94 SBC_HL_RR(sp, SP, 3)
96 #define ADC_HL_RR(rrn, rr, n) \
97 OPDEF(adc_hl_ ## rrn, 0x4A+0x10*n) \
98 { \
99 register dbyte res; \
100 register int idx, flag; \
101 flag = RF; \
102 res = HL + rr + (flag & CF); \
103 idx = DIDXCALC(HL, rr, res); \
104 HL = res; \
105 flag = (RF & ~(ALLF)) | \
106 (TAB(addf_tbl)[idx] & ALLF); \
107 if(!res) flag |= ZF; \
108 RF = flag; \
109 ENTIME(15); \
112 ADC_HL_RR(bc, BC, 0)
113 ADC_HL_RR(de, DE, 1)
114 ADC_HL_RR(hl, HL, 2)
115 ADC_HL_RR(sp, SP, 3)
119 #define LD_INN_RR(rrn, pf, rr, n) \
120 OPDEF(ld_inn_ ## rrn ## pf, 0x43+0x10*n) \
122 register dbyte dtmp; \
123 FETCHD(dtmp); \
124 DWRITE(dtmp, rr); \
125 ENTIME(20); \
129 LD_INN_RR(bc, , BC, 0)
130 LD_INN_RR(de, , DE, 1)
131 LD_INN_RR(hl, _ed, HL, 2)
132 LD_INN_RR(sp, , SP, 3)
135 #define LD_RR_INN(rrn, pf, rr, n) \
136 OPDEF(ld_## rrn ## _inn ## pf, 0x4B+0x10*n) \
138 register dbyte dtmp; \
139 FETCHD(dtmp); \
140 rr = DREAD(dtmp); \
141 ENTIME(20); \
145 LD_RR_INN(bc, , BC, 0)
146 LD_RR_INN(de, , DE, 1)
147 LD_RR_INN(hl, _ed, HL, 2)
148 LD_RR_INN(sp, , SP, 3)
150 OPDEF(neg, 0x44 0x4C 0x54 0x5C 0x64 0x6C 0x74 0x7C)
152 register byte res;
153 register int idx;
154 register int flag;
156 res = 0 - RA;
157 idx = IDXCALC(0, RA, res);
158 RA = res;
159 flag = (RF & ~(AALLF)) | TAB(subf_tbl)[idx];
160 if(!res) flag |= ZF;
161 RF = flag;
162 ENTIME(8);
165 OPDEF(retn, 0x45 0x55 0x5D 0x65 0x6D 0x75 0x7D)
167 DANM(iff1) = DANM(iff2);
168 POP(PC);
169 ENTIME(14);
173 OPDEF(reti, 0x4D)
175 POP(PC);
176 ENTIME(14);
179 OPDEF(im_0, 0x46 0x4E 0x56 0x5E)
181 DANM(it_mode) = 0;
182 ENTIME(8);
186 OPDEF(im_1, 0x56 0x76)
188 DANM(it_mode) = 1;
189 ENTIME(8);
193 OPDEF(im_2, 0x5E 0x7E)
195 DANM(it_mode) = 2;
196 ENTIME(8);
199 OPDEF(ld_i_a, 0x47)
201 RI = RA;
202 ENTIME(9);
205 OPDEF(ld_r_a, 0x4F)
207 DANM(rl7) = RA & 0x80;
208 RR = RA;
209 ENTIME(9);
212 OPDEF(ld_a_i, 0x57)
214 register int flag;
216 RA = RI;
217 flag = (RF & ~(BUTCF)) | (RA & SF);
218 if(!RA) flag |= ZF;
219 if(DANM(iff2)) flag |= PVF;
220 RF = flag;
222 ENTIME(9);
225 OPDEF(ld_a_r, 0x5F)
227 register int flag;
229 RA = (RR & 0x7F) | DANM(rl7);
230 flag = (RF & ~(BUTCF)) | (RA & SF);
231 if(!RA) flag |= ZF;
232 if(DANM(iff2)) flag |= PVF;
233 RF = flag;
235 ENTIME(9);
238 OPDEF(rrd, 0x67)
240 register dbyte dtmp;
242 dtmp = *HLP | (RA << 8);
243 RA = (RA & 0xF0) | (dtmp & 0x0F);
244 SETFLAGS(ABUTCF, TAB(orf_tbl)[RA]);
245 dtmp >>= 4;
246 PUTMEM(HL, HLP, (byte) dtmp);
248 ENTIME(18);
251 OPDEF(rld, 0x6F)
253 register dbyte dtmp;
255 dtmp = (*HLP << 4) | (RA & 0x0F);
256 RA = (RA & 0xF0) | ((dtmp >> 8) & 0x0F);
257 SETFLAGS(ABUTCF, TAB(orf_tbl)[RA]);
258 PUTMEM(HL, HLP, (byte) dtmp);
260 ENTIME(18);
263 #define NOREPEAT() \
264 if(BC) RF |= PVF; \
265 ENTIME(16)
267 #define LDREPEAT() \
268 if(BC) { \
269 RF |= PVF; \
270 PC-=2; \
271 ENTIME(21); \
273 else { \
274 ENTIME(16); \
278 #define LDID(dir) \
279 register byte res; \
280 res = *HLP; \
281 PUTMEM(DE, DEP, res); \
282 DE dir, HL dir; \
283 RF = RF & ~(HF | PVF | NF); \
284 BC--
286 OPDEF(ldi, 0xA0)
288 LDID(++);
289 NOREPEAT();
292 OPDEF(ldd, 0xA8)
294 LDID(--);
295 NOREPEAT();
298 OPDEF(ldir, 0xB0)
300 LDID(++);
301 LDREPEAT();
305 OPDEF(lddr, 0xB8)
307 LDID(--);
308 LDREPEAT();
311 #define CPREPEAT() \
312 if(res && BC) { \
313 RF |= PVF; \
314 PC-=2; \
315 ENTIME(21); \
317 else { \
318 ENTIME(16); \
321 #define CPID(dir) \
322 register byte res; \
323 register int idx; \
324 res = RA - *HLP; \
325 idx = IDXCALC(RA, *HLP, res); \
326 RF = (RF & ~BUTCF) | \
327 (TAB(subf_tbl)[idx] & \
328 (SF | HF | NF | B3F | B5F)); \
329 if(!res) RF |= ZF; \
330 HL dir; \
331 BC--
334 OPDEF(cpi, 0xA1)
336 CPID(++);
337 NOREPEAT();
341 OPDEF(cpd, 0xA9)
343 CPID(--);
344 NOREPEAT();
348 OPDEF(cpir, 0xB1)
350 CPID(++);
351 CPREPEAT();
354 OPDEF(cpdr, 0xB9)
356 CPID(--);
357 CPREPEAT();
360 #define IOREPEAT() \
361 if(RB) { \
362 PC-=2; \
363 ENTIME(21); \
365 else { \
366 ENTIME(16); \
370 #define INID(dir) \
371 register byte res; \
372 register int idx; \
373 res = RB - 1; \
374 idx = IDXCALC(RB, 1, res); \
375 RF = (RF & ~BUTCF) | \
376 (TAB(subf_tbl)[idx] & \
377 (SF | HF | PVF | NF | B3F | B5F)); \
378 if(!res) RF |= ZF; \
379 RB = res; \
380 IN(RB, RC, res); \
381 PUTMEM(HL, HLP, res); \
382 HL dir
385 OPDEF(ini, 0xA2)
387 INID(++);
388 ENTIME(16);
391 OPDEF(ind, 0xAA)
393 INID(--);
394 ENTIME(16);
397 OPDEF(inir, 0xB2)
399 INID(++);
400 IOREPEAT();
403 OPDEF(indr, 0xBA)
405 INID(--);
406 IOREPEAT();
411 #define OUTID(dir) \
412 register byte res; \
413 register int idx; \
414 res = RB - 1; \
415 idx = IDXCALC(RB, 1, res); \
416 RF = (RF & ~BUTCF) | \
417 (TAB(subf_tbl)[idx] & \
418 (SF | HF | PVF | NF )); \
419 if(!res) RF |= ZF; \
420 RB = res; \
421 OUT(RB, RC, *HLP); \
422 HL dir
426 OPDEF(outi, 0xA3)
428 OUTID(++);
429 ENTIME(16);
432 OPDEF(outd, 0xAB)
434 OUTID(--);
435 ENTIME(16);
439 OPDEF(otir, 0xB3)
441 OUTID(++);
442 IOREPEAT();
445 OPDEF(otdr, 0xBB)
447 OUTID(--);
448 IOREPEAT();