1 /* Z80 instruction set simulator.
2 Copyright (C) 1995 Frank D. Cringle.
4 This file is part of yaze - yet another Z80 emulator.
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.
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.
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. */
20 /* This file was generated from simz80.pl
21 with the following choice of options */
31 static const unsigned char partab
[256] = {
32 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
33 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
34 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
35 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
36 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
37 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
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 4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
43 0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
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,
50 #define parity(x) partab[(x)&0xff]
57 FASTREG y = RAM(SP); SP++; \
58 x = y + (RAM(SP) << 8); SP++; \
61 #define PUSH(x) do { \
62 --SP; RAM(SP) = (x) >> 8; \
66 #define JPC(cond) PC = cond ? GetWORD(PC) : PC+2
68 #define CALLC(cond) { \
70 FASTREG adrr = GetWORD(PC); \
78 /* load Z80 registers into (we hope) host registers */
79 #define LOAD_STATE() \
82 BC = regs[regs_sel].bc; \
83 DE = regs[regs_sel].de; \
84 HL = regs[regs_sel].hl; \
87 /* load Z80 registers into (we hope) host registers */
88 #define DECLARE_STATE() \
90 FASTREG AF = af[af_sel]; \
91 FASTREG BC = regs[regs_sel].bc; \
92 FASTREG DE = regs[regs_sel].de; \
93 FASTREG HL = regs[regs_sel].hl; \
96 /* save Z80 registers back into memory */
97 #define SAVE_STATE() \
100 regs[regs_sel].bc = BC; \
101 regs[regs_sel].de = DE; \
102 regs[regs_sel].hl = HL; \
106 cb_prefix(FASTREG adr
)
109 FASTWORK temp
= 0, acu
= 0, op
, cbits
;
111 switch ((op
= GetBYTE(PC
)) & 7) {
112 case 0: ++PC
; acu
= hreg(BC
); break;
113 case 1: ++PC
; acu
= lreg(BC
); break;
114 case 2: ++PC
; acu
= hreg(DE
); break;
115 case 3: ++PC
; acu
= lreg(DE
); break;
116 case 4: ++PC
; acu
= hreg(HL
); break;
117 case 5: ++PC
; acu
= lreg(HL
); break;
118 case 6: ++PC
; acu
= GetBYTE(adr
); break;
119 case 7: ++PC
; acu
= hreg(AF
); break;
122 case 0x00: /* shift/rotate */
125 temp
= (acu
<< 1) | (acu
>> 7);
129 temp
= (acu
>> 1) | (acu
<< 7);
133 temp
= (acu
<< 1) | TSTFLAG(C
);
137 temp
= (acu
>> 1) | (TSTFLAG(C
) << 7);
145 temp
= (acu
>> 1) | (acu
& 0x80);
148 case 0x30: /* SLIA */
149 temp
= (acu
<< 1) | 1;
156 AF
= (AF
& ~0xff) | (temp
& 0xa8) |
157 (((temp
& 0xff) == 0) << 6) |
158 parity(temp
) | !!cbits
;
162 if (acu
& (1 << ((op
>> 3) & 7)))
163 AF
= (AF
& ~0xfe) | 0x10 |
164 (((op
& 0x38) == 0x38) << 7);
166 AF
= (AF
& ~0xfe) | 0x54;
172 temp
= acu
& ~(1 << ((op
>> 3) & 7));
175 temp
= acu
| (1 << ((op
>> 3) & 7));
179 case 0: Sethreg(BC
, temp
); break;
180 case 1: Setlreg(BC
, temp
); break;
181 case 2: Sethreg(DE
, temp
); break;
182 case 3: Setlreg(DE
, temp
); break;
183 case 4: Sethreg(HL
, temp
); break;
184 case 5: Setlreg(HL
, temp
); break;
185 case 6: PutBYTE(adr
, temp
); break;
186 case 7: Sethreg(AF
, temp
); break;
192 dfd_prefix(FASTREG IXY
)
195 FASTWORK temp
, adr
, acu
, op
, sum
, cbits
;
197 switch (++PC
, op
= GetBYTE(PC
-1)) {
198 case 0x09: /* ADD IXY,BC */
202 cbits
= (IXY
^ BC
^ sum
) >> 8;
204 AF
= (AF
& ~0x3b) | ((sum
>> 8) & 0x28) |
205 (cbits
& 0x10) | ((cbits
>> 8) & 1);
207 case 0x19: /* ADD IXY,DE */
211 cbits
= (IXY
^ DE
^ sum
) >> 8;
213 AF
= (AF
& ~0x3b) | ((sum
>> 8) & 0x28) |
214 (cbits
& 0x10) | ((cbits
>> 8) & 1);
216 case 0x21: /* LD IXY,nnnn */
220 case 0x22: /* LD (nnnn),IXY */
225 case 0x23: /* INC IXY */
228 case 0x24: /* INC IXYH */
231 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
232 (((temp
& 0xff) == 0) << 6) |
233 (((temp
& 0xf) == 0) << 4) |
234 ((temp
== 0x80) << 2);
236 case 0x25: /* DEC IXYH */
239 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
240 (((temp
& 0xff) == 0) << 6) |
241 (((temp
& 0xf) == 0xf) << 4) |
242 ((temp
== 0x7f) << 2) | 2;
244 case 0x26: /* LD IXYH,nn */
245 Sethreg(IXY
, GetBYTE(PC
)); ++PC
;
247 case 0x29: /* ADD IXY,IXY */
250 cbits
= (IXY
^ IXY
^ sum
) >> 8;
252 AF
= (AF
& ~0x3b) | ((sum
>> 8) & 0x28) |
253 (cbits
& 0x10) | ((cbits
>> 8) & 1);
255 case 0x2A: /* LD IXY,(nnnn) */
260 case 0x2B: /* DEC IXY */
263 case 0x2C: /* INC IXYL */
266 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
267 (((temp
& 0xff) == 0) << 6) |
268 (((temp
& 0xf) == 0) << 4) |
269 ((temp
== 0x80) << 2);
271 case 0x2D: /* DEC IXYL */
274 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
275 (((temp
& 0xff) == 0) << 6) |
276 (((temp
& 0xf) == 0xf) << 4) |
277 ((temp
== 0x7f) << 2) | 2;
279 case 0x2E: /* LD IXYL,nn */
280 Setlreg(IXY
, GetBYTE(PC
)); ++PC
;
282 case 0x34: /* INC (IXY+dd) */
283 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
284 temp
= GetBYTE(adr
)+1;
286 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
287 (((temp
& 0xff) == 0) << 6) |
288 (((temp
& 0xf) == 0) << 4) |
289 ((temp
== 0x80) << 2);
291 case 0x35: /* DEC (IXY+dd) */
292 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
293 temp
= GetBYTE(adr
)-1;
295 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
296 (((temp
& 0xff) == 0) << 6) |
297 (((temp
& 0xf) == 0xf) << 4) |
298 ((temp
== 0x7f) << 2) | 2;
300 case 0x36: /* LD (IXY+dd),nn */
301 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
302 PutBYTE(adr
, GetBYTE(PC
)); ++PC
;
304 case 0x39: /* ADD IXY,SP */
308 cbits
= (IXY
^ SP
^ sum
) >> 8;
310 AF
= (AF
& ~0x3b) | ((sum
>> 8) & 0x28) |
311 (cbits
& 0x10) | ((cbits
>> 8) & 1);
313 case 0x44: /* LD B,IXYH */
314 Sethreg(BC
, hreg(IXY
));
316 case 0x45: /* LD B,IXYL */
317 Sethreg(BC
, lreg(IXY
));
319 case 0x46: /* LD B,(IXY+dd) */
320 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
321 Sethreg(BC
, GetBYTE(adr
));
323 case 0x4C: /* LD C,IXYH */
324 Setlreg(BC
, hreg(IXY
));
326 case 0x4D: /* LD C,IXYL */
327 Setlreg(BC
, lreg(IXY
));
329 case 0x4E: /* LD C,(IXY+dd) */
330 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
331 Setlreg(BC
, GetBYTE(adr
));
333 case 0x54: /* LD D,IXYH */
334 Sethreg(DE
, hreg(IXY
));
336 case 0x55: /* LD D,IXYL */
337 Sethreg(DE
, lreg(IXY
));
339 case 0x56: /* LD D,(IXY+dd) */
340 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
341 Sethreg(DE
, GetBYTE(adr
));
343 case 0x5C: /* LD E,H */
344 Setlreg(DE
, hreg(IXY
));
346 case 0x5D: /* LD E,L */
347 Setlreg(DE
, lreg(IXY
));
349 case 0x5E: /* LD E,(IXY+dd) */
350 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
351 Setlreg(DE
, GetBYTE(adr
));
353 case 0x60: /* LD IXYH,B */
354 Sethreg(IXY
, hreg(BC
));
356 case 0x61: /* LD IXYH,C */
357 Sethreg(IXY
, lreg(BC
));
359 case 0x62: /* LD IXYH,D */
360 Sethreg(IXY
, hreg(DE
));
362 case 0x63: /* LD IXYH,E */
363 Sethreg(IXY
, lreg(DE
));
365 case 0x64: /* LD IXYH,IXYH */
368 case 0x65: /* LD IXYH,IXYL */
369 Sethreg(IXY
, lreg(IXY
));
371 case 0x66: /* LD H,(IXY+dd) */
372 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
373 Sethreg(HL
, GetBYTE(adr
));
375 case 0x67: /* LD IXYH,A */
376 Sethreg(IXY
, hreg(AF
));
378 case 0x68: /* LD IXYL,B */
379 Setlreg(IXY
, hreg(BC
));
381 case 0x69: /* LD IXYL,C */
382 Setlreg(IXY
, lreg(BC
));
384 case 0x6A: /* LD IXYL,D */
385 Setlreg(IXY
, hreg(DE
));
387 case 0x6B: /* LD IXYL,E */
388 Setlreg(IXY
, lreg(DE
));
390 case 0x6C: /* LD IXYL,IXYH */
391 Setlreg(IXY
, hreg(IXY
));
393 case 0x6D: /* LD IXYL,IXYL */
396 case 0x6E: /* LD L,(IXY+dd) */
397 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
398 Setlreg(HL
, GetBYTE(adr
));
400 case 0x6F: /* LD IXYL,A */
401 Setlreg(IXY
, hreg(AF
));
403 case 0x70: /* LD (IXY+dd),B */
404 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
405 PutBYTE(adr
, hreg(BC
));
407 case 0x71: /* LD (IXY+dd),C */
408 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
409 PutBYTE(adr
, lreg(BC
));
411 case 0x72: /* LD (IXY+dd),D */
412 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
413 PutBYTE(adr
, hreg(DE
));
415 case 0x73: /* LD (IXY+dd),E */
416 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
417 PutBYTE(adr
, lreg(DE
));
419 case 0x74: /* LD (IXY+dd),H */
420 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
421 PutBYTE(adr
, hreg(HL
));
423 case 0x75: /* LD (IXY+dd),L */
424 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
425 PutBYTE(adr
, lreg(HL
));
427 case 0x77: /* LD (IXY+dd),A */
428 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
429 PutBYTE(adr
, hreg(AF
));
431 case 0x7C: /* LD A,IXYH */
432 Sethreg(AF
, hreg(IXY
));
434 case 0x7D: /* LD A,IXYL */
435 Sethreg(AF
, lreg(IXY
));
437 case 0x7E: /* LD A,(IXY+dd) */
438 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
439 Sethreg(AF
, GetBYTE(adr
));
441 case 0x84: /* ADD A,IXYH */
445 cbits
= acu
^ temp
^ sum
;
446 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
447 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
448 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
451 case 0x85: /* ADD A,IXYL */
455 cbits
= acu
^ temp
^ sum
;
456 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
457 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
458 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
461 case 0x86: /* ADD A,(IXY+dd) */
462 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
466 cbits
= acu
^ temp
^ sum
;
467 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
468 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
469 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
472 case 0x8C: /* ADC A,IXYH */
475 sum
= acu
+ temp
+ TSTFLAG(C
);
476 cbits
= acu
^ temp
^ sum
;
477 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
478 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
479 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
482 case 0x8D: /* ADC A,IXYL */
485 sum
= acu
+ temp
+ TSTFLAG(C
);
486 cbits
= acu
^ temp
^ sum
;
487 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
488 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
489 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
492 case 0x8E: /* ADC A,(IXY+dd) */
493 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
496 sum
= acu
+ temp
+ TSTFLAG(C
);
497 cbits
= acu
^ temp
^ sum
;
498 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
499 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
500 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
503 case 0x94: /* SUB IXYH */
507 cbits
= acu
^ temp
^ sum
;
508 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
509 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
510 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
513 case 0x95: /* SUB IXYL */
517 cbits
= acu
^ temp
^ sum
;
518 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
519 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
520 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
523 case 0x96: /* SUB (IXY+dd) */
524 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
528 cbits
= acu
^ temp
^ sum
;
529 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
530 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
531 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
534 case 0x9C: /* SBC A,IXYH */
537 sum
= acu
- temp
- TSTFLAG(C
);
538 cbits
= acu
^ temp
^ sum
;
539 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
540 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
541 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
544 case 0x9D: /* SBC A,IXYL */
547 sum
= acu
- temp
- TSTFLAG(C
);
548 cbits
= acu
^ temp
^ sum
;
549 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
550 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
551 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
554 case 0x9E: /* SBC A,(IXY+dd) */
555 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
558 sum
= acu
- temp
- TSTFLAG(C
);
559 cbits
= acu
^ temp
^ sum
;
560 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
561 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
562 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
565 case 0xA4: /* AND IXYH */
566 sum
= ((AF
& (IXY
)) >> 8) & 0xff;
567 AF
= (sum
<< 8) | (sum
& 0xa8) |
568 ((sum
== 0) << 6) | 0x10 | partab
[sum
];
570 case 0xA5: /* AND IXYL */
571 sum
= ((AF
>> 8) & IXY
) & 0xff;
572 AF
= (sum
<< 8) | (sum
& 0xa8) | 0x10 |
573 ((sum
== 0) << 6) | partab
[sum
];
575 case 0xA6: /* AND (IXY+dd) */
576 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
577 sum
= ((AF
>> 8) & GetBYTE(adr
)) & 0xff;
578 AF
= (sum
<< 8) | (sum
& 0xa8) | 0x10 |
579 ((sum
== 0) << 6) | partab
[sum
];
581 case 0xAC: /* XOR IXYH */
582 sum
= ((AF
^ (IXY
)) >> 8) & 0xff;
583 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
585 case 0xAD: /* XOR IXYL */
586 sum
= ((AF
>> 8) ^ IXY
) & 0xff;
587 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
589 case 0xAE: /* XOR (IXY+dd) */
590 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
591 sum
= ((AF
>> 8) ^ GetBYTE(adr
)) & 0xff;
592 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
594 case 0xB4: /* OR IXYH */
595 sum
= ((AF
| (IXY
)) >> 8) & 0xff;
596 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
598 case 0xB5: /* OR IXYL */
599 sum
= ((AF
>> 8) | IXY
) & 0xff;
600 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
602 case 0xB6: /* OR (IXY+dd) */
603 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
604 sum
= ((AF
>> 8) | GetBYTE(adr
)) & 0xff;
605 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
607 case 0xBC: /* CP IXYH */
609 AF
= (AF
& ~0x28) | (temp
& 0x28);
612 cbits
= acu
^ temp
^ sum
;
613 AF
= (AF
& ~0xff) | (sum
& 0x80) |
614 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
615 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
616 (cbits
& 0x10) | ((cbits
>> 8) & 1);
618 case 0xBD: /* CP IXYL */
620 AF
= (AF
& ~0x28) | (temp
& 0x28);
623 cbits
= acu
^ temp
^ sum
;
624 AF
= (AF
& ~0xff) | (sum
& 0x80) |
625 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
626 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
627 (cbits
& 0x10) | ((cbits
>> 8) & 1);
629 case 0xBE: /* CP (IXY+dd) */
630 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
632 AF
= (AF
& ~0x28) | (temp
& 0x28);
635 cbits
= acu
^ temp
^ sum
;
636 AF
= (AF
& ~0xff) | (sum
& 0x80) |
637 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
638 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
639 (cbits
& 0x10) | ((cbits
>> 8) & 1);
641 case 0xCB: /* CB prefix */
642 adr
= IXY
+ (signed char) GetBYTE(PC
); ++PC
;
647 case 0xE1: /* POP IXY */
650 case 0xE3: /* EX (SP),IXY */
651 temp
= IXY
; POP(IXY
); PUSH(temp
);
653 case 0xE5: /* PUSH IXY */
656 case 0xE9: /* JP (IXY) */
659 case 0xF9: /* LD SP,IXY */
662 default: PC
--; /* ignore DD */
669 simz80(FASTREG PC
, int count
, int (*fnc
)())
671 FASTREG AF
= af
[af_sel
];
672 FASTREG BC
= regs
[regs_sel
].bc
;
673 FASTREG DE
= regs
[regs_sel
].de
;
674 FASTREG HL
= regs
[regs_sel
].hl
;
676 FASTWORK temp
, acu
, sum
, cbits
;
684 if (fnc
&& --n
== 0) {
690 switch(++PC
,RAM(PC
-1)) {
693 case 0x01: /* LD BC,nnnn */
697 case 0x02: /* LD (BC),A */
698 PutBYTE(BC
, hreg(AF
));
700 case 0x03: /* INC BC */
703 case 0x04: /* INC B */
706 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
707 (((temp
& 0xff) == 0) << 6) |
708 (((temp
& 0xf) == 0) << 4) |
709 ((temp
== 0x80) << 2);
711 case 0x05: /* DEC B */
714 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
715 (((temp
& 0xff) == 0) << 6) |
716 (((temp
& 0xf) == 0xf) << 4) |
717 ((temp
== 0x7f) << 2) | 2;
719 case 0x06: /* LD B,nn */
720 Sethreg(BC
, GetBYTE(PC
)); ++PC
;
722 case 0x07: /* RLCA */
723 AF
= ((AF
>> 7) & 0x0128) | ((AF
<< 1) & ~0x1ff) |
724 (AF
& 0xc4) | ((AF
>> 15) & 1);
726 case 0x08: /* EX AF,AF' */
731 case 0x09: /* ADD HL,BC */
735 cbits
= (HL
^ BC
^ sum
) >> 8;
737 AF
= (AF
& ~0x3b) | ((sum
>> 8) & 0x28) |
738 (cbits
& 0x10) | ((cbits
>> 8) & 1);
740 case 0x0A: /* LD A,(BC) */
741 Sethreg(AF
, GetBYTE(BC
));
743 case 0x0B: /* DEC BC */
746 case 0x0C: /* INC C */
749 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
750 (((temp
& 0xff) == 0) << 6) |
751 (((temp
& 0xf) == 0) << 4) |
752 ((temp
== 0x80) << 2);
754 case 0x0D: /* DEC C */
757 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
758 (((temp
& 0xff) == 0) << 6) |
759 (((temp
& 0xf) == 0xf) << 4) |
760 ((temp
== 0x7f) << 2) | 2;
762 case 0x0E: /* LD C,nn */
763 Setlreg(BC
, GetBYTE(PC
)); ++PC
;
765 case 0x0F: /* RRCA */
768 AF
= ((temp
& 1) << 15) | (sum
<< 8) |
769 (sum
& 0x28) | (AF
& 0xc4) | (temp
& 1);
771 case 0x10: /* DJNZ dd */
772 PC
+= ((BC
-= 0x100) & 0xff00) ? (signed char) GetBYTE(PC
) + 1 : 1;
774 case 0x11: /* LD DE,nnnn */
778 case 0x12: /* LD (DE),A */
779 PutBYTE(DE
, hreg(AF
));
781 case 0x13: /* INC DE */
784 case 0x14: /* INC D */
787 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
788 (((temp
& 0xff) == 0) << 6) |
789 (((temp
& 0xf) == 0) << 4) |
790 ((temp
== 0x80) << 2);
792 case 0x15: /* DEC D */
795 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
796 (((temp
& 0xff) == 0) << 6) |
797 (((temp
& 0xf) == 0xf) << 4) |
798 ((temp
== 0x7f) << 2) | 2;
800 case 0x16: /* LD D,nn */
801 Sethreg(DE
, GetBYTE(PC
)); ++PC
;
804 AF
= ((AF
<< 8) & 0x0100) | ((AF
>> 7) & 0x28) | ((AF
<< 1) & ~0x01ff) |
805 (AF
& 0xc4) | ((AF
>> 15) & 1);
807 case 0x18: /* JR dd */
808 PC
+= (1) ? (signed char) GetBYTE(PC
) + 1 : 1;
810 case 0x19: /* ADD HL,DE */
814 cbits
= (HL
^ DE
^ sum
) >> 8;
816 AF
= (AF
& ~0x3b) | ((sum
>> 8) & 0x28) |
817 (cbits
& 0x10) | ((cbits
>> 8) & 1);
819 case 0x1A: /* LD A,(DE) */
820 Sethreg(AF
, GetBYTE(DE
));
822 case 0x1B: /* DEC DE */
825 case 0x1C: /* INC E */
828 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
829 (((temp
& 0xff) == 0) << 6) |
830 (((temp
& 0xf) == 0) << 4) |
831 ((temp
== 0x80) << 2);
833 case 0x1D: /* DEC E */
836 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
837 (((temp
& 0xff) == 0) << 6) |
838 (((temp
& 0xf) == 0xf) << 4) |
839 ((temp
== 0x7f) << 2) | 2;
841 case 0x1E: /* LD E,nn */
842 Setlreg(DE
, GetBYTE(PC
)); ++PC
;
847 AF
= ((AF
& 1) << 15) | (sum
<< 8) |
848 (sum
& 0x28) | (AF
& 0xc4) | (temp
& 1);
850 case 0x20: /* JR NZ,dd */
851 PC
+= (!TSTFLAG(Z
)) ? (signed char) GetBYTE(PC
) + 1 : 1;
853 case 0x21: /* LD HL,nnnn */
857 case 0x22: /* LD (nnnn),HL */
862 case 0x23: /* INC HL */
865 case 0x24: /* INC H */
868 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
869 (((temp
& 0xff) == 0) << 6) |
870 (((temp
& 0xf) == 0) << 4) |
871 ((temp
== 0x80) << 2);
873 case 0x25: /* DEC H */
876 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
877 (((temp
& 0xff) == 0) << 6) |
878 (((temp
& 0xf) == 0xf) << 4) |
879 ((temp
== 0x7f) << 2) | 2;
881 case 0x26: /* LD H,nn */
882 Sethreg(HL
, GetBYTE(PC
)); ++PC
;
888 if (TSTFLAG(N
)) { /* last operation was a subtract */
889 int hd
= cbits
|| acu
> 0x99;
890 if (TSTFLAG(H
) || (temp
> 9)) { /* adjust low digit */
896 if (hd
) /* adjust high digit */
899 else { /* last operation was an add */
900 if (TSTFLAG(H
) || (temp
> 9)) { /* adjust low digit */
901 SETFLAG(H
, (temp
> 9));
904 if (cbits
|| ((acu
& 0x1f0) > 0x90)) /* adjust high digit */
907 cbits
|= (acu
>> 8) & 1;
909 AF
= (acu
<< 8) | (acu
& 0xa8) | ((acu
== 0) << 6) |
910 (AF
& 0x12) | partab
[acu
] | cbits
;
912 case 0x28: /* JR Z,dd */
913 PC
+= (TSTFLAG(Z
)) ? (signed char) GetBYTE(PC
) + 1 : 1;
915 case 0x29: /* ADD HL,HL */
918 cbits
= (HL
^ HL
^ sum
) >> 8;
920 AF
= (AF
& ~0x3b) | ((sum
>> 8) & 0x28) |
921 (cbits
& 0x10) | ((cbits
>> 8) & 1);
923 case 0x2A: /* LD HL,(nnnn) */
928 case 0x2B: /* DEC HL */
931 case 0x2C: /* INC L */
934 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
935 (((temp
& 0xff) == 0) << 6) |
936 (((temp
& 0xf) == 0) << 4) |
937 ((temp
== 0x80) << 2);
939 case 0x2D: /* DEC L */
942 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
943 (((temp
& 0xff) == 0) << 6) |
944 (((temp
& 0xf) == 0xf) << 4) |
945 ((temp
== 0x7f) << 2) | 2;
947 case 0x2E: /* LD L,nn */
948 Setlreg(HL
, GetBYTE(PC
)); ++PC
;
951 AF
= (~AF
& ~0xff) | (AF
& 0xc5) | ((~AF
>> 8) & 0x28) | 0x12;
953 case 0x30: /* JR NC,dd */
954 PC
+= (!TSTFLAG(C
)) ? (signed char) GetBYTE(PC
) + 1 : 1;
956 case 0x31: /* LD SP,nnnn */
960 case 0x32: /* LD (nnnn),A */
962 PutBYTE(temp
, hreg(AF
));
965 case 0x33: /* INC SP */
968 case 0x34: /* INC (HL) */
969 temp
= GetBYTE(HL
)+1;
971 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
972 (((temp
& 0xff) == 0) << 6) |
973 (((temp
& 0xf) == 0) << 4) |
974 ((temp
== 0x80) << 2);
976 case 0x35: /* DEC (HL) */
977 temp
= GetBYTE(HL
)-1;
979 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
980 (((temp
& 0xff) == 0) << 6) |
981 (((temp
& 0xf) == 0xf) << 4) |
982 ((temp
== 0x7f) << 2) | 2;
984 case 0x36: /* LD (HL),nn */
985 PutBYTE(HL
, GetBYTE(PC
)); ++PC
;
988 AF
= (AF
&~0x3b)|((AF
>>8)&0x28)|1;
990 case 0x38: /* JR C,dd */
991 PC
+= (TSTFLAG(C
)) ? (signed char) GetBYTE(PC
) + 1 : 1;
993 case 0x39: /* ADD HL,SP */
997 cbits
= (HL
^ SP
^ sum
) >> 8;
999 AF
= (AF
& ~0x3b) | ((sum
>> 8) & 0x28) |
1000 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1002 case 0x3A: /* LD A,(nnnn) */
1004 Sethreg(AF
, GetBYTE(temp
));
1007 case 0x3B: /* DEC SP */
1010 case 0x3C: /* INC A */
1013 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
1014 (((temp
& 0xff) == 0) << 6) |
1015 (((temp
& 0xf) == 0) << 4) |
1016 ((temp
== 0x80) << 2);
1018 case 0x3D: /* DEC A */
1021 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
1022 (((temp
& 0xff) == 0) << 6) |
1023 (((temp
& 0xf) == 0xf) << 4) |
1024 ((temp
== 0x7f) << 2) | 2;
1026 case 0x3E: /* LD A,nn */
1027 Sethreg(AF
, GetBYTE(PC
)); ++PC
;
1029 case 0x3F: /* CCF */
1030 AF
= (AF
&~0x3b)|((AF
>>8)&0x28)|((AF
&1)<<4)|(~AF
&1);
1032 case 0x40: /* LD B,B */
1035 case 0x41: /* LD B,C */
1036 BC
= (BC
& 255) | ((BC
& 255) << 8);
1038 case 0x42: /* LD B,D */
1039 BC
= (BC
& 255) | (DE
& ~255);
1041 case 0x43: /* LD B,E */
1042 BC
= (BC
& 255) | ((DE
& 255) << 8);
1044 case 0x44: /* LD B,H */
1045 BC
= (BC
& 255) | (HL
& ~255);
1047 case 0x45: /* LD B,L */
1048 BC
= (BC
& 255) | ((HL
& 255) << 8);
1050 case 0x46: /* LD B,(HL) */
1051 Sethreg(BC
, GetBYTE(HL
));
1053 case 0x47: /* LD B,A */
1054 BC
= (BC
& 255) | (AF
& ~255);
1056 case 0x48: /* LD C,B */
1057 BC
= (BC
& ~255) | ((BC
>> 8) & 255);
1059 case 0x49: /* LD C,C */
1062 case 0x4A: /* LD C,D */
1063 BC
= (BC
& ~255) | ((DE
>> 8) & 255);
1065 case 0x4B: /* LD C,E */
1066 BC
= (BC
& ~255) | (DE
& 255);
1068 case 0x4C: /* LD C,H */
1069 BC
= (BC
& ~255) | ((HL
>> 8) & 255);
1071 case 0x4D: /* LD C,L */
1072 BC
= (BC
& ~255) | (HL
& 255);
1074 case 0x4E: /* LD C,(HL) */
1075 Setlreg(BC
, GetBYTE(HL
));
1077 case 0x4F: /* LD C,A */
1078 BC
= (BC
& ~255) | ((AF
>> 8) & 255);
1080 case 0x50: /* LD D,B */
1081 DE
= (DE
& 255) | (BC
& ~255);
1083 case 0x51: /* LD D,C */
1084 DE
= (DE
& 255) | ((BC
& 255) << 8);
1086 case 0x52: /* LD D,D */
1089 case 0x53: /* LD D,E */
1090 DE
= (DE
& 255) | ((DE
& 255) << 8);
1092 case 0x54: /* LD D,H */
1093 DE
= (DE
& 255) | (HL
& ~255);
1095 case 0x55: /* LD D,L */
1096 DE
= (DE
& 255) | ((HL
& 255) << 8);
1098 case 0x56: /* LD D,(HL) */
1099 Sethreg(DE
, GetBYTE(HL
));
1101 case 0x57: /* LD D,A */
1102 DE
= (DE
& 255) | (AF
& ~255);
1104 case 0x58: /* LD E,B */
1105 DE
= (DE
& ~255) | ((BC
>> 8) & 255);
1107 case 0x59: /* LD E,C */
1108 DE
= (DE
& ~255) | (BC
& 255);
1110 case 0x5A: /* LD E,D */
1111 DE
= (DE
& ~255) | ((DE
>> 8) & 255);
1113 case 0x5B: /* LD E,E */
1116 case 0x5C: /* LD E,H */
1117 DE
= (DE
& ~255) | ((HL
>> 8) & 255);
1119 case 0x5D: /* LD E,L */
1120 DE
= (DE
& ~255) | (HL
& 255);
1122 case 0x5E: /* LD E,(HL) */
1123 Setlreg(DE
, GetBYTE(HL
));
1125 case 0x5F: /* LD E,A */
1126 DE
= (DE
& ~255) | ((AF
>> 8) & 255);
1128 case 0x60: /* LD H,B */
1129 HL
= (HL
& 255) | (BC
& ~255);
1131 case 0x61: /* LD H,C */
1132 HL
= (HL
& 255) | ((BC
& 255) << 8);
1134 case 0x62: /* LD H,D */
1135 HL
= (HL
& 255) | (DE
& ~255);
1137 case 0x63: /* LD H,E */
1138 HL
= (HL
& 255) | ((DE
& 255) << 8);
1140 case 0x64: /* LD H,H */
1143 case 0x65: /* LD H,L */
1144 HL
= (HL
& 255) | ((HL
& 255) << 8);
1146 case 0x66: /* LD H,(HL) */
1147 Sethreg(HL
, GetBYTE(HL
));
1149 case 0x67: /* LD H,A */
1150 HL
= (HL
& 255) | (AF
& ~255);
1152 case 0x68: /* LD L,B */
1153 HL
= (HL
& ~255) | ((BC
>> 8) & 255);
1155 case 0x69: /* LD L,C */
1156 HL
= (HL
& ~255) | (BC
& 255);
1158 case 0x6A: /* LD L,D */
1159 HL
= (HL
& ~255) | ((DE
>> 8) & 255);
1161 case 0x6B: /* LD L,E */
1162 HL
= (HL
& ~255) | (DE
& 255);
1164 case 0x6C: /* LD L,H */
1165 HL
= (HL
& ~255) | ((HL
>> 8) & 255);
1167 case 0x6D: /* LD L,L */
1170 case 0x6E: /* LD L,(HL) */
1171 Setlreg(HL
, GetBYTE(HL
));
1173 case 0x6F: /* LD L,A */
1174 HL
= (HL
& ~255) | ((AF
>> 8) & 255);
1176 case 0x70: /* LD (HL),B */
1177 PutBYTE(HL
, hreg(BC
));
1179 case 0x71: /* LD (HL),C */
1180 PutBYTE(HL
, lreg(BC
));
1182 case 0x72: /* LD (HL),D */
1183 PutBYTE(HL
, hreg(DE
));
1185 case 0x73: /* LD (HL),E */
1186 PutBYTE(HL
, lreg(DE
));
1188 case 0x74: /* LD (HL),H */
1189 PutBYTE(HL
, hreg(HL
));
1191 case 0x75: /* LD (HL),L */
1192 PutBYTE(HL
, lreg(HL
));
1194 case 0x76: /* HALT */
1197 case 0x77: /* LD (HL),A */
1198 PutBYTE(HL
, hreg(AF
));
1200 case 0x78: /* LD A,B */
1201 AF
= (AF
& 255) | (BC
& ~255);
1203 case 0x79: /* LD A,C */
1204 AF
= (AF
& 255) | ((BC
& 255) << 8);
1206 case 0x7A: /* LD A,D */
1207 AF
= (AF
& 255) | (DE
& ~255);
1209 case 0x7B: /* LD A,E */
1210 AF
= (AF
& 255) | ((DE
& 255) << 8);
1212 case 0x7C: /* LD A,H */
1213 AF
= (AF
& 255) | (HL
& ~255);
1215 case 0x7D: /* LD A,L */
1216 AF
= (AF
& 255) | ((HL
& 255) << 8);
1218 case 0x7E: /* LD A,(HL) */
1219 Sethreg(AF
, GetBYTE(HL
));
1221 case 0x7F: /* LD A,A */
1224 case 0x80: /* ADD A,B */
1228 cbits
= acu
^ temp
^ sum
;
1229 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1230 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1231 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1234 case 0x81: /* ADD A,C */
1238 cbits
= acu
^ temp
^ sum
;
1239 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1240 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1241 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1244 case 0x82: /* ADD A,D */
1248 cbits
= acu
^ temp
^ sum
;
1249 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1250 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1251 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1254 case 0x83: /* ADD A,E */
1258 cbits
= acu
^ temp
^ sum
;
1259 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1260 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1261 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1264 case 0x84: /* ADD A,H */
1268 cbits
= acu
^ temp
^ sum
;
1269 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1270 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1271 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1274 case 0x85: /* ADD A,L */
1278 cbits
= acu
^ temp
^ sum
;
1279 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1280 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1281 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1284 case 0x86: /* ADD A,(HL) */
1288 cbits
= acu
^ temp
^ sum
;
1289 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1290 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1291 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1294 case 0x87: /* ADD A,A */
1298 cbits
= acu
^ temp
^ sum
;
1299 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1300 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1301 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1304 case 0x88: /* ADC A,B */
1307 sum
= acu
+ temp
+ TSTFLAG(C
);
1308 cbits
= acu
^ temp
^ sum
;
1309 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1310 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1311 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1314 case 0x89: /* ADC A,C */
1317 sum
= acu
+ temp
+ TSTFLAG(C
);
1318 cbits
= acu
^ temp
^ sum
;
1319 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1320 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1321 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1324 case 0x8A: /* ADC A,D */
1327 sum
= acu
+ temp
+ TSTFLAG(C
);
1328 cbits
= acu
^ temp
^ sum
;
1329 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1330 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1331 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1334 case 0x8B: /* ADC A,E */
1337 sum
= acu
+ temp
+ TSTFLAG(C
);
1338 cbits
= acu
^ temp
^ sum
;
1339 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1340 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1341 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1344 case 0x8C: /* ADC A,H */
1347 sum
= acu
+ temp
+ TSTFLAG(C
);
1348 cbits
= acu
^ temp
^ sum
;
1349 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1350 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1351 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1354 case 0x8D: /* ADC A,L */
1357 sum
= acu
+ temp
+ TSTFLAG(C
);
1358 cbits
= acu
^ temp
^ sum
;
1359 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1360 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1361 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1364 case 0x8E: /* ADC A,(HL) */
1367 sum
= acu
+ temp
+ TSTFLAG(C
);
1368 cbits
= acu
^ temp
^ sum
;
1369 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1370 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1371 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1374 case 0x8F: /* ADC A,A */
1377 sum
= acu
+ temp
+ TSTFLAG(C
);
1378 cbits
= acu
^ temp
^ sum
;
1379 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1380 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1381 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1384 case 0x90: /* SUB B */
1388 cbits
= acu
^ temp
^ sum
;
1389 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1390 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1391 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1394 case 0x91: /* SUB C */
1398 cbits
= acu
^ temp
^ sum
;
1399 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1400 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1401 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1404 case 0x92: /* SUB D */
1408 cbits
= acu
^ temp
^ sum
;
1409 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1410 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1411 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1414 case 0x93: /* SUB E */
1418 cbits
= acu
^ temp
^ sum
;
1419 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1420 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1421 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1424 case 0x94: /* SUB H */
1428 cbits
= acu
^ temp
^ sum
;
1429 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1430 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1431 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1434 case 0x95: /* SUB L */
1438 cbits
= acu
^ temp
^ sum
;
1439 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1440 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1441 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1444 case 0x96: /* SUB (HL) */
1448 cbits
= acu
^ temp
^ sum
;
1449 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1450 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1451 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1454 case 0x97: /* SUB A */
1458 cbits
= acu
^ temp
^ sum
;
1459 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1460 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1461 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1464 case 0x98: /* SBC A,B */
1467 sum
= acu
- temp
- TSTFLAG(C
);
1468 cbits
= acu
^ temp
^ sum
;
1469 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1470 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1471 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1474 case 0x99: /* SBC A,C */
1477 sum
= acu
- temp
- TSTFLAG(C
);
1478 cbits
= acu
^ temp
^ sum
;
1479 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1480 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1481 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1484 case 0x9A: /* SBC A,D */
1487 sum
= acu
- temp
- TSTFLAG(C
);
1488 cbits
= acu
^ temp
^ sum
;
1489 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1490 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1491 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1494 case 0x9B: /* SBC A,E */
1497 sum
= acu
- temp
- TSTFLAG(C
);
1498 cbits
= acu
^ temp
^ sum
;
1499 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1500 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1501 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1504 case 0x9C: /* SBC A,H */
1507 sum
= acu
- temp
- TSTFLAG(C
);
1508 cbits
= acu
^ temp
^ sum
;
1509 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1510 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1511 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1514 case 0x9D: /* SBC A,L */
1517 sum
= acu
- temp
- TSTFLAG(C
);
1518 cbits
= acu
^ temp
^ sum
;
1519 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1520 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1521 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1524 case 0x9E: /* SBC A,(HL) */
1527 sum
= acu
- temp
- TSTFLAG(C
);
1528 cbits
= acu
^ temp
^ sum
;
1529 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1530 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1531 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1534 case 0x9F: /* SBC A,A */
1537 sum
= acu
- temp
- TSTFLAG(C
);
1538 cbits
= acu
^ temp
^ sum
;
1539 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1540 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1541 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1544 case 0xA0: /* AND B */
1545 sum
= ((AF
& (BC
)) >> 8) & 0xff;
1546 AF
= (sum
<< 8) | (sum
& 0xa8) |
1547 ((sum
== 0) << 6) | 0x10 | partab
[sum
];
1549 case 0xA1: /* AND C */
1550 sum
= ((AF
>> 8) & BC
) & 0xff;
1551 AF
= (sum
<< 8) | (sum
& 0xa8) | 0x10 |
1552 ((sum
== 0) << 6) | partab
[sum
];
1554 case 0xA2: /* AND D */
1555 sum
= ((AF
& (DE
)) >> 8) & 0xff;
1556 AF
= (sum
<< 8) | (sum
& 0xa8) |
1557 ((sum
== 0) << 6) | 0x10 | partab
[sum
];
1559 case 0xA3: /* AND E */
1560 sum
= ((AF
>> 8) & DE
) & 0xff;
1561 AF
= (sum
<< 8) | (sum
& 0xa8) | 0x10 |
1562 ((sum
== 0) << 6) | partab
[sum
];
1564 case 0xA4: /* AND H */
1565 sum
= ((AF
& (HL
)) >> 8) & 0xff;
1566 AF
= (sum
<< 8) | (sum
& 0xa8) |
1567 ((sum
== 0) << 6) | 0x10 | partab
[sum
];
1569 case 0xA5: /* AND L */
1570 sum
= ((AF
>> 8) & HL
) & 0xff;
1571 AF
= (sum
<< 8) | (sum
& 0xa8) | 0x10 |
1572 ((sum
== 0) << 6) | partab
[sum
];
1574 case 0xA6: /* AND (HL) */
1575 sum
= ((AF
>> 8) & GetBYTE(HL
)) & 0xff;
1576 AF
= (sum
<< 8) | (sum
& 0xa8) | 0x10 |
1577 ((sum
== 0) << 6) | partab
[sum
];
1579 case 0xA7: /* AND A */
1580 sum
= ((AF
& (AF
)) >> 8) & 0xff;
1581 AF
= (sum
<< 8) | (sum
& 0xa8) |
1582 ((sum
== 0) << 6) | 0x10 | partab
[sum
];
1584 case 0xA8: /* XOR B */
1585 sum
= ((AF
^ (BC
)) >> 8) & 0xff;
1586 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1588 case 0xA9: /* XOR C */
1589 sum
= ((AF
>> 8) ^ BC
) & 0xff;
1590 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1592 case 0xAA: /* XOR D */
1593 sum
= ((AF
^ (DE
)) >> 8) & 0xff;
1594 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1596 case 0xAB: /* XOR E */
1597 sum
= ((AF
>> 8) ^ DE
) & 0xff;
1598 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1600 case 0xAC: /* XOR H */
1601 sum
= ((AF
^ (HL
)) >> 8) & 0xff;
1602 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1604 case 0xAD: /* XOR L */
1605 sum
= ((AF
>> 8) ^ HL
) & 0xff;
1606 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1608 case 0xAE: /* XOR (HL) */
1609 sum
= ((AF
>> 8) ^ GetBYTE(HL
)) & 0xff;
1610 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1612 case 0xAF: /* XOR A */
1613 sum
= ((AF
^ (AF
)) >> 8) & 0xff;
1614 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1616 case 0xB0: /* OR B */
1617 sum
= ((AF
| (BC
)) >> 8) & 0xff;
1618 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1620 case 0xB1: /* OR C */
1621 sum
= ((AF
>> 8) | BC
) & 0xff;
1622 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1624 case 0xB2: /* OR D */
1625 sum
= ((AF
| (DE
)) >> 8) & 0xff;
1626 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1628 case 0xB3: /* OR E */
1629 sum
= ((AF
>> 8) | DE
) & 0xff;
1630 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1632 case 0xB4: /* OR H */
1633 sum
= ((AF
| (HL
)) >> 8) & 0xff;
1634 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1636 case 0xB5: /* OR L */
1637 sum
= ((AF
>> 8) | HL
) & 0xff;
1638 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1640 case 0xB6: /* OR (HL) */
1641 sum
= ((AF
>> 8) | GetBYTE(HL
)) & 0xff;
1642 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1644 case 0xB7: /* OR A */
1645 sum
= ((AF
| (AF
)) >> 8) & 0xff;
1646 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
1648 case 0xB8: /* CP B */
1650 AF
= (AF
& ~0x28) | (temp
& 0x28);
1653 cbits
= acu
^ temp
^ sum
;
1654 AF
= (AF
& ~0xff) | (sum
& 0x80) |
1655 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
1656 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1657 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1659 case 0xB9: /* CP C */
1661 AF
= (AF
& ~0x28) | (temp
& 0x28);
1664 cbits
= acu
^ temp
^ sum
;
1665 AF
= (AF
& ~0xff) | (sum
& 0x80) |
1666 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
1667 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1668 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1670 case 0xBA: /* CP D */
1672 AF
= (AF
& ~0x28) | (temp
& 0x28);
1675 cbits
= acu
^ temp
^ sum
;
1676 AF
= (AF
& ~0xff) | (sum
& 0x80) |
1677 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
1678 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1679 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1681 case 0xBB: /* CP E */
1683 AF
= (AF
& ~0x28) | (temp
& 0x28);
1686 cbits
= acu
^ temp
^ sum
;
1687 AF
= (AF
& ~0xff) | (sum
& 0x80) |
1688 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
1689 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1690 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1692 case 0xBC: /* CP H */
1694 AF
= (AF
& ~0x28) | (temp
& 0x28);
1697 cbits
= acu
^ temp
^ sum
;
1698 AF
= (AF
& ~0xff) | (sum
& 0x80) |
1699 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
1700 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1701 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1703 case 0xBD: /* CP L */
1705 AF
= (AF
& ~0x28) | (temp
& 0x28);
1708 cbits
= acu
^ temp
^ sum
;
1709 AF
= (AF
& ~0xff) | (sum
& 0x80) |
1710 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
1711 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1712 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1714 case 0xBE: /* CP (HL) */
1716 AF
= (AF
& ~0x28) | (temp
& 0x28);
1719 cbits
= acu
^ temp
^ sum
;
1720 AF
= (AF
& ~0xff) | (sum
& 0x80) |
1721 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
1722 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1723 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1725 case 0xBF: /* CP A */
1727 AF
= (AF
& ~0x28) | (temp
& 0x28);
1730 cbits
= acu
^ temp
^ sum
;
1731 AF
= (AF
& ~0xff) | (sum
& 0x80) |
1732 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
1733 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1734 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1736 case 0xC0: /* RET NZ */
1737 if (!TSTFLAG(Z
)) POP(PC
);
1739 case 0xC1: /* POP BC */
1742 case 0xC2: /* JP NZ,nnnn */
1745 case 0xC3: /* JP nnnn */
1748 case 0xC4: /* CALL NZ,nnnn */
1751 case 0xC5: /* PUSH BC */
1754 case 0xC6: /* ADD A,nn */
1758 cbits
= acu
^ temp
^ sum
;
1759 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1760 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1761 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1765 case 0xC7: /* RST 0 */
1768 case 0xC8: /* RET Z */
1769 if (TSTFLAG(Z
)) POP(PC
);
1771 case 0xC9: /* RET */
1774 case 0xCA: /* JP Z,nnnn */
1777 case 0xCB: /* CB prefix */
1782 case 0xCC: /* CALL Z,nnnn */
1785 case 0xCD: /* CALL nnnn */
1788 case 0xCE: /* ADC A,nn */
1791 sum
= acu
+ temp
+ TSTFLAG(C
);
1792 cbits
= acu
^ temp
^ sum
;
1793 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1794 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1795 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1799 case 0xCF: /* RST 8 */
1802 case 0xD0: /* RET NC */
1803 if (!TSTFLAG(C
)) POP(PC
);
1805 case 0xD1: /* POP DE */
1808 case 0xD2: /* JP NC,nnnn */
1811 case 0xD3: /* OUT (nn),A */
1812 Output(GetBYTE(PC
), hreg(AF
)); ++PC
;
1814 case 0xD4: /* CALL NC,nnnn */
1817 case 0xD5: /* PUSH DE */
1820 case 0xD6: /* SUB nn */
1824 cbits
= acu
^ temp
^ sum
;
1825 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1826 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1827 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1831 case 0xD7: /* RST 10H */
1832 PUSH(PC
); PC
= 0x10;
1834 case 0xD8: /* RET C */
1835 if (TSTFLAG(C
)) POP(PC
);
1837 case 0xD9: /* EXX */
1838 regs
[regs_sel
].bc
= BC
;
1839 regs
[regs_sel
].de
= DE
;
1840 regs
[regs_sel
].hl
= HL
;
1841 regs_sel
= 1 - regs_sel
;
1842 BC
= regs
[regs_sel
].bc
;
1843 DE
= regs
[regs_sel
].de
;
1844 HL
= regs
[regs_sel
].hl
;
1846 case 0xDA: /* JP C,nnnn */
1849 case 0xDB: /* IN A,(nn) */
1850 Sethreg(AF
, Input(GetBYTE(PC
))); ++PC
;
1852 case 0xDC: /* CALL C,nnnn */
1855 case 0xDD: /* DD prefix */
1857 ix
= dfd_prefix(ix
);
1860 case 0xDE: /* SBC A,nn */
1863 sum
= acu
- temp
- TSTFLAG(C
);
1864 cbits
= acu
^ temp
^ sum
;
1865 AF
= ((sum
& 0xff) << 8) | (sum
& 0xa8) |
1866 (((sum
& 0xff) == 0) << 6) | (cbits
& 0x10) |
1867 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
1871 case 0xDF: /* RST 18H */
1872 PUSH(PC
); PC
= 0x18;
1874 case 0xE0: /* RET PO */
1875 if (!TSTFLAG(P
)) POP(PC
);
1877 case 0xE1: /* POP HL */
1880 case 0xE2: /* JP PO,nnnn */
1883 case 0xE3: /* EX (SP),HL */
1884 temp
= HL
; POP(HL
); PUSH(temp
);
1886 case 0xE4: /* CALL PO,nnnn */
1889 case 0xE5: /* PUSH HL */
1892 case 0xE6: /* AND nn */
1893 sum
= ((AF
>> 8) & GetBYTE(PC
)) & 0xff;
1894 AF
= (sum
<< 8) | (sum
& 0xa8) | 0x10 |
1895 ((sum
== 0) << 6) | partab
[sum
];
1898 case 0xE7: /* RST 20H */
1899 PUSH(PC
); PC
= 0x20;
1901 case 0xE8: /* RET PE */
1902 if (TSTFLAG(P
)) POP(PC
);
1904 case 0xE9: /* JP (HL) */
1907 case 0xEA: /* JP PE,nnnn */
1910 case 0xEB: /* EX DE,HL */
1911 temp
= HL
; HL
= DE
; DE
= temp
;
1913 case 0xEC: /* CALL PE,nnnn */
1916 case 0xED: /* ED prefix */
1917 switch (++PC
, op
= GetBYTE(PC
-1)) {
1918 case 0x40: /* IN B,(C) */
1919 temp
= Input(lreg(BC
));
1921 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
1922 (((temp
& 0xff) == 0) << 6) |
1925 case 0x41: /* OUT (C),B */
1926 Output(lreg(BC
), BC
);
1928 case 0x42: /* SBC HL,BC */
1931 sum
= HL
- BC
- TSTFLAG(C
);
1932 cbits
= (HL
^ BC
^ sum
) >> 8;
1934 AF
= (AF
& ~0xff) | ((sum
>> 8) & 0xa8) |
1935 (((sum
& 0xffff) == 0) << 6) |
1936 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1937 (cbits
& 0x10) | 2 | ((cbits
>> 8) & 1);
1939 case 0x43: /* LD (nnnn),BC */
1944 case 0x44: /* NEG */
1946 AF
= (-(AF
& 0xff00) & 0xff00);
1947 AF
|= ((AF
>> 8) & 0xa8) | (((AF
& 0xff00) == 0) << 6) |
1948 (((temp
& 0x0f) != 0) << 4) | ((temp
== 0x80) << 2) |
1951 case 0x45: /* RETN */
1955 case 0x46: /* IM 0 */
1956 /* interrupt mode 0 */
1958 case 0x47: /* LD I,A */
1959 ir
= (ir
& 255) | (AF
& ~255);
1961 case 0x48: /* IN C,(C) */
1962 temp
= Input(lreg(BC
));
1964 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
1965 (((temp
& 0xff) == 0) << 6) |
1968 case 0x49: /* OUT (C),C */
1969 Output(lreg(BC
), BC
);
1971 case 0x4A: /* ADC HL,BC */
1974 sum
= HL
+ BC
+ TSTFLAG(C
);
1975 cbits
= (HL
^ BC
^ sum
) >> 8;
1977 AF
= (AF
& ~0xff) | ((sum
>> 8) & 0xa8) |
1978 (((sum
& 0xffff) == 0) << 6) |
1979 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
1980 (cbits
& 0x10) | ((cbits
>> 8) & 1);
1982 case 0x4B: /* LD BC,(nnnn) */
1987 case 0x4D: /* RETI */
1991 case 0x4F: /* LD R,A */
1992 ir
= (ir
& ~255) | ((AF
>> 8) & 255);
1994 case 0x50: /* IN D,(C) */
1995 temp
= Input(lreg(BC
));
1997 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
1998 (((temp
& 0xff) == 0) << 6) |
2001 case 0x51: /* OUT (C),D */
2002 Output(lreg(BC
), DE
);
2004 case 0x52: /* SBC HL,DE */
2007 sum
= HL
- DE
- TSTFLAG(C
);
2008 cbits
= (HL
^ DE
^ sum
) >> 8;
2010 AF
= (AF
& ~0xff) | ((sum
>> 8) & 0xa8) |
2011 (((sum
& 0xffff) == 0) << 6) |
2012 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
2013 (cbits
& 0x10) | 2 | ((cbits
>> 8) & 1);
2015 case 0x53: /* LD (nnnn),DE */
2020 case 0x56: /* IM 1 */
2021 /* interrupt mode 1 */
2023 case 0x57: /* LD A,I */
2024 AF
= (AF
& 0x29) | (ir
& ~255) | ((ir
>> 8) & 0x80) | (((ir
& ~255) == 0) << 6) | ((IFF
& 2) << 1);
2026 case 0x58: /* IN E,(C) */
2027 temp
= Input(lreg(BC
));
2029 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
2030 (((temp
& 0xff) == 0) << 6) |
2033 case 0x59: /* OUT (C),E */
2034 Output(lreg(BC
), DE
);
2036 case 0x5A: /* ADC HL,DE */
2039 sum
= HL
+ DE
+ TSTFLAG(C
);
2040 cbits
= (HL
^ DE
^ sum
) >> 8;
2042 AF
= (AF
& ~0xff) | ((sum
>> 8) & 0xa8) |
2043 (((sum
& 0xffff) == 0) << 6) |
2044 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
2045 (cbits
& 0x10) | ((cbits
>> 8) & 1);
2047 case 0x5B: /* LD DE,(nnnn) */
2052 case 0x5E: /* IM 2 */
2053 /* interrupt mode 2 */
2055 case 0x5F: /* LD A,R */
2056 AF
= (AF
& 0x29) | ((ir
& 255) << 8) | (ir
& 0x80) | (((ir
& 255) == 0) << 6) | ((IFF
& 2) << 1);
2058 case 0x60: /* IN H,(C) */
2059 temp
= Input(lreg(BC
));
2061 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
2062 (((temp
& 0xff) == 0) << 6) |
2065 case 0x61: /* OUT (C),H */
2066 Output(lreg(BC
), HL
);
2068 case 0x62: /* SBC HL,HL */
2070 sum
= HL
- HL
- TSTFLAG(C
);
2071 cbits
= (HL
^ HL
^ sum
) >> 8;
2073 AF
= (AF
& ~0xff) | ((sum
>> 8) & 0xa8) |
2074 (((sum
& 0xffff) == 0) << 6) |
2075 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
2076 (cbits
& 0x10) | 2 | ((cbits
>> 8) & 1);
2078 case 0x63: /* LD (nnnn),HL */
2083 case 0x67: /* RRD */
2086 PutBYTE(HL
, hdig(temp
) | (ldig(acu
) << 4));
2087 acu
= (acu
& 0xf0) | ldig(temp
);
2088 AF
= (acu
<< 8) | (acu
& 0xa8) | (((acu
& 0xff) == 0) << 6) |
2089 partab
[acu
] | (AF
& 1);
2091 case 0x68: /* IN L,(C) */
2092 temp
= Input(lreg(BC
));
2094 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
2095 (((temp
& 0xff) == 0) << 6) |
2098 case 0x69: /* OUT (C),L */
2099 Output(lreg(BC
), HL
);
2101 case 0x6A: /* ADC HL,HL */
2103 sum
= HL
+ HL
+ TSTFLAG(C
);
2104 cbits
= (HL
^ HL
^ sum
) >> 8;
2106 AF
= (AF
& ~0xff) | ((sum
>> 8) & 0xa8) |
2107 (((sum
& 0xffff) == 0) << 6) |
2108 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
2109 (cbits
& 0x10) | ((cbits
>> 8) & 1);
2111 case 0x6B: /* LD HL,(nnnn) */
2116 case 0x6F: /* RLD */
2119 PutBYTE(HL
, (ldig(temp
) << 4) | ldig(acu
));
2120 acu
= (acu
& 0xf0) | hdig(temp
);
2121 AF
= (acu
<< 8) | (acu
& 0xa8) | (((acu
& 0xff) == 0) << 6) |
2122 partab
[acu
] | (AF
& 1);
2124 case 0x70: /* IN (C) */
2125 temp
= Input(lreg(BC
));
2126 Setlreg(temp
, temp
);
2127 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
2128 (((temp
& 0xff) == 0) << 6) |
2131 case 0x71: /* OUT (C),0 */
2132 Output(lreg(BC
), 0);
2134 case 0x72: /* SBC HL,SP */
2137 sum
= HL
- SP
- TSTFLAG(C
);
2138 cbits
= (HL
^ SP
^ sum
) >> 8;
2140 AF
= (AF
& ~0xff) | ((sum
>> 8) & 0xa8) |
2141 (((sum
& 0xffff) == 0) << 6) |
2142 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
2143 (cbits
& 0x10) | 2 | ((cbits
>> 8) & 1);
2145 case 0x73: /* LD (nnnn),SP */
2150 case 0x78: /* IN A,(C) */
2151 temp
= Input(lreg(BC
));
2153 AF
= (AF
& ~0xfe) | (temp
& 0xa8) |
2154 (((temp
& 0xff) == 0) << 6) |
2157 case 0x79: /* OUT (C),A */
2158 Output(lreg(BC
), AF
);
2160 case 0x7A: /* ADC HL,SP */
2163 sum
= HL
+ SP
+ TSTFLAG(C
);
2164 cbits
= (HL
^ SP
^ sum
) >> 8;
2166 AF
= (AF
& ~0xff) | ((sum
>> 8) & 0xa8) |
2167 (((sum
& 0xffff) == 0) << 6) |
2168 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) |
2169 (cbits
& 0x10) | ((cbits
>> 8) & 1);
2171 case 0x7B: /* LD SP,(nnnn) */
2176 case 0xA0: /* LDI */
2177 acu
= GetBYTE(HL
); ++HL
;
2178 PutBYTE(DE
, acu
); ++DE
;
2180 AF
= (AF
& ~0x3e) | (acu
& 8) | ((acu
& 2) << 4) |
2181 (((--BC
& 0xffff) != 0) << 2);
2183 case 0xA1: /* CPI */
2185 temp
= GetBYTE(HL
); ++HL
;
2187 cbits
= acu
^ temp
^ sum
;
2188 AF
= (AF
& ~0xfe) | (sum
& 0x80) | (!(sum
& 0xff) << 6) |
2189 (((sum
- ((cbits
&16)>>4))&2) << 4) | (cbits
& 16) |
2190 ((sum
- ((cbits
>> 4) & 1)) & 8) |
2191 ((--BC
& 0xffff) != 0) << 2 | 2;
2192 if ((sum
& 15) == 8 && (cbits
& 16) != 0)
2195 case 0xA2: /* INI */
2196 PutBYTE(HL
, Input(lreg(BC
))); ++HL
;
2198 SETFLAG(P
, (--BC
& 0xffff) != 0);
2200 case 0xA3: /* OUTI */
2201 Output(lreg(BC
), GetBYTE(HL
)); ++HL
;
2203 Sethreg(BC
, lreg(BC
) - 1);
2204 SETFLAG(Z
, lreg(BC
) == 0);
2206 case 0xA8: /* LDD */
2207 acu
= GetBYTE(HL
); --HL
;
2208 PutBYTE(DE
, acu
); --DE
;
2210 AF
= (AF
& ~0x3e) | (acu
& 8) | ((acu
& 2) << 4) |
2211 (((--BC
& 0xffff) != 0) << 2);
2213 case 0xA9: /* CPD */
2215 temp
= GetBYTE(HL
); --HL
;
2217 cbits
= acu
^ temp
^ sum
;
2218 AF
= (AF
& ~0xfe) | (sum
& 0x80) | (!(sum
& 0xff) << 6) |
2219 (((sum
- ((cbits
&16)>>4))&2) << 4) | (cbits
& 16) |
2220 ((sum
- ((cbits
>> 4) & 1)) & 8) |
2221 ((--BC
& 0xffff) != 0) << 2 | 2;
2222 if ((sum
& 15) == 8 && (cbits
& 16) != 0)
2225 case 0xAA: /* IND */
2226 PutBYTE(HL
, Input(lreg(BC
))); --HL
;
2228 Sethreg(BC
, lreg(BC
) - 1);
2229 SETFLAG(Z
, lreg(BC
) == 0);
2231 case 0xAB: /* OUTD */
2232 Output(lreg(BC
), GetBYTE(HL
)); --HL
;
2234 Sethreg(BC
, lreg(BC
) - 1);
2235 SETFLAG(Z
, lreg(BC
) == 0);
2237 case 0xB0: /* LDIR */
2241 acu
= GetBYTE(HL
); ++HL
;
2242 PutBYTE(DE
, acu
); ++DE
;
2245 AF
= (AF
& ~0x3e) | (acu
& 8) | ((acu
& 2) << 4);
2247 case 0xB1: /* CPIR */
2251 temp
= GetBYTE(HL
); ++HL
;
2254 } while (op
&& sum
!= 0);
2255 cbits
= acu
^ temp
^ sum
;
2256 AF
= (AF
& ~0xfe) | (sum
& 0x80) | (!(sum
& 0xff) << 6) |
2257 (((sum
- ((cbits
&16)>>4))&2) << 4) |
2258 (cbits
& 16) | ((sum
- ((cbits
>> 4) & 1)) & 8) |
2260 if ((sum
& 15) == 8 && (cbits
& 16) != 0)
2263 case 0xB2: /* INIR */
2266 PutBYTE(HL
, Input(lreg(BC
))); ++HL
;
2272 case 0xB3: /* OTIR */
2275 Output(lreg(BC
), GetBYTE(HL
)); ++HL
;
2281 case 0xB8: /* LDDR */
2284 acu
= GetBYTE(HL
); --HL
;
2285 PutBYTE(DE
, acu
); --DE
;
2288 AF
= (AF
& ~0x3e) | (acu
& 8) | ((acu
& 2) << 4);
2290 case 0xB9: /* CPDR */
2294 temp
= GetBYTE(HL
); --HL
;
2297 } while (op
&& sum
!= 0);
2298 cbits
= acu
^ temp
^ sum
;
2299 AF
= (AF
& ~0xfe) | (sum
& 0x80) | (!(sum
& 0xff) << 6) |
2300 (((sum
- ((cbits
&16)>>4))&2) << 4) |
2301 (cbits
& 16) | ((sum
- ((cbits
>> 4) & 1)) & 8) |
2303 if ((sum
& 15) == 8 && (cbits
& 16) != 0)
2306 case 0xBA: /* INDR */
2309 PutBYTE(HL
, Input(lreg(BC
))); --HL
;
2315 case 0xBB: /* OTDR */
2318 Output(lreg(BC
), GetBYTE(HL
)); --HL
;
2324 default: if (0x40 <= op
&& op
<= 0x7f) PC
--; /* ignore ED */
2327 case 0xEE: /* XOR nn */
2328 sum
= ((AF
>> 8) ^ GetBYTE(PC
)) & 0xff;
2329 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
2332 case 0xEF: /* RST 28H */
2333 PUSH(PC
); PC
= 0x28;
2335 case 0xF0: /* RET P */
2336 if (!TSTFLAG(S
)) POP(PC
);
2338 case 0xF1: /* POP AF */
2341 case 0xF2: /* JP P,nnnn */
2347 case 0xF4: /* CALL P,nnnn */
2350 case 0xF5: /* PUSH AF */
2353 case 0xF6: /* OR nn */
2354 sum
= ((AF
>> 8) | GetBYTE(PC
)) & 0xff;
2355 AF
= (sum
<< 8) | (sum
& 0xa8) | ((sum
== 0) << 6) | partab
[sum
];
2358 case 0xF7: /* RST 30H */
2359 PUSH(PC
); PC
= 0x30;
2361 case 0xF8: /* RET M */
2362 if (TSTFLAG(S
)) POP(PC
);
2364 case 0xF9: /* LD SP,HL */
2367 case 0xFA: /* JP M,nnnn */
2373 case 0xFC: /* CALL M,nnnn */
2376 case 0xFD: /* FD prefix */
2378 iy
= dfd_prefix(iy
);
2381 case 0xFE: /* CP nn */
2383 AF
= (AF
& ~0x28) | (temp
& 0x28);
2386 cbits
= acu
^ temp
^ sum
;
2387 AF
= (AF
& ~0xff) | (sum
& 0x80) |
2388 (((sum
& 0xff) == 0) << 6) | (temp
& 0x28) |
2389 (((cbits
>> 6) ^ (cbits
>> 5)) & 4) | 2 |
2390 (cbits
& 0x10) | ((cbits
>> 8) & 1);
2393 case 0xFF: /* RST 38H */
2394 PUSH(PC
); PC
= 0x38;
2397 /* make registers visible for debugging if interrupted */
2399 return (PC
&0xffff)|0x10000; /* flag non-bios stop */