struct / union in initializer, RFE #901.
[sdcc.git] / sdcc-extra / emu / rrz80 / cpu / z80_op5.c
blobc0d617132af3927499a1eaaa3fe6a8f59a5b7c36
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 #ifdef DEBUG_Z80
27 #include <stdio.h>
28 #endif
30 OPDEF(ill_ed, 0x00)
32 #ifdef DEBUG_Z80
33 printf("ILL_ED: %04X - %02X\n", (dbyte) (PC-1), DANM(mem)[(dbyte) (PC-1)]);
34 #endif
36 ENTIME(8);
39 #define IN_R_IC(rn, r, n) \
40 OPDEF(in_ ## rn ## _ic, 0x40+8*n) \
41 { \
42 register byte res, flag; \
43 IN(RB, RC, res); \
44 r = res; \
45 flag = (RF & ~(ABUTCF)) | \
46 TAB(orf_tbl)[res]; \
47 RF = flag; \
48 ENTIME(12); \
51 IN_R_IC(b, RB, 0)
52 IN_R_IC(c, RC, 1)
53 IN_R_IC(d, RD, 2)
54 IN_R_IC(e, RE, 3)
55 IN_R_IC(h, RH, 4)
56 IN_R_IC(l, RL, 5)
57 IN_R_IC(f, res, 6)
58 IN_R_IC(a, RA, 7)
61 #define OUT_IC_R(rn, r, n) \
62 OPDEF(out_ic_ ## rn, 0x41+8*n) \
63 { \
64 OUT(RB, RC, r); \
65 ENTIME(12); \
68 OUT_IC_R(b, RB, 0)
69 OUT_IC_R(c, RC, 1)
70 OUT_IC_R(d, RD, 2)
71 OUT_IC_R(e, RE, 3)
72 OUT_IC_R(h, RH, 4)
73 OUT_IC_R(l, RL, 5)
74 OUT_IC_R(0, 0, 6)
75 OUT_IC_R(a, RA, 7)
79 #define SBC_HL_RR(rrn, rr, n) \
80 OPDEF(sbc_hl_ ## rrn, 0x42+0x10*n) \
81 { \
82 register dbyte res; \
83 register int idx, flag; \
84 flag = RF; \
85 res = HL - rr - (flag & CF); \
86 idx = DIDXCALC(HL, rr, res); \
87 HL = res; \
88 flag = (RF & ~(ALLF)) | \
89 (TAB(subf_tbl)[idx] & ALLF); \
90 if(!res) flag |= ZF; \
91 RF = flag; \
92 ENTIME(15); \
95 SBC_HL_RR(bc, BC, 0)
96 SBC_HL_RR(de, DE, 1)
97 SBC_HL_RR(hl, HL, 2)
98 SBC_HL_RR(sp, SP, 3)
100 #define ADC_HL_RR(rrn, rr, n) \
101 OPDEF(adc_hl_ ## rrn, 0x4A+0x10*n) \
103 register dbyte res; \
104 register int idx, flag; \
105 flag = RF; \
106 res = HL + rr + (flag & CF); \
107 idx = DIDXCALC(HL, rr, res); \
108 HL = res; \
109 flag = (RF & ~(ALLF)) | \
110 (TAB(addf_tbl)[idx] & ALLF); \
111 if(!res) flag |= ZF; \
112 RF = flag; \
113 ENTIME(15); \
116 ADC_HL_RR(bc, BC, 0)
117 ADC_HL_RR(de, DE, 1)
118 ADC_HL_RR(hl, HL, 2)
119 ADC_HL_RR(sp, SP, 3)
123 #define LD_INN_RR(rrn, pf, rr, n) \
124 OPDEF(ld_inn_ ## rrn ## pf, 0x43+0x10*n) \
126 register dbyte dtmp; \
127 FETCHD(dtmp); \
128 DWRITE(dtmp, rr); \
129 ENTIME(20); \
133 LD_INN_RR(bc, , BC, 0)
134 LD_INN_RR(de, , DE, 1)
135 LD_INN_RR(hl, _ed, HL, 2)
136 LD_INN_RR(sp, , SP, 3)
139 #define LD_RR_INN(rrn, pf, rr, n) \
140 OPDEF(ld_## rrn ## _inn ## pf, 0x4B+0x10*n) \
142 register dbyte dtmp; \
143 FETCHD(dtmp); \
144 rr = DREAD(dtmp); \
145 ENTIME(20); \
149 LD_RR_INN(bc, , BC, 0)
150 LD_RR_INN(de, , DE, 1)
151 LD_RR_INN(hl, _ed, HL, 2)
152 LD_RR_INN(sp, , SP, 3)
154 OPDEF(neg, 0x44 0x4C 0x54 0x5C 0x64 0x6C 0x74 0x7C)
156 register byte res;
157 register int idx;
158 register int flag;
160 res = 0 - RA;
161 idx = IDXCALC(0, RA, res);
162 RA = res;
163 flag = (RF & ~(AALLF)) | TAB(subf_tbl)[idx];
164 if(!res) flag |= ZF;
165 RF = flag;
166 ENTIME(8);
169 OPDEF(retn, 0x45 0x55 0x5D 0x65 0x6D 0x75 0x7D)
171 DANM(iff1) = DANM(iff2);
172 POP(PC);
173 ENTIME(14);
177 OPDEF(reti, 0x4D)
179 POP(PC);
180 ENTIME(14);
183 OPDEF(im_0, 0x46 0x4E 0x56 0x5E)
185 DANM(it_mode) = 0;
186 ENTIME(8);
190 OPDEF(im_1, 0x56 0x76)
192 DANM(it_mode) = 1;
193 ENTIME(8);
197 OPDEF(im_2, 0x5E 0x7E)
199 DANM(it_mode) = 2;
200 ENTIME(8);
203 OPDEF(ld_i_a, 0x47)
205 RI = RA;
206 ENTIME(9);
209 OPDEF(ld_r_a, 0x4F)
211 DANM(rl7) = RA & 0x80;
212 RR = RA;
213 ENTIME(9);
216 OPDEF(ld_a_i, 0x57)
218 register int flag;
220 RA = RI;
221 flag = (RF & ~(BUTCF)) | (RA & SF);
222 if(!RA) flag |= ZF;
223 if(DANM(iff2)) flag |= PVF;
224 RF = flag;
226 ENTIME(9);
229 OPDEF(ld_a_r, 0x5F)
231 register int flag;
233 RA = (RR & 0x7F) | DANM(rl7);
234 flag = (RF & ~(BUTCF)) | (RA & SF);
235 if(!RA) flag |= ZF;
236 if(DANM(iff2)) flag |= PVF;
237 RF = flag;
239 ENTIME(9);
242 OPDEF(rrd, 0x67)
244 register dbyte dtmp;
246 dtmp = *HLP | (RA << 8);
247 RA = (RA & 0xF0) | (dtmp & 0x0F);
248 SETFLAGS(ABUTCF, TAB(orf_tbl)[RA]);
249 dtmp >>= 4;
250 PUTMEM(HL, HLP, (byte) dtmp);
252 ENTIME(18);
255 OPDEF(rld, 0x6F)
257 register dbyte dtmp;
259 dtmp = (*HLP << 4) | (RA & 0x0F);
260 RA = (RA & 0xF0) | ((dtmp >> 8) & 0x0F);
261 SETFLAGS(ABUTCF, TAB(orf_tbl)[RA]);
262 PUTMEM(HL, HLP, (byte) dtmp);
264 ENTIME(18);
267 #define NOREPEAT() \
268 if(BC) RF |= PVF; \
269 ENTIME(16)
271 #define LDREPEAT() \
272 if(BC) { \
273 RF |= PVF; \
274 PC-=2; \
275 ENTIME(21); \
277 else { \
278 ENTIME(16); \
282 #define LDID(dir) \
283 register byte res; \
284 res = *HLP; \
285 PUTMEM(DE, DEP, res); \
286 DE dir, HL dir; \
287 RF = RF & ~(HF | PVF | NF); \
288 BC--
290 OPDEF(ldi, 0xA0)
292 LDID(++);
293 NOREPEAT();
296 OPDEF(ldd, 0xA8)
298 LDID(--);
299 NOREPEAT();
302 OPDEF(ldir, 0xB0)
304 LDID(++);
305 LDREPEAT();
309 OPDEF(lddr, 0xB8)
311 LDID(--);
312 LDREPEAT();
315 #define CPREPEAT() \
316 if(res && BC) { \
317 RF |= PVF; \
318 PC-=2; \
319 ENTIME(21); \
321 else { \
322 ENTIME(16); \
325 #define CPID(dir) \
326 register byte res; \
327 register int idx; \
328 res = RA - *HLP; \
329 idx = IDXCALC(RA, *HLP, res); \
330 RF = (RF & ~BUTCF) | \
331 (TAB(subf_tbl)[idx] & \
332 (SF | HF | NF | B3F | B5F)); \
333 if(!res) RF |= ZF; \
334 HL dir; \
335 BC--
338 OPDEF(cpi, 0xA1)
340 CPID(++);
341 NOREPEAT();
345 OPDEF(cpd, 0xA9)
347 CPID(--);
348 NOREPEAT();
352 OPDEF(cpir, 0xB1)
354 CPID(++);
355 CPREPEAT();
358 OPDEF(cpdr, 0xB9)
360 CPID(--);
361 CPREPEAT();
364 #define IOREPEAT() \
365 if(RB) { \
366 PC-=2; \
367 ENTIME(21); \
369 else { \
370 ENTIME(16); \
374 #define INID(dir) \
375 register byte res; \
376 register int idx; \
377 res = RB - 1; \
378 idx = IDXCALC(RB, 1, res); \
379 RF = (RF & ~BUTCF) | \
380 (TAB(subf_tbl)[idx] & \
381 (SF | HF | PVF | NF | B3F | B5F)); \
382 if(!res) RF |= ZF; \
383 RB = res; \
384 IN(RB, RC, res); \
385 PUTMEM(HL, HLP, res); \
386 HL dir
389 OPDEF(ini, 0xA2)
391 INID(++);
392 ENTIME(16);
395 OPDEF(ind, 0xAA)
397 INID(--);
398 ENTIME(16);
401 OPDEF(inir, 0xB2)
403 INID(++);
404 IOREPEAT();
407 OPDEF(indr, 0xBA)
409 INID(--);
410 IOREPEAT();
415 #define OUTID(dir) \
416 register byte res; \
417 register int idx; \
418 res = RB - 1; \
419 idx = IDXCALC(RB, 1, res); \
420 RF = (RF & ~BUTCF) | \
421 (TAB(subf_tbl)[idx] & \
422 (SF | HF | PVF | NF )); \
423 if(!res) RF |= ZF; \
424 RB = res; \
425 OUT(RB, RC, *HLP); \
426 HL dir
430 OPDEF(outi, 0xA3)
432 OUTID(++);
433 ENTIME(16);
436 OPDEF(outd, 0xAB)
438 OUTID(--);
439 ENTIME(16);
443 OPDEF(otir, 0xB3)
445 OUTID(++);
446 IOREPEAT();
449 OPDEF(otdr, 0xBB)
451 OUTID(--);
452 IOREPEAT();