1 /* Z80 instruction set simulator.
2 Copyright (C) 1995 Frank D. Cringle.
3
4 This file is part of yaze - yet another Z80 emulator.
5
6 Yaze is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 /* This file was generated from simz80.pl
21 with the following choice of options */
22 /*
23 char *perl_params =
24 "combine=0,"
25 "optab=0,"
26 "cb_inline=1,"
27 "dfd_inline=1,"
28 "ed_inline=1";
29 */
30
31 #include <stdio.h>
32 /* #include <stdbool.h> */
33 #include "mem_mmu.h"
34 #include "simz80.h"
35 #include "ytypes.h"
36
37 static const unsigned char partab[256] = {
38 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
39 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
40 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
41 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
42 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
43 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
44 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
45 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
46 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
47 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
48 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
49 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
50 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
51 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
52 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
53 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
54 };
55
56 extern bool rtc_avail;
57 extern ui32 sim_os_msec();
58 extern ui32 sim_os_ms_sleep(unsigned int milliseconds);
59
60 #define parity(x) partab[(x)&0xff]
61
62 #ifdef DEBUG
63 volatile int stopsim;
64 #endif
65
66 #define POP(x) do { \
67 FASTREG y = RAM_pp(SP); \
68 x = y + (RAM_pp(SP) << 8); \
69 } while (0)
70
71 #define PUSH(x) do { \
72 mm_RAM(SP) = (x) >> 8; \
73 mm_RAM(SP) = x; \
74 } while (0)
75
76 #define JPC(cond) { tStates += 10; PC = cond ? GetWORD(PC) : PC+2; }
77
78 #define CALLC(cond) { \
79 if (cond) { \
80 FASTREG adrr = GetWORD(PC); \
81 PUSH(PC+2); \
82 PC = adrr; \
83 tStates += 17; \
84 } else { \
85 PC += 2; \
86 tStates += 10; \
87 } \
88 }
89
90 /* load Z80 registers into (we hope) host registers */
91 #define LOAD_STATE() \
92 PC = pc; \
93 AF = af[af_sel]; \
94 BC = regs[regs_sel].bc; \
95 DE = regs[regs_sel].de; \
96 HL = regs[regs_sel].hl; \
97 IX = ix; \
98 IY = iy; \
99 SP = sp
100
101 /* load Z80 registers into (we hope) host registers */
102 #define DECLARE_STATE() \
103 FASTREG PC = pc; \
104 FASTREG AF = af[af_sel]; \
105 FASTREG BC = regs[regs_sel].bc; \
106 FASTREG DE = regs[regs_sel].de; \
107 FASTREG HL = regs[regs_sel].hl; \
108 FASTREG IX = ix; \
109 FASTREG IY = iy; \
110 FASTREG SP = sp
111
112 /* save Z80 registers back into memory */
113 #define SAVE_STATE() \
114 pc = PC; \
115 af[af_sel] = AF; \
116 regs[regs_sel].bc = BC; \
117 regs[regs_sel].de = DE; \
118 regs[regs_sel].hl = HL; \
119 ix = IX; \
120 iy = IY; \
121 sp = SP; \
122 tStates_save = tStates; \
123 tStatesInSlice_save = tStatesInSlice; \
124 startTime_save = startTime; \
125 clockFrequency_save = clockFrequency;
126
127 FASTWORK
simz80_with_tStates(FASTREG PC)128 simz80_with_tStates(FASTREG PC)
129 {
130 FASTREG AF = af[af_sel];
131 FASTREG BC = regs[regs_sel].bc;
132 FASTREG DE = regs[regs_sel].de;
133 FASTREG HL = regs[regs_sel].hl;
134 FASTREG SP = sp;
135 FASTREG IX = ix;
136 FASTREG IY = iy;
137 FASTWORK temp, acu, sum, cbits;
138 FASTWORK op, adr;
139 #ifdef MMU
140 FASTREG tmp2;
141 #endif
142
143 register FASTREG tStates = tStates_save;
144 register FASTREG tStatesInSlice = tStatesInSlice_save;
145 /* number of t-states in 10 mSec time-slice */
146 FASTREG startTime = startTime_save;
147 FASTREG now;
148 register FASTREG clockFrequency = clockFrequency_save;
149 /* in kHz --> for example 4000 kHz */
150 static const FASTREG sliceLength = 10; /* 10 msec */
151 bool tStateModifier = false;
152
153 if ((sim_os_msec()) >= startTime) {
154 tStates = 0;
155 /* putchar('m'); fflush(stdout); */
156 startTime = sim_os_msec();
157 }
158
159 /* initialization of the brake */
160 if (brakeini) {
161 brakeini = false;
162 tStates = 0;
163 if (rtc_avail) {
164 tStatesInSlice = sliceLength * clockFrequency;
165 /* printf("In brackeIni! %d\r\n",tStatesInSlice); */
166 startTime = clockFrequency ? sim_os_msec() : 0;
167 } else {/* make sure that sim_os_msec() is not called later */
168 clockFrequency = startTime = tStatesInSlice = 0;
169 }
170 }
171
172
173
174 #ifdef DEBUG
175 while (!stopsim) {
176 #else
177 while (1) {
178 #endif
179
180 /* the brake */
181 if (clockFrequency && (tStates >= tStatesInSlice)) {
182 /* clockFrequency != 0 implies that real time clock is available */
183 startTime += sliceLength;
184 tStates -= tStatesInSlice;
185 if (startTime > (now = sim_os_msec())) {
186 sim_os_ms_sleep(startTime - now);
187 /* putchar('.'); fflush(stdout); */
188 }
189 }
190
191
192 switch(RAM_pp(PC)) {
193 case 0x00: /* NOP */
194 tStates += 4; /* 4 */
195 break;
196 case 0x01: /* LD BC,nnnn */
197 tStates += 10;
198 BC = GetWORD(PC);
199 PC += 2;
200 break;
201 case 0x02: /* LD (BC),A */
202 tStates += 7;
203 PutBYTE(BC, hreg(AF));
204 break;
205 case 0x03: /* INC BC */
206 tStates += 6;
207 ++BC;
208 break;
209 case 0x04: /* INC B */
210 tStates += 4;
211 BC += 0x100;
212 temp = hreg(BC);
213 AF = (AF & ~0xfe) | (temp & 0xa8) |
214 (((temp & 0xff) == 0) << 6) |
215 (((temp & 0xf) == 0) << 4) |
216 ((temp == 0x80) << 2);
217 break;
218 case 0x05: /* DEC B */
219 tStates += 4;
220 BC -= 0x100;
221 temp = hreg(BC);
222 AF = (AF & ~0xfe) | (temp & 0xa8) |
223 (((temp & 0xff) == 0) << 6) |
224 (((temp & 0xf) == 0xf) << 4) |
225 ((temp == 0x7f) << 2) | 2;
226 break;
227 case 0x06: /* LD B,nn */
228 tStates += 7;
229 Sethreg(BC, GetBYTE_pp(PC));
230 break;
231 case 0x07: /* RLCA */
232 tStates += 4;
233 AF = ((AF >> 7) & 0x0128) | ((AF << 1) & ~0x1ff) |
234 (AF & 0xc4) | ((AF >> 15) & 1);
235 break;
236 case 0x08: /* EX AF,AF' */
237 tStates += 4;
238 af[af_sel] = AF;
239 af_sel = 1 - af_sel;
240 AF = af[af_sel];
241 break;
242 case 0x09: /* ADD HL,BC */
243 tStates += 11;
244 HL &= 0xffff;
245 BC &= 0xffff;
246 sum = HL + BC;
247 cbits = (HL ^ BC ^ sum) >> 8;
248 HL = sum;
249 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
250 (cbits & 0x10) | ((cbits >> 8) & 1);
251 break;
252 case 0x0A: /* LD A,(BC) */
253 tStates += 7;
254 Sethreg(AF, GetBYTE(BC));
255 break;
256 case 0x0B: /* DEC BC */
257 tStates += 6;
258 --BC;
259 break;
260 case 0x0C: /* INC C */
261 tStates += 4;
262 temp = lreg(BC)+1;
263 Setlreg(BC, temp);
264 AF = (AF & ~0xfe) | (temp & 0xa8) |
265 (((temp & 0xff) == 0) << 6) |
266 (((temp & 0xf) == 0) << 4) |
267 ((temp == 0x80) << 2);
268 break;
269 case 0x0D: /* DEC C */
270 tStates += 4;
271 temp = lreg(BC)-1;
272 Setlreg(BC, temp);
273 AF = (AF & ~0xfe) | (temp & 0xa8) |
274 (((temp & 0xff) == 0) << 6) |
275 (((temp & 0xf) == 0xf) << 4) |
276 ((temp == 0x7f) << 2) | 2;
277 break;
278 case 0x0E: /* LD C,nn */
279 tStates += 7;
280 Setlreg(BC, GetBYTE_pp(PC));
281 break;
282 case 0x0F: /* RRCA */
283 tStates += 4;
284 temp = hreg(AF);
285 sum = temp >> 1;
286 AF = ((temp & 1) << 15) | (sum << 8) |
287 (sum & 0x28) | (AF & 0xc4) | (temp & 1);
288 break;
289 case 0x10: /* DJNZ dd */
290 /* urspr�ngliche Zeile:
291 PC += ((BC -= 0x100) & 0xff00) ? (signed char) GetBYTE(PC) + 1 : 1;
292 */
293 if ((BC -= 0x100) & 0xff00) {
294 PC += (signed char) GetBYTE(PC) + 1;
295 tStates += 13;
296 } else {
297 PC++;
298 tStates += 8;
299 }
300 break;
301 case 0x11: /* LD DE,nnnn */
302 tStates += 10;
303 DE = GetWORD(PC);
304 PC += 2;
305 break;
306 case 0x12: /* LD (DE),A */
307 tStates += 7;
308 PutBYTE(DE, hreg(AF));
309 break;
310 case 0x13: /* INC DE */
311 tStates += 6;
312 ++DE;
313 break;
314 case 0x14: /* INC D */
315 tStates += 4;
316 DE += 0x100;
317 temp = hreg(DE);
318 AF = (AF & ~0xfe) | (temp & 0xa8) |
319 (((temp & 0xff) == 0) << 6) |
320 (((temp & 0xf) == 0) << 4) |
321 ((temp == 0x80) << 2);
322 break;
323 case 0x15: /* DEC D */
324 tStates += 4;
325 DE -= 0x100;
326 temp = hreg(DE);
327 AF = (AF & ~0xfe) | (temp & 0xa8) |
328 (((temp & 0xff) == 0) << 6) |
329 (((temp & 0xf) == 0xf) << 4) |
330 ((temp == 0x7f) << 2) | 2;
331 break;
332 case 0x16: /* LD D,nn */
333 tStates += 7;
334 Sethreg(DE, GetBYTE_pp(PC));
335 break;
336 case 0x17: /* RLA */
337 tStates += 4;
338 AF = ((AF << 8) & 0x0100) | ((AF >> 7) & 0x28) | ((AF << 1) & ~0x01ff) |
339 (AF & 0xc4) | ((AF >> 15) & 1);
340 break;
341 case 0x18: /* JR dd */
342 tStates += 12;
343 PC += (1) ? (signed char) GetBYTE(PC) + 1 : 1;
344 break;
345 case 0x19: /* ADD HL,DE */
346 tStates += 11;
347 HL &= 0xffff;
348 DE &= 0xffff;
349 sum = HL + DE;
350 cbits = (HL ^ DE ^ sum) >> 8;
351 HL = sum;
352 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
353 (cbits & 0x10) | ((cbits >> 8) & 1);
354 break;
355 case 0x1A: /* LD A,(DE) */
356 tStates += 4;
357 Sethreg(AF, GetBYTE(DE));
358 break;
359 case 0x1B: /* DEC DE */
360 tStates += 6;
361 --DE;
362 break;
363 case 0x1C: /* INC E */
364 tStates += 4;
365 temp = lreg(DE)+1;
366 Setlreg(DE, temp);
367 AF = (AF & ~0xfe) | (temp & 0xa8) |
368 (((temp & 0xff) == 0) << 6) |
369 (((temp & 0xf) == 0) << 4) |
370 ((temp == 0x80) << 2);
371 break;
372 case 0x1D: /* DEC E */
373 tStates += 4;
374 temp = lreg(DE)-1;
375 Setlreg(DE, temp);
376 AF = (AF & ~0xfe) | (temp & 0xa8) |
377 (((temp & 0xff) == 0) << 6) |
378 (((temp & 0xf) == 0xf) << 4) |
379 ((temp == 0x7f) << 2) | 2;
380 break;
381 case 0x1E: /* LD E,nn */
382 tStates += 7;
383 Setlreg(DE, GetBYTE_pp(PC));
384 break;
385 case 0x1F: /* RRA */
386 tStates += 4;
387 temp = hreg(AF);
388 sum = temp >> 1;
389 AF = ((AF & 1) << 15) | (sum << 8) |
390 (sum & 0x28) | (AF & 0xc4) | (temp & 1);
391 break;
392 case 0x20: /* JR NZ,dd */
393 /* PC += (!TSTFLAG(Z)) ? (signed char) GetBYTE(PC) + 1 : 1; */
394 if (TSTFLAG(Z)) {
395 PC++;
396 tStates += 7;
397 } else {
398 PC += (signed char) GetBYTE(PC) + 1;
399 tStates += 12;
400 }
401 break;
402 case 0x21: /* LD HL,nnnn */
403 tStates += 10;
404 HL = GetWORD(PC);
405 PC += 2;
406 break;
407 case 0x22: /* LD (nnnn),HL */
408 tStates += 16;
409 temp = GetWORD(PC);
410 PutWORD(temp, HL);
411 PC += 2;
412 break;
413 case 0x23: /* INC HL */
414 tStates += 6;
415 ++HL;
416 break;
417 case 0x24: /* INC H */
418 tStates += 4;
419 HL += 0x100;
420 temp = hreg(HL);
421 AF = (AF & ~0xfe) | (temp & 0xa8) |
422 (((temp & 0xff) == 0) << 6) |
423 (((temp & 0xf) == 0) << 4) |
424 ((temp == 0x80) << 2);
425 break;
426 case 0x25: /* DEC H */
427 tStates += 4;
428 HL -= 0x100;
429 temp = hreg(HL);
430 AF = (AF & ~0xfe) | (temp & 0xa8) |
431 (((temp & 0xff) == 0) << 6) |
432 (((temp & 0xf) == 0xf) << 4) |
433 ((temp == 0x7f) << 2) | 2;
434 break;
435 case 0x26: /* LD H,nn */
436 tStates += 7;
437 Sethreg(HL, GetBYTE_pp(PC));
438 break;
439 case 0x27: /* DAA */
440 tStates += 4;
441 acu = hreg(AF);
442 temp = ldig(acu);
443 cbits = TSTFLAG(C);
444 if (TSTFLAG(N)) { /* last operation was a subtract */
445 int hd = cbits || acu > 0x99;
446 if (TSTFLAG(H) || (temp > 9)) { /* adjust low digit */
447 if (temp > 5)
448 SETFLAG(H, 0);
449 acu -= 6;
450 acu &= 0xff;
451 }
452 if (hd) /* adjust high digit */
453 acu -= 0x160;
454 }
455 else { /* last operation was an add */
456 if (TSTFLAG(H) || (temp > 9)) { /* adjust low digit */
457 SETFLAG(H, (temp > 9));
458 acu += 6;
459 }
460 if (cbits || ((acu & 0x1f0) > 0x90)) /* adjust high digit */
461 acu += 0x60;
462 }
463 cbits |= (acu >> 8) & 1;
464 acu &= 0xff;
465 AF = (acu << 8) | (acu & 0xa8) | ((acu == 0) << 6) |
466 (AF & 0x12) | partab[acu] | cbits;
467 break;
468 case 0x28: /* JR Z,dd */
469 PC += (TSTFLAG(Z)) ? (tStates += 12,(signed char) GetBYTE(PC) + 1)
470 : (tStates += 7, 1);
471 /*
472 if (TSTFLAG(Z)) {
473 PC += (signed char) GetBYTE(PC) + 1;
474 tStates += 12;
475 } else {
476 PC++;
477 tStates += 7;
478 }
479 */
480 break;
481 case 0x29: /* ADD HL,HL */
482 tStates += 11;
483 HL &= 0xffff;
484 sum = HL + HL;
485 cbits = (HL ^ HL ^ sum) >> 8;
486 HL = sum;
487 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
488 (cbits & 0x10) | ((cbits >> 8) & 1);
489 break;
490 case 0x2A: /* LD HL,(nnnn) */
491 tStates += 16;
492 temp = GetWORD(PC);
493 HL = GetWORD(temp);
494 PC += 2;
495 break;
496 case 0x2B: /* DEC HL */
497 tStates += 6;
498 --HL;
499 break;
500 case 0x2C: /* INC L */
501 tStates += 4;
502 temp = lreg(HL)+1;
503 Setlreg(HL, temp);
504 AF = (AF & ~0xfe) | (temp & 0xa8) |
505 (((temp & 0xff) == 0) << 6) |
506 (((temp & 0xf) == 0) << 4) |
507 ((temp == 0x80) << 2);
508 break;
509 case 0x2D: /* DEC L */
510 tStates += 4;
511 temp = lreg(HL)-1;
512 Setlreg(HL, temp);
513 AF = (AF & ~0xfe) | (temp & 0xa8) |
514 (((temp & 0xff) == 0) << 6) |
515 (((temp & 0xf) == 0xf) << 4) |
516 ((temp == 0x7f) << 2) | 2;
517 break;
518 case 0x2E: /* LD L,nn */
519 tStates += 7;
520 Setlreg(HL, GetBYTE_pp(PC));
521 break;
522 case 0x2F: /* CPL */
523 tStates += 4;
524 AF = (~AF & ~0xff) | (AF & 0xc5) | ((~AF >> 8) & 0x28) | 0x12;
525 break;
526 case 0x30: /* JR NC,dd */
527 PC += (!TSTFLAG(C)) ? (tStates += 12,(signed char) GetBYTE(PC) + 1)
528 : (tStates += 7, 1);
529 break;
530 case 0x31: /* LD SP,nnnn */
531 tStates += 10;
532 SP = GetWORD(PC);
533 PC += 2;
534 break;
535 case 0x32: /* LD (nnnn),A */
536 tStates += 13;
537 temp = GetWORD(PC);
538 PutBYTE(temp, hreg(AF));
539 PC += 2;
540 break;
541 case 0x33: /* INC SP */
542 tStates += 6;
543 ++SP;
544 break;
545 case 0x34: /* INC (HL) */
546 tStates += 11;
547 temp = GetBYTE(HL)+1;
548 PutBYTE(HL, temp);
549 AF = (AF & ~0xfe) | (temp & 0xa8) |
550 (((temp & 0xff) == 0) << 6) |
551 (((temp & 0xf) == 0) << 4) |
552 ((temp == 0x80) << 2);
553 break;
554 case 0x35: /* DEC (HL) */
555 tStates += 11;
556 temp = GetBYTE(HL)-1;
557 PutBYTE(HL, temp);
558 AF = (AF & ~0xfe) | (temp & 0xa8) |
559 (((temp & 0xff) == 0) << 6) |
560 (((temp & 0xf) == 0xf) << 4) |
561 ((temp == 0x7f) << 2) | 2;
562 break;
563 case 0x36: /* LD (HL),nn */
564 tStates += 10;
565 PutBYTE(HL, GetBYTE_pp(PC));
566 break;
567 case 0x37: /* SCF */
568 tStates += 4;
569 AF = (AF&~0x3b)|((AF>>8)&0x28)|1;
570 break;
571 case 0x38: /* JR C,dd */
572 PC += (TSTFLAG(C)) ? (tStates +=12, (signed char) GetBYTE(PC) + 1)
573 : (tStates += 7, 1);
574 break;
575 case 0x39: /* ADD HL,SP */
576 tStates += 11;
577 HL &= 0xffff;
578 SP &= 0xffff;
579 sum = HL + SP;
580 cbits = (HL ^ SP ^ sum) >> 8;
581 HL = sum;
582 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
583 (cbits & 0x10) | ((cbits >> 8) & 1);
584 break;
585 case 0x3A: /* LD A,(nnnn) */
586 tStates += 13;
587 temp = GetWORD(PC);
588 Sethreg(AF, GetBYTE(temp));
589 PC += 2;
590 break;
591 case 0x3B: /* DEC SP */
592 tStates += 6;
593 --SP;
594 break;
595 case 0x3C: /* INC A */
596 tStates += 4;
597 AF += 0x100;
598 temp = hreg(AF);
599 AF = (AF & ~0xfe) | (temp & 0xa8) |
600 (((temp & 0xff) == 0) << 6) |
601 (((temp & 0xf) == 0) << 4) |
602 ((temp == 0x80) << 2);
603 break;
604 case 0x3D: /* DEC A */
605 tStates += 4;
606 AF -= 0x100;
607 temp = hreg(AF);
608 AF = (AF & ~0xfe) | (temp & 0xa8) |
609 (((temp & 0xff) == 0) << 6) |
610 (((temp & 0xf) == 0xf) << 4) |
611 ((temp == 0x7f) << 2) | 2;
612 break;
613 case 0x3E: /* LD A,nn */
614 tStates += 7;
615 Sethreg(AF, GetBYTE_pp(PC));
616 break;
617 case 0x3F: /* CCF */
618 tStates += 4;
619 AF = (AF&~0x3b)|((AF>>8)&0x28)|((AF&1)<<4)|(~AF&1);
620 break;
621 case 0x40: /* LD B,B */
622 /* nop */
623 tStates += 4;
624 break;
625 case 0x41: /* LD B,C */
626 tStates += 4;
627 BC = (BC & 255) | ((BC & 255) << 8);
628 break;
629 case 0x42: /* LD B,D */
630 tStates += 4;
631 BC = (BC & 255) | (DE & ~255);
632 break;
633 case 0x43: /* LD B,E */
634 tStates += 4;
635 BC = (BC & 255) | ((DE & 255) << 8);
636 break;
637 case 0x44: /* LD B,H */
638 tStates += 4;
639 BC = (BC & 255) | (HL & ~255);
640 break;
641 case 0x45: /* LD B,L */
642 tStates += 4;
643 BC = (BC & 255) | ((HL & 255) << 8);
644 break;
645 case 0x46: /* LD B,(HL) */
646 tStates += 7;
647 Sethreg(BC, GetBYTE(HL));
648 break;
649 case 0x47: /* LD B,A */
650 tStates += 4;
651 BC = (BC & 255) | (AF & ~255);
652 break;
653 case 0x48: /* LD C,B */
654 tStates += 4;
655 BC = (BC & ~255) | ((BC >> 8) & 255);
656 break;
657 case 0x49: /* LD C,C */
658 tStates += 4;
659 /* nop */
660 break;
661 case 0x4A: /* LD C,D */
662 tStates += 4;
663 BC = (BC & ~255) | ((DE >> 8) & 255);
664 break;
665 case 0x4B: /* LD C,E */
666 tStates += 4;
667 BC = (BC & ~255) | (DE & 255);
668 break;
669 case 0x4C: /* LD C,H */
670 tStates += 4;
671 BC = (BC & ~255) | ((HL >> 8) & 255);
672 break;
673 case 0x4D: /* LD C,L */
674 tStates += 4;
675 BC = (BC & ~255) | (HL & 255);
676 break;
677 case 0x4E: /* LD C,(HL) */
678 tStates += 7;
679 Setlreg(BC, GetBYTE(HL));
680 break;
681 case 0x4F: /* LD C,A */
682 tStates += 4;
683 BC = (BC & ~255) | ((AF >> 8) & 255);
684 break;
685 case 0x50: /* LD D,B */
686 tStates += 4;
687 DE = (DE & 255) | (BC & ~255);
688 break;
689 case 0x51: /* LD D,C */
690 tStates += 4;
691 DE = (DE & 255) | ((BC & 255) << 8);
692 break;
693 case 0x52: /* LD D,D */
694 tStates += 4;
695 /* nop */
696 break;
697 case 0x53: /* LD D,E */
698 tStates += 4;
699 DE = (DE & 255) | ((DE & 255) << 8);
700 break;
701 case 0x54: /* LD D,H */
702 tStates += 4;
703 DE = (DE & 255) | (HL & ~255);
704 break;
705 case 0x55: /* LD D,L */
706 tStates += 4;
707 DE = (DE & 255) | ((HL & 255) << 8);
708 break;
709 case 0x56: /* LD D,(HL) */
710 tStates += 7;
711 Sethreg(DE, GetBYTE(HL));
712 break;
713 case 0x57: /* LD D,A */
714 tStates += 4;
715 DE = (DE & 255) | (AF & ~255);
716 break;
717 case 0x58: /* LD E,B */
718 tStates += 4;
719 DE = (DE & ~255) | ((BC >> 8) & 255);
720 break;
721 case 0x59: /* LD E,C */
722 tStates += 4;
723 DE = (DE & ~255) | (BC & 255);
724 break;
725 case 0x5A: /* LD E,D */
726 tStates += 4;
727 DE = (DE & ~255) | ((DE >> 8) & 255);
728 break;
729 case 0x5B: /* LD E,E */
730 tStates += 4;
731 /* nop */
732 break;
733 case 0x5C: /* LD E,H */
734 tStates += 4;
735 DE = (DE & ~255) | ((HL >> 8) & 255);
736 break;
737 case 0x5D: /* LD E,L */
738 tStates += 4;
739 DE = (DE & ~255) | (HL & 255);
740 break;
741 case 0x5E: /* LD E,(HL) */
742 tStates += 7;
743 Setlreg(DE, GetBYTE(HL));
744 break;
745 case 0x5F: /* LD E,A */
746 tStates += 4;
747 DE = (DE & ~255) | ((AF >> 8) & 255);
748 break;
749 case 0x60: /* LD H,B */
750 tStates += 4;
751 HL = (HL & 255) | (BC & ~255);
752 break;
753 case 0x61: /* LD H,C */
754 tStates += 4;
755 HL = (HL & 255) | ((BC & 255) << 8);
756 break;
757 case 0x62: /* LD H,D */
758 tStates += 4;
759 HL = (HL & 255) | (DE & ~255);
760 break;
761 case 0x63: /* LD H,E */
762 tStates += 4;
763 HL = (HL & 255) | ((DE & 255) << 8);
764 break;
765 case 0x64: /* LD H,H */
766 tStates += 4;
767 /* nop */
768 break;
769 case 0x65: /* LD H,L */
770 tStates += 4;
771 HL = (HL & 255) | ((HL & 255) << 8);
772 break;
773 case 0x66: /* LD H,(HL) */
774 tStates += 7;
775 Sethreg(HL, GetBYTE(HL));
776 break;
777 case 0x67: /* LD H,A */
778 tStates += 4;
779 HL = (HL & 255) | (AF & ~255);
780 break;
781 case 0x68: /* LD L,B */
782 tStates += 4;
783 HL = (HL & ~255) | ((BC >> 8) & 255);
784 break;
785 case 0x69: /* LD L,C */
786 tStates += 4;
787 HL = (HL & ~255) | (BC & 255);
788 break;
789 case 0x6A: /* LD L,D */
790 tStates += 4;
791 HL = (HL & ~255) | ((DE >> 8) & 255);
792 break;
793 case 0x6B: /* LD L,E */
794 tStates += 4;
795 HL = (HL & ~255) | (DE & 255);
796 break;
797 case 0x6C: /* LD L,H */
798 tStates += 4;
799 HL = (HL & ~255) | ((HL >> 8) & 255);
800 break;
801 case 0x6D: /* LD L,L */
802 tStates += 4;
803 /* nop */
804 break;
805 case 0x6E: /* LD L,(HL) */
806 tStates += 7;
807 Setlreg(HL, GetBYTE(HL));
808 break;
809 case 0x6F: /* LD L,A */
810 tStates += 4;
811 HL = (HL & ~255) | ((AF >> 8) & 255);
812 break;
813 case 0x70: /* LD (HL),B */
814 tStates += 7;
815 PutBYTE(HL, hreg(BC));
816 break;
817 case 0x71: /* LD (HL),C */
818 tStates += 7;
819 PutBYTE(HL, lreg(BC));
820 break;
821 case 0x72: /* LD (HL),D */
822 tStates += 7;
823 PutBYTE(HL, hreg(DE));
824 break;
825 case 0x73: /* LD (HL),E */
826 tStates += 7;
827 PutBYTE(HL, lreg(DE));
828 break;
829 case 0x74: /* LD (HL),H */
830 tStates += 7;
831 PutBYTE(HL, hreg(HL));
832 break;
833 case 0x75: /* LD (HL),L */
834 PutBYTE(HL, lreg(HL));
835 break;
836 case 0x76: /* HALT */
837 tStates += 4;
838 SAVE_STATE();
839 return PC&0xffff;
840 case 0x77: /* LD (HL),A */
841 tStates += 7;
842 PutBYTE(HL, hreg(AF));
843 break;
844 case 0x78: /* LD A,B */
845 tStates += 4;
846 AF = (AF & 255) | (BC & ~255);
847 break;
848 case 0x79: /* LD A,C */
849 tStates += 4;
850 AF = (AF & 255) | ((BC & 255) << 8);
851 break;
852 case 0x7A: /* LD A,D */
853 tStates += 4;
854 AF = (AF & 255) | (DE & ~255);
855 break;
856 case 0x7B: /* LD A,E */
857 tStates += 4;
858 AF = (AF & 255) | ((DE & 255) << 8);
859 break;
860 case 0x7C: /* LD A,H */
861 tStates += 4;
862 AF = (AF & 255) | (HL & ~255);
863 break;
864 case 0x7D: /* LD A,L */
865 tStates += 4;
866 AF = (AF & 255) | ((HL & 255) << 8);
867 break;
868 case 0x7E: /* LD A,(HL) */
869 tStates += 7;
870 Sethreg(AF, GetBYTE(HL));
871 break;
872 case 0x7F: /* LD A,A */
873 tStates += 4;
874 /* nop */
875 break;
876 case 0x80: /* ADD A,B */
877 tStates += 4;
878 temp = hreg(BC);
879 acu = hreg(AF);
880 sum = acu + temp;
881 cbits = acu ^ temp ^ sum;
882 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
883 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
884 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
885 ((cbits >> 8) & 1);
886 break;
887 case 0x81: /* ADD A,C */
888 tStates += 4;
889 temp = lreg(BC);
890 acu = hreg(AF);
891 sum = acu + temp;
892 cbits = acu ^ temp ^ sum;
893 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
894 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
895 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
896 ((cbits >> 8) & 1);
897 break;
898 case 0x82: /* ADD A,D */
899 tStates += 4;
900 temp = hreg(DE);
901 acu = hreg(AF);
902 sum = acu + temp;
903 cbits = acu ^ temp ^ sum;
904 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
905 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
906 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
907 ((cbits >> 8) & 1);
908 break;
909 case 0x83: /* ADD A,E */
910 tStates += 4;
911 temp = lreg(DE);
912 acu = hreg(AF);
913 sum = acu + temp;
914 cbits = acu ^ temp ^ sum;
915 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
916 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
917 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
918 ((cbits >> 8) & 1);
919 break;
920 case 0x84: /* ADD A,H */
921 tStates += 4;
922 temp = hreg(HL);
923 acu = hreg(AF);
924 sum = acu + temp;
925 cbits = acu ^ temp ^ sum;
926 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
927 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
928 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
929 ((cbits >> 8) & 1);
930 break;
931 case 0x85: /* ADD A,L */
932 tStates += 4;
933 temp = lreg(HL);
934 acu = hreg(AF);
935 sum = acu + temp;
936 cbits = acu ^ temp ^ sum;
937 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
938 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
939 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
940 ((cbits >> 8) & 1);
941 break;
942 case 0x86: /* ADD A,(HL) */
943 tStates += 7;
944 temp = GetBYTE(HL);
945 acu = hreg(AF);
946 sum = acu + temp;
947 cbits = acu ^ temp ^ sum;
948 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
949 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
950 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
951 ((cbits >> 8) & 1);
952 break;
953 case 0x87: /* ADD A,A */
954 tStates += 4;
955 temp = hreg(AF);
956 acu = hreg(AF);
957 sum = acu + temp;
958 cbits = acu ^ temp ^ sum;
959 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
960 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
961 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
962 ((cbits >> 8) & 1);
963 break;
964 case 0x88: /* ADC A,B */
965 tStates += 4;
966 temp = hreg(BC);
967 acu = hreg(AF);
968 sum = acu + temp + TSTFLAG(C);
969 cbits = acu ^ temp ^ sum;
970 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
971 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
972 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
973 ((cbits >> 8) & 1);
974 break;
975 case 0x89: /* ADC A,C */
976 tStates += 4;
977 temp = lreg(BC);
978 acu = hreg(AF);
979 sum = acu + temp + TSTFLAG(C);
980 cbits = acu ^ temp ^ sum;
981 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
982 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
983 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
984 ((cbits >> 8) & 1);
985 break;
986 case 0x8A: /* ADC A,D */
987 tStates += 4;
988 temp = hreg(DE);
989 acu = hreg(AF);
990 sum = acu + temp + TSTFLAG(C);
991 cbits = acu ^ temp ^ sum;
992 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
993 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
994 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
995 ((cbits >> 8) & 1);
996 break;
997 case 0x8B: /* ADC A,E */
998 tStates += 4;
999 temp = lreg(DE);
1000 acu = hreg(AF);
1001 sum = acu + temp + TSTFLAG(C);
1002 cbits = acu ^ temp ^ sum;
1003 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1004 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1005 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
1006 ((cbits >> 8) & 1);
1007 break;
1008 case 0x8C: /* ADC A,H */
1009 tStates += 4;
1010 temp = hreg(HL);
1011 acu = hreg(AF);
1012 sum = acu + temp + TSTFLAG(C);
1013 cbits = acu ^ temp ^ sum;
1014 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1015 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1016 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
1017 ((cbits >> 8) & 1);
1018 break;
1019 case 0x8D: /* ADC A,L */
1020 tStates += 4;
1021 temp = lreg(HL);
1022 acu = hreg(AF);
1023 sum = acu + temp + TSTFLAG(C);
1024 cbits = acu ^ temp ^ sum;
1025 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1026 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1027 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
1028 ((cbits >> 8) & 1);
1029 break;
1030 case 0x8E: /* ADC A,(HL) */
1031 tStates += 7;
1032 temp = GetBYTE(HL);
1033 acu = hreg(AF);
1034 sum = acu + temp + TSTFLAG(C);
1035 cbits = acu ^ temp ^ sum;
1036 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1037 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1038 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
1039 ((cbits >> 8) & 1);
1040 break;
1041 case 0x8F: /* ADC A,A */
1042 tStates += 4;
1043 temp = hreg(AF);
1044 acu = hreg(AF);
1045 sum = acu + temp + TSTFLAG(C);
1046 cbits = acu ^ temp ^ sum;
1047 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1048 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1049 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
1050 ((cbits >> 8) & 1);
1051 break;
1052 case 0x90: /* SUB B */
1053 tStates += 4;
1054 temp = hreg(BC);
1055 acu = hreg(AF);
1056 sum = acu - temp;
1057 cbits = acu ^ temp ^ sum;
1058 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1059 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1060 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1061 ((cbits >> 8) & 1);
1062 break;
1063 case 0x91: /* SUB C */
1064 tStates += 4;
1065 temp = lreg(BC);
1066 acu = hreg(AF);
1067 sum = acu - temp;
1068 cbits = acu ^ temp ^ sum;
1069 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1070 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1071 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1072 ((cbits >> 8) & 1);
1073 break;
1074 case 0x92: /* SUB D */
1075 tStates += 4;
1076 temp = hreg(DE);
1077 acu = hreg(AF);
1078 sum = acu - temp;
1079 cbits = acu ^ temp ^ sum;
1080 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1081 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1082 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1083 ((cbits >> 8) & 1);
1084 break;
1085 case 0x93: /* SUB E */
1086 tStates += 4;
1087 temp = lreg(DE);
1088 acu = hreg(AF);
1089 sum = acu - temp;
1090 cbits = acu ^ temp ^ sum;
1091 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1092 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1093 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1094 ((cbits >> 8) & 1);
1095 break;
1096 case 0x94: /* SUB H */
1097 tStates += 4;
1098 temp = hreg(HL);
1099 acu = hreg(AF);
1100 sum = acu - temp;
1101 cbits = acu ^ temp ^ sum;
1102 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1103 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1104 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1105 ((cbits >> 8) & 1);
1106 break;
1107 case 0x95: /* SUB L */
1108 tStates += 4;
1109 temp = lreg(HL);
1110 acu = hreg(AF);
1111 sum = acu - temp;
1112 cbits = acu ^ temp ^ sum;
1113 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1114 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1115 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1116 ((cbits >> 8) & 1);
1117 break;
1118 case 0x96: /* SUB (HL) */
1119 tStates += 7;
1120 temp = GetBYTE(HL);
1121 acu = hreg(AF);
1122 sum = acu - temp;
1123 cbits = acu ^ temp ^ sum;
1124 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1125 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1126 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1127 ((cbits >> 8) & 1);
1128 break;
1129 case 0x97: /* SUB A */
1130 tStates += 4;
1131 temp = hreg(AF);
1132 acu = hreg(AF);
1133 sum = acu - temp;
1134 cbits = acu ^ temp ^ sum;
1135 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1136 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1137 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1138 ((cbits >> 8) & 1);
1139 break;
1140 case 0x98: /* SBC A,B */
1141 tStates += 4;
1142 temp = hreg(BC);
1143 acu = hreg(AF);
1144 sum = acu - temp - TSTFLAG(C);
1145 cbits = acu ^ temp ^ sum;
1146 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1147 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1148 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1149 ((cbits >> 8) & 1);
1150 break;
1151 case 0x99: /* SBC A,C */
1152 tStates += 4;
1153 temp = lreg(BC);
1154 acu = hreg(AF);
1155 sum = acu - temp - TSTFLAG(C);
1156 cbits = acu ^ temp ^ sum;
1157 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1158 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1159 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1160 ((cbits >> 8) & 1);
1161 break;
1162 case 0x9A: /* SBC A,D */
1163 tStates += 4;
1164 temp = hreg(DE);
1165 acu = hreg(AF);
1166 sum = acu - temp - TSTFLAG(C);
1167 cbits = acu ^ temp ^ sum;
1168 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1169 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1170 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1171 ((cbits >> 8) & 1);
1172 break;
1173 case 0x9B: /* SBC A,E */
1174 tStates += 4;
1175 temp = lreg(DE);
1176 acu = hreg(AF);
1177 sum = acu - temp - TSTFLAG(C);
1178 cbits = acu ^ temp ^ sum;
1179 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1180 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1181 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1182 ((cbits >> 8) & 1);
1183 break;
1184 case 0x9C: /* SBC A,H */
1185 tStates += 4;
1186 temp = hreg(HL);
1187 acu = hreg(AF);
1188 sum = acu - temp - TSTFLAG(C);
1189 cbits = acu ^ temp ^ sum;
1190 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1191 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1192 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1193 ((cbits >> 8) & 1);
1194 break;
1195 case 0x9D: /* SBC A,L */
1196 tStates += 4;
1197 temp = lreg(HL);
1198 acu = hreg(AF);
1199 sum = acu - temp - TSTFLAG(C);
1200 cbits = acu ^ temp ^ sum;
1201 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1202 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1203 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1204 ((cbits >> 8) & 1);
1205 break;
1206 case 0x9E: /* SBC A,(HL) */
1207 tStates += 7;
1208 temp = GetBYTE(HL);
1209 acu = hreg(AF);
1210 sum = acu - temp - TSTFLAG(C);
1211 cbits = acu ^ temp ^ sum;
1212 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1213 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1214 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1215 ((cbits >> 8) & 1);
1216 break;
1217 case 0x9F: /* SBC A,A */
1218 tStates += 4;
1219 temp = hreg(AF);
1220 acu = hreg(AF);
1221 sum = acu - temp - TSTFLAG(C);
1222 cbits = acu ^ temp ^ sum;
1223 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1224 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1225 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1226 ((cbits >> 8) & 1);
1227 break;
1228 case 0xA0: /* AND B */
1229 tStates += 4;
1230 sum = ((AF & (BC)) >> 8) & 0xff;
1231 AF = (sum << 8) | (sum & 0xa8) |
1232 ((sum == 0) << 6) | 0x10 | partab[sum];
1233 break;
1234 case 0xA1: /* AND C */
1235 tStates += 4;
1236 sum = ((AF >> 8) & BC) & 0xff;
1237 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
1238 ((sum == 0) << 6) | partab[sum];
1239 break;
1240 case 0xA2: /* AND D */
1241 tStates += 4;
1242 sum = ((AF & (DE)) >> 8) & 0xff;
1243 AF = (sum << 8) | (sum & 0xa8) |
1244 ((sum == 0) << 6) | 0x10 | partab[sum];
1245 break;
1246 case 0xA3: /* AND E */
1247 tStates += 4;
1248 sum = ((AF >> 8) & DE) & 0xff;
1249 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
1250 ((sum == 0) << 6) | partab[sum];
1251 break;
1252 case 0xA4: /* AND H */
1253 tStates += 4;
1254 sum = ((AF & (HL)) >> 8) & 0xff;
1255 AF = (sum << 8) | (sum & 0xa8) |
1256 ((sum == 0) << 6) | 0x10 | partab[sum];
1257 break;
1258 case 0xA5: /* AND L */
1259 tStates += 4;
1260 sum = ((AF >> 8) & HL) & 0xff;
1261 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
1262 ((sum == 0) << 6) | partab[sum];
1263 break;
1264 case 0xA6: /* AND (HL) */
1265 tStates += 7;
1266 sum = ((AF >> 8) & GetBYTE(HL)) & 0xff;
1267 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
1268 ((sum == 0) << 6) | partab[sum];
1269 break;
1270 case 0xA7: /* AND A */
1271 tStates += 4;
1272 sum = ((AF & (AF)) >> 8) & 0xff;
1273 AF = (sum << 8) | (sum & 0xa8) |
1274 ((sum == 0) << 6) | 0x10 | partab[sum];
1275 break;
1276 case 0xA8: /* XOR B */
1277 tStates += 4;
1278 sum = ((AF ^ (BC)) >> 8) & 0xff;
1279 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1280 break;
1281 case 0xA9: /* XOR C */
1282 tStates += 4;
1283 sum = ((AF >> 8) ^ BC) & 0xff;
1284 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1285 break;
1286 case 0xAA: /* XOR D */
1287 tStates += 4;
1288 sum = ((AF ^ (DE)) >> 8) & 0xff;
1289 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1290 break;
1291 case 0xAB: /* XOR E */
1292 tStates += 4;
1293 sum = ((AF >> 8) ^ DE) & 0xff;
1294 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1295 break;
1296 case 0xAC: /* XOR H */
1297 tStates += 4;
1298 sum = ((AF ^ (HL)) >> 8) & 0xff;
1299 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1300 break;
1301 case 0xAD: /* XOR L */
1302 tStates += 4;
1303 sum = ((AF >> 8) ^ HL) & 0xff;
1304 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1305 break;
1306 case 0xAE: /* XOR (HL) */
1307 tStates += 7;
1308 sum = ((AF >> 8) ^ GetBYTE(HL)) & 0xff;
1309 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1310 break;
1311 case 0xAF: /* XOR A */
1312 tStates += 4;
1313 sum = ((AF ^ (AF)) >> 8) & 0xff;
1314 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1315 break;
1316 case 0xB0: /* OR B */
1317 tStates += 4;
1318 sum = ((AF | (BC)) >> 8) & 0xff;
1319 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1320 break;
1321 case 0xB1: /* OR C */
1322 tStates += 4;
1323 sum = ((AF >> 8) | BC) & 0xff;
1324 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1325 break;
1326 case 0xB2: /* OR D */
1327 tStates += 4;
1328 sum = ((AF | (DE)) >> 8) & 0xff;
1329 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1330 break;
1331 case 0xB3: /* OR E */
1332 tStates += 4;
1333 sum = ((AF >> 8) | DE) & 0xff;
1334 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1335 break;
1336 case 0xB4: /* OR H */
1337 tStates += 4;
1338 sum = ((AF | (HL)) >> 8) & 0xff;
1339 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1340 break;
1341 case 0xB5: /* OR L */
1342 tStates += 4;
1343 sum = ((AF >> 8) | HL) & 0xff;
1344 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1345 break;
1346 case 0xB6: /* OR (HL) */
1347 tStates += 7;
1348 sum = ((AF >> 8) | GetBYTE(HL)) & 0xff;
1349 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1350 break;
1351 case 0xB7: /* OR A */
1352 tStates += 4;
1353 sum = ((AF | (AF)) >> 8) & 0xff;
1354 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
1355 break;
1356 case 0xB8: /* CP B */
1357 tStates += 4;
1358 temp = hreg(BC);
1359 AF = (AF & ~0x28) | (temp & 0x28);
1360 acu = hreg(AF);
1361 sum = acu - temp;
1362 cbits = acu ^ temp ^ sum;
1363 AF = (AF & ~0xff) | (sum & 0x80) |
1364 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
1365 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1366 (cbits & 0x10) | ((cbits >> 8) & 1);
1367 break;
1368 case 0xB9: /* CP C */
1369 tStates += 4;
1370 temp = lreg(BC);
1371 AF = (AF & ~0x28) | (temp & 0x28);
1372 acu = hreg(AF);
1373 sum = acu - temp;
1374 cbits = acu ^ temp ^ sum;
1375 AF = (AF & ~0xff) | (sum & 0x80) |
1376 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
1377 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1378 (cbits & 0x10) | ((cbits >> 8) & 1);
1379 break;
1380 case 0xBA: /* CP D */
1381 tStates += 4;
1382 temp = hreg(DE);
1383 AF = (AF & ~0x28) | (temp & 0x28);
1384 acu = hreg(AF);
1385 sum = acu - temp;
1386 cbits = acu ^ temp ^ sum;
1387 AF = (AF & ~0xff) | (sum & 0x80) |
1388 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
1389 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1390 (cbits & 0x10) | ((cbits >> 8) & 1);
1391 break;
1392 case 0xBB: /* CP E */
1393 tStates += 4;
1394 temp = lreg(DE);
1395 AF = (AF & ~0x28) | (temp & 0x28);
1396 acu = hreg(AF);
1397 sum = acu - temp;
1398 cbits = acu ^ temp ^ sum;
1399 AF = (AF & ~0xff) | (sum & 0x80) |
1400 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
1401 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1402 (cbits & 0x10) | ((cbits >> 8) & 1);
1403 break;
1404 case 0xBC: /* CP H */
1405 tStates += 4;
1406 temp = hreg(HL);
1407 AF = (AF & ~0x28) | (temp & 0x28);
1408 acu = hreg(AF);
1409 sum = acu - temp;
1410 cbits = acu ^ temp ^ sum;
1411 AF = (AF & ~0xff) | (sum & 0x80) |
1412 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
1413 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1414 (cbits & 0x10) | ((cbits >> 8) & 1);
1415 break;
1416 case 0xBD: /* CP L */
1417 tStates += 4;
1418 temp = lreg(HL);
1419 AF = (AF & ~0x28) | (temp & 0x28);
1420 acu = hreg(AF);
1421 sum = acu - temp;
1422 cbits = acu ^ temp ^ sum;
1423 AF = (AF & ~0xff) | (sum & 0x80) |
1424 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
1425 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1426 (cbits & 0x10) | ((cbits >> 8) & 1);
1427 break;
1428 case 0xBE: /* CP (HL) */
1429 tStates += 7;
1430 temp = GetBYTE(HL);
1431 AF = (AF & ~0x28) | (temp & 0x28);
1432 acu = hreg(AF);
1433 sum = acu - temp;
1434 cbits = acu ^ temp ^ sum;
1435 AF = (AF & ~0xff) | (sum & 0x80) |
1436 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
1437 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1438 (cbits & 0x10) | ((cbits >> 8) & 1);
1439 break;
1440 case 0xBF: /* CP A */
1441 tStates += 4;
1442 temp = hreg(AF);
1443 AF = (AF & ~0x28) | (temp & 0x28);
1444 acu = hreg(AF);
1445 sum = acu - temp;
1446 cbits = acu ^ temp ^ sum;
1447 AF = (AF & ~0xff) | (sum & 0x80) |
1448 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
1449 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1450 (cbits & 0x10) | ((cbits >> 8) & 1);
1451 break;
1452 case 0xC0: /* RET NZ */
1453 if (!TSTFLAG(Z)) {
1454 POP(PC);
1455 tStates += 11;
1456 } else {
1457 tStates += 5;
1458 }
1459 break;
1460 case 0xC1: /* POP BC */
1461 tStates += 10;
1462 POP(BC);
1463 break;
1464 case 0xC2: /* JP NZ,nnnn */
1465 JPC(!TSTFLAG(Z)); /* also updates tStates */
1466 break;
1467 case 0xC3: /* JP nnnn */
1468 JPC(1); /* also updates tStates */
1469 break;
1470 case 0xC4: /* CALL NZ,nnnn */
1471 CALLC(!TSTFLAG(Z)); /* also updates tStates */
1472 break;
1473 case 0xC5: /* PUSH BC */
1474 tStates += 11;
1475 PUSH(BC);
1476 break;
1477 case 0xC6: /* ADD A,nn */
1478 tStates += 7;
1479 temp = GetBYTE_pp(PC);
1480 acu = hreg(AF);
1481 sum = acu + temp;
1482 cbits = acu ^ temp ^ sum;
1483 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1484 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1485 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
1486 ((cbits >> 8) & 1);
1487 break;
1488 case 0xC7: /* RST 0 */
1489 tStates += 11;
1490 PUSH(PC); PC = 0;
1491 break;
1492 case 0xC8: /* RET Z */
1493 if (TSTFLAG(Z)) {
1494 tStates += 11;
1495 POP(PC);
1496 } else {
1497 tStates += 5;
1498 }
1499 break;
1500 case 0xC9: /* RET */
1501 tStates += 10;
1502 POP(PC);
1503 break;
1504 case 0xCA: /* JP Z,nnnn */
1505 JPC(TSTFLAG(Z)); /* also updates tStates */
1506 break;
1507 case 0xCB: /* CB prefix */
1508 adr = HL;
1509 switch ((op = GetBYTE(PC)) & 7) {
1510 /*
1511 * Use default to supress compiler warning: "warning:
1512 * 'acu' may be used uninitialized in this function"
1513 */
1514 default:
1515 case 0: ++PC; acu = hreg(BC); tStates += 8;
1516 tStateModifier = false;
1517 break;
1518 case 1: ++PC; acu = lreg(BC); tStates += 8;
1519 tStateModifier = false;
1520 break;
1521 case 2: ++PC; acu = hreg(DE); tStates += 8;
1522 tStateModifier = false;
1523 break;
1524 case 3: ++PC; acu = lreg(DE); tStates += 8;
1525 tStateModifier = false;
1526 break;
1527 case 4: ++PC; acu = hreg(HL); tStates += 8;
1528 tStateModifier = false;
1529 break;
1530 case 5: ++PC; acu = lreg(HL); tStates += 8;
1531 tStateModifier = false;
1532 break;
1533 case 6: ++PC; acu = GetBYTE(adr); tStates += 15;
1534 tStateModifier = true;
1535 break;
1536 case 7: ++PC; acu = hreg(AF); tStates += 8;
1537 tStateModifier = false;
1538 break;
1539 }
1540 switch (op & 0xc0) {
1541 /*
1542 * Use default to supress compiler warning: "warning:
1543 * 'temp' may be used uninitialized in this function"
1544 */
1545 default:
1546 case 0x00: /* shift/rotate */
1547 switch (op & 0x38) {
1548 /*
1549 * Use default to supress compiler warning: "warning:
1550 * 'temp' may be used uninitialized in this function"
1551 */
1552 default:
1553 case 0x00: /* RLC */
1554 temp = (acu << 1) | (acu >> 7);
1555 cbits = temp & 1;
1556 goto cbshflg1;
1557 case 0x08: /* RRC */
1558 temp = (acu >> 1) | (acu << 7);
1559 cbits = temp & 0x80;
1560 goto cbshflg1;
1561 case 0x10: /* RL */
1562 temp = (acu << 1) | TSTFLAG(C);
1563 cbits = acu & 0x80;
1564 goto cbshflg1;
1565 case 0x18: /* RR */
1566 temp = (acu >> 1) | (TSTFLAG(C) << 7);
1567 cbits = acu & 1;
1568 goto cbshflg1;
1569 case 0x20: /* SLA */
1570 temp = acu << 1;
1571 cbits = acu & 0x80;
1572 goto cbshflg1;
1573 case 0x28: /* SRA */
1574 temp = (acu >> 1) | (acu & 0x80);
1575 cbits = acu & 1;
1576 goto cbshflg1;
1577 case 0x30: /* SLIA */
1578 temp = (acu << 1) | 1;
1579 cbits = acu & 0x80;
1580 goto cbshflg1;
1581 case 0x38: /* SRL */
1582 temp = acu >> 1;
1583 cbits = acu & 1;
1584 cbshflg1:
1585 AF = (AF & ~0xff) | (temp & 0xa8) |
1586 (((temp & 0xff) == 0) << 6) |
1587 parity(temp) | !!cbits;
1588 }
1589 break;
1590 case 0x40: /* BIT */
1591 if (tStateModifier)
1592 tStates -= 3;
1593 if (acu & (1 << ((op >> 3) & 7)))
1594 AF = (AF & ~0xfe) | 0x10 |
1595 (((op & 0x38) == 0x38) << 7);
1596 else
1597 AF = (AF & ~0xfe) | 0x54;
1598 if ((op&7) != 6)
1599 AF |= (acu & 0x28);
1600 temp = acu;
1601 break;
1602 case 0x80: /* RES */
1603 temp = acu & ~(1 << ((op >> 3) & 7));
1604 break;
1605 case 0xc0: /* SET */
1606 temp = acu | (1 << ((op >> 3) & 7));
1607 break;
1608 }
1609 switch (op & 7) {
1610 case 0: Sethreg(BC, temp); break;
1611 case 1: Setlreg(BC, temp); break;
1612 case 2: Sethreg(DE, temp); break;
1613 case 3: Setlreg(DE, temp); break;
1614 case 4: Sethreg(HL, temp); break;
1615 case 5: Setlreg(HL, temp); break;
1616 case 6: PutBYTE(adr, temp); break;
1617 case 7: Sethreg(AF, temp); break;
1618 }
1619 break;
1620 case 0xCC: /* CALL Z,nnnn */
1621 CALLC(TSTFLAG(Z)); /* also updates tStates */
1622 break;
1623 case 0xCD: /* CALL nnnn */
1624 CALLC(1); /* also updates tStates */
1625 break;
1626 case 0xCE: /* ADC A,nn */
1627 tStates += 7;
1628 temp = GetBYTE_pp(PC);
1629 acu = hreg(AF);
1630 sum = acu + temp + TSTFLAG(C);
1631 cbits = acu ^ temp ^ sum;
1632 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1633 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1634 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
1635 ((cbits >> 8) & 1);
1636 break;
1637 case 0xCF: /* RST 8 */
1638 tStates += 11;
1639 PUSH(PC);
1640 PC = 8;
1641 break;
1642 case 0xD0: /* RET NC */
1643 if (!TSTFLAG(C)) {
1644 POP(PC);
1645 tStates += 11;
1646 } else {
1647 tStates += 5;
1648 }
1649 break;
1650 case 0xD1: /* POP DE */
1651 tStates += 10;
1652 POP(DE);
1653 break;
1654 case 0xD2: /* JP NC,nnnn */
1655 JPC(!TSTFLAG(C)); /* also updates tStates */
1656 break;
1657 case 0xD3: /* OUT (nn),A */
1658 tStates += 11;
1659 Output(GetBYTE_pp(PC), hreg(AF));
1660 break;
1661 case 0xD4: /* CALL NC,nnnn */
1662 CALLC(!TSTFLAG(C)); /* also updates tStates */
1663 break;
1664 case 0xD5: /* PUSH DE */
1665 tStates += 11;
1666 PUSH(DE);
1667 break;
1668 case 0xD6: /* SUB nn */
1669 tStates += 7;
1670 temp = GetBYTE_pp(PC);
1671 acu = hreg(AF);
1672 sum = acu - temp;
1673 cbits = acu ^ temp ^ sum;
1674 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
1675 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
1676 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
1677 ((cbits >> 8) & 1);
1678 break;
1679 case 0xD7: /* RST 10H */
1680 tStates += 11;
1681 PUSH(PC); PC = 0x10;
1682 break;
1683 case 0xD8: /* RET C */
1684 if (TSTFLAG(C)) {
1685 POP(PC);
1686 tStates += 11;
1687 } else {
1688 tStates += 5;
1689 }
1690 break;
1691 case 0xD9: /* EXX */
1692 tStates += 4;
1693 regs[regs_sel].bc = BC;
1694 regs[regs_sel].de = DE;
1695 regs[regs_sel].hl = HL;
1696 regs_sel = 1 - regs_sel;
1697 BC = regs[regs_sel].bc;
1698 DE = regs[regs_sel].de;
1699 HL = regs[regs_sel].hl;
1700 break;
1701 case 0xDA: /* JP C,nnnn */
1702 JPC(TSTFLAG(C)); /* also updates tStates */
1703 break;
1704 case 0xDB: /* IN A,(nn) */
1705 tStates += 11;
1706 Sethreg(AF, Input(GetBYTE_pp(PC)));
1707 break;
1708 case 0xDC: /* CALL C,nnnn */
1709 CALLC(TSTFLAG(C)); /* also updates tStates */
1710 break;
1711 case 0xDD: /* DD prefix */
1712 switch (op = GetBYTE_pp(PC)) {
1713 case 0x09: /* ADD IX,BC */
1714 tStates += 15;
1715 IX &= 0xffff;
1716 BC &= 0xffff;
1717 sum = IX + BC;
1718 cbits = (IX ^ BC ^ sum) >> 8;
1719 IX = sum;
1720 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
1721 (cbits & 0x10) | ((cbits >> 8) & 1);
1722 break;
1723 case 0x19: /* ADD IX,DE */
1724 tStates += 15;
1725 IX &= 0xffff;
1726 DE &= 0xffff;
1727 sum = IX + DE;
1728 cbits = (IX ^ DE ^ sum) >> 8;
1729 IX = sum;
1730 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
1731 (cbits & 0x10) | ((cbits >> 8) & 1);
1732 break;
1733 case 0x21: /* LD IX,nnnn */
1734 tStates += 14;
1735 IX = GetWORD(PC);
1736 PC += 2;
1737 break;
1738 case 0x22: /* LD (nnnn),IX */
1739 tStates += 20;
1740 temp = GetWORD(PC);
1741 PutWORD(temp, IX);
1742 PC += 2;
1743 break;
1744 case 0x23: /* INC IX */
1745 tStates += 10;
1746 ++IX;
1747 break;
1748 case 0x24: /* INC IXH */
1749 tStates += 9;
1750 IX += 0x100;
1751 temp = hreg(IX);
1752 AF = (AF & ~0xfe) | (temp & 0xa8) |
1753 (((temp & 0xff) == 0) << 6) |
1754 (((temp & 0xf) == 0) << 4) |
1755 ((temp == 0x80) << 2);
1756 break;
1757 case 0x25: /* DEC IXH */
1758 tStates += 9;
1759 IX -= 0x100;
1760 temp = hreg(IX);
1761 AF = (AF & ~0xfe) | (temp & 0xa8) |
1762 (((temp & 0xff) == 0) << 6) |
1763 (((temp & 0xf) == 0xf) << 4) |
1764 ((temp == 0x7f) << 2) | 2;
1765 break;
1766 case 0x26: /* LD IXH,nn */
1767 tStates += 9;
1768 Sethreg(IX, GetBYTE_pp(PC));
1769 break;
1770 case 0x29: /* ADD IX,IX */
1771 tStates += 15;
1772 IX &= 0xffff;
1773 sum = IX + IX;
1774 cbits = (IX ^ IX ^ sum) >> 8;
1775 IX = sum;
1776 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
1777 (cbits & 0x10) | ((cbits >> 8) & 1);
1778 break;
1779 case 0x2A: /* LD IX,(nnnn) */
1780 tStates += 20;
1781 temp = GetWORD(PC);
1782 IX = GetWORD(temp);
1783 PC += 2;
1784 break;
1785 case 0x2B: /* DEC IX */
1786 tStates += 10;
1787 --IX;
1788 break;
1789 case 0x2C: /* INC IXL */
1790 tStates += 9;
1791 temp = lreg(IX)+1;
1792 Setlreg(IX, temp);
1793 AF = (AF & ~0xfe) | (temp & 0xa8) |
1794 (((temp & 0xff) == 0) << 6) |
1795 (((temp & 0xf) == 0) << 4) |
1796 ((temp == 0x80) << 2);
1797 break;
1798 case 0x2D: /* DEC IXL */
1799 tStates += 9;
1800 temp = lreg(IX)-1;
1801 Setlreg(IX, temp);
1802 AF = (AF & ~0xfe) | (temp & 0xa8) |
1803 (((temp & 0xff) == 0) << 6) |
1804 (((temp & 0xf) == 0xf) << 4) |
1805 ((temp == 0x7f) << 2) | 2;
1806 break;
1807 case 0x2E: /* LD IXL,nn */
1808 tStates += 9;
1809 Setlreg(IX, GetBYTE_pp(PC));
1810 break;
1811 case 0x34: /* INC (IX+dd) */
1812 tStates += 23;
1813 adr = IX + (signed char) GetBYTE_pp(PC);
1814 temp = GetBYTE(adr)+1;
1815 PutBYTE(adr, temp);
1816 AF = (AF & ~0xfe) | (temp & 0xa8) |
1817 (((temp & 0xff) == 0) << 6) |
1818 (((temp & 0xf) == 0) << 4) |
1819 ((temp == 0x80) << 2);
1820 break;
1821 case 0x35: /* DEC (IX+dd) */
1822 tStates += 23;
1823 adr = IX + (signed char) GetBYTE_pp(PC);
1824 temp = GetBYTE(adr)-1;
1825 PutBYTE(adr, temp);
1826 AF = (AF & ~0xfe) | (temp & 0xa8) |
1827 (((temp & 0xff) == 0) << 6) |
1828 (((temp & 0xf) == 0xf) << 4) |
1829 ((temp == 0x7f) << 2) | 2;
1830 break;
1831 case 0x36: /* LD (IX+dd),nn */
1832 tStates += 19;
1833 adr = IX + (signed char) GetBYTE_pp(PC);
1834 PutBYTE(adr, GetBYTE_pp(PC));
1835 break;
1836 case 0x39: /* ADD IX,SP */
1837 tStates += 15;
1838 IX &= 0xffff;
1839 SP &= 0xffff;
1840 sum = IX + SP;
1841 cbits = (IX ^ SP ^ sum) >> 8;
1842 IX = sum;
1843 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
1844 (cbits & 0x10) | ((cbits >> 8) & 1);
1845 break;
1846 case 0x44: /* LD B,IXH */
1847 tStates += 9;
1848 Sethreg(BC, hreg(IX));
1849 break;
1850 case 0x45: /* LD B,IXL */
1851 tStates += 9;
1852 Sethreg(BC, lreg(IX));
1853 break;
1854 case 0x46: /* LD B,(IX+dd) */
1855 tStates += 19;
1856 adr = IX + (signed char) GetBYTE_pp(PC);
1857 Sethreg(BC, GetBYTE(adr));
1858 break;
1859 case 0x4C: /* LD C,IXH */
1860 tStates += 9;
1861 Setlreg(BC, hreg(IX));
1862 break;
1863 case 0x4D: /* LD C,IXL */
1864 tStates += 9;
1865 Setlreg(BC, lreg(IX));
1866 break;
1867 case 0x4E: /* LD C,(IX+dd) */
1868 tStates += 19;
1869 adr = IX + (signed char) GetBYTE_pp(PC);
1870 Setlreg(BC, GetBYTE(adr));
1871 break;
1872 case 0x54: /* LD D,IXH */
1873 tStates += 9;
1874 Sethreg(DE, hreg(IX));
1875 break;
1876 case 0x55: /* LD D,IXL */
1877 tStates += 9;
1878 Sethreg(DE, lreg(IX));
1879 break;
1880 case 0x56: /* LD D,(IX+dd) */
1881 tStates += 19;
1882 adr = IX + (signed char) GetBYTE_pp(PC);
1883 Sethreg(DE, GetBYTE(adr));
1884 break;
1885 case 0x5C: /* LD E,IXH */
1886 tStates += 9;
1887 Setlreg(DE, hreg(IX));
1888 break;
1889 case 0x5D: /* LD E,IXL */
1890 tStates += 9;
1891 Setlreg(DE, lreg(IX));
1892 break;
1893 case 0x5E: /* LD E,(IX+dd) */
1894 tStates += 19;
1895 adr = IX + (signed char) GetBYTE_pp(PC);
1896 Setlreg(DE, GetBYTE(adr));
1897 break;
1898 case 0x60: /* LD IXH,B */
1899 tStates += 9;
1900 Sethreg(IX, hreg(BC));
1901 break;
1902 case 0x61: /* LD IXH,C */
1903 tStates += 9;
1904 Sethreg(IX, lreg(BC));
1905 break;
1906 case 0x62: /* LD IXH,D */
1907 tStates += 9;
1908 Sethreg(IX, hreg(DE));
1909 break;
1910 case 0x63: /* LD IXH,E */
1911 tStates += 9;
1912 Sethreg(IX, lreg(DE));
1913 break;
1914 case 0x64: /* LD IXH,IXH */
1915 tStates += 9;
1916 /* nop */
1917 break;
1918 case 0x65: /* LD IXH,IXL */
1919 tStates += 9;
1920 Sethreg(IX, lreg(IX));
1921 break;
1922 case 0x66: /* LD H,(IX+dd) */
1923 tStates += 19;
1924 adr = IX + (signed char) GetBYTE_pp(PC);
1925 Sethreg(HL, GetBYTE(adr));
1926 break;
1927 case 0x67: /* LD IXH,A */
1928 tStates += 9;
1929 Sethreg(IX, hreg(AF));
1930 break;
1931 case 0x68: /* LD IXL,B */
1932 tStates += 9;
1933 Setlreg(IX, hreg(BC));
1934 break;
1935 case 0x69: /* LD IXL,C */
1936 tStates += 9;
1937 Setlreg(IX, lreg(BC));
1938 break;
1939 case 0x6A: /* LD IXL,D */
1940 tStates += 9;
1941 Setlreg(IX, hreg(DE));
1942 break;
1943 case 0x6B: /* LD IXL,E */
1944 tStates += 9;
1945 Setlreg(IX, lreg(DE));
1946 break;
1947 case 0x6C: /* LD IXL,IXH */
1948 tStates += 9;
1949 Setlreg(IX, hreg(IX));
1950 break;
1951 case 0x6D: /* LD IXL,IXL */
1952 tStates += 9;
1953 /* nop */
1954 break;
1955 case 0x6E: /* LD L,(IX+dd) */
1956 tStates += 19;
1957 adr = IX + (signed char) GetBYTE_pp(PC);
1958 Setlreg(HL, GetBYTE(adr));
1959 break;
1960 case 0x6F: /* LD IXL,A */
1961 tStates += 9;
1962 Setlreg(IX, hreg(AF));
1963 break;
1964 case 0x70: /* LD (IX+dd),B */
1965 tStates += 19;
1966 adr = IX + (signed char) GetBYTE_pp(PC);
1967 PutBYTE(adr, hreg(BC));
1968 break;
1969 case 0x71: /* LD (IX+dd),C */
1970 tStates += 19;
1971 adr = IX + (signed char) GetBYTE_pp(PC);
1972 PutBYTE(adr, lreg(BC));
1973 break;
1974 case 0x72: /* LD (IX+dd),D */
1975 tStates += 19;
1976 adr = IX + (signed char) GetBYTE_pp(PC);
1977 PutBYTE(adr, hreg(DE));
1978 break;
1979 case 0x73: /* LD (IX+dd),E */
1980 tStates += 19;
1981 adr = IX + (signed char) GetBYTE_pp(PC);
1982 PutBYTE(adr, lreg(DE));
1983 break;
1984 case 0x74: /* LD (IX+dd),H */
1985 tStates += 19;
1986 adr = IX + (signed char) GetBYTE_pp(PC);
1987 PutBYTE(adr, hreg(HL));
1988 break;
1989 case 0x75: /* LD (IX+dd),L */
1990 tStates += 19;
1991 adr = IX + (signed char) GetBYTE_pp(PC);
1992 PutBYTE(adr, lreg(HL));
1993 break;
1994 case 0x77: /* LD (IX+dd),A */
1995 tStates += 19;
1996 adr = IX + (signed char) GetBYTE_pp(PC);
1997 PutBYTE(adr, hreg(AF));
1998 break;
1999 case 0x7C: /* LD A,IXH */
2000 tStates += 9;
2001 Sethreg(AF, hreg(IX));
2002 break;
2003 case 0x7D: /* LD A,IXL */
2004 tStates += 9;
2005 Sethreg(AF, lreg(IX));
2006 break;
2007 case 0x7E: /* LD A,(IX+dd) */
2008 tStates += 19;
2009 adr = IX + (signed char) GetBYTE_pp(PC);
2010 Sethreg(AF, GetBYTE(adr));
2011 break;
2012 case 0x84: /* ADD A,IXH */
2013 tStates += 9;
2014 temp = hreg(IX);
2015 acu = hreg(AF);
2016 sum = acu + temp;
2017 cbits = acu ^ temp ^ sum;
2018 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2019 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2020 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2021 ((cbits >> 8) & 1);
2022 break;
2023 case 0x85: /* ADD A,IXL */
2024 tStates += 9;
2025 temp = lreg(IX);
2026 acu = hreg(AF);
2027 sum = acu + temp;
2028 cbits = acu ^ temp ^ sum;
2029 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2030 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2031 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2032 ((cbits >> 8) & 1);
2033 break;
2034 case 0x86: /* ADD A,(IX+dd) */
2035 tStates += 19;
2036 adr = IX + (signed char) GetBYTE_pp(PC);
2037 temp = GetBYTE(adr);
2038 acu = hreg(AF);
2039 sum = acu + temp;
2040 cbits = acu ^ temp ^ sum;
2041 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2042 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2043 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2044 ((cbits >> 8) & 1);
2045 break;
2046 case 0x8C: /* ADC A,IXH */
2047 tStates += 9;
2048 temp = hreg(IX);
2049 acu = hreg(AF);
2050 sum = acu + temp + TSTFLAG(C);
2051 cbits = acu ^ temp ^ sum;
2052 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2053 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2054 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2055 ((cbits >> 8) & 1);
2056 break;
2057 case 0x8D: /* ADC A,IXL */
2058 tStates += 9;
2059 temp = lreg(IX);
2060 acu = hreg(AF);
2061 sum = acu + temp + TSTFLAG(C);
2062 cbits = acu ^ temp ^ sum;
2063 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2064 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2065 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2066 ((cbits >> 8) & 1);
2067 break;
2068 case 0x8E: /* ADC A,(IX+dd) */
2069 tStates += 19;
2070 adr = IX + (signed char) GetBYTE_pp(PC);
2071 temp = GetBYTE(adr);
2072 acu = hreg(AF);
2073 sum = acu + temp + TSTFLAG(C);
2074 cbits = acu ^ temp ^ sum;
2075 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2076 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2077 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2078 ((cbits >> 8) & 1);
2079 break;
2080 case 0x94: /* SUB IXH */
2081 tStates += 9;
2082 temp = hreg(IX);
2083 acu = hreg(AF);
2084 sum = acu - temp;
2085 cbits = acu ^ temp ^ sum;
2086 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2087 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2088 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2089 ((cbits >> 8) & 1);
2090 break;
2091 case 0x95: /* SUB IXL */
2092 tStates += 9;
2093 temp = lreg(IX);
2094 acu = hreg(AF);
2095 sum = acu - temp;
2096 cbits = acu ^ temp ^ sum;
2097 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2098 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2099 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2100 ((cbits >> 8) & 1);
2101 break;
2102 case 0x96: /* SUB (IX+dd) */
2103 tStates += 19;
2104 adr = IX + (signed char) GetBYTE_pp(PC);
2105 temp = GetBYTE(adr);
2106 acu = hreg(AF);
2107 sum = acu - temp;
2108 cbits = acu ^ temp ^ sum;
2109 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2110 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2111 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2112 ((cbits >> 8) & 1);
2113 break;
2114 case 0x9C: /* SBC A,IXH */
2115 tStates += 9;
2116 temp = hreg(IX);
2117 acu = hreg(AF);
2118 sum = acu - temp - TSTFLAG(C);
2119 cbits = acu ^ temp ^ sum;
2120 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2121 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2122 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2123 ((cbits >> 8) & 1);
2124 break;
2125 case 0x9D: /* SBC A,IXL */
2126 tStates += 9;
2127 temp = lreg(IX);
2128 acu = hreg(AF);
2129 sum = acu - temp - TSTFLAG(C);
2130 cbits = acu ^ temp ^ sum;
2131 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2132 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2133 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2134 ((cbits >> 8) & 1);
2135 break;
2136 case 0x9E: /* SBC A,(IX+dd) */
2137 tStates += 19;
2138 adr = IX + (signed char) GetBYTE_pp(PC);
2139 temp = GetBYTE(adr);
2140 acu = hreg(AF);
2141 sum = acu - temp - TSTFLAG(C);
2142 cbits = acu ^ temp ^ sum;
2143 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2144 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2145 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2146 ((cbits >> 8) & 1);
2147 break;
2148 case 0xA4: /* AND IXH */
2149 tStates += 9;
2150 sum = ((AF & (IX)) >> 8) & 0xff;
2151 AF = (sum << 8) | (sum & 0xa8) |
2152 ((sum == 0) << 6) | 0x10 | partab[sum];
2153 break;
2154 case 0xA5: /* AND IXL */
2155 tStates += 9;
2156 sum = ((AF >> 8) & IX) & 0xff;
2157 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
2158 ((sum == 0) << 6) | partab[sum];
2159 break;
2160 case 0xA6: /* AND (IX+dd) */
2161 tStates += 19;
2162 adr = IX + (signed char) GetBYTE_pp(PC);
2163 sum = ((AF >> 8) & GetBYTE(adr)) & 0xff;
2164 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
2165 ((sum == 0) << 6) | partab[sum];
2166 break;
2167 case 0xAC: /* XOR IXH */
2168 tStates += 9;
2169 sum = ((AF ^ (IX)) >> 8) & 0xff;
2170 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
2171 break;
2172 case 0xAD: /* XOR IXL */
2173 tStates += 9;
2174 sum = ((AF >> 8) ^ IX) & 0xff;
2175 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
2176 break;
2177 case 0xAE: /* XOR (IX+dd) */
2178 tStates += 19;
2179 adr = IX + (signed char) GetBYTE_pp(PC);
2180 sum = ((AF >> 8) ^ GetBYTE(adr)) & 0xff;
2181 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
2182 break;
2183 case 0xB4: /* OR IXH */
2184 tStates += 9;
2185 sum = ((AF | (IX)) >> 8) & 0xff;
2186 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
2187 break;
2188 case 0xB5: /* OR IXL */
2189 tStates += 9;
2190 sum = ((AF >> 8) | IX) & 0xff;
2191 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
2192 break;
2193 case 0xB6: /* OR (IX+dd) */
2194 tStates += 19;
2195 adr = IX + (signed char) GetBYTE_pp(PC);
2196 sum = ((AF >> 8) | GetBYTE(adr)) & 0xff;
2197 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
2198 break;
2199 case 0xBC: /* CP IXH */
2200 tStates += 9;
2201 temp = hreg(IX);
2202 AF = (AF & ~0x28) | (temp & 0x28);
2203 acu = hreg(AF);
2204 sum = acu - temp;
2205 cbits = acu ^ temp ^ sum;
2206 AF = (AF & ~0xff) | (sum & 0x80) |
2207 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
2208 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2209 (cbits & 0x10) | ((cbits >> 8) & 1);
2210 break;
2211 case 0xBD: /* CP IXL */
2212 tStates += 9;
2213 temp = lreg(IX);
2214 AF = (AF & ~0x28) | (temp & 0x28);
2215 acu = hreg(AF);
2216 sum = acu - temp;
2217 cbits = acu ^ temp ^ sum;
2218 AF = (AF & ~0xff) | (sum & 0x80) |
2219 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
2220 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2221 (cbits & 0x10) | ((cbits >> 8) & 1);
2222 break;
2223 case 0xBE: /* CP (IX+dd) */
2224 tStates += 19;
2225 adr = IX + (signed char) GetBYTE_pp(PC);
2226 temp = GetBYTE(adr);
2227 AF = (AF & ~0x28) | (temp & 0x28);
2228 acu = hreg(AF);
2229 sum = acu - temp;
2230 cbits = acu ^ temp ^ sum;
2231 AF = (AF & ~0xff) | (sum & 0x80) |
2232 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
2233 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2234 (cbits & 0x10) | ((cbits >> 8) & 1);
2235 break;
2236 case 0xCB: /* CB prefix */
2237 adr = IX + (signed char) GetBYTE_pp(PC);
2238 switch ((op = GetBYTE(PC)) & 7) {
2239 /*
2240 * default: supresses compiler warning: "warning:
2241 * 'acu' may be used uninitialized in this function"
2242 */
2243 default:
2244 case 0: ++PC; acu = hreg(BC); break;
2245 case 1: ++PC; acu = lreg(BC); break;
2246 case 2: ++PC; acu = hreg(DE); break;
2247 case 3: ++PC; acu = lreg(DE); break;
2248 case 4: ++PC; acu = hreg(HL); break;
2249 case 5: ++PC; acu = lreg(HL); break;
2250 case 6: ++PC; acu = GetBYTE(adr); break;
2251 case 7: ++PC; acu = hreg(AF); break;
2252 }
2253 switch (op & 0xc0) {
2254 /*
2255 * Use default to supress compiler warning: "warning:
2256 * 'temp' may be used uninitialized in this function"
2257 */
2258 default:
2259 case 0x00: /* shift/rotate */
2260 switch (op & 0x38) {
2261 /*
2262 * Use default: to supress compiler warning
2263 * about 'temp' being used uninitialized
2264 */
2265 default:
2266 case 0x00: /* RLC */
2267 temp = (acu << 1) | (acu >> 7);
2268 cbits = temp & 1;
2269 goto cbshflg2;
2270 case 0x08: /* RRC */
2271 temp = (acu >> 1) | (acu << 7);
2272 cbits = temp & 0x80;
2273 goto cbshflg2;
2274 case 0x10: /* RL */
2275 temp = (acu << 1) | TSTFLAG(C);
2276 cbits = acu & 0x80;
2277 goto cbshflg2;
2278 case 0x18: /* RR */
2279 temp = (acu >> 1) | (TSTFLAG(C) << 7);
2280 cbits = acu & 1;
2281 goto cbshflg2;
2282 case 0x20: /* SLA */
2283 temp = acu << 1;
2284 cbits = acu & 0x80;
2285 goto cbshflg2;
2286 case 0x28: /* SRA */
2287 temp = (acu >> 1) | (acu & 0x80);
2288 cbits = acu & 1;
2289 goto cbshflg2;
2290 case 0x30: /* SLIA */
2291 temp = (acu << 1) | 1;
2292 cbits = acu & 0x80;
2293 goto cbshflg2;
2294 case 0x38: /* SRL */
2295 temp = acu >> 1;
2296 cbits = acu & 1;
2297 cbshflg2:
2298 AF = (AF & ~0xff) | (temp & 0xa8) |
2299 (((temp & 0xff) == 0) << 6) |
2300 parity(temp) | !!cbits;
2301 }
2302 break;
2303 case 0x40: /* BIT */
2304 tStates += 20;
2305 if (acu & (1 << ((op >> 3) & 7)))
2306 AF = (AF & ~0xfe) | 0x10 |
2307 (((op & 0x38) == 0x38) << 7);
2308 else
2309 AF = (AF & ~0xfe) | 0x54;
2310 if ((op&7) != 6)
2311 AF |= (acu & 0x28);
2312 temp = acu;
2313 break;
2314 case 0x80: /* RES */
2315 tStates += 23;
2316 temp = acu & ~(1 << ((op >> 3) & 7));
2317 break;
2318 case 0xc0: /* SET */
2319 tStates += 23;
2320 temp = acu | (1 << ((op >> 3) & 7));
2321 break;
2322 }
2323 switch (op & 7) {
2324 case 0: Sethreg(BC, temp); break;
2325 case 1: Setlreg(BC, temp); break;
2326 case 2: Sethreg(DE, temp); break;
2327 case 3: Setlreg(DE, temp); break;
2328 case 4: Sethreg(HL, temp); break;
2329 case 5: Setlreg(HL, temp); break;
2330 case 6: PutBYTE(adr, temp); break;
2331 case 7: Sethreg(AF, temp); break;
2332 }
2333 break;
2334 case 0xE1: /* POP IX */
2335 tStates += 14;
2336 POP(IX);
2337 break;
2338 case 0xE3: /* EX (SP),IX */
2339 tStates += 23;
2340 temp = IX; POP(IX); PUSH(temp);
2341 break;
2342 case 0xE5: /* PUSH IX */
2343 tStates += 15;
2344 PUSH(IX);
2345 break;
2346 case 0xE9: /* JP (IX) */
2347 tStates += 8;
2348 PC = IX;
2349 break;
2350 case 0xF9: /* LD SP,IX */
2351 tStates += 10;
2352 SP = IX;
2353 break;
2354 default: PC--; /* ignore DD */
2355 }
2356 break;
2357 case 0xDE: /* SBC A,nn */
2358 tStates += 7;
2359 temp = GetBYTE_pp(PC);
2360 acu = hreg(AF);
2361 sum = acu - temp - TSTFLAG(C);
2362 cbits = acu ^ temp ^ sum;
2363 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
2364 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
2365 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
2366 ((cbits >> 8) & 1);
2367 break;
2368 case 0xDF: /* RST 18H */
2369 tStates += 11;
2370 PUSH(PC); PC = 0x18;
2371 break;
2372 case 0xE0: /* RET PO */
2373 if (!TSTFLAG(P)) {
2374 POP(PC);
2375 tStates += 11;
2376 } else {
2377 tStates += 5;
2378 }
2379 break;
2380 case 0xE1: /* POP HL */
2381 tStates += 10;
2382 POP(HL);
2383 break;
2384 case 0xE2: /* JP PO,nnnn */
2385 JPC(!TSTFLAG(P)); /* also updates tStates */
2386 break;
2387 case 0xE3: /* EX (SP),HL */
2388 tStates += 19;
2389 temp = HL; POP(HL); PUSH(temp);
2390 break;
2391 case 0xE4: /* CALL PO,nnnn */
2392 CALLC(!TSTFLAG(P)); /* also updates tStates */
2393 break;
2394 case 0xE5: /* PUSH HL */
2395 tStates += 11;
2396 PUSH(HL);
2397 break;
2398 case 0xE6: /* AND nn */
2399 tStates += 7;
2400 sum = ((AF >> 8) & GetBYTE_pp(PC)) & 0xff;
2401 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
2402 ((sum == 0) << 6) | partab[sum];
2403 break;
2404 case 0xE7: /* RST 20H */
2405 tStates += 11;
2406 PUSH(PC); PC = 0x20;
2407 break;
2408 case 0xE8: /* RET PE */
2409 if (TSTFLAG(P)) {
2410 POP(PC);
2411 tStates += 11;
2412 } else {
2413 tStates += 5;
2414 }
2415 break;
2416 case 0xE9: /* JP (HL) */
2417 tStates += 4;
2418 PC = HL;
2419 break;
2420 case 0xEA: /* JP PE,nnnn */
2421 JPC(TSTFLAG(P)); /* also updates tStates */
2422 break;
2423 case 0xEB: /* EX DE,HL */
2424 tStates += 4;
2425 temp = HL; HL = DE; DE = temp;
2426 break;
2427 case 0xEC: /* CALL PE,nnnn */
2428 CALLC(TSTFLAG(P)); /* also updates tStates */
2429 break;
2430 case 0xED: /* ED prefix */
2431 switch (op = GetBYTE_pp(PC)) {
2432 case 0x40: /* IN B,(C) */
2433 tStates += 12;
2434 temp = Input(lreg(BC));
2435 Sethreg(BC, temp);
2436 AF = (AF & ~0xfe) | (temp & 0xa8) |
2437 (((temp & 0xff) == 0) << 6) |
2438 parity(temp);
2439 break;
2440 case 0x41: /* OUT (C),B */
2441 tStates += 12;
2442 Output(lreg(BC), hreg(BC));
2443 break;
2444 case 0x42: /* SBC HL,BC */
2445 tStates += 15;
2446 HL &= 0xffff;
2447 BC &= 0xffff;
2448 sum = HL - BC - TSTFLAG(C);
2449 cbits = (HL ^ BC ^ sum) >> 8;
2450 HL = sum;
2451 AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
2452 (((sum & 0xffff) == 0) << 6) |
2453 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2454 (cbits & 0x10) | 2 | ((cbits >> 8) & 1);
2455 break;
2456 case 0x43: /* LD (nnnn),BC */
2457 tStates += 20;
2458 temp = GetWORD(PC);
2459 PutWORD(temp, BC);
2460 PC += 2;
2461 break;
2462 case 0x44: /* NEG */
2463 temp = hreg(AF);
2464 AF = (-(AF & 0xff00) & 0xff00);
2465 AF |= ((AF >> 8) & 0xa8) | (((AF & 0xff00) == 0) << 6) |
2466 (((temp & 0x0f) != 0) << 4) | ((temp == 0x80) << 2) |
2467 2 | (temp != 0);
2468 break;
2469 case 0x45: /* RETN */
2470 tStates += 14;
2471 IFF |= IFF >> 1;
2472 POP(PC);
2473 break;
2474 case 0x46: /* IM 0 */
2475 tStates += 8;
2476 /* interrupt mode 0 */
2477 break;
2478 case 0x47: /* LD I,A */
2479 tStates += 9;
2480 ir = (ir & 255) | (AF & ~255);
2481 break;
2482 case 0x48: /* IN C,(C) */
2483 tStates += 12;
2484 temp = Input(lreg(BC));
2485 Setlreg(BC, temp);
2486 AF = (AF & ~0xfe) | (temp & 0xa8) |
2487 (((temp & 0xff) == 0) << 6) |
2488 parity(temp);
2489 break;
2490 case 0x49: /* OUT (C),C */
2491 tStates += 12;
2492 Output(lreg(BC), BC);
2493 break;
2494 case 0x4A: /* ADC HL,BC */
2495 tStates += 15;
2496 HL &= 0xffff;
2497 BC &= 0xffff;
2498 sum = HL + BC + TSTFLAG(C);
2499 cbits = (HL ^ BC ^ sum) >> 8;
2500 HL = sum;
2501 AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
2502 (((sum & 0xffff) == 0) << 6) |
2503 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2504 (cbits & 0x10) | ((cbits >> 8) & 1);
2505 break;
2506 case 0x4B: /* LD BC,(nnnn) */
2507 tStates += 20;
2508 temp = GetWORD(PC);
2509 BC = GetWORD(temp);
2510 PC += 2;
2511 break;
2512 case 0x4D: /* RETI */
2513 tStates += 14;
2514 IFF |= IFF >> 1;
2515 POP(PC);
2516 break;
2517 case 0x4F: /* LD R,A */
2518 tStates += 9;
2519 ir = (ir & ~255) | ((AF >> 8) & 255);
2520 break;
2521 case 0x50: /* IN D,(C) */
2522 tStates += 12;
2523 temp = Input(lreg(BC));
2524 Sethreg(DE, temp);
2525 AF = (AF & ~0xfe) | (temp & 0xa8) |
2526 (((temp & 0xff) == 0) << 6) |
2527 parity(temp);
2528 break;
2529 case 0x51: /* OUT (C),D */
2530 tStates += 12;
2531 Output(lreg(BC), hreg(DE));
2532 break;
2533 case 0x52: /* SBC HL,DE */
2534 tStates += 15;
2535 HL &= 0xffff;
2536 DE &= 0xffff;
2537 sum = HL - DE - TSTFLAG(C);
2538 cbits = (HL ^ DE ^ sum) >> 8;
2539 HL = sum;
2540 AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
2541 (((sum & 0xffff) == 0) << 6) |
2542 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2543 (cbits & 0x10) | 2 | ((cbits >> 8) & 1);
2544 break;
2545 case 0x53: /* LD (nnnn),DE */
2546 tStates += 20;
2547 temp = GetWORD(PC);
2548 PutWORD(temp, DE);
2549 PC += 2;
2550 break;
2551 case 0x56: /* IM 1 */
2552 tStates += 8;
2553 /* interrupt mode 1 */
2554 break;
2555 case 0x57: /* LD A,I */
2556 tStates += 9;
2557 AF = (AF & 0x29) | (ir & ~255) | ((ir >> 8) & 0x80) | (((ir & ~255) == 0) << 6) | ((IFF & 2) << 1);
2558 break;
2559 case 0x58: /* IN E,(C) */
2560 tStates += 12;
2561 temp = Input(lreg(BC));
2562 Setlreg(DE, temp);
2563 AF = (AF & ~0xfe) | (temp & 0xa8) |
2564 (((temp & 0xff) == 0) << 6) |
2565 parity(temp);
2566 break;
2567 case 0x59: /* OUT (C),E */
2568 tStates += 12;
2569 Output(lreg(BC), DE);
2570 break;
2571 case 0x5A: /* ADC HL,DE */
2572 tStates += 15;
2573 HL &= 0xffff;
2574 DE &= 0xffff;
2575 sum = HL + DE + TSTFLAG(C);
2576 cbits = (HL ^ DE ^ sum) >> 8;
2577 HL = sum;
2578 AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
2579 (((sum & 0xffff) == 0) << 6) |
2580 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2581 (cbits & 0x10) | ((cbits >> 8) & 1);
2582 break;
2583 case 0x5B: /* LD DE,(nnnn) */
2584 tStates += 20;
2585 temp = GetWORD(PC);
2586 DE = GetWORD(temp);
2587 PC += 2;
2588 break;
2589 case 0x5E: /* IM 2 */
2590 tStates += 8;
2591 /* interrupt mode 2 */
2592 break;
2593 case 0x5F: /* LD A,R */
2594 tStates += 9;
2595 AF = (AF & 0x29) | ((ir & 255) << 8) | (ir & 0x80) | (((ir & 255) == 0) << 6) | ((IFF & 2) << 1);
2596 break;
2597 case 0x60: /* IN H,(C) */
2598 tStates += 12;
2599 temp = Input(lreg(BC));
2600 Sethreg(HL, temp);
2601 AF = (AF & ~0xfe) | (temp & 0xa8) |
2602 (((temp & 0xff) == 0) << 6) |
2603 parity(temp);
2604 break;
2605 case 0x61: /* OUT (C),H */
2606 tStates += 12;
2607 Output(lreg(BC), hreg(HL));
2608 break;
2609 case 0x62: /* SBC HL,HL */
2610 tStates += 15;
2611 HL &= 0xffff;
2612 sum = HL - HL - TSTFLAG(C);
2613 cbits = (HL ^ HL ^ sum) >> 8;
2614 HL = sum;
2615 AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
2616 (((sum & 0xffff) == 0) << 6) |
2617 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2618 (cbits & 0x10) | 2 | ((cbits >> 8) & 1);
2619 break;
2620 case 0x63: /* LD (nnnn),HL */
2621 tStates += 20;
2622 temp = GetWORD(PC);
2623 PutWORD(temp, HL);
2624 PC += 2;
2625 break;
2626 case 0x67: /* RRD */
2627 tStates += 18;
2628 temp = GetBYTE(HL);
2629 acu = hreg(AF);
2630 PutBYTE(HL, hdig(temp) | (ldig(acu) << 4));
2631 acu = (acu & 0xf0) | ldig(temp);
2632 AF = (acu << 8) | (acu & 0xa8) | (((acu & 0xff) == 0) << 6) |
2633 partab[acu] | (AF & 1);
2634 break;
2635 case 0x68: /* IN L,(C) */
2636 tStates += 12;
2637 temp = Input(lreg(BC));
2638 Setlreg(HL, temp);
2639 AF = (AF & ~0xfe) | (temp & 0xa8) |
2640 (((temp & 0xff) == 0) << 6) |
2641 parity(temp);
2642 break;
2643 case 0x69: /* OUT (C),L */
2644 tStates += 12;
2645 Output(lreg(BC), lreg(HL));
2646 break;
2647 case 0x6A: /* ADC HL,HL */
2648 tStates += 15;
2649 HL &= 0xffff;
2650 sum = HL + HL + TSTFLAG(C);
2651 cbits = (HL ^ HL ^ sum) >> 8;
2652 HL = sum;
2653 AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
2654 (((sum & 0xffff) == 0) << 6) |
2655 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2656 (cbits & 0x10) | ((cbits >> 8) & 1);
2657 break;
2658 case 0x6B: /* LD HL,(nnnn) */
2659 tStates += 20;
2660 temp = GetWORD(PC);
2661 HL = GetWORD(temp);
2662 PC += 2;
2663 break;
2664 case 0x6F: /* RLD */
2665 tStates += 18;
2666 temp = GetBYTE(HL);
2667 acu = hreg(AF);
2668 PutBYTE(HL, (ldig(temp) << 4) | ldig(acu));
2669 acu = (acu & 0xf0) | hdig(temp);
2670 AF = (acu << 8) | (acu & 0xa8) | (((acu & 0xff) == 0) << 6) |
2671 partab[acu] | (AF & 1);
2672 break;
2673 case 0x70: /* IN (C) */
2674 tStates += 12;
2675 temp = Input(lreg(BC));
2676 Setlreg(temp, temp);
2677 AF = (AF & ~0xfe) | (temp & 0xa8) |
2678 (((temp & 0xff) == 0) << 6) |
2679 parity(temp);
2680 break;
2681 case 0x71: /* OUT (C),0 */
2682 tStates += 12;
2683 Output(lreg(BC), 0);
2684 break;
2685 case 0x72: /* SBC HL,SP */
2686 tStates += 15;
2687 HL &= 0xffff;
2688 SP &= 0xffff;
2689 sum = HL - SP - TSTFLAG(C);
2690 cbits = (HL ^ SP ^ sum) >> 8;
2691 HL = sum;
2692 AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
2693 (((sum & 0xffff) == 0) << 6) |
2694 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2695 (cbits & 0x10) | 2 | ((cbits >> 8) & 1);
2696 break;
2697 case 0x73: /* LD (nnnn),SP */
2698 tStates += 20;
2699 temp = GetWORD(PC);
2700 PutWORD(temp, SP);
2701 PC += 2;
2702 break;
2703 case 0x78: /* IN A,(C) */
2704 tStates += 12;
2705 temp = Input(lreg(BC));
2706 Sethreg(AF, temp);
2707 AF = (AF & ~0xfe) | (temp & 0xa8) |
2708 (((temp & 0xff) == 0) << 6) |
2709 parity(temp);
2710 break;
2711 case 0x79: /* OUT (C),A */
2712 Output(lreg(BC), hreg(AF));
2713 break;
2714 case 0x7A: /* ADC HL,SP */
2715 tStates += 15;
2716 HL &= 0xffff;
2717 SP &= 0xffff;
2718 sum = HL + SP + TSTFLAG(C);
2719 cbits = (HL ^ SP ^ sum) >> 8;
2720 HL = sum;
2721 AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
2722 (((sum & 0xffff) == 0) << 6) |
2723 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
2724 (cbits & 0x10) | ((cbits >> 8) & 1);
2725 break;
2726 case 0x7B: /* LD SP,(nnnn) */
2727 tStates += 20;
2728 temp = GetWORD(PC);
2729 SP = GetWORD(temp);
2730 PC += 2;
2731 break;
2732 case 0xA0: /* LDI */
2733 tStates += 16;
2734 acu = GetBYTE_pp(HL);
2735 PutBYTE_pp(DE, acu);
2736 acu += hreg(AF);
2737 AF = (AF & ~0x3e) | (acu & 8) | ((acu & 2) << 4) |
2738 (((--BC & 0xffff) != 0) << 2);
2739 break;
2740 case 0xA1: /* CPI */
2741 tStates += 16;
2742 acu = hreg(AF);
2743 temp = GetBYTE_pp(HL);
2744 sum = acu - temp;
2745 cbits = acu ^ temp ^ sum;
2746 AF = (AF & ~0xfe) | (sum & 0x80) | (!(sum & 0xff) << 6) |
2747 (((sum - ((cbits&16)>>4))&2) << 4) | (cbits & 16) |
2748 ((sum - ((cbits >> 4) & 1)) & 8) |
2749 ((--BC & 0xffff) != 0) << 2 | 2;
2750 if ((sum & 15) == 8 && (cbits & 16) != 0)
2751 AF &= ~8;
2752 break;
2753 case 0xA2: /* INI */
2754 tStates += 16;
2755 PutBYTE(HL, Input(lreg(BC))); ++HL;
2756 SETFLAG(N, 1);
2757 /* SETFLAG(P, (--BC & 0xffff) != 0); deleted */
2758 Sethreg(BC, lreg(BC) - 1); /* added at 2019-03-23 */
2759 SETFLAG(Z, lreg(BC) == 0); /* added at 2019-03-23 */
2760 break;
2761 case 0xA3: /* OUTI */
2762 tStates += 16;
2763 Output(lreg(BC), GetBYTE(HL)); ++HL;
2764 SETFLAG(N, 1);
2765 Sethreg(BC, hreg(BC) - 1);
2766 SETFLAG(Z, hreg(BC) == 0);
2767 break;
2768 case 0xA8: /* LDD */
2769 tStates += 16;
2770 acu = GetBYTE_mm(HL);
2771 PutBYTE_mm(DE, acu);
2772 acu += hreg(AF);
2773 AF = (AF & ~0x3e) | (acu & 8) | ((acu & 2) << 4) |
2774 (((--BC & 0xffff) != 0) << 2);
2775 break;
2776 case 0xA9: /* CPD */
2777 tStates += 16;
2778 acu = hreg(AF);
2779 temp = GetBYTE_mm(HL);
2780 sum = acu - temp;
2781 cbits = acu ^ temp ^ sum;
2782 AF = (AF & ~0xfe) | (sum & 0x80) | (!(sum & 0xff) << 6) |
2783 (((sum - ((cbits&16)>>4))&2) << 4) | (cbits & 16) |
2784 ((sum - ((cbits >> 4) & 1)) & 8) |
2785 ((--BC & 0xffff) != 0) << 2 | 2;
2786 if ((sum & 15) == 8 && (cbits & 16) != 0)
2787 AF &= ~8;
2788 break;
2789 case 0xAA: /* IND */
2790 tStates += 16;
2791 PutBYTE(HL, Input(lreg(BC))); --HL;
2792 SETFLAG(N, 1);
2793 Sethreg(BC, lreg(BC) - 1);
2794 SETFLAG(Z, lreg(BC) == 0);
2795 break;
2796 case 0xAB: /* OUTD */
2797 tStates += 16;
2798 Output(lreg(BC), GetBYTE(HL)); --HL;
2799 SETFLAG(N, 1);
2800 Sethreg(BC, hreg(BC) - 1);
2801 SETFLAG(Z, hreg(BC) == 0);
2802 break;
2803 case 0xB0: /* LDIR */
2804 tStates -= 5;;
2805 acu = hreg(AF);
2806 BC &= 0xffff;
2807 if (BC == 0)
2808 BC = 0x10000;
2809 do {
2810 tStates += 21;
2811 acu = GetBYTE_pp(HL);
2812 PutBYTE_pp(DE, acu);
2813 } while (--BC);
2814 acu += hreg(AF);
2815 AF = (AF & ~0x3e) | (acu & 8) | ((acu & 2) << 4);
2816 break;
2817 case 0xB1: /* CPIR */
2818 tStates -= 5;
2819 acu = hreg(AF);
2820 BC &= 0xffff;
2821 if (BC == 0)
2822 BC = 0x10000;
2823 do {
2824 tStates += 21;
2825 temp = GetBYTE_pp(HL);
2826 op = --BC != 0;
2827 sum = acu - temp;
2828 } while (op && sum != 0);
2829 cbits = acu ^ temp ^ sum;
2830 AF = (AF & ~0xfe) | (sum & 0x80) | (!(sum & 0xff) << 6) |
2831 (((sum - ((cbits&16)>>4))&2) << 4) |
2832 (cbits & 16) | ((sum - ((cbits >> 4) & 1)) & 8) |
2833 op << 2 | 2;
2834 if ((sum & 15) == 8 && (cbits & 16) != 0)
2835 AF &= ~8;
2836 break;
2837 case 0xB2: /* INIR */
2838 tStates -= 5;
2839 temp = hreg(BC);
2840 do {
2841 tStates += 21;
2842 PutBYTE(HL, Input(lreg(BC))); ++HL;
2843 } while (--temp);
2844 Sethreg(BC, 0);
2845 SETFLAG(N, 1);
2846 SETFLAG(Z, 1);
2847 break;
2848 case 0xB3: /* OTIR */
2849 tStates -= 5;
2850 temp = hreg(BC);
2851 do {
2852 tStates += 21;
2853 Output(lreg(BC), GetBYTE(HL)); ++HL;
2854 } while (--temp);
2855 Sethreg(BC, 0);
2856 SETFLAG(N, 1);
2857 SETFLAG(Z, 1);
2858 break;
2859 case 0xB8: /* LDDR */
2860 tStates -= 5;
2861 BC &= 0xffff;
2862 if (BC == 0)
2863 BC = 0x10000;
2864 do {
2865 tStates += 21;
2866 tStates += 21;
2867 acu = GetBYTE_mm(HL);
2868 PutBYTE_mm(DE, acu);
2869 } while (--BC);
2870 acu += hreg(AF);
2871 AF = (AF & ~0x3e) | (acu & 8) | ((acu & 2) << 4);
2872 break;
2873 case 0xB9: /* CPDR */
2874 tStates -= 5;
2875 acu = hreg(AF);
2876 BC &= 0xffff;
2877 if (BC == 0)
2878 BC = 0x10000;
2879 do {
2880 tStates += 21;
2881 temp = GetBYTE_mm(HL);
2882 op = --BC != 0;
2883 sum = acu - temp;
2884 } while (op && sum != 0);
2885 cbits = acu ^ temp ^ sum;
2886 AF = (AF & ~0xfe) | (sum & 0x80) | (!(sum & 0xff) << 6) |
2887 (((sum - ((cbits&16)>>4))&2) << 4) |
2888 (cbits & 16) | ((sum - ((cbits >> 4) & 1)) & 8) |
2889 op << 2 | 2;
2890 if ((sum & 15) == 8 && (cbits & 16) != 0)
2891 AF &= ~8;
2892 break;
2893 case 0xBA: /* INDR */
2894 tStates -= 5;
2895 temp = hreg(BC);
2896 do {
2897 tStates += 21;
2898 PutBYTE(HL, Input(lreg(BC))); --HL;
2899 } while (--temp);
2900 Sethreg(BC, 0);
2901 SETFLAG(N, 1);
2902 SETFLAG(Z, 1);
2903 break;
2904 case 0xBB: /* OTDR */
2905 tStates -= 5;
2906 temp = hreg(BC);
2907 do {
2908 tStates += 21;
2909 Output(lreg(BC), GetBYTE(HL));
2910 --HL;
2911 } while (--temp);
2912 Sethreg(BC, 0);
2913 SETFLAG(N, 1);
2914 SETFLAG(Z, 1);
2915 break;
2916 default: if (0x40 <= op && op <= 0x7f) PC--; /* ignore ED */
2917 }
2918 break;
2919 case 0xEE: /* XOR nn */
2920 tStates += 7;
2921 sum = ((AF >> 8) ^ GetBYTE_pp(PC)) & 0xff;
2922 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
2923 break;
2924 case 0xEF: /* RST 28H */
2925 tStates += 11;
2926 PUSH(PC); PC = 0x28;
2927 break;
2928 case 0xF0: /* RET P */
2929 if (!TSTFLAG(S)) {
2930 POP(PC);
2931 tStates += 11;
2932 } else {
2933 tStates += 5;
2934 }
2935 break;
2936 case 0xF1: /* POP AF */
2937 tStates += 10;
2938 POP(AF);
2939 break;
2940 case 0xF2: /* JP P,nnnn */
2941 JPC(!TSTFLAG(S)); /* also updates tStates */
2942 break;
2943 case 0xF3: /* DI */
2944 tStates += 4;
2945 IFF = 0;
2946 break;
2947 case 0xF4: /* CALL P,nnnn */
2948 CALLC(!TSTFLAG(S)); /* also updates tStates */
2949 break;
2950 case 0xF5: /* PUSH AF */
2951 tStates += 11;
2952 PUSH(AF);
2953 break;
2954 case 0xF6: /* OR nn */
2955 tStates += 7;
2956 sum = ((AF >> 8) | GetBYTE_pp(PC)) & 0xff;
2957 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
2958 break;
2959 case 0xF7: /* RST 30H */
2960 tStates += 11;
2961 PUSH(PC); PC = 0x30;
2962 break;
2963 case 0xF8: /* RET M */
2964 if (TSTFLAG(S)) {
2965 POP(PC);
2966 tStates += 11;
2967 } else {
2968 tStates += 5;
2969 }
2970 break;
2971 case 0xF9: /* LD SP,HL */
2972 tStates += 6;
2973 SP = HL;
2974 break;
2975 case 0xFA: /* JP M,nnnn */
2976 JPC(TSTFLAG(S)); /* also updates tStates */
2977 break;
2978 case 0xFB: /* EI */
2979 tStates += 4;
2980 IFF = 3;
2981 break;
2982 case 0xFC: /* CALL M,nnnn */
2983 CALLC(TSTFLAG(S)); /* also updates tStates */
2984 break;
2985 case 0xFD: /* FD prefix */
2986 switch (op = GetBYTE_pp(PC)) {
2987 case 0x09: /* ADD IY,BC */
2988 tStates += 15;
2989 IY &= 0xffff;
2990 BC &= 0xffff;
2991 sum = IY + BC;
2992 cbits = (IY ^ BC ^ sum) >> 8;
2993 IY = sum;
2994 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
2995 (cbits & 0x10) | ((cbits >> 8) & 1);
2996 break;
2997 case 0x19: /* ADD IY,DE */
2998 tStates += 15;
2999 IY &= 0xffff;
3000 DE &= 0xffff;
3001 sum = IY + DE;
3002 cbits = (IY ^ DE ^ sum) >> 8;
3003 IY = sum;
3004 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
3005 (cbits & 0x10) | ((cbits >> 8) & 1);
3006 break;
3007 case 0x21: /* LD IY,nnnn */
3008 tStates += 14;
3009 IY = GetWORD(PC);
3010 PC += 2;
3011 break;
3012 case 0x22: /* LD (nnnn),IY */
3013 tStates += 20;
3014 temp = GetWORD(PC);
3015 PutWORD(temp, IY);
3016 PC += 2;
3017 break;
3018 case 0x23: /* INC IY */
3019 tStates += 10;
3020 ++IY;
3021 break;
3022 case 0x24: /* INC IYH */
3023 tStates += 9;
3024 IY += 0x100;
3025 temp = hreg(IY);
3026 AF = (AF & ~0xfe) | (temp & 0xa8) |
3027 (((temp & 0xff) == 0) << 6) |
3028 (((temp & 0xf) == 0) << 4) |
3029 ((temp == 0x80) << 2);
3030 break;
3031 case 0x25: /* DEC IYH */
3032 tStates += 9;
3033 IY -= 0x100;
3034 temp = hreg(IY);
3035 AF = (AF & ~0xfe) | (temp & 0xa8) |
3036 (((temp & 0xff) == 0) << 6) |
3037 (((temp & 0xf) == 0xf) << 4) |
3038 ((temp == 0x7f) << 2) | 2;
3039 break;
3040 case 0x26: /* LD IYH,nn */
3041 tStates += 9;
3042 Sethreg(IY, GetBYTE_pp(PC));
3043 break;
3044 case 0x29: /* ADD IY,IY */
3045 tStates += 15;
3046 IY &= 0xffff;
3047 sum = IY + IY;
3048 cbits = (IY ^ IY ^ sum) >> 8;
3049 IY = sum;
3050 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
3051 (cbits & 0x10) | ((cbits >> 8) & 1);
3052 break;
3053 case 0x2A: /* LD IY,(nnnn) */
3054 tStates += 20;
3055 temp = GetWORD(PC);
3056 IY = GetWORD(temp);
3057 PC += 2;
3058 break;
3059 case 0x2B: /* DEC IY */
3060 tStates += 10;
3061 --IY;
3062 break;
3063 case 0x2C: /* INC IYL */
3064 tStates += 9;
3065 temp = lreg(IY)+1;
3066 Setlreg(IY, temp);
3067 AF = (AF & ~0xfe) | (temp & 0xa8) |
3068 (((temp & 0xff) == 0) << 6) |
3069 (((temp & 0xf) == 0) << 4) |
3070 ((temp == 0x80) << 2);
3071 break;
3072 case 0x2D: /* DEC IYL */
3073 tStates += 9;
3074 temp = lreg(IY)-1;
3075 Setlreg(IY, temp);
3076 AF = (AF & ~0xfe) | (temp & 0xa8) |
3077 (((temp & 0xff) == 0) << 6) |
3078 (((temp & 0xf) == 0xf) << 4) |
3079 ((temp == 0x7f) << 2) | 2;
3080 break;
3081 case 0x2E: /* LD IYL,nn */
3082 tStates += 9;
3083 Setlreg(IY, GetBYTE_pp(PC));
3084 break;
3085 case 0x34: /* INC (IY+dd) */
3086 tStates += 23;
3087 adr = IY + (signed char) GetBYTE_pp(PC);
3088 temp = GetBYTE(adr)+1;
3089 PutBYTE(adr, temp);
3090 AF = (AF & ~0xfe) | (temp & 0xa8) |
3091 (((temp & 0xff) == 0) << 6) |
3092 (((temp & 0xf) == 0) << 4) |
3093 ((temp == 0x80) << 2);
3094 break;
3095 case 0x35: /* DEC (IY+dd) */
3096 tStates += 23;
3097 adr = IY + (signed char) GetBYTE_pp(PC);
3098 temp = GetBYTE(adr)-1;
3099 PutBYTE(adr, temp);
3100 AF = (AF & ~0xfe) | (temp & 0xa8) |
3101 (((temp & 0xff) == 0) << 6) |
3102 (((temp & 0xf) == 0xf) << 4) |
3103 ((temp == 0x7f) << 2) | 2;
3104 break;
3105 case 0x36: /* LD (IY+dd),nn */
3106 tStates += 19;
3107 adr = IY + (signed char) GetBYTE_pp(PC);
3108 PutBYTE(adr, GetBYTE_pp(PC));
3109 break;
3110 case 0x39: /* ADD IY,SP */
3111 tStates += 15;
3112 IY &= 0xffff;
3113 SP &= 0xffff;
3114 sum = IY + SP;
3115 cbits = (IY ^ SP ^ sum) >> 8;
3116 IY = sum;
3117 AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
3118 (cbits & 0x10) | ((cbits >> 8) & 1);
3119 break;
3120 case 0x44: /* LD B,IYH */
3121 tStates += 9;
3122 Sethreg(BC, hreg(IY));
3123 break;
3124 case 0x45: /* LD B,IYL */
3125 tStates += 9;
3126 Sethreg(BC, lreg(IY));
3127 break;
3128 case 0x46: /* LD B,(IY+dd) */
3129 tStates += 19;
3130 adr = IY + (signed char) GetBYTE_pp(PC);
3131 Sethreg(BC, GetBYTE(adr));
3132 break;
3133 case 0x4C: /* LD C,IYH */
3134 tStates += 9;
3135 Setlreg(BC, hreg(IY));
3136 break;
3137 case 0x4D: /* LD C,IYL */
3138 tStates += 9;
3139 Setlreg(BC, lreg(IY));
3140 break;
3141 case 0x4E: /* LD C,(IY+dd) */
3142 tStates += 19;
3143 adr = IY + (signed char) GetBYTE_pp(PC);
3144 Setlreg(BC, GetBYTE(adr));
3145 break;
3146 case 0x54: /* LD D,IYH */
3147 tStates += 9;
3148 Sethreg(DE, hreg(IY));
3149 break;
3150 case 0x55: /* LD D,IYL */
3151 tStates += 9;
3152 Sethreg(DE, lreg(IY));
3153 break;
3154 case 0x56: /* LD D,(IY+dd) */
3155 tStates += 19;
3156 adr = IY + (signed char) GetBYTE_pp(PC);
3157 Sethreg(DE, GetBYTE(adr));
3158 break;
3159 case 0x5C: /* LD E,IYH */
3160 tStates += 9;
3161 Setlreg(DE, hreg(IY));
3162 break;
3163 case 0x5D: /* LD E,IYL */
3164 Setlreg(DE, lreg(IY));
3165 break;
3166 case 0x5E: /* LD E,(IY+dd) */
3167 tStates += 19;
3168 adr = IY + (signed char) GetBYTE_pp(PC);
3169 Setlreg(DE, GetBYTE(adr));
3170 break;
3171 case 0x60: /* LD IYH,B */
3172 tStates += 9;
3173 Sethreg(IY, hreg(BC));
3174 break;
3175 case 0x61: /* LD IYH,C */
3176 tStates += 9;
3177 Sethreg(IY, lreg(BC));
3178 break;
3179 case 0x62: /* LD IYH,D */
3180 tStates += 9;
3181 Sethreg(IY, hreg(DE));
3182 break;
3183 case 0x63: /* LD IYH,E */
3184 tStates += 9;
3185 Sethreg(IY, lreg(DE));
3186 break;
3187 case 0x64: /* LD IYH,IYH */
3188 tStates += 9;
3189 /* nop */
3190 break;
3191 case 0x65: /* LD IYH,IYL */
3192 tStates += 9;
3193 Sethreg(IY, lreg(IY));
3194 break;
3195 case 0x66: /* LD H,(IY+dd) */
3196 tStates += 19;
3197 adr = IY + (signed char) GetBYTE_pp(PC);
3198 Sethreg(HL, GetBYTE(adr));
3199 break;
3200 case 0x67: /* LD IYH,A */
3201 tStates += 9;
3202 Sethreg(IY, hreg(AF));
3203 break;
3204 case 0x68: /* LD IYL,B */
3205 tStates += 9;
3206 Setlreg(IY, hreg(BC));
3207 break;
3208 case 0x69: /* LD IYL,C */
3209 tStates += 9;
3210 Setlreg(IY, lreg(BC));
3211 break;
3212 case 0x6A: /* LD IYL,D */
3213 tStates += 9;
3214 Setlreg(IY, hreg(DE));
3215 break;
3216 case 0x6B: /* LD IYL,E */
3217 tStates += 9;
3218 Setlreg(IY, lreg(DE));
3219 break;
3220 case 0x6C: /* LD IYL,IYH */
3221 tStates += 9;
3222 Setlreg(IY, hreg(IY));
3223 break;
3224 case 0x6D: /* LD IYL,IYL */
3225 tStates += 9;
3226 /* nop */
3227 break;
3228 case 0x6E: /* LD L,(IY+dd) */
3229 tStates += 19;
3230 adr = IY + (signed char) GetBYTE_pp(PC);
3231 Setlreg(HL, GetBYTE(adr));
3232 break;
3233 case 0x6F: /* LD IYL,A */
3234 tStates += 9;
3235 Setlreg(IY, hreg(AF));
3236 break;
3237 case 0x70: /* LD (IY+dd),B */
3238 tStates += 19;
3239 adr = IY + (signed char) GetBYTE_pp(PC);
3240 PutBYTE(adr, hreg(BC));
3241 break;
3242 case 0x71: /* LD (IY+dd),C */
3243 tStates += 19;
3244 adr = IY + (signed char) GetBYTE_pp(PC);
3245 PutBYTE(adr, lreg(BC));
3246 break;
3247 case 0x72: /* LD (IY+dd),D */
3248 tStates += 19;
3249 adr = IY + (signed char) GetBYTE_pp(PC);
3250 PutBYTE(adr, hreg(DE));
3251 break;
3252 case 0x73: /* LD (IY+dd),E */
3253 tStates += 19;
3254 adr = IY + (signed char) GetBYTE_pp(PC);
3255 PutBYTE(adr, lreg(DE));
3256 break;
3257 case 0x74: /* LD (IY+dd),H */
3258 tStates += 19;
3259 adr = IY + (signed char) GetBYTE_pp(PC);
3260 PutBYTE(adr, hreg(HL));
3261 break;
3262 case 0x75: /* LD (IY+dd),L */
3263 tStates += 19;
3264 adr = IY + (signed char) GetBYTE_pp(PC);
3265 PutBYTE(adr, lreg(HL));
3266 break;
3267 case 0x77: /* LD (IY+dd),A */
3268 tStates += 19;
3269 adr = IY + (signed char) GetBYTE_pp(PC);
3270 PutBYTE(adr, hreg(AF));
3271 break;
3272 case 0x7C: /* LD A,IYH */
3273 tStates += 9;
3274 Sethreg(AF, hreg(IY));
3275 break;
3276 case 0x7D: /* LD A,IYL */
3277 tStates += 9;
3278 Sethreg(AF, lreg(IY));
3279 break;
3280 case 0x7E: /* LD A,(IY+dd) */
3281 tStates += 19;
3282 adr = IY + (signed char) GetBYTE_pp(PC);
3283 Sethreg(AF, GetBYTE(adr));
3284 break;
3285 case 0x84: /* ADD A,IYH */
3286 tStates += 9;
3287 temp = hreg(IY);
3288 acu = hreg(AF);
3289 sum = acu + temp;
3290 cbits = acu ^ temp ^ sum;
3291 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3292 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3293 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
3294 ((cbits >> 8) & 1);
3295 break;
3296 case 0x85: /* ADD A,IYL */
3297 tStates += 9;
3298 temp = lreg(IY);
3299 acu = hreg(AF);
3300 sum = acu + temp;
3301 cbits = acu ^ temp ^ sum;
3302 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3303 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3304 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
3305 ((cbits >> 8) & 1);
3306 break;
3307 case 0x86: /* ADD A,(IY+dd) */
3308 tStates += 19;
3309 adr = IY + (signed char) GetBYTE_pp(PC);
3310 temp = GetBYTE(adr);
3311 acu = hreg(AF);
3312 sum = acu + temp;
3313 cbits = acu ^ temp ^ sum;
3314 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3315 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3316 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
3317 ((cbits >> 8) & 1);
3318 break;
3319 case 0x8C: /* ADC A,IYH */
3320 tStates += 9;
3321 temp = hreg(IY);
3322 acu = hreg(AF);
3323 sum = acu + temp + TSTFLAG(C);
3324 cbits = acu ^ temp ^ sum;
3325 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3326 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3327 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
3328 ((cbits >> 8) & 1);
3329 break;
3330 case 0x8D: /* ADC A,IYL */
3331 tStates += 9;
3332 temp = lreg(IY);
3333 acu = hreg(AF);
3334 sum = acu + temp + TSTFLAG(C);
3335 cbits = acu ^ temp ^ sum;
3336 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3337 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3338 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
3339 ((cbits >> 8) & 1);
3340 break;
3341 case 0x8E: /* ADC A,(IY+dd) */
3342 tStates += 19;
3343 adr = IY + (signed char) GetBYTE_pp(PC);
3344 temp = GetBYTE(adr);
3345 acu = hreg(AF);
3346 sum = acu + temp + TSTFLAG(C);
3347 cbits = acu ^ temp ^ sum;
3348 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3349 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3350 (((cbits >> 6) ^ (cbits >> 5)) & 4) |
3351 ((cbits >> 8) & 1);
3352 break;
3353 case 0x94: /* SUB IYH */
3354 tStates += 9;
3355 temp = hreg(IY);
3356 acu = hreg(AF);
3357 sum = acu - temp;
3358 cbits = acu ^ temp ^ sum;
3359 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3360 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3361 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3362 ((cbits >> 8) & 1);
3363 break;
3364 case 0x95: /* SUB IYL */
3365 tStates += 9;
3366 temp = lreg(IY);
3367 acu = hreg(AF);
3368 sum = acu - temp;
3369 cbits = acu ^ temp ^ sum;
3370 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3371 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3372 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3373 ((cbits >> 8) & 1);
3374 break;
3375 case 0x96: /* SUB (IY+dd) */
3376 tStates += 19;
3377 adr = IY + (signed char) GetBYTE_pp(PC);
3378 temp = GetBYTE(adr);
3379 acu = hreg(AF);
3380 sum = acu - temp;
3381 cbits = acu ^ temp ^ sum;
3382 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3383 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3384 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3385 ((cbits >> 8) & 1);
3386 break;
3387 case 0x9C: /* SBC A,IYH */
3388 tStates += 9;
3389 temp = hreg(IY);
3390 acu = hreg(AF);
3391 sum = acu - temp - TSTFLAG(C);
3392 cbits = acu ^ temp ^ sum;
3393 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3394 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3395 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3396 ((cbits >> 8) & 1);
3397 break;
3398 case 0x9D: /* SBC A,IYL */
3399 tStates += 9;
3400 temp = lreg(IY);
3401 acu = hreg(AF);
3402 sum = acu - temp - TSTFLAG(C);
3403 cbits = acu ^ temp ^ sum;
3404 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3405 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3406 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3407 ((cbits >> 8) & 1);
3408 break;
3409 case 0x9E: /* SBC A,(IY+dd) */
3410 tStates += 19;
3411 adr = IY + (signed char) GetBYTE_pp(PC);
3412 temp = GetBYTE(adr);
3413 acu = hreg(AF);
3414 sum = acu - temp - TSTFLAG(C);
3415 cbits = acu ^ temp ^ sum;
3416 AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
3417 (((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
3418 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3419 ((cbits >> 8) & 1);
3420 break;
3421 case 0xA4: /* AND IYH */
3422 tStates += 9;
3423 sum = ((AF & (IY)) >> 8) & 0xff;
3424 AF = (sum << 8) | (sum & 0xa8) |
3425 ((sum == 0) << 6) | 0x10 | partab[sum];
3426 break;
3427 case 0xA5: /* AND IYL */
3428 tStates += 9;
3429 sum = ((AF >> 8) & IY) & 0xff;
3430 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
3431 ((sum == 0) << 6) | partab[sum];
3432 break;
3433 case 0xA6: /* AND (IY+dd) */
3434 tStates += 19;
3435 adr = IY + (signed char) GetBYTE_pp(PC);
3436 sum = ((AF >> 8) & GetBYTE(adr)) & 0xff;
3437 AF = (sum << 8) | (sum & 0xa8) | 0x10 |
3438 ((sum == 0) << 6) | partab[sum];
3439 break;
3440 case 0xAC: /* XOR IYH */
3441 tStates += 9;
3442 sum = ((AF ^ (IY)) >> 8) & 0xff;
3443 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
3444 break;
3445 case 0xAD: /* XOR IYL */
3446 tStates += 9;
3447 sum = ((AF >> 8) ^ IY) & 0xff;
3448 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
3449 break;
3450 case 0xAE: /* XOR (IY+dd) */
3451 tStates += 19;
3452 adr = IY + (signed char) GetBYTE_pp(PC);
3453 sum = ((AF >> 8) ^ GetBYTE(adr)) & 0xff;
3454 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
3455 break;
3456 case 0xB4: /* OR IYH */
3457 tStates += 9;
3458 sum = ((AF | (IY)) >> 8) & 0xff;
3459 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
3460 break;
3461 case 0xB5: /* OR IYL */
3462 tStates += 9;
3463 sum = ((AF >> 8) | IY) & 0xff;
3464 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
3465 break;
3466 case 0xB6: /* OR (IY+dd) */
3467 tStates += 19;
3468 adr = IY + (signed char) GetBYTE_pp(PC);
3469 sum = ((AF >> 8) | GetBYTE(adr)) & 0xff;
3470 AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
3471 break;
3472 case 0xBC: /* CP IYH */
3473 tStates += 9;
3474 temp = hreg(IY);
3475 AF = (AF & ~0x28) | (temp & 0x28);
3476 acu = hreg(AF);
3477 sum = acu - temp;
3478 cbits = acu ^ temp ^ sum;
3479 AF = (AF & ~0xff) | (sum & 0x80) |
3480 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
3481 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3482 (cbits & 0x10) | ((cbits >> 8) & 1);
3483 break;
3484 case 0xBD: /* CP IYL */
3485 tStates += 9;
3486 temp = lreg(IY);
3487 AF = (AF & ~0x28) | (temp & 0x28);
3488 acu = hreg(AF);
3489 sum = acu - temp;
3490 cbits = acu ^ temp ^ sum;
3491 AF = (AF & ~0xff) | (sum & 0x80) |
3492 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
3493 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3494 (cbits & 0x10) | ((cbits >> 8) & 1);
3495 break;
3496 case 0xBE: /* CP (IY+dd) */
3497 tStates += 9;
3498 adr = IY + (signed char) GetBYTE_pp(PC);
3499 temp = GetBYTE(adr);
3500 AF = (AF & ~0x28) | (temp & 0x28);
3501 acu = hreg(AF);
3502 sum = acu - temp;
3503 cbits = acu ^ temp ^ sum;
3504 AF = (AF & ~0xff) | (sum & 0x80) |
3505 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
3506 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3507 (cbits & 0x10) | ((cbits >> 8) & 1);
3508 break;
3509 case 0xCB: /* CB prefix */
3510 adr = IY + (signed char) GetBYTE_pp(PC);
3511 switch ((op = GetBYTE(PC)) & 7) {
3512 /*
3513 * default: supresses compiler warning: "warning:
3514 * 'acu' may be used uninitialized in this function"
3515 */
3516 default:
3517 case 0: ++PC; acu = hreg(BC); break;
3518 case 1: ++PC; acu = lreg(BC); break;
3519 case 2: ++PC; acu = hreg(DE); break;
3520 case 3: ++PC; acu = lreg(DE); break;
3521 case 4: ++PC; acu = hreg(HL); break;
3522 case 5: ++PC; acu = lreg(HL); break;
3523 case 6: ++PC; acu = GetBYTE(adr); break;
3524 case 7: ++PC; acu = hreg(AF); break;
3525 }
3526 switch (op & 0xc0) {
3527 /*
3528 * Use default to supress compiler warning: "warning:
3529 * 'temp' may be used uninitialized in this function"
3530 */
3531 default:
3532 case 0x00: /* shift/rotate */
3533 switch (op & 0x38) {
3534 /*
3535 * Use default to supress compiler warning:
3536 * "warning: 'temp' may be used uninitialized
3537 * in this function"
3538 */
3539 default:
3540 case 0x00: /* RLC */
3541 temp = (acu << 1) | (acu >> 7);
3542 cbits = temp & 1;
3543 goto cbshflg3;
3544 case 0x08: /* RRC */
3545 temp = (acu >> 1) | (acu << 7);
3546 cbits = temp & 0x80;
3547 goto cbshflg3;
3548 case 0x10: /* RL */
3549 temp = (acu << 1) | TSTFLAG(C);
3550 cbits = acu & 0x80;
3551 goto cbshflg3;
3552 case 0x18: /* RR */
3553 temp = (acu >> 1) | (TSTFLAG(C) << 7);
3554 cbits = acu & 1;
3555 goto cbshflg3;
3556 case 0x20: /* SLA */
3557 temp = acu << 1;
3558 cbits = acu & 0x80;
3559 goto cbshflg3;
3560 case 0x28: /* SRA */
3561 temp = (acu >> 1) | (acu & 0x80);
3562 cbits = acu & 1;
3563 goto cbshflg3;
3564 case 0x30: /* SLIA */
3565 temp = (acu << 1) | 1;
3566 cbits = acu & 0x80;
3567 goto cbshflg3;
3568 case 0x38: /* SRL */
3569 temp = acu >> 1;
3570 cbits = acu & 1;
3571 cbshflg3:
3572 AF = (AF & ~0xff) | (temp & 0xa8) |
3573 (((temp & 0xff) == 0) << 6) |
3574 parity(temp) | !!cbits;
3575 }
3576 break;
3577 case 0x40: /* BIT */
3578 tStates += 20;
3579 if (acu & (1 << ((op >> 3) & 7)))
3580 AF = (AF & ~0xfe) | 0x10 |
3581 (((op & 0x38) == 0x38) << 7);
3582 else
3583 AF = (AF & ~0xfe) | 0x54;
3584 if ((op&7) != 6)
3585 AF |= (acu & 0x28);
3586 temp = acu;
3587 break;
3588 case 0x80: /* RES */
3589 tStates += 23;
3590 temp = acu & ~(1 << ((op >> 3) & 7));
3591 break;
3592 case 0xc0: /* SET */
3593 tStates += 23;
3594 temp = acu | (1 << ((op >> 3) & 7));
3595 break;
3596 }
3597 switch (op & 7) {
3598 case 0: Sethreg(BC, temp); break;
3599 case 1: Setlreg(BC, temp); break;
3600 case 2: Sethreg(DE, temp); break;
3601 case 3: Setlreg(DE, temp); break;
3602 case 4: Sethreg(HL, temp); break;
3603 case 5: Setlreg(HL, temp); break;
3604 case 6: PutBYTE(adr, temp); break;
3605 case 7: Sethreg(AF, temp); break;
3606 }
3607 break;
3608 case 0xE1: /* POP IY */
3609 tStates += 14;
3610 POP(IY);
3611 break;
3612 case 0xE3: /* EX (SP),IY */
3613 tStates += 23;
3614 temp = IY; POP(IY); PUSH(temp);
3615 break;
3616 case 0xE5: /* PUSH IY */
3617 tStates += 15;
3618 PUSH(IY);
3619 break;
3620 case 0xE9: /* JP (IY) */
3621 tStates += 8;
3622 PC = IY;
3623 break;
3624 case 0xF9: /* LD SP,IY */
3625 tStates += 9;
3626 SP = IY;
3627 break;
3628 default: PC--; /* ignore DD */
3629 }
3630 break;
3631 case 0xFE: /* CP nn */
3632 tStates += 7;
3633 temp = GetBYTE_pp(PC);
3634 AF = (AF & ~0x28) | (temp & 0x28);
3635 acu = hreg(AF);
3636 sum = acu - temp;
3637 cbits = acu ^ temp ^ sum;
3638 AF = (AF & ~0xff) | (sum & 0x80) |
3639 (((sum & 0xff) == 0) << 6) | (temp & 0x28) |
3640 (((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
3641 (cbits & 0x10) | ((cbits >> 8) & 1);
3642 break;
3643 case 0xFF: /* RST 38H */
3644 tStates += 11;
3645 PUSH(PC); PC = 0x38;
3646 }
3647 }
3648 /* make registers visible for debugging if interrupted */
3649 SAVE_STATE();
3650 return (PC&0xffff)|0x10000; /* flag non-bios stop */
3651 }
3652