Prepare new maemo release
[maemo-rb.git] / apps / plugins / pacbox / z80.c
blob575771c5e41227d6b7e85d38bf38918267e9c772
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Pacbox - a Pacman Emulator for Rockbox
12 * Based on PIE - Pacman Instructional Emulator
14 * Copyright (c) 1997-2003,2004 Alessandro Scotti
15 * http://www.ascotti.org/
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
25 ****************************************************************************/
27 #include "plugin.h"
28 #include "hardware.h"
29 #include "z80.h"
30 #include "z80_internal.h"
32 // Table with parity, sign and zero flags precomputed for each byte value
33 unsigned char PSZ_[256] IDATA_ATTR = {
34 Zero|Parity, 0, 0, Parity, 0, Parity, Parity, 0, 0, Parity, Parity, 0, Parity, 0, 0, Parity,
35 0, Parity, Parity, 0, Parity, 0, 0, Parity, Parity, 0, 0, Parity, 0, Parity, Parity, 0,
36 0, Parity, Parity, 0, Parity, 0, 0, Parity, Parity, 0, 0, Parity, 0, Parity, Parity, 0,
37 Parity, 0, 0, Parity, 0, Parity, Parity, 0, 0, Parity, Parity, 0, Parity, 0, 0, Parity,
38 0, Parity, Parity, 0, Parity, 0, 0, Parity, Parity, 0, 0, Parity, 0, Parity, Parity, 0,
39 Parity, 0, 0, Parity, 0, Parity, Parity, 0, 0, Parity, Parity, 0, Parity, 0, 0, Parity,
40 Parity, 0, 0, Parity, 0, Parity, Parity, 0, 0, Parity, Parity, 0, Parity, 0, 0, Parity,
41 0, Parity, Parity, 0, Parity, 0, 0, Parity, Parity, 0, 0, Parity, 0, Parity, Parity, 0,
42 Sign, Sign|Parity, Sign|Parity, Sign, Sign|Parity, Sign, Sign, Sign|Parity, Sign|Parity, Sign, Sign, Sign|Parity, Sign, Sign|Parity, Sign|Parity, Sign,
43 Sign|Parity, Sign, Sign, Sign|Parity, Sign, Sign|Parity, Sign|Parity, Sign, Sign, Sign|Parity, Sign|Parity, Sign, Sign|Parity, Sign, Sign, Sign|Parity,
44 Sign|Parity, Sign, Sign, Sign|Parity, Sign, Sign|Parity, Sign|Parity, Sign, Sign, Sign|Parity, Sign|Parity, Sign, Sign|Parity, Sign, Sign, Sign|Parity,
45 Sign, Sign|Parity, Sign|Parity, Sign, Sign|Parity, Sign, Sign, Sign|Parity, Sign|Parity, Sign, Sign, Sign|Parity, Sign, Sign|Parity, Sign|Parity, Sign,
46 Sign|Parity, Sign, Sign, Sign|Parity, Sign, Sign|Parity, Sign|Parity, Sign, Sign, Sign|Parity, Sign|Parity, Sign, Sign|Parity, Sign, Sign, Sign|Parity,
47 Sign, Sign|Parity, Sign|Parity, Sign, Sign|Parity, Sign, Sign, Sign|Parity, Sign|Parity, Sign, Sign, Sign|Parity, Sign, Sign|Parity, Sign|Parity, Sign,
48 Sign, Sign|Parity, Sign|Parity, Sign, Sign|Parity, Sign, Sign, Sign|Parity, Sign|Parity, Sign, Sign, Sign|Parity, Sign, Sign|Parity, Sign|Parity, Sign,
49 Sign|Parity, Sign, Sign, Sign|Parity, Sign, Sign|Parity, Sign|Parity, Sign, Sign, Sign|Parity, Sign|Parity, Sign, Sign|Parity, Sign, Sign, Sign|Parity
52 // Interrupt flags
53 enum {
54 IFF1 = 0x40, // Interrupts enabled/disabled
55 IFF2 = 0x20, // Copy of IFF1 (used by non-maskable interrupts)
56 Halted = 0x10 // Internal use: signals that the CPU is halted
59 // Implements an opcode
60 typedef void (OpcodeHandler)(void);
62 typedef struct {
63 OpcodeHandler* handler;
64 unsigned cycles;
65 } OpcodeInfo;
67 // Implements an opcode for instructions that use the form (IX/IY + b)
68 typedef void (OpcodeHandlerXY)( unsigned );
70 typedef struct {
71 OpcodeHandlerXY* handler;
72 unsigned cycles;
73 } OpcodeInfoXY;
75 /** */
76 void do_opcode_xy( OpcodeInfo * );
78 /** */
79 unsigned do_opcode_xycb( unsigned xy );
81 unsigned iflags_ IBSS_ATTR; // Interrupt mode (bits 0 and 1) and flags
82 unsigned cycles_ IBSS_ATTR; // Number of CPU cycles elapsed so far
85 // Registers
86 unsigned char B IBSS_ATTR; //@- B register
87 unsigned char C IBSS_ATTR; //@- C register
88 unsigned char D IBSS_ATTR; //@- D register
89 unsigned char E IBSS_ATTR; //@- E register
90 unsigned char H IBSS_ATTR; //@- H register
91 unsigned char L IBSS_ATTR; //@- L register
92 unsigned char A IBSS_ATTR; //@- A register (accumulator)
93 unsigned char F IBSS_ATTR; //@- Flags register
94 unsigned char B1 IBSS_ATTR; //@- Alternate B register (B')
95 unsigned char C1 IBSS_ATTR; //@- Alternate C register (C')
96 unsigned char D1 IBSS_ATTR; //@- Alternate D register (D')
97 unsigned char E1 IBSS_ATTR; //@- Alternate E register (E')
98 unsigned char H1 IBSS_ATTR; //@- Alternate H register (H')
99 unsigned char L1 IBSS_ATTR; //@- Alternate L register (L')
100 unsigned char A1 IBSS_ATTR; //@- Alternate A register (A')
101 unsigned char F1 IBSS_ATTR; //@- Alternate flags register (F')
102 unsigned IX IBSS_ATTR; //@- Index register X
103 unsigned IY IBSS_ATTR; //@- Index register Y
104 unsigned PC IBSS_ATTR; //@- Program counter
105 unsigned SP IBSS_ATTR; //@- Stack pointer
106 unsigned char I IBSS_ATTR; //@- Interrupt register
107 unsigned char R IBSS_ATTR; //@- Refresh register
110 /** Returns the 16 bit register BC. */
111 #define BC() (((unsigned)B << 8) | C)
112 #define DE() (((unsigned)D << 8) | E)
113 #define HL() (((unsigned)H << 8) | L)
115 /**
116 Returns the number of Z80 CPU cycles elapsed so far.
118 The cycle count is reset to zero when reset() is called, or
119 it can be set to any value with setCycles(). It is updated after
120 a CPU instruction is executed, for example by calling step()
121 or interrupt().
123 unsigned getCycles(void) {
124 return cycles_;
127 /** Sets the CPU cycle counter to the specified value. */
128 void setCycles( unsigned value ) {
129 cycles_ = value;
132 /** Returns the current interrupt mode. */
133 unsigned getInterruptMode(void) {
134 return iflags_ & 0x03;
137 /** Sets the interrupt mode to the specified value. */
138 void setInterruptMode( unsigned mode );
140 /** Returns non-zero if the CPU is halted, otherwise zero. */
141 int isHalted(void) {
142 return iflags_ & Halted;
146 Sets the interrupt mode to IM0, IM1 or IM2.
148 void setInterruptMode( unsigned mode )
150 if( mode <= 2 ) {
151 iflags_ = (iflags_ & ~0x03) | mode;
156 Calls a subroutine at the specified address.
158 void callSub( unsigned addr )
160 SP -= 2;
161 writeWord( SP, PC ); // Save current program counter in the stack
162 PC = addr & 0xFFFF; // Jump to the specified address
166 Decrements a byte value by one.
167 Note that this is different from subtracting one from the byte value,
168 because flags behave differently.
170 static inline unsigned char decByte( unsigned char b )
172 F = Subtraction | (F & Carry); // Preserve the carry flag
173 if( (b & 0x0F) == 0 ) F |= Halfcarry;
174 --b;
175 if( b == 0x7F ) F |= Overflow;
176 if( b & 0x80 ) F |= Sign;
177 if( b == 0 ) F |= Zero;
179 return b;
183 Increments a byte value by one.
184 Note that this is different from adding one to the byte value,
185 because flags behave differently.
187 static inline unsigned char incByte( unsigned char b )
189 ++b;
190 F &= Carry; // Preserve the carry flag
191 if( ! (b & 0x0F) ) F |= Halfcarry;
192 if( b == 0x80 ) F |= Overflow;
193 if( b & 0x80 ) F |= Sign;
194 if( b == 0 ) F |= Zero;
196 return b;
200 Reads one byte from port C, updating flags according to the rules of "IN r,(C)".
202 static inline unsigned char inpReg(void)
204 unsigned char r = readPort( C );
206 F = (F & Carry) | PSZ_[r];
208 return r;
212 Performs a relative jump to the specified offset.
214 static inline void relJump( unsigned char o )
216 int offset = (int)((signed char)o);
218 PC = (unsigned)((int)PC + offset) & 0xFFFF;
219 cycles_++;
223 Returns from a subroutine, popping the saved Program Counter from the stack.
225 static inline void retFromSub(void)
227 PC = readWord( SP );
228 SP += 2;
232 Rotates left one byte thru the carry flag.
234 static inline unsigned char rotateLeft( unsigned char op )
236 unsigned char f = F;
238 F = 0;
239 if( op & 0x80 ) F |= Carry;
240 op <<= 1;
241 if( f & Carry ) op |= 0x01;
242 F |= PSZ_[op];
244 return op;
248 Rotates left one byte copying the most significant bit (bit 7) in the carry flag.
250 static inline unsigned char rotateLeftCarry( unsigned char op )
252 F = 0;
253 if( op & 0x80 ) F |= Carry;
254 op = (op << 1) | (op >> 7);
255 F |= PSZ_[op];
257 return op;
261 Rotates right one byte thru the carry flag.
263 static inline unsigned char rotateRight( unsigned char op )
265 unsigned char f = F;
267 F = 0;
268 if( op & 0x01 ) F |= Carry;
269 op >>= 1;
270 if( f & Carry ) op |= 0x80;
271 F |= PSZ_[op];
273 return op;
277 Rotates right one byte copying the least significant bit (bit 0) in the carry flag.
279 static inline unsigned char rotateRightCarry( unsigned char op )
281 F = 0;
282 if( op & 0x01 ) F |= Carry;
283 op = (op >> 1) | (op << 7);
284 F |= PSZ_[op];
286 return op;
290 Shifts left one byte.
292 static inline unsigned char shiftLeft( unsigned char op )
294 F = 0;
295 if( op & 0x80 ) F |= Carry;
296 op <<= 1;
297 F |= PSZ_[op];
299 return op;
303 Shifts right one byte, preserving its sign (most significant bit).
305 static inline unsigned char shiftRightArith( unsigned char op )
307 F = 0;
308 if( op & 0x01 ) F |= Carry;
309 op = (op >> 1) | (op & 0x80);
311 F |= PSZ_[op];
313 return op;
317 Shifts right one byte.
319 static inline unsigned char shiftRightLogical( unsigned char op )
321 F = 0;
322 if( op & 0x01 ) F |= Carry;
323 op >>= 1;
325 F |= PSZ_[op];
327 return op;
331 Tests whether the specified bit of op is set.
333 static inline void testBit( unsigned char bit, unsigned char op )
335 // Flags for a bit test operation are:
336 // S, P: unknown
337 // Z: set if bit is zero, reset otherwise
338 // N: reset
339 // H: set
340 // C: unaffected
341 // However, it seems that parity is always set like Z, so we emulate that as well.
342 F = (F & (Carry | Sign)) | Halfcarry;
344 if( (op & (1 << bit)) == 0 ) {
345 // Bit is not set, so set the zero flag
346 F |= Zero | Parity;
351 Adds the specified byte op to the accumulator, adding
352 carry.
354 static inline void addByte( unsigned char op, unsigned char cf )
356 unsigned x = A + op;
358 if( cf ) x++; // Add carry
360 F = 0;
361 if( !(x & 0xFF) ) F |= Zero;
362 if( x & 0x80 ) F |= Sign;
363 if( x >= 0x100 ) F |= Carry;
366 Halfcarry is set on carry from the low order four bits.
368 To see how to compute it, let's take a look at the following table, which
369 shows the binary addition of two binary numbers:
371 A B A+B
372 -----------
373 0 0 0
374 0 1 1
375 1 0 1
376 1 1 0
378 Note that if only the lowest bit is used, then A+B, A-B and A^B yield the same
379 value. If we know A, B and the sum A+B+C, then C is easily derived:
380 C = A+B+C - A - B, that is
381 C = A+B+C ^ A ^ B.
383 For the halfcarry, A and B above are the fifth bit of a byte, which corresponds
384 to the value 0x10. So:
386 Halfcarry = ((accumulator+operand+halfcarry) ^ accumulator ^ operand) & 0x10
388 Note that masking off all bits but one is important because we have worked all
389 the math by using one bit only.
391 if( (A ^ op ^ x) & 0x10 ) F |= Halfcarry;
394 The overflow bit is set when the result is too large to fit into the destination
395 register, causing a change in the sign bit.
397 For a sum, we can only have overflow when adding two numbers that are both positive
398 or both negative. For example 0x5E + 0x4B (94 + 75) yields 0xA9 (169), which fits
399 into an 8-bit register only if it is interpreted as an unsigned number. If we
400 consider the result as a signed integer, then 0xA9 corresponds to decimal -87 and
401 we have overflow.
402 Note that if we add two signed numbers of opposite sign then we cannot overflow
403 the destination register, because the absolute value of the result will always fit
404 in 7 bits, leaving the most significant bit free for use as a sign bit.
406 We can code all the above concisely by noting that:
408 ~(A ^ op) & 0x80
410 is true if and only if A and op have the same sign. Also:
412 (x ^ op) & 0x80
414 is true if and only if the sum of A and op has taken a sign opposite to that
415 of its operands.
417 Thus the expression:
419 ~(A ^ op) & (x ^ op) & 0x80
421 reads "A has the same sign as op, and the opposite as x", where x is the sum of
422 A and op (and an optional carry).
424 if( ~(A ^ op) & (x ^ op) & 0x80 ) F |= Overflow;
426 A = x;
430 Subtracts the specified byte op from the accumulator, using carry as
431 borrow from a previous operation.
433 static inline unsigned char subByte( unsigned char op, unsigned char cf )
435 unsigned char x = A - op;
437 if( cf ) x--;
439 F = Subtraction;
440 if( x == 0 ) F |= Zero;
441 if( x & 0x80 ) F |= Sign;
442 if( (x >= A) && (op | cf)) F |= Carry;
444 // See addByte() for an explanation of the halfcarry bit
445 if( (A ^ op ^ x) & 0x10 ) F |= Halfcarry;
447 // See addByte() for an explanation of the overflow bit. The only difference here
448 // is that for a subtraction we must check that the two operands have different
449 // sign, because in fact A-B is A+(-B). Note however that since subtraction is not
450 // symmetric, we have to use (x ^ A) to get the correct result, whereas for the
451 // addition (x ^ A) is equivalent to (x ^ op)
452 if( (A ^ op) & (x ^ A) & 0x80 ) F |= Overflow;
454 return x;
457 static inline unsigned addDispl( unsigned addr, unsigned char displ ) {
458 return (unsigned)((int)addr + (int)(signed char)displ);
461 /** Compares the accumulator and the specified operand (CP op) */
462 static inline void cmpByte( unsigned char op ) {
463 subByte( op, 0 );
466 /** Fetches a byte from the program counter location */
467 static inline unsigned char fetchByte(void) {
468 return readByte( PC++ );
471 /** Fetches a 16 bit word from the program counter location */
472 static inline unsigned fetchWord(void) {
473 unsigned x = readWord( PC );
474 PC += 2;
475 return x;
478 /** Sets the parity, sign and zero flags from the accumulator value */
479 static inline void setFlagsPSZ(void) {
480 F = Halfcarry | PSZ_[A];
483 /** Sets the parity, sign, zero, 3rd and 5th flag bits from the accumulator value */
484 static inline void setFlags35PSZ(void) {
485 F = (F & (Carry | Halfcarry | Subtraction)) | PSZ_[A];
488 /** */
489 static inline void setFlags35PSZ000(void) {
490 F = PSZ_[A];
493 /* Resets the CPU */
494 void z80_reset()
496 PC = 0; // Program counter is zero
497 I = 0; // Interrupt register cleared
498 R = 0; // Memory refresh register cleared
499 iflags_ = 0; // IFF1 and IFF2 cleared, IM0 enabled
500 cycles_ = 0; // Could that be 2 (according to some Zilog docs)?
502 // There is no official documentation for the following!
503 B = B1 = 0;
504 C = C1 = 0;
505 D = D1 = 0;
506 E = E1 = 0;
507 H = H1 = 0;
508 L = L1 = 0;
509 A = A1 = 0;
510 F = F1 = 0;
511 IX = 0;
512 IY = 0;
513 SP = 0xF000;
516 unsigned z80_getSizeOfSnapshotBuffer(void)
518 unsigned result =
519 8*2 + // 8-bit registers
520 1 + // I
521 1 + // R
522 2 + // IX
523 2 + // IY
524 2 + // PC
525 2 + // SP
526 4 + // iflags_
527 4; // cycles_
529 return result;
532 static unsigned saveUint16( unsigned char * buffer, unsigned u )
534 *buffer++ = (unsigned char) (u >> 8);
535 *buffer = (unsigned char) (u);
537 return 2;
540 unsigned z80_takeSnapshot( unsigned char * buffer )
542 unsigned char * buf = buffer;
544 *buf++ = A; *buf++ = A1;
545 *buf++ = B; *buf++ = B1;
546 *buf++ = C; *buf++ = C1;
547 *buf++ = D; *buf++ = D1;
548 *buf++ = E; *buf++ = E1;
549 *buf++ = H; *buf++ = H1;
550 *buf++ = L; *buf++ = L1;
551 *buf++ = F; *buf++ = F1;
553 *buf++ = I;
554 *buf++ = R;
556 buf += saveUint16( buf, IX );
557 buf += saveUint16( buf, IY );
558 buf += saveUint16( buf, PC );
559 buf += saveUint16( buf, SP );
561 buf += saveUint16( buf, iflags_ >> 16 );
562 buf += saveUint16( buf, iflags_ );
563 buf += saveUint16( buf, cycles_ >> 16 );
564 buf += saveUint16( buf, cycles_ );
566 return buffer - buf;
569 static unsigned loadUint16( unsigned char ** buffer )
571 unsigned char * buf = *buffer;
572 unsigned result = *buf++;
574 result = (result << 8) | *buf++;
576 *buffer = buf;
578 return result;
581 unsigned z80_restoreSnapshot( unsigned char * buffer )
583 unsigned char * buf = buffer;
585 A = *buf++; A1 = *buf++;
586 B = *buf++; B1 = *buf++;
587 C = *buf++; C1 = *buf++;
588 D = *buf++; D1 = *buf++;
589 E = *buf++; E1 = *buf++;
590 H = *buf++; H1 = *buf++;
591 L = *buf++; L1 = *buf++;
592 F = *buf++; F1 = *buf++;
594 I = *buf++;
595 R = *buf++;
597 IX = loadUint16( &buf );
598 IY = loadUint16( &buf );
599 PC = loadUint16( &buf );
600 SP = loadUint16( &buf );
602 iflags_ = loadUint16( &buf );
603 iflags_ = (iflags_ << 16) | loadUint16(&buf);
604 cycles_ = loadUint16( &buf );
605 cycles_ = (cycles_ << 16) | loadUint16(&buf);
607 return buf - buffer;
610 OpcodeInfo OpInfoCB_[256] = {
611 { &opcode_cb_00, 8 }, // RLC B
612 { &opcode_cb_01, 8 }, // RLC C
613 { &opcode_cb_02, 8 }, // RLC D
614 { &opcode_cb_03, 8 }, // RLC E
615 { &opcode_cb_04, 8 }, // RLC H
616 { &opcode_cb_05, 8 }, // RLC L
617 { &opcode_cb_06, 15 }, // RLC (HL)
618 { &opcode_cb_07, 8 }, // RLC A
619 { &opcode_cb_08, 8 }, // RRC B
620 { &opcode_cb_09, 8 }, // RRC C
621 { &opcode_cb_0a, 8 }, // RRC D
622 { &opcode_cb_0b, 8 }, // RRC E
623 { &opcode_cb_0c, 8 }, // RRC H
624 { &opcode_cb_0d, 8 }, // RRC L
625 { &opcode_cb_0e, 15 }, // RRC (HL)
626 { &opcode_cb_0f, 8 }, // RRC A
627 { &opcode_cb_10, 8 }, // RL B
628 { &opcode_cb_11, 8 }, // RL C
629 { &opcode_cb_12, 8 }, // RL D
630 { &opcode_cb_13, 8 }, // RL E
631 { &opcode_cb_14, 8 }, // RL H
632 { &opcode_cb_15, 8 }, // RL L
633 { &opcode_cb_16, 15 }, // RL (HL)
634 { &opcode_cb_17, 8 }, // RL A
635 { &opcode_cb_18, 8 }, // RR B
636 { &opcode_cb_19, 8 }, // RR C
637 { &opcode_cb_1a, 8 }, // RR D
638 { &opcode_cb_1b, 8 }, // RR E
639 { &opcode_cb_1c, 8 }, // RR H
640 { &opcode_cb_1d, 8 }, // RR L
641 { &opcode_cb_1e, 15 }, // RR (HL)
642 { &opcode_cb_1f, 8 }, // RR A
643 { &opcode_cb_20, 8 }, // SLA B
644 { &opcode_cb_21, 8 }, // SLA C
645 { &opcode_cb_22, 8 }, // SLA D
646 { &opcode_cb_23, 8 }, // SLA E
647 { &opcode_cb_24, 8 }, // SLA H
648 { &opcode_cb_25, 8 }, // SLA L
649 { &opcode_cb_26, 15 }, // SLA (HL)
650 { &opcode_cb_27, 8 }, // SLA A
651 { &opcode_cb_28, 8 }, // SRA B
652 { &opcode_cb_29, 8 }, // SRA C
653 { &opcode_cb_2a, 8 }, // SRA D
654 { &opcode_cb_2b, 8 }, // SRA E
655 { &opcode_cb_2c, 8 }, // SRA H
656 { &opcode_cb_2d, 8 }, // SRA L
657 { &opcode_cb_2e, 15 }, // SRA (HL)
658 { &opcode_cb_2f, 8 }, // SRA A
659 { &opcode_cb_30, 8 }, // SLL B
660 { &opcode_cb_31, 8 }, // SLL C
661 { &opcode_cb_32, 8 }, // SLL D
662 { &opcode_cb_33, 8 }, // SLL E
663 { &opcode_cb_34, 8 }, // SLL H
664 { &opcode_cb_35, 8 }, // SLL L
665 { &opcode_cb_36, 15 }, // SLL (HL)
666 { &opcode_cb_37, 8 }, // SLL A
667 { &opcode_cb_38, 8 }, // SRL B
668 { &opcode_cb_39, 8 }, // SRL C
669 { &opcode_cb_3a, 8 }, // SRL D
670 { &opcode_cb_3b, 8 }, // SRL E
671 { &opcode_cb_3c, 8 }, // SRL H
672 { &opcode_cb_3d, 8 }, // SRL L
673 { &opcode_cb_3e, 15 }, // SRL (HL)
674 { &opcode_cb_3f, 8 }, // SRL A
675 { &opcode_cb_40, 8 }, // BIT 0, B
676 { &opcode_cb_41, 8 }, // BIT 0, C
677 { &opcode_cb_42, 8 }, // BIT 0, D
678 { &opcode_cb_43, 8 }, // BIT 0, E
679 { &opcode_cb_44, 8 }, // BIT 0, H
680 { &opcode_cb_45, 8 }, // BIT 0, L
681 { &opcode_cb_46, 12 }, // BIT 0, (HL)
682 { &opcode_cb_47, 8 }, // BIT 0, A
683 { &opcode_cb_48, 8 }, // BIT 1, B
684 { &opcode_cb_49, 8 }, // BIT 1, C
685 { &opcode_cb_4a, 8 }, // BIT 1, D
686 { &opcode_cb_4b, 8 }, // BIT 1, E
687 { &opcode_cb_4c, 8 }, // BIT 1, H
688 { &opcode_cb_4d, 8 }, // BIT 1, L
689 { &opcode_cb_4e, 12 }, // BIT 1, (HL)
690 { &opcode_cb_4f, 8 }, // BIT 1, A
691 { &opcode_cb_50, 8 }, // BIT 2, B
692 { &opcode_cb_51, 8 }, // BIT 2, C
693 { &opcode_cb_52, 8 }, // BIT 2, D
694 { &opcode_cb_53, 8 }, // BIT 2, E
695 { &opcode_cb_54, 8 }, // BIT 2, H
696 { &opcode_cb_55, 8 }, // BIT 2, L
697 { &opcode_cb_56, 12 }, // BIT 2, (HL)
698 { &opcode_cb_57, 8 }, // BIT 2, A
699 { &opcode_cb_58, 8 }, // BIT 3, B
700 { &opcode_cb_59, 8 }, // BIT 3, C
701 { &opcode_cb_5a, 8 }, // BIT 3, D
702 { &opcode_cb_5b, 8 }, // BIT 3, E
703 { &opcode_cb_5c, 8 }, // BIT 3, H
704 { &opcode_cb_5d, 8 }, // BIT 3, L
705 { &opcode_cb_5e, 12 }, // BIT 3, (HL)
706 { &opcode_cb_5f, 8 }, // BIT 3, A
707 { &opcode_cb_60, 8 }, // BIT 4, B
708 { &opcode_cb_61, 8 }, // BIT 4, C
709 { &opcode_cb_62, 8 }, // BIT 4, D
710 { &opcode_cb_63, 8 }, // BIT 4, E
711 { &opcode_cb_64, 8 }, // BIT 4, H
712 { &opcode_cb_65, 8 }, // BIT 4, L
713 { &opcode_cb_66, 12 }, // BIT 4, (HL)
714 { &opcode_cb_67, 8 }, // BIT 4, A
715 { &opcode_cb_68, 8 }, // BIT 5, B
716 { &opcode_cb_69, 8 }, // BIT 5, C
717 { &opcode_cb_6a, 8 }, // BIT 5, D
718 { &opcode_cb_6b, 8 }, // BIT 5, E
719 { &opcode_cb_6c, 8 }, // BIT 5, H
720 { &opcode_cb_6d, 8 }, // BIT 5, L
721 { &opcode_cb_6e, 12 }, // BIT 5, (HL)
722 { &opcode_cb_6f, 8 }, // BIT 5, A
723 { &opcode_cb_70, 8 }, // BIT 6, B
724 { &opcode_cb_71, 8 }, // BIT 6, C
725 { &opcode_cb_72, 8 }, // BIT 6, D
726 { &opcode_cb_73, 8 }, // BIT 6, E
727 { &opcode_cb_74, 8 }, // BIT 6, H
728 { &opcode_cb_75, 8 }, // BIT 6, L
729 { &opcode_cb_76, 12 }, // BIT 6, (HL)
730 { &opcode_cb_77, 8 }, // BIT 6, A
731 { &opcode_cb_78, 8 }, // BIT 7, B
732 { &opcode_cb_79, 8 }, // BIT 7, C
733 { &opcode_cb_7a, 8 }, // BIT 7, D
734 { &opcode_cb_7b, 8 }, // BIT 7, E
735 { &opcode_cb_7c, 8 }, // BIT 7, H
736 { &opcode_cb_7d, 8 }, // BIT 7, L
737 { &opcode_cb_7e, 12 }, // BIT 7, (HL)
738 { &opcode_cb_7f, 8 }, // BIT 7, A
739 { &opcode_cb_80, 8 }, // RES 0, B
740 { &opcode_cb_81, 8 }, // RES 0, C
741 { &opcode_cb_82, 8 }, // RES 0, D
742 { &opcode_cb_83, 8 }, // RES 0, E
743 { &opcode_cb_84, 8 }, // RES 0, H
744 { &opcode_cb_85, 8 }, // RES 0, L
745 { &opcode_cb_86, 15 }, // RES 0, (HL)
746 { &opcode_cb_87, 8 }, // RES 0, A
747 { &opcode_cb_88, 8 }, // RES 1, B
748 { &opcode_cb_89, 8 }, // RES 1, C
749 { &opcode_cb_8a, 8 }, // RES 1, D
750 { &opcode_cb_8b, 8 }, // RES 1, E
751 { &opcode_cb_8c, 8 }, // RES 1, H
752 { &opcode_cb_8d, 8 }, // RES 1, L
753 { &opcode_cb_8e, 15 }, // RES 1, (HL)
754 { &opcode_cb_8f, 8 }, // RES 1, A
755 { &opcode_cb_90, 8 }, // RES 2, B
756 { &opcode_cb_91, 8 }, // RES 2, C
757 { &opcode_cb_92, 8 }, // RES 2, D
758 { &opcode_cb_93, 8 }, // RES 2, E
759 { &opcode_cb_94, 8 }, // RES 2, H
760 { &opcode_cb_95, 8 }, // RES 2, L
761 { &opcode_cb_96, 15 }, // RES 2, (HL)
762 { &opcode_cb_97, 8 }, // RES 2, A
763 { &opcode_cb_98, 8 }, // RES 3, B
764 { &opcode_cb_99, 8 }, // RES 3, C
765 { &opcode_cb_9a, 8 }, // RES 3, D
766 { &opcode_cb_9b, 8 }, // RES 3, E
767 { &opcode_cb_9c, 8 }, // RES 3, H
768 { &opcode_cb_9d, 8 }, // RES 3, L
769 { &opcode_cb_9e, 15 }, // RES 3, (HL)
770 { &opcode_cb_9f, 8 }, // RES 3, A
771 { &opcode_cb_a0, 8 }, // RES 4, B
772 { &opcode_cb_a1, 8 }, // RES 4, C
773 { &opcode_cb_a2, 8 }, // RES 4, D
774 { &opcode_cb_a3, 8 }, // RES 4, E
775 { &opcode_cb_a4, 8 }, // RES 4, H
776 { &opcode_cb_a5, 8 }, // RES 4, L
777 { &opcode_cb_a6, 15 }, // RES 4, (HL)
778 { &opcode_cb_a7, 8 }, // RES 4, A
779 { &opcode_cb_a8, 8 }, // RES 5, B
780 { &opcode_cb_a9, 8 }, // RES 5, C
781 { &opcode_cb_aa, 8 }, // RES 5, D
782 { &opcode_cb_ab, 8 }, // RES 5, E
783 { &opcode_cb_ac, 8 }, // RES 5, H
784 { &opcode_cb_ad, 8 }, // RES 5, L
785 { &opcode_cb_ae, 15 }, // RES 5, (HL)
786 { &opcode_cb_af, 8 }, // RES 5, A
787 { &opcode_cb_b0, 8 }, // RES 6, B
788 { &opcode_cb_b1, 8 }, // RES 6, C
789 { &opcode_cb_b2, 8 }, // RES 6, D
790 { &opcode_cb_b3, 8 }, // RES 6, E
791 { &opcode_cb_b4, 8 }, // RES 6, H
792 { &opcode_cb_b5, 8 }, // RES 6, L
793 { &opcode_cb_b6, 15 }, // RES 6, (HL)
794 { &opcode_cb_b7, 8 }, // RES 6, A
795 { &opcode_cb_b8, 8 }, // RES 7, B
796 { &opcode_cb_b9, 8 }, // RES 7, C
797 { &opcode_cb_ba, 8 }, // RES 7, D
798 { &opcode_cb_bb, 8 }, // RES 7, E
799 { &opcode_cb_bc, 8 }, // RES 7, H
800 { &opcode_cb_bd, 8 }, // RES 7, L
801 { &opcode_cb_be, 15 }, // RES 7, (HL)
802 { &opcode_cb_bf, 8 }, // RES 7, A
803 { &opcode_cb_c0, 8 }, // SET 0, B
804 { &opcode_cb_c1, 8 }, // SET 0, C
805 { &opcode_cb_c2, 8 }, // SET 0, D
806 { &opcode_cb_c3, 8 }, // SET 0, E
807 { &opcode_cb_c4, 8 }, // SET 0, H
808 { &opcode_cb_c5, 8 }, // SET 0, L
809 { &opcode_cb_c6, 15 }, // SET 0, (HL)
810 { &opcode_cb_c7, 8 }, // SET 0, A
811 { &opcode_cb_c8, 8 }, // SET 1, B
812 { &opcode_cb_c9, 8 }, // SET 1, C
813 { &opcode_cb_ca, 8 }, // SET 1, D
814 { &opcode_cb_cb, 8 }, // SET 1, E
815 { &opcode_cb_cc, 8 }, // SET 1, H
816 { &opcode_cb_cd, 8 }, // SET 1, L
817 { &opcode_cb_ce, 15 }, // SET 1, (HL)
818 { &opcode_cb_cf, 8 }, // SET 1, A
819 { &opcode_cb_d0, 8 }, // SET 2, B
820 { &opcode_cb_d1, 8 }, // SET 2, C
821 { &opcode_cb_d2, 8 }, // SET 2, D
822 { &opcode_cb_d3, 8 }, // SET 2, E
823 { &opcode_cb_d4, 8 }, // SET 2, H
824 { &opcode_cb_d5, 8 }, // SET 2, L
825 { &opcode_cb_d6, 15 }, // SET 2, (HL)
826 { &opcode_cb_d7, 8 }, // SET 2, A
827 { &opcode_cb_d8, 8 }, // SET 3, B
828 { &opcode_cb_d9, 8 }, // SET 3, C
829 { &opcode_cb_da, 8 }, // SET 3, D
830 { &opcode_cb_db, 8 }, // SET 3, E
831 { &opcode_cb_dc, 8 }, // SET 3, H
832 { &opcode_cb_dd, 8 }, // SET 3, L
833 { &opcode_cb_de, 15 }, // SET 3, (HL)
834 { &opcode_cb_df, 8 }, // SET 3, A
835 { &opcode_cb_e0, 8 }, // SET 4, B
836 { &opcode_cb_e1, 8 }, // SET 4, C
837 { &opcode_cb_e2, 8 }, // SET 4, D
838 { &opcode_cb_e3, 8 }, // SET 4, E
839 { &opcode_cb_e4, 8 }, // SET 4, H
840 { &opcode_cb_e5, 8 }, // SET 4, L
841 { &opcode_cb_e6, 15 }, // SET 4, (HL)
842 { &opcode_cb_e7, 8 }, // SET 4, A
843 { &opcode_cb_e8, 8 }, // SET 5, B
844 { &opcode_cb_e9, 8 }, // SET 5, C
845 { &opcode_cb_ea, 8 }, // SET 5, D
846 { &opcode_cb_eb, 8 }, // SET 5, E
847 { &opcode_cb_ec, 8 }, // SET 5, H
848 { &opcode_cb_ed, 8 }, // SET 5, L
849 { &opcode_cb_ee, 15 }, // SET 5, (HL)
850 { &opcode_cb_ef, 8 }, // SET 5, A
851 { &opcode_cb_f0, 8 }, // SET 6, B
852 { &opcode_cb_f1, 8 }, // SET 6, C
853 { &opcode_cb_f2, 8 }, // SET 6, D
854 { &opcode_cb_f3, 8 }, // SET 6, E
855 { &opcode_cb_f4, 8 }, // SET 6, H
856 { &opcode_cb_f5, 8 }, // SET 6, L
857 { &opcode_cb_f6, 15 }, // SET 6, (HL)
858 { &opcode_cb_f7, 8 }, // SET 6, A
859 { &opcode_cb_f8, 8 }, // SET 7, B
860 { &opcode_cb_f9, 8 }, // SET 7, C
861 { &opcode_cb_fa, 8 }, // SET 7, D
862 { &opcode_cb_fb, 8 }, // SET 7, E
863 { &opcode_cb_fc, 8 }, // SET 7, H
864 { &opcode_cb_fd, 8 }, // SET 7, L
865 { &opcode_cb_fe, 15 }, // SET 7, (HL)
866 { &opcode_cb_ff, 8 } // SET 7, A
869 void opcode_cb_00() // RLC B
871 B = rotateLeftCarry( B );
874 void opcode_cb_01() // RLC C
876 C = rotateLeftCarry( C );
879 void opcode_cb_02() // RLC D
881 D = rotateLeftCarry( D );
884 void opcode_cb_03() // RLC E
886 E = rotateLeftCarry( E );
889 void opcode_cb_04() // RLC H
891 H = rotateLeftCarry( H );
894 void opcode_cb_05() // RLC L
896 L = rotateLeftCarry( L );
899 void opcode_cb_06() // RLC (HL)
901 writeByte( HL(), rotateLeftCarry( readByte( HL() ) ) );
904 void opcode_cb_07() // RLC A
906 A = rotateLeftCarry( A );
909 void opcode_cb_08() // RRC B
911 B = rotateRightCarry( B );
914 void opcode_cb_09() // RRC C
916 C = rotateLeftCarry( C );
919 void opcode_cb_0a() // RRC D
921 D = rotateLeftCarry( D );
924 void opcode_cb_0b() // RRC E
926 E = rotateLeftCarry( E );
929 void opcode_cb_0c() // RRC H
931 H = rotateLeftCarry( H );
934 void opcode_cb_0d() // RRC L
936 L = rotateLeftCarry( L );
939 void opcode_cb_0e() // RRC (HL)
941 writeByte( HL(), rotateRightCarry( readByte( HL() ) ) );
944 void opcode_cb_0f() // RRC A
946 A = rotateLeftCarry( A );
949 void opcode_cb_10() // RL B
951 B = rotateLeft( B );
954 void opcode_cb_11() // RL C
956 C = rotateLeft( C );
959 void opcode_cb_12() // RL D
961 D = rotateLeft( D );
964 void opcode_cb_13() // RL E
966 E = rotateLeft( E );
969 void opcode_cb_14() // RL H
971 H = rotateLeft( H );
974 void opcode_cb_15() // RL L
976 L = rotateLeft( L );
979 void opcode_cb_16() // RL (HL)
981 writeByte( HL(), rotateLeft( readByte( HL() ) ) );
984 void opcode_cb_17() // RL A
986 A = rotateLeft( A );
989 void opcode_cb_18() // RR B
991 B = rotateRight( B );
994 void opcode_cb_19() // RR C
996 C = rotateRight( C );
999 void opcode_cb_1a() // RR D
1001 D = rotateRight( D );
1004 void opcode_cb_1b() // RR E
1006 E = rotateRight( E );
1009 void opcode_cb_1c() // RR H
1011 H = rotateRight( H );
1014 void opcode_cb_1d() // RR L
1016 L = rotateRight( L );
1019 void opcode_cb_1e() // RR (HL)
1021 writeByte( HL(), rotateRight( readByte( HL() ) ) );
1024 void opcode_cb_1f() // RR A
1026 A = rotateRight( A );
1029 void opcode_cb_20() // SLA B
1031 B = shiftLeft( B );
1034 void opcode_cb_21() // SLA C
1036 C = shiftLeft( C );
1039 void opcode_cb_22() // SLA D
1041 D = shiftLeft( D );
1044 void opcode_cb_23() // SLA E
1046 E = shiftLeft( E );
1049 void opcode_cb_24() // SLA H
1051 H = shiftLeft( H );
1054 void opcode_cb_25() // SLA L
1056 L = shiftLeft( L );
1059 void opcode_cb_26() // SLA (HL)
1061 writeByte( HL(), shiftLeft( readByte( HL() ) ) );
1064 void opcode_cb_27() // SLA A
1066 A = shiftLeft( A );
1069 void opcode_cb_28() // SRA B
1071 B = shiftRightArith( B );
1074 void opcode_cb_29() // SRA C
1076 C = shiftRightArith( C );
1079 void opcode_cb_2a() // SRA D
1081 D = shiftRightArith( D );
1084 void opcode_cb_2b() // SRA E
1086 E = shiftRightArith( E );
1089 void opcode_cb_2c() // SRA H
1091 H = shiftRightArith( H );
1094 void opcode_cb_2d() // SRA L
1096 L = shiftRightArith( L );
1099 void opcode_cb_2e() // SRA (HL)
1101 writeByte( HL(), shiftRightArith( readByte( HL() ) ) );
1104 void opcode_cb_2f() // SRA A
1106 A = shiftRightArith( A );
1109 void opcode_cb_30() // SLL B
1111 B = shiftLeft( B ) | 0x01;
1114 void opcode_cb_31() // SLL C
1116 C = shiftLeft( C ) | 0x01;
1119 void opcode_cb_32() // SLL D
1121 D = shiftLeft( D ) | 0x01;
1124 void opcode_cb_33() // SLL E
1126 E = shiftLeft( E ) | 0x01;
1129 void opcode_cb_34() // SLL H
1131 H = shiftLeft( H ) | 0x01;
1134 void opcode_cb_35() // SLL L
1136 L = shiftLeft( L ) | 0x01;
1139 void opcode_cb_36() // SLL (HL)
1141 writeByte( HL(), shiftLeft( readByte( HL() ) ) | 0x01 );
1144 void opcode_cb_37() // SLL A
1146 A = shiftLeft( A ) | 0x01;
1149 void opcode_cb_38() // SRL B
1151 B = shiftRightLogical( B );
1154 void opcode_cb_39() // SRL C
1156 C = shiftRightLogical( C );
1159 void opcode_cb_3a() // SRL D
1161 D = shiftRightLogical( D );
1164 void opcode_cb_3b() // SRL E
1166 E = shiftRightLogical( E );
1169 void opcode_cb_3c() // SRL H
1171 H = shiftRightLogical( H );
1174 void opcode_cb_3d() // SRL L
1176 L = shiftRightLogical( L );
1179 void opcode_cb_3e() // SRL (HL)
1181 writeByte( HL(), shiftRightLogical( readByte( HL() ) ) );
1184 void opcode_cb_3f() // SRL A
1186 A = shiftRightLogical( A );
1189 void opcode_cb_40() // BIT 0, B
1191 testBit( 0, B );
1194 void opcode_cb_41() // BIT 0, C
1196 testBit( 0, C );
1199 void opcode_cb_42() // BIT 0, D
1201 testBit( 0, D );
1204 void opcode_cb_43() // BIT 0, E
1206 testBit( 0, E );
1209 void opcode_cb_44() // BIT 0, H
1211 testBit( 0, H );
1214 void opcode_cb_45() // BIT 0, L
1216 testBit( 0, L );
1219 void opcode_cb_46() // BIT 0, (HL)
1221 testBit( 0, readByte( HL() ) );
1224 void opcode_cb_47() // BIT 0, A
1226 testBit( 0, A );
1229 void opcode_cb_48() // BIT 1, B
1231 testBit( 1, B );
1234 void opcode_cb_49() // BIT 1, C
1236 testBit( 1, C );
1239 void opcode_cb_4a() // BIT 1, D
1241 testBit( 1, D );
1244 void opcode_cb_4b() // BIT 1, E
1246 testBit( 1, E );
1249 void opcode_cb_4c() // BIT 1, H
1251 testBit( 1, H );
1254 void opcode_cb_4d() // BIT 1, L
1256 testBit( 1, L );
1259 void opcode_cb_4e() // BIT 1, (HL)
1261 testBit( 1, readByte( HL() ) );
1264 void opcode_cb_4f() // BIT 1, A
1266 testBit( 1, A );
1269 void opcode_cb_50() // BIT 2, B
1271 testBit( 2, B );
1274 void opcode_cb_51() // BIT 2, C
1276 testBit( 2, C );
1279 void opcode_cb_52() // BIT 2, D
1281 testBit( 2, D );
1284 void opcode_cb_53() // BIT 2, E
1286 testBit( 2, E );
1289 void opcode_cb_54() // BIT 2, H
1291 testBit( 2, H );
1294 void opcode_cb_55() // BIT 2, L
1296 testBit( 2, L );
1299 void opcode_cb_56() // BIT 2, (HL)
1301 testBit( 2, readByte( HL() ) );
1304 void opcode_cb_57() // BIT 2, A
1306 testBit( 2, A );
1309 void opcode_cb_58() // BIT 3, B
1311 testBit( 3, B );
1314 void opcode_cb_59() // BIT 3, C
1316 testBit( 3, C );
1319 void opcode_cb_5a() // BIT 3, D
1321 testBit( 3, D );
1324 void opcode_cb_5b() // BIT 3, E
1326 testBit( 3, E );
1329 void opcode_cb_5c() // BIT 3, H
1331 testBit( 3, H );
1334 void opcode_cb_5d() // BIT 3, L
1336 testBit( 3, L );
1339 void opcode_cb_5e() // BIT 3, (HL)
1341 testBit( 3, readByte( HL() ) );
1344 void opcode_cb_5f() // BIT 3, A
1346 testBit( 3, A );
1349 void opcode_cb_60() // BIT 4, B
1351 testBit( 4, B );
1354 void opcode_cb_61() // BIT 4, C
1356 testBit( 4, C );
1359 void opcode_cb_62() // BIT 4, D
1361 testBit( 4, D );
1364 void opcode_cb_63() // BIT 4, E
1366 testBit( 4, E );
1369 void opcode_cb_64() // BIT 4, H
1371 testBit( 4, H );
1374 void opcode_cb_65() // BIT 4, L
1376 testBit( 4, L );
1379 void opcode_cb_66() // BIT 4, (HL)
1381 testBit( 4, readByte( HL() ) );
1384 void opcode_cb_67() // BIT 4, A
1386 testBit( 4, A );
1389 void opcode_cb_68() // BIT 5, B
1391 testBit( 5, B );
1394 void opcode_cb_69() // BIT 5, C
1396 testBit( 5, C );
1399 void opcode_cb_6a() // BIT 5, D
1401 testBit( 5, D );
1404 void opcode_cb_6b() // BIT 5, E
1406 testBit( 5, E );
1409 void opcode_cb_6c() // BIT 5, H
1411 testBit( 5, H );
1414 void opcode_cb_6d() // BIT 5, L
1416 testBit( 5, L );
1419 void opcode_cb_6e() // BIT 5, (HL)
1421 testBit( 5, readByte( HL() ) );
1424 void opcode_cb_6f() // BIT 5, A
1426 testBit( 5, A );
1429 void opcode_cb_70() // BIT 6, B
1431 testBit( 6, B );
1434 void opcode_cb_71() // BIT 6, C
1436 testBit( 6, C );
1439 void opcode_cb_72() // BIT 6, D
1441 testBit( 6, D );
1444 void opcode_cb_73() // BIT 6, E
1446 testBit( 6, E );
1449 void opcode_cb_74() // BIT 6, H
1451 testBit( 6, H );
1454 void opcode_cb_75() // BIT 6, L
1456 testBit( 6, L );
1459 void opcode_cb_76() // BIT 6, (HL)
1461 testBit( 6, readByte( HL() ) );
1464 void opcode_cb_77() // BIT 6, A
1466 testBit( 6, A );
1469 void opcode_cb_78() // BIT 7, B
1471 testBit( 7, B );
1474 void opcode_cb_79() // BIT 7, C
1476 testBit( 7, C );
1479 void opcode_cb_7a() // BIT 7, D
1481 testBit( 7, D );
1484 void opcode_cb_7b() // BIT 7, E
1486 testBit( 7, E );
1489 void opcode_cb_7c() // BIT 7, H
1491 testBit( 7, H );
1494 void opcode_cb_7d() // BIT 7, L
1496 testBit( 7, L );
1499 void opcode_cb_7e() // BIT 7, (HL)
1501 testBit( 7, readByte( HL() ) );
1504 void opcode_cb_7f() // BIT 7, A
1506 testBit( 7, A );
1509 void opcode_cb_80() // RES 0, B
1511 B &= ~(unsigned char) (1 << 0);
1514 void opcode_cb_81() // RES 0, C
1516 C &= ~(unsigned char) (1 << 0);
1519 void opcode_cb_82() // RES 0, D
1521 D &= ~(unsigned char) (1 << 0);
1524 void opcode_cb_83() // RES 0, E
1526 E &= ~(unsigned char) (1 << 0);
1529 void opcode_cb_84() // RES 0, H
1531 H &= ~(unsigned char) (1 << 0);
1534 void opcode_cb_85() // RES 0, L
1536 L &= ~(unsigned char) (1 << 0);
1539 void opcode_cb_86() // RES 0, (HL)
1541 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 0) );
1544 void opcode_cb_87() // RES 0, A
1546 A &= ~(unsigned char) (1 << 0);
1549 void opcode_cb_88() // RES 1, B
1551 B &= ~(unsigned char) (1 << 1);
1554 void opcode_cb_89() // RES 1, C
1556 C &= ~(unsigned char) (1 << 1);
1559 void opcode_cb_8a() // RES 1, D
1561 D &= ~(unsigned char) (1 << 1);
1564 void opcode_cb_8b() // RES 1, E
1566 E &= ~(unsigned char) (1 << 1);
1569 void opcode_cb_8c() // RES 1, H
1571 H &= ~(unsigned char) (1 << 1);
1574 void opcode_cb_8d() // RES 1, L
1576 L &= ~(unsigned char) (1 << 1);
1579 void opcode_cb_8e() // RES 1, (HL)
1581 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 1) );
1584 void opcode_cb_8f() // RES 1, A
1586 A &= ~(unsigned char) (1 << 1);
1589 void opcode_cb_90() // RES 2, B
1591 B &= ~(unsigned char) (1 << 2);
1594 void opcode_cb_91() // RES 2, C
1596 C &= ~(unsigned char) (1 << 2);
1599 void opcode_cb_92() // RES 2, D
1601 D &= ~(unsigned char) (1 << 2);
1604 void opcode_cb_93() // RES 2, E
1606 E &= ~(unsigned char) (1 << 2);
1609 void opcode_cb_94() // RES 2, H
1611 H &= ~(unsigned char) (1 << 2);
1614 void opcode_cb_95() // RES 2, L
1616 L &= ~(unsigned char) (1 << 2);
1619 void opcode_cb_96() // RES 2, (HL)
1621 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 2) );
1624 void opcode_cb_97() // RES 2, A
1626 A &= ~(unsigned char) (1 << 2);
1629 void opcode_cb_98() // RES 3, B
1631 B &= ~(unsigned char) (1 << 3);
1634 void opcode_cb_99() // RES 3, C
1636 C &= ~(unsigned char) (1 << 3);
1639 void opcode_cb_9a() // RES 3, D
1641 D &= ~(unsigned char) (1 << 3);
1644 void opcode_cb_9b() // RES 3, E
1646 E &= ~(unsigned char) (1 << 3);
1649 void opcode_cb_9c() // RES 3, H
1651 H &= ~(unsigned char) (1 << 3);
1654 void opcode_cb_9d() // RES 3, L
1656 L &= ~(unsigned char) (1 << 3);
1659 void opcode_cb_9e() // RES 3, (HL)
1661 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 3) );
1664 void opcode_cb_9f() // RES 3, A
1666 A &= ~(unsigned char) (1 << 3);
1669 void opcode_cb_a0() // RES 4, B
1671 B &= ~(unsigned char) (1 << 4);
1674 void opcode_cb_a1() // RES 4, C
1676 C &= ~(unsigned char) (1 << 4);
1679 void opcode_cb_a2() // RES 4, D
1681 D &= ~(unsigned char) (1 << 4);
1684 void opcode_cb_a3() // RES 4, E
1686 E &= ~(unsigned char) (1 << 4);
1689 void opcode_cb_a4() // RES 4, H
1691 H &= ~(unsigned char) (1 << 4);
1694 void opcode_cb_a5() // RES 4, L
1696 L &= ~(unsigned char) (1 << 4);
1699 void opcode_cb_a6() // RES 4, (HL)
1701 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 4) );
1704 void opcode_cb_a7() // RES 4, A
1706 A &= ~(unsigned char) (1 << 4);
1709 void opcode_cb_a8() // RES 5, B
1711 B &= ~(unsigned char) (1 << 5);
1714 void opcode_cb_a9() // RES 5, C
1716 C &= ~(unsigned char) (1 << 5);
1719 void opcode_cb_aa() // RES 5, D
1721 D &= ~(unsigned char) (1 << 5);
1724 void opcode_cb_ab() // RES 5, E
1726 E &= ~(unsigned char) (1 << 5);
1729 void opcode_cb_ac() // RES 5, H
1731 H &= ~(unsigned char) (1 << 5);
1734 void opcode_cb_ad() // RES 5, L
1736 L &= ~(unsigned char) (1 << 5);
1739 void opcode_cb_ae() // RES 5, (HL)
1741 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 5) );
1744 void opcode_cb_af() // RES 5, A
1746 A &= ~(unsigned char) (1 << 5);
1749 void opcode_cb_b0() // RES 6, B
1751 B &= ~(unsigned char) (1 << 6);
1754 void opcode_cb_b1() // RES 6, C
1756 C &= ~(unsigned char) (1 << 6);
1759 void opcode_cb_b2() // RES 6, D
1761 D &= ~(unsigned char) (1 << 6);
1764 void opcode_cb_b3() // RES 6, E
1766 E &= ~(unsigned char) (1 << 6);
1769 void opcode_cb_b4() // RES 6, H
1771 H &= ~(unsigned char) (1 << 6);
1774 void opcode_cb_b5() // RES 6, L
1776 L &= ~(unsigned char) (1 << 6);
1779 void opcode_cb_b6() // RES 6, (HL)
1781 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 6) );
1784 void opcode_cb_b7() // RES 6, A
1786 A &= ~(unsigned char) (1 << 6);
1789 void opcode_cb_b8() // RES 7, B
1791 B &= ~(unsigned char) (1 << 7);
1794 void opcode_cb_b9() // RES 7, C
1796 C &= ~(unsigned char) (1 << 7);
1799 void opcode_cb_ba() // RES 7, D
1801 D &= ~(unsigned char) (1 << 7);
1804 void opcode_cb_bb() // RES 7, E
1806 E &= ~(unsigned char) (1 << 7);
1809 void opcode_cb_bc() // RES 7, H
1811 H &= ~(unsigned char) (1 << 7);
1814 void opcode_cb_bd() // RES 7, L
1816 L &= ~(unsigned char) (1 << 7);
1819 void opcode_cb_be() // RES 7, (HL)
1821 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 7) );
1824 void opcode_cb_bf() // RES 7, A
1826 A &= ~(unsigned char) (1 << 7);
1829 void opcode_cb_c0() // SET 0, B
1831 B |= (unsigned char) (1 << 0);
1834 void opcode_cb_c1() // SET 0, C
1836 C |= (unsigned char) (1 << 0);
1839 void opcode_cb_c2() // SET 0, D
1841 D |= (unsigned char) (1 << 0);
1844 void opcode_cb_c3() // SET 0, E
1846 E |= (unsigned char) (1 << 0);
1849 void opcode_cb_c4() // SET 0, H
1851 H |= (unsigned char) (1 << 0);
1854 void opcode_cb_c5() // SET 0, L
1856 L |= (unsigned char) (1 << 0);
1859 void opcode_cb_c6() // SET 0, (HL)
1861 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 0) );
1864 void opcode_cb_c7() // SET 0, A
1866 A |= (unsigned char) (1 << 0);
1869 void opcode_cb_c8() // SET 1, B
1871 B |= (unsigned char) (1 << 1);
1874 void opcode_cb_c9() // SET 1, C
1876 C |= (unsigned char) (1 << 1);
1879 void opcode_cb_ca() // SET 1, D
1881 D |= (unsigned char) (1 << 1);
1884 void opcode_cb_cb() // SET 1, E
1886 E |= (unsigned char) (1 << 1);
1889 void opcode_cb_cc() // SET 1, H
1891 H |= (unsigned char) (1 << 1);
1894 void opcode_cb_cd() // SET 1, L
1896 L |= (unsigned char) (1 << 1);
1899 void opcode_cb_ce() // SET 1, (HL)
1901 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 1) );
1904 void opcode_cb_cf() // SET 1, A
1906 A |= (unsigned char) (1 << 1);
1909 void opcode_cb_d0() // SET 2, B
1911 B |= (unsigned char) (1 << 2);
1914 void opcode_cb_d1() // SET 2, C
1916 C |= (unsigned char) (1 << 2);
1919 void opcode_cb_d2() // SET 2, D
1921 D |= (unsigned char) (1 << 2);
1924 void opcode_cb_d3() // SET 2, E
1926 E |= (unsigned char) (1 << 2);
1929 void opcode_cb_d4() // SET 2, H
1931 H |= (unsigned char) (1 << 2);
1934 void opcode_cb_d5() // SET 2, L
1936 L |= (unsigned char) (1 << 2);
1939 void opcode_cb_d6() // SET 2, (HL)
1941 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 2) );
1944 void opcode_cb_d7() // SET 2, A
1946 A |= (unsigned char) (1 << 2);
1949 void opcode_cb_d8() // SET 3, B
1951 B |= (unsigned char) (1 << 3);
1954 void opcode_cb_d9() // SET 3, C
1956 C |= (unsigned char) (1 << 3);
1959 void opcode_cb_da() // SET 3, D
1961 D |= (unsigned char) (1 << 3);
1964 void opcode_cb_db() // SET 3, E
1966 E |= (unsigned char) (1 << 3);
1969 void opcode_cb_dc() // SET 3, H
1971 H |= (unsigned char) (1 << 3);
1974 void opcode_cb_dd() // SET 3, L
1976 L |= (unsigned char) (1 << 3);
1979 void opcode_cb_de() // SET 3, (HL)
1981 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 3) );
1984 void opcode_cb_df() // SET 3, A
1986 A |= (unsigned char) (1 << 3);
1989 void opcode_cb_e0() // SET 4, B
1991 B |= (unsigned char) (1 << 4);
1994 void opcode_cb_e1() // SET 4, C
1996 C |= (unsigned char) (1 << 4);
1999 void opcode_cb_e2() // SET 4, D
2001 D |= (unsigned char) (1 << 4);
2004 void opcode_cb_e3() // SET 4, E
2006 E |= (unsigned char) (1 << 4);
2009 void opcode_cb_e4() // SET 4, H
2011 H |= (unsigned char) (1 << 4);
2014 void opcode_cb_e5() // SET 4, L
2016 L |= (unsigned char) (1 << 4);
2019 void opcode_cb_e6() // SET 4, (HL)
2021 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 4) );
2024 void opcode_cb_e7() // SET 4, A
2026 A |= (unsigned char) (1 << 4);
2029 void opcode_cb_e8() // SET 5, B
2031 B |= (unsigned char) (1 << 5);
2034 void opcode_cb_e9() // SET 5, C
2036 C |= (unsigned char) (1 << 5);
2039 void opcode_cb_ea() // SET 5, D
2041 D |= (unsigned char) (1 << 5);
2044 void opcode_cb_eb() // SET 5, E
2046 E |= (unsigned char) (1 << 5);
2049 void opcode_cb_ec() // SET 5, H
2051 H |= (unsigned char) (1 << 5);
2054 void opcode_cb_ed() // SET 5, L
2056 L |= (unsigned char) (1 << 5);
2059 void opcode_cb_ee() // SET 5, (HL)
2061 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 5) );
2064 void opcode_cb_ef() // SET 5, A
2066 A |= (unsigned char) (1 << 5);
2069 void opcode_cb_f0() // SET 6, B
2071 B |= (unsigned char) (1 << 6);
2074 void opcode_cb_f1() // SET 6, C
2076 C |= (unsigned char) (1 << 6);
2079 void opcode_cb_f2() // SET 6, D
2081 D |= (unsigned char) (1 << 6);
2084 void opcode_cb_f3() // SET 6, E
2086 E |= (unsigned char) (1 << 6);
2089 void opcode_cb_f4() // SET 6, H
2091 H |= (unsigned char) (1 << 6);
2094 void opcode_cb_f5() // SET 6, L
2096 L |= (unsigned char) (1 << 6);
2099 void opcode_cb_f6() // SET 6, (HL)
2101 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 6) );
2104 void opcode_cb_f7() // SET 6, A
2106 A |= (unsigned char) (1 << 6);
2109 void opcode_cb_f8() // SET 7, B
2111 B |= (unsigned char) (1 << 7);
2114 void opcode_cb_f9() // SET 7, C
2116 C |= (unsigned char) (1 << 7);
2119 void opcode_cb_fa() // SET 7, D
2121 D |= (unsigned char) (1 << 7);
2124 void opcode_cb_fb() // SET 7, E
2126 E |= (unsigned char) (1 << 7);
2129 void opcode_cb_fc() // SET 7, H
2131 H |= (unsigned char) (1 << 7);
2134 void opcode_cb_fd() // SET 7, L
2136 L |= (unsigned char) (1 << 7);
2139 void opcode_cb_fe() // SET 7, (HL)
2141 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 7) );
2144 void opcode_cb_ff() // SET 7, A
2146 A |= (unsigned char) (1 << 7);
2149 OpcodeInfo OpInfoDD_[256] = {
2150 { 0, 0 }, // 0x00
2151 { 0, 0 }, // 0x01
2152 { 0, 0 }, // 0x02
2153 { 0, 0 }, // 0x03
2154 { 0, 0 }, // 0x04
2155 { 0, 0 }, // 0x05
2156 { 0, 0 }, // 0x06
2157 { 0, 0 }, // 0x07
2158 { 0, 0 }, // 0x08
2159 { &opcode_dd_09, 15 }, // ADD IX, BC
2160 { 0, 0 }, // 0x0A
2161 { 0, 0 }, // 0x0B
2162 { 0, 0 }, // 0x0C
2163 { 0, 0 }, // 0x0D
2164 { 0, 0 }, // 0x0E
2165 { 0, 0 }, // 0x0F
2166 { 0, 0 }, // 0x10
2167 { 0, 0 }, // 0x11
2168 { 0, 0 }, // 0x12
2169 { 0, 0 }, // 0x13
2170 { 0, 0 }, // 0x14
2171 { 0, 0 }, // 0x15
2172 { 0, 0 }, // 0x16
2173 { 0, 0 }, // 0x17
2174 { 0, 0 }, // 0x18
2175 { &opcode_dd_19, 15 }, // ADD IX, DE
2176 { 0, 0 }, // 0x1A
2177 { 0, 0 }, // 0x1B
2178 { 0, 0 }, // 0x1C
2179 { 0, 0 }, // 0x1D
2180 { 0, 0 }, // 0x1E
2181 { 0, 0 }, // 0x1F
2182 { 0, 0 }, // 0x20
2183 { &opcode_dd_21, 14 }, // LD IX, nn
2184 { &opcode_dd_22, 20 }, // LD (nn), IX
2185 { &opcode_dd_23, 10 }, // INC IX
2186 { &opcode_dd_24, 9 }, // INC IXH
2187 { &opcode_dd_25, 9 }, // DEC IXH
2188 { &opcode_dd_26, 9 }, // LD IXH, n
2189 { 0, 0 }, // 0x27
2190 { 0, 0 }, // 0x28
2191 { &opcode_dd_29, 15 }, // ADD IX, IX
2192 { &opcode_dd_2a, 20 }, // LD IX, (nn)
2193 { &opcode_dd_2b, 10 }, // DEC IX
2194 { &opcode_dd_2c, 9 }, // INC IXL
2195 { &opcode_dd_2d, 9 }, // DEC IXL
2196 { &opcode_dd_2e, 9 }, // LD IXL, n
2197 { 0, 0 }, // 0x2F
2198 { 0, 0 }, // 0x30
2199 { 0, 0 }, // 0x31
2200 { 0, 0 }, // 0x32
2201 { 0, 0 }, // 0x33
2202 { &opcode_dd_34, 23 }, // INC (IX + d)
2203 { &opcode_dd_35, 23 }, // DEC (IX + d)
2204 { &opcode_dd_36, 19 }, // LD (IX + d), n
2205 { 0, 0 }, // 0x37
2206 { 0, 0 }, // 0x38
2207 { &opcode_dd_39, 15 }, // ADD IX, SP
2208 { 0, 0 }, // 0x3A
2209 { 0, 0 }, // 0x3B
2210 { 0, 0 }, // 0x3C
2211 { 0, 0 }, // 0x3D
2212 { 0, 0 }, // 0x3E
2213 { 0, 0 }, // 0x3F
2214 { 0, 0 }, // 0x40
2215 { 0, 0 }, // 0x41
2216 { 0, 0 }, // 0x42
2217 { 0, 0 }, // 0x43
2218 { &opcode_dd_44, 9 }, // LD B, IXH
2219 { &opcode_dd_45, 9 }, // LD B, IXL
2220 { &opcode_dd_46, 19 }, // LD B, (IX + d)
2221 { 0, 0 }, // 0x47
2222 { 0, 0 }, // 0x48
2223 { 0, 0 }, // 0x49
2224 { 0, 0 }, // 0x4A
2225 { 0, 0 }, // 0x4B
2226 { &opcode_dd_4c, 9 }, // LD C, IXH
2227 { &opcode_dd_4d, 9 }, // LD C, IXL
2228 { &opcode_dd_4e, 19 }, // LD C, (IX + d)
2229 { 0, 0 }, // 0x4F
2230 { 0, 0 }, // 0x50
2231 { 0, 0 }, // 0x51
2232 { 0, 0 }, // 0x52
2233 { 0, 0 }, // 0x53
2234 { &opcode_dd_54, 9 }, // LD D, IXH
2235 { &opcode_dd_55, 9 }, // LD D, IXL
2236 { &opcode_dd_56, 19 }, // LD D, (IX + d)
2237 { 0, 0 }, // 0x57
2238 { 0, 0 }, // 0x58
2239 { 0, 0 }, // 0x59
2240 { 0, 0 }, // 0x5A
2241 { 0, 0 }, // 0x5B
2242 { &opcode_dd_5c, 9 }, // LD E, IXH
2243 { &opcode_dd_5d, 9 }, // LD E, IXL
2244 { &opcode_dd_5e, 19 }, // LD E, (IX + d)
2245 { 0, 0 }, // 0x5F
2246 { &opcode_dd_60, 9 }, // LD IXH, B
2247 { &opcode_dd_61, 9 }, // LD IXH, C
2248 { &opcode_dd_62, 9 }, // LD IXH, D
2249 { &opcode_dd_63, 9 }, // LD IXH, E
2250 { &opcode_dd_64, 9 }, // LD IXH, IXH
2251 { &opcode_dd_65, 9 }, // LD IXH, IXL
2252 { &opcode_dd_66, 9 }, // LD H, (IX + d)
2253 { &opcode_dd_67, 9 }, // LD IXH, A
2254 { &opcode_dd_68, 9 }, // LD IXL, B
2255 { &opcode_dd_69, 9 }, // LD IXL, C
2256 { &opcode_dd_6a, 9 }, // LD IXL, D
2257 { &opcode_dd_6b, 9 }, // LD IXL, E
2258 { &opcode_dd_6c, 9 }, // LD IXL, IXH
2259 { &opcode_dd_6d, 9 }, // LD IXL, IXL
2260 { &opcode_dd_6e, 9 }, // LD L, (IX + d)
2261 { &opcode_dd_6f, 9 }, // LD IXL, A
2262 { &opcode_dd_70, 19 }, // LD (IX + d), B
2263 { &opcode_dd_71, 19 }, // LD (IX + d), C
2264 { &opcode_dd_72, 19 }, // LD (IX + d), D
2265 { &opcode_dd_73, 19 }, // LD (IX + d), E
2266 { &opcode_dd_74, 19 }, // LD (IX + d), H
2267 { &opcode_dd_75, 19 }, // LD (IX + d), L
2268 { 0,19 }, // 0x76
2269 { &opcode_dd_77, 19 }, // LD (IX + d), A
2270 { 0, 0 }, // 0x78
2271 { 0, 0 }, // 0x79
2272 { 0, 0 }, // 0x7A
2273 { 0, 0 }, // 0x7B
2274 { &opcode_dd_7c, 9 }, // LD A, IXH
2275 { &opcode_dd_7d, 9 }, // LD A, IXL
2276 { &opcode_dd_7e, 19 }, // LD A, (IX + d)
2277 { 0, 0 }, // 0x7F
2278 { 0, 0 }, // 0x80
2279 { 0, 0 }, // 0x81
2280 { 0, 0 }, // 0x82
2281 { 0, 0 }, // 0x83
2282 { &opcode_dd_84, 9 }, // ADD A, IXH
2283 { &opcode_dd_85, 9 }, // ADD A, IXL
2284 { &opcode_dd_86, 19 }, // ADD A, (IX + d)
2285 { 0, 0 }, // 0x87
2286 { 0, 0 }, // 0x88
2287 { 0, 0 }, // 0x89
2288 { 0, 0 }, // 0x8A
2289 { 0, 0 }, // 0x8B
2290 { &opcode_dd_8c, 9 }, // ADC A, IXH
2291 { &opcode_dd_8d, 9 }, // ADC A, IXL
2292 { &opcode_dd_8e, 19 }, // ADC A, (IX + d)
2293 { 0, 0 }, // 0x8F
2294 { 0, 0 }, // 0x90
2295 { 0, 0 }, // 0x91
2296 { 0, 0 }, // 0x92
2297 { 0, 0 }, // 0x93
2298 { &opcode_dd_94, 9 }, // SUB IXH
2299 { &opcode_dd_95, 9 }, // SUB IXL
2300 { &opcode_dd_96, 19 }, // SUB (IX + d)
2301 { 0, 0 }, // 0x97
2302 { 0, 0 }, // 0x98
2303 { 0, 0 }, // 0x99
2304 { 0, 0 }, // 0x9A
2305 { 0, 0 }, // 0x9B
2306 { &opcode_dd_9c, 9 }, // SBC A, IXH
2307 { &opcode_dd_9d, 9 }, // SBC A, IXL
2308 { &opcode_dd_9e, 19 }, // SBC A, (IX + d)
2309 { 0, 0 }, // 0x9F
2310 { 0, 0 }, // 0xA0
2311 { 0, 0 }, // 0xA1
2312 { 0, 0 }, // 0xA2
2313 { 0, 0 }, // 0xA3
2314 { &opcode_dd_a4, 9 }, // AND IXH
2315 { &opcode_dd_a5, 9 }, // AND IXL
2316 { &opcode_dd_a6, 19 }, // AND (IX + d)
2317 { 0, 0 }, // 0xA7
2318 { 0, 0 }, // 0xA8
2319 { 0, 0 }, // 0xA9
2320 { 0, 0 }, // 0xAA
2321 { 0, 0 }, // 0xAB
2322 { &opcode_dd_ac, 9 }, // XOR IXH
2323 { &opcode_dd_ad, 9 }, // XOR IXL
2324 { &opcode_dd_ae, 19 }, // XOR (IX + d)
2325 { 0, 0 }, // 0xAF
2326 { 0, 0 }, // 0xB0
2327 { 0, 0 }, // 0xB1
2328 { 0, 0 }, // 0xB2
2329 { 0, 0 }, // 0xB3
2330 { &opcode_dd_b4, 9 }, // OR IXH
2331 { &opcode_dd_b5, 9 }, // OR IXL
2332 { &opcode_dd_b6, 19 }, // OR (IX + d)
2333 { 0, 0 }, // 0xB7
2334 { 0, 0 }, // 0xB8
2335 { 0, 0 }, // 0xB9
2336 { 0, 0 }, // 0xBA
2337 { 0, 0 }, // 0xBB
2338 { &opcode_dd_bc, 9 }, // CP IXH
2339 { &opcode_dd_bd, 9 }, // CP IXL
2340 { &opcode_dd_be, 19 }, // CP (IX + d)
2341 { 0, 0 }, // 0xBF
2342 { 0, 0 }, // 0xC0
2343 { 0, 0 }, // 0xC1
2344 { 0, 0 }, // 0xC2
2345 { 0, 0 }, // 0xC3
2346 { 0, 0 }, // 0xC4
2347 { 0, 0 }, // 0xC5
2348 { 0, 0 }, // 0xC6
2349 { 0, 0 }, // 0xC7
2350 { 0, 0 }, // 0xC8
2351 { 0, 0 }, // 0xC9
2352 { 0, 0 }, // 0xCA
2353 { &opcode_dd_cb, 0 }, //
2354 { 0, 0 }, // 0xCC
2355 { 0, 0 }, // 0xCD
2356 { 0, 0 }, // 0xCE
2357 { 0, 0 }, // 0xCF
2358 { 0, 0 }, // 0xD0
2359 { 0, 0 }, // 0xD1
2360 { 0, 0 }, // 0xD2
2361 { 0, 0 }, // 0xD3
2362 { 0, 0 }, // 0xD4
2363 { 0, 0 }, // 0xD5
2364 { 0, 0 }, // 0xD6
2365 { 0, 0 }, // 0xD7
2366 { 0, 0 }, // 0xD8
2367 { 0, 0 }, // 0xD9
2368 { 0, 0 }, // 0xDA
2369 { 0, 0 }, // 0xDB
2370 { 0, 0 }, // 0xDC
2371 { 0, 0 }, // 0xDD
2372 { 0, 0 }, // 0xDE
2373 { 0, 0 }, // 0xDF
2374 { 0, 0 }, // 0xE0
2375 { &opcode_dd_e1, 14 }, // POP IX
2376 { 0, 0 }, // 0xE2
2377 { &opcode_dd_e3, 23 }, // EX (SP), IX
2378 { 0, 0 }, // 0xE4
2379 { &opcode_dd_e5, 15 }, // PUSH IX
2380 { 0, 0 }, // 0xE6
2381 { 0, 0 }, // 0xE7
2382 { 0, 0 }, // 0xE8
2383 { &opcode_dd_e9, 8 }, // JP (IX)
2384 { 0, 0 }, // 0xEA
2385 { 0, 0 }, // 0xEB
2386 { 0, 0 }, // 0xEC
2387 { 0, 0 }, // 0xED
2388 { 0, 0 }, // 0xEE
2389 { 0, 0 }, // 0xEF
2390 { 0, 0 }, // 0xF0
2391 { 0, 0 }, // 0xF1
2392 { 0, 0 }, // 0xF2
2393 { 0, 0 }, // 0xF3
2394 { 0, 0 }, // 0xF4
2395 { 0, 0 }, // 0xF5
2396 { 0, 0 }, // 0xF6
2397 { 0, 0 }, // 0xF7
2398 { 0, 0 }, // 0xF8
2399 { &opcode_dd_f9, 10 }, // LD SP, IX
2400 { 0, 0 }, // 0xFA
2401 { 0, 0 }, // 0xFB
2402 { 0, 0 }, // 0xFC
2403 { 0, 0 }, // 0xFD
2404 { 0, 0 }, // 0xFE
2405 { 0, 0 } // 0xFF
2408 void opcode_dd_09() // ADD IX, BC
2410 unsigned rr = BC();
2412 F &= (Zero | Sign | Parity);
2413 if( ((IX & 0xFFF)+(rr & 0xFFF)) > 0xFFF ) F |= Halfcarry;
2414 IX += rr;
2415 if( IX & 0x10000 ) F |= Carry;
2418 void opcode_dd_19() // ADD IX, DE
2420 unsigned rr = DE();
2422 F &= (Zero | Sign | Parity);
2423 if( ((IX & 0xFFF)+(rr & 0xFFF)) > 0xFFF ) F |= Halfcarry;
2424 IX += rr;
2425 if( IX & 0x10000 ) F |= Carry;
2428 void opcode_dd_21() // LD IX, nn
2430 IX = fetchWord();
2433 void opcode_dd_22() // LD (nn), IX
2435 writeWord( fetchWord(), IX );
2438 void opcode_dd_23() // INC IX
2440 IX++;
2443 void opcode_dd_24() // INC IXH
2445 IX = (IX & 0xFF) | ((unsigned)incByte( IX >> 8 ) << 8);
2448 void opcode_dd_25() // DEC IXH
2450 IX = (IX & 0xFF) | ((unsigned)decByte( IX >> 8 ) << 8);
2453 void opcode_dd_26() // LD IXH, n
2455 IX = (IX & 0xFF) | ((unsigned)fetchByte() << 8);
2458 void opcode_dd_29() // ADD IX, IX
2460 F &= (Zero | Sign | Parity);
2461 if( IX & 0x800 ) F |= Halfcarry;
2462 IX += IX;
2463 if( IX & 0x10000 ) F |= Carry;
2466 void opcode_dd_2a() // LD IX, (nn)
2468 IX = readWord( fetchWord() );
2471 void opcode_dd_2b() // DEC IX
2473 IX--;
2476 void opcode_dd_2c() // INC IXL
2478 IX = (IX & 0xFF00) | incByte( IX & 0xFF );
2481 void opcode_dd_2d() // DEC IXL
2483 IX = (IX & 0xFF00) | decByte( IX & 0xFF );
2486 void opcode_dd_2e() // LD IXL, n
2488 IX = (IX & 0xFF00) | fetchByte();
2491 void opcode_dd_34() // INC (IX + d)
2493 unsigned addr = addDispl( IX, fetchByte() );
2495 writeByte( addr, incByte( readByte( addr ) ) );
2498 void opcode_dd_35() // DEC (IX + d)
2500 unsigned addr = addDispl( IX, fetchByte() );
2502 writeByte( addr, decByte( readByte( addr ) ) );
2505 void opcode_dd_36() // LD (IX + d), n
2507 unsigned addr = addDispl( IX, fetchByte() );
2509 writeByte( addr, fetchByte() );
2512 void opcode_dd_39() // ADD IX, SP
2514 F &= (Zero | Sign | Parity);
2515 if( ((IX & 0xFFF)+(SP & 0xFFF)) > 0xFFF ) F |= Halfcarry;
2516 IX += SP;
2517 if( IX & 0x10000 ) F |= Carry;
2520 void opcode_dd_44() // LD B, IXH
2522 B = IX >> 8;
2525 void opcode_dd_45() // LD B, IXL
2527 B = IX & 0xFF;
2530 void opcode_dd_46() // LD B, (IX + d)
2532 B = readByte( addDispl(IX,fetchByte()) );
2535 void opcode_dd_4c() // LD C, IXH
2537 C = IX >> 8;
2540 void opcode_dd_4d() // LD C, IXL
2542 C = IX & 0xFF;
2545 void opcode_dd_4e() // LD C, (IX + d)
2547 C = readByte( addDispl(IX,fetchByte()) );
2550 void opcode_dd_54() // LD D, IXH
2552 D = IX >> 8;
2555 void opcode_dd_55() // LD D, IXL
2557 D = IX & 0xFF;
2560 void opcode_dd_56() // LD D, (IX + d)
2562 D = readByte( addDispl(IX,fetchByte()) );
2565 void opcode_dd_5c() // LD E, IXH
2567 E = IX >> 8;
2570 void opcode_dd_5d() // LD E, IXL
2572 E = IX & 0xFF;
2575 void opcode_dd_5e() // LD E, (IX + d)
2577 E = readByte( addDispl(IX,fetchByte()) );
2580 void opcode_dd_60() // LD IXH, B
2582 IX = (IX & 0xFF) | ((unsigned)B << 8);
2585 void opcode_dd_61() // LD IXH, C
2587 IX = (IX & 0xFF) | ((unsigned)C << 8);
2590 void opcode_dd_62() // LD IXH, D
2592 IX = (IX & 0xFF) | ((unsigned)D << 8);
2595 void opcode_dd_63() // LD IXH, E
2597 IX = (IX & 0xFF) | ((unsigned)E << 8);
2600 void opcode_dd_64() // LD IXH, IXH
2604 void opcode_dd_65() // LD IXH, IXL
2606 IX = (IX & 0xFF) | ((IX << 8) & 0xFF00);
2609 void opcode_dd_66() // LD H, (IX + d)
2611 H = readByte( addDispl(IX,fetchByte()) );
2614 void opcode_dd_67() // LD IXH, A
2616 IX = (IX & 0xFF) | ((unsigned)A << 8);
2619 void opcode_dd_68() // LD IXL, B
2621 IX = (IX & 0xFF00) | B;
2624 void opcode_dd_69() // LD IXL, C
2626 IX = (IX & 0xFF00) | C;
2629 void opcode_dd_6a() // LD IXL, D
2631 IX = (IX & 0xFF00) | D;
2634 void opcode_dd_6b() // LD IXL, E
2636 IX = (IX & 0xFF00) | E;
2639 void opcode_dd_6c() // LD IXL, IXH
2641 IX = (IX & 0xFF00) | ((IX >> 8) & 0xFF);
2644 void opcode_dd_6d() // LD IXL, IXL
2648 void opcode_dd_6e() // LD L, (IX + d)
2650 L = readByte( addDispl(IX,fetchByte()) );
2653 void opcode_dd_6f() // LD IXL, A
2655 IX = (IX & 0xFF00) | A;
2658 void opcode_dd_70() // LD (IX + d), B
2660 writeByte( addDispl(IX,fetchByte()), B );
2663 void opcode_dd_71() // LD (IX + d), C
2665 writeByte( addDispl(IX,fetchByte()), C );
2668 void opcode_dd_72() // LD (IX + d), D
2670 writeByte( addDispl(IX,fetchByte()), D );
2673 void opcode_dd_73() // LD (IX + d), E
2675 writeByte( addDispl(IX,fetchByte()), E );
2678 void opcode_dd_74() // LD (IX + d), H
2680 writeByte( addDispl(IX,fetchByte()), H );
2683 void opcode_dd_75() // LD (IX + d), L
2685 writeByte( addDispl(IX,fetchByte()), L );
2688 void opcode_dd_77() // LD (IX + d), A
2690 writeByte( addDispl(IX,fetchByte()), A );
2693 void opcode_dd_7c() // LD A, IXH
2695 A = IX >> 8;
2698 void opcode_dd_7d() // LD A, IXL
2700 A = IX & 0xFF;
2703 void opcode_dd_7e() // LD A, (IX + d)
2705 A = readByte( addDispl(IX,fetchByte()) );
2708 void opcode_dd_84() // ADD A, IXH
2710 addByte( IX >> 8, 0 );
2713 void opcode_dd_85() // ADD A, IXL
2715 addByte( IX & 0xFF, 0 );
2718 void opcode_dd_86() // ADD A, (IX + d)
2720 addByte( readByte( addDispl(IX,fetchByte()) ), 0 );
2723 void opcode_dd_8c() // ADC A, IXH
2725 addByte( IX >> 8, F & Carry );
2728 void opcode_dd_8d() // ADC A, IXL
2730 addByte( IX & 0xFF, F & Carry );
2733 void opcode_dd_8e() // ADC A, (IX + d)
2735 addByte( readByte( addDispl(IX,fetchByte()) ), F & Carry );
2738 void opcode_dd_94() // SUB IXH
2740 A = subByte( IX >> 8, 0 );
2743 void opcode_dd_95() // SUB IXL
2745 A = subByte( IX & 0xFF, 0 );
2748 void opcode_dd_96() // SUB (IX + d)
2750 A = subByte( readByte( addDispl(IX,fetchByte()) ), 0 );
2753 void opcode_dd_9c() // SBC A, IXH
2755 A = subByte( IX >> 8, F & Carry );
2758 void opcode_dd_9d() // SBC A, IXL
2760 A = subByte( IX & 0xFF, F & Carry );
2763 void opcode_dd_9e() // SBC A, (IX + d)
2765 A = subByte( readByte( addDispl(IX,fetchByte()) ), F & Carry );
2768 void opcode_dd_a4() // AND IXH
2770 A &= IX >> 8;
2771 setFlags35PSZ000();
2772 F |= Halfcarry;
2775 void opcode_dd_a5() // AND IXL
2777 A &= IX & 0xFF;
2778 setFlags35PSZ000();
2779 F |= Halfcarry;
2782 void opcode_dd_a6() // AND (IX + d)
2784 A &= readByte( addDispl(IX,fetchByte()) );
2785 setFlags35PSZ000();
2786 F |= Halfcarry;
2789 void opcode_dd_ac() // XOR IXH
2791 A ^= IX >> 8;
2792 setFlags35PSZ000();
2795 void opcode_dd_ad() // XOR IXL
2797 A ^= IX & 0xFF;
2798 setFlags35PSZ000();
2801 void opcode_dd_ae() // XOR (IX + d)
2803 A ^= readByte( addDispl(IX,fetchByte()) );
2804 setFlags35PSZ000();
2807 void opcode_dd_b4() // OR IXH
2809 A |= IX >> 8;
2810 setFlags35PSZ000();
2813 void opcode_dd_b5() // OR IXL
2815 A |= IX & 0xFF;
2816 setFlags35PSZ000();
2819 void opcode_dd_b6() // OR (IX + d)
2821 A |= readByte( addDispl(IX,fetchByte()) );
2822 setFlags35PSZ000();
2825 void opcode_dd_bc() // CP IXH
2827 cmpByte( IX >> 8 );
2830 void opcode_dd_bd() // CP IXL
2832 cmpByte( IX & 0xFF );
2835 void opcode_dd_be() // CP (IX + d)
2837 cmpByte( readByte( addDispl(IX,fetchByte()) ) );
2840 void opcode_dd_cb() //
2842 do_opcode_xycb( IX );
2845 void opcode_dd_e1() // POP IX
2847 IX = readWord( SP );
2848 SP += 2;
2851 void opcode_dd_e3() // EX (SP), IX
2853 unsigned ix = IX;
2855 IX = readWord( SP );
2856 writeWord( SP, ix );
2859 void opcode_dd_e5() // PUSH IX
2861 SP -= 2;
2862 writeWord( SP, IX );
2865 void opcode_dd_e9() // JP (IX)
2867 PC = IX;
2870 void opcode_dd_f9() // LD SP, IX
2872 SP = IX;
2875 OpcodeInfo OpInfoED_[256] = {
2876 { 0, 0 }, // 0x00
2877 { 0, 0 }, // 0x01
2878 { 0, 0 }, // 0x02
2879 { 0, 0 }, // 0x03
2880 { 0, 0 }, // 0x04
2881 { 0, 0 }, // 0x05
2882 { 0, 0 }, // 0x06
2883 { 0, 0 }, // 0x07
2884 { 0, 0 }, // 0x08
2885 { 0, 0 }, // 0x09
2886 { 0, 0 }, // 0x0A
2887 { 0, 0 }, // 0x0B
2888 { 0, 0 }, // 0x0C
2889 { 0, 0 }, // 0x0D
2890 { 0, 0 }, // 0x0E
2891 { 0, 0 }, // 0x0F
2892 { 0, 0 }, // 0x10
2893 { 0, 0 }, // 0x11
2894 { 0, 0 }, // 0x12
2895 { 0, 0 }, // 0x13
2896 { 0, 0 }, // 0x14
2897 { 0, 0 }, // 0x15
2898 { 0, 0 }, // 0x16
2899 { 0, 0 }, // 0x17
2900 { 0, 0 }, // 0x18
2901 { 0, 0 }, // 0x19
2902 { 0, 0 }, // 0x1A
2903 { 0, 0 }, // 0x1B
2904 { 0, 0 }, // 0x1C
2905 { 0, 0 }, // 0x1D
2906 { 0, 0 }, // 0x1E
2907 { 0, 0 }, // 0x1F
2908 { 0, 0 }, // 0x20
2909 { 0, 0 }, // 0x21
2910 { 0, 0 }, // 0x22
2911 { 0, 0 }, // 0x23
2912 { 0, 0 }, // 0x24
2913 { 0, 0 }, // 0x25
2914 { 0, 0 }, // 0x26
2915 { 0, 0 }, // 0x27
2916 { 0, 0 }, // 0x28
2917 { 0, 0 }, // 0x29
2918 { 0, 0 }, // 0x2A
2919 { 0, 0 }, // 0x2B
2920 { 0, 0 }, // 0x2C
2921 { 0, 0 }, // 0x2D
2922 { 0, 0 }, // 0x2E
2923 { 0, 0 }, // 0x2F
2924 { 0, 0 }, // 0x30
2925 { 0, 0 }, // 0x31
2926 { 0, 0 }, // 0x32
2927 { 0, 0 }, // 0x33
2928 { 0, 0 }, // 0x34
2929 { 0, 0 }, // 0x35
2930 { 0, 0 }, // 0x36
2931 { 0, 0 }, // 0x37
2932 { 0, 0 }, // 0x38
2933 { 0, 0 }, // 0x39
2934 { 0, 0 }, // 0x3A
2935 { 0, 0 }, // 0x3B
2936 { 0, 0 }, // 0x3C
2937 { 0, 0 }, // 0x3D
2938 { 0, 0 }, // 0x3E
2939 { 0, 0 }, // 0x3F
2940 { &opcode_ed_40, 12 }, // IN B, (C)
2941 { &opcode_ed_41, 12 }, // OUT (C), B
2942 { &opcode_ed_42, 15 }, // SBC HL, BC
2943 { &opcode_ed_43, 20 }, // LD (nn), BC
2944 { &opcode_ed_44, 8 }, // NEG
2945 { &opcode_ed_45, 14 }, // RETN
2946 { &opcode_ed_46, 8 }, // IM 0
2947 { &opcode_ed_47, 9 }, // LD I, A
2948 { &opcode_ed_48, 12 }, // IN C, (C)
2949 { &opcode_ed_49, 12 }, // OUT (C), C
2950 { &opcode_ed_4a, 15 }, // ADC HL, BC
2951 { &opcode_ed_4b, 20 }, // LD BC, (nn)
2952 { &opcode_ed_4c, 8 }, // NEG
2953 { &opcode_ed_4d, 14 }, // RETI
2954 { &opcode_ed_4e, 8 }, // IM 0/1
2955 { &opcode_ed_4f, 9 }, // LD R, A
2956 { &opcode_ed_50, 12 }, // IN D, (C)
2957 { &opcode_ed_51, 12 }, // OUT (C), D
2958 { &opcode_ed_52, 15 }, // SBC HL, DE
2959 { &opcode_ed_53, 20 }, // LD (nn), DE
2960 { &opcode_ed_54, 8 }, // NEG
2961 { &opcode_ed_55, 14 }, // RETN
2962 { &opcode_ed_56, 8 }, // IM 1
2963 { &opcode_ed_57, 9 }, // LD A, I
2964 { &opcode_ed_58, 12 }, // IN E, (C)
2965 { &opcode_ed_59, 12 }, // OUT (C), E
2966 { &opcode_ed_5a, 15 }, // ADC HL, DE
2967 { &opcode_ed_5b, 20 }, // LD DE, (nn)
2968 { &opcode_ed_5c, 8 }, // NEG
2969 { &opcode_ed_5d, 14 }, // RETN
2970 { &opcode_ed_5e, 8 }, // IM 2
2971 { &opcode_ed_5f, 9 }, // LD A, R
2972 { &opcode_ed_60, 12 }, // IN H, (C)
2973 { &opcode_ed_61, 12 }, // OUT (C), H
2974 { &opcode_ed_62, 15 }, // SBC HL, HL
2975 { &opcode_ed_63, 20 }, // LD (nn), HL
2976 { &opcode_ed_64, 8 }, // NEG
2977 { &opcode_ed_65, 14 }, // RETN
2978 { &opcode_ed_66, 8 }, // IM 0
2979 { &opcode_ed_67, 18 }, // RRD
2980 { &opcode_ed_68, 12 }, // IN L, (C)
2981 { &opcode_ed_69, 12 }, // OUT (C), L
2982 { &opcode_ed_6a, 15 }, // ADC HL, HL
2983 { &opcode_ed_6b, 20 }, // LD HL, (nn)
2984 { &opcode_ed_6c, 8 }, // NEG
2985 { &opcode_ed_6d, 14 }, // RETN
2986 { &opcode_ed_6e, 8 }, // IM 0/1
2987 { &opcode_ed_6f, 18 }, // RLD
2988 { &opcode_ed_70, 12 }, // IN (C) / IN F, (C)
2989 { &opcode_ed_71, 12 }, // OUT (C), 0
2990 { &opcode_ed_72, 15 }, // SBC HL, SP
2991 { &opcode_ed_73, 20 }, // LD (nn), SP
2992 { &opcode_ed_74, 8 }, // NEG
2993 { &opcode_ed_75, 14 }, // RETN
2994 { &opcode_ed_76, 8 }, // IM 1
2995 { 0, 0 }, // 0x77
2996 { &opcode_ed_78, 12 }, // IN A, (C)
2997 { &opcode_ed_79, 12 }, // OUT (C), A
2998 { &opcode_ed_7a, 15 }, // ADC HL, SP
2999 { &opcode_ed_7b, 20 }, // LD SP, (nn)
3000 { &opcode_ed_7c, 8 }, // NEG
3001 { &opcode_ed_7d, 14 }, // RETN
3002 { &opcode_ed_7e, 8 }, // IM 2
3003 { 0, 0 }, // 0x7F
3004 { 0, 0 }, // 0x80
3005 { 0, 0 }, // 0x81
3006 { 0, 0 }, // 0x82
3007 { 0, 0 }, // 0x83
3008 { 0, 0 }, // 0x84
3009 { 0, 0 }, // 0x85
3010 { 0, 0 }, // 0x86
3011 { 0, 0 }, // 0x87
3012 { 0, 0 }, // 0x88
3013 { 0, 0 }, // 0x89
3014 { 0, 0 }, // 0x8A
3015 { 0, 0 }, // 0x8B
3016 { 0, 0 }, // 0x8C
3017 { 0, 0 }, // 0x8D
3018 { 0, 0 }, // 0x8E
3019 { 0, 0 }, // 0x8F
3020 { 0, 0 }, // 0x90
3021 { 0, 0 }, // 0x91
3022 { 0, 0 }, // 0x92
3023 { 0, 0 }, // 0x93
3024 { 0, 0 }, // 0x94
3025 { 0, 0 }, // 0x95
3026 { 0, 0 }, // 0x96
3027 { 0, 0 }, // 0x97
3028 { 0, 0 }, // 0x98
3029 { 0, 0 }, // 0x99
3030 { 0, 0 }, // 0x9A
3031 { 0, 0 }, // 0x9B
3032 { 0, 0 }, // 0x9C
3033 { 0, 0 }, // 0x9D
3034 { 0, 0 }, // 0x9E
3035 { 0, 0 }, // 0x9F
3036 { &opcode_ed_a0, 16 }, // LDI
3037 { &opcode_ed_a1, 16 }, // CPI
3038 { &opcode_ed_a2, 16 }, // INI
3039 { &opcode_ed_a3, 16 }, // OUTI
3040 { 0, 0 }, // 0xA4
3041 { 0, 0 }, // 0xA5
3042 { 0, 0 }, // 0xA6
3043 { 0, 0 }, // 0xA7
3044 { &opcode_ed_a8, 16 }, // LDD
3045 { &opcode_ed_a9, 16 }, // CPD
3046 { &opcode_ed_aa, 16 }, // IND
3047 { &opcode_ed_ab, 16 }, // OUTD
3048 { 0, 0 }, // 0xAC
3049 { 0, 0 }, // 0xAD
3050 { 0, 0 }, // 0xAE
3051 { 0, 0 }, // 0xAF
3052 { &opcode_ed_b0, 0 }, // LDIR
3053 { &opcode_ed_b1, 0 }, // CPIR
3054 { &opcode_ed_b2, 0 }, // INIR
3055 { &opcode_ed_b3, 0 }, // OTIR
3056 { 0, 0 }, // 0xB4
3057 { 0, 0 }, // 0xB5
3058 { 0, 0 }, // 0xB6
3059 { 0, 0 }, // 0xB7
3060 { &opcode_ed_b8, 0 }, // LDDR
3061 { &opcode_ed_b9, 0 }, // CPDR
3062 { &opcode_ed_ba, 0 }, // INDR
3063 { &opcode_ed_bb, 0 }, // OTDR
3064 { 0, 0 }, // 0xBC
3065 { 0, 0 }, // 0xBD
3066 { 0, 0 }, // 0xBE
3067 { 0, 0 }, // 0xBF
3068 { 0, 0 }, // 0xC0
3069 { 0, 0 }, // 0xC1
3070 { 0, 0 }, // 0xC2
3071 { 0, 0 }, // 0xC3
3072 { 0, 0 }, // 0xC4
3073 { 0, 0 }, // 0xC5
3074 { 0, 0 }, // 0xC6
3075 { 0, 0 }, // 0xC7
3076 { 0, 0 }, // 0xC8
3077 { 0, 0 }, // 0xC9
3078 { 0, 0 }, // 0xCA
3079 { 0, 0 }, // 0xCB
3080 { 0, 0 }, // 0xCC
3081 { 0, 0 }, // 0xCD
3082 { 0, 0 }, // 0xCE
3083 { 0, 0 }, // 0xCF
3084 { 0, 0 }, // 0xD0
3085 { 0, 0 }, // 0xD1
3086 { 0, 0 }, // 0xD2
3087 { 0, 0 }, // 0xD3
3088 { 0, 0 }, // 0xD4
3089 { 0, 0 }, // 0xD5
3090 { 0, 0 }, // 0xD6
3091 { 0, 0 }, // 0xD7
3092 { 0, 0 }, // 0xD8
3093 { 0, 0 }, // 0xD9
3094 { 0, 0 }, // 0xDA
3095 { 0, 0 }, // 0xDB
3096 { 0, 0 }, // 0xDC
3097 { 0, 0 }, // 0xDD
3098 { 0, 0 }, // 0xDE
3099 { 0, 0 }, // 0xDF
3100 { 0, 0 }, // 0xE0
3101 { 0, 0 }, // 0xE1
3102 { 0, 0 }, // 0xE2
3103 { 0, 0 }, // 0xE3
3104 { 0, 0 }, // 0xE4
3105 { 0, 0 }, // 0xE5
3106 { 0, 0 }, // 0xE6
3107 { 0, 0 }, // 0xE7
3108 { 0, 0 }, // 0xE8
3109 { 0, 0 }, // 0xE9
3110 { 0, 0 }, // 0xEA
3111 { 0, 0 }, // 0xEB
3112 { 0, 0 }, // 0xEC
3113 { 0, 0 }, // 0xED
3114 { 0, 0 }, // 0xEE
3115 { 0, 0 }, // 0xEF
3116 { 0, 0 }, // 0xF0
3117 { 0, 0 }, // 0xF1
3118 { 0, 0 }, // 0xF2
3119 { 0, 0 }, // 0xF3
3120 { 0, 0 }, // 0xF4
3121 { 0, 0 }, // 0xF5
3122 { 0, 0 }, // 0xF6
3123 { 0, 0 }, // 0xF7
3124 { 0, 0 }, // 0xF8
3125 { 0, 0 }, // 0xF9
3126 { 0, 0 }, // 0xFA
3127 { 0, 0 }, // 0xFB
3128 { 0, 0 }, // 0xFC
3129 { 0, 0 }, // 0xFD
3130 { 0, 0 }, // 0xFE
3131 { 0, 0 } // 0xFF
3134 void opcode_ed_40() // IN B, (C)
3136 B = inpReg();
3139 void opcode_ed_41() // OUT (C), B
3141 writePort( C, B );
3144 void opcode_ed_42() // SBC HL, BC
3146 unsigned char a;
3148 a = A;
3149 A = L; L = subByte( C, F & Carry );
3150 A = H; H = subByte( B, F & Carry );
3151 A = a;
3152 if( HL() == 0 ) F |= Zero; else F &= ~Zero;
3155 void opcode_ed_43() // LD (nn), BC
3157 unsigned addr = fetchWord();
3159 writeByte( addr, C );
3160 writeByte( addr+1, B );
3163 void opcode_ed_44() // NEG
3165 unsigned char a = A;
3167 A = 0;
3168 A = subByte( a, 0 );
3171 void opcode_ed_45() // RETN
3173 retFromSub();
3174 iflags_ &= ~IFF1;
3175 if( iflags_ & IFF2 ) iflags_ |= IFF1;
3178 void opcode_ed_46() // IM 0
3180 setInterruptMode( 0 );
3183 void opcode_ed_47() // LD I, A
3185 I = A;
3188 void opcode_ed_48() // IN C, (C)
3190 C = inpReg();
3193 void opcode_ed_49() // OUT (C), C
3195 writePort( C, C );
3198 void opcode_ed_4a() // ADC HL, BC
3200 unsigned char a;
3202 a = A;
3203 A = L; addByte( C, F & Carry ); L = A;
3204 A = H; addByte( B, F & Carry ); H = A;
3205 A = a;
3206 if( HL() == 0 ) F |= Zero; else F &= ~Zero;
3209 void opcode_ed_4b() // LD BC, (nn)
3211 unsigned addr = fetchWord();
3213 C = readByte( addr );
3214 B = readByte( addr+1 );
3217 void opcode_ed_4c() // NEG
3219 opcode_ed_44();
3222 void opcode_ed_4d() // RETI
3224 retFromSub();
3225 //onReturnFromInterrupt();
3228 void opcode_ed_4e() // IM 0/1
3230 setInterruptMode( 0 );
3233 void opcode_ed_4f() // LD R, A
3235 R = A;
3238 void opcode_ed_50() // IN D, (C)
3240 D = inpReg();
3243 void opcode_ed_51() // OUT (C), D
3245 writePort( C, D );
3248 void opcode_ed_52() // SBC HL, DE
3250 unsigned char a;
3252 a = A;
3253 A = L; L = subByte( E, F & Carry );
3254 A = H; H = subByte( D, F & Carry );
3255 A = a;
3256 if( HL() == 0 ) F |= Zero; else F &= ~Zero;
3259 void opcode_ed_53() // LD (nn), DE
3261 unsigned addr = fetchWord();
3263 writeByte( addr, E );
3264 writeByte( addr+1, D );
3267 void opcode_ed_54() // NEG
3269 opcode_ed_44();
3272 void opcode_ed_55() // RETN
3274 opcode_ed_45();
3277 void opcode_ed_56() // IM 1
3279 setInterruptMode( 1 );
3282 void opcode_ed_57() // LD A, I
3284 A = I;
3285 setFlags35PSZ();
3286 F &= ~(Halfcarry | Parity | AddSub);
3287 if( iflags_ & IFF2 ) F |= Parity;
3290 void opcode_ed_58() // IN E, (C)
3292 E = inpReg();
3295 void opcode_ed_59() // OUT (C), E
3297 writePort( C, E );
3300 void opcode_ed_5a() // ADC HL, DE
3302 unsigned char a;
3304 a = A;
3305 A = L; addByte( E, F & Carry ); L = A;
3306 A = H; addByte( D, F & Carry ); H = A;
3307 A = a;
3308 if( HL() == 0 ) F |= Zero; else F &= ~Zero;
3311 void opcode_ed_5b() // LD DE, (nn)
3313 unsigned addr = fetchWord();
3315 E = readByte( addr );
3316 D = readByte( addr+1 );
3319 void opcode_ed_5c() // NEG
3321 opcode_ed_44();
3324 void opcode_ed_5d() // RETN
3326 opcode_ed_45();
3329 void opcode_ed_5e() // IM 2
3331 setInterruptMode( 2 );
3334 void opcode_ed_5f() // LD A, R
3336 A = R;
3337 setFlags35PSZ();
3338 F &= ~(Halfcarry | Parity | AddSub);
3339 if( iflags_ & IFF2 ) F |= Parity;
3342 void opcode_ed_60() // IN H, (C)
3344 H = inpReg();
3347 void opcode_ed_61() // OUT (C), H
3349 writePort( C, H );
3352 void opcode_ed_62() // SBC HL, HL
3354 unsigned char a;
3356 a = A;
3357 A = L; L = subByte( L, F & Carry );
3358 A = H; H = subByte( H, F & Carry );
3359 A = a;
3360 if( HL() == 0 ) F |= Zero; else F &= ~Zero;
3363 void opcode_ed_63() // LD (nn), HL
3365 unsigned addr = fetchWord();
3367 writeByte( addr, L );
3368 writeByte( addr+1, H );
3371 void opcode_ed_64() // NEG
3373 opcode_ed_44();
3376 void opcode_ed_65() // RETN
3378 opcode_ed_45();
3381 void opcode_ed_66() // IM 0
3383 setInterruptMode( 0 );
3386 void opcode_ed_67() // RRD
3388 unsigned char x = readByte( HL() );
3390 writeByte( HL(), (A << 4) | (x >> 4) );
3391 A = (A & 0xF0) | (x & 0x0F);
3392 setFlags35PSZ();
3393 F &= ~(Halfcarry | AddSub);
3396 void opcode_ed_68() // IN L, (C)
3398 L = inpReg();
3401 void opcode_ed_69() // OUT (C), L
3403 writePort( C, L );
3406 void opcode_ed_6a() // ADC HL, HL
3408 unsigned char a;
3410 a = A;
3411 A = L; addByte( L, F & Carry ); L = A;
3412 A = H; addByte( H, F & Carry ); H = A;
3413 A = a;
3414 if( HL() == 0 ) F |= Zero; else F &= ~Zero;
3417 void opcode_ed_6b() // LD HL, (nn)
3419 unsigned addr = fetchWord();
3421 L = readByte( addr );
3422 H = readByte( addr+1 );
3425 void opcode_ed_6c() // NEG
3427 opcode_ed_44();
3430 void opcode_ed_6d() // RETN
3432 opcode_ed_45();
3435 void opcode_ed_6e() // IM 0/1
3437 setInterruptMode( 0 );
3440 void opcode_ed_6f() // RLD
3442 unsigned char x = readByte( HL() );
3444 writeByte( HL(), (x << 4) | (A & 0x0F) );
3445 A = (A & 0xF0) | (x >> 4);
3446 setFlags35PSZ();
3447 F &= ~(Halfcarry | AddSub);
3450 void opcode_ed_70() // IN (C) / IN F, (C)
3452 inpReg();
3455 void opcode_ed_71() // OUT (C), 0
3457 writePort( C, 0 );
3460 void opcode_ed_72() // SBC HL, SP
3462 unsigned char a;
3464 a = A;
3465 A = L; L = subByte( SP & 0xFF, F & Carry );
3466 A = H; H = subByte( (SP >> 8) & 0xFF, F & Carry );
3467 A = a;
3468 if( HL() == 0 ) F |= Zero; else F &= ~Zero;
3471 void opcode_ed_73() // LD (nn), SP
3473 writeWord( fetchWord(), SP );
3476 void opcode_ed_74() // NEG
3478 opcode_ed_44();
3481 void opcode_ed_75() // RETN
3483 opcode_ed_45();
3486 void opcode_ed_76() // IM 1
3488 setInterruptMode( 1 );
3491 void opcode_ed_78() // IN A, (C)
3493 A = inpReg();
3496 void opcode_ed_79() // OUT (C), A
3498 writePort( C, A );
3501 void opcode_ed_7a() // ADC HL, SP
3503 unsigned char a;
3505 a = A;
3506 A = L; addByte( SP & 0xFF, F & Carry ); L = A;
3507 A = H; addByte( (SP >> 8) & 0xFF, F & Carry ); H = A;
3508 A = a;
3509 if( HL() == 0 ) F |= Zero; else F &= ~Zero;
3512 void opcode_ed_7b() // LD SP, (nn)
3514 SP = readWord( fetchWord() );
3517 void opcode_ed_7c() // NEG
3519 opcode_ed_44();
3522 void opcode_ed_7d() // RETN
3524 opcode_ed_45();
3527 void opcode_ed_7e() // IM 2
3529 setInterruptMode( 2 );
3532 void opcode_ed_a0() // LDI
3534 writeByte( DE(), readByte( HL() ) );
3535 if( ++L == 0 ) ++H; // HL++
3536 if( ++E == 0 ) ++D; // DE++
3537 if( C-- == 0 ) --B; // BC--
3538 F &= ~(Halfcarry | Subtraction | Parity);
3539 if( BC() ) F |= Parity;
3542 void opcode_ed_a1() // CPI
3544 unsigned char f = F;
3546 cmpByte( readByte( HL() ) );
3547 if( ++L == 0 ) ++H; // HL++
3548 if( C-- == 0 ) --B; // BC--
3549 F = (F & ~(Carry | Parity)) | (f & Carry);
3550 if( BC() ) F |= Parity;
3553 void opcode_ed_a2() // INI
3555 writeByte( HL(), readPort( C ) );
3556 if( ++L == 0 ) ++H; // HL++
3557 B = decByte( B );
3560 void opcode_ed_a3() // OUTI
3562 writePort( C, readByte( HL() ) );
3563 if( ++L == 0 ) ++H; // HL++
3564 B = decByte( B );
3567 void opcode_ed_a8() // LDD
3569 writeByte( DE(), readByte( HL() ) );
3570 if( L-- == 0 ) --H; // HL--
3571 if( E-- == 0 ) --D; // DE--
3572 if( C-- == 0 ) --B; // BC--
3573 F &= ~(Halfcarry | Subtraction | Parity);
3574 if( BC() ) F |= Parity;
3577 void opcode_ed_a9() // CPD
3579 unsigned char f = F;
3581 cmpByte( readByte( HL() ) );
3582 if( L-- == 0 ) --H; // HL--
3583 if( C-- == 0 ) --B; // BC--
3584 F = (F & ~(Carry | Parity)) | (f & Carry);
3585 if( BC() ) F |= Parity;
3588 void opcode_ed_aa() // IND
3590 writeByte( HL(), readPort( C ) );
3591 if( L-- == 0 ) --H; // HL--
3592 B = decByte( B );
3595 void opcode_ed_ab() // OUTD
3597 writePort( C, readByte( HL() ) );
3598 if( L-- == 0 ) --H; // HL--
3599 B = decByte( B );
3602 void opcode_ed_b0() // LDIR
3604 opcode_ed_a0(); // LDI
3605 if( F & Parity ) { // After LDI, the Parity flag will be zero when BC=0
3606 cycles_ += 5;
3607 PC -= 2; // Decrement PC so that instruction is re-executed at next step (this allows interrupts to occur)
3611 void opcode_ed_b1() // CPIR
3613 opcode_ed_a1(); // CPI
3614 if( (F & Parity) && !(F & Zero) ) { // Parity clear when BC=0, Zero set when A=(HL)
3615 cycles_ += 5;
3616 PC -= 2; // Decrement PC so that instruction is re-executed at next step (this allows interrupts to occur)
3620 void opcode_ed_b2() // INIR
3622 opcode_ed_a2(); // INI
3623 if( B != 0 ) {
3624 cycles_ += 5;
3625 PC -= 2; // Decrement PC so that instruction is re-executed at next step (this allows interrupts to occur)
3629 void opcode_ed_b3() // OTIR
3631 opcode_ed_a3(); // OUTI
3632 if( B != 0 ) {
3633 cycles_ += 5;
3634 PC -= 2; // Decrement PC so that instruction is re-executed at next step (this allows interrupts to occur)
3638 void opcode_ed_b8() // LDDR
3640 opcode_ed_a8(); // LDD
3641 if( F & Parity ) { // After LDD, the Parity flag will be zero when BC=0
3642 cycles_ += 5;
3643 PC -= 2; // Decrement PC so that instruction is re-executed at next step (this allows interrupts to occur)
3647 void opcode_ed_b9() // CPDR
3649 opcode_ed_a9(); // CPD
3650 if( (F & Parity) && !(F & Zero) ) { // Parity clear when BC=0, Zero set when A=(HL)
3651 cycles_ += 5;
3652 PC -= 2; // Decrement PC so that instruction is re-executed at next step (this allows interrupts to occur)
3656 void opcode_ed_ba() // INDR
3658 opcode_ed_aa(); // IND
3659 if( B != 0 ) {
3660 cycles_ += 5;
3661 PC -= 2; // Decrement PC so that instruction is re-executed at next step (this allows interrupts to occur)
3665 void opcode_ed_bb() // OTDR
3667 opcode_ed_ab(); // OUTD
3668 if( B != 0 ) {
3669 cycles_ += 5;
3670 PC -= 2; // Decrement PC so that instruction is re-executed at next step (this allows interrupts to occur)
3674 OpcodeInfo OpInfoFD_[256] = {
3675 { 0, 0 }, // 0x00
3676 { 0, 0 }, // 0x01
3677 { 0, 0 }, // 0x02
3678 { 0, 0 }, // 0x03
3679 { 0, 0 }, // 0x04
3680 { 0, 0 }, // 0x05
3681 { 0, 0 }, // 0x06
3682 { 0, 0 }, // 0x07
3683 { 0, 0 }, // 0x08
3684 { &opcode_fd_09, 15 }, // ADD IY, BC
3685 { 0, 0 }, // 0x0A
3686 { 0, 0 }, // 0x0B
3687 { 0, 0 }, // 0x0C
3688 { 0, 0 }, // 0x0D
3689 { 0, 0 }, // 0x0E
3690 { 0, 0 }, // 0x0F
3691 { 0, 0 }, // 0x10
3692 { 0, 0 }, // 0x11
3693 { 0, 0 }, // 0x12
3694 { 0, 0 }, // 0x13
3695 { 0, 0 }, // 0x14
3696 { 0, 0 }, // 0x15
3697 { 0, 0 }, // 0x16
3698 { 0, 0 }, // 0x17
3699 { 0, 0 }, // 0x18
3700 { &opcode_fd_19, 15 }, // ADD IY, DE
3701 { 0, 0 }, // 0x1A
3702 { 0, 0 }, // 0x1B
3703 { 0, 0 }, // 0x1C
3704 { 0, 0 }, // 0x1D
3705 { 0, 0 }, // 0x1E
3706 { 0, 0 }, // 0x1F
3707 { 0, 0 }, // 0x20
3708 { &opcode_fd_21, 14 }, // LD IY, nn
3709 { &opcode_fd_22, 20 }, // LD (nn), IY
3710 { &opcode_fd_23, 10 }, // INC IY
3711 { &opcode_fd_24, 9 }, // INC IYH
3712 { &opcode_fd_25, 9 }, // DEC IYH
3713 { &opcode_fd_26, 9 }, // LD IYH, n
3714 { 0, 0 }, // 0x27
3715 { 0, 0 }, // 0x28
3716 { &opcode_fd_29, 15 }, // ADD IY, IY
3717 { &opcode_fd_2a, 20 }, // LD IY, (nn)
3718 { &opcode_fd_2b, 10 }, // DEC IY
3719 { &opcode_fd_2c, 9 }, // INC IYL
3720 { &opcode_fd_2d, 9 }, // DEC IYL
3721 { &opcode_fd_2e, 9 }, // LD IYL, n
3722 { 0, 0 }, // 0x2F
3723 { 0, 0 }, // 0x30
3724 { 0, 0 }, // 0x31
3725 { 0, 0 }, // 0x32
3726 { 0, 0 }, // 0x33
3727 { &opcode_fd_34, 23 }, // INC (IY + d)
3728 { &opcode_fd_35, 23 }, // DEC (IY + d)
3729 { &opcode_fd_36, 19 }, // LD (IY + d), n
3730 { 0, 0 }, // 0x37
3731 { 0, 0 }, // 0x38
3732 { &opcode_fd_39, 15 }, // ADD IY, SP
3733 { 0, 0 }, // 0x3A
3734 { 0, 0 }, // 0x3B
3735 { 0, 0 }, // 0x3C
3736 { 0, 0 }, // 0x3D
3737 { 0, 0 }, // 0x3E
3738 { 0, 0 }, // 0x3F
3739 { 0, 0 }, // 0x40
3740 { 0, 0 }, // 0x41
3741 { 0, 0 }, // 0x42
3742 { 0, 0 }, // 0x43
3743 { &opcode_fd_44, 9 }, // LD B, IYH
3744 { &opcode_fd_45, 9 }, // LD B, IYL
3745 { &opcode_fd_46, 19 }, // LD B, (IY + d)
3746 { 0, 0 }, // 0x47
3747 { 0, 0 }, // 0x48
3748 { 0, 0 }, // 0x49
3749 { 0, 0 }, // 0x4A
3750 { 0, 0 }, // 0x4B
3751 { &opcode_fd_4c, 9 }, // LD C, IYH
3752 { &opcode_fd_4d, 9 }, // LD C, IYL
3753 { &opcode_fd_4e, 19 }, // LD C, (IY + d)
3754 { 0, 0 }, // 0x4F
3755 { 0, 0 }, // 0x50
3756 { 0, 0 }, // 0x51
3757 { 0, 0 }, // 0x52
3758 { 0, 0 }, // 0x53
3759 { &opcode_fd_54, 9 }, // LD D, IYH
3760 { &opcode_fd_55, 9 }, // LD D, IYL
3761 { &opcode_fd_56, 19 }, // LD D, (IY + d)
3762 { 0, 0 }, // 0x57
3763 { 0, 0 }, // 0x58
3764 { 0, 0 }, // 0x59
3765 { 0, 0 }, // 0x5A
3766 { 0, 0 }, // 0x5B
3767 { &opcode_fd_5c, 9 }, // LD E, IYH
3768 { &opcode_fd_5d, 9 }, // LD E, IYL
3769 { &opcode_fd_5e, 19 }, // LD E, (IY + d)
3770 { 0, 0 }, // 0x5F
3771 { &opcode_fd_60, 9 }, // LD IYH, B
3772 { &opcode_fd_61, 9 }, // LD IYH, C
3773 { &opcode_fd_62, 9 }, // LD IYH, D
3774 { &opcode_fd_63, 9 }, // LD IYH, E
3775 { &opcode_fd_64, 9 }, // LD IYH, IYH
3776 { &opcode_fd_65, 9 }, // LD IYH, IYL
3777 { &opcode_fd_66, 9 }, // LD H, (IY + d)
3778 { &opcode_fd_67, 9 }, // LD IYH, A
3779 { &opcode_fd_68, 9 }, // LD IYL, B
3780 { &opcode_fd_69, 9 }, // LD IYL, C
3781 { &opcode_fd_6a, 9 }, // LD IYL, D
3782 { &opcode_fd_6b, 9 }, // LD IYL, E
3783 { &opcode_fd_6c, 9 }, // LD IYL, IYH
3784 { &opcode_fd_6d, 9 }, // LD IYL, IYL
3785 { &opcode_fd_6e, 9 }, // LD L, (IY + d)
3786 { &opcode_fd_6f, 9 }, // LD IYL, A
3787 { &opcode_fd_70, 19 }, // LD (IY + d), B
3788 { &opcode_fd_71, 19 }, // LD (IY + d), C
3789 { &opcode_fd_72, 19 }, // LD (IY + d), D
3790 { &opcode_fd_73, 19 }, // LD (IY + d), E
3791 { &opcode_fd_74, 19 }, // LD (IY + d), H
3792 { &opcode_fd_75, 19 }, // LD (IY + d), L
3793 { 0,19 }, // 0x76
3794 { &opcode_fd_77, 19 }, // LD (IY + d), A
3795 { 0, 0 }, // 0x78
3796 { 0, 0 }, // 0x79
3797 { 0, 0 }, // 0x7A
3798 { 0, 0 }, // 0x7B
3799 { &opcode_fd_7c, 9 }, // LD A, IYH
3800 { &opcode_fd_7d, 9 }, // LD A, IYL
3801 { &opcode_fd_7e, 19 }, // LD A, (IY + d)
3802 { 0, 0 }, // 0x7F
3803 { 0, 0 }, // 0x80
3804 { 0, 0 }, // 0x81
3805 { 0, 0 }, // 0x82
3806 { 0, 0 }, // 0x83
3807 { &opcode_fd_84, 9 }, // ADD A, IYH
3808 { &opcode_fd_85, 9 }, // ADD A, IYL
3809 { &opcode_fd_86, 19 }, // ADD A, (IY + d)
3810 { 0, 0 }, // 0x87
3811 { 0, 0 }, // 0x88
3812 { 0, 0 }, // 0x89
3813 { 0, 0 }, // 0x8A
3814 { 0, 0 }, // 0x8B
3815 { &opcode_fd_8c, 9 }, // ADC A, IYH
3816 { &opcode_fd_8d, 9 }, // ADC A, IYL
3817 { &opcode_fd_8e, 19 }, // ADC A, (IY + d)
3818 { 0, 0 }, // 0x8F
3819 { 0, 0 }, // 0x90
3820 { 0, 0 }, // 0x91
3821 { 0, 0 }, // 0x92
3822 { 0, 0 }, // 0x93
3823 { &opcode_fd_94, 9 }, // SUB IYH
3824 { &opcode_fd_95, 9 }, // SUB IYL
3825 { &opcode_fd_96, 19 }, // SUB (IY + d)
3826 { 0, 0 }, // 0x97
3827 { 0, 0 }, // 0x98
3828 { 0, 0 }, // 0x99
3829 { 0, 0 }, // 0x9A
3830 { 0, 0 }, // 0x9B
3831 { &opcode_fd_9c, 9 }, // SBC A, IYH
3832 { &opcode_fd_9d, 9 }, // SBC A, IYL
3833 { &opcode_fd_9e, 19 }, // SBC A, (IY + d)
3834 { 0, 0 }, // 0x9F
3835 { 0, 0 }, // 0xA0
3836 { 0, 0 }, // 0xA1
3837 { 0, 0 }, // 0xA2
3838 { 0, 0 }, // 0xA3
3839 { &opcode_fd_a4, 9 }, // AND IYH
3840 { &opcode_fd_a5, 9 }, // AND IYL
3841 { &opcode_fd_a6, 19 }, // AND (IY + d)
3842 { 0, 0 }, // 0xA7
3843 { 0, 0 }, // 0xA8
3844 { 0, 0 }, // 0xA9
3845 { 0, 0 }, // 0xAA
3846 { 0, 0 }, // 0xAB
3847 { &opcode_fd_ac, 9 }, // XOR IYH
3848 { &opcode_fd_ad, 9 }, // XOR IYL
3849 { &opcode_fd_ae, 19 }, // XOR (IY + d)
3850 { 0, 0 }, // 0xAF
3851 { 0, 0 }, // 0xB0
3852 { 0, 0 }, // 0xB1
3853 { 0, 0 }, // 0xB2
3854 { 0, 0 }, // 0xB3
3855 { &opcode_fd_b4, 9 }, // OR IYH
3856 { &opcode_fd_b5, 9 }, // OR IYL
3857 { &opcode_fd_b6, 19 }, // OR (IY + d)
3858 { 0, 0 }, // 0xB7
3859 { 0, 0 }, // 0xB8
3860 { 0, 0 }, // 0xB9
3861 { 0, 0 }, // 0xBA
3862 { 0, 0 }, // 0xBB
3863 { &opcode_fd_bc, 9 }, // CP IYH
3864 { &opcode_fd_bd, 9 }, // CP IYL
3865 { &opcode_fd_be, 19 }, // CP (IY + d)
3866 { 0, 0 }, // 0xBF
3867 { 0, 0 }, // 0xC0
3868 { 0, 0 }, // 0xC1
3869 { 0, 0 }, // 0xC2
3870 { 0, 0 }, // 0xC3
3871 { 0, 0 }, // 0xC4
3872 { 0, 0 }, // 0xC5
3873 { 0, 0 }, // 0xC6
3874 { 0, 0 }, // 0xC7
3875 { 0, 0 }, // 0xC8
3876 { 0, 0 }, // 0xC9
3877 { 0, 0 }, // 0xCA
3878 { &opcode_fd_cb, 0 }, //
3879 { 0, 0 }, // 0xCC
3880 { 0, 0 }, // 0xCD
3881 { 0, 0 }, // 0xCE
3882 { 0, 0 }, // 0xCF
3883 { 0, 0 }, // 0xD0
3884 { 0, 0 }, // 0xD1
3885 { 0, 0 }, // 0xD2
3886 { 0, 0 }, // 0xD3
3887 { 0, 0 }, // 0xD4
3888 { 0, 0 }, // 0xD5
3889 { 0, 0 }, // 0xD6
3890 { 0, 0 }, // 0xD7
3891 { 0, 0 }, // 0xD8
3892 { 0, 0 }, // 0xD9
3893 { 0, 0 }, // 0xDA
3894 { 0, 0 }, // 0xDB
3895 { 0, 0 }, // 0xDC
3896 { 0, 0 }, // 0xDD
3897 { 0, 0 }, // 0xDE
3898 { 0, 0 }, // 0xDF
3899 { 0, 0 }, // 0xE0
3900 { &opcode_fd_e1, 14 }, // POP IY
3901 { 0, 0 }, // 0xE2
3902 { &opcode_fd_e3, 23 }, // EX (SP), IY
3903 { 0, 0 }, // 0xE4
3904 { &opcode_fd_e5, 15 }, // PUSH IY
3905 { 0, 0 }, // 0xE6
3906 { 0, 0 }, // 0xE7
3907 { 0, 0 }, // 0xE8
3908 { &opcode_fd_e9, 8 }, // JP (IY)
3909 { 0, 0 }, // 0xEA
3910 { 0, 0 }, // 0xEB
3911 { 0, 0 }, // 0xEC
3912 { 0, 0 }, // 0xED
3913 { 0, 0 }, // 0xEE
3914 { 0, 0 }, // 0xEF
3915 { 0, 0 }, // 0xF0
3916 { 0, 0 }, // 0xF1
3917 { 0, 0 }, // 0xF2
3918 { 0, 0 }, // 0xF3
3919 { 0, 0 }, // 0xF4
3920 { 0, 0 }, // 0xF5
3921 { 0, 0 }, // 0xF6
3922 { 0, 0 }, // 0xF7
3923 { 0, 0 }, // 0xF8
3924 { &opcode_fd_f9, 10 }, // LD SP, IY
3925 { 0, 0 }, // 0xFA
3926 { 0, 0 }, // 0xFB
3927 { 0, 0 }, // 0xFC
3928 { 0, 0 }, // 0xFD
3929 { 0, 0 }, // 0xFE
3930 { 0, 0 } // 0xFF
3933 void opcode_fd_09() // ADD IY, BC
3935 unsigned rr = BC();
3937 F &= (Zero | Sign | Parity);
3938 if( ((IY & 0xFFF)+(rr & 0xFFF)) > 0xFFF ) F |= Halfcarry;
3939 IY += rr;
3940 if( IY & 0x10000 ) F |= Carry;
3943 void opcode_fd_19() // ADD IY, DE
3945 unsigned rr = DE();
3947 F &= (Zero | Sign | Parity);
3948 if( ((IY & 0xFFF)+(rr & 0xFFF)) > 0xFFF ) F |= Halfcarry;
3949 IY += rr;
3950 if( IY & 0x10000 ) F |= Carry;
3953 void opcode_fd_21() // LD IY, nn
3955 IY = fetchWord();
3958 void opcode_fd_22() // LD (nn), IY
3960 writeWord( fetchWord(), IY );
3963 void opcode_fd_23() // INC IY
3965 IY++;
3968 void opcode_fd_24() // INC IYH
3970 IY = (IY & 0xFF) | ((unsigned)incByte( IY >> 8 ) << 8);
3973 void opcode_fd_25() // DEC IYH
3975 IY = (IY & 0xFF) | ((unsigned)decByte( IY >> 8 ) << 8);
3978 void opcode_fd_26() // LD IYH, n
3980 IY = (IY & 0xFF) | ((unsigned)fetchByte() << 8);
3983 void opcode_fd_29() // ADD IY, IY
3985 F &= (Zero | Sign | Parity);
3986 if( IY & 0x800 ) F |= Halfcarry;
3987 IY += IY;
3988 if( IY & 0x10000 ) F |= Carry;
3991 void opcode_fd_2a() // LD IY, (nn)
3993 IY = readWord( fetchWord() );
3996 void opcode_fd_2b() // DEC IY
3998 IY--;
4001 void opcode_fd_2c() // INC IYL
4003 IY = (IY & 0xFF00) | incByte( IY & 0xFF );
4006 void opcode_fd_2d() // DEC IYL
4008 IY = (IY & 0xFF00) | decByte( IY & 0xFF );
4011 void opcode_fd_2e() // LD IYL, n
4013 IY = (IY & 0xFF00) | fetchByte();
4016 void opcode_fd_34() // INC (IY + d)
4018 unsigned addr = addDispl( IY, fetchByte() );
4020 writeByte( addr, incByte( readByte( addr ) ) );
4023 void opcode_fd_35() // DEC (IY + d)
4025 unsigned addr = addDispl( IY, fetchByte() );
4027 writeByte( addr, decByte( readByte( addr ) ) );
4030 void opcode_fd_36() // LD (IY + d), n
4032 unsigned addr = addDispl( IY, fetchByte() );
4034 writeByte( addr, fetchByte() );
4037 void opcode_fd_39() // ADD IY, SP
4039 F &= (Zero | Sign | Parity);
4040 if( ((IY & 0xFFF)+(SP & 0xFFF)) > 0xFFF ) F |= Halfcarry;
4041 IY += SP;
4042 if( IY & 0x10000 ) F |= Carry;
4045 void opcode_fd_44() // LD B, IYH
4047 B = IY >> 8;
4050 void opcode_fd_45() // LD B, IYL
4052 B = IY & 0xFF;
4055 void opcode_fd_46() // LD B, (IY + d)
4057 B = readByte( addDispl(IY,fetchByte()) );
4060 void opcode_fd_4c() // LD C, IYH
4062 C = IY >> 8;
4065 void opcode_fd_4d() // LD C, IYL
4067 C = IY & 0xFF;
4070 void opcode_fd_4e() // LD C, (IY + d)
4072 C = readByte( addDispl(IY,fetchByte()) );
4075 void opcode_fd_54() // LD D, IYH
4077 D = IY >> 8;
4080 void opcode_fd_55() // LD D, IYL
4082 D = IY & 0xFF;
4085 void opcode_fd_56() // LD D, (IY + d)
4087 D = readByte( addDispl(IY,fetchByte()) );
4090 void opcode_fd_5c() // LD E, IYH
4092 E = IY >> 8;
4095 void opcode_fd_5d() // LD E, IYL
4097 E = IY & 0xFF;
4100 void opcode_fd_5e() // LD E, (IY + d)
4102 E = readByte( addDispl(IY,fetchByte()) );
4105 void opcode_fd_60() // LD IYH, B
4107 IY = (IY & 0xFF) | ((unsigned)B << 8);
4110 void opcode_fd_61() // LD IYH, C
4112 IY = (IY & 0xFF) | ((unsigned)C << 8);
4115 void opcode_fd_62() // LD IYH, D
4117 IY = (IY & 0xFF) | ((unsigned)D << 8);
4120 void opcode_fd_63() // LD IYH, E
4122 IY = (IY & 0xFF) | ((unsigned)E << 8);
4125 void opcode_fd_64() // LD IYH, IYH
4129 void opcode_fd_65() // LD IYH, IYL
4131 IY = (IY & 0xFF) | ((IY << 8) & 0xFF00);
4134 void opcode_fd_66() // LD H, (IY + d)
4136 H = readByte( addDispl(IY,fetchByte()) );
4139 void opcode_fd_67() // LD IYH, A
4141 IY = (IY & 0xFF) | ((unsigned)A << 8);
4144 void opcode_fd_68() // LD IYL, B
4146 IY = (IY & 0xFF00) | B;
4149 void opcode_fd_69() // LD IYL, C
4151 IY = (IY & 0xFF00) | C;
4154 void opcode_fd_6a() // LD IYL, D
4156 IY = (IY & 0xFF00) | D;
4159 void opcode_fd_6b() // LD IYL, E
4161 IY = (IY & 0xFF00) | E;
4164 void opcode_fd_6c() // LD IYL, IYH
4166 IY = (IY & 0xFF00) | ((IY >> 8) & 0xFF);
4169 void opcode_fd_6d() // LD IYL, IYL
4173 void opcode_fd_6e() // LD L, (IY + d)
4175 L = readByte( addDispl(IY,fetchByte()) );
4178 void opcode_fd_6f() // LD IYL, A
4180 IY = (IY & 0xFF00) | A;
4183 void opcode_fd_70() // LD (IY + d), B
4185 writeByte( addDispl(IY,fetchByte()), B );
4188 void opcode_fd_71() // LD (IY + d), C
4190 writeByte( addDispl(IY,fetchByte()), C );
4193 void opcode_fd_72() // LD (IY + d), D
4195 writeByte( addDispl(IY,fetchByte()), D );
4198 void opcode_fd_73() // LD (IY + d), E
4200 writeByte( addDispl(IY,fetchByte()), E );
4203 void opcode_fd_74() // LD (IY + d), H
4205 writeByte( addDispl(IY,fetchByte()), H );
4208 void opcode_fd_75() // LD (IY + d), L
4210 writeByte( addDispl(IY,fetchByte()), L );
4213 void opcode_fd_77() // LD (IY + d), A
4215 writeByte( addDispl(IY,fetchByte()), A );
4218 void opcode_fd_7c() // LD A, IYH
4220 A = IY >> 8;
4223 void opcode_fd_7d() // LD A, IYL
4225 A = IY & 0xFF;
4228 void opcode_fd_7e() // LD A, (IY + d)
4230 A = readByte( addDispl(IY,fetchByte()) );
4233 void opcode_fd_84() // ADD A, IYH
4235 addByte( IY >> 8, 0 );
4238 void opcode_fd_85() // ADD A, IYL
4240 addByte( IY & 0xFF, 0 );
4243 void opcode_fd_86() // ADD A, (IY + d)
4245 addByte( readByte( addDispl(IY,fetchByte()) ), 0 );
4248 void opcode_fd_8c() // ADC A, IYH
4250 addByte( IY >> 8, F & Carry );
4253 void opcode_fd_8d() // ADC A, IYL
4255 addByte( IY & 0xFF, F & Carry );
4258 void opcode_fd_8e() // ADC A, (IY + d)
4260 addByte( readByte( addDispl(IY,fetchByte()) ), F & Carry );
4263 void opcode_fd_94() // SUB IYH
4265 A = subByte( IY >> 8, 0 );
4268 void opcode_fd_95() // SUB IYL
4270 A = subByte( IY & 0xFF, 0 );
4273 void opcode_fd_96() // SUB (IY + d)
4275 A = subByte( readByte( addDispl(IY,fetchByte()) ), 0 );
4278 void opcode_fd_9c() // SBC A, IYH
4280 A = subByte( IY >> 8, F & Carry );
4283 void opcode_fd_9d() // SBC A, IYL
4285 A = subByte( IY & 0xFF, F & Carry );
4288 void opcode_fd_9e() // SBC A, (IY + d)
4290 A = subByte( readByte( addDispl(IY,fetchByte()) ), F & Carry );
4293 void opcode_fd_a4() // AND IYH
4295 A &= IY >> 8;
4296 setFlags35PSZ000();
4297 F |= Halfcarry;
4300 void opcode_fd_a5() // AND IYL
4302 A &= IY & 0xFF;
4303 setFlags35PSZ000();
4304 F |= Halfcarry;
4307 void opcode_fd_a6() // AND (IY + d)
4309 A &= readByte( addDispl(IY,fetchByte()) );
4310 setFlags35PSZ000();
4311 F |= Halfcarry;
4314 void opcode_fd_ac() // XOR IYH
4316 A ^= IY >> 8;
4317 setFlags35PSZ000();
4320 void opcode_fd_ad() // XOR IYL
4322 A ^= IY & 0xFF;
4323 setFlags35PSZ000();
4326 void opcode_fd_ae() // XOR (IY + d)
4328 A ^= readByte( addDispl(IY,fetchByte()) );
4329 setFlags35PSZ000();
4332 void opcode_fd_b4() // OR IYH
4334 A |= IY >> 8;
4335 setFlags35PSZ000();
4338 void opcode_fd_b5() // OR IYL
4340 A |= IY & 0xFF;
4341 setFlags35PSZ000();
4344 void opcode_fd_b6() // OR (IY + d)
4346 A |= readByte( addDispl(IY,fetchByte()) );
4347 setFlags35PSZ000();
4350 void opcode_fd_bc() // CP IYH
4352 cmpByte( IY >> 8 );
4355 void opcode_fd_bd() // CP IYL
4357 cmpByte( IY & 0xFF );
4360 void opcode_fd_be() // CP (IY + d)
4362 cmpByte( readByte( addDispl(IY,fetchByte()) ) );
4365 void opcode_fd_cb() //
4367 do_opcode_xycb( IY );
4370 void opcode_fd_e1() // POP IY
4372 IY = readWord( SP );
4373 SP += 2;
4376 void opcode_fd_e3() // EX (SP), IY
4378 unsigned iy = IY;
4380 IY = readWord( SP );
4381 writeWord( SP, iy );
4384 void opcode_fd_e5() // PUSH IY
4386 SP -= 2;
4387 writeWord( SP, IY );
4390 void opcode_fd_e9() // JP (IY)
4392 PC = IY;
4395 void opcode_fd_f9() // LD SP, IY
4397 SP = IY;
4400 OpcodeInfoXY OpInfoXYCB_[256] = {
4401 { &opcode_xycb_00, 20 }, // LD B, RLC (IX + d)
4402 { &opcode_xycb_01, 20 }, // LD C, RLC (IX + d)
4403 { &opcode_xycb_02, 20 }, // LD D, RLC (IX + d)
4404 { &opcode_xycb_03, 20 }, // LD E, RLC (IX + d)
4405 { &opcode_xycb_04, 20 }, // LD H, RLC (IX + d)
4406 { &opcode_xycb_05, 20 }, // LD L, RLC (IX + d)
4407 { &opcode_xycb_06, 20 }, // RLC (IX + d)
4408 { &opcode_xycb_07, 20 }, // LD A, RLC (IX + d)
4409 { &opcode_xycb_08, 20 }, // LD B, RRC (IX + d)
4410 { &opcode_xycb_09, 20 }, // LD C, RRC (IX + d)
4411 { &opcode_xycb_0a, 20 }, // LD D, RRC (IX + d)
4412 { &opcode_xycb_0b, 20 }, // LD E, RRC (IX + d)
4413 { &opcode_xycb_0c, 20 }, // LD H, RRC (IX + d)
4414 { &opcode_xycb_0d, 20 }, // LD L, RRC (IX + d)
4415 { &opcode_xycb_0e, 20 }, // RRC (IX + d)
4416 { &opcode_xycb_0f, 20 }, // LD A, RRC (IX + d)
4417 { &opcode_xycb_10, 20 }, // LD B, RL (IX + d)
4418 { &opcode_xycb_11, 20 }, // LD C, RL (IX + d)
4419 { &opcode_xycb_12, 20 }, // LD D, RL (IX + d)
4420 { &opcode_xycb_13, 20 }, // LD E, RL (IX + d)
4421 { &opcode_xycb_14, 20 }, // LD H, RL (IX + d)
4422 { &opcode_xycb_15, 20 }, // LD L, RL (IX + d)
4423 { &opcode_xycb_16, 20 }, // RL (IX + d)
4424 { &opcode_xycb_17, 20 }, // LD A, RL (IX + d)
4425 { &opcode_xycb_18, 20 }, // LD B, RR (IX + d)
4426 { &opcode_xycb_19, 20 }, // LD C, RR (IX + d)
4427 { &opcode_xycb_1a, 20 }, // LD D, RR (IX + d)
4428 { &opcode_xycb_1b, 20 }, // LD E, RR (IX + d)
4429 { &opcode_xycb_1c, 20 }, // LD H, RR (IX + d)
4430 { &opcode_xycb_1d, 20 }, // LD L, RR (IX + d)
4431 { &opcode_xycb_1e, 20 }, // RR (IX + d)
4432 { &opcode_xycb_1f, 20 }, // LD A, RR (IX + d)
4433 { &opcode_xycb_20, 20 }, // LD B, SLA (IX + d)
4434 { &opcode_xycb_21, 20 }, // LD C, SLA (IX + d)
4435 { &opcode_xycb_22, 20 }, // LD D, SLA (IX + d)
4436 { &opcode_xycb_23, 20 }, // LD E, SLA (IX + d)
4437 { &opcode_xycb_24, 20 }, // LD H, SLA (IX + d)
4438 { &opcode_xycb_25, 20 }, // LD L, SLA (IX + d)
4439 { &opcode_xycb_26, 20 }, // SLA (IX + d)
4440 { &opcode_xycb_27, 20 }, // LD A, SLA (IX + d)
4441 { &opcode_xycb_28, 20 }, // LD B, SRA (IX + d)
4442 { &opcode_xycb_29, 20 }, // LD C, SRA (IX + d)
4443 { &opcode_xycb_2a, 20 }, // LD D, SRA (IX + d)
4444 { &opcode_xycb_2b, 20 }, // LD E, SRA (IX + d)
4445 { &opcode_xycb_2c, 20 }, // LD H, SRA (IX + d)
4446 { &opcode_xycb_2d, 20 }, // LD L, SRA (IX + d)
4447 { &opcode_xycb_2e, 20 }, // SRA (IX + d)
4448 { &opcode_xycb_2f, 20 }, // LD A, SRA (IX + d)
4449 { &opcode_xycb_30, 20 }, // LD B, SLL (IX + d)
4450 { &opcode_xycb_31, 20 }, // LD C, SLL (IX + d)
4451 { &opcode_xycb_32, 20 }, // LD D, SLL (IX + d)
4452 { &opcode_xycb_33, 20 }, // LD E, SLL (IX + d)
4453 { &opcode_xycb_34, 20 }, // LD H, SLL (IX + d)
4454 { &opcode_xycb_35, 20 }, // LD L, SLL (IX + d)
4455 { &opcode_xycb_36, 20 }, // SLL (IX + d)
4456 { &opcode_xycb_37, 20 }, // LD A, SLL (IX + d)
4457 { &opcode_xycb_38, 20 }, // LD B, SRL (IX + d)
4458 { &opcode_xycb_39, 20 }, // LD C, SRL (IX + d)
4459 { &opcode_xycb_3a, 20 }, // LD D, SRL (IX + d)
4460 { &opcode_xycb_3b, 20 }, // LD E, SRL (IX + d)
4461 { &opcode_xycb_3c, 20 }, // LD H, SRL (IX + d)
4462 { &opcode_xycb_3d, 20 }, // LD L, SRL (IX + d)
4463 { &opcode_xycb_3e, 20 }, // SRL (IX + d)
4464 { &opcode_xycb_3f, 20 }, // LD A, SRL (IX + d)
4465 { &opcode_xycb_40, 20 }, // BIT 0, (IX + d)
4466 { &opcode_xycb_41, 20 }, // BIT 0, (IX + d)
4467 { &opcode_xycb_42, 20 }, // BIT 0, (IX + d)
4468 { &opcode_xycb_43, 20 }, // BIT 0, (IX + d)
4469 { &opcode_xycb_44, 20 }, // BIT 0, (IX + d)
4470 { &opcode_xycb_45, 20 }, // BIT 0, (IX + d)
4471 { &opcode_xycb_46, 20 }, // BIT 0, (IX + d)
4472 { &opcode_xycb_47, 20 }, // BIT 0, (IX + d)
4473 { &opcode_xycb_48, 20 }, // BIT 1, (IX + d)
4474 { &opcode_xycb_49, 20 }, // BIT 1, (IX + d)
4475 { &opcode_xycb_4a, 20 }, // BIT 1, (IX + d)
4476 { &opcode_xycb_4b, 20 }, // BIT 1, (IX + d)
4477 { &opcode_xycb_4c, 20 }, // BIT 1, (IX + d)
4478 { &opcode_xycb_4d, 20 }, // BIT 1, (IX + d)
4479 { &opcode_xycb_4e, 20 }, // BIT 1, (IX + d)
4480 { &opcode_xycb_4f, 20 }, // BIT 1, (IX + d)
4481 { &opcode_xycb_50, 20 }, // BIT 2, (IX + d)
4482 { &opcode_xycb_51, 20 }, // BIT 2, (IX + d)
4483 { &opcode_xycb_52, 20 }, // BIT 2, (IX + d)
4484 { &opcode_xycb_53, 20 }, // BIT 2, (IX + d)
4485 { &opcode_xycb_54, 20 }, // BIT 2, (IX + d)
4486 { &opcode_xycb_55, 20 }, // BIT 2, (IX + d)
4487 { &opcode_xycb_56, 20 }, // BIT 2, (IX + d)
4488 { &opcode_xycb_57, 20 }, // BIT 2, (IX + d)
4489 { &opcode_xycb_58, 20 }, // BIT 3, (IX + d)
4490 { &opcode_xycb_59, 20 }, // BIT 3, (IX + d)
4491 { &opcode_xycb_5a, 20 }, // BIT 3, (IX + d)
4492 { &opcode_xycb_5b, 20 }, // BIT 3, (IX + d)
4493 { &opcode_xycb_5c, 20 }, // BIT 3, (IX + d)
4494 { &opcode_xycb_5d, 20 }, // BIT 3, (IX + d)
4495 { &opcode_xycb_5e, 20 }, // BIT 3, (IX + d)
4496 { &opcode_xycb_5f, 20 }, // BIT 3, (IX + d)
4497 { &opcode_xycb_60, 20 }, // BIT 4, (IX + d)
4498 { &opcode_xycb_61, 20 }, // BIT 4, (IX + d)
4499 { &opcode_xycb_62, 20 }, // BIT 4, (IX + d)
4500 { &opcode_xycb_63, 20 }, // BIT 4, (IX + d)
4501 { &opcode_xycb_64, 20 }, // BIT 4, (IX + d)
4502 { &opcode_xycb_65, 20 }, // BIT 4, (IX + d)
4503 { &opcode_xycb_66, 20 }, // BIT 4, (IX + d)
4504 { &opcode_xycb_67, 20 }, // BIT 4, (IX + d)
4505 { &opcode_xycb_68, 20 }, // BIT 5, (IX + d)
4506 { &opcode_xycb_69, 20 }, // BIT 5, (IX + d)
4507 { &opcode_xycb_6a, 20 }, // BIT 5, (IX + d)
4508 { &opcode_xycb_6b, 20 }, // BIT 5, (IX + d)
4509 { &opcode_xycb_6c, 20 }, // BIT 5, (IX + d)
4510 { &opcode_xycb_6d, 20 }, // BIT 5, (IX + d)
4511 { &opcode_xycb_6e, 20 }, // BIT 5, (IX + d)
4512 { &opcode_xycb_6f, 20 }, // BIT 5, (IX + d)
4513 { &opcode_xycb_70, 20 }, // BIT 6, (IX + d)
4514 { &opcode_xycb_71, 20 }, // BIT 6, (IX + d)
4515 { &opcode_xycb_72, 20 }, // BIT 6, (IX + d)
4516 { &opcode_xycb_73, 20 }, // BIT 6, (IX + d)
4517 { &opcode_xycb_74, 20 }, // BIT 6, (IX + d)
4518 { &opcode_xycb_75, 20 }, // BIT 6, (IX + d)
4519 { &opcode_xycb_76, 20 }, // BIT 6, (IX + d)
4520 { &opcode_xycb_77, 20 }, // BIT 6, (IX + d)
4521 { &opcode_xycb_78, 20 }, // BIT 7, (IX + d)
4522 { &opcode_xycb_79, 20 }, // BIT 7, (IX + d)
4523 { &opcode_xycb_7a, 20 }, // BIT 7, (IX + d)
4524 { &opcode_xycb_7b, 20 }, // BIT 7, (IX + d)
4525 { &opcode_xycb_7c, 20 }, // BIT 7, (IX + d)
4526 { &opcode_xycb_7d, 20 }, // BIT 7, (IX + d)
4527 { &opcode_xycb_7e, 20 }, // BIT 7, (IX + d)
4528 { &opcode_xycb_7f, 20 }, // BIT 7, (IX + d)
4529 { &opcode_xycb_80, 20 }, // LD B, RES 0, (IX + d)
4530 { &opcode_xycb_81, 20 }, // LD C, RES 0, (IX + d)
4531 { &opcode_xycb_82, 20 }, // LD D, RES 0, (IX + d)
4532 { &opcode_xycb_83, 20 }, // LD E, RES 0, (IX + d)
4533 { &opcode_xycb_84, 20 }, // LD H, RES 0, (IX + d)
4534 { &opcode_xycb_85, 20 }, // LD L, RES 0, (IX + d)
4535 { &opcode_xycb_86, 20 }, // RES 0, (IX + d)
4536 { &opcode_xycb_87, 20 }, // LD A, RES 0, (IX + d)
4537 { &opcode_xycb_88, 20 }, // LD B, RES 1, (IX + d)
4538 { &opcode_xycb_89, 20 }, // LD C, RES 1, (IX + d)
4539 { &opcode_xycb_8a, 20 }, // LD D, RES 1, (IX + d)
4540 { &opcode_xycb_8b, 20 }, // LD E, RES 1, (IX + d)
4541 { &opcode_xycb_8c, 20 }, // LD H, RES 1, (IX + d)
4542 { &opcode_xycb_8d, 20 }, // LD L, RES 1, (IX + d)
4543 { &opcode_xycb_8e, 20 }, // RES 1, (IX + d)
4544 { &opcode_xycb_8f, 20 }, // LD A, RES 1, (IX + d)
4545 { &opcode_xycb_90, 20 }, // LD B, RES 2, (IX + d)
4546 { &opcode_xycb_91, 20 }, // LD C, RES 2, (IX + d)
4547 { &opcode_xycb_92, 20 }, // LD D, RES 2, (IX + d)
4548 { &opcode_xycb_93, 20 }, // LD E, RES 2, (IX + d)
4549 { &opcode_xycb_94, 20 }, // LD H, RES 2, (IX + d)
4550 { &opcode_xycb_95, 20 }, // LD L, RES 2, (IX + d)
4551 { &opcode_xycb_96, 20 }, // RES 2, (IX + d)
4552 { &opcode_xycb_97, 20 }, // LD A, RES 2, (IX + d)
4553 { &opcode_xycb_98, 20 }, // LD B, RES 3, (IX + d)
4554 { &opcode_xycb_99, 20 }, // LD C, RES 3, (IX + d)
4555 { &opcode_xycb_9a, 20 }, // LD D, RES 3, (IX + d)
4556 { &opcode_xycb_9b, 20 }, // LD E, RES 3, (IX + d)
4557 { &opcode_xycb_9c, 20 }, // LD H, RES 3, (IX + d)
4558 { &opcode_xycb_9d, 20 }, // LD L, RES 3, (IX + d)
4559 { &opcode_xycb_9e, 20 }, // RES 3, (IX + d)
4560 { &opcode_xycb_9f, 20 }, // LD A, RES 3, (IX + d)
4561 { &opcode_xycb_a0, 20 }, // LD B, RES 4, (IX + d)
4562 { &opcode_xycb_a1, 20 }, // LD C, RES 4, (IX + d)
4563 { &opcode_xycb_a2, 20 }, // LD D, RES 4, (IX + d)
4564 { &opcode_xycb_a3, 20 }, // LD E, RES 4, (IX + d)
4565 { &opcode_xycb_a4, 20 }, // LD H, RES 4, (IX + d)
4566 { &opcode_xycb_a5, 20 }, // LD L, RES 4, (IX + d)
4567 { &opcode_xycb_a6, 20 }, // RES 4, (IX + d)
4568 { &opcode_xycb_a7, 20 }, // LD A, RES 4, (IX + d)
4569 { &opcode_xycb_a8, 20 }, // LD B, RES 5, (IX + d)
4570 { &opcode_xycb_a9, 20 }, // LD C, RES 5, (IX + d)
4571 { &opcode_xycb_aa, 20 }, // LD D, RES 5, (IX + d)
4572 { &opcode_xycb_ab, 20 }, // LD E, RES 5, (IX + d)
4573 { &opcode_xycb_ac, 20 }, // LD H, RES 5, (IX + d)
4574 { &opcode_xycb_ad, 20 }, // LD L, RES 5, (IX + d)
4575 { &opcode_xycb_ae, 20 }, // RES 5, (IX + d)
4576 { &opcode_xycb_af, 20 }, // LD A, RES 5, (IX + d)
4577 { &opcode_xycb_b0, 20 }, // LD B, RES 6, (IX + d)
4578 { &opcode_xycb_b1, 20 }, // LD C, RES 6, (IX + d)
4579 { &opcode_xycb_b2, 20 }, // LD D, RES 6, (IX + d)
4580 { &opcode_xycb_b3, 20 }, // LD E, RES 6, (IX + d)
4581 { &opcode_xycb_b4, 20 }, // LD H, RES 6, (IX + d)
4582 { &opcode_xycb_b5, 20 }, // LD L, RES 6, (IX + d)
4583 { &opcode_xycb_b6, 20 }, // RES 6, (IX + d)
4584 { &opcode_xycb_b7, 20 }, // LD A, RES 6, (IX + d)
4585 { &opcode_xycb_b8, 20 }, // LD B, RES 7, (IX + d)
4586 { &opcode_xycb_b9, 20 }, // LD C, RES 7, (IX + d)
4587 { &opcode_xycb_ba, 20 }, // LD D, RES 7, (IX + d)
4588 { &opcode_xycb_bb, 20 }, // LD E, RES 7, (IX + d)
4589 { &opcode_xycb_bc, 20 }, // LD H, RES 7, (IX + d)
4590 { &opcode_xycb_bd, 20 }, // LD L, RES 7, (IX + d)
4591 { &opcode_xycb_be, 20 }, // RES 7, (IX + d)
4592 { &opcode_xycb_bf, 20 }, // LD A, RES 7, (IX + d)
4593 { &opcode_xycb_c0, 20 }, // LD B, SET 0, (IX + d)
4594 { &opcode_xycb_c1, 20 }, // LD C, SET 0, (IX + d)
4595 { &opcode_xycb_c2, 20 }, // LD D, SET 0, (IX + d)
4596 { &opcode_xycb_c3, 20 }, // LD E, SET 0, (IX + d)
4597 { &opcode_xycb_c4, 20 }, // LD H, SET 0, (IX + d)
4598 { &opcode_xycb_c5, 20 }, // LD L, SET 0, (IX + d)
4599 { &opcode_xycb_c6, 20 }, // SET 0, (IX + d)
4600 { &opcode_xycb_c7, 20 }, // LD A, SET 0, (IX + d)
4601 { &opcode_xycb_c8, 20 }, // LD B, SET 1, (IX + d)
4602 { &opcode_xycb_c9, 20 }, // LD C, SET 1, (IX + d)
4603 { &opcode_xycb_ca, 20 }, // LD D, SET 1, (IX + d)
4604 { &opcode_xycb_cb, 20 }, // LD E, SET 1, (IX + d)
4605 { &opcode_xycb_cc, 20 }, // LD H, SET 1, (IX + d)
4606 { &opcode_xycb_cd, 20 }, // LD L, SET 1, (IX + d)
4607 { &opcode_xycb_ce, 20 }, // SET 1, (IX + d)
4608 { &opcode_xycb_cf, 20 }, // LD A, SET 1, (IX + d)
4609 { &opcode_xycb_d0, 20 }, // LD B, SET 2, (IX + d)
4610 { &opcode_xycb_d1, 20 }, // LD C, SET 2, (IX + d)
4611 { &opcode_xycb_d2, 20 }, // LD D, SET 2, (IX + d)
4612 { &opcode_xycb_d3, 20 }, // LD E, SET 2, (IX + d)
4613 { &opcode_xycb_d4, 20 }, // LD H, SET 2, (IX + d)
4614 { &opcode_xycb_d5, 20 }, // LD L, SET 2, (IX + d)
4615 { &opcode_xycb_d6, 20 }, // SET 2, (IX + d)
4616 { &opcode_xycb_d7, 20 }, // LD A, SET 2, (IX + d)
4617 { &opcode_xycb_d8, 20 }, // LD B, SET 3, (IX + d)
4618 { &opcode_xycb_d9, 20 }, // LD C, SET 3, (IX + d)
4619 { &opcode_xycb_da, 20 }, // LD D, SET 3, (IX + d)
4620 { &opcode_xycb_db, 20 }, // LD E, SET 3, (IX + d)
4621 { &opcode_xycb_dc, 20 }, // LD H, SET 3, (IX + d)
4622 { &opcode_xycb_dd, 20 }, // LD L, SET 3, (IX + d)
4623 { &opcode_xycb_de, 20 }, // SET 3, (IX + d)
4624 { &opcode_xycb_df, 20 }, // LD A, SET 3, (IX + d)
4625 { &opcode_xycb_e0, 20 }, // LD B, SET 4, (IX + d)
4626 { &opcode_xycb_e1, 20 }, // LD C, SET 4, (IX + d)
4627 { &opcode_xycb_e2, 20 }, // LD D, SET 4, (IX + d)
4628 { &opcode_xycb_e3, 20 }, // LD E, SET 4, (IX + d)
4629 { &opcode_xycb_e4, 20 }, // LD H, SET 4, (IX + d)
4630 { &opcode_xycb_e5, 20 }, // LD L, SET 4, (IX + d)
4631 { &opcode_xycb_e6, 20 }, // SET 4, (IX + d)
4632 { &opcode_xycb_e7, 20 }, // LD A, SET 4, (IX + d)
4633 { &opcode_xycb_e8, 20 }, // LD B, SET 5, (IX + d)
4634 { &opcode_xycb_e9, 20 }, // LD C, SET 5, (IX + d)
4635 { &opcode_xycb_ea, 20 }, // LD D, SET 5, (IX + d)
4636 { &opcode_xycb_eb, 20 }, // LD E, SET 5, (IX + d)
4637 { &opcode_xycb_ec, 20 }, // LD H, SET 5, (IX + d)
4638 { &opcode_xycb_ed, 20 }, // LD L, SET 5, (IX + d)
4639 { &opcode_xycb_ee, 20 }, // SET 5, (IX + d)
4640 { &opcode_xycb_ef, 20 }, // LD A, SET 5, (IX + d)
4641 { &opcode_xycb_f0, 20 }, // LD B, SET 6, (IX + d)
4642 { &opcode_xycb_f1, 20 }, // LD C, SET 6, (IX + d)
4643 { &opcode_xycb_f2, 20 }, // LD D, SET 6, (IX + d)
4644 { &opcode_xycb_f3, 20 }, // LD E, SET 6, (IX + d)
4645 { &opcode_xycb_f4, 20 }, // LD H, SET 6, (IX + d)
4646 { &opcode_xycb_f5, 20 }, // LD L, SET 6, (IX + d)
4647 { &opcode_xycb_f6, 20 }, // SET 6, (IX + d)
4648 { &opcode_xycb_f7, 20 }, // LD A, SET 6, (IX + d)
4649 { &opcode_xycb_f8, 20 }, // LD B, SET 7, (IX + d)
4650 { &opcode_xycb_f9, 20 }, // LD C, SET 7, (IX + d)
4651 { &opcode_xycb_fa, 20 }, // LD D, SET 7, (IX + d)
4652 { &opcode_xycb_fb, 20 }, // LD E, SET 7, (IX + d)
4653 { &opcode_xycb_fc, 20 }, // LD H, SET 7, (IX + d)
4654 { &opcode_xycb_fd, 20 }, // LD L, SET 7, (IX + d)
4655 { &opcode_xycb_fe, 20 }, // SET 7, (IX + d)
4656 { &opcode_xycb_ff, 20 } // LD A, SET 7, (IX + d)
4659 unsigned do_opcode_xycb( unsigned xy )
4661 xy = addDispl( xy, fetchByte() );
4663 unsigned op = fetchByte();
4665 cycles_ += OpInfoXYCB_[ op ].cycles;
4667 OpInfoXYCB_[ op ].handler( xy );
4669 return xy;
4672 void opcode_xycb_00( unsigned xy ) // LD B, RLC (IX + d)
4674 B = rotateLeftCarry( readByte(xy) );
4675 writeByte( xy, B );
4678 void opcode_xycb_01( unsigned xy ) // LD C, RLC (IX + d)
4680 C = rotateLeftCarry( readByte(xy) );
4681 writeByte( xy, C );
4684 void opcode_xycb_02( unsigned xy ) // LD D, RLC (IX + d)
4686 D = rotateLeftCarry( readByte(xy) );
4687 writeByte( xy, D );
4690 void opcode_xycb_03( unsigned xy ) // LD E, RLC (IX + d)
4692 E = rotateLeftCarry( readByte(xy) );
4693 writeByte( xy, E );
4696 void opcode_xycb_04( unsigned xy ) // LD H, RLC (IX + d)
4698 H = rotateLeftCarry( readByte(xy) );
4699 writeByte( xy, H );
4702 void opcode_xycb_05( unsigned xy ) // LD L, RLC (IX + d)
4704 L = rotateLeftCarry( readByte(xy) );
4705 writeByte( xy, L );
4708 void opcode_xycb_06( unsigned xy ) // RLC (IX + d)
4710 writeByte( xy, rotateLeftCarry( readByte(xy) ) );
4713 void opcode_xycb_07( unsigned xy ) // LD A, RLC (IX + d)
4715 A = rotateLeftCarry( readByte(xy) );
4716 writeByte( xy, A );
4719 void opcode_xycb_08( unsigned xy ) // LD B, RRC (IX + d)
4721 B = rotateRightCarry( readByte(xy) );
4722 writeByte( xy, B );
4725 void opcode_xycb_09( unsigned xy ) // LD C, RRC (IX + d)
4727 C = rotateRightCarry( readByte(xy) );
4728 writeByte( xy, C );
4731 void opcode_xycb_0a( unsigned xy ) // LD D, RRC (IX + d)
4733 D = rotateRightCarry( readByte(xy) );
4734 writeByte( xy, D );
4737 void opcode_xycb_0b( unsigned xy ) // LD E, RRC (IX + d)
4739 E = rotateRightCarry( readByte(xy) );
4740 writeByte( xy, E );
4743 void opcode_xycb_0c( unsigned xy ) // LD H, RRC (IX + d)
4745 H = rotateRightCarry( readByte(xy) );
4746 writeByte( xy, H );
4749 void opcode_xycb_0d( unsigned xy ) // LD L, RRC (IX + d)
4751 L = rotateRightCarry( readByte(xy) );
4752 writeByte( xy, L );
4755 void opcode_xycb_0e( unsigned xy ) // RRC (IX + d)
4757 writeByte( xy, rotateRightCarry( readByte(xy) ) );
4760 void opcode_xycb_0f( unsigned xy ) // LD A, RRC (IX + d)
4762 A = rotateRightCarry( readByte(xy) );
4763 writeByte( xy, A );
4766 void opcode_xycb_10( unsigned xy ) // LD B, RL (IX + d)
4768 B = rotateLeft( readByte(xy) );
4769 writeByte( xy, B );
4772 void opcode_xycb_11( unsigned xy ) // LD C, RL (IX + d)
4774 C = rotateLeft( readByte(xy) );
4775 writeByte( xy, C );
4778 void opcode_xycb_12( unsigned xy ) // LD D, RL (IX + d)
4780 D = rotateLeft( readByte(xy) );
4781 writeByte( xy, D );
4784 void opcode_xycb_13( unsigned xy ) // LD E, RL (IX + d)
4786 E = rotateLeft( readByte(xy) );
4787 writeByte( xy, E );
4790 void opcode_xycb_14( unsigned xy ) // LD H, RL (IX + d)
4792 H = rotateLeft( readByte(xy) );
4793 writeByte( xy, H );
4796 void opcode_xycb_15( unsigned xy ) // LD L, RL (IX + d)
4798 L = rotateLeft( readByte(xy) );
4799 writeByte( xy, L );
4802 void opcode_xycb_16( unsigned xy ) // RL (IX + d)
4804 writeByte( xy, rotateLeft( readByte(xy) ) );
4807 void opcode_xycb_17( unsigned xy ) // LD A, RL (IX + d)
4809 A = rotateLeft( readByte(xy) );
4810 writeByte( xy, A );
4813 void opcode_xycb_18( unsigned xy ) // LD B, RR (IX + d)
4815 B = rotateRight( readByte(xy) );
4816 writeByte( xy, B );
4819 void opcode_xycb_19( unsigned xy ) // LD C, RR (IX + d)
4821 C = rotateRight( readByte(xy) );
4822 writeByte( xy, C );
4825 void opcode_xycb_1a( unsigned xy ) // LD D, RR (IX + d)
4827 D = rotateRight( readByte(xy) );
4828 writeByte( xy, D );
4831 void opcode_xycb_1b( unsigned xy ) // LD E, RR (IX + d)
4833 E = rotateRight( readByte(xy) );
4834 writeByte( xy, E );
4837 void opcode_xycb_1c( unsigned xy ) // LD H, RR (IX + d)
4839 H = rotateRight( readByte(xy) );
4840 writeByte( xy, H );
4843 void opcode_xycb_1d( unsigned xy ) // LD L, RR (IX + d)
4845 L = rotateRight( readByte(xy) );
4846 writeByte( xy, L );
4849 void opcode_xycb_1e( unsigned xy ) // RR (IX + d)
4851 writeByte( xy, rotateRight( readByte(xy) ) );
4854 void opcode_xycb_1f( unsigned xy ) // LD A, RR (IX + d)
4856 A = rotateRight( readByte(xy) );
4857 writeByte( xy, A );
4860 void opcode_xycb_20( unsigned xy ) // LD B, SLA (IX + d)
4862 B = shiftLeft( readByte(xy) );
4863 writeByte( xy, B );
4866 void opcode_xycb_21( unsigned xy ) // LD C, SLA (IX + d)
4868 C = shiftLeft( readByte(xy) );
4869 writeByte( xy, C );
4872 void opcode_xycb_22( unsigned xy ) // LD D, SLA (IX + d)
4874 D = shiftLeft( readByte(xy) );
4875 writeByte( xy, D );
4878 void opcode_xycb_23( unsigned xy ) // LD E, SLA (IX + d)
4880 E = shiftLeft( readByte(xy) );
4881 writeByte( xy, E );
4884 void opcode_xycb_24( unsigned xy ) // LD H, SLA (IX + d)
4886 H = shiftLeft( readByte(xy) );
4887 writeByte( xy, H );
4890 void opcode_xycb_25( unsigned xy ) // LD L, SLA (IX + d)
4892 L = shiftLeft( readByte(xy) );
4893 writeByte( xy, L );
4896 void opcode_xycb_26( unsigned xy ) // SLA (IX + d)
4898 writeByte( xy, shiftLeft( readByte(xy) ) );
4901 void opcode_xycb_27( unsigned xy ) // LD A, SLA (IX + d)
4903 A = shiftLeft( readByte(xy) );
4904 writeByte( xy, A );
4907 void opcode_xycb_28( unsigned xy ) // LD B, SRA (IX + d)
4909 B = shiftRightArith( readByte(xy) );
4910 writeByte( xy, B );
4913 void opcode_xycb_29( unsigned xy ) // LD C, SRA (IX + d)
4915 C = shiftRightArith( readByte(xy) );
4916 writeByte( xy, C );
4919 void opcode_xycb_2a( unsigned xy ) // LD D, SRA (IX + d)
4921 D = shiftRightArith( readByte(xy) );
4922 writeByte( xy, D );
4925 void opcode_xycb_2b( unsigned xy ) // LD E, SRA (IX + d)
4927 E = shiftRightArith( readByte(xy) );
4928 writeByte( xy, E );
4931 void opcode_xycb_2c( unsigned xy ) // LD H, SRA (IX + d)
4933 H = shiftRightArith( readByte(xy) );
4934 writeByte( xy, H );
4937 void opcode_xycb_2d( unsigned xy ) // LD L, SRA (IX + d)
4939 L = shiftRightArith( readByte(xy) );
4940 writeByte( xy, L );
4943 void opcode_xycb_2e( unsigned xy ) // SRA (IX + d)
4945 writeByte( xy, shiftRightArith( readByte(xy) ) );
4948 void opcode_xycb_2f( unsigned xy ) // LD A, SRA (IX + d)
4950 A = shiftRightArith( readByte(xy) );
4951 writeByte( xy, A );
4954 void opcode_xycb_30( unsigned xy ) // LD B, SLL (IX + d)
4956 B = shiftLeft( readByte(xy) ) | 0x01;
4957 writeByte( xy, B );
4960 void opcode_xycb_31( unsigned xy ) // LD C, SLL (IX + d)
4962 C = shiftLeft( readByte(xy) ) | 0x01;
4963 writeByte( xy, C );
4966 void opcode_xycb_32( unsigned xy ) // LD D, SLL (IX + d)
4968 D = shiftLeft( readByte(xy) ) | 0x01;
4969 writeByte( xy, D );
4972 void opcode_xycb_33( unsigned xy ) // LD E, SLL (IX + d)
4974 E = shiftLeft( readByte(xy) ) | 0x01;
4975 writeByte( xy, E );
4978 void opcode_xycb_34( unsigned xy ) // LD H, SLL (IX + d)
4980 H = shiftLeft( readByte(xy) ) | 0x01;
4981 writeByte( xy, H );
4984 void opcode_xycb_35( unsigned xy ) // LD L, SLL (IX + d)
4986 L = shiftLeft( readByte(xy) ) | 0x01;
4987 writeByte( xy, L );
4990 void opcode_xycb_36( unsigned xy ) // SLL (IX + d)
4992 writeByte( xy, shiftLeft( readByte(xy) ) | 0x01 );
4995 void opcode_xycb_37( unsigned xy ) // LD A, SLL (IX + d)
4997 A = shiftLeft( readByte(xy) ) | 0x01;
4998 writeByte( xy, A );
5001 void opcode_xycb_38( unsigned xy ) // LD B, SRL (IX + d)
5003 B = shiftRightLogical( readByte(xy) );
5004 writeByte( xy, B );
5007 void opcode_xycb_39( unsigned xy ) // LD C, SRL (IX + d)
5009 C = shiftRightLogical( readByte(xy) );
5010 writeByte( xy, C );
5013 void opcode_xycb_3a( unsigned xy ) // LD D, SRL (IX + d)
5015 D = shiftRightLogical( readByte(xy) );
5016 writeByte( xy, D );
5019 void opcode_xycb_3b( unsigned xy ) // LD E, SRL (IX + d)
5021 E = shiftRightLogical( readByte(xy) );
5022 writeByte( xy, E );
5025 void opcode_xycb_3c( unsigned xy ) // LD H, SRL (IX + d)
5027 H = shiftRightLogical( readByte(xy) );
5028 writeByte( xy, H );
5031 void opcode_xycb_3d( unsigned xy ) // LD L, SRL (IX + d)
5033 L = shiftRightLogical( readByte(xy) );
5034 writeByte( xy, L );
5037 void opcode_xycb_3e( unsigned xy ) // SRL (IX + d)
5039 writeByte( xy, shiftRightLogical( readByte(xy) ) );
5042 void opcode_xycb_3f( unsigned xy ) // LD A, SRL (IX + d)
5044 A = shiftRightLogical( readByte(xy) );
5045 writeByte( xy, A );
5048 void opcode_xycb_40( unsigned xy ) // BIT 0, (IX + d)
5050 testBit( 0, readByte( xy ) );
5053 void opcode_xycb_41( unsigned xy ) // BIT 0, (IX + d)
5055 testBit( 0, readByte( xy ) );
5058 void opcode_xycb_42( unsigned xy ) // BIT 0, (IX + d)
5060 testBit( 0, readByte( xy ) );
5063 void opcode_xycb_43( unsigned xy ) // BIT 0, (IX + d)
5065 testBit( 0, readByte( xy ) );
5068 void opcode_xycb_44( unsigned xy ) // BIT 0, (IX + d)
5070 testBit( 0, readByte( xy ) );
5073 void opcode_xycb_45( unsigned xy ) // BIT 0, (IX + d)
5075 testBit( 0, readByte( xy ) );
5078 void opcode_xycb_46( unsigned xy ) // BIT 0, (IX + d)
5080 testBit( 0, readByte( xy ) );
5083 void opcode_xycb_47( unsigned xy ) // BIT 0, (IX + d)
5085 testBit( 0, readByte( xy ) );
5088 void opcode_xycb_48( unsigned xy ) // BIT 1, (IX + d)
5090 testBit( 1, readByte( xy ) );
5093 void opcode_xycb_49( unsigned xy ) // BIT 1, (IX + d)
5095 testBit( 1, readByte( xy ) );
5098 void opcode_xycb_4a( unsigned xy ) // BIT 1, (IX + d)
5100 testBit( 1, readByte( xy ) );
5103 void opcode_xycb_4b( unsigned xy ) // BIT 1, (IX + d)
5105 testBit( 1, readByte( xy ) );
5108 void opcode_xycb_4c( unsigned xy ) // BIT 1, (IX + d)
5110 testBit( 1, readByte( xy ) );
5113 void opcode_xycb_4d( unsigned xy ) // BIT 1, (IX + d)
5115 testBit( 1, readByte( xy ) );
5118 void opcode_xycb_4e( unsigned xy ) // BIT 1, (IX + d)
5120 testBit( 1, readByte( xy ) );
5123 void opcode_xycb_4f( unsigned xy ) // BIT 1, (IX + d)
5125 testBit( 1, readByte( xy ) );
5128 void opcode_xycb_50( unsigned xy ) // BIT 2, (IX + d)
5130 testBit( 2, readByte( xy ) );
5133 void opcode_xycb_51( unsigned xy ) // BIT 2, (IX + d)
5135 testBit( 2, readByte( xy ) );
5138 void opcode_xycb_52( unsigned xy ) // BIT 2, (IX + d)
5140 testBit( 2, readByte( xy ) );
5143 void opcode_xycb_53( unsigned xy ) // BIT 2, (IX + d)
5145 testBit( 2, readByte( xy ) );
5148 void opcode_xycb_54( unsigned xy ) // BIT 2, (IX + d)
5150 testBit( 2, readByte( xy ) );
5153 void opcode_xycb_55( unsigned xy ) // BIT 2, (IX + d)
5155 testBit( 2, readByte( xy ) );
5158 void opcode_xycb_56( unsigned xy ) // BIT 2, (IX + d)
5160 testBit( 2, readByte( xy ) );
5163 void opcode_xycb_57( unsigned xy ) // BIT 2, (IX + d)
5165 testBit( 2, readByte( xy ) );
5168 void opcode_xycb_58( unsigned xy ) // BIT 3, (IX + d)
5170 testBit( 3, readByte( xy ) );
5173 void opcode_xycb_59( unsigned xy ) // BIT 3, (IX + d)
5175 testBit( 3, readByte( xy ) );
5178 void opcode_xycb_5a( unsigned xy ) // BIT 3, (IX + d)
5180 testBit( 3, readByte( xy ) );
5183 void opcode_xycb_5b( unsigned xy ) // BIT 3, (IX + d)
5185 testBit( 3, readByte( xy ) );
5188 void opcode_xycb_5c( unsigned xy ) // BIT 3, (IX + d)
5190 testBit( 3, readByte( xy ) );
5193 void opcode_xycb_5d( unsigned xy ) // BIT 3, (IX + d)
5195 testBit( 3, readByte( xy ) );
5198 void opcode_xycb_5e( unsigned xy ) // BIT 3, (IX + d)
5200 testBit( 3, readByte( xy ) );
5203 void opcode_xycb_5f( unsigned xy ) // BIT 3, (IX + d)
5205 testBit( 3, readByte( xy ) );
5208 void opcode_xycb_60( unsigned xy ) // BIT 4, (IX + d)
5210 testBit( 4, readByte( xy ) );
5213 void opcode_xycb_61( unsigned xy ) // BIT 4, (IX + d)
5215 testBit( 4, readByte( xy ) );
5218 void opcode_xycb_62( unsigned xy ) // BIT 4, (IX + d)
5220 testBit( 4, readByte( xy ) );
5223 void opcode_xycb_63( unsigned xy ) // BIT 4, (IX + d)
5225 testBit( 4, readByte( xy ) );
5228 void opcode_xycb_64( unsigned xy ) // BIT 4, (IX + d)
5230 testBit( 4, readByte( xy ) );
5233 void opcode_xycb_65( unsigned xy ) // BIT 4, (IX + d)
5235 testBit( 4, readByte( xy ) );
5238 void opcode_xycb_66( unsigned xy ) // BIT 4, (IX + d)
5240 testBit( 4, readByte( xy ) );
5243 void opcode_xycb_67( unsigned xy ) // BIT 4, (IX + d)
5245 testBit( 4, readByte( xy ) );
5248 void opcode_xycb_68( unsigned xy ) // BIT 5, (IX + d)
5250 testBit( 5, readByte( xy ) );
5253 void opcode_xycb_69( unsigned xy ) // BIT 5, (IX + d)
5255 testBit( 5, readByte( xy ) );
5258 void opcode_xycb_6a( unsigned xy ) // BIT 5, (IX + d)
5260 testBit( 5, readByte( xy ) );
5263 void opcode_xycb_6b( unsigned xy ) // BIT 5, (IX + d)
5265 testBit( 5, readByte( xy ) );
5268 void opcode_xycb_6c( unsigned xy ) // BIT 5, (IX + d)
5270 testBit( 5, readByte( xy ) );
5273 void opcode_xycb_6d( unsigned xy ) // BIT 5, (IX + d)
5275 testBit( 5, readByte( xy ) );
5278 void opcode_xycb_6e( unsigned xy ) // BIT 5, (IX + d)
5280 testBit( 5, readByte( xy ) );
5283 void opcode_xycb_6f( unsigned xy ) // BIT 5, (IX + d)
5285 testBit( 5, readByte( xy ) );
5288 void opcode_xycb_70( unsigned xy ) // BIT 6, (IX + d)
5290 testBit( 6, readByte( xy ) );
5293 void opcode_xycb_71( unsigned xy ) // BIT 6, (IX + d)
5295 testBit( 6, readByte( xy ) );
5298 void opcode_xycb_72( unsigned xy ) // BIT 6, (IX + d)
5300 testBit( 6, readByte( xy ) );
5303 void opcode_xycb_73( unsigned xy ) // BIT 6, (IX + d)
5305 testBit( 6, readByte( xy ) );
5308 void opcode_xycb_74( unsigned xy ) // BIT 6, (IX + d)
5310 testBit( 6, readByte( xy ) );
5313 void opcode_xycb_75( unsigned xy ) // BIT 6, (IX + d)
5315 testBit( 6, readByte( xy ) );
5318 void opcode_xycb_76( unsigned xy ) // BIT 6, (IX + d)
5320 testBit( 6, readByte( xy ) );
5323 void opcode_xycb_77( unsigned xy ) // BIT 6, (IX + d)
5325 testBit( 6, readByte( xy ) );
5328 void opcode_xycb_78( unsigned xy ) // BIT 7, (IX + d)
5330 testBit( 7, readByte( xy ) );
5333 void opcode_xycb_79( unsigned xy ) // BIT 7, (IX + d)
5335 testBit( 7, readByte( xy ) );
5338 void opcode_xycb_7a( unsigned xy ) // BIT 7, (IX + d)
5340 testBit( 7, readByte( xy ) );
5343 void opcode_xycb_7b( unsigned xy ) // BIT 7, (IX + d)
5345 testBit( 7, readByte( xy ) );
5348 void opcode_xycb_7c( unsigned xy ) // BIT 7, (IX + d)
5350 testBit( 7, readByte( xy ) );
5353 void opcode_xycb_7d( unsigned xy ) // BIT 7, (IX + d)
5355 testBit( 7, readByte( xy ) );
5358 void opcode_xycb_7e( unsigned xy ) // BIT 7, (IX + d)
5360 testBit( 7, readByte( xy ) );
5363 void opcode_xycb_7f( unsigned xy ) // BIT 7, (IX + d)
5365 testBit( 7, readByte( xy ) );
5368 void opcode_xycb_80( unsigned xy ) // LD B, RES 0, (IX + d)
5370 B = readByte(xy) & (unsigned char) ~(1 << 0);
5371 writeByte( xy, B );
5374 void opcode_xycb_81( unsigned xy ) // LD C, RES 0, (IX + d)
5376 C = readByte(xy) & (unsigned char) ~(1 << 0);
5377 writeByte( xy, C );
5380 void opcode_xycb_82( unsigned xy ) // LD D, RES 0, (IX + d)
5382 D = readByte(xy) & (unsigned char) ~(1 << 0);
5383 writeByte( xy, D );
5386 void opcode_xycb_83( unsigned xy ) // LD E, RES 0, (IX + d)
5388 E = readByte(xy) & (unsigned char) ~(1 << 0);
5389 writeByte( xy, E );
5392 void opcode_xycb_84( unsigned xy ) // LD H, RES 0, (IX + d)
5394 H = readByte(xy) & (unsigned char) ~(1 << 0);
5395 writeByte( xy, H );
5398 void opcode_xycb_85( unsigned xy ) // LD L, RES 0, (IX + d)
5400 L = readByte(xy) & (unsigned char) ~(1 << 0);
5401 writeByte( xy, L );
5404 void opcode_xycb_86( unsigned xy ) // RES 0, (IX + d)
5406 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 0) );
5409 void opcode_xycb_87( unsigned xy ) // LD A, RES 0, (IX + d)
5411 A = readByte(xy) & (unsigned char) ~(1 << 0);
5412 writeByte( xy, A );
5415 void opcode_xycb_88( unsigned xy ) // LD B, RES 1, (IX + d)
5417 B = readByte(xy) & (unsigned char) ~(1 << 1);
5418 writeByte( xy, B );
5421 void opcode_xycb_89( unsigned xy ) // LD C, RES 1, (IX + d)
5423 C = readByte(xy) & (unsigned char) ~(1 << 1);
5424 writeByte( xy, C );
5427 void opcode_xycb_8a( unsigned xy ) // LD D, RES 1, (IX + d)
5429 D = readByte(xy) & (unsigned char) ~(1 << 1);
5430 writeByte( xy, D );
5433 void opcode_xycb_8b( unsigned xy ) // LD E, RES 1, (IX + d)
5435 E = readByte(xy) & (unsigned char) ~(1 << 1);
5436 writeByte( xy, E );
5439 void opcode_xycb_8c( unsigned xy ) // LD H, RES 1, (IX + d)
5441 H = readByte(xy) & (unsigned char) ~(1 << 1);
5442 writeByte( xy, H );
5445 void opcode_xycb_8d( unsigned xy ) // LD L, RES 1, (IX + d)
5447 L = readByte(xy) & (unsigned char) ~(1 << 1);
5448 writeByte( xy, L );
5451 void opcode_xycb_8e( unsigned xy ) // RES 1, (IX + d)
5453 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 1) );
5456 void opcode_xycb_8f( unsigned xy ) // LD A, RES 1, (IX + d)
5458 A = readByte(xy) & (unsigned char) ~(1 << 1);
5459 writeByte( xy, A );
5462 void opcode_xycb_90( unsigned xy ) // LD B, RES 2, (IX + d)
5464 B = readByte(xy) & (unsigned char) ~(1 << 2);
5465 writeByte( xy, B );
5468 void opcode_xycb_91( unsigned xy ) // LD C, RES 2, (IX + d)
5470 C = readByte(xy) & (unsigned char) ~(1 << 2);
5471 writeByte( xy, C );
5474 void opcode_xycb_92( unsigned xy ) // LD D, RES 2, (IX + d)
5476 D = readByte(xy) & (unsigned char) ~(1 << 2);
5477 writeByte( xy, D );
5480 void opcode_xycb_93( unsigned xy ) // LD E, RES 2, (IX + d)
5482 E = readByte(xy) & (unsigned char) ~(1 << 2);
5483 writeByte( xy, E );
5486 void opcode_xycb_94( unsigned xy ) // LD H, RES 2, (IX + d)
5488 H = readByte(xy) & (unsigned char) ~(1 << 2);
5489 writeByte( xy, H );
5492 void opcode_xycb_95( unsigned xy ) // LD L, RES 2, (IX + d)
5494 L = readByte(xy) & (unsigned char) ~(1 << 2);
5495 writeByte( xy, L );
5498 void opcode_xycb_96( unsigned xy ) // RES 2, (IX + d)
5500 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 2) );
5503 void opcode_xycb_97( unsigned xy ) // LD A, RES 2, (IX + d)
5505 A = readByte(xy) & (unsigned char) ~(1 << 2);
5506 writeByte( xy, A );
5509 void opcode_xycb_98( unsigned xy ) // LD B, RES 3, (IX + d)
5511 B = readByte(xy) & (unsigned char) ~(1 << 3);
5512 writeByte( xy, B );
5515 void opcode_xycb_99( unsigned xy ) // LD C, RES 3, (IX + d)
5517 C = readByte(xy) & (unsigned char) ~(1 << 3);
5518 writeByte( xy, C );
5521 void opcode_xycb_9a( unsigned xy ) // LD D, RES 3, (IX + d)
5523 D = readByte(xy) & (unsigned char) ~(1 << 3);
5524 writeByte( xy, D );
5527 void opcode_xycb_9b( unsigned xy ) // LD E, RES 3, (IX + d)
5529 E = readByte(xy) & (unsigned char) ~(1 << 3);
5530 writeByte( xy, E );
5533 void opcode_xycb_9c( unsigned xy ) // LD H, RES 3, (IX + d)
5535 H = readByte(xy) & (unsigned char) ~(1 << 3);
5536 writeByte( xy, H );
5539 void opcode_xycb_9d( unsigned xy ) // LD L, RES 3, (IX + d)
5541 L = readByte(xy) & (unsigned char) ~(1 << 3);
5542 writeByte( xy, L );
5545 void opcode_xycb_9e( unsigned xy ) // RES 3, (IX + d)
5547 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 3) );
5550 void opcode_xycb_9f( unsigned xy ) // LD A, RES 3, (IX + d)
5552 A = readByte(xy) & (unsigned char) ~(1 << 3);
5553 writeByte( xy, A );
5556 void opcode_xycb_a0( unsigned xy ) // LD B, RES 4, (IX + d)
5558 B = readByte(xy) & (unsigned char) ~(1 << 4);
5559 writeByte( xy, B );
5562 void opcode_xycb_a1( unsigned xy ) // LD C, RES 4, (IX + d)
5564 C = readByte(xy) & (unsigned char) ~(1 << 4);
5565 writeByte( xy, C );
5568 void opcode_xycb_a2( unsigned xy ) // LD D, RES 4, (IX + d)
5570 D = readByte(xy) & (unsigned char) ~(1 << 4);
5571 writeByte( xy, D );
5574 void opcode_xycb_a3( unsigned xy ) // LD E, RES 4, (IX + d)
5576 E = readByte(xy) & (unsigned char) ~(1 << 4);
5577 writeByte( xy, E );
5580 void opcode_xycb_a4( unsigned xy ) // LD H, RES 4, (IX + d)
5582 H = readByte(xy) & (unsigned char) ~(1 << 4);
5583 writeByte( xy, H );
5586 void opcode_xycb_a5( unsigned xy ) // LD L, RES 4, (IX + d)
5588 L = readByte(xy) & (unsigned char) ~(1 << 4);
5589 writeByte( xy, L );
5592 void opcode_xycb_a6( unsigned xy ) // RES 4, (IX + d)
5594 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 4) );
5597 void opcode_xycb_a7( unsigned xy ) // LD A, RES 4, (IX + d)
5599 A = readByte(xy) & (unsigned char) ~(1 << 4);
5600 writeByte( xy, A );
5603 void opcode_xycb_a8( unsigned xy ) // LD B, RES 5, (IX + d)
5605 B = readByte(xy) & (unsigned char) ~(1 << 5);
5606 writeByte( xy, B );
5609 void opcode_xycb_a9( unsigned xy ) // LD C, RES 5, (IX + d)
5611 C = readByte(xy) & (unsigned char) ~(1 << 5);
5612 writeByte( xy, C );
5615 void opcode_xycb_aa( unsigned xy ) // LD D, RES 5, (IX + d)
5617 D = readByte(xy) & (unsigned char) ~(1 << 5);
5618 writeByte( xy, D );
5621 void opcode_xycb_ab( unsigned xy ) // LD E, RES 5, (IX + d)
5623 E = readByte(xy) & (unsigned char) ~(1 << 5);
5624 writeByte( xy, E );
5627 void opcode_xycb_ac( unsigned xy ) // LD H, RES 5, (IX + d)
5629 H = readByte(xy) & (unsigned char) ~(1 << 5);
5630 writeByte( xy, H );
5633 void opcode_xycb_ad( unsigned xy ) // LD L, RES 5, (IX + d)
5635 L = readByte(xy) & (unsigned char) ~(1 << 5);
5636 writeByte( xy, L );
5639 void opcode_xycb_ae( unsigned xy ) // RES 5, (IX + d)
5641 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 5) );
5644 void opcode_xycb_af( unsigned xy ) // LD A, RES 5, (IX + d)
5646 A = readByte(xy) & (unsigned char) ~(1 << 5);
5647 writeByte( xy, A );
5650 void opcode_xycb_b0( unsigned xy ) // LD B, RES 6, (IX + d)
5652 B = readByte(xy) & (unsigned char) ~(1 << 6);
5653 writeByte( xy, B );
5656 void opcode_xycb_b1( unsigned xy ) // LD C, RES 6, (IX + d)
5658 C = readByte(xy) & (unsigned char) ~(1 << 6);
5659 writeByte( xy, C );
5662 void opcode_xycb_b2( unsigned xy ) // LD D, RES 6, (IX + d)
5664 D = readByte(xy) & (unsigned char) ~(1 << 6);
5665 writeByte( xy, D );
5668 void opcode_xycb_b3( unsigned xy ) // LD E, RES 6, (IX + d)
5670 E = readByte(xy) & (unsigned char) ~(1 << 6);
5671 writeByte( xy, E );
5674 void opcode_xycb_b4( unsigned xy ) // LD H, RES 6, (IX + d)
5676 H = readByte(xy) & (unsigned char) ~(1 << 6);
5677 writeByte( xy, H );
5680 void opcode_xycb_b5( unsigned xy ) // LD L, RES 6, (IX + d)
5682 L = readByte(xy) & (unsigned char) ~(1 << 6);
5683 writeByte( xy, L );
5686 void opcode_xycb_b6( unsigned xy ) // RES 6, (IX + d)
5688 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 6) );
5691 void opcode_xycb_b7( unsigned xy ) // LD A, RES 6, (IX + d)
5693 A = readByte(xy) & (unsigned char) ~(1 << 6);
5694 writeByte( xy, A );
5697 void opcode_xycb_b8( unsigned xy ) // LD B, RES 7, (IX + d)
5699 B = readByte(xy) & (unsigned char) ~(1 << 7);
5700 writeByte( xy, B );
5703 void opcode_xycb_b9( unsigned xy ) // LD C, RES 7, (IX + d)
5705 C = readByte(xy) & (unsigned char) ~(1 << 7);
5706 writeByte( xy, C );
5709 void opcode_xycb_ba( unsigned xy ) // LD D, RES 7, (IX + d)
5711 D = readByte(xy) & (unsigned char) ~(1 << 7);
5712 writeByte( xy, D );
5715 void opcode_xycb_bb( unsigned xy ) // LD E, RES 7, (IX + d)
5717 E = readByte(xy) & (unsigned char) ~(1 << 7);
5718 writeByte( xy, E );
5721 void opcode_xycb_bc( unsigned xy ) // LD H, RES 7, (IX + d)
5723 H = readByte(xy) & (unsigned char) ~(1 << 7);
5724 writeByte( xy, H );
5727 void opcode_xycb_bd( unsigned xy ) // LD L, RES 7, (IX + d)
5729 L = readByte(xy) & (unsigned char) ~(1 << 7);
5730 writeByte( xy, L );
5733 void opcode_xycb_be( unsigned xy ) // RES 7, (IX + d)
5735 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 7) );
5738 void opcode_xycb_bf( unsigned xy ) // LD A, RES 7, (IX + d)
5740 A = readByte(xy) & (unsigned char) ~(1 << 7);
5741 writeByte( xy, A );
5744 void opcode_xycb_c0( unsigned xy ) // LD B, SET 0, (IX + d)
5746 B = readByte(xy) | (unsigned char) (1 << 0);
5747 writeByte( xy, B );
5750 void opcode_xycb_c1( unsigned xy ) // LD C, SET 0, (IX + d)
5752 C = readByte(xy) | (unsigned char) (1 << 0);
5753 writeByte( xy, C );
5756 void opcode_xycb_c2( unsigned xy ) // LD D, SET 0, (IX + d)
5758 D = readByte(xy) | (unsigned char) (1 << 0);
5759 writeByte( xy, D );
5762 void opcode_xycb_c3( unsigned xy ) // LD E, SET 0, (IX + d)
5764 E = readByte(xy) | (unsigned char) (1 << 0);
5765 writeByte( xy, E );
5768 void opcode_xycb_c4( unsigned xy ) // LD H, SET 0, (IX + d)
5770 H = readByte(xy) | (unsigned char) (1 << 0);
5771 writeByte( xy, H );
5774 void opcode_xycb_c5( unsigned xy ) // LD L, SET 0, (IX + d)
5776 L = readByte(xy) | (unsigned char) (1 << 0);
5777 writeByte( xy, L );
5780 void opcode_xycb_c6( unsigned xy ) // SET 0, (IX + d)
5782 writeByte( xy, readByte(xy) | (unsigned char) (1 << 0) );
5785 void opcode_xycb_c7( unsigned xy ) // LD A, SET 0, (IX + d)
5787 A = readByte(xy) | (unsigned char) (1 << 0);
5788 writeByte( xy, A );
5791 void opcode_xycb_c8( unsigned xy ) // LD B, SET 1, (IX + d)
5793 B = readByte(xy) | (unsigned char) (1 << 1);
5794 writeByte( xy, B );
5797 void opcode_xycb_c9( unsigned xy ) // LD C, SET 1, (IX + d)
5799 C = readByte(xy) | (unsigned char) (1 << 1);
5800 writeByte( xy, C );
5803 void opcode_xycb_ca( unsigned xy ) // LD D, SET 1, (IX + d)
5805 D = readByte(xy) | (unsigned char) (1 << 1);
5806 writeByte( xy, D );
5809 void opcode_xycb_cb( unsigned xy ) // LD E, SET 1, (IX + d)
5811 E = readByte(xy) | (unsigned char) (1 << 1);
5812 writeByte( xy, E );
5815 void opcode_xycb_cc( unsigned xy ) // LD H, SET 1, (IX + d)
5817 H = readByte(xy) | (unsigned char) (1 << 1);
5818 writeByte( xy, H );
5821 void opcode_xycb_cd( unsigned xy ) // LD L, SET 1, (IX + d)
5823 L = readByte(xy) | (unsigned char) (1 << 1);
5824 writeByte( xy, L );
5827 void opcode_xycb_ce( unsigned xy ) // SET 1, (IX + d)
5829 writeByte( xy, readByte(xy) | (unsigned char) (1 << 1) );
5832 void opcode_xycb_cf( unsigned xy ) // LD A, SET 1, (IX + d)
5834 A = readByte(xy) | (unsigned char) (1 << 1);
5835 writeByte( xy, A );
5838 void opcode_xycb_d0( unsigned xy ) // LD B, SET 2, (IX + d)
5840 B = readByte(xy) | (unsigned char) (1 << 2);
5841 writeByte( xy, B );
5844 void opcode_xycb_d1( unsigned xy ) // LD C, SET 2, (IX + d)
5846 C = readByte(xy) | (unsigned char) (1 << 2);
5847 writeByte( xy, C );
5850 void opcode_xycb_d2( unsigned xy ) // LD D, SET 2, (IX + d)
5852 D = readByte(xy) | (unsigned char) (1 << 2);
5853 writeByte( xy, D );
5856 void opcode_xycb_d3( unsigned xy ) // LD E, SET 2, (IX + d)
5858 E = readByte(xy) | (unsigned char) (1 << 2);
5859 writeByte( xy, E );
5862 void opcode_xycb_d4( unsigned xy ) // LD H, SET 2, (IX + d)
5864 H = readByte(xy) | (unsigned char) (1 << 2);
5865 writeByte( xy, H );
5868 void opcode_xycb_d5( unsigned xy ) // LD L, SET 2, (IX + d)
5870 L = readByte(xy) | (unsigned char) (1 << 2);
5871 writeByte( xy, L );
5874 void opcode_xycb_d6( unsigned xy ) // SET 2, (IX + d)
5876 writeByte( xy, readByte(xy) | (unsigned char) (1 << 2) );
5879 void opcode_xycb_d7( unsigned xy ) // LD A, SET 2, (IX + d)
5881 A = readByte(xy) | (unsigned char) (1 << 2);
5882 writeByte( xy, A );
5885 void opcode_xycb_d8( unsigned xy ) // LD B, SET 3, (IX + d)
5887 B = readByte(xy) | (unsigned char) (1 << 3);
5888 writeByte( xy, B );
5891 void opcode_xycb_d9( unsigned xy ) // LD C, SET 3, (IX + d)
5893 C = readByte(xy) | (unsigned char) (1 << 3);
5894 writeByte( xy, C );
5897 void opcode_xycb_da( unsigned xy ) // LD D, SET 3, (IX + d)
5899 D = readByte(xy) | (unsigned char) (1 << 3);
5900 writeByte( xy, D );
5903 void opcode_xycb_db( unsigned xy ) // LD E, SET 3, (IX + d)
5905 E = readByte(xy) | (unsigned char) (1 << 3);
5906 writeByte( xy, E );
5909 void opcode_xycb_dc( unsigned xy ) // LD H, SET 3, (IX + d)
5911 H = readByte(xy) | (unsigned char) (1 << 3);
5912 writeByte( xy, H );
5915 void opcode_xycb_dd( unsigned xy ) // LD L, SET 3, (IX + d)
5917 L = readByte(xy) | (unsigned char) (1 << 3);
5918 writeByte( xy, L );
5921 void opcode_xycb_de( unsigned xy ) // SET 3, (IX + d)
5923 writeByte( xy, readByte(xy) | (unsigned char) (1 << 3) );
5926 void opcode_xycb_df( unsigned xy ) // LD A, SET 3, (IX + d)
5928 A = readByte(xy) | (unsigned char) (1 << 3);
5929 writeByte( xy, A );
5932 void opcode_xycb_e0( unsigned xy ) // LD B, SET 4, (IX + d)
5934 B = readByte(xy) | (unsigned char) (1 << 4);
5935 writeByte( xy, B );
5938 void opcode_xycb_e1( unsigned xy ) // LD C, SET 4, (IX + d)
5940 C = readByte(xy) | (unsigned char) (1 << 4);
5941 writeByte( xy, C );
5944 void opcode_xycb_e2( unsigned xy ) // LD D, SET 4, (IX + d)
5946 D = readByte(xy) | (unsigned char) (1 << 4);
5947 writeByte( xy, D );
5950 void opcode_xycb_e3( unsigned xy ) // LD E, SET 4, (IX + d)
5952 E = readByte(xy) | (unsigned char) (1 << 4);
5953 writeByte( xy, E );
5956 void opcode_xycb_e4( unsigned xy ) // LD H, SET 4, (IX + d)
5958 H = readByte(xy) | (unsigned char) (1 << 4);
5959 writeByte( xy, H );
5962 void opcode_xycb_e5( unsigned xy ) // LD L, SET 4, (IX + d)
5964 L = readByte(xy) | (unsigned char) (1 << 4);
5965 writeByte( xy, L );
5968 void opcode_xycb_e6( unsigned xy ) // SET 4, (IX + d)
5970 writeByte( xy, readByte(xy) | (unsigned char) (1 << 4) );
5973 void opcode_xycb_e7( unsigned xy ) // LD A, SET 4, (IX + d)
5975 A = readByte(xy) | (unsigned char) (1 << 4);
5976 writeByte( xy, A );
5979 void opcode_xycb_e8( unsigned xy ) // LD B, SET 5, (IX + d)
5981 B = readByte(xy) | (unsigned char) (1 << 5);
5982 writeByte( xy, B );
5985 void opcode_xycb_e9( unsigned xy ) // LD C, SET 5, (IX + d)
5987 C = readByte(xy) | (unsigned char) (1 << 5);
5988 writeByte( xy, C );
5991 void opcode_xycb_ea( unsigned xy ) // LD D, SET 5, (IX + d)
5993 D = readByte(xy) | (unsigned char) (1 << 5);
5994 writeByte( xy, D );
5997 void opcode_xycb_eb( unsigned xy ) // LD E, SET 5, (IX + d)
5999 E = readByte(xy) | (unsigned char) (1 << 5);
6000 writeByte( xy, E );
6003 void opcode_xycb_ec( unsigned xy ) // LD H, SET 5, (IX + d)
6005 H = readByte(xy) | (unsigned char) (1 << 5);
6006 writeByte( xy, H );
6009 void opcode_xycb_ed( unsigned xy ) // LD L, SET 5, (IX + d)
6011 L = readByte(xy) | (unsigned char) (1 << 5);
6012 writeByte( xy, L );
6015 void opcode_xycb_ee( unsigned xy ) // SET 5, (IX + d)
6017 writeByte( xy, readByte(xy) | (unsigned char) (1 << 5) );
6020 void opcode_xycb_ef( unsigned xy ) // LD A, SET 5, (IX + d)
6022 A = readByte(xy) | (unsigned char) (1 << 5);
6023 writeByte( xy, A );
6026 void opcode_xycb_f0( unsigned xy ) // LD B, SET 6, (IX + d)
6028 B = readByte(xy) | (unsigned char) (1 << 6);
6029 writeByte( xy, B );
6032 void opcode_xycb_f1( unsigned xy ) // LD C, SET 6, (IX + d)
6034 C = readByte(xy) | (unsigned char) (1 << 6);
6035 writeByte( xy, C );
6038 void opcode_xycb_f2( unsigned xy ) // LD D, SET 6, (IX + d)
6040 D = readByte(xy) | (unsigned char) (1 << 6);
6041 writeByte( xy, D );
6044 void opcode_xycb_f3( unsigned xy ) // LD E, SET 6, (IX + d)
6046 E = readByte(xy) | (unsigned char) (1 << 6);
6047 writeByte( xy, E );
6050 void opcode_xycb_f4( unsigned xy ) // LD H, SET 6, (IX + d)
6052 H = readByte(xy) | (unsigned char) (1 << 6);
6053 writeByte( xy, H );
6056 void opcode_xycb_f5( unsigned xy ) // LD L, SET 6, (IX + d)
6058 L = readByte(xy) | (unsigned char) (1 << 6);
6059 writeByte( xy, L );
6062 void opcode_xycb_f6( unsigned xy ) // SET 6, (IX + d)
6064 writeByte( xy, readByte(xy) | (unsigned char) (1 << 6) );
6067 void opcode_xycb_f7( unsigned xy ) // LD A, SET 6, (IX + d)
6069 A = readByte(xy) | (unsigned char) (1 << 6);
6070 writeByte( xy, A );
6073 void opcode_xycb_f8( unsigned xy ) // LD B, SET 7, (IX + d)
6075 B = readByte(xy) | (unsigned char) (1 << 7);
6076 writeByte( xy, B );
6079 void opcode_xycb_f9( unsigned xy ) // LD C, SET 7, (IX + d)
6081 C = readByte(xy) | (unsigned char) (1 << 7);
6082 writeByte( xy, C );
6085 void opcode_xycb_fa( unsigned xy ) // LD D, SET 7, (IX + d)
6087 D = readByte(xy) | (unsigned char) (1 << 7);
6088 writeByte( xy, D );
6091 void opcode_xycb_fb( unsigned xy ) // LD E, SET 7, (IX + d)
6093 E = readByte(xy) | (unsigned char) (1 << 7);
6094 writeByte( xy, E );
6097 void opcode_xycb_fc( unsigned xy ) // LD H, SET 7, (IX + d)
6099 H = readByte(xy) | (unsigned char) (1 << 7);
6100 writeByte( xy, H );
6103 void opcode_xycb_fd( unsigned xy ) // LD L, SET 7, (IX + d)
6105 L = readByte(xy) | (unsigned char) (1 << 7);
6106 writeByte( xy, L );
6109 void opcode_xycb_fe( unsigned xy ) // SET 7, (IX + d)
6111 writeByte( xy, readByte(xy) | (unsigned char) (1 << 7) );
6114 void opcode_xycb_ff( unsigned xy ) // LD A, SET 7, (IX + d)
6116 A = readByte(xy) | (unsigned char) (1 << 7);
6117 writeByte( xy, A );
6120 OpcodeInfo OpInfo_[256] = {
6121 { &opcode_00, 4 }, // NOP
6122 { &opcode_01, 10 }, // LD BC,nn
6123 { &opcode_02, 7 }, // LD (BC),A
6124 { &opcode_03, 6 }, // INC BC
6125 { &opcode_04, 4 }, // INC B
6126 { &opcode_05, 4 }, // DEC B
6127 { &opcode_06, 7 }, // LD B,n
6128 { &opcode_07, 4 }, // RLCA
6129 { &opcode_08, 4 }, // EX AF,AF'
6130 { &opcode_09, 11 }, // ADD HL,BC
6131 { &opcode_0a, 7 }, // LD A,(BC)
6132 { &opcode_0b, 6 }, // DEC BC
6133 { &opcode_0c, 4 }, // INC C
6134 { &opcode_0d, 4 }, // DEC C
6135 { &opcode_0e, 7 }, // LD C,n
6136 { &opcode_0f, 4 }, // RRCA
6137 { &opcode_10, 8 }, // DJNZ d
6138 { &opcode_11, 10 }, // LD DE,nn
6139 { &opcode_12, 7 }, // LD (DE),A
6140 { &opcode_13, 6 }, // INC DE
6141 { &opcode_14, 4 }, // INC D
6142 { &opcode_15, 4 }, // DEC D
6143 { &opcode_16, 7 }, // LD D,n
6144 { &opcode_17, 4 }, // RLA
6145 { &opcode_18, 12 }, // JR d
6146 { &opcode_19, 11 }, // ADD HL,DE
6147 { &opcode_1a, 7 }, // LD A,(DE)
6148 { &opcode_1b, 6 }, // DEC DE
6149 { &opcode_1c, 4 }, // INC E
6150 { &opcode_1d, 4 }, // DEC E
6151 { &opcode_1e, 7 }, // LD E,n
6152 { &opcode_1f, 4 }, // RRA
6153 { &opcode_20, 7 }, // JR NZ,d
6154 { &opcode_21, 10 }, // LD HL,nn
6155 { &opcode_22, 16 }, // LD (nn),HL
6156 { &opcode_23, 6 }, // INC HL
6157 { &opcode_24, 4 }, // INC H
6158 { &opcode_25, 4 }, // DEC H
6159 { &opcode_26, 7 }, // LD H,n
6160 { &opcode_27, 4 }, // DAA
6161 { &opcode_28, 7 }, // JR Z,d
6162 { &opcode_29, 11 }, // ADD HL,HL
6163 { &opcode_2a, 16 }, // LD HL,(nn)
6164 { &opcode_2b, 6 }, // DEC HL
6165 { &opcode_2c, 4 }, // INC L
6166 { &opcode_2d, 4 }, // DEC L
6167 { &opcode_2e, 7 }, // LD L,n
6168 { &opcode_2f, 4 }, // CPL
6169 { &opcode_30, 7 }, // JR NC,d
6170 { &opcode_31, 10 }, // LD SP,nn
6171 { &opcode_32, 13 }, // LD (nn),A
6172 { &opcode_33, 6 }, // INC SP
6173 { &opcode_34, 11 }, // INC (HL)
6174 { &opcode_35, 11 }, // DEC (HL)
6175 { &opcode_36, 10 }, // LD (HL),n
6176 { &opcode_37, 4 }, // SCF
6177 { &opcode_38, 7 }, // JR C,d
6178 { &opcode_39, 11 }, // ADD HL,SP
6179 { &opcode_3a, 13 }, // LD A,(nn)
6180 { &opcode_3b, 6 }, // DEC SP
6181 { &opcode_3c, 4 }, // INC A
6182 { &opcode_3d, 4 }, // DEC A
6183 { &opcode_3e, 7 }, // LD A,n
6184 { &opcode_3f, 4 }, // CCF
6185 { &opcode_40, 4 }, // LD B,B
6186 { &opcode_41, 4 }, // LD B,C
6187 { &opcode_42, 4 }, // LD B,D
6188 { &opcode_43, 4 }, // LD B,E
6189 { &opcode_44, 4 }, // LD B,H
6190 { &opcode_45, 4 }, // LD B,L
6191 { &opcode_46, 7 }, // LD B,(HL)
6192 { &opcode_47, 4 }, // LD B,A
6193 { &opcode_48, 4 }, // LD C,B
6194 { &opcode_49, 4 }, // LD C,C
6195 { &opcode_4a, 4 }, // LD C,D
6196 { &opcode_4b, 4 }, // LD C,E
6197 { &opcode_4c, 4 }, // LD C,H
6198 { &opcode_4d, 4 }, // LD C,L
6199 { &opcode_4e, 7 }, // LD C,(HL)
6200 { &opcode_4f, 4 }, // LD C,A
6201 { &opcode_50, 4 }, // LD D,B
6202 { &opcode_51, 4 }, // LD D,C
6203 { &opcode_52, 4 }, // LD D,D
6204 { &opcode_53, 4 }, // LD D,E
6205 { &opcode_54, 4 }, // LD D,H
6206 { &opcode_55, 4 }, // LD D,L
6207 { &opcode_56, 7 }, // LD D,(HL)
6208 { &opcode_57, 4 }, // LD D,A
6209 { &opcode_58, 4 }, // LD E,B
6210 { &opcode_59, 4 }, // LD E,C
6211 { &opcode_5a, 4 }, // LD E,D
6212 { &opcode_5b, 4 }, // LD E,E
6213 { &opcode_5c, 4 }, // LD E,H
6214 { &opcode_5d, 4 }, // LD E,L
6215 { &opcode_5e, 7 }, // LD E,(HL)
6216 { &opcode_5f, 4 }, // LD E,A
6217 { &opcode_60, 4 }, // LD H,B
6218 { &opcode_61, 4 }, // LD H,C
6219 { &opcode_62, 4 }, // LD H,D
6220 { &opcode_63, 4 }, // LD H,E
6221 { &opcode_64, 4 }, // LD H,H
6222 { &opcode_65, 4 }, // LD H,L
6223 { &opcode_66, 7 }, // LD H,(HL)
6224 { &opcode_67, 4 }, // LD H,A
6225 { &opcode_68, 4 }, // LD L,B
6226 { &opcode_69, 4 }, // LD L,C
6227 { &opcode_6a, 4 }, // LD L,D
6228 { &opcode_6b, 4 }, // LD L,E
6229 { &opcode_6c, 4 }, // LD L,H
6230 { &opcode_6d, 4 }, // LD L,L
6231 { &opcode_6e, 7 }, // LD L,(HL)
6232 { &opcode_6f, 4 }, // LD L,A
6233 { &opcode_70, 7 }, // LD (HL),B
6234 { &opcode_71, 7 }, // LD (HL),C
6235 { &opcode_72, 7 }, // LD (HL),D
6236 { &opcode_73, 7 }, // LD (HL),E
6237 { &opcode_74, 7 }, // LD (HL),H
6238 { &opcode_75, 7 }, // LD (HL),L
6239 { &opcode_76, 4 }, // HALT
6240 { &opcode_77, 7 }, // LD (HL),A
6241 { &opcode_78, 4 }, // LD A,B
6242 { &opcode_79, 4 }, // LD A,C
6243 { &opcode_7a, 4 }, // LD A,D
6244 { &opcode_7b, 4 }, // LD A,E
6245 { &opcode_7c, 4 }, // LD A,H
6246 { &opcode_7d, 4 }, // LD A,L
6247 { &opcode_7e, 7 }, // LD A,(HL)
6248 { &opcode_7f, 4 }, // LD A,A
6249 { &opcode_80, 4 }, // ADD A,B
6250 { &opcode_81, 4 }, // ADD A,C
6251 { &opcode_82, 4 }, // ADD A,D
6252 { &opcode_83, 4 }, // ADD A,E
6253 { &opcode_84, 4 }, // ADD A,H
6254 { &opcode_85, 4 }, // ADD A,L
6255 { &opcode_86, 7 }, // ADD A,(HL)
6256 { &opcode_87, 4 }, // ADD A,A
6257 { &opcode_88, 4 }, // ADC A,B
6258 { &opcode_89, 4 }, // ADC A,C
6259 { &opcode_8a, 4 }, // ADC A,D
6260 { &opcode_8b, 4 }, // ADC A,E
6261 { &opcode_8c, 4 }, // ADC A,H
6262 { &opcode_8d, 4 }, // ADC A,L
6263 { &opcode_8e, 7 }, // ADC A,(HL)
6264 { &opcode_8f, 4 }, // ADC A,A
6265 { &opcode_90, 4 }, // SUB B
6266 { &opcode_91, 4 }, // SUB C
6267 { &opcode_92, 4 }, // SUB D
6268 { &opcode_93, 4 }, // SUB E
6269 { &opcode_94, 4 }, // SUB H
6270 { &opcode_95, 4 }, // SUB L
6271 { &opcode_96, 7 }, // SUB (HL)
6272 { &opcode_97, 4 }, // SUB A
6273 { &opcode_98, 4 }, // SBC A,B
6274 { &opcode_99, 4 }, // SBC A,C
6275 { &opcode_9a, 4 }, // SBC A,D
6276 { &opcode_9b, 4 }, // SBC A,E
6277 { &opcode_9c, 4 }, // SBC A,H
6278 { &opcode_9d, 4 }, // SBC A,L
6279 { &opcode_9e, 7 }, // SBC A,(HL)
6280 { &opcode_9f, 4 }, // SBC A,A
6281 { &opcode_a0, 4 }, // AND B
6282 { &opcode_a1, 4 }, // AND C
6283 { &opcode_a2, 4 }, // AND D
6284 { &opcode_a3, 4 }, // AND E
6285 { &opcode_a4, 4 }, // AND H
6286 { &opcode_a5, 4 }, // AND L
6287 { &opcode_a6, 7 }, // AND (HL)
6288 { &opcode_a7, 4 }, // AND A
6289 { &opcode_a8, 4 }, // XOR B
6290 { &opcode_a9, 4 }, // XOR C
6291 { &opcode_aa, 4 }, // XOR D
6292 { &opcode_ab, 4 }, // XOR E
6293 { &opcode_ac, 4 }, // XOR H
6294 { &opcode_ad, 4 }, // XOR L
6295 { &opcode_ae, 7 }, // XOR (HL)
6296 { &opcode_af, 4 }, // XOR A
6297 { &opcode_b0, 4 }, // OR B
6298 { &opcode_b1, 4 }, // OR C
6299 { &opcode_b2, 4 }, // OR D
6300 { &opcode_b3, 4 }, // OR E
6301 { &opcode_b4, 4 }, // OR H
6302 { &opcode_b5, 4 }, // OR L
6303 { &opcode_b6, 7 }, // OR (HL)
6304 { &opcode_b7, 4 }, // OR A
6305 { &opcode_b8, 4 }, // CP B
6306 { &opcode_b9, 4 }, // CP C
6307 { &opcode_ba, 4 }, // CP D
6308 { &opcode_bb, 4 }, // CP E
6309 { &opcode_bc, 4 }, // CP H
6310 { &opcode_bd, 4 }, // CP L
6311 { &opcode_be, 7 }, // CP (HL)
6312 { &opcode_bf, 4 }, // CP A
6313 { &opcode_c0, 5 }, // RET NZ
6314 { &opcode_c1, 10 }, // POP BC
6315 { &opcode_c2, 10 }, // JP NZ,nn
6316 { &opcode_c3, 10 }, // JP nn
6317 { &opcode_c4, 10 }, // CALL NZ,nn
6318 { &opcode_c5, 11 }, // PUSH BC
6319 { &opcode_c6, 7 }, // ADD A,n
6320 { &opcode_c7, 11 }, // RST 0
6321 { &opcode_c8, 5 }, // RET Z
6322 { &opcode_c9, 10 }, // RET
6323 { &opcode_ca, 10 }, // JP Z,nn
6324 { &opcode_cb, 0 }, // [Prefix]
6325 { &opcode_cc, 10 }, // CALL Z,nn
6326 { &opcode_cd, 17 }, // CALL nn
6327 { &opcode_ce, 7 }, // ADC A,n
6328 { &opcode_cf, 11 }, // RST 8
6329 { &opcode_d0, 5 }, // RET NC
6330 { &opcode_d1, 10 }, // POP DE
6331 { &opcode_d2, 10 }, // JP NC,nn
6332 { &opcode_d3, 11 }, // OUT (n),A
6333 { &opcode_d4, 10 }, // CALL NC,nn
6334 { &opcode_d5, 11 }, // PUSH DE
6335 { &opcode_d6, 7 }, // SUB n
6336 { &opcode_d7, 11 }, // RST 10H
6337 { &opcode_d8, 5 }, // RET C
6338 { &opcode_d9, 4 }, // EXX
6339 { &opcode_da, 10 }, // JP C,nn
6340 { &opcode_db, 11 }, // IN A,(n)
6341 { &opcode_dc, 10 }, // CALL C,nn
6342 { &opcode_dd, 0 }, // [IX Prefix]
6343 { &opcode_de, 7 }, // SBC A,n
6344 { &opcode_df, 11 }, // RST 18H
6345 { &opcode_e0, 5 }, // RET PO
6346 { &opcode_e1, 10 }, // POP HL
6347 { &opcode_e2, 10 }, // JP PO,nn
6348 { &opcode_e3, 19 }, // EX (SP),HL
6349 { &opcode_e4, 10 }, // CALL PO,nn
6350 { &opcode_e5, 11 }, // PUSH HL
6351 { &opcode_e6, 7 }, // AND n
6352 { &opcode_e7, 11 }, // RST 20H
6353 { &opcode_e8, 5 }, // RET PE
6354 { &opcode_e9, 4 }, // JP (HL)
6355 { &opcode_ea, 10 }, // JP PE,nn
6356 { &opcode_eb, 4 }, // EX DE,HL
6357 { &opcode_ec, 10 }, // CALL PE,nn
6358 { &opcode_ed, 0 }, // [Prefix]
6359 { &opcode_ee, 7 }, // XOR n
6360 { &opcode_ef, 11 }, // RST 28H
6361 { &opcode_f0, 5 }, // RET P
6362 { &opcode_f1, 10 }, // POP AF
6363 { &opcode_f2, 10 }, // JP P,nn
6364 { &opcode_f3, 4 }, // DI
6365 { &opcode_f4, 10 }, // CALL P,nn
6366 { &opcode_f5, 11 }, // PUSH AF
6367 { &opcode_f6, 7 }, // OR n
6368 { &opcode_f7, 11 }, // RST 30H
6369 { &opcode_f8, 5 }, // RET M
6370 { &opcode_f9, 6 }, // LD SP,HL
6371 { &opcode_fa, 10 }, // JP M,nn
6372 { &opcode_fb, 4 }, // EI
6373 { &opcode_fc, 10 }, // CALL M,nn
6374 { &opcode_fd, 0 }, // [IY Prefix]
6375 { &opcode_fe, 7 }, // CP n
6376 { &opcode_ff, 11 } // RST 38H
6379 void opcode_00() // NOP
6383 void opcode_01() // LD BC,nn
6385 C = fetchByte();
6386 B = fetchByte();
6389 void opcode_02() // LD (BC),A
6391 writeByte( BC(), A );
6394 void opcode_03() // INC BC
6396 if( ++C == 0 ) ++B;
6399 void opcode_04() // INC B
6401 B = incByte( B );
6404 void opcode_05() // DEC B
6406 B = decByte( B );
6409 void opcode_06() // LD B,n
6411 B = fetchByte();
6414 void opcode_07() // RLCA
6416 A = (A << 1) | (A >> 7);
6417 F = F & ~(AddSub | Halfcarry | Carry);
6418 if( A & 0x01 ) F |= Carry;
6421 void opcode_08() // EX AF,AF'
6423 unsigned char x;
6425 x = A; A = A1; A1 = x;
6426 x = F; F = F1; F1 = x;
6429 void opcode_09() // ADD HL,BC
6431 unsigned hl = HL();
6432 unsigned rp = BC();
6433 unsigned x = hl + rp;
6435 F &= Sign | Zero | Parity;
6436 if( x > 0xFFFF ) F |= Carry;
6437 if( ((hl & 0xFFF) + (rp & 0xFFF)) > 0xFFF ) F |= Halfcarry;
6439 L = x & 0xFF;
6440 H = (x >> 8) & 0xFF;
6443 void opcode_0a() // LD A,(BC)
6445 A = readByte( BC() );
6448 void opcode_0b() // DEC BC
6450 if( C-- == 0 ) --B;
6453 void opcode_0c() // INC C
6455 C = incByte( C );
6458 void opcode_0d() // DEC C
6460 C = decByte( C );
6463 void opcode_0e() // LD C,n
6465 C = fetchByte();
6468 void opcode_0f() // RRCA
6470 A = (A >> 1) | (A << 7);
6471 F = F & ~(AddSub | Halfcarry | Carry);
6472 if( A & 0x80 ) F |= Carry;
6475 void opcode_10() // DJNZ d
6477 unsigned char o = fetchByte();
6479 if( --B != 0 ) relJump( o );
6482 void opcode_11() // LD DE,nn
6484 E = fetchByte();
6485 D = fetchByte();
6488 void opcode_12() // LD (DE),A
6490 writeByte( DE(), A );
6493 void opcode_13() // INC DE
6495 if( ++E == 0 ) ++D;
6498 void opcode_14() // INC D
6500 D = incByte( D );
6503 void opcode_15() // DEC D
6505 D = decByte( D );
6508 void opcode_16() // LD D,n
6510 D = fetchByte();
6513 void opcode_17() // RLA
6515 unsigned char a = A;
6517 A <<= 1;
6518 if( F & Carry ) A |= 0x01;
6519 F = F & ~(AddSub | Halfcarry | Carry);
6520 if( a & 0x80 ) F |= Carry;
6523 void opcode_18() // JR d
6525 relJump( fetchByte() );
6528 void opcode_19() // ADD HL,DE
6530 unsigned hl = HL();
6531 unsigned rp = DE();
6532 unsigned x = hl + rp;
6534 F &= Sign | Zero | Parity;
6535 if( x > 0xFFFF ) F |= Carry;
6536 if( ((hl & 0xFFF) + (rp & 0xFFF)) > 0xFFF ) F |= Halfcarry;
6538 L = x & 0xFF;
6539 H = (x >> 8) & 0xFF;
6542 void opcode_1a() // LD A,(DE)
6544 A = readByte( DE() );
6547 void opcode_1b() // DEC DE
6549 if( E-- == 0 ) --D;
6552 void opcode_1c() // INC E
6554 E = incByte( E );
6557 void opcode_1d() // DEC E
6559 E = decByte( E );
6562 void opcode_1e() // LD E,n
6564 E = fetchByte();
6567 void opcode_1f() // RRA
6569 unsigned char a = A;
6571 A >>= 1;
6572 if( F & Carry ) A |= 0x80;
6573 F = F & ~(AddSub | Halfcarry | Carry);
6574 if( a & 0x01 ) F |= Carry;
6577 void opcode_20() // JR NZ,d
6579 unsigned char o = fetchByte();
6581 if( ! (F & Zero) ) relJump( o );
6584 void opcode_21() // LD HL,nn
6586 L = fetchByte();
6587 H = fetchByte();
6590 void opcode_22() // LD (nn),HL
6592 unsigned x = fetchWord();
6594 writeByte( x , L );
6595 writeByte( x+1, H );
6598 void opcode_23() // INC HL
6600 if( ++L == 0 ) ++H;
6603 void opcode_24() // INC H
6605 H = incByte( H );
6608 void opcode_25() // DEC H
6610 H = decByte( H );
6613 void opcode_26() // LD H,n
6615 H = fetchByte();
6619 DAA is computed using the following table to get a diff value
6620 that is added to or subtracted (according to the N flag) from A:
6622 C Upper H Lower Diff
6623 -+-----+-+-----+----
6624 1 * 0 0-9 60
6625 1 * 1 0-9 66
6626 1 * * A-F 66
6627 0 0-9 0 0-9 00
6628 0 0-9 1 0-9 06
6629 0 0-8 * A-F 06
6630 0 A-F 0 0-9 60
6631 0 9-F * A-F 66
6632 0 A-F 1 0-9 66
6634 The carry and halfcarry flags are then updated using similar tables.
6636 These tables were found by Stefano Donati of Ramsoft and are
6637 published in the "Undocumented Z80 Documented" paper by Sean Young,
6638 the following is an algorithmical implementation with no lookups.
6640 void opcode_27() // DAA
6642 unsigned char diff;
6643 unsigned char hf = F & Halfcarry;
6644 unsigned char cf = F & Carry;
6645 unsigned char lower = A & 0x0F;
6647 if( cf ) {
6648 diff = (lower >= 0x0A) || hf ? 0x66 : 0x60;
6650 else {
6651 diff = (A >= 0x9A) ? 0x60 : 0x00;
6653 if( hf || (lower >= 0x0A) ) diff += 0x06;
6656 if( A >= 0x9A ) cf = Carry;
6658 if( F & Subtraction ) {
6659 A -= diff;
6660 F = PSZ_[A] | Subtraction | cf;
6661 if( hf && (lower <= 0x05) ) F |= Halfcarry;
6663 else {
6664 A += diff;
6665 F = PSZ_[A] | cf;
6666 if( lower >= 0x0A ) F |= Halfcarry;
6670 void opcode_28() // JR Z,d
6672 unsigned char o = fetchByte();
6674 if( F & Zero ) relJump( o );
6677 void opcode_29() // ADD HL,HL
6679 unsigned hl = HL();
6680 unsigned rp = hl;
6681 unsigned x = hl + rp;
6683 F &= Sign | Zero | Parity;
6684 if( x > 0xFFFF ) F |= Carry;
6685 if( ((hl & 0xFFF) + (rp & 0xFFF)) > 0xFFF ) F |= Halfcarry;
6687 L = x & 0xFF;
6688 H = (x >> 8) & 0xFF;
6691 void opcode_2a() // LD HL,(nn)
6693 unsigned x = fetchWord();
6695 L = readByte( x );
6696 H = readByte( x+1 );
6699 void opcode_2b() // DEC HL
6701 if( L-- == 0 ) --H;
6704 void opcode_2c() // INC L
6706 L = incByte( L );
6709 void opcode_2d() // DEC L
6711 L = decByte( L );
6714 void opcode_2e() // LD L,n
6716 L = fetchByte();
6719 void opcode_2f() // CPL
6721 A ^= 0xFF;
6722 F |= AddSub | Halfcarry;
6725 void opcode_30() // JR NC,d
6727 unsigned char o = fetchByte();
6729 if( ! (F & Carry) ) relJump( o );
6732 void opcode_31() // LD SP,nn
6734 SP = fetchWord();
6737 void opcode_32() // LD (nn),A
6739 writeByte( fetchWord(), A );
6742 void opcode_33() // INC SP
6744 SP = (SP + 1) & 0xFFFF;
6747 void opcode_34() // INC (HL)
6749 writeByte( HL(), incByte( readByte( HL() ) ) );
6752 void opcode_35() // DEC (HL)
6754 writeByte( HL(), decByte( readByte( HL() ) ) );
6757 void opcode_36() // LD (HL),n
6759 writeByte( HL(), fetchByte() );
6762 void opcode_37() // SCF
6764 F = (F & (Parity | Sign | Zero)) | Carry;
6767 void opcode_38() // JR C,d
6769 unsigned char o = fetchByte();
6771 if( F & Carry ) relJump( o );
6774 void opcode_39() // ADD HL,SP
6776 unsigned hl = HL();
6777 unsigned rp = SP;
6778 unsigned x = hl + rp;
6780 F &= Sign | Zero | Parity;
6781 if( x > 0xFFFF ) F |= Carry;
6782 if( ((hl & 0xFFF) + (rp & 0xFFF)) > 0xFFF ) F |= Halfcarry;
6784 L = x & 0xFF;
6785 H = (x >> 8) & 0xFF;
6788 void opcode_3a() // LD A,(nn)
6790 A = readByte( fetchWord() );
6793 void opcode_3b() // DEC SP
6795 SP = (SP - 1) & 0xFFFF;
6798 void opcode_3c() // INC A
6800 A = incByte( A );
6803 void opcode_3d() // DEC A
6805 A = decByte( A );
6808 void opcode_3e() // LD A,n
6810 A = fetchByte();
6813 void opcode_3f() // CCF
6815 if( F & Carry ) {
6816 F = (F & (Parity | Sign | Zero)) | Halfcarry; // Halfcarry holds previous carry
6818 else {
6819 F = (F & (Parity | Sign | Zero)) | Carry;
6823 void opcode_40() // LD B,B
6827 void opcode_41() // LD B,C
6829 B = C;
6832 void opcode_42() // LD B,D
6834 B = D;
6837 void opcode_43() // LD B,E
6839 B = E;
6842 void opcode_44() // LD B,H
6844 B = H;
6847 void opcode_45() // LD B,L
6849 B = L;
6852 void opcode_46() // LD B,(HL)
6854 B = readByte( HL() );
6857 void opcode_47() // LD B,A
6859 B = A;
6862 void opcode_48() // LD C,B
6864 C = B;
6867 void opcode_49() // LD C,C
6871 void opcode_4a() // LD C,D
6873 C = D;
6876 void opcode_4b() // LD C,E
6878 C = E;
6881 void opcode_4c() // LD C,H
6883 C = H;
6886 void opcode_4d() // LD C,L
6888 C = L;
6891 void opcode_4e() // LD C,(HL)
6893 C = readByte( HL() );
6896 void opcode_4f() // LD C,A
6898 C = A;
6901 void opcode_50() // LD D,B
6903 D = B;
6906 void opcode_51() // LD D,C
6908 D = C;
6911 void opcode_52() // LD D,D
6915 void opcode_53() // LD D,E
6917 D = E;
6920 void opcode_54() // LD D,H
6922 D = H;
6925 void opcode_55() // LD D,L
6927 D = L;
6930 void opcode_56() // LD D,(HL)
6932 D = readByte( HL() );
6935 void opcode_57() // LD D,A
6937 D = A;
6940 void opcode_58() // LD E,B
6942 E = B;
6945 void opcode_59() // LD E,C
6947 E = C;
6950 void opcode_5a() // LD E,D
6952 E = D;
6955 void opcode_5b() // LD E,E
6959 void opcode_5c() // LD E,H
6961 E = H;
6964 void opcode_5d() // LD E,L
6966 E = L;
6969 void opcode_5e() // LD E,(HL)
6971 E = readByte( HL() );
6974 void opcode_5f() // LD E,A
6976 E = A;
6979 void opcode_60() // LD H,B
6981 H = B;
6984 void opcode_61() // LD H,C
6986 H = C;
6989 void opcode_62() // LD H,D
6991 H = D;
6994 void opcode_63() // LD H,E
6996 H = E;
6999 void opcode_64() // LD H,H
7003 void opcode_65() // LD H,L
7005 H = L;
7008 void opcode_66() // LD H,(HL)
7010 H = readByte( HL() );
7013 void opcode_67() // LD H,A
7015 H = A;
7018 void opcode_68() // LD L,B
7020 L = B;
7023 void opcode_69() // LD L,C
7025 L = C;
7028 void opcode_6a() // LD L,D
7030 L = D;
7033 void opcode_6b() // LD L,E
7035 L = E;
7038 void opcode_6c() // LD L,H
7040 L = H;
7043 void opcode_6d() // LD L,L
7047 void opcode_6e() // LD L,(HL)
7049 L = readByte( HL() );
7052 void opcode_6f() // LD L,A
7054 L = A;
7057 void opcode_70() // LD (HL),B
7059 writeByte( HL(), B );
7062 void opcode_71() // LD (HL),C
7064 writeByte( HL(), C );
7067 void opcode_72() // LD (HL),D
7069 writeByte( HL(), D );
7072 void opcode_73() // LD (HL),E
7074 writeByte( HL(), E );
7077 void opcode_74() // LD (HL),H
7079 writeByte( HL(), H );
7082 void opcode_75() // LD (HL),L
7084 writeByte( HL(), L );
7087 void opcode_76() // HALT
7089 iflags_ |= Halted;
7092 void opcode_77() // LD (HL),A
7094 writeByte( HL(), A );
7097 void opcode_78() // LD A,B
7099 A = B;
7102 void opcode_79() // LD A,C
7104 A = C;
7107 void opcode_7a() // LD A,D
7109 A = D;
7112 void opcode_7b() // LD A,E
7114 A = E;
7117 void opcode_7c() // LD A,H
7119 A = H;
7122 void opcode_7d() // LD A,L
7124 A = L;
7127 void opcode_7e() // LD A,(HL)
7129 A = readByte( HL() );
7132 void opcode_7f() // LD A,A
7136 void opcode_80() // ADD A,B
7138 addByte( B, 0 );
7141 void opcode_81() // ADD A,C
7143 addByte( C, 0 );
7146 void opcode_82() // ADD A,D
7148 addByte( D, 0 );
7151 void opcode_83() // ADD A,E
7153 addByte( E, 0 );
7156 void opcode_84() // ADD A,H
7158 addByte( H, 0 );
7161 void opcode_85() // ADD A,L
7163 addByte( L, 0 );
7166 void opcode_86() // ADD A,(HL)
7168 addByte( readByte( HL() ), 0 );
7171 void opcode_87() // ADD A,A
7173 addByte( A, 0 );
7176 void opcode_88() // ADC A,B
7178 addByte( B, F & Carry );
7181 void opcode_89() // ADC A,C
7183 addByte( C, F & Carry );
7186 void opcode_8a() // ADC A,D
7188 addByte( D, F & Carry );
7191 void opcode_8b() // ADC A,E
7193 addByte( E, F & Carry );
7196 void opcode_8c() // ADC A,H
7198 addByte( H, F & Carry );
7201 void opcode_8d() // ADC A,L
7203 addByte( L, F & Carry );
7206 void opcode_8e() // ADC A,(HL)
7208 addByte( readByte( HL() ), F & Carry );
7211 void opcode_8f() // ADC A,A
7213 addByte( A, F & Carry );
7216 void opcode_90() // SUB B
7218 A = subByte( B, 0 );
7221 void opcode_91() // SUB C
7223 A = subByte( C, 0 );
7226 void opcode_92() // SUB D
7228 A = subByte( D, 0 );
7231 void opcode_93() // SUB E
7233 A = subByte( E, 0 );
7236 void opcode_94() // SUB H
7238 A = subByte( H, 0 );
7241 void opcode_95() // SUB L
7243 A = subByte( L, 0 );
7246 void opcode_96() // SUB (HL)
7248 A = subByte( readByte( HL() ), 0 );
7251 void opcode_97() // SUB A
7253 A = subByte( A, 0 );
7256 void opcode_98() // SBC A,B
7258 A = subByte( B, F & Carry );
7261 void opcode_99() // SBC A,C
7263 A = subByte( C, F & Carry );
7266 void opcode_9a() // SBC A,D
7268 A = subByte( D, F & Carry );
7271 void opcode_9b() // SBC A,E
7273 A = subByte( E, F & Carry );
7276 void opcode_9c() // SBC A,H
7278 A = subByte( H, F & Carry );
7281 void opcode_9d() // SBC A,L
7283 A = subByte( L, F & Carry );
7286 void opcode_9e() // SBC A,(HL)
7288 A = subByte( readByte( HL() ), F & Carry );
7291 void opcode_9f() // SBC A,A
7293 A = subByte( A, F & Carry );
7296 void opcode_a0() // AND B
7298 A &= B;
7299 setFlagsPSZ();
7302 void opcode_a1() // AND C
7304 A &= C;
7305 setFlagsPSZ();
7308 void opcode_a2() // AND D
7310 A &= D;
7311 setFlagsPSZ();
7314 void opcode_a3() // AND E
7316 A &= E;
7317 setFlagsPSZ();
7320 void opcode_a4() // AND H
7322 A &= H;
7323 setFlagsPSZ();
7326 void opcode_a5() // AND L
7328 A &= L;
7329 setFlagsPSZ();
7332 void opcode_a6() // AND (HL)
7334 A &= readByte( HL() );
7335 setFlagsPSZ();
7338 void opcode_a7() // AND A
7340 setFlagsPSZ();
7343 void opcode_a8() // XOR B
7345 A ^= B;
7346 setFlags35PSZ000();
7349 void opcode_a9() // XOR C
7351 A ^= C;
7352 setFlags35PSZ000();
7355 void opcode_aa() // XOR D
7357 A ^= D;
7358 setFlags35PSZ000();
7361 void opcode_ab() // XOR E
7363 A ^= E;
7364 setFlags35PSZ000();
7367 void opcode_ac() // XOR H
7369 A ^= H;
7370 setFlags35PSZ000();
7373 void opcode_ad() // XOR L
7375 A ^= L;
7376 setFlags35PSZ000();
7379 void opcode_ae() // XOR (HL)
7381 A ^= readByte( HL() );
7382 setFlags35PSZ000();
7385 void opcode_af() // XOR A
7387 A = 0;
7388 setFlags35PSZ000();
7391 void opcode_b0() // OR B
7393 A |= B;
7394 setFlags35PSZ000();
7397 void opcode_b1() // OR C
7399 A |= C;
7400 setFlags35PSZ000();
7403 void opcode_b2() // OR D
7405 A |= D;
7406 setFlags35PSZ000();
7409 void opcode_b3() // OR E
7411 A |= E;
7412 setFlags35PSZ000();
7415 void opcode_b4() // OR H
7417 A |= H;
7418 setFlags35PSZ000();
7421 void opcode_b5() // OR L
7423 A |= L;
7424 setFlags35PSZ000();
7427 void opcode_b6() // OR (HL)
7429 A |= readByte( HL() );
7430 setFlags35PSZ000();
7433 void opcode_b7() // OR A
7435 setFlags35PSZ000();
7438 void opcode_b8() // CP B
7440 cmpByte( B );
7443 void opcode_b9() // CP C
7445 cmpByte( C );
7448 void opcode_ba() // CP D
7450 cmpByte( D );
7453 void opcode_bb() // CP E
7455 cmpByte( E );
7458 void opcode_bc() // CP H
7460 cmpByte( H );
7463 void opcode_bd() // CP L
7465 cmpByte( L );
7468 void opcode_be() // CP (HL)
7470 cmpByte( readByte( HL() ) );
7473 void opcode_bf() // CP A
7475 cmpByte( A );
7478 void opcode_c0() // RET NZ
7480 if( ! (F & Zero) ) {
7481 retFromSub();
7482 cycles_ += 2;
7486 void opcode_c1() // POP BC
7488 C = readByte( SP++ );
7489 B = readByte( SP++ );
7492 void opcode_c2() // JP NZ,nn
7494 if( ! (F & Zero) )
7495 PC = fetchWord();
7496 else
7497 PC += 2;
7500 void opcode_c3() // JP nn
7502 PC = readWord( PC );
7505 void opcode_c4() // CALL NZ,nn
7507 if( ! (F & Zero) ) {
7508 callSub( fetchWord() );
7509 cycles_ += 2;
7511 else {
7512 PC += 2;
7516 void opcode_c5() // PUSH BC
7518 writeByte( --SP, B );
7519 writeByte( --SP, C );
7522 void opcode_c6() // ADD A,n
7524 addByte( fetchByte(), 0 );
7527 void opcode_c7() // RST 0
7529 callSub( 0x00 );
7532 void opcode_c8() // RET Z
7534 if( F & Zero ) {
7535 retFromSub();
7536 cycles_ += 2;
7540 void opcode_c9() // RET
7542 retFromSub();
7545 void opcode_ca() // JP Z,nn
7547 if( F & Zero )
7548 PC = fetchWord();
7549 else
7550 PC += 2;
7553 void opcode_cb() // [Prefix]
7555 unsigned op = fetchByte();
7557 cycles_ += OpInfoCB_[ op ].cycles;
7558 OpInfoCB_[ op ].handler();
7561 void opcode_cc() // CALL Z,nn
7563 if( F & Zero ) {
7564 callSub( fetchWord() );
7565 cycles_ += 2;
7567 else {
7568 PC += 2;
7572 void opcode_cd() // CALL nn
7574 callSub( fetchWord() );
7577 void opcode_ce() // ADC A,n
7579 addByte( fetchByte(), F & Carry );
7582 void opcode_cf() // RST 8
7584 callSub( 0x08 );
7587 void opcode_d0() // RET NC
7589 if( ! (F & Carry) ) {
7590 retFromSub();
7591 cycles_ += 2;
7595 void opcode_d1() // POP DE
7597 E = readByte( SP++ );
7598 D = readByte( SP++ );
7601 void opcode_d2() // JP NC,nn
7603 if( ! (F & Carry) )
7604 PC = fetchWord();
7605 else
7606 PC += 2;
7609 void opcode_d3() // OUT (n),A
7611 writePort( fetchByte(), A );
7614 void opcode_d4() // CALL NC,nn
7616 if( ! (F & Carry) ) {
7617 callSub( fetchWord() );
7618 cycles_ += 2;
7620 else {
7621 PC += 2;
7625 void opcode_d5() // PUSH DE
7627 writeByte( --SP, D );
7628 writeByte( --SP, E );
7631 void opcode_d6() // SUB n
7633 A = subByte( fetchByte(), 0 );
7636 void opcode_d7() // RST 10H
7638 callSub( 0x10 );
7641 void opcode_d8() // RET C
7643 if( F & Carry ) {
7644 retFromSub();
7645 cycles_ += 2;
7649 void opcode_d9() // EXX
7651 unsigned char x;
7653 x = B; B = B1; B1 = x;
7654 x = C; C = C1; C1 = x;
7655 x = D; D = D1; D1 = x;
7656 x = E; E = E1; E1 = x;
7657 x = H; H = H1; H1 = x;
7658 x = L; L = L1; L1 = x;
7661 void opcode_da() // JP C,nn
7663 if( F & Carry )
7664 PC = fetchWord();
7665 else
7666 PC += 2;
7669 void opcode_db() // IN A,(n)
7671 A = readPort( fetchByte() );
7674 void opcode_dc() // CALL C,nn
7676 if( F & Carry ) {
7677 callSub( fetchWord() );
7678 cycles_ += 2;
7680 else {
7681 PC += 2;
7685 void opcode_dd() // [IX Prefix]
7687 do_opcode_xy( OpInfoDD_ );
7688 IX &= 0xFFFF;
7691 void opcode_de() // SBC A,n
7693 A = subByte( fetchByte(), F & Carry );
7696 void opcode_df() // RST 18H
7698 callSub( 0x18 );
7701 void opcode_e0() // RET PO
7703 if( ! (F & Parity) ) {
7704 retFromSub();
7705 cycles_ += 2;
7709 void opcode_e1() // POP HL
7711 L = readByte( SP++ );
7712 H = readByte( SP++ );
7715 void opcode_e2() // JP PO,nn
7717 if( ! (F & Parity) )
7718 PC = fetchWord();
7719 else
7720 PC += 2;
7723 void opcode_e3() // EX (SP),HL
7725 unsigned char x;
7727 x = readByte( SP ); writeByte( SP, L ); L = x;
7728 x = readByte( SP+1 ); writeByte( SP+1, H ); H = x;
7731 void opcode_e4() // CALL PO,nn
7733 if( ! (F & Parity) ) {
7734 callSub( fetchWord() );
7735 cycles_ += 2;
7737 else {
7738 PC += 2;
7742 void opcode_e5() // PUSH HL
7744 writeByte( --SP, H );
7745 writeByte( --SP, L );
7748 void opcode_e6() // AND n
7750 A &= fetchByte();
7751 setFlagsPSZ();
7754 void opcode_e7() // RST 20H
7756 callSub( 0x20 );
7759 void opcode_e8() // RET PE
7761 if( F & Parity ) {
7762 retFromSub();
7763 cycles_ += 2;
7767 void opcode_e9() // JP (HL)
7769 PC = HL();
7772 void opcode_ea() // JP PE,nn
7774 if( F & Parity )
7775 PC = fetchWord();
7776 else
7777 PC += 2;
7780 void opcode_eb() // EX DE,HL
7782 unsigned char x;
7784 x = D; D = H; H = x;
7785 x = E; E = L; L = x;
7788 void opcode_ec() // CALL PE,nn
7790 if( F & Parity ) {
7791 callSub( fetchWord() );
7792 cycles_ += 2;
7794 else {
7795 PC += 2;
7799 void opcode_ed() // [Prefix]
7801 unsigned op = fetchByte();
7803 if( OpInfoED_[ op ].handler ) {
7804 OpInfoED_[ op ].handler();
7805 cycles_ += OpInfoED_[ op ].cycles;
7807 else {
7808 cycles_ += OpInfo_[ 0 ].cycles; // NOP
7812 void opcode_ee() // XOR n
7814 A ^= fetchByte();
7815 setFlags35PSZ000();
7818 void opcode_ef() // RST 28H
7820 callSub( 0x28 );
7823 void opcode_f0() // RET P
7825 if( ! (F & Sign) ) {
7826 retFromSub();
7827 cycles_ += 2;
7831 void opcode_f1() // POP AF
7833 F = readByte( SP++ );
7834 A = readByte( SP++ );
7837 void opcode_f2() // JP P,nn
7839 if( ! (F & Sign) )
7840 PC = fetchWord();
7841 else
7842 PC += 2;
7845 void opcode_f3() // DI
7847 iflags_ &= ~(IFF1 | IFF2);
7850 void opcode_f4() // CALL P,nn
7852 if( ! (F & Sign) ) {
7853 callSub( fetchWord() );
7854 cycles_ += 2;
7856 else {
7857 PC += 2;
7861 void opcode_f5() // PUSH AF
7863 writeByte( --SP, A );
7864 writeByte( --SP, F );
7867 void opcode_f6() // OR n
7869 A |= fetchByte();
7870 setFlags35PSZ000();
7873 void opcode_f7() // RST 30H
7875 callSub( 0x30 );
7878 void opcode_f8() // RET M
7880 if( F & Sign ) {
7881 retFromSub();
7882 cycles_ += 2;
7886 void opcode_f9() // LD SP,HL
7888 SP = HL();
7891 void opcode_fa() // JP M,nn
7893 if( F & Sign )
7894 PC = fetchWord();
7895 else
7896 PC += 2;
7899 void opcode_fb() // EI
7901 iflags_ |= IFF1 | IFF2;
7904 void opcode_fc() // CALL M,nn
7906 if( F & Sign ) {
7907 callSub( fetchWord() );
7908 cycles_ += 2;
7910 else {
7911 PC += 2;
7915 void opcode_fd() // [IY Prefix]
7917 do_opcode_xy( OpInfoFD_ );
7918 IY &= 0xFFFF;
7922 void opcode_fe() // CP n
7924 subByte( fetchByte(), 0 );
7927 void opcode_ff() // RST 38H
7929 callSub( 0x38 );
7933 /* Executes one instruction */
7934 void step(void)
7936 // Update memory refresh register (not strictly needed but...)
7937 R = (R+1) & 0x7F;
7939 if( iflags_ & Halted ) {
7940 // CPU is halted, do a NOP instruction
7941 cycles_ += OpInfo_[0].cycles; // NOP
7943 else {
7944 // Get the opcode to execute
7945 unsigned op = fetchByte();
7947 // Update the cycles counter with the number of cycles for this opcode
7948 cycles_ += OpInfo_[ op ].cycles;
7950 // Execute the opcode handler
7951 OpInfo_[ op ].handler();
7953 // Update registers
7954 PC &= 0xFFFF; // Clip program counter
7955 SP &= 0xFFFF; // Clip stack pointer
7960 Runs the CPU for the specified number of cycles.
7962 Note: the memory refresh register is not updated!
7964 unsigned z80_run( unsigned runCycles )
7966 unsigned target_cycles = cycles_ + runCycles;
7968 // Execute instructions until the specified number of
7969 // cycles has elapsed
7970 while( cycles_ < target_cycles ) {
7971 if( iflags_ & Halted ) {
7972 // CPU is halted, do NOPs for the rest of cycles
7973 // (this may be off by a few cycles)
7974 cycles_ = target_cycles;
7976 else {
7977 // Get the opcode to execute
7978 unsigned op = fetchByte();
7980 // Update the cycles counter with the number of cycles for this opcode
7981 cycles_ += OpInfo_[ op ].cycles;
7983 // Execute the opcode handler
7984 OpInfo_[ op ].handler();
7988 // Update registers
7989 PC &= 0xFFFF; // Clip program counter
7990 SP &= 0xFFFF; // Clip stack pointer
7992 // Return the number of extra cycles executed
7993 return cycles_ - target_cycles;
7996 /* Interrupt */
7997 void z80_interrupt( unsigned char data )
7999 // Execute interrupt only if interrupts are enabled
8000 if( iflags_ & IFF1 ) {
8001 // Disable maskable interrupts and restart the CPU if halted
8002 iflags_ &= ~(IFF1 | IFF2 | Halted);
8004 switch( getInterruptMode() ) {
8005 case 0:
8006 OpInfo_[ data ].handler();
8007 cycles_ += 11;
8008 break;
8009 case 1:
8010 callSub( 0x38 );
8011 cycles_ += 11;
8012 break;
8013 case 2:
8014 callSub( readWord( ((unsigned)I) << 8 | (data & 0xFE) ) );
8015 cycles_ += 19;
8016 break;
8021 /* Non-maskable interrupt */
8022 void nmi(void)
8024 // Disable maskable interrupts but preserve IFF2 (that is a copy of IFF1),
8025 // also restart the CPU if halted
8026 iflags_ &= ~(IFF1 | Halted);
8028 callSub( 0x66 );
8030 cycles_ += 11;
8033 void do_opcode_xy( OpcodeInfo * info )
8035 unsigned op = fetchByte();
8037 if( (op == 0xDD) || (op == 0xFD) ) {
8038 // Exit now, to avoid possible infinite loops
8039 PC--;
8040 cycles_ += OpInfo_[ 0 ].cycles; // NOP
8042 else if( op == 0xED ) {
8043 // IX or IY prefix is ignored for this opcode
8044 opcode_ed();
8046 else {
8047 // Handle IX or IY prefix if possible
8048 if( info[ op ].handler ) {
8049 // Extended opcode is valid
8050 cycles_ += info[ op ].cycles;
8051 info[ op ].handler();
8053 else {
8054 // Extended opcode not valid, fall back to standard opcode
8055 cycles_ += OpInfo_[ op ].cycles;
8056 OpInfo_[ op ].handler();