A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 8060 lines 171 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Pacbox - a Pacman Emulator for Rockbox 11 * 12 * Based on PIE - Pacman Instructional Emulator 13 * 14 * Copyright (c) 1997-2003,2004 Alessandro Scotti 15 * http://www.ascotti.org/ 16 * 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. 21 * 22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 23 * KIND, either express or implied. 24 * 25 ****************************************************************************/ 26 27#include "plugin.h" 28#include "hardware.h" 29#include "z80.h" 30#include "z80_internal.h" 31 32// Table with parity, sign and zero flags precomputed for each byte value 33unsigned 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 50}; 51 52// Interrupt flags 53enum { 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 57}; 58 59// Implements an opcode 60typedef void (OpcodeHandler)(void); 61 62typedef struct { 63 OpcodeHandler* handler; 64 unsigned cycles; 65} OpcodeInfo; 66 67// Implements an opcode for instructions that use the form (IX/IY + b) 68typedef void (OpcodeHandlerXY)( unsigned ); 69 70typedef struct { 71 OpcodeHandlerXY* handler; 72 unsigned cycles; 73} OpcodeInfoXY; 74 75/** */ 76void do_opcode_xy( OpcodeInfo * ); 77 78/** */ 79unsigned do_opcode_xycb( unsigned xy ); 80 81unsigned iflags_ IBSS_ATTR; // Interrupt mode (bits 0 and 1) and flags 82unsigned cycles_ IBSS_ATTR; // Number of CPU cycles elapsed so far 83 84 85// Registers 86unsigned char B IBSS_ATTR; //@- B register 87unsigned char C IBSS_ATTR; //@- C register 88unsigned char D IBSS_ATTR; //@- D register 89unsigned char E IBSS_ATTR; //@- E register 90unsigned char H IBSS_ATTR; //@- H register 91unsigned char L IBSS_ATTR; //@- L register 92unsigned char A IBSS_ATTR; //@- A register (accumulator) 93unsigned char F IBSS_ATTR; //@- Flags register 94unsigned char B1 IBSS_ATTR; //@- Alternate B register (B') 95unsigned char C1 IBSS_ATTR; //@- Alternate C register (C') 96unsigned char D1 IBSS_ATTR; //@- Alternate D register (D') 97unsigned char E1 IBSS_ATTR; //@- Alternate E register (E') 98unsigned char H1 IBSS_ATTR; //@- Alternate H register (H') 99unsigned char L1 IBSS_ATTR; //@- Alternate L register (L') 100unsigned char A1 IBSS_ATTR; //@- Alternate A register (A') 101unsigned char F1 IBSS_ATTR; //@- Alternate flags register (F') 102unsigned IX IBSS_ATTR; //@- Index register X 103unsigned IY IBSS_ATTR; //@- Index register Y 104unsigned PC IBSS_ATTR; //@- Program counter 105unsigned SP IBSS_ATTR; //@- Stack pointer 106unsigned char I IBSS_ATTR; //@- Interrupt register 107unsigned char R IBSS_ATTR; //@- Refresh register 108 109 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) 114 115/** 116 Returns the number of Z80 CPU cycles elapsed so far. 117 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(). 122*/ 123unsigned getCycles(void) { 124 return cycles_; 125} 126 127/** Sets the CPU cycle counter to the specified value. */ 128void setCycles( unsigned value ) { 129 cycles_ = value; 130} 131 132/** Returns the current interrupt mode. */ 133unsigned getInterruptMode(void) { 134 return iflags_ & 0x03; 135} 136 137/** Sets the interrupt mode to the specified value. */ 138void setInterruptMode( unsigned mode ); 139 140/** Returns non-zero if the CPU is halted, otherwise zero. */ 141int isHalted(void) { 142 return iflags_ & Halted; 143} 144 145/* 146 Sets the interrupt mode to IM0, IM1 or IM2. 147*/ 148void setInterruptMode( unsigned mode ) 149{ 150 if( mode <= 2 ) { 151 iflags_ = (iflags_ & ~0x03) | mode; 152 } 153} 154 155/* 156 Calls a subroutine at the specified address. 157*/ 158void callSub( unsigned addr ) 159{ 160 SP -= 2; 161 writeWord( SP, PC ); // Save current program counter in the stack 162 PC = addr & 0xFFFF; // Jump to the specified address 163} 164 165/* 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. 169*/ 170static inline unsigned char decByte( unsigned char b ) 171{ 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; 178 179 return b; 180} 181 182/* 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. 186*/ 187static inline unsigned char incByte( unsigned char b ) 188{ 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; 195 196 return b; 197} 198 199/* 200 Reads one byte from port C, updating flags according to the rules of "IN r,(C)". 201*/ 202static inline unsigned char inpReg(void) 203{ 204 unsigned char r = readPort( C ); 205 206 F = (F & Carry) | PSZ_[r]; 207 208 return r; 209} 210 211/* 212 Performs a relative jump to the specified offset. 213*/ 214static inline void relJump( unsigned char o ) 215{ 216 int offset = (int)((signed char)o); 217 218 PC = (unsigned)((int)PC + offset) & 0xFFFF; 219 cycles_++; 220} 221 222/* 223 Returns from a subroutine, popping the saved Program Counter from the stack. 224*/ 225static inline void retFromSub(void) 226{ 227 PC = readWord( SP ); 228 SP += 2; 229} 230 231/* 232 Rotates left one byte thru the carry flag. 233*/ 234static inline unsigned char rotateLeft( unsigned char op ) 235{ 236 unsigned char f = F; 237 238 F = 0; 239 if( op & 0x80 ) F |= Carry; 240 op <<= 1; 241 if( f & Carry ) op |= 0x01; 242 F |= PSZ_[op]; 243 244 return op; 245} 246 247/* 248 Rotates left one byte copying the most significant bit (bit 7) in the carry flag. 249*/ 250static inline unsigned char rotateLeftCarry( unsigned char op ) 251{ 252 F = 0; 253 if( op & 0x80 ) F |= Carry; 254 op = (op << 1) | (op >> 7); 255 F |= PSZ_[op]; 256 257 return op; 258} 259 260/* 261 Rotates right one byte thru the carry flag. 262*/ 263static inline unsigned char rotateRight( unsigned char op ) 264{ 265 unsigned char f = F; 266 267 F = 0; 268 if( op & 0x01 ) F |= Carry; 269 op >>= 1; 270 if( f & Carry ) op |= 0x80; 271 F |= PSZ_[op]; 272 273 return op; 274} 275 276/* 277 Rotates right one byte copying the least significant bit (bit 0) in the carry flag. 278*/ 279static inline unsigned char rotateRightCarry( unsigned char op ) 280{ 281 F = 0; 282 if( op & 0x01 ) F |= Carry; 283 op = (op >> 1) | (op << 7); 284 F |= PSZ_[op]; 285 286 return op; 287} 288 289/* 290 Shifts left one byte. 291*/ 292static inline unsigned char shiftLeft( unsigned char op ) 293{ 294 F = 0; 295 if( op & 0x80 ) F |= Carry; 296 op <<= 1; 297 F |= PSZ_[op]; 298 299 return op; 300} 301 302/* 303 Shifts right one byte, preserving its sign (most significant bit). 304*/ 305static inline unsigned char shiftRightArith( unsigned char op ) 306{ 307 F = 0; 308 if( op & 0x01 ) F |= Carry; 309 op = (op >> 1) | (op & 0x80); 310 311 F |= PSZ_[op]; 312 313 return op; 314} 315 316/* 317 Shifts right one byte. 318*/ 319static inline unsigned char shiftRightLogical( unsigned char op ) 320{ 321 F = 0; 322 if( op & 0x01 ) F |= Carry; 323 op >>= 1; 324 325 F |= PSZ_[op]; 326 327 return op; 328} 329 330/* 331 Tests whether the specified bit of op is set. 332*/ 333static inline void testBit( unsigned char bit, unsigned char op ) 334{ 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; 343 344 if( (op & (1 << bit)) == 0 ) { 345 // Bit is not set, so set the zero flag 346 F |= Zero | Parity; 347 } 348} 349 350/* 351 Adds the specified byte op to the accumulator, adding 352 carry. 353*/ 354static inline void addByte( unsigned char op, unsigned char cf ) 355{ 356 unsigned x = A + op; 357 358 if( cf ) x++; // Add carry 359 360 F = 0; 361 if( !(x & 0xFF) ) F |= Zero; 362 if( x & 0x80 ) F |= Sign; 363 if( x >= 0x100 ) F |= Carry; 364 365 /* 366 Halfcarry is set on carry from the low order four bits. 367 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: 370 371 A B A+B 372 ----------- 373 0 0 0 374 0 1 1 375 1 0 1 376 1 1 0 377 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. 382 383 For the halfcarry, A and B above are the fifth bit of a byte, which corresponds 384 to the value 0x10. So: 385 386 Halfcarry = ((accumulator+operand+halfcarry) ^ accumulator ^ operand) & 0x10 387 388 Note that masking off all bits but one is important because we have worked all 389 the math by using one bit only. 390 */ 391 if( (A ^ op ^ x) & 0x10 ) F |= Halfcarry; 392 393 /* 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. 396 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. 405 406 We can code all the above concisely by noting that: 407 408 ~(A ^ op) & 0x80 409 410 is true if and only if A and op have the same sign. Also: 411 412 (x ^ op) & 0x80 413 414 is true if and only if the sum of A and op has taken a sign opposite to that 415 of its operands. 416 417 Thus the expression: 418 419 ~(A ^ op) & (x ^ op) & 0x80 420 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). 423 */ 424 if( ~(A ^ op) & (x ^ op) & 0x80 ) F |= Overflow; 425 426 A = x; 427} 428 429/* 430 Subtracts the specified byte op from the accumulator, using carry as 431 borrow from a previous operation. 432*/ 433static inline unsigned char subByte( unsigned char op, unsigned char cf ) 434{ 435 unsigned char x = A - op; 436 437 if( cf ) x--; 438 439 F = Subtraction; 440 if( x == 0 ) F |= Zero; 441 if( x & 0x80 ) F |= Sign; 442 if( (x >= A) && (op | cf)) F |= Carry; 443 444 // See addByte() for an explanation of the halfcarry bit 445 if( (A ^ op ^ x) & 0x10 ) F |= Halfcarry; 446 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; 453 454 return x; 455} 456 457static inline unsigned addDispl( unsigned addr, unsigned char displ ) { 458 return (unsigned)((int)addr + (int)(signed char)displ); 459} 460 461/** Compares the accumulator and the specified operand (CP op) */ 462static inline void cmpByte( unsigned char op ) { 463 subByte( op, 0 ); 464} 465 466/** Fetches a byte from the program counter location */ 467static inline unsigned char fetchByte(void) { 468 return readByte( PC++ ); 469} 470 471/** Fetches a 16 bit word from the program counter location */ 472static inline unsigned fetchWord(void) { 473 unsigned x = readWord( PC ); 474 PC += 2; 475 return x; 476} 477 478/** Sets the parity, sign and zero flags from the accumulator value */ 479static inline void setFlagsPSZ(void) { 480 F = Halfcarry | PSZ_[A]; 481} 482 483/** Sets the parity, sign, zero, 3rd and 5th flag bits from the accumulator value */ 484static inline void setFlags35PSZ(void) { 485 F = (F & (Carry | Halfcarry | Subtraction)) | PSZ_[A]; 486} 487 488/** */ 489static inline void setFlags35PSZ000(void) { 490 F = PSZ_[A]; 491} 492 493/* Resets the CPU */ 494void z80_reset() 495{ 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)? 501 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; 514} 515 516unsigned z80_getSizeOfSnapshotBuffer(void) 517{ 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_ 528 529 return result; 530} 531 532static unsigned saveUint16( unsigned char * buffer, unsigned u ) 533{ 534 *buffer++ = (unsigned char) (u >> 8); 535 *buffer = (unsigned char) (u); 536 537 return 2; 538} 539 540unsigned z80_takeSnapshot( unsigned char * buffer ) 541{ 542 unsigned char * buf = buffer; 543 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; 552 553 *buf++ = I; 554 *buf++ = R; 555 556 buf += saveUint16( buf, IX ); 557 buf += saveUint16( buf, IY ); 558 buf += saveUint16( buf, PC ); 559 buf += saveUint16( buf, SP ); 560 561 buf += saveUint16( buf, iflags_ >> 16 ); 562 buf += saveUint16( buf, iflags_ ); 563 buf += saveUint16( buf, cycles_ >> 16 ); 564 buf += saveUint16( buf, cycles_ ); 565 566 return buffer - buf; 567} 568 569static unsigned loadUint16( unsigned char ** buffer ) 570{ 571 unsigned char * buf = *buffer; 572 unsigned result = *buf++; 573 574 result = (result << 8) | *buf++; 575 576 *buffer = buf; 577 578 return result; 579} 580 581unsigned z80_restoreSnapshot( unsigned char * buffer ) 582{ 583 unsigned char * buf = buffer; 584 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++; 593 594 I = *buf++; 595 R = *buf++; 596 597 IX = loadUint16( &buf ); 598 IY = loadUint16( &buf ); 599 PC = loadUint16( &buf ); 600 SP = loadUint16( &buf ); 601 602 iflags_ = loadUint16( &buf ); 603 iflags_ = (iflags_ << 16) | loadUint16(&buf); 604 cycles_ = loadUint16( &buf ); 605 cycles_ = (cycles_ << 16) | loadUint16(&buf); 606 607 return buf - buffer; 608} 609 610OpcodeInfo 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 867}; 868 869void opcode_cb_00() // RLC B 870{ 871 B = rotateLeftCarry( B ); 872} 873 874void opcode_cb_01() // RLC C 875{ 876 C = rotateLeftCarry( C ); 877} 878 879void opcode_cb_02() // RLC D 880{ 881 D = rotateLeftCarry( D ); 882} 883 884void opcode_cb_03() // RLC E 885{ 886 E = rotateLeftCarry( E ); 887} 888 889void opcode_cb_04() // RLC H 890{ 891 H = rotateLeftCarry( H ); 892} 893 894void opcode_cb_05() // RLC L 895{ 896 L = rotateLeftCarry( L ); 897} 898 899void opcode_cb_06() // RLC (HL) 900{ 901 writeByte( HL(), rotateLeftCarry( readByte( HL() ) ) ); 902} 903 904void opcode_cb_07() // RLC A 905{ 906 A = rotateLeftCarry( A ); 907} 908 909void opcode_cb_08() // RRC B 910{ 911 B = rotateRightCarry( B ); 912} 913 914void opcode_cb_09() // RRC C 915{ 916 C = rotateLeftCarry( C ); 917} 918 919void opcode_cb_0a() // RRC D 920{ 921 D = rotateLeftCarry( D ); 922} 923 924void opcode_cb_0b() // RRC E 925{ 926 E = rotateLeftCarry( E ); 927} 928 929void opcode_cb_0c() // RRC H 930{ 931 H = rotateLeftCarry( H ); 932} 933 934void opcode_cb_0d() // RRC L 935{ 936 L = rotateLeftCarry( L ); 937} 938 939void opcode_cb_0e() // RRC (HL) 940{ 941 writeByte( HL(), rotateRightCarry( readByte( HL() ) ) ); 942} 943 944void opcode_cb_0f() // RRC A 945{ 946 A = rotateLeftCarry( A ); 947} 948 949void opcode_cb_10() // RL B 950{ 951 B = rotateLeft( B ); 952} 953 954void opcode_cb_11() // RL C 955{ 956 C = rotateLeft( C ); 957} 958 959void opcode_cb_12() // RL D 960{ 961 D = rotateLeft( D ); 962} 963 964void opcode_cb_13() // RL E 965{ 966 E = rotateLeft( E ); 967} 968 969void opcode_cb_14() // RL H 970{ 971 H = rotateLeft( H ); 972} 973 974void opcode_cb_15() // RL L 975{ 976 L = rotateLeft( L ); 977} 978 979void opcode_cb_16() // RL (HL) 980{ 981 writeByte( HL(), rotateLeft( readByte( HL() ) ) ); 982} 983 984void opcode_cb_17() // RL A 985{ 986 A = rotateLeft( A ); 987} 988 989void opcode_cb_18() // RR B 990{ 991 B = rotateRight( B ); 992} 993 994void opcode_cb_19() // RR C 995{ 996 C = rotateRight( C ); 997} 998 999void opcode_cb_1a() // RR D 1000{ 1001 D = rotateRight( D ); 1002} 1003 1004void opcode_cb_1b() // RR E 1005{ 1006 E = rotateRight( E ); 1007} 1008 1009void opcode_cb_1c() // RR H 1010{ 1011 H = rotateRight( H ); 1012} 1013 1014void opcode_cb_1d() // RR L 1015{ 1016 L = rotateRight( L ); 1017} 1018 1019void opcode_cb_1e() // RR (HL) 1020{ 1021 writeByte( HL(), rotateRight( readByte( HL() ) ) ); 1022} 1023 1024void opcode_cb_1f() // RR A 1025{ 1026 A = rotateRight( A ); 1027} 1028 1029void opcode_cb_20() // SLA B 1030{ 1031 B = shiftLeft( B ); 1032} 1033 1034void opcode_cb_21() // SLA C 1035{ 1036 C = shiftLeft( C ); 1037} 1038 1039void opcode_cb_22() // SLA D 1040{ 1041 D = shiftLeft( D ); 1042} 1043 1044void opcode_cb_23() // SLA E 1045{ 1046 E = shiftLeft( E ); 1047} 1048 1049void opcode_cb_24() // SLA H 1050{ 1051 H = shiftLeft( H ); 1052} 1053 1054void opcode_cb_25() // SLA L 1055{ 1056 L = shiftLeft( L ); 1057} 1058 1059void opcode_cb_26() // SLA (HL) 1060{ 1061 writeByte( HL(), shiftLeft( readByte( HL() ) ) ); 1062} 1063 1064void opcode_cb_27() // SLA A 1065{ 1066 A = shiftLeft( A ); 1067} 1068 1069void opcode_cb_28() // SRA B 1070{ 1071 B = shiftRightArith( B ); 1072} 1073 1074void opcode_cb_29() // SRA C 1075{ 1076 C = shiftRightArith( C ); 1077} 1078 1079void opcode_cb_2a() // SRA D 1080{ 1081 D = shiftRightArith( D ); 1082} 1083 1084void opcode_cb_2b() // SRA E 1085{ 1086 E = shiftRightArith( E ); 1087} 1088 1089void opcode_cb_2c() // SRA H 1090{ 1091 H = shiftRightArith( H ); 1092} 1093 1094void opcode_cb_2d() // SRA L 1095{ 1096 L = shiftRightArith( L ); 1097} 1098 1099void opcode_cb_2e() // SRA (HL) 1100{ 1101 writeByte( HL(), shiftRightArith( readByte( HL() ) ) ); 1102} 1103 1104void opcode_cb_2f() // SRA A 1105{ 1106 A = shiftRightArith( A ); 1107} 1108 1109void opcode_cb_30() // SLL B 1110{ 1111 B = shiftLeft( B ) | 0x01; 1112} 1113 1114void opcode_cb_31() // SLL C 1115{ 1116 C = shiftLeft( C ) | 0x01; 1117} 1118 1119void opcode_cb_32() // SLL D 1120{ 1121 D = shiftLeft( D ) | 0x01; 1122} 1123 1124void opcode_cb_33() // SLL E 1125{ 1126 E = shiftLeft( E ) | 0x01; 1127} 1128 1129void opcode_cb_34() // SLL H 1130{ 1131 H = shiftLeft( H ) | 0x01; 1132} 1133 1134void opcode_cb_35() // SLL L 1135{ 1136 L = shiftLeft( L ) | 0x01; 1137} 1138 1139void opcode_cb_36() // SLL (HL) 1140{ 1141 writeByte( HL(), shiftLeft( readByte( HL() ) ) | 0x01 ); 1142} 1143 1144void opcode_cb_37() // SLL A 1145{ 1146 A = shiftLeft( A ) | 0x01; 1147} 1148 1149void opcode_cb_38() // SRL B 1150{ 1151 B = shiftRightLogical( B ); 1152} 1153 1154void opcode_cb_39() // SRL C 1155{ 1156 C = shiftRightLogical( C ); 1157} 1158 1159void opcode_cb_3a() // SRL D 1160{ 1161 D = shiftRightLogical( D ); 1162} 1163 1164void opcode_cb_3b() // SRL E 1165{ 1166 E = shiftRightLogical( E ); 1167} 1168 1169void opcode_cb_3c() // SRL H 1170{ 1171 H = shiftRightLogical( H ); 1172} 1173 1174void opcode_cb_3d() // SRL L 1175{ 1176 L = shiftRightLogical( L ); 1177} 1178 1179void opcode_cb_3e() // SRL (HL) 1180{ 1181 writeByte( HL(), shiftRightLogical( readByte( HL() ) ) ); 1182} 1183 1184void opcode_cb_3f() // SRL A 1185{ 1186 A = shiftRightLogical( A ); 1187} 1188 1189void opcode_cb_40() // BIT 0, B 1190{ 1191 testBit( 0, B ); 1192} 1193 1194void opcode_cb_41() // BIT 0, C 1195{ 1196 testBit( 0, C ); 1197} 1198 1199void opcode_cb_42() // BIT 0, D 1200{ 1201 testBit( 0, D ); 1202} 1203 1204void opcode_cb_43() // BIT 0, E 1205{ 1206 testBit( 0, E ); 1207} 1208 1209void opcode_cb_44() // BIT 0, H 1210{ 1211 testBit( 0, H ); 1212} 1213 1214void opcode_cb_45() // BIT 0, L 1215{ 1216 testBit( 0, L ); 1217} 1218 1219void opcode_cb_46() // BIT 0, (HL) 1220{ 1221 testBit( 0, readByte( HL() ) ); 1222} 1223 1224void opcode_cb_47() // BIT 0, A 1225{ 1226 testBit( 0, A ); 1227} 1228 1229void opcode_cb_48() // BIT 1, B 1230{ 1231 testBit( 1, B ); 1232} 1233 1234void opcode_cb_49() // BIT 1, C 1235{ 1236 testBit( 1, C ); 1237} 1238 1239void opcode_cb_4a() // BIT 1, D 1240{ 1241 testBit( 1, D ); 1242} 1243 1244void opcode_cb_4b() // BIT 1, E 1245{ 1246 testBit( 1, E ); 1247} 1248 1249void opcode_cb_4c() // BIT 1, H 1250{ 1251 testBit( 1, H ); 1252} 1253 1254void opcode_cb_4d() // BIT 1, L 1255{ 1256 testBit( 1, L ); 1257} 1258 1259void opcode_cb_4e() // BIT 1, (HL) 1260{ 1261 testBit( 1, readByte( HL() ) ); 1262} 1263 1264void opcode_cb_4f() // BIT 1, A 1265{ 1266 testBit( 1, A ); 1267} 1268 1269void opcode_cb_50() // BIT 2, B 1270{ 1271 testBit( 2, B ); 1272} 1273 1274void opcode_cb_51() // BIT 2, C 1275{ 1276 testBit( 2, C ); 1277} 1278 1279void opcode_cb_52() // BIT 2, D 1280{ 1281 testBit( 2, D ); 1282} 1283 1284void opcode_cb_53() // BIT 2, E 1285{ 1286 testBit( 2, E ); 1287} 1288 1289void opcode_cb_54() // BIT 2, H 1290{ 1291 testBit( 2, H ); 1292} 1293 1294void opcode_cb_55() // BIT 2, L 1295{ 1296 testBit( 2, L ); 1297} 1298 1299void opcode_cb_56() // BIT 2, (HL) 1300{ 1301 testBit( 2, readByte( HL() ) ); 1302} 1303 1304void opcode_cb_57() // BIT 2, A 1305{ 1306 testBit( 2, A ); 1307} 1308 1309void opcode_cb_58() // BIT 3, B 1310{ 1311 testBit( 3, B ); 1312} 1313 1314void opcode_cb_59() // BIT 3, C 1315{ 1316 testBit( 3, C ); 1317} 1318 1319void opcode_cb_5a() // BIT 3, D 1320{ 1321 testBit( 3, D ); 1322} 1323 1324void opcode_cb_5b() // BIT 3, E 1325{ 1326 testBit( 3, E ); 1327} 1328 1329void opcode_cb_5c() // BIT 3, H 1330{ 1331 testBit( 3, H ); 1332} 1333 1334void opcode_cb_5d() // BIT 3, L 1335{ 1336 testBit( 3, L ); 1337} 1338 1339void opcode_cb_5e() // BIT 3, (HL) 1340{ 1341 testBit( 3, readByte( HL() ) ); 1342} 1343 1344void opcode_cb_5f() // BIT 3, A 1345{ 1346 testBit( 3, A ); 1347} 1348 1349void opcode_cb_60() // BIT 4, B 1350{ 1351 testBit( 4, B ); 1352} 1353 1354void opcode_cb_61() // BIT 4, C 1355{ 1356 testBit( 4, C ); 1357} 1358 1359void opcode_cb_62() // BIT 4, D 1360{ 1361 testBit( 4, D ); 1362} 1363 1364void opcode_cb_63() // BIT 4, E 1365{ 1366 testBit( 4, E ); 1367} 1368 1369void opcode_cb_64() // BIT 4, H 1370{ 1371 testBit( 4, H ); 1372} 1373 1374void opcode_cb_65() // BIT 4, L 1375{ 1376 testBit( 4, L ); 1377} 1378 1379void opcode_cb_66() // BIT 4, (HL) 1380{ 1381 testBit( 4, readByte( HL() ) ); 1382} 1383 1384void opcode_cb_67() // BIT 4, A 1385{ 1386 testBit( 4, A ); 1387} 1388 1389void opcode_cb_68() // BIT 5, B 1390{ 1391 testBit( 5, B ); 1392} 1393 1394void opcode_cb_69() // BIT 5, C 1395{ 1396 testBit( 5, C ); 1397} 1398 1399void opcode_cb_6a() // BIT 5, D 1400{ 1401 testBit( 5, D ); 1402} 1403 1404void opcode_cb_6b() // BIT 5, E 1405{ 1406 testBit( 5, E ); 1407} 1408 1409void opcode_cb_6c() // BIT 5, H 1410{ 1411 testBit( 5, H ); 1412} 1413 1414void opcode_cb_6d() // BIT 5, L 1415{ 1416 testBit( 5, L ); 1417} 1418 1419void opcode_cb_6e() // BIT 5, (HL) 1420{ 1421 testBit( 5, readByte( HL() ) ); 1422} 1423 1424void opcode_cb_6f() // BIT 5, A 1425{ 1426 testBit( 5, A ); 1427} 1428 1429void opcode_cb_70() // BIT 6, B 1430{ 1431 testBit( 6, B ); 1432} 1433 1434void opcode_cb_71() // BIT 6, C 1435{ 1436 testBit( 6, C ); 1437} 1438 1439void opcode_cb_72() // BIT 6, D 1440{ 1441 testBit( 6, D ); 1442} 1443 1444void opcode_cb_73() // BIT 6, E 1445{ 1446 testBit( 6, E ); 1447} 1448 1449void opcode_cb_74() // BIT 6, H 1450{ 1451 testBit( 6, H ); 1452} 1453 1454void opcode_cb_75() // BIT 6, L 1455{ 1456 testBit( 6, L ); 1457} 1458 1459void opcode_cb_76() // BIT 6, (HL) 1460{ 1461 testBit( 6, readByte( HL() ) ); 1462} 1463 1464void opcode_cb_77() // BIT 6, A 1465{ 1466 testBit( 6, A ); 1467} 1468 1469void opcode_cb_78() // BIT 7, B 1470{ 1471 testBit( 7, B ); 1472} 1473 1474void opcode_cb_79() // BIT 7, C 1475{ 1476 testBit( 7, C ); 1477} 1478 1479void opcode_cb_7a() // BIT 7, D 1480{ 1481 testBit( 7, D ); 1482} 1483 1484void opcode_cb_7b() // BIT 7, E 1485{ 1486 testBit( 7, E ); 1487} 1488 1489void opcode_cb_7c() // BIT 7, H 1490{ 1491 testBit( 7, H ); 1492} 1493 1494void opcode_cb_7d() // BIT 7, L 1495{ 1496 testBit( 7, L ); 1497} 1498 1499void opcode_cb_7e() // BIT 7, (HL) 1500{ 1501 testBit( 7, readByte( HL() ) ); 1502} 1503 1504void opcode_cb_7f() // BIT 7, A 1505{ 1506 testBit( 7, A ); 1507} 1508 1509void opcode_cb_80() // RES 0, B 1510{ 1511 B &= ~(unsigned char) (1 << 0); 1512} 1513 1514void opcode_cb_81() // RES 0, C 1515{ 1516 C &= ~(unsigned char) (1 << 0); 1517} 1518 1519void opcode_cb_82() // RES 0, D 1520{ 1521 D &= ~(unsigned char) (1 << 0); 1522} 1523 1524void opcode_cb_83() // RES 0, E 1525{ 1526 E &= ~(unsigned char) (1 << 0); 1527} 1528 1529void opcode_cb_84() // RES 0, H 1530{ 1531 H &= ~(unsigned char) (1 << 0); 1532} 1533 1534void opcode_cb_85() // RES 0, L 1535{ 1536 L &= ~(unsigned char) (1 << 0); 1537} 1538 1539void opcode_cb_86() // RES 0, (HL) 1540{ 1541 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 0) ); 1542} 1543 1544void opcode_cb_87() // RES 0, A 1545{ 1546 A &= ~(unsigned char) (1 << 0); 1547} 1548 1549void opcode_cb_88() // RES 1, B 1550{ 1551 B &= ~(unsigned char) (1 << 1); 1552} 1553 1554void opcode_cb_89() // RES 1, C 1555{ 1556 C &= ~(unsigned char) (1 << 1); 1557} 1558 1559void opcode_cb_8a() // RES 1, D 1560{ 1561 D &= ~(unsigned char) (1 << 1); 1562} 1563 1564void opcode_cb_8b() // RES 1, E 1565{ 1566 E &= ~(unsigned char) (1 << 1); 1567} 1568 1569void opcode_cb_8c() // RES 1, H 1570{ 1571 H &= ~(unsigned char) (1 << 1); 1572} 1573 1574void opcode_cb_8d() // RES 1, L 1575{ 1576 L &= ~(unsigned char) (1 << 1); 1577} 1578 1579void opcode_cb_8e() // RES 1, (HL) 1580{ 1581 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 1) ); 1582} 1583 1584void opcode_cb_8f() // RES 1, A 1585{ 1586 A &= ~(unsigned char) (1 << 1); 1587} 1588 1589void opcode_cb_90() // RES 2, B 1590{ 1591 B &= ~(unsigned char) (1 << 2); 1592} 1593 1594void opcode_cb_91() // RES 2, C 1595{ 1596 C &= ~(unsigned char) (1 << 2); 1597} 1598 1599void opcode_cb_92() // RES 2, D 1600{ 1601 D &= ~(unsigned char) (1 << 2); 1602} 1603 1604void opcode_cb_93() // RES 2, E 1605{ 1606 E &= ~(unsigned char) (1 << 2); 1607} 1608 1609void opcode_cb_94() // RES 2, H 1610{ 1611 H &= ~(unsigned char) (1 << 2); 1612} 1613 1614void opcode_cb_95() // RES 2, L 1615{ 1616 L &= ~(unsigned char) (1 << 2); 1617} 1618 1619void opcode_cb_96() // RES 2, (HL) 1620{ 1621 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 2) ); 1622} 1623 1624void opcode_cb_97() // RES 2, A 1625{ 1626 A &= ~(unsigned char) (1 << 2); 1627} 1628 1629void opcode_cb_98() // RES 3, B 1630{ 1631 B &= ~(unsigned char) (1 << 3); 1632} 1633 1634void opcode_cb_99() // RES 3, C 1635{ 1636 C &= ~(unsigned char) (1 << 3); 1637} 1638 1639void opcode_cb_9a() // RES 3, D 1640{ 1641 D &= ~(unsigned char) (1 << 3); 1642} 1643 1644void opcode_cb_9b() // RES 3, E 1645{ 1646 E &= ~(unsigned char) (1 << 3); 1647} 1648 1649void opcode_cb_9c() // RES 3, H 1650{ 1651 H &= ~(unsigned char) (1 << 3); 1652} 1653 1654void opcode_cb_9d() // RES 3, L 1655{ 1656 L &= ~(unsigned char) (1 << 3); 1657} 1658 1659void opcode_cb_9e() // RES 3, (HL) 1660{ 1661 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 3) ); 1662} 1663 1664void opcode_cb_9f() // RES 3, A 1665{ 1666 A &= ~(unsigned char) (1 << 3); 1667} 1668 1669void opcode_cb_a0() // RES 4, B 1670{ 1671 B &= ~(unsigned char) (1 << 4); 1672} 1673 1674void opcode_cb_a1() // RES 4, C 1675{ 1676 C &= ~(unsigned char) (1 << 4); 1677} 1678 1679void opcode_cb_a2() // RES 4, D 1680{ 1681 D &= ~(unsigned char) (1 << 4); 1682} 1683 1684void opcode_cb_a3() // RES 4, E 1685{ 1686 E &= ~(unsigned char) (1 << 4); 1687} 1688 1689void opcode_cb_a4() // RES 4, H 1690{ 1691 H &= ~(unsigned char) (1 << 4); 1692} 1693 1694void opcode_cb_a5() // RES 4, L 1695{ 1696 L &= ~(unsigned char) (1 << 4); 1697} 1698 1699void opcode_cb_a6() // RES 4, (HL) 1700{ 1701 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 4) ); 1702} 1703 1704void opcode_cb_a7() // RES 4, A 1705{ 1706 A &= ~(unsigned char) (1 << 4); 1707} 1708 1709void opcode_cb_a8() // RES 5, B 1710{ 1711 B &= ~(unsigned char) (1 << 5); 1712} 1713 1714void opcode_cb_a9() // RES 5, C 1715{ 1716 C &= ~(unsigned char) (1 << 5); 1717} 1718 1719void opcode_cb_aa() // RES 5, D 1720{ 1721 D &= ~(unsigned char) (1 << 5); 1722} 1723 1724void opcode_cb_ab() // RES 5, E 1725{ 1726 E &= ~(unsigned char) (1 << 5); 1727} 1728 1729void opcode_cb_ac() // RES 5, H 1730{ 1731 H &= ~(unsigned char) (1 << 5); 1732} 1733 1734void opcode_cb_ad() // RES 5, L 1735{ 1736 L &= ~(unsigned char) (1 << 5); 1737} 1738 1739void opcode_cb_ae() // RES 5, (HL) 1740{ 1741 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 5) ); 1742} 1743 1744void opcode_cb_af() // RES 5, A 1745{ 1746 A &= ~(unsigned char) (1 << 5); 1747} 1748 1749void opcode_cb_b0() // RES 6, B 1750{ 1751 B &= ~(unsigned char) (1 << 6); 1752} 1753 1754void opcode_cb_b1() // RES 6, C 1755{ 1756 C &= ~(unsigned char) (1 << 6); 1757} 1758 1759void opcode_cb_b2() // RES 6, D 1760{ 1761 D &= ~(unsigned char) (1 << 6); 1762} 1763 1764void opcode_cb_b3() // RES 6, E 1765{ 1766 E &= ~(unsigned char) (1 << 6); 1767} 1768 1769void opcode_cb_b4() // RES 6, H 1770{ 1771 H &= ~(unsigned char) (1 << 6); 1772} 1773 1774void opcode_cb_b5() // RES 6, L 1775{ 1776 L &= ~(unsigned char) (1 << 6); 1777} 1778 1779void opcode_cb_b6() // RES 6, (HL) 1780{ 1781 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 6) ); 1782} 1783 1784void opcode_cb_b7() // RES 6, A 1785{ 1786 A &= ~(unsigned char) (1 << 6); 1787} 1788 1789void opcode_cb_b8() // RES 7, B 1790{ 1791 B &= ~(unsigned char) (1 << 7); 1792} 1793 1794void opcode_cb_b9() // RES 7, C 1795{ 1796 C &= ~(unsigned char) (1 << 7); 1797} 1798 1799void opcode_cb_ba() // RES 7, D 1800{ 1801 D &= ~(unsigned char) (1 << 7); 1802} 1803 1804void opcode_cb_bb() // RES 7, E 1805{ 1806 E &= ~(unsigned char) (1 << 7); 1807} 1808 1809void opcode_cb_bc() // RES 7, H 1810{ 1811 H &= ~(unsigned char) (1 << 7); 1812} 1813 1814void opcode_cb_bd() // RES 7, L 1815{ 1816 L &= ~(unsigned char) (1 << 7); 1817} 1818 1819void opcode_cb_be() // RES 7, (HL) 1820{ 1821 writeByte( HL(), readByte( HL() ) & (unsigned char) ~(unsigned char) (1 << 7) ); 1822} 1823 1824void opcode_cb_bf() // RES 7, A 1825{ 1826 A &= ~(unsigned char) (1 << 7); 1827} 1828 1829void opcode_cb_c0() // SET 0, B 1830{ 1831 B |= (unsigned char) (1 << 0); 1832} 1833 1834void opcode_cb_c1() // SET 0, C 1835{ 1836 C |= (unsigned char) (1 << 0); 1837} 1838 1839void opcode_cb_c2() // SET 0, D 1840{ 1841 D |= (unsigned char) (1 << 0); 1842} 1843 1844void opcode_cb_c3() // SET 0, E 1845{ 1846 E |= (unsigned char) (1 << 0); 1847} 1848 1849void opcode_cb_c4() // SET 0, H 1850{ 1851 H |= (unsigned char) (1 << 0); 1852} 1853 1854void opcode_cb_c5() // SET 0, L 1855{ 1856 L |= (unsigned char) (1 << 0); 1857} 1858 1859void opcode_cb_c6() // SET 0, (HL) 1860{ 1861 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 0) ); 1862} 1863 1864void opcode_cb_c7() // SET 0, A 1865{ 1866 A |= (unsigned char) (1 << 0); 1867} 1868 1869void opcode_cb_c8() // SET 1, B 1870{ 1871 B |= (unsigned char) (1 << 1); 1872} 1873 1874void opcode_cb_c9() // SET 1, C 1875{ 1876 C |= (unsigned char) (1 << 1); 1877} 1878 1879void opcode_cb_ca() // SET 1, D 1880{ 1881 D |= (unsigned char) (1 << 1); 1882} 1883 1884void opcode_cb_cb() // SET 1, E 1885{ 1886 E |= (unsigned char) (1 << 1); 1887} 1888 1889void opcode_cb_cc() // SET 1, H 1890{ 1891 H |= (unsigned char) (1 << 1); 1892} 1893 1894void opcode_cb_cd() // SET 1, L 1895{ 1896 L |= (unsigned char) (1 << 1); 1897} 1898 1899void opcode_cb_ce() // SET 1, (HL) 1900{ 1901 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 1) ); 1902} 1903 1904void opcode_cb_cf() // SET 1, A 1905{ 1906 A |= (unsigned char) (1 << 1); 1907} 1908 1909void opcode_cb_d0() // SET 2, B 1910{ 1911 B |= (unsigned char) (1 << 2); 1912} 1913 1914void opcode_cb_d1() // SET 2, C 1915{ 1916 C |= (unsigned char) (1 << 2); 1917} 1918 1919void opcode_cb_d2() // SET 2, D 1920{ 1921 D |= (unsigned char) (1 << 2); 1922} 1923 1924void opcode_cb_d3() // SET 2, E 1925{ 1926 E |= (unsigned char) (1 << 2); 1927} 1928 1929void opcode_cb_d4() // SET 2, H 1930{ 1931 H |= (unsigned char) (1 << 2); 1932} 1933 1934void opcode_cb_d5() // SET 2, L 1935{ 1936 L |= (unsigned char) (1 << 2); 1937} 1938 1939void opcode_cb_d6() // SET 2, (HL) 1940{ 1941 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 2) ); 1942} 1943 1944void opcode_cb_d7() // SET 2, A 1945{ 1946 A |= (unsigned char) (1 << 2); 1947} 1948 1949void opcode_cb_d8() // SET 3, B 1950{ 1951 B |= (unsigned char) (1 << 3); 1952} 1953 1954void opcode_cb_d9() // SET 3, C 1955{ 1956 C |= (unsigned char) (1 << 3); 1957} 1958 1959void opcode_cb_da() // SET 3, D 1960{ 1961 D |= (unsigned char) (1 << 3); 1962} 1963 1964void opcode_cb_db() // SET 3, E 1965{ 1966 E |= (unsigned char) (1 << 3); 1967} 1968 1969void opcode_cb_dc() // SET 3, H 1970{ 1971 H |= (unsigned char) (1 << 3); 1972} 1973 1974void opcode_cb_dd() // SET 3, L 1975{ 1976 L |= (unsigned char) (1 << 3); 1977} 1978 1979void opcode_cb_de() // SET 3, (HL) 1980{ 1981 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 3) ); 1982} 1983 1984void opcode_cb_df() // SET 3, A 1985{ 1986 A |= (unsigned char) (1 << 3); 1987} 1988 1989void opcode_cb_e0() // SET 4, B 1990{ 1991 B |= (unsigned char) (1 << 4); 1992} 1993 1994void opcode_cb_e1() // SET 4, C 1995{ 1996 C |= (unsigned char) (1 << 4); 1997} 1998 1999void opcode_cb_e2() // SET 4, D 2000{ 2001 D |= (unsigned char) (1 << 4); 2002} 2003 2004void opcode_cb_e3() // SET 4, E 2005{ 2006 E |= (unsigned char) (1 << 4); 2007} 2008 2009void opcode_cb_e4() // SET 4, H 2010{ 2011 H |= (unsigned char) (1 << 4); 2012} 2013 2014void opcode_cb_e5() // SET 4, L 2015{ 2016 L |= (unsigned char) (1 << 4); 2017} 2018 2019void opcode_cb_e6() // SET 4, (HL) 2020{ 2021 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 4) ); 2022} 2023 2024void opcode_cb_e7() // SET 4, A 2025{ 2026 A |= (unsigned char) (1 << 4); 2027} 2028 2029void opcode_cb_e8() // SET 5, B 2030{ 2031 B |= (unsigned char) (1 << 5); 2032} 2033 2034void opcode_cb_e9() // SET 5, C 2035{ 2036 C |= (unsigned char) (1 << 5); 2037} 2038 2039void opcode_cb_ea() // SET 5, D 2040{ 2041 D |= (unsigned char) (1 << 5); 2042} 2043 2044void opcode_cb_eb() // SET 5, E 2045{ 2046 E |= (unsigned char) (1 << 5); 2047} 2048 2049void opcode_cb_ec() // SET 5, H 2050{ 2051 H |= (unsigned char) (1 << 5); 2052} 2053 2054void opcode_cb_ed() // SET 5, L 2055{ 2056 L |= (unsigned char) (1 << 5); 2057} 2058 2059void opcode_cb_ee() // SET 5, (HL) 2060{ 2061 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 5) ); 2062} 2063 2064void opcode_cb_ef() // SET 5, A 2065{ 2066 A |= (unsigned char) (1 << 5); 2067} 2068 2069void opcode_cb_f0() // SET 6, B 2070{ 2071 B |= (unsigned char) (1 << 6); 2072} 2073 2074void opcode_cb_f1() // SET 6, C 2075{ 2076 C |= (unsigned char) (1 << 6); 2077} 2078 2079void opcode_cb_f2() // SET 6, D 2080{ 2081 D |= (unsigned char) (1 << 6); 2082} 2083 2084void opcode_cb_f3() // SET 6, E 2085{ 2086 E |= (unsigned char) (1 << 6); 2087} 2088 2089void opcode_cb_f4() // SET 6, H 2090{ 2091 H |= (unsigned char) (1 << 6); 2092} 2093 2094void opcode_cb_f5() // SET 6, L 2095{ 2096 L |= (unsigned char) (1 << 6); 2097} 2098 2099void opcode_cb_f6() // SET 6, (HL) 2100{ 2101 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 6) ); 2102} 2103 2104void opcode_cb_f7() // SET 6, A 2105{ 2106 A |= (unsigned char) (1 << 6); 2107} 2108 2109void opcode_cb_f8() // SET 7, B 2110{ 2111 B |= (unsigned char) (1 << 7); 2112} 2113 2114void opcode_cb_f9() // SET 7, C 2115{ 2116 C |= (unsigned char) (1 << 7); 2117} 2118 2119void opcode_cb_fa() // SET 7, D 2120{ 2121 D |= (unsigned char) (1 << 7); 2122} 2123 2124void opcode_cb_fb() // SET 7, E 2125{ 2126 E |= (unsigned char) (1 << 7); 2127} 2128 2129void opcode_cb_fc() // SET 7, H 2130{ 2131 H |= (unsigned char) (1 << 7); 2132} 2133 2134void opcode_cb_fd() // SET 7, L 2135{ 2136 L |= (unsigned char) (1 << 7); 2137} 2138 2139void opcode_cb_fe() // SET 7, (HL) 2140{ 2141 writeByte( HL(), readByte( HL() ) | (unsigned char) (1 << 7) ); 2142} 2143 2144void opcode_cb_ff() // SET 7, A 2145{ 2146 A |= (unsigned char) (1 << 7); 2147} 2148 2149OpcodeInfo 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 2406}; 2407 2408void opcode_dd_09() // ADD IX, BC 2409{ 2410 unsigned rr = BC(); 2411 2412 F &= (Zero | Sign | Parity); 2413 if( ((IX & 0xFFF)+(rr & 0xFFF)) > 0xFFF ) F |= Halfcarry; 2414 IX += rr; 2415 if( IX & 0x10000 ) F |= Carry; 2416} 2417 2418void opcode_dd_19() // ADD IX, DE 2419{ 2420 unsigned rr = DE(); 2421 2422 F &= (Zero | Sign | Parity); 2423 if( ((IX & 0xFFF)+(rr & 0xFFF)) > 0xFFF ) F |= Halfcarry; 2424 IX += rr; 2425 if( IX & 0x10000 ) F |= Carry; 2426} 2427 2428void opcode_dd_21() // LD IX, nn 2429{ 2430 IX = fetchWord(); 2431} 2432 2433void opcode_dd_22() // LD (nn), IX 2434{ 2435 writeWord( fetchWord(), IX ); 2436} 2437 2438void opcode_dd_23() // INC IX 2439{ 2440 IX++; 2441} 2442 2443void opcode_dd_24() // INC IXH 2444{ 2445 IX = (IX & 0xFF) | ((unsigned)incByte( IX >> 8 ) << 8); 2446} 2447 2448void opcode_dd_25() // DEC IXH 2449{ 2450 IX = (IX & 0xFF) | ((unsigned)decByte( IX >> 8 ) << 8); 2451} 2452 2453void opcode_dd_26() // LD IXH, n 2454{ 2455 IX = (IX & 0xFF) | ((unsigned)fetchByte() << 8); 2456} 2457 2458void opcode_dd_29() // ADD IX, IX 2459{ 2460 F &= (Zero | Sign | Parity); 2461 if( IX & 0x800 ) F |= Halfcarry; 2462 IX += IX; 2463 if( IX & 0x10000 ) F |= Carry; 2464} 2465 2466void opcode_dd_2a() // LD IX, (nn) 2467{ 2468 IX = readWord( fetchWord() ); 2469} 2470 2471void opcode_dd_2b() // DEC IX 2472{ 2473 IX--; 2474} 2475 2476void opcode_dd_2c() // INC IXL 2477{ 2478 IX = (IX & 0xFF00) | incByte( IX & 0xFF ); 2479} 2480 2481void opcode_dd_2d() // DEC IXL 2482{ 2483 IX = (IX & 0xFF00) | decByte( IX & 0xFF ); 2484} 2485 2486void opcode_dd_2e() // LD IXL, n 2487{ 2488 IX = (IX & 0xFF00) | fetchByte(); 2489} 2490 2491void opcode_dd_34() // INC (IX + d) 2492{ 2493 unsigned addr = addDispl( IX, fetchByte() ); 2494 2495 writeByte( addr, incByte( readByte( addr ) ) ); 2496} 2497 2498void opcode_dd_35() // DEC (IX + d) 2499{ 2500 unsigned addr = addDispl( IX, fetchByte() ); 2501 2502 writeByte( addr, decByte( readByte( addr ) ) ); 2503} 2504 2505void opcode_dd_36() // LD (IX + d), n 2506{ 2507 unsigned addr = addDispl( IX, fetchByte() ); 2508 2509 writeByte( addr, fetchByte() ); 2510} 2511 2512void opcode_dd_39() // ADD IX, SP 2513{ 2514 F &= (Zero | Sign | Parity); 2515 if( ((IX & 0xFFF)+(SP & 0xFFF)) > 0xFFF ) F |= Halfcarry; 2516 IX += SP; 2517 if( IX & 0x10000 ) F |= Carry; 2518} 2519 2520void opcode_dd_44() // LD B, IXH 2521{ 2522 B = IX >> 8; 2523} 2524 2525void opcode_dd_45() // LD B, IXL 2526{ 2527 B = IX & 0xFF; 2528} 2529 2530void opcode_dd_46() // LD B, (IX + d) 2531{ 2532 B = readByte( addDispl(IX,fetchByte()) ); 2533} 2534 2535void opcode_dd_4c() // LD C, IXH 2536{ 2537 C = IX >> 8; 2538} 2539 2540void opcode_dd_4d() // LD C, IXL 2541{ 2542 C = IX & 0xFF; 2543} 2544 2545void opcode_dd_4e() // LD C, (IX + d) 2546{ 2547 C = readByte( addDispl(IX,fetchByte()) ); 2548} 2549 2550void opcode_dd_54() // LD D, IXH 2551{ 2552 D = IX >> 8; 2553} 2554 2555void opcode_dd_55() // LD D, IXL 2556{ 2557 D = IX & 0xFF; 2558} 2559 2560void opcode_dd_56() // LD D, (IX + d) 2561{ 2562 D = readByte( addDispl(IX,fetchByte()) ); 2563} 2564 2565void opcode_dd_5c() // LD E, IXH 2566{ 2567 E = IX >> 8; 2568} 2569 2570void opcode_dd_5d() // LD E, IXL 2571{ 2572 E = IX & 0xFF; 2573} 2574 2575void opcode_dd_5e() // LD E, (IX + d) 2576{ 2577 E = readByte( addDispl(IX,fetchByte()) ); 2578} 2579 2580void opcode_dd_60() // LD IXH, B 2581{ 2582 IX = (IX & 0xFF) | ((unsigned)B << 8); 2583} 2584 2585void opcode_dd_61() // LD IXH, C 2586{ 2587 IX = (IX & 0xFF) | ((unsigned)C << 8); 2588} 2589 2590void opcode_dd_62() // LD IXH, D 2591{ 2592 IX = (IX & 0xFF) | ((unsigned)D << 8); 2593} 2594 2595void opcode_dd_63() // LD IXH, E 2596{ 2597 IX = (IX & 0xFF) | ((unsigned)E << 8); 2598} 2599 2600void opcode_dd_64() // LD IXH, IXH 2601{ 2602} 2603 2604void opcode_dd_65() // LD IXH, IXL 2605{ 2606 IX = (IX & 0xFF) | ((IX << 8) & 0xFF00); 2607} 2608 2609void opcode_dd_66() // LD H, (IX + d) 2610{ 2611 H = readByte( addDispl(IX,fetchByte()) ); 2612} 2613 2614void opcode_dd_67() // LD IXH, A 2615{ 2616 IX = (IX & 0xFF) | ((unsigned)A << 8); 2617} 2618 2619void opcode_dd_68() // LD IXL, B 2620{ 2621 IX = (IX & 0xFF00) | B; 2622} 2623 2624void opcode_dd_69() // LD IXL, C 2625{ 2626 IX = (IX & 0xFF00) | C; 2627} 2628 2629void opcode_dd_6a() // LD IXL, D 2630{ 2631 IX = (IX & 0xFF00) | D; 2632} 2633 2634void opcode_dd_6b() // LD IXL, E 2635{ 2636 IX = (IX & 0xFF00) | E; 2637} 2638 2639void opcode_dd_6c() // LD IXL, IXH 2640{ 2641 IX = (IX & 0xFF00) | ((IX >> 8) & 0xFF); 2642} 2643 2644void opcode_dd_6d() // LD IXL, IXL 2645{ 2646} 2647 2648void opcode_dd_6e() // LD L, (IX + d) 2649{ 2650 L = readByte( addDispl(IX,fetchByte()) ); 2651} 2652 2653void opcode_dd_6f() // LD IXL, A 2654{ 2655 IX = (IX & 0xFF00) | A; 2656} 2657 2658void opcode_dd_70() // LD (IX + d), B 2659{ 2660 writeByte( addDispl(IX,fetchByte()), B ); 2661} 2662 2663void opcode_dd_71() // LD (IX + d), C 2664{ 2665 writeByte( addDispl(IX,fetchByte()), C ); 2666} 2667 2668void opcode_dd_72() // LD (IX + d), D 2669{ 2670 writeByte( addDispl(IX,fetchByte()), D ); 2671} 2672 2673void opcode_dd_73() // LD (IX + d), E 2674{ 2675 writeByte( addDispl(IX,fetchByte()), E ); 2676} 2677 2678void opcode_dd_74() // LD (IX + d), H 2679{ 2680 writeByte( addDispl(IX,fetchByte()), H ); 2681} 2682 2683void opcode_dd_75() // LD (IX + d), L 2684{ 2685 writeByte( addDispl(IX,fetchByte()), L ); 2686} 2687 2688void opcode_dd_77() // LD (IX + d), A 2689{ 2690 writeByte( addDispl(IX,fetchByte()), A ); 2691} 2692 2693void opcode_dd_7c() // LD A, IXH 2694{ 2695 A = IX >> 8; 2696} 2697 2698void opcode_dd_7d() // LD A, IXL 2699{ 2700 A = IX & 0xFF; 2701} 2702 2703void opcode_dd_7e() // LD A, (IX + d) 2704{ 2705 A = readByte( addDispl(IX,fetchByte()) ); 2706} 2707 2708void opcode_dd_84() // ADD A, IXH 2709{ 2710 addByte( IX >> 8, 0 ); 2711} 2712 2713void opcode_dd_85() // ADD A, IXL 2714{ 2715 addByte( IX & 0xFF, 0 ); 2716} 2717 2718void opcode_dd_86() // ADD A, (IX + d) 2719{ 2720 addByte( readByte( addDispl(IX,fetchByte()) ), 0 ); 2721} 2722 2723void opcode_dd_8c() // ADC A, IXH 2724{ 2725 addByte( IX >> 8, F & Carry ); 2726} 2727 2728void opcode_dd_8d() // ADC A, IXL 2729{ 2730 addByte( IX & 0xFF, F & Carry ); 2731} 2732 2733void opcode_dd_8e() // ADC A, (IX + d) 2734{ 2735 addByte( readByte( addDispl(IX,fetchByte()) ), F & Carry ); 2736} 2737 2738void opcode_dd_94() // SUB IXH 2739{ 2740 A = subByte( IX >> 8, 0 ); 2741} 2742 2743void opcode_dd_95() // SUB IXL 2744{ 2745 A = subByte( IX & 0xFF, 0 ); 2746} 2747 2748void opcode_dd_96() // SUB (IX + d) 2749{ 2750 A = subByte( readByte( addDispl(IX,fetchByte()) ), 0 ); 2751} 2752 2753void opcode_dd_9c() // SBC A, IXH 2754{ 2755 A = subByte( IX >> 8, F & Carry ); 2756} 2757 2758void opcode_dd_9d() // SBC A, IXL 2759{ 2760 A = subByte( IX & 0xFF, F & Carry ); 2761} 2762 2763void opcode_dd_9e() // SBC A, (IX + d) 2764{ 2765 A = subByte( readByte( addDispl(IX,fetchByte()) ), F & Carry ); 2766} 2767 2768void opcode_dd_a4() // AND IXH 2769{ 2770 A &= IX >> 8; 2771 setFlags35PSZ000(); 2772 F |= Halfcarry; 2773} 2774 2775void opcode_dd_a5() // AND IXL 2776{ 2777 A &= IX & 0xFF; 2778 setFlags35PSZ000(); 2779 F |= Halfcarry; 2780} 2781 2782void opcode_dd_a6() // AND (IX + d) 2783{ 2784 A &= readByte( addDispl(IX,fetchByte()) ); 2785 setFlags35PSZ000(); 2786 F |= Halfcarry; 2787} 2788 2789void opcode_dd_ac() // XOR IXH 2790{ 2791 A ^= IX >> 8; 2792 setFlags35PSZ000(); 2793} 2794 2795void opcode_dd_ad() // XOR IXL 2796{ 2797 A ^= IX & 0xFF; 2798 setFlags35PSZ000(); 2799} 2800 2801void opcode_dd_ae() // XOR (IX + d) 2802{ 2803 A ^= readByte( addDispl(IX,fetchByte()) ); 2804 setFlags35PSZ000(); 2805} 2806 2807void opcode_dd_b4() // OR IXH 2808{ 2809 A |= IX >> 8; 2810 setFlags35PSZ000(); 2811} 2812 2813void opcode_dd_b5() // OR IXL 2814{ 2815 A |= IX & 0xFF; 2816 setFlags35PSZ000(); 2817} 2818 2819void opcode_dd_b6() // OR (IX + d) 2820{ 2821 A |= readByte( addDispl(IX,fetchByte()) ); 2822 setFlags35PSZ000(); 2823} 2824 2825void opcode_dd_bc() // CP IXH 2826{ 2827 cmpByte( IX >> 8 ); 2828} 2829 2830void opcode_dd_bd() // CP IXL 2831{ 2832 cmpByte( IX & 0xFF ); 2833} 2834 2835void opcode_dd_be() // CP (IX + d) 2836{ 2837 cmpByte( readByte( addDispl(IX,fetchByte()) ) ); 2838} 2839 2840void opcode_dd_cb() // 2841{ 2842 do_opcode_xycb( IX ); 2843} 2844 2845void opcode_dd_e1() // POP IX 2846{ 2847 IX = readWord( SP ); 2848 SP += 2; 2849} 2850 2851void opcode_dd_e3() // EX (SP), IX 2852{ 2853 unsigned ix = IX; 2854 2855 IX = readWord( SP ); 2856 writeWord( SP, ix ); 2857} 2858 2859void opcode_dd_e5() // PUSH IX 2860{ 2861 SP -= 2; 2862 writeWord( SP, IX ); 2863} 2864 2865void opcode_dd_e9() // JP (IX) 2866{ 2867 PC = IX; 2868} 2869 2870void opcode_dd_f9() // LD SP, IX 2871{ 2872 SP = IX; 2873} 2874 2875OpcodeInfo 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 3132}; 3133 3134void opcode_ed_40() // IN B, (C) 3135{ 3136 B = inpReg(); 3137} 3138 3139void opcode_ed_41() // OUT (C), B 3140{ 3141 writePort( C, B ); 3142} 3143 3144void opcode_ed_42() // SBC HL, BC 3145{ 3146 unsigned char a; 3147 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; 3153} 3154 3155void opcode_ed_43() // LD (nn), BC 3156{ 3157 unsigned addr = fetchWord(); 3158 3159 writeByte( addr, C ); 3160 writeByte( addr+1, B ); 3161} 3162 3163void opcode_ed_44() // NEG 3164{ 3165 unsigned char a = A; 3166 3167 A = 0; 3168 A = subByte( a, 0 ); 3169} 3170 3171void opcode_ed_45() // RETN 3172{ 3173 retFromSub(); 3174 iflags_ &= ~IFF1; 3175 if( iflags_ & IFF2 ) iflags_ |= IFF1; 3176} 3177 3178void opcode_ed_46() // IM 0 3179{ 3180 setInterruptMode( 0 ); 3181} 3182 3183void opcode_ed_47() // LD I, A 3184{ 3185 I = A; 3186} 3187 3188void opcode_ed_48() // IN C, (C) 3189{ 3190 C = inpReg(); 3191} 3192 3193void opcode_ed_49() // OUT (C), C 3194{ 3195 writePort( C, C ); 3196} 3197 3198void opcode_ed_4a() // ADC HL, BC 3199{ 3200 unsigned char a; 3201 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; 3207} 3208 3209void opcode_ed_4b() // LD BC, (nn) 3210{ 3211 unsigned addr = fetchWord(); 3212 3213 C = readByte( addr ); 3214 B = readByte( addr+1 ); 3215} 3216 3217void opcode_ed_4c() // NEG 3218{ 3219 opcode_ed_44(); 3220} 3221 3222void opcode_ed_4d() // RETI 3223{ 3224 retFromSub(); 3225 //onReturnFromInterrupt(); 3226} 3227 3228void opcode_ed_4e() // IM 0/1 3229{ 3230 setInterruptMode( 0 ); 3231} 3232 3233void opcode_ed_4f() // LD R, A 3234{ 3235 R = A; 3236} 3237 3238void opcode_ed_50() // IN D, (C) 3239{ 3240 D = inpReg(); 3241} 3242 3243void opcode_ed_51() // OUT (C), D 3244{ 3245 writePort( C, D ); 3246} 3247 3248void opcode_ed_52() // SBC HL, DE 3249{ 3250 unsigned char a; 3251 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; 3257} 3258 3259void opcode_ed_53() // LD (nn), DE 3260{ 3261 unsigned addr = fetchWord(); 3262 3263 writeByte( addr, E ); 3264 writeByte( addr+1, D ); 3265} 3266 3267void opcode_ed_54() // NEG 3268{ 3269 opcode_ed_44(); 3270} 3271 3272void opcode_ed_55() // RETN 3273{ 3274 opcode_ed_45(); 3275} 3276 3277void opcode_ed_56() // IM 1 3278{ 3279 setInterruptMode( 1 ); 3280} 3281 3282void opcode_ed_57() // LD A, I 3283{ 3284 A = I; 3285 setFlags35PSZ(); 3286 F &= ~(Halfcarry | Parity | AddSub); 3287 if( iflags_ & IFF2 ) F |= Parity; 3288} 3289 3290void opcode_ed_58() // IN E, (C) 3291{ 3292 E = inpReg(); 3293} 3294 3295void opcode_ed_59() // OUT (C), E 3296{ 3297 writePort( C, E ); 3298} 3299 3300void opcode_ed_5a() // ADC HL, DE 3301{ 3302 unsigned char a; 3303 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; 3309} 3310 3311void opcode_ed_5b() // LD DE, (nn) 3312{ 3313 unsigned addr = fetchWord(); 3314 3315 E = readByte( addr ); 3316 D = readByte( addr+1 ); 3317} 3318 3319void opcode_ed_5c() // NEG 3320{ 3321 opcode_ed_44(); 3322} 3323 3324void opcode_ed_5d() // RETN 3325{ 3326 opcode_ed_45(); 3327} 3328 3329void opcode_ed_5e() // IM 2 3330{ 3331 setInterruptMode( 2 ); 3332} 3333 3334void opcode_ed_5f() // LD A, R 3335{ 3336 A = R; 3337 setFlags35PSZ(); 3338 F &= ~(Halfcarry | Parity | AddSub); 3339 if( iflags_ & IFF2 ) F |= Parity; 3340} 3341 3342void opcode_ed_60() // IN H, (C) 3343{ 3344 H = inpReg(); 3345} 3346 3347void opcode_ed_61() // OUT (C), H 3348{ 3349 writePort( C, H ); 3350} 3351 3352void opcode_ed_62() // SBC HL, HL 3353{ 3354 unsigned char a; 3355 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; 3361} 3362 3363void opcode_ed_63() // LD (nn), HL 3364{ 3365 unsigned addr = fetchWord(); 3366 3367 writeByte( addr, L ); 3368 writeByte( addr+1, H ); 3369} 3370 3371void opcode_ed_64() // NEG 3372{ 3373 opcode_ed_44(); 3374} 3375 3376void opcode_ed_65() // RETN 3377{ 3378 opcode_ed_45(); 3379} 3380 3381void opcode_ed_66() // IM 0 3382{ 3383 setInterruptMode( 0 ); 3384} 3385 3386void opcode_ed_67() // RRD 3387{ 3388 unsigned char x = readByte( HL() ); 3389 3390 writeByte( HL(), (A << 4) | (x >> 4) ); 3391 A = (A & 0xF0) | (x & 0x0F); 3392 setFlags35PSZ(); 3393 F &= ~(Halfcarry | AddSub); 3394} 3395 3396void opcode_ed_68() // IN L, (C) 3397{ 3398 L = inpReg(); 3399} 3400 3401void opcode_ed_69() // OUT (C), L 3402{ 3403 writePort( C, L ); 3404} 3405 3406void opcode_ed_6a() // ADC HL, HL 3407{ 3408 unsigned char a; 3409 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; 3415} 3416 3417void opcode_ed_6b() // LD HL, (nn) 3418{ 3419 unsigned addr = fetchWord(); 3420 3421 L = readByte( addr ); 3422 H = readByte( addr+1 ); 3423} 3424 3425void opcode_ed_6c() // NEG 3426{ 3427 opcode_ed_44(); 3428} 3429 3430void opcode_ed_6d() // RETN 3431{ 3432 opcode_ed_45(); 3433} 3434 3435void opcode_ed_6e() // IM 0/1 3436{ 3437 setInterruptMode( 0 ); 3438} 3439 3440void opcode_ed_6f() // RLD 3441{ 3442 unsigned char x = readByte( HL() ); 3443 3444 writeByte( HL(), (x << 4) | (A & 0x0F) ); 3445 A = (A & 0xF0) | (x >> 4); 3446 setFlags35PSZ(); 3447 F &= ~(Halfcarry | AddSub); 3448} 3449 3450void opcode_ed_70() // IN (C) / IN F, (C) 3451{ 3452 inpReg(); 3453} 3454 3455void opcode_ed_71() // OUT (C), 0 3456{ 3457 writePort( C, 0 ); 3458} 3459 3460void opcode_ed_72() // SBC HL, SP 3461{ 3462 unsigned char a; 3463 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; 3469} 3470 3471void opcode_ed_73() // LD (nn), SP 3472{ 3473 writeWord( fetchWord(), SP ); 3474} 3475 3476void opcode_ed_74() // NEG 3477{ 3478 opcode_ed_44(); 3479} 3480 3481void opcode_ed_75() // RETN 3482{ 3483 opcode_ed_45(); 3484} 3485 3486void opcode_ed_76() // IM 1 3487{ 3488 setInterruptMode( 1 ); 3489} 3490 3491void opcode_ed_78() // IN A, (C) 3492{ 3493 A = inpReg(); 3494} 3495 3496void opcode_ed_79() // OUT (C), A 3497{ 3498 writePort( C, A ); 3499} 3500 3501void opcode_ed_7a() // ADC HL, SP 3502{ 3503 unsigned char a; 3504 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; 3510} 3511 3512void opcode_ed_7b() // LD SP, (nn) 3513{ 3514 SP = readWord( fetchWord() ); 3515} 3516 3517void opcode_ed_7c() // NEG 3518{ 3519 opcode_ed_44(); 3520} 3521 3522void opcode_ed_7d() // RETN 3523{ 3524 opcode_ed_45(); 3525} 3526 3527void opcode_ed_7e() // IM 2 3528{ 3529 setInterruptMode( 2 ); 3530} 3531 3532void opcode_ed_a0() // LDI 3533{ 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; 3540} 3541 3542void opcode_ed_a1() // CPI 3543{ 3544 unsigned char f = F; 3545 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; 3551} 3552 3553void opcode_ed_a2() // INI 3554{ 3555 writeByte( HL(), readPort( C ) ); 3556 if( ++L == 0 ) ++H; // HL++ 3557 B = decByte( B ); 3558} 3559 3560void opcode_ed_a3() // OUTI 3561{ 3562 writePort( C, readByte( HL() ) ); 3563 if( ++L == 0 ) ++H; // HL++ 3564 B = decByte( B ); 3565} 3566 3567void opcode_ed_a8() // LDD 3568{ 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; 3575} 3576 3577void opcode_ed_a9() // CPD 3578{ 3579 unsigned char f = F; 3580 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; 3586} 3587 3588void opcode_ed_aa() // IND 3589{ 3590 writeByte( HL(), readPort( C ) ); 3591 if( L-- == 0 ) --H; // HL-- 3592 B = decByte( B ); 3593} 3594 3595void opcode_ed_ab() // OUTD 3596{ 3597 writePort( C, readByte( HL() ) ); 3598 if( L-- == 0 ) --H; // HL-- 3599 B = decByte( B ); 3600} 3601 3602void opcode_ed_b0() // LDIR 3603{ 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) 3608 } 3609} 3610 3611void opcode_ed_b1() // CPIR 3612{ 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) 3617 } 3618} 3619 3620void opcode_ed_b2() // INIR 3621{ 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) 3626 } 3627} 3628 3629void opcode_ed_b3() // OTIR 3630{ 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) 3635 } 3636} 3637 3638void opcode_ed_b8() // LDDR 3639{ 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) 3644 } 3645} 3646 3647void opcode_ed_b9() // CPDR 3648{ 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) 3653 } 3654} 3655 3656void opcode_ed_ba() // INDR 3657{ 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) 3662 } 3663} 3664 3665void opcode_ed_bb() // OTDR 3666{ 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) 3671 } 3672} 3673 3674OpcodeInfo 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 3931}; 3932 3933void opcode_fd_09() // ADD IY, BC 3934{ 3935 unsigned rr = BC(); 3936 3937 F &= (Zero | Sign | Parity); 3938 if( ((IY & 0xFFF)+(rr & 0xFFF)) > 0xFFF ) F |= Halfcarry; 3939 IY += rr; 3940 if( IY & 0x10000 ) F |= Carry; 3941} 3942 3943void opcode_fd_19() // ADD IY, DE 3944{ 3945 unsigned rr = DE(); 3946 3947 F &= (Zero | Sign | Parity); 3948 if( ((IY & 0xFFF)+(rr & 0xFFF)) > 0xFFF ) F |= Halfcarry; 3949 IY += rr; 3950 if( IY & 0x10000 ) F |= Carry; 3951} 3952 3953void opcode_fd_21() // LD IY, nn 3954{ 3955 IY = fetchWord(); 3956} 3957 3958void opcode_fd_22() // LD (nn), IY 3959{ 3960 writeWord( fetchWord(), IY ); 3961} 3962 3963void opcode_fd_23() // INC IY 3964{ 3965 IY++; 3966} 3967 3968void opcode_fd_24() // INC IYH 3969{ 3970 IY = (IY & 0xFF) | ((unsigned)incByte( IY >> 8 ) << 8); 3971} 3972 3973void opcode_fd_25() // DEC IYH 3974{ 3975 IY = (IY & 0xFF) | ((unsigned)decByte( IY >> 8 ) << 8); 3976} 3977 3978void opcode_fd_26() // LD IYH, n 3979{ 3980 IY = (IY & 0xFF) | ((unsigned)fetchByte() << 8); 3981} 3982 3983void opcode_fd_29() // ADD IY, IY 3984{ 3985 F &= (Zero | Sign | Parity); 3986 if( IY & 0x800 ) F |= Halfcarry; 3987 IY += IY; 3988 if( IY & 0x10000 ) F |= Carry; 3989} 3990 3991void opcode_fd_2a() // LD IY, (nn) 3992{ 3993 IY = readWord( fetchWord() ); 3994} 3995 3996void opcode_fd_2b() // DEC IY 3997{ 3998 IY--; 3999} 4000 4001void opcode_fd_2c() // INC IYL 4002{ 4003 IY = (IY & 0xFF00) | incByte( IY & 0xFF ); 4004} 4005 4006void opcode_fd_2d() // DEC IYL 4007{ 4008 IY = (IY & 0xFF00) | decByte( IY & 0xFF ); 4009} 4010 4011void opcode_fd_2e() // LD IYL, n 4012{ 4013 IY = (IY & 0xFF00) | fetchByte(); 4014} 4015 4016void opcode_fd_34() // INC (IY + d) 4017{ 4018 unsigned addr = addDispl( IY, fetchByte() ); 4019 4020 writeByte( addr, incByte( readByte( addr ) ) ); 4021} 4022 4023void opcode_fd_35() // DEC (IY + d) 4024{ 4025 unsigned addr = addDispl( IY, fetchByte() ); 4026 4027 writeByte( addr, decByte( readByte( addr ) ) ); 4028} 4029 4030void opcode_fd_36() // LD (IY + d), n 4031{ 4032 unsigned addr = addDispl( IY, fetchByte() ); 4033 4034 writeByte( addr, fetchByte() ); 4035} 4036 4037void opcode_fd_39() // ADD IY, SP 4038{ 4039 F &= (Zero | Sign | Parity); 4040 if( ((IY & 0xFFF)+(SP & 0xFFF)) > 0xFFF ) F |= Halfcarry; 4041 IY += SP; 4042 if( IY & 0x10000 ) F |= Carry; 4043} 4044 4045void opcode_fd_44() // LD B, IYH 4046{ 4047 B = IY >> 8; 4048} 4049 4050void opcode_fd_45() // LD B, IYL 4051{ 4052 B = IY & 0xFF; 4053} 4054 4055void opcode_fd_46() // LD B, (IY + d) 4056{ 4057 B = readByte( addDispl(IY,fetchByte()) ); 4058} 4059 4060void opcode_fd_4c() // LD C, IYH 4061{ 4062 C = IY >> 8; 4063} 4064 4065void opcode_fd_4d() // LD C, IYL 4066{ 4067 C = IY & 0xFF; 4068} 4069 4070void opcode_fd_4e() // LD C, (IY + d) 4071{ 4072 C = readByte( addDispl(IY,fetchByte()) ); 4073} 4074 4075void opcode_fd_54() // LD D, IYH 4076{ 4077 D = IY >> 8; 4078} 4079 4080void opcode_fd_55() // LD D, IYL 4081{ 4082 D = IY & 0xFF; 4083} 4084 4085void opcode_fd_56() // LD D, (IY + d) 4086{ 4087 D = readByte( addDispl(IY,fetchByte()) ); 4088} 4089 4090void opcode_fd_5c() // LD E, IYH 4091{ 4092 E = IY >> 8; 4093} 4094 4095void opcode_fd_5d() // LD E, IYL 4096{ 4097 E = IY & 0xFF; 4098} 4099 4100void opcode_fd_5e() // LD E, (IY + d) 4101{ 4102 E = readByte( addDispl(IY,fetchByte()) ); 4103} 4104 4105void opcode_fd_60() // LD IYH, B 4106{ 4107 IY = (IY & 0xFF) | ((unsigned)B << 8); 4108} 4109 4110void opcode_fd_61() // LD IYH, C 4111{ 4112 IY = (IY & 0xFF) | ((unsigned)C << 8); 4113} 4114 4115void opcode_fd_62() // LD IYH, D 4116{ 4117 IY = (IY & 0xFF) | ((unsigned)D << 8); 4118} 4119 4120void opcode_fd_63() // LD IYH, E 4121{ 4122 IY = (IY & 0xFF) | ((unsigned)E << 8); 4123} 4124 4125void opcode_fd_64() // LD IYH, IYH 4126{ 4127} 4128 4129void opcode_fd_65() // LD IYH, IYL 4130{ 4131 IY = (IY & 0xFF) | ((IY << 8) & 0xFF00); 4132} 4133 4134void opcode_fd_66() // LD H, (IY + d) 4135{ 4136 H = readByte( addDispl(IY,fetchByte()) ); 4137} 4138 4139void opcode_fd_67() // LD IYH, A 4140{ 4141 IY = (IY & 0xFF) | ((unsigned)A << 8); 4142} 4143 4144void opcode_fd_68() // LD IYL, B 4145{ 4146 IY = (IY & 0xFF00) | B; 4147} 4148 4149void opcode_fd_69() // LD IYL, C 4150{ 4151 IY = (IY & 0xFF00) | C; 4152} 4153 4154void opcode_fd_6a() // LD IYL, D 4155{ 4156 IY = (IY & 0xFF00) | D; 4157} 4158 4159void opcode_fd_6b() // LD IYL, E 4160{ 4161 IY = (IY & 0xFF00) | E; 4162} 4163 4164void opcode_fd_6c() // LD IYL, IYH 4165{ 4166 IY = (IY & 0xFF00) | ((IY >> 8) & 0xFF); 4167} 4168 4169void opcode_fd_6d() // LD IYL, IYL 4170{ 4171} 4172 4173void opcode_fd_6e() // LD L, (IY + d) 4174{ 4175 L = readByte( addDispl(IY,fetchByte()) ); 4176} 4177 4178void opcode_fd_6f() // LD IYL, A 4179{ 4180 IY = (IY & 0xFF00) | A; 4181} 4182 4183void opcode_fd_70() // LD (IY + d), B 4184{ 4185 writeByte( addDispl(IY,fetchByte()), B ); 4186} 4187 4188void opcode_fd_71() // LD (IY + d), C 4189{ 4190 writeByte( addDispl(IY,fetchByte()), C ); 4191} 4192 4193void opcode_fd_72() // LD (IY + d), D 4194{ 4195 writeByte( addDispl(IY,fetchByte()), D ); 4196} 4197 4198void opcode_fd_73() // LD (IY + d), E 4199{ 4200 writeByte( addDispl(IY,fetchByte()), E ); 4201} 4202 4203void opcode_fd_74() // LD (IY + d), H 4204{ 4205 writeByte( addDispl(IY,fetchByte()), H ); 4206} 4207 4208void opcode_fd_75() // LD (IY + d), L 4209{ 4210 writeByte( addDispl(IY,fetchByte()), L ); 4211} 4212 4213void opcode_fd_77() // LD (IY + d), A 4214{ 4215 writeByte( addDispl(IY,fetchByte()), A ); 4216} 4217 4218void opcode_fd_7c() // LD A, IYH 4219{ 4220 A = IY >> 8; 4221} 4222 4223void opcode_fd_7d() // LD A, IYL 4224{ 4225 A = IY & 0xFF; 4226} 4227 4228void opcode_fd_7e() // LD A, (IY + d) 4229{ 4230 A = readByte( addDispl(IY,fetchByte()) ); 4231} 4232 4233void opcode_fd_84() // ADD A, IYH 4234{ 4235 addByte( IY >> 8, 0 ); 4236} 4237 4238void opcode_fd_85() // ADD A, IYL 4239{ 4240 addByte( IY & 0xFF, 0 ); 4241} 4242 4243void opcode_fd_86() // ADD A, (IY + d) 4244{ 4245 addByte( readByte( addDispl(IY,fetchByte()) ), 0 ); 4246} 4247 4248void opcode_fd_8c() // ADC A, IYH 4249{ 4250 addByte( IY >> 8, F & Carry ); 4251} 4252 4253void opcode_fd_8d() // ADC A, IYL 4254{ 4255 addByte( IY & 0xFF, F & Carry ); 4256} 4257 4258void opcode_fd_8e() // ADC A, (IY + d) 4259{ 4260 addByte( readByte( addDispl(IY,fetchByte()) ), F & Carry ); 4261} 4262 4263void opcode_fd_94() // SUB IYH 4264{ 4265 A = subByte( IY >> 8, 0 ); 4266} 4267 4268void opcode_fd_95() // SUB IYL 4269{ 4270 A = subByte( IY & 0xFF, 0 ); 4271} 4272 4273void opcode_fd_96() // SUB (IY + d) 4274{ 4275 A = subByte( readByte( addDispl(IY,fetchByte()) ), 0 ); 4276} 4277 4278void opcode_fd_9c() // SBC A, IYH 4279{ 4280 A = subByte( IY >> 8, F & Carry ); 4281} 4282 4283void opcode_fd_9d() // SBC A, IYL 4284{ 4285 A = subByte( IY & 0xFF, F & Carry ); 4286} 4287 4288void opcode_fd_9e() // SBC A, (IY + d) 4289{ 4290 A = subByte( readByte( addDispl(IY,fetchByte()) ), F & Carry ); 4291} 4292 4293void opcode_fd_a4() // AND IYH 4294{ 4295 A &= IY >> 8; 4296 setFlags35PSZ000(); 4297 F |= Halfcarry; 4298} 4299 4300void opcode_fd_a5() // AND IYL 4301{ 4302 A &= IY & 0xFF; 4303 setFlags35PSZ000(); 4304 F |= Halfcarry; 4305} 4306 4307void opcode_fd_a6() // AND (IY + d) 4308{ 4309 A &= readByte( addDispl(IY,fetchByte()) ); 4310 setFlags35PSZ000(); 4311 F |= Halfcarry; 4312} 4313 4314void opcode_fd_ac() // XOR IYH 4315{ 4316 A ^= IY >> 8; 4317 setFlags35PSZ000(); 4318} 4319 4320void opcode_fd_ad() // XOR IYL 4321{ 4322 A ^= IY & 0xFF; 4323 setFlags35PSZ000(); 4324} 4325 4326void opcode_fd_ae() // XOR (IY + d) 4327{ 4328 A ^= readByte( addDispl(IY,fetchByte()) ); 4329 setFlags35PSZ000(); 4330} 4331 4332void opcode_fd_b4() // OR IYH 4333{ 4334 A |= IY >> 8; 4335 setFlags35PSZ000(); 4336} 4337 4338void opcode_fd_b5() // OR IYL 4339{ 4340 A |= IY & 0xFF; 4341 setFlags35PSZ000(); 4342} 4343 4344void opcode_fd_b6() // OR (IY + d) 4345{ 4346 A |= readByte( addDispl(IY,fetchByte()) ); 4347 setFlags35PSZ000(); 4348} 4349 4350void opcode_fd_bc() // CP IYH 4351{ 4352 cmpByte( IY >> 8 ); 4353} 4354 4355void opcode_fd_bd() // CP IYL 4356{ 4357 cmpByte( IY & 0xFF ); 4358} 4359 4360void opcode_fd_be() // CP (IY + d) 4361{ 4362 cmpByte( readByte( addDispl(IY,fetchByte()) ) ); 4363} 4364 4365void opcode_fd_cb() // 4366{ 4367 do_opcode_xycb( IY ); 4368} 4369 4370void opcode_fd_e1() // POP IY 4371{ 4372 IY = readWord( SP ); 4373 SP += 2; 4374} 4375 4376void opcode_fd_e3() // EX (SP), IY 4377{ 4378 unsigned iy = IY; 4379 4380 IY = readWord( SP ); 4381 writeWord( SP, iy ); 4382} 4383 4384void opcode_fd_e5() // PUSH IY 4385{ 4386 SP -= 2; 4387 writeWord( SP, IY ); 4388} 4389 4390void opcode_fd_e9() // JP (IY) 4391{ 4392 PC = IY; 4393} 4394 4395void opcode_fd_f9() // LD SP, IY 4396{ 4397 SP = IY; 4398} 4399 4400OpcodeInfoXY 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) 4657}; 4658 4659unsigned do_opcode_xycb( unsigned xy ) 4660{ 4661 xy = addDispl( xy, fetchByte() ); 4662 4663 unsigned op = fetchByte(); 4664 4665 cycles_ += OpInfoXYCB_[ op ].cycles; 4666 4667 OpInfoXYCB_[ op ].handler( xy ); 4668 4669 return xy; 4670} 4671 4672void opcode_xycb_00( unsigned xy ) // LD B, RLC (IX + d) 4673{ 4674 B = rotateLeftCarry( readByte(xy) ); 4675 writeByte( xy, B ); 4676} 4677 4678void opcode_xycb_01( unsigned xy ) // LD C, RLC (IX + d) 4679{ 4680 C = rotateLeftCarry( readByte(xy) ); 4681 writeByte( xy, C ); 4682} 4683 4684void opcode_xycb_02( unsigned xy ) // LD D, RLC (IX + d) 4685{ 4686 D = rotateLeftCarry( readByte(xy) ); 4687 writeByte( xy, D ); 4688} 4689 4690void opcode_xycb_03( unsigned xy ) // LD E, RLC (IX + d) 4691{ 4692 E = rotateLeftCarry( readByte(xy) ); 4693 writeByte( xy, E ); 4694} 4695 4696void opcode_xycb_04( unsigned xy ) // LD H, RLC (IX + d) 4697{ 4698 H = rotateLeftCarry( readByte(xy) ); 4699 writeByte( xy, H ); 4700} 4701 4702void opcode_xycb_05( unsigned xy ) // LD L, RLC (IX + d) 4703{ 4704 L = rotateLeftCarry( readByte(xy) ); 4705 writeByte( xy, L ); 4706} 4707 4708void opcode_xycb_06( unsigned xy ) // RLC (IX + d) 4709{ 4710 writeByte( xy, rotateLeftCarry( readByte(xy) ) ); 4711} 4712 4713void opcode_xycb_07( unsigned xy ) // LD A, RLC (IX + d) 4714{ 4715 A = rotateLeftCarry( readByte(xy) ); 4716 writeByte( xy, A ); 4717} 4718 4719void opcode_xycb_08( unsigned xy ) // LD B, RRC (IX + d) 4720{ 4721 B = rotateRightCarry( readByte(xy) ); 4722 writeByte( xy, B ); 4723} 4724 4725void opcode_xycb_09( unsigned xy ) // LD C, RRC (IX + d) 4726{ 4727 C = rotateRightCarry( readByte(xy) ); 4728 writeByte( xy, C ); 4729} 4730 4731void opcode_xycb_0a( unsigned xy ) // LD D, RRC (IX + d) 4732{ 4733 D = rotateRightCarry( readByte(xy) ); 4734 writeByte( xy, D ); 4735} 4736 4737void opcode_xycb_0b( unsigned xy ) // LD E, RRC (IX + d) 4738{ 4739 E = rotateRightCarry( readByte(xy) ); 4740 writeByte( xy, E ); 4741} 4742 4743void opcode_xycb_0c( unsigned xy ) // LD H, RRC (IX + d) 4744{ 4745 H = rotateRightCarry( readByte(xy) ); 4746 writeByte( xy, H ); 4747} 4748 4749void opcode_xycb_0d( unsigned xy ) // LD L, RRC (IX + d) 4750{ 4751 L = rotateRightCarry( readByte(xy) ); 4752 writeByte( xy, L ); 4753} 4754 4755void opcode_xycb_0e( unsigned xy ) // RRC (IX + d) 4756{ 4757 writeByte( xy, rotateRightCarry( readByte(xy) ) ); 4758} 4759 4760void opcode_xycb_0f( unsigned xy ) // LD A, RRC (IX + d) 4761{ 4762 A = rotateRightCarry( readByte(xy) ); 4763 writeByte( xy, A ); 4764} 4765 4766void opcode_xycb_10( unsigned xy ) // LD B, RL (IX + d) 4767{ 4768 B = rotateLeft( readByte(xy) ); 4769 writeByte( xy, B ); 4770} 4771 4772void opcode_xycb_11( unsigned xy ) // LD C, RL (IX + d) 4773{ 4774 C = rotateLeft( readByte(xy) ); 4775 writeByte( xy, C ); 4776} 4777 4778void opcode_xycb_12( unsigned xy ) // LD D, RL (IX + d) 4779{ 4780 D = rotateLeft( readByte(xy) ); 4781 writeByte( xy, D ); 4782} 4783 4784void opcode_xycb_13( unsigned xy ) // LD E, RL (IX + d) 4785{ 4786 E = rotateLeft( readByte(xy) ); 4787 writeByte( xy, E ); 4788} 4789 4790void opcode_xycb_14( unsigned xy ) // LD H, RL (IX + d) 4791{ 4792 H = rotateLeft( readByte(xy) ); 4793 writeByte( xy, H ); 4794} 4795 4796void opcode_xycb_15( unsigned xy ) // LD L, RL (IX + d) 4797{ 4798 L = rotateLeft( readByte(xy) ); 4799 writeByte( xy, L ); 4800} 4801 4802void opcode_xycb_16( unsigned xy ) // RL (IX + d) 4803{ 4804 writeByte( xy, rotateLeft( readByte(xy) ) ); 4805} 4806 4807void opcode_xycb_17( unsigned xy ) // LD A, RL (IX + d) 4808{ 4809 A = rotateLeft( readByte(xy) ); 4810 writeByte( xy, A ); 4811} 4812 4813void opcode_xycb_18( unsigned xy ) // LD B, RR (IX + d) 4814{ 4815 B = rotateRight( readByte(xy) ); 4816 writeByte( xy, B ); 4817} 4818 4819void opcode_xycb_19( unsigned xy ) // LD C, RR (IX + d) 4820{ 4821 C = rotateRight( readByte(xy) ); 4822 writeByte( xy, C ); 4823} 4824 4825void opcode_xycb_1a( unsigned xy ) // LD D, RR (IX + d) 4826{ 4827 D = rotateRight( readByte(xy) ); 4828 writeByte( xy, D ); 4829} 4830 4831void opcode_xycb_1b( unsigned xy ) // LD E, RR (IX + d) 4832{ 4833 E = rotateRight( readByte(xy) ); 4834 writeByte( xy, E ); 4835} 4836 4837void opcode_xycb_1c( unsigned xy ) // LD H, RR (IX + d) 4838{ 4839 H = rotateRight( readByte(xy) ); 4840 writeByte( xy, H ); 4841} 4842 4843void opcode_xycb_1d( unsigned xy ) // LD L, RR (IX + d) 4844{ 4845 L = rotateRight( readByte(xy) ); 4846 writeByte( xy, L ); 4847} 4848 4849void opcode_xycb_1e( unsigned xy ) // RR (IX + d) 4850{ 4851 writeByte( xy, rotateRight( readByte(xy) ) ); 4852} 4853 4854void opcode_xycb_1f( unsigned xy ) // LD A, RR (IX + d) 4855{ 4856 A = rotateRight( readByte(xy) ); 4857 writeByte( xy, A ); 4858} 4859 4860void opcode_xycb_20( unsigned xy ) // LD B, SLA (IX + d) 4861{ 4862 B = shiftLeft( readByte(xy) ); 4863 writeByte( xy, B ); 4864} 4865 4866void opcode_xycb_21( unsigned xy ) // LD C, SLA (IX + d) 4867{ 4868 C = shiftLeft( readByte(xy) ); 4869 writeByte( xy, C ); 4870} 4871 4872void opcode_xycb_22( unsigned xy ) // LD D, SLA (IX + d) 4873{ 4874 D = shiftLeft( readByte(xy) ); 4875 writeByte( xy, D ); 4876} 4877 4878void opcode_xycb_23( unsigned xy ) // LD E, SLA (IX + d) 4879{ 4880 E = shiftLeft( readByte(xy) ); 4881 writeByte( xy, E ); 4882} 4883 4884void opcode_xycb_24( unsigned xy ) // LD H, SLA (IX + d) 4885{ 4886 H = shiftLeft( readByte(xy) ); 4887 writeByte( xy, H ); 4888} 4889 4890void opcode_xycb_25( unsigned xy ) // LD L, SLA (IX + d) 4891{ 4892 L = shiftLeft( readByte(xy) ); 4893 writeByte( xy, L ); 4894} 4895 4896void opcode_xycb_26( unsigned xy ) // SLA (IX + d) 4897{ 4898 writeByte( xy, shiftLeft( readByte(xy) ) ); 4899} 4900 4901void opcode_xycb_27( unsigned xy ) // LD A, SLA (IX + d) 4902{ 4903 A = shiftLeft( readByte(xy) ); 4904 writeByte( xy, A ); 4905} 4906 4907void opcode_xycb_28( unsigned xy ) // LD B, SRA (IX + d) 4908{ 4909 B = shiftRightArith( readByte(xy) ); 4910 writeByte( xy, B ); 4911} 4912 4913void opcode_xycb_29( unsigned xy ) // LD C, SRA (IX + d) 4914{ 4915 C = shiftRightArith( readByte(xy) ); 4916 writeByte( xy, C ); 4917} 4918 4919void opcode_xycb_2a( unsigned xy ) // LD D, SRA (IX + d) 4920{ 4921 D = shiftRightArith( readByte(xy) ); 4922 writeByte( xy, D ); 4923} 4924 4925void opcode_xycb_2b( unsigned xy ) // LD E, SRA (IX + d) 4926{ 4927 E = shiftRightArith( readByte(xy) ); 4928 writeByte( xy, E ); 4929} 4930 4931void opcode_xycb_2c( unsigned xy ) // LD H, SRA (IX + d) 4932{ 4933 H = shiftRightArith( readByte(xy) ); 4934 writeByte( xy, H ); 4935} 4936 4937void opcode_xycb_2d( unsigned xy ) // LD L, SRA (IX + d) 4938{ 4939 L = shiftRightArith( readByte(xy) ); 4940 writeByte( xy, L ); 4941} 4942 4943void opcode_xycb_2e( unsigned xy ) // SRA (IX + d) 4944{ 4945 writeByte( xy, shiftRightArith( readByte(xy) ) ); 4946} 4947 4948void opcode_xycb_2f( unsigned xy ) // LD A, SRA (IX + d) 4949{ 4950 A = shiftRightArith( readByte(xy) ); 4951 writeByte( xy, A ); 4952} 4953 4954void opcode_xycb_30( unsigned xy ) // LD B, SLL (IX + d) 4955{ 4956 B = shiftLeft( readByte(xy) ) | 0x01; 4957 writeByte( xy, B ); 4958} 4959 4960void opcode_xycb_31( unsigned xy ) // LD C, SLL (IX + d) 4961{ 4962 C = shiftLeft( readByte(xy) ) | 0x01; 4963 writeByte( xy, C ); 4964} 4965 4966void opcode_xycb_32( unsigned xy ) // LD D, SLL (IX + d) 4967{ 4968 D = shiftLeft( readByte(xy) ) | 0x01; 4969 writeByte( xy, D ); 4970} 4971 4972void opcode_xycb_33( unsigned xy ) // LD E, SLL (IX + d) 4973{ 4974 E = shiftLeft( readByte(xy) ) | 0x01; 4975 writeByte( xy, E ); 4976} 4977 4978void opcode_xycb_34( unsigned xy ) // LD H, SLL (IX + d) 4979{ 4980 H = shiftLeft( readByte(xy) ) | 0x01; 4981 writeByte( xy, H ); 4982} 4983 4984void opcode_xycb_35( unsigned xy ) // LD L, SLL (IX + d) 4985{ 4986 L = shiftLeft( readByte(xy) ) | 0x01; 4987 writeByte( xy, L ); 4988} 4989 4990void opcode_xycb_36( unsigned xy ) // SLL (IX + d) 4991{ 4992 writeByte( xy, shiftLeft( readByte(xy) ) | 0x01 ); 4993} 4994 4995void opcode_xycb_37( unsigned xy ) // LD A, SLL (IX + d) 4996{ 4997 A = shiftLeft( readByte(xy) ) | 0x01; 4998 writeByte( xy, A ); 4999} 5000 5001void opcode_xycb_38( unsigned xy ) // LD B, SRL (IX + d) 5002{ 5003 B = shiftRightLogical( readByte(xy) ); 5004 writeByte( xy, B ); 5005} 5006 5007void opcode_xycb_39( unsigned xy ) // LD C, SRL (IX + d) 5008{ 5009 C = shiftRightLogical( readByte(xy) ); 5010 writeByte( xy, C ); 5011} 5012 5013void opcode_xycb_3a( unsigned xy ) // LD D, SRL (IX + d) 5014{ 5015 D = shiftRightLogical( readByte(xy) ); 5016 writeByte( xy, D ); 5017} 5018 5019void opcode_xycb_3b( unsigned xy ) // LD E, SRL (IX + d) 5020{ 5021 E = shiftRightLogical( readByte(xy) ); 5022 writeByte( xy, E ); 5023} 5024 5025void opcode_xycb_3c( unsigned xy ) // LD H, SRL (IX + d) 5026{ 5027 H = shiftRightLogical( readByte(xy) ); 5028 writeByte( xy, H ); 5029} 5030 5031void opcode_xycb_3d( unsigned xy ) // LD L, SRL (IX + d) 5032{ 5033 L = shiftRightLogical( readByte(xy) ); 5034 writeByte( xy, L ); 5035} 5036 5037void opcode_xycb_3e( unsigned xy ) // SRL (IX + d) 5038{ 5039 writeByte( xy, shiftRightLogical( readByte(xy) ) ); 5040} 5041 5042void opcode_xycb_3f( unsigned xy ) // LD A, SRL (IX + d) 5043{ 5044 A = shiftRightLogical( readByte(xy) ); 5045 writeByte( xy, A ); 5046} 5047 5048void opcode_xycb_40( unsigned xy ) // BIT 0, (IX + d) 5049{ 5050 testBit( 0, readByte( xy ) ); 5051} 5052 5053void opcode_xycb_41( unsigned xy ) // BIT 0, (IX + d) 5054{ 5055 testBit( 0, readByte( xy ) ); 5056} 5057 5058void opcode_xycb_42( unsigned xy ) // BIT 0, (IX + d) 5059{ 5060 testBit( 0, readByte( xy ) ); 5061} 5062 5063void opcode_xycb_43( unsigned xy ) // BIT 0, (IX + d) 5064{ 5065 testBit( 0, readByte( xy ) ); 5066} 5067 5068void opcode_xycb_44( unsigned xy ) // BIT 0, (IX + d) 5069{ 5070 testBit( 0, readByte( xy ) ); 5071} 5072 5073void opcode_xycb_45( unsigned xy ) // BIT 0, (IX + d) 5074{ 5075 testBit( 0, readByte( xy ) ); 5076} 5077 5078void opcode_xycb_46( unsigned xy ) // BIT 0, (IX + d) 5079{ 5080 testBit( 0, readByte( xy ) ); 5081} 5082 5083void opcode_xycb_47( unsigned xy ) // BIT 0, (IX + d) 5084{ 5085 testBit( 0, readByte( xy ) ); 5086} 5087 5088void opcode_xycb_48( unsigned xy ) // BIT 1, (IX + d) 5089{ 5090 testBit( 1, readByte( xy ) ); 5091} 5092 5093void opcode_xycb_49( unsigned xy ) // BIT 1, (IX + d) 5094{ 5095 testBit( 1, readByte( xy ) ); 5096} 5097 5098void opcode_xycb_4a( unsigned xy ) // BIT 1, (IX + d) 5099{ 5100 testBit( 1, readByte( xy ) ); 5101} 5102 5103void opcode_xycb_4b( unsigned xy ) // BIT 1, (IX + d) 5104{ 5105 testBit( 1, readByte( xy ) ); 5106} 5107 5108void opcode_xycb_4c( unsigned xy ) // BIT 1, (IX + d) 5109{ 5110 testBit( 1, readByte( xy ) ); 5111} 5112 5113void opcode_xycb_4d( unsigned xy ) // BIT 1, (IX + d) 5114{ 5115 testBit( 1, readByte( xy ) ); 5116} 5117 5118void opcode_xycb_4e( unsigned xy ) // BIT 1, (IX + d) 5119{ 5120 testBit( 1, readByte( xy ) ); 5121} 5122 5123void opcode_xycb_4f( unsigned xy ) // BIT 1, (IX + d) 5124{ 5125 testBit( 1, readByte( xy ) ); 5126} 5127 5128void opcode_xycb_50( unsigned xy ) // BIT 2, (IX + d) 5129{ 5130 testBit( 2, readByte( xy ) ); 5131} 5132 5133void opcode_xycb_51( unsigned xy ) // BIT 2, (IX + d) 5134{ 5135 testBit( 2, readByte( xy ) ); 5136} 5137 5138void opcode_xycb_52( unsigned xy ) // BIT 2, (IX + d) 5139{ 5140 testBit( 2, readByte( xy ) ); 5141} 5142 5143void opcode_xycb_53( unsigned xy ) // BIT 2, (IX + d) 5144{ 5145 testBit( 2, readByte( xy ) ); 5146} 5147 5148void opcode_xycb_54( unsigned xy ) // BIT 2, (IX + d) 5149{ 5150 testBit( 2, readByte( xy ) ); 5151} 5152 5153void opcode_xycb_55( unsigned xy ) // BIT 2, (IX + d) 5154{ 5155 testBit( 2, readByte( xy ) ); 5156} 5157 5158void opcode_xycb_56( unsigned xy ) // BIT 2, (IX + d) 5159{ 5160 testBit( 2, readByte( xy ) ); 5161} 5162 5163void opcode_xycb_57( unsigned xy ) // BIT 2, (IX + d) 5164{ 5165 testBit( 2, readByte( xy ) ); 5166} 5167 5168void opcode_xycb_58( unsigned xy ) // BIT 3, (IX + d) 5169{ 5170 testBit( 3, readByte( xy ) ); 5171} 5172 5173void opcode_xycb_59( unsigned xy ) // BIT 3, (IX + d) 5174{ 5175 testBit( 3, readByte( xy ) ); 5176} 5177 5178void opcode_xycb_5a( unsigned xy ) // BIT 3, (IX + d) 5179{ 5180 testBit( 3, readByte( xy ) ); 5181} 5182 5183void opcode_xycb_5b( unsigned xy ) // BIT 3, (IX + d) 5184{ 5185 testBit( 3, readByte( xy ) ); 5186} 5187 5188void opcode_xycb_5c( unsigned xy ) // BIT 3, (IX + d) 5189{ 5190 testBit( 3, readByte( xy ) ); 5191} 5192 5193void opcode_xycb_5d( unsigned xy ) // BIT 3, (IX + d) 5194{ 5195 testBit( 3, readByte( xy ) ); 5196} 5197 5198void opcode_xycb_5e( unsigned xy ) // BIT 3, (IX + d) 5199{ 5200 testBit( 3, readByte( xy ) ); 5201} 5202 5203void opcode_xycb_5f( unsigned xy ) // BIT 3, (IX + d) 5204{ 5205 testBit( 3, readByte( xy ) ); 5206} 5207 5208void opcode_xycb_60( unsigned xy ) // BIT 4, (IX + d) 5209{ 5210 testBit( 4, readByte( xy ) ); 5211} 5212 5213void opcode_xycb_61( unsigned xy ) // BIT 4, (IX + d) 5214{ 5215 testBit( 4, readByte( xy ) ); 5216} 5217 5218void opcode_xycb_62( unsigned xy ) // BIT 4, (IX + d) 5219{ 5220 testBit( 4, readByte( xy ) ); 5221} 5222 5223void opcode_xycb_63( unsigned xy ) // BIT 4, (IX + d) 5224{ 5225 testBit( 4, readByte( xy ) ); 5226} 5227 5228void opcode_xycb_64( unsigned xy ) // BIT 4, (IX + d) 5229{ 5230 testBit( 4, readByte( xy ) ); 5231} 5232 5233void opcode_xycb_65( unsigned xy ) // BIT 4, (IX + d) 5234{ 5235 testBit( 4, readByte( xy ) ); 5236} 5237 5238void opcode_xycb_66( unsigned xy ) // BIT 4, (IX + d) 5239{ 5240 testBit( 4, readByte( xy ) ); 5241} 5242 5243void opcode_xycb_67( unsigned xy ) // BIT 4, (IX + d) 5244{ 5245 testBit( 4, readByte( xy ) ); 5246} 5247 5248void opcode_xycb_68( unsigned xy ) // BIT 5, (IX + d) 5249{ 5250 testBit( 5, readByte( xy ) ); 5251} 5252 5253void opcode_xycb_69( unsigned xy ) // BIT 5, (IX + d) 5254{ 5255 testBit( 5, readByte( xy ) ); 5256} 5257 5258void opcode_xycb_6a( unsigned xy ) // BIT 5, (IX + d) 5259{ 5260 testBit( 5, readByte( xy ) ); 5261} 5262 5263void opcode_xycb_6b( unsigned xy ) // BIT 5, (IX + d) 5264{ 5265 testBit( 5, readByte( xy ) ); 5266} 5267 5268void opcode_xycb_6c( unsigned xy ) // BIT 5, (IX + d) 5269{ 5270 testBit( 5, readByte( xy ) ); 5271} 5272 5273void opcode_xycb_6d( unsigned xy ) // BIT 5, (IX + d) 5274{ 5275 testBit( 5, readByte( xy ) ); 5276} 5277 5278void opcode_xycb_6e( unsigned xy ) // BIT 5, (IX + d) 5279{ 5280 testBit( 5, readByte( xy ) ); 5281} 5282 5283void opcode_xycb_6f( unsigned xy ) // BIT 5, (IX + d) 5284{ 5285 testBit( 5, readByte( xy ) ); 5286} 5287 5288void opcode_xycb_70( unsigned xy ) // BIT 6, (IX + d) 5289{ 5290 testBit( 6, readByte( xy ) ); 5291} 5292 5293void opcode_xycb_71( unsigned xy ) // BIT 6, (IX + d) 5294{ 5295 testBit( 6, readByte( xy ) ); 5296} 5297 5298void opcode_xycb_72( unsigned xy ) // BIT 6, (IX + d) 5299{ 5300 testBit( 6, readByte( xy ) ); 5301} 5302 5303void opcode_xycb_73( unsigned xy ) // BIT 6, (IX + d) 5304{ 5305 testBit( 6, readByte( xy ) ); 5306} 5307 5308void opcode_xycb_74( unsigned xy ) // BIT 6, (IX + d) 5309{ 5310 testBit( 6, readByte( xy ) ); 5311} 5312 5313void opcode_xycb_75( unsigned xy ) // BIT 6, (IX + d) 5314{ 5315 testBit( 6, readByte( xy ) ); 5316} 5317 5318void opcode_xycb_76( unsigned xy ) // BIT 6, (IX + d) 5319{ 5320 testBit( 6, readByte( xy ) ); 5321} 5322 5323void opcode_xycb_77( unsigned xy ) // BIT 6, (IX + d) 5324{ 5325 testBit( 6, readByte( xy ) ); 5326} 5327 5328void opcode_xycb_78( unsigned xy ) // BIT 7, (IX + d) 5329{ 5330 testBit( 7, readByte( xy ) ); 5331} 5332 5333void opcode_xycb_79( unsigned xy ) // BIT 7, (IX + d) 5334{ 5335 testBit( 7, readByte( xy ) ); 5336} 5337 5338void opcode_xycb_7a( unsigned xy ) // BIT 7, (IX + d) 5339{ 5340 testBit( 7, readByte( xy ) ); 5341} 5342 5343void opcode_xycb_7b( unsigned xy ) // BIT 7, (IX + d) 5344{ 5345 testBit( 7, readByte( xy ) ); 5346} 5347 5348void opcode_xycb_7c( unsigned xy ) // BIT 7, (IX + d) 5349{ 5350 testBit( 7, readByte( xy ) ); 5351} 5352 5353void opcode_xycb_7d( unsigned xy ) // BIT 7, (IX + d) 5354{ 5355 testBit( 7, readByte( xy ) ); 5356} 5357 5358void opcode_xycb_7e( unsigned xy ) // BIT 7, (IX + d) 5359{ 5360 testBit( 7, readByte( xy ) ); 5361} 5362 5363void opcode_xycb_7f( unsigned xy ) // BIT 7, (IX + d) 5364{ 5365 testBit( 7, readByte( xy ) ); 5366} 5367 5368void opcode_xycb_80( unsigned xy ) // LD B, RES 0, (IX + d) 5369{ 5370 B = readByte(xy) & (unsigned char) ~(1 << 0); 5371 writeByte( xy, B ); 5372} 5373 5374void opcode_xycb_81( unsigned xy ) // LD C, RES 0, (IX + d) 5375{ 5376 C = readByte(xy) & (unsigned char) ~(1 << 0); 5377 writeByte( xy, C ); 5378} 5379 5380void opcode_xycb_82( unsigned xy ) // LD D, RES 0, (IX + d) 5381{ 5382 D = readByte(xy) & (unsigned char) ~(1 << 0); 5383 writeByte( xy, D ); 5384} 5385 5386void opcode_xycb_83( unsigned xy ) // LD E, RES 0, (IX + d) 5387{ 5388 E = readByte(xy) & (unsigned char) ~(1 << 0); 5389 writeByte( xy, E ); 5390} 5391 5392void opcode_xycb_84( unsigned xy ) // LD H, RES 0, (IX + d) 5393{ 5394 H = readByte(xy) & (unsigned char) ~(1 << 0); 5395 writeByte( xy, H ); 5396} 5397 5398void opcode_xycb_85( unsigned xy ) // LD L, RES 0, (IX + d) 5399{ 5400 L = readByte(xy) & (unsigned char) ~(1 << 0); 5401 writeByte( xy, L ); 5402} 5403 5404void opcode_xycb_86( unsigned xy ) // RES 0, (IX + d) 5405{ 5406 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 0) ); 5407} 5408 5409void opcode_xycb_87( unsigned xy ) // LD A, RES 0, (IX + d) 5410{ 5411 A = readByte(xy) & (unsigned char) ~(1 << 0); 5412 writeByte( xy, A ); 5413} 5414 5415void opcode_xycb_88( unsigned xy ) // LD B, RES 1, (IX + d) 5416{ 5417 B = readByte(xy) & (unsigned char) ~(1 << 1); 5418 writeByte( xy, B ); 5419} 5420 5421void opcode_xycb_89( unsigned xy ) // LD C, RES 1, (IX + d) 5422{ 5423 C = readByte(xy) & (unsigned char) ~(1 << 1); 5424 writeByte( xy, C ); 5425} 5426 5427void opcode_xycb_8a( unsigned xy ) // LD D, RES 1, (IX + d) 5428{ 5429 D = readByte(xy) & (unsigned char) ~(1 << 1); 5430 writeByte( xy, D ); 5431} 5432 5433void opcode_xycb_8b( unsigned xy ) // LD E, RES 1, (IX + d) 5434{ 5435 E = readByte(xy) & (unsigned char) ~(1 << 1); 5436 writeByte( xy, E ); 5437} 5438 5439void opcode_xycb_8c( unsigned xy ) // LD H, RES 1, (IX + d) 5440{ 5441 H = readByte(xy) & (unsigned char) ~(1 << 1); 5442 writeByte( xy, H ); 5443} 5444 5445void opcode_xycb_8d( unsigned xy ) // LD L, RES 1, (IX + d) 5446{ 5447 L = readByte(xy) & (unsigned char) ~(1 << 1); 5448 writeByte( xy, L ); 5449} 5450 5451void opcode_xycb_8e( unsigned xy ) // RES 1, (IX + d) 5452{ 5453 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 1) ); 5454} 5455 5456void opcode_xycb_8f( unsigned xy ) // LD A, RES 1, (IX + d) 5457{ 5458 A = readByte(xy) & (unsigned char) ~(1 << 1); 5459 writeByte( xy, A ); 5460} 5461 5462void opcode_xycb_90( unsigned xy ) // LD B, RES 2, (IX + d) 5463{ 5464 B = readByte(xy) & (unsigned char) ~(1 << 2); 5465 writeByte( xy, B ); 5466} 5467 5468void opcode_xycb_91( unsigned xy ) // LD C, RES 2, (IX + d) 5469{ 5470 C = readByte(xy) & (unsigned char) ~(1 << 2); 5471 writeByte( xy, C ); 5472} 5473 5474void opcode_xycb_92( unsigned xy ) // LD D, RES 2, (IX + d) 5475{ 5476 D = readByte(xy) & (unsigned char) ~(1 << 2); 5477 writeByte( xy, D ); 5478} 5479 5480void opcode_xycb_93( unsigned xy ) // LD E, RES 2, (IX + d) 5481{ 5482 E = readByte(xy) & (unsigned char) ~(1 << 2); 5483 writeByte( xy, E ); 5484} 5485 5486void opcode_xycb_94( unsigned xy ) // LD H, RES 2, (IX + d) 5487{ 5488 H = readByte(xy) & (unsigned char) ~(1 << 2); 5489 writeByte( xy, H ); 5490} 5491 5492void opcode_xycb_95( unsigned xy ) // LD L, RES 2, (IX + d) 5493{ 5494 L = readByte(xy) & (unsigned char) ~(1 << 2); 5495 writeByte( xy, L ); 5496} 5497 5498void opcode_xycb_96( unsigned xy ) // RES 2, (IX + d) 5499{ 5500 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 2) ); 5501} 5502 5503void opcode_xycb_97( unsigned xy ) // LD A, RES 2, (IX + d) 5504{ 5505 A = readByte(xy) & (unsigned char) ~(1 << 2); 5506 writeByte( xy, A ); 5507} 5508 5509void opcode_xycb_98( unsigned xy ) // LD B, RES 3, (IX + d) 5510{ 5511 B = readByte(xy) & (unsigned char) ~(1 << 3); 5512 writeByte( xy, B ); 5513} 5514 5515void opcode_xycb_99( unsigned xy ) // LD C, RES 3, (IX + d) 5516{ 5517 C = readByte(xy) & (unsigned char) ~(1 << 3); 5518 writeByte( xy, C ); 5519} 5520 5521void opcode_xycb_9a( unsigned xy ) // LD D, RES 3, (IX + d) 5522{ 5523 D = readByte(xy) & (unsigned char) ~(1 << 3); 5524 writeByte( xy, D ); 5525} 5526 5527void opcode_xycb_9b( unsigned xy ) // LD E, RES 3, (IX + d) 5528{ 5529 E = readByte(xy) & (unsigned char) ~(1 << 3); 5530 writeByte( xy, E ); 5531} 5532 5533void opcode_xycb_9c( unsigned xy ) // LD H, RES 3, (IX + d) 5534{ 5535 H = readByte(xy) & (unsigned char) ~(1 << 3); 5536 writeByte( xy, H ); 5537} 5538 5539void opcode_xycb_9d( unsigned xy ) // LD L, RES 3, (IX + d) 5540{ 5541 L = readByte(xy) & (unsigned char) ~(1 << 3); 5542 writeByte( xy, L ); 5543} 5544 5545void opcode_xycb_9e( unsigned xy ) // RES 3, (IX + d) 5546{ 5547 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 3) ); 5548} 5549 5550void opcode_xycb_9f( unsigned xy ) // LD A, RES 3, (IX + d) 5551{ 5552 A = readByte(xy) & (unsigned char) ~(1 << 3); 5553 writeByte( xy, A ); 5554} 5555 5556void opcode_xycb_a0( unsigned xy ) // LD B, RES 4, (IX + d) 5557{ 5558 B = readByte(xy) & (unsigned char) ~(1 << 4); 5559 writeByte( xy, B ); 5560} 5561 5562void opcode_xycb_a1( unsigned xy ) // LD C, RES 4, (IX + d) 5563{ 5564 C = readByte(xy) & (unsigned char) ~(1 << 4); 5565 writeByte( xy, C ); 5566} 5567 5568void opcode_xycb_a2( unsigned xy ) // LD D, RES 4, (IX + d) 5569{ 5570 D = readByte(xy) & (unsigned char) ~(1 << 4); 5571 writeByte( xy, D ); 5572} 5573 5574void opcode_xycb_a3( unsigned xy ) // LD E, RES 4, (IX + d) 5575{ 5576 E = readByte(xy) & (unsigned char) ~(1 << 4); 5577 writeByte( xy, E ); 5578} 5579 5580void opcode_xycb_a4( unsigned xy ) // LD H, RES 4, (IX + d) 5581{ 5582 H = readByte(xy) & (unsigned char) ~(1 << 4); 5583 writeByte( xy, H ); 5584} 5585 5586void opcode_xycb_a5( unsigned xy ) // LD L, RES 4, (IX + d) 5587{ 5588 L = readByte(xy) & (unsigned char) ~(1 << 4); 5589 writeByte( xy, L ); 5590} 5591 5592void opcode_xycb_a6( unsigned xy ) // RES 4, (IX + d) 5593{ 5594 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 4) ); 5595} 5596 5597void opcode_xycb_a7( unsigned xy ) // LD A, RES 4, (IX + d) 5598{ 5599 A = readByte(xy) & (unsigned char) ~(1 << 4); 5600 writeByte( xy, A ); 5601} 5602 5603void opcode_xycb_a8( unsigned xy ) // LD B, RES 5, (IX + d) 5604{ 5605 B = readByte(xy) & (unsigned char) ~(1 << 5); 5606 writeByte( xy, B ); 5607} 5608 5609void opcode_xycb_a9( unsigned xy ) // LD C, RES 5, (IX + d) 5610{ 5611 C = readByte(xy) & (unsigned char) ~(1 << 5); 5612 writeByte( xy, C ); 5613} 5614 5615void opcode_xycb_aa( unsigned xy ) // LD D, RES 5, (IX + d) 5616{ 5617 D = readByte(xy) & (unsigned char) ~(1 << 5); 5618 writeByte( xy, D ); 5619} 5620 5621void opcode_xycb_ab( unsigned xy ) // LD E, RES 5, (IX + d) 5622{ 5623 E = readByte(xy) & (unsigned char) ~(1 << 5); 5624 writeByte( xy, E ); 5625} 5626 5627void opcode_xycb_ac( unsigned xy ) // LD H, RES 5, (IX + d) 5628{ 5629 H = readByte(xy) & (unsigned char) ~(1 << 5); 5630 writeByte( xy, H ); 5631} 5632 5633void opcode_xycb_ad( unsigned xy ) // LD L, RES 5, (IX + d) 5634{ 5635 L = readByte(xy) & (unsigned char) ~(1 << 5); 5636 writeByte( xy, L ); 5637} 5638 5639void opcode_xycb_ae( unsigned xy ) // RES 5, (IX + d) 5640{ 5641 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 5) ); 5642} 5643 5644void opcode_xycb_af( unsigned xy ) // LD A, RES 5, (IX + d) 5645{ 5646 A = readByte(xy) & (unsigned char) ~(1 << 5); 5647 writeByte( xy, A ); 5648} 5649 5650void opcode_xycb_b0( unsigned xy ) // LD B, RES 6, (IX + d) 5651{ 5652 B = readByte(xy) & (unsigned char) ~(1 << 6); 5653 writeByte( xy, B ); 5654} 5655 5656void opcode_xycb_b1( unsigned xy ) // LD C, RES 6, (IX + d) 5657{ 5658 C = readByte(xy) & (unsigned char) ~(1 << 6); 5659 writeByte( xy, C ); 5660} 5661 5662void opcode_xycb_b2( unsigned xy ) // LD D, RES 6, (IX + d) 5663{ 5664 D = readByte(xy) & (unsigned char) ~(1 << 6); 5665 writeByte( xy, D ); 5666} 5667 5668void opcode_xycb_b3( unsigned xy ) // LD E, RES 6, (IX + d) 5669{ 5670 E = readByte(xy) & (unsigned char) ~(1 << 6); 5671 writeByte( xy, E ); 5672} 5673 5674void opcode_xycb_b4( unsigned xy ) // LD H, RES 6, (IX + d) 5675{ 5676 H = readByte(xy) & (unsigned char) ~(1 << 6); 5677 writeByte( xy, H ); 5678} 5679 5680void opcode_xycb_b5( unsigned xy ) // LD L, RES 6, (IX + d) 5681{ 5682 L = readByte(xy) & (unsigned char) ~(1 << 6); 5683 writeByte( xy, L ); 5684} 5685 5686void opcode_xycb_b6( unsigned xy ) // RES 6, (IX + d) 5687{ 5688 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 6) ); 5689} 5690 5691void opcode_xycb_b7( unsigned xy ) // LD A, RES 6, (IX + d) 5692{ 5693 A = readByte(xy) & (unsigned char) ~(1 << 6); 5694 writeByte( xy, A ); 5695} 5696 5697void opcode_xycb_b8( unsigned xy ) // LD B, RES 7, (IX + d) 5698{ 5699 B = readByte(xy) & (unsigned char) ~(1 << 7); 5700 writeByte( xy, B ); 5701} 5702 5703void opcode_xycb_b9( unsigned xy ) // LD C, RES 7, (IX + d) 5704{ 5705 C = readByte(xy) & (unsigned char) ~(1 << 7); 5706 writeByte( xy, C ); 5707} 5708 5709void opcode_xycb_ba( unsigned xy ) // LD D, RES 7, (IX + d) 5710{ 5711 D = readByte(xy) & (unsigned char) ~(1 << 7); 5712 writeByte( xy, D ); 5713} 5714 5715void opcode_xycb_bb( unsigned xy ) // LD E, RES 7, (IX + d) 5716{ 5717 E = readByte(xy) & (unsigned char) ~(1 << 7); 5718 writeByte( xy, E ); 5719} 5720 5721void opcode_xycb_bc( unsigned xy ) // LD H, RES 7, (IX + d) 5722{ 5723 H = readByte(xy) & (unsigned char) ~(1 << 7); 5724 writeByte( xy, H ); 5725} 5726 5727void opcode_xycb_bd( unsigned xy ) // LD L, RES 7, (IX + d) 5728{ 5729 L = readByte(xy) & (unsigned char) ~(1 << 7); 5730 writeByte( xy, L ); 5731} 5732 5733void opcode_xycb_be( unsigned xy ) // RES 7, (IX + d) 5734{ 5735 writeByte( xy, readByte(xy) & (unsigned char) ~(1 << 7) ); 5736} 5737 5738void opcode_xycb_bf( unsigned xy ) // LD A, RES 7, (IX + d) 5739{ 5740 A = readByte(xy) & (unsigned char) ~(1 << 7); 5741 writeByte( xy, A ); 5742} 5743 5744void opcode_xycb_c0( unsigned xy ) // LD B, SET 0, (IX + d) 5745{ 5746 B = readByte(xy) | (unsigned char) (1 << 0); 5747 writeByte( xy, B ); 5748} 5749 5750void opcode_xycb_c1( unsigned xy ) // LD C, SET 0, (IX + d) 5751{ 5752 C = readByte(xy) | (unsigned char) (1 << 0); 5753 writeByte( xy, C ); 5754} 5755 5756void opcode_xycb_c2( unsigned xy ) // LD D, SET 0, (IX + d) 5757{ 5758 D = readByte(xy) | (unsigned char) (1 << 0); 5759 writeByte( xy, D ); 5760} 5761 5762void opcode_xycb_c3( unsigned xy ) // LD E, SET 0, (IX + d) 5763{ 5764 E = readByte(xy) | (unsigned char) (1 << 0); 5765 writeByte( xy, E ); 5766} 5767 5768void opcode_xycb_c4( unsigned xy ) // LD H, SET 0, (IX + d) 5769{ 5770 H = readByte(xy) | (unsigned char) (1 << 0); 5771 writeByte( xy, H ); 5772} 5773 5774void opcode_xycb_c5( unsigned xy ) // LD L, SET 0, (IX + d) 5775{ 5776 L = readByte(xy) | (unsigned char) (1 << 0); 5777 writeByte( xy, L ); 5778} 5779 5780void opcode_xycb_c6( unsigned xy ) // SET 0, (IX + d) 5781{ 5782 writeByte( xy, readByte(xy) | (unsigned char) (1 << 0) ); 5783} 5784 5785void opcode_xycb_c7( unsigned xy ) // LD A, SET 0, (IX + d) 5786{ 5787 A = readByte(xy) | (unsigned char) (1 << 0); 5788 writeByte( xy, A ); 5789} 5790 5791void opcode_xycb_c8( unsigned xy ) // LD B, SET 1, (IX + d) 5792{ 5793 B = readByte(xy) | (unsigned char) (1 << 1); 5794 writeByte( xy, B ); 5795} 5796 5797void opcode_xycb_c9( unsigned xy ) // LD C, SET 1, (IX + d) 5798{ 5799 C = readByte(xy) | (unsigned char) (1 << 1); 5800 writeByte( xy, C ); 5801} 5802 5803void opcode_xycb_ca( unsigned xy ) // LD D, SET 1, (IX + d) 5804{ 5805 D = readByte(xy) | (unsigned char) (1 << 1); 5806 writeByte( xy, D ); 5807} 5808 5809void opcode_xycb_cb( unsigned xy ) // LD E, SET 1, (IX + d) 5810{ 5811 E = readByte(xy) | (unsigned char) (1 << 1); 5812 writeByte( xy, E ); 5813} 5814 5815void opcode_xycb_cc( unsigned xy ) // LD H, SET 1, (IX + d) 5816{ 5817 H = readByte(xy) | (unsigned char) (1 << 1); 5818 writeByte( xy, H ); 5819} 5820 5821void opcode_xycb_cd( unsigned xy ) // LD L, SET 1, (IX + d) 5822{ 5823 L = readByte(xy) | (unsigned char) (1 << 1); 5824 writeByte( xy, L ); 5825} 5826 5827void opcode_xycb_ce( unsigned xy ) // SET 1, (IX + d) 5828{ 5829 writeByte( xy, readByte(xy) | (unsigned char) (1 << 1) ); 5830} 5831 5832void opcode_xycb_cf( unsigned xy ) // LD A, SET 1, (IX + d) 5833{ 5834 A = readByte(xy) | (unsigned char) (1 << 1); 5835 writeByte( xy, A ); 5836} 5837 5838void opcode_xycb_d0( unsigned xy ) // LD B, SET 2, (IX + d) 5839{ 5840 B = readByte(xy) | (unsigned char) (1 << 2); 5841 writeByte( xy, B ); 5842} 5843 5844void opcode_xycb_d1( unsigned xy ) // LD C, SET 2, (IX + d) 5845{ 5846 C = readByte(xy) | (unsigned char) (1 << 2); 5847 writeByte( xy, C ); 5848} 5849 5850void opcode_xycb_d2( unsigned xy ) // LD D, SET 2, (IX + d) 5851{ 5852 D = readByte(xy) | (unsigned char) (1 << 2); 5853 writeByte( xy, D ); 5854} 5855 5856void opcode_xycb_d3( unsigned xy ) // LD E, SET 2, (IX + d) 5857{ 5858 E = readByte(xy) | (unsigned char) (1 << 2); 5859 writeByte( xy, E ); 5860} 5861 5862void opcode_xycb_d4( unsigned xy ) // LD H, SET 2, (IX + d) 5863{ 5864 H = readByte(xy) | (unsigned char) (1 << 2); 5865 writeByte( xy, H ); 5866} 5867 5868void opcode_xycb_d5( unsigned xy ) // LD L, SET 2, (IX + d) 5869{ 5870 L = readByte(xy) | (unsigned char) (1 << 2); 5871 writeByte( xy, L ); 5872} 5873 5874void opcode_xycb_d6( unsigned xy ) // SET 2, (IX + d) 5875{ 5876 writeByte( xy, readByte(xy) | (unsigned char) (1 << 2) ); 5877} 5878 5879void opcode_xycb_d7( unsigned xy ) // LD A, SET 2, (IX + d) 5880{ 5881 A = readByte(xy) | (unsigned char) (1 << 2); 5882 writeByte( xy, A ); 5883} 5884 5885void opcode_xycb_d8( unsigned xy ) // LD B, SET 3, (IX + d) 5886{ 5887 B = readByte(xy) | (unsigned char) (1 << 3); 5888 writeByte( xy, B ); 5889} 5890 5891void opcode_xycb_d9( unsigned xy ) // LD C, SET 3, (IX + d) 5892{ 5893 C = readByte(xy) | (unsigned char) (1 << 3); 5894 writeByte( xy, C ); 5895} 5896 5897void opcode_xycb_da( unsigned xy ) // LD D, SET 3, (IX + d) 5898{ 5899 D = readByte(xy) | (unsigned char) (1 << 3); 5900 writeByte( xy, D ); 5901} 5902 5903void opcode_xycb_db( unsigned xy ) // LD E, SET 3, (IX + d) 5904{ 5905 E = readByte(xy) | (unsigned char) (1 << 3); 5906 writeByte( xy, E ); 5907} 5908 5909void opcode_xycb_dc( unsigned xy ) // LD H, SET 3, (IX + d) 5910{ 5911 H = readByte(xy) | (unsigned char) (1 << 3); 5912 writeByte( xy, H ); 5913} 5914 5915void opcode_xycb_dd( unsigned xy ) // LD L, SET 3, (IX + d) 5916{ 5917 L = readByte(xy) | (unsigned char) (1 << 3); 5918 writeByte( xy, L ); 5919} 5920 5921void opcode_xycb_de( unsigned xy ) // SET 3, (IX + d) 5922{ 5923 writeByte( xy, readByte(xy) | (unsigned char) (1 << 3) ); 5924} 5925 5926void opcode_xycb_df( unsigned xy ) // LD A, SET 3, (IX + d) 5927{ 5928 A = readByte(xy) | (unsigned char) (1 << 3); 5929 writeByte( xy, A ); 5930} 5931 5932void opcode_xycb_e0( unsigned xy ) // LD B, SET 4, (IX + d) 5933{ 5934 B = readByte(xy) | (unsigned char) (1 << 4); 5935 writeByte( xy, B ); 5936} 5937 5938void opcode_xycb_e1( unsigned xy ) // LD C, SET 4, (IX + d) 5939{ 5940 C = readByte(xy) | (unsigned char) (1 << 4); 5941 writeByte( xy, C ); 5942} 5943 5944void opcode_xycb_e2( unsigned xy ) // LD D, SET 4, (IX + d) 5945{ 5946 D = readByte(xy) | (unsigned char) (1 << 4); 5947 writeByte( xy, D ); 5948} 5949 5950void opcode_xycb_e3( unsigned xy ) // LD E, SET 4, (IX + d) 5951{ 5952 E = readByte(xy) | (unsigned char) (1 << 4); 5953 writeByte( xy, E ); 5954} 5955 5956void opcode_xycb_e4( unsigned xy ) // LD H, SET 4, (IX + d) 5957{ 5958 H = readByte(xy) | (unsigned char) (1 << 4); 5959 writeByte( xy, H ); 5960} 5961 5962void opcode_xycb_e5( unsigned xy ) // LD L, SET 4, (IX + d) 5963{ 5964 L = readByte(xy) | (unsigned char) (1 << 4); 5965 writeByte( xy, L ); 5966} 5967 5968void opcode_xycb_e6( unsigned xy ) // SET 4, (IX + d) 5969{ 5970 writeByte( xy, readByte(xy) | (unsigned char) (1 << 4) ); 5971} 5972 5973void opcode_xycb_e7( unsigned xy ) // LD A, SET 4, (IX + d) 5974{ 5975 A = readByte(xy) | (unsigned char) (1 << 4); 5976 writeByte( xy, A ); 5977} 5978 5979void opcode_xycb_e8( unsigned xy ) // LD B, SET 5, (IX + d) 5980{ 5981 B = readByte(xy) | (unsigned char) (1 << 5); 5982 writeByte( xy, B ); 5983} 5984 5985void opcode_xycb_e9( unsigned xy ) // LD C, SET 5, (IX + d) 5986{ 5987 C = readByte(xy) | (unsigned char) (1 << 5); 5988 writeByte( xy, C ); 5989} 5990 5991void opcode_xycb_ea( unsigned xy ) // LD D, SET 5, (IX + d) 5992{ 5993 D = readByte(xy) | (unsigned char) (1 << 5); 5994 writeByte( xy, D ); 5995} 5996 5997void opcode_xycb_eb( unsigned xy ) // LD E, SET 5, (IX + d) 5998{ 5999 E = readByte(xy) | (unsigned char) (1 << 5); 6000 writeByte( xy, E ); 6001} 6002 6003void opcode_xycb_ec( unsigned xy ) // LD H, SET 5, (IX + d) 6004{ 6005 H = readByte(xy) | (unsigned char) (1 << 5); 6006 writeByte( xy, H ); 6007} 6008 6009void opcode_xycb_ed( unsigned xy ) // LD L, SET 5, (IX + d) 6010{ 6011 L = readByte(xy) | (unsigned char) (1 << 5); 6012 writeByte( xy, L ); 6013} 6014 6015void opcode_xycb_ee( unsigned xy ) // SET 5, (IX + d) 6016{ 6017 writeByte( xy, readByte(xy) | (unsigned char) (1 << 5) ); 6018} 6019 6020void opcode_xycb_ef( unsigned xy ) // LD A, SET 5, (IX + d) 6021{ 6022 A = readByte(xy) | (unsigned char) (1 << 5); 6023 writeByte( xy, A ); 6024} 6025 6026void opcode_xycb_f0( unsigned xy ) // LD B, SET 6, (IX + d) 6027{ 6028 B = readByte(xy) | (unsigned char) (1 << 6); 6029 writeByte( xy, B ); 6030} 6031 6032void opcode_xycb_f1( unsigned xy ) // LD C, SET 6, (IX + d) 6033{ 6034 C = readByte(xy) | (unsigned char) (1 << 6); 6035 writeByte( xy, C ); 6036} 6037 6038void opcode_xycb_f2( unsigned xy ) // LD D, SET 6, (IX + d) 6039{ 6040 D = readByte(xy) | (unsigned char) (1 << 6); 6041 writeByte( xy, D ); 6042} 6043 6044void opcode_xycb_f3( unsigned xy ) // LD E, SET 6, (IX + d) 6045{ 6046 E = readByte(xy) | (unsigned char) (1 << 6); 6047 writeByte( xy, E ); 6048} 6049 6050void opcode_xycb_f4( unsigned xy ) // LD H, SET 6, (IX + d) 6051{ 6052 H = readByte(xy) | (unsigned char) (1 << 6); 6053 writeByte( xy, H ); 6054} 6055 6056void opcode_xycb_f5( unsigned xy ) // LD L, SET 6, (IX + d) 6057{ 6058 L = readByte(xy) | (unsigned char) (1 << 6); 6059 writeByte( xy, L ); 6060} 6061 6062void opcode_xycb_f6( unsigned xy ) // SET 6, (IX + d) 6063{ 6064 writeByte( xy, readByte(xy) | (unsigned char) (1 << 6) ); 6065} 6066 6067void opcode_xycb_f7( unsigned xy ) // LD A, SET 6, (IX + d) 6068{ 6069 A = readByte(xy) | (unsigned char) (1 << 6); 6070 writeByte( xy, A ); 6071} 6072 6073void opcode_xycb_f8( unsigned xy ) // LD B, SET 7, (IX + d) 6074{ 6075 B = readByte(xy) | (unsigned char) (1 << 7); 6076 writeByte( xy, B ); 6077} 6078 6079void opcode_xycb_f9( unsigned xy ) // LD C, SET 7, (IX + d) 6080{ 6081 C = readByte(xy) | (unsigned char) (1 << 7); 6082 writeByte( xy, C ); 6083} 6084 6085void opcode_xycb_fa( unsigned xy ) // LD D, SET 7, (IX + d) 6086{ 6087 D = readByte(xy) | (unsigned char) (1 << 7); 6088 writeByte( xy, D ); 6089} 6090 6091void opcode_xycb_fb( unsigned xy ) // LD E, SET 7, (IX + d) 6092{ 6093 E = readByte(xy) | (unsigned char) (1 << 7); 6094 writeByte( xy, E ); 6095} 6096 6097void opcode_xycb_fc( unsigned xy ) // LD H, SET 7, (IX + d) 6098{ 6099 H = readByte(xy) | (unsigned char) (1 << 7); 6100 writeByte( xy, H ); 6101} 6102 6103void opcode_xycb_fd( unsigned xy ) // LD L, SET 7, (IX + d) 6104{ 6105 L = readByte(xy) | (unsigned char) (1 << 7); 6106 writeByte( xy, L ); 6107} 6108 6109void opcode_xycb_fe( unsigned xy ) // SET 7, (IX + d) 6110{ 6111 writeByte( xy, readByte(xy) | (unsigned char) (1 << 7) ); 6112} 6113 6114void opcode_xycb_ff( unsigned xy ) // LD A, SET 7, (IX + d) 6115{ 6116 A = readByte(xy) | (unsigned char) (1 << 7); 6117 writeByte( xy, A ); 6118} 6119 6120OpcodeInfo 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 6377}; 6378 6379void opcode_00() // NOP 6380{ 6381} 6382 6383void opcode_01() // LD BC,nn 6384{ 6385 C = fetchByte(); 6386 B = fetchByte(); 6387} 6388 6389void opcode_02() // LD (BC),A 6390{ 6391 writeByte( BC(), A ); 6392} 6393 6394void opcode_03() // INC BC 6395{ 6396 if( ++C == 0 ) ++B; 6397} 6398 6399void opcode_04() // INC B 6400{ 6401 B = incByte( B ); 6402} 6403 6404void opcode_05() // DEC B 6405{ 6406 B = decByte( B ); 6407} 6408 6409void opcode_06() // LD B,n 6410{ 6411 B = fetchByte(); 6412} 6413 6414void opcode_07() // RLCA 6415{ 6416 A = (A << 1) | (A >> 7); 6417 F = F & ~(AddSub | Halfcarry | Carry); 6418 if( A & 0x01 ) F |= Carry; 6419} 6420 6421void opcode_08() // EX AF,AF' 6422{ 6423 unsigned char x; 6424 6425 x = A; A = A1; A1 = x; 6426 x = F; F = F1; F1 = x; 6427} 6428 6429void opcode_09() // ADD HL,BC 6430{ 6431 unsigned hl = HL(); 6432 unsigned rp = BC(); 6433 unsigned x = hl + rp; 6434 6435 F &= Sign | Zero | Parity; 6436 if( x > 0xFFFF ) F |= Carry; 6437 if( ((hl & 0xFFF) + (rp & 0xFFF)) > 0xFFF ) F |= Halfcarry; 6438 6439 L = x & 0xFF; 6440 H = (x >> 8) & 0xFF; 6441} 6442 6443void opcode_0a() // LD A,(BC) 6444{ 6445 A = readByte( BC() ); 6446} 6447 6448void opcode_0b() // DEC BC 6449{ 6450 if( C-- == 0 ) --B; 6451} 6452 6453void opcode_0c() // INC C 6454{ 6455 C = incByte( C ); 6456} 6457 6458void opcode_0d() // DEC C 6459{ 6460 C = decByte( C ); 6461} 6462 6463void opcode_0e() // LD C,n 6464{ 6465 C = fetchByte(); 6466} 6467 6468void opcode_0f() // RRCA 6469{ 6470 A = (A >> 1) | (A << 7); 6471 F = F & ~(AddSub | Halfcarry | Carry); 6472 if( A & 0x80 ) F |= Carry; 6473} 6474 6475void opcode_10() // DJNZ d 6476{ 6477 unsigned char o = fetchByte(); 6478 6479 if( --B != 0 ) relJump( o ); 6480} 6481 6482void opcode_11() // LD DE,nn 6483{ 6484 E = fetchByte(); 6485 D = fetchByte(); 6486} 6487 6488void opcode_12() // LD (DE),A 6489{ 6490 writeByte( DE(), A ); 6491} 6492 6493void opcode_13() // INC DE 6494{ 6495 if( ++E == 0 ) ++D; 6496} 6497 6498void opcode_14() // INC D 6499{ 6500 D = incByte( D ); 6501} 6502 6503void opcode_15() // DEC D 6504{ 6505 D = decByte( D ); 6506} 6507 6508void opcode_16() // LD D,n 6509{ 6510 D = fetchByte(); 6511} 6512 6513void opcode_17() // RLA 6514{ 6515 unsigned char a = A; 6516 6517 A <<= 1; 6518 if( F & Carry ) A |= 0x01; 6519 F = F & ~(AddSub | Halfcarry | Carry); 6520 if( a & 0x80 ) F |= Carry; 6521} 6522 6523void opcode_18() // JR d 6524{ 6525 relJump( fetchByte() ); 6526} 6527 6528void opcode_19() // ADD HL,DE 6529{ 6530 unsigned hl = HL(); 6531 unsigned rp = DE(); 6532 unsigned x = hl + rp; 6533 6534 F &= Sign | Zero | Parity; 6535 if( x > 0xFFFF ) F |= Carry; 6536 if( ((hl & 0xFFF) + (rp & 0xFFF)) > 0xFFF ) F |= Halfcarry; 6537 6538 L = x & 0xFF; 6539 H = (x >> 8) & 0xFF; 6540} 6541 6542void opcode_1a() // LD A,(DE) 6543{ 6544 A = readByte( DE() ); 6545} 6546 6547void opcode_1b() // DEC DE 6548{ 6549 if( E-- == 0 ) --D; 6550} 6551 6552void opcode_1c() // INC E 6553{ 6554 E = incByte( E ); 6555} 6556 6557void opcode_1d() // DEC E 6558{ 6559 E = decByte( E ); 6560} 6561 6562void opcode_1e() // LD E,n 6563{ 6564 E = fetchByte(); 6565} 6566 6567void opcode_1f() // RRA 6568{ 6569 unsigned char a = A; 6570 6571 A >>= 1; 6572 if( F & Carry ) A |= 0x80; 6573 F = F & ~(AddSub | Halfcarry | Carry); 6574 if( a & 0x01 ) F |= Carry; 6575} 6576 6577void opcode_20() // JR NZ,d 6578{ 6579 unsigned char o = fetchByte(); 6580 6581 if( ! (F & Zero) ) relJump( o ); 6582} 6583 6584void opcode_21() // LD HL,nn 6585{ 6586 L = fetchByte(); 6587 H = fetchByte(); 6588} 6589 6590void opcode_22() // LD (nn),HL 6591{ 6592 unsigned x = fetchWord(); 6593 6594 writeByte( x , L ); 6595 writeByte( x+1, H ); 6596} 6597 6598void opcode_23() // INC HL 6599{ 6600 if( ++L == 0 ) ++H; 6601} 6602 6603void opcode_24() // INC H 6604{ 6605 H = incByte( H ); 6606} 6607 6608void opcode_25() // DEC H 6609{ 6610 H = decByte( H ); 6611} 6612 6613void opcode_26() // LD H,n 6614{ 6615 H = fetchByte(); 6616} 6617 6618/* 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: 6621 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 6633 6634 The carry and halfcarry flags are then updated using similar tables. 6635 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. 6639*/ 6640void opcode_27() // DAA 6641{ 6642 unsigned char diff; 6643 unsigned char hf = F & Halfcarry; 6644 unsigned char cf = F & Carry; 6645 unsigned char lower = A & 0x0F; 6646 6647 if( cf ) { 6648 diff = (lower >= 0x0A) || hf ? 0x66 : 0x60; 6649 } 6650 else { 6651 diff = (A >= 0x9A) ? 0x60 : 0x00; 6652 6653 if( hf || (lower >= 0x0A) ) diff += 0x06; 6654 } 6655 6656 if( A >= 0x9A ) cf = Carry; 6657 6658 if( F & Subtraction ) { 6659 A -= diff; 6660 F = PSZ_[A] | Subtraction | cf; 6661 if( hf && (lower <= 0x05) ) F |= Halfcarry; 6662 } 6663 else { 6664 A += diff; 6665 F = PSZ_[A] | cf; 6666 if( lower >= 0x0A ) F |= Halfcarry; 6667 } 6668} 6669 6670void opcode_28() // JR Z,d 6671{ 6672 unsigned char o = fetchByte(); 6673 6674 if( F & Zero ) relJump( o ); 6675} 6676 6677void opcode_29() // ADD HL,HL 6678{ 6679 unsigned hl = HL(); 6680 unsigned rp = hl; 6681 unsigned x = hl + rp; 6682 6683 F &= Sign | Zero | Parity; 6684 if( x > 0xFFFF ) F |= Carry; 6685 if( ((hl & 0xFFF) + (rp & 0xFFF)) > 0xFFF ) F |= Halfcarry; 6686 6687 L = x & 0xFF; 6688 H = (x >> 8) & 0xFF; 6689} 6690 6691void opcode_2a() // LD HL,(nn) 6692{ 6693 unsigned x = fetchWord(); 6694 6695 L = readByte( x ); 6696 H = readByte( x+1 ); 6697} 6698 6699void opcode_2b() // DEC HL 6700{ 6701 if( L-- == 0 ) --H; 6702} 6703 6704void opcode_2c() // INC L 6705{ 6706 L = incByte( L ); 6707} 6708 6709void opcode_2d() // DEC L 6710{ 6711 L = decByte( L ); 6712} 6713 6714void opcode_2e() // LD L,n 6715{ 6716 L = fetchByte(); 6717} 6718 6719void opcode_2f() // CPL 6720{ 6721 A ^= 0xFF; 6722 F |= AddSub | Halfcarry; 6723} 6724 6725void opcode_30() // JR NC,d 6726{ 6727 unsigned char o = fetchByte(); 6728 6729 if( ! (F & Carry) ) relJump( o ); 6730} 6731 6732void opcode_31() // LD SP,nn 6733{ 6734 SP = fetchWord(); 6735} 6736 6737void opcode_32() // LD (nn),A 6738{ 6739 writeByte( fetchWord(), A ); 6740} 6741 6742void opcode_33() // INC SP 6743{ 6744 SP = (SP + 1) & 0xFFFF; 6745} 6746 6747void opcode_34() // INC (HL) 6748{ 6749 writeByte( HL(), incByte( readByte( HL() ) ) ); 6750} 6751 6752void opcode_35() // DEC (HL) 6753{ 6754 writeByte( HL(), decByte( readByte( HL() ) ) ); 6755} 6756 6757void opcode_36() // LD (HL),n 6758{ 6759 writeByte( HL(), fetchByte() ); 6760} 6761 6762void opcode_37() // SCF 6763{ 6764 F = (F & (Parity | Sign | Zero)) | Carry; 6765} 6766 6767void opcode_38() // JR C,d 6768{ 6769 unsigned char o = fetchByte(); 6770 6771 if( F & Carry ) relJump( o ); 6772} 6773 6774void opcode_39() // ADD HL,SP 6775{ 6776 unsigned hl = HL(); 6777 unsigned rp = SP; 6778 unsigned x = hl + rp; 6779 6780 F &= Sign | Zero | Parity; 6781 if( x > 0xFFFF ) F |= Carry; 6782 if( ((hl & 0xFFF) + (rp & 0xFFF)) > 0xFFF ) F |= Halfcarry; 6783 6784 L = x & 0xFF; 6785 H = (x >> 8) & 0xFF; 6786} 6787 6788void opcode_3a() // LD A,(nn) 6789{ 6790 A = readByte( fetchWord() ); 6791} 6792 6793void opcode_3b() // DEC SP 6794{ 6795 SP = (SP - 1) & 0xFFFF; 6796} 6797 6798void opcode_3c() // INC A 6799{ 6800 A = incByte( A ); 6801} 6802 6803void opcode_3d() // DEC A 6804{ 6805 A = decByte( A ); 6806} 6807 6808void opcode_3e() // LD A,n 6809{ 6810 A = fetchByte(); 6811} 6812 6813void opcode_3f() // CCF 6814{ 6815 if( F & Carry ) { 6816 F = (F & (Parity | Sign | Zero)) | Halfcarry; // Halfcarry holds previous carry 6817 } 6818 else { 6819 F = (F & (Parity | Sign | Zero)) | Carry; 6820 } 6821} 6822 6823void opcode_40() // LD B,B 6824{ 6825} 6826 6827void opcode_41() // LD B,C 6828{ 6829 B = C; 6830} 6831 6832void opcode_42() // LD B,D 6833{ 6834 B = D; 6835} 6836 6837void opcode_43() // LD B,E 6838{ 6839 B = E; 6840} 6841 6842void opcode_44() // LD B,H 6843{ 6844 B = H; 6845} 6846 6847void opcode_45() // LD B,L 6848{ 6849 B = L; 6850} 6851 6852void opcode_46() // LD B,(HL) 6853{ 6854 B = readByte( HL() ); 6855} 6856 6857void opcode_47() // LD B,A 6858{ 6859 B = A; 6860} 6861 6862void opcode_48() // LD C,B 6863{ 6864 C = B; 6865} 6866 6867void opcode_49() // LD C,C 6868{ 6869} 6870 6871void opcode_4a() // LD C,D 6872{ 6873 C = D; 6874} 6875 6876void opcode_4b() // LD C,E 6877{ 6878 C = E; 6879} 6880 6881void opcode_4c() // LD C,H 6882{ 6883 C = H; 6884} 6885 6886void opcode_4d() // LD C,L 6887{ 6888 C = L; 6889} 6890 6891void opcode_4e() // LD C,(HL) 6892{ 6893 C = readByte( HL() ); 6894} 6895 6896void opcode_4f() // LD C,A 6897{ 6898 C = A; 6899} 6900 6901void opcode_50() // LD D,B 6902{ 6903 D = B; 6904} 6905 6906void opcode_51() // LD D,C 6907{ 6908 D = C; 6909} 6910 6911void opcode_52() // LD D,D 6912{ 6913} 6914 6915void opcode_53() // LD D,E 6916{ 6917 D = E; 6918} 6919 6920void opcode_54() // LD D,H 6921{ 6922 D = H; 6923} 6924 6925void opcode_55() // LD D,L 6926{ 6927 D = L; 6928} 6929 6930void opcode_56() // LD D,(HL) 6931{ 6932 D = readByte( HL() ); 6933} 6934 6935void opcode_57() // LD D,A 6936{ 6937 D = A; 6938} 6939 6940void opcode_58() // LD E,B 6941{ 6942 E = B; 6943} 6944 6945void opcode_59() // LD E,C 6946{ 6947 E = C; 6948} 6949 6950void opcode_5a() // LD E,D 6951{ 6952 E = D; 6953} 6954 6955void opcode_5b() // LD E,E 6956{ 6957} 6958 6959void opcode_5c() // LD E,H 6960{ 6961 E = H; 6962} 6963 6964void opcode_5d() // LD E,L 6965{ 6966 E = L; 6967} 6968 6969void opcode_5e() // LD E,(HL) 6970{ 6971 E = readByte( HL() ); 6972} 6973 6974void opcode_5f() // LD E,A 6975{ 6976 E = A; 6977} 6978 6979void opcode_60() // LD H,B 6980{ 6981 H = B; 6982} 6983 6984void opcode_61() // LD H,C 6985{ 6986 H = C; 6987} 6988 6989void opcode_62() // LD H,D 6990{ 6991 H = D; 6992} 6993 6994void opcode_63() // LD H,E 6995{ 6996 H = E; 6997} 6998 6999void opcode_64() // LD H,H 7000{ 7001} 7002 7003void opcode_65() // LD H,L 7004{ 7005 H = L; 7006} 7007 7008void opcode_66() // LD H,(HL) 7009{ 7010 H = readByte( HL() ); 7011} 7012 7013void opcode_67() // LD H,A 7014{ 7015 H = A; 7016} 7017 7018void opcode_68() // LD L,B 7019{ 7020 L = B; 7021} 7022 7023void opcode_69() // LD L,C 7024{ 7025 L = C; 7026} 7027 7028void opcode_6a() // LD L,D 7029{ 7030 L = D; 7031} 7032 7033void opcode_6b() // LD L,E 7034{ 7035 L = E; 7036} 7037 7038void opcode_6c() // LD L,H 7039{ 7040 L = H; 7041} 7042 7043void opcode_6d() // LD L,L 7044{ 7045} 7046 7047void opcode_6e() // LD L,(HL) 7048{ 7049 L = readByte( HL() ); 7050} 7051 7052void opcode_6f() // LD L,A 7053{ 7054 L = A; 7055} 7056 7057void opcode_70() // LD (HL),B 7058{ 7059 writeByte( HL(), B ); 7060} 7061 7062void opcode_71() // LD (HL),C 7063{ 7064 writeByte( HL(), C ); 7065} 7066 7067void opcode_72() // LD (HL),D 7068{ 7069 writeByte( HL(), D ); 7070} 7071 7072void opcode_73() // LD (HL),E 7073{ 7074 writeByte( HL(), E ); 7075} 7076 7077void opcode_74() // LD (HL),H 7078{ 7079 writeByte( HL(), H ); 7080} 7081 7082void opcode_75() // LD (HL),L 7083{ 7084 writeByte( HL(), L ); 7085} 7086 7087void opcode_76() // HALT 7088{ 7089 iflags_ |= Halted; 7090} 7091 7092void opcode_77() // LD (HL),A 7093{ 7094 writeByte( HL(), A ); 7095} 7096 7097void opcode_78() // LD A,B 7098{ 7099 A = B; 7100} 7101 7102void opcode_79() // LD A,C 7103{ 7104 A = C; 7105} 7106 7107void opcode_7a() // LD A,D 7108{ 7109 A = D; 7110} 7111 7112void opcode_7b() // LD A,E 7113{ 7114 A = E; 7115} 7116 7117void opcode_7c() // LD A,H 7118{ 7119 A = H; 7120} 7121 7122void opcode_7d() // LD A,L 7123{ 7124 A = L; 7125} 7126 7127void opcode_7e() // LD A,(HL) 7128{ 7129 A = readByte( HL() ); 7130} 7131 7132void opcode_7f() // LD A,A 7133{ 7134} 7135 7136void opcode_80() // ADD A,B 7137{ 7138 addByte( B, 0 ); 7139} 7140 7141void opcode_81() // ADD A,C 7142{ 7143 addByte( C, 0 ); 7144} 7145 7146void opcode_82() // ADD A,D 7147{ 7148 addByte( D, 0 ); 7149} 7150 7151void opcode_83() // ADD A,E 7152{ 7153 addByte( E, 0 ); 7154} 7155 7156void opcode_84() // ADD A,H 7157{ 7158 addByte( H, 0 ); 7159} 7160 7161void opcode_85() // ADD A,L 7162{ 7163 addByte( L, 0 ); 7164} 7165 7166void opcode_86() // ADD A,(HL) 7167{ 7168 addByte( readByte( HL() ), 0 ); 7169} 7170 7171void opcode_87() // ADD A,A 7172{ 7173 addByte( A, 0 ); 7174} 7175 7176void opcode_88() // ADC A,B 7177{ 7178 addByte( B, F & Carry ); 7179} 7180 7181void opcode_89() // ADC A,C 7182{ 7183 addByte( C, F & Carry ); 7184} 7185 7186void opcode_8a() // ADC A,D 7187{ 7188 addByte( D, F & Carry ); 7189} 7190 7191void opcode_8b() // ADC A,E 7192{ 7193 addByte( E, F & Carry ); 7194} 7195 7196void opcode_8c() // ADC A,H 7197{ 7198 addByte( H, F & Carry ); 7199} 7200 7201void opcode_8d() // ADC A,L 7202{ 7203 addByte( L, F & Carry ); 7204} 7205 7206void opcode_8e() // ADC A,(HL) 7207{ 7208 addByte( readByte( HL() ), F & Carry ); 7209} 7210 7211void opcode_8f() // ADC A,A 7212{ 7213 addByte( A, F & Carry ); 7214} 7215 7216void opcode_90() // SUB B 7217{ 7218 A = subByte( B, 0 ); 7219} 7220 7221void opcode_91() // SUB C 7222{ 7223 A = subByte( C, 0 ); 7224} 7225 7226void opcode_92() // SUB D 7227{ 7228 A = subByte( D, 0 ); 7229} 7230 7231void opcode_93() // SUB E 7232{ 7233 A = subByte( E, 0 ); 7234} 7235 7236void opcode_94() // SUB H 7237{ 7238 A = subByte( H, 0 ); 7239} 7240 7241void opcode_95() // SUB L 7242{ 7243 A = subByte( L, 0 ); 7244} 7245 7246void opcode_96() // SUB (HL) 7247{ 7248 A = subByte( readByte( HL() ), 0 ); 7249} 7250 7251void opcode_97() // SUB A 7252{ 7253 A = subByte( A, 0 ); 7254} 7255 7256void opcode_98() // SBC A,B 7257{ 7258 A = subByte( B, F & Carry ); 7259} 7260 7261void opcode_99() // SBC A,C 7262{ 7263 A = subByte( C, F & Carry ); 7264} 7265 7266void opcode_9a() // SBC A,D 7267{ 7268 A = subByte( D, F & Carry ); 7269} 7270 7271void opcode_9b() // SBC A,E 7272{ 7273 A = subByte( E, F & Carry ); 7274} 7275 7276void opcode_9c() // SBC A,H 7277{ 7278 A = subByte( H, F & Carry ); 7279} 7280 7281void opcode_9d() // SBC A,L 7282{ 7283 A = subByte( L, F & Carry ); 7284} 7285 7286void opcode_9e() // SBC A,(HL) 7287{ 7288 A = subByte( readByte( HL() ), F & Carry ); 7289} 7290 7291void opcode_9f() // SBC A,A 7292{ 7293 A = subByte( A, F & Carry ); 7294} 7295 7296void opcode_a0() // AND B 7297{ 7298 A &= B; 7299 setFlagsPSZ(); 7300} 7301 7302void opcode_a1() // AND C 7303{ 7304 A &= C; 7305 setFlagsPSZ(); 7306} 7307 7308void opcode_a2() // AND D 7309{ 7310 A &= D; 7311 setFlagsPSZ(); 7312} 7313 7314void opcode_a3() // AND E 7315{ 7316 A &= E; 7317 setFlagsPSZ(); 7318} 7319 7320void opcode_a4() // AND H 7321{ 7322 A &= H; 7323 setFlagsPSZ(); 7324} 7325 7326void opcode_a5() // AND L 7327{ 7328 A &= L; 7329 setFlagsPSZ(); 7330} 7331 7332void opcode_a6() // AND (HL) 7333{ 7334 A &= readByte( HL() ); 7335 setFlagsPSZ(); 7336} 7337 7338void opcode_a7() // AND A 7339{ 7340 setFlagsPSZ(); 7341} 7342 7343void opcode_a8() // XOR B 7344{ 7345 A ^= B; 7346 setFlags35PSZ000(); 7347} 7348 7349void opcode_a9() // XOR C 7350{ 7351 A ^= C; 7352 setFlags35PSZ000(); 7353} 7354 7355void opcode_aa() // XOR D 7356{ 7357 A ^= D; 7358 setFlags35PSZ000(); 7359} 7360 7361void opcode_ab() // XOR E 7362{ 7363 A ^= E; 7364 setFlags35PSZ000(); 7365} 7366 7367void opcode_ac() // XOR H 7368{ 7369 A ^= H; 7370 setFlags35PSZ000(); 7371} 7372 7373void opcode_ad() // XOR L 7374{ 7375 A ^= L; 7376 setFlags35PSZ000(); 7377} 7378 7379void opcode_ae() // XOR (HL) 7380{ 7381 A ^= readByte( HL() ); 7382 setFlags35PSZ000(); 7383} 7384 7385void opcode_af() // XOR A 7386{ 7387 A = 0; 7388 setFlags35PSZ000(); 7389} 7390 7391void opcode_b0() // OR B 7392{ 7393 A |= B; 7394 setFlags35PSZ000(); 7395} 7396 7397void opcode_b1() // OR C 7398{ 7399 A |= C; 7400 setFlags35PSZ000(); 7401} 7402 7403void opcode_b2() // OR D 7404{ 7405 A |= D; 7406 setFlags35PSZ000(); 7407} 7408 7409void opcode_b3() // OR E 7410{ 7411 A |= E; 7412 setFlags35PSZ000(); 7413} 7414 7415void opcode_b4() // OR H 7416{ 7417 A |= H; 7418 setFlags35PSZ000(); 7419} 7420 7421void opcode_b5() // OR L 7422{ 7423 A |= L; 7424 setFlags35PSZ000(); 7425} 7426 7427void opcode_b6() // OR (HL) 7428{ 7429 A |= readByte( HL() ); 7430 setFlags35PSZ000(); 7431} 7432 7433void opcode_b7() // OR A 7434{ 7435 setFlags35PSZ000(); 7436} 7437 7438void opcode_b8() // CP B 7439{ 7440 cmpByte( B ); 7441} 7442 7443void opcode_b9() // CP C 7444{ 7445 cmpByte( C ); 7446} 7447 7448void opcode_ba() // CP D 7449{ 7450 cmpByte( D ); 7451} 7452 7453void opcode_bb() // CP E 7454{ 7455 cmpByte( E ); 7456} 7457 7458void opcode_bc() // CP H 7459{ 7460 cmpByte( H ); 7461} 7462 7463void opcode_bd() // CP L 7464{ 7465 cmpByte( L ); 7466} 7467 7468void opcode_be() // CP (HL) 7469{ 7470 cmpByte( readByte( HL() ) ); 7471} 7472 7473void opcode_bf() // CP A 7474{ 7475 cmpByte( A ); 7476} 7477 7478void opcode_c0() // RET NZ 7479{ 7480 if( ! (F & Zero) ) { 7481 retFromSub(); 7482 cycles_ += 2; 7483 } 7484} 7485 7486void opcode_c1() // POP BC 7487{ 7488 C = readByte( SP++ ); 7489 B = readByte( SP++ ); 7490} 7491 7492void opcode_c2() // JP NZ,nn 7493{ 7494 if( ! (F & Zero) ) 7495 PC = fetchWord(); 7496 else 7497 PC += 2; 7498} 7499 7500void opcode_c3() // JP nn 7501{ 7502 PC = readWord( PC ); 7503} 7504 7505void opcode_c4() // CALL NZ,nn 7506{ 7507 if( ! (F & Zero) ) { 7508 callSub( fetchWord() ); 7509 cycles_ += 2; 7510 } 7511 else { 7512 PC += 2; 7513 } 7514} 7515 7516void opcode_c5() // PUSH BC 7517{ 7518 writeByte( --SP, B ); 7519 writeByte( --SP, C ); 7520} 7521 7522void opcode_c6() // ADD A,n 7523{ 7524 addByte( fetchByte(), 0 ); 7525} 7526 7527void opcode_c7() // RST 0 7528{ 7529 callSub( 0x00 ); 7530} 7531 7532void opcode_c8() // RET Z 7533{ 7534 if( F & Zero ) { 7535 retFromSub(); 7536 cycles_ += 2; 7537 } 7538} 7539 7540void opcode_c9() // RET 7541{ 7542 retFromSub(); 7543} 7544 7545void opcode_ca() // JP Z,nn 7546{ 7547 if( F & Zero ) 7548 PC = fetchWord(); 7549 else 7550 PC += 2; 7551} 7552 7553void opcode_cb() // [Prefix] 7554{ 7555 unsigned op = fetchByte(); 7556 7557 cycles_ += OpInfoCB_[ op ].cycles; 7558 OpInfoCB_[ op ].handler(); 7559} 7560 7561void opcode_cc() // CALL Z,nn 7562{ 7563 if( F & Zero ) { 7564 callSub( fetchWord() ); 7565 cycles_ += 2; 7566 } 7567 else { 7568 PC += 2; 7569 } 7570} 7571 7572void opcode_cd() // CALL nn 7573{ 7574 callSub( fetchWord() ); 7575} 7576 7577void opcode_ce() // ADC A,n 7578{ 7579 addByte( fetchByte(), F & Carry ); 7580} 7581 7582void opcode_cf() // RST 8 7583{ 7584 callSub( 0x08 ); 7585} 7586 7587void opcode_d0() // RET NC 7588{ 7589 if( ! (F & Carry) ) { 7590 retFromSub(); 7591 cycles_ += 2; 7592 } 7593} 7594 7595void opcode_d1() // POP DE 7596{ 7597 E = readByte( SP++ ); 7598 D = readByte( SP++ ); 7599} 7600 7601void opcode_d2() // JP NC,nn 7602{ 7603 if( ! (F & Carry) ) 7604 PC = fetchWord(); 7605 else 7606 PC += 2; 7607} 7608 7609void opcode_d3() // OUT (n),A 7610{ 7611 writePort( fetchByte(), A ); 7612} 7613 7614void opcode_d4() // CALL NC,nn 7615{ 7616 if( ! (F & Carry) ) { 7617 callSub( fetchWord() ); 7618 cycles_ += 2; 7619 } 7620 else { 7621 PC += 2; 7622 } 7623} 7624 7625void opcode_d5() // PUSH DE 7626{ 7627 writeByte( --SP, D ); 7628 writeByte( --SP, E ); 7629} 7630 7631void opcode_d6() // SUB n 7632{ 7633 A = subByte( fetchByte(), 0 ); 7634} 7635 7636void opcode_d7() // RST 10H 7637{ 7638 callSub( 0x10 ); 7639} 7640 7641void opcode_d8() // RET C 7642{ 7643 if( F & Carry ) { 7644 retFromSub(); 7645 cycles_ += 2; 7646 } 7647} 7648 7649void opcode_d9() // EXX 7650{ 7651 unsigned char x; 7652 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; 7659} 7660 7661void opcode_da() // JP C,nn 7662{ 7663 if( F & Carry ) 7664 PC = fetchWord(); 7665 else 7666 PC += 2; 7667} 7668 7669void opcode_db() // IN A,(n) 7670{ 7671 A = readPort( fetchByte() ); 7672} 7673 7674void opcode_dc() // CALL C,nn 7675{ 7676 if( F & Carry ) { 7677 callSub( fetchWord() ); 7678 cycles_ += 2; 7679 } 7680 else { 7681 PC += 2; 7682 } 7683} 7684 7685void opcode_dd() // [IX Prefix] 7686{ 7687 do_opcode_xy( OpInfoDD_ ); 7688 IX &= 0xFFFF; 7689} 7690 7691void opcode_de() // SBC A,n 7692{ 7693 A = subByte( fetchByte(), F & Carry ); 7694} 7695 7696void opcode_df() // RST 18H 7697{ 7698 callSub( 0x18 ); 7699} 7700 7701void opcode_e0() // RET PO 7702{ 7703 if( ! (F & Parity) ) { 7704 retFromSub(); 7705 cycles_ += 2; 7706 } 7707} 7708 7709void opcode_e1() // POP HL 7710{ 7711 L = readByte( SP++ ); 7712 H = readByte( SP++ ); 7713} 7714 7715void opcode_e2() // JP PO,nn 7716{ 7717 if( ! (F & Parity) ) 7718 PC = fetchWord(); 7719 else 7720 PC += 2; 7721} 7722 7723void opcode_e3() // EX (SP),HL 7724{ 7725 unsigned char x; 7726 7727 x = readByte( SP ); writeByte( SP, L ); L = x; 7728 x = readByte( SP+1 ); writeByte( SP+1, H ); H = x; 7729} 7730 7731void opcode_e4() // CALL PO,nn 7732{ 7733 if( ! (F & Parity) ) { 7734 callSub( fetchWord() ); 7735 cycles_ += 2; 7736 } 7737 else { 7738 PC += 2; 7739 } 7740} 7741 7742void opcode_e5() // PUSH HL 7743{ 7744 writeByte( --SP, H ); 7745 writeByte( --SP, L ); 7746} 7747 7748void opcode_e6() // AND n 7749{ 7750 A &= fetchByte(); 7751 setFlagsPSZ(); 7752} 7753 7754void opcode_e7() // RST 20H 7755{ 7756 callSub( 0x20 ); 7757} 7758 7759void opcode_e8() // RET PE 7760{ 7761 if( F & Parity ) { 7762 retFromSub(); 7763 cycles_ += 2; 7764 } 7765} 7766 7767void opcode_e9() // JP (HL) 7768{ 7769 PC = HL(); 7770} 7771 7772void opcode_ea() // JP PE,nn 7773{ 7774 if( F & Parity ) 7775 PC = fetchWord(); 7776 else 7777 PC += 2; 7778} 7779 7780void opcode_eb() // EX DE,HL 7781{ 7782 unsigned char x; 7783 7784 x = D; D = H; H = x; 7785 x = E; E = L; L = x; 7786} 7787 7788void opcode_ec() // CALL PE,nn 7789{ 7790 if( F & Parity ) { 7791 callSub( fetchWord() ); 7792 cycles_ += 2; 7793 } 7794 else { 7795 PC += 2; 7796 } 7797} 7798 7799void opcode_ed() // [Prefix] 7800{ 7801 unsigned op = fetchByte(); 7802 7803 if( OpInfoED_[ op ].handler ) { 7804 OpInfoED_[ op ].handler(); 7805 cycles_ += OpInfoED_[ op ].cycles; 7806 } 7807 else { 7808 cycles_ += OpInfo_[ 0 ].cycles; // NOP 7809 } 7810} 7811 7812void opcode_ee() // XOR n 7813{ 7814 A ^= fetchByte(); 7815 setFlags35PSZ000(); 7816} 7817 7818void opcode_ef() // RST 28H 7819{ 7820 callSub( 0x28 ); 7821} 7822 7823void opcode_f0() // RET P 7824{ 7825 if( ! (F & Sign) ) { 7826 retFromSub(); 7827 cycles_ += 2; 7828 } 7829} 7830 7831void opcode_f1() // POP AF 7832{ 7833 F = readByte( SP++ ); 7834 A = readByte( SP++ ); 7835} 7836 7837void opcode_f2() // JP P,nn 7838{ 7839 if( ! (F & Sign) ) 7840 PC = fetchWord(); 7841 else 7842 PC += 2; 7843} 7844 7845void opcode_f3() // DI 7846{ 7847 iflags_ &= ~(IFF1 | IFF2); 7848} 7849 7850void opcode_f4() // CALL P,nn 7851{ 7852 if( ! (F & Sign) ) { 7853 callSub( fetchWord() ); 7854 cycles_ += 2; 7855 } 7856 else { 7857 PC += 2; 7858 } 7859} 7860 7861void opcode_f5() // PUSH AF 7862{ 7863 writeByte( --SP, A ); 7864 writeByte( --SP, F ); 7865} 7866 7867void opcode_f6() // OR n 7868{ 7869 A |= fetchByte(); 7870 setFlags35PSZ000(); 7871} 7872 7873void opcode_f7() // RST 30H 7874{ 7875 callSub( 0x30 ); 7876} 7877 7878void opcode_f8() // RET M 7879{ 7880 if( F & Sign ) { 7881 retFromSub(); 7882 cycles_ += 2; 7883 } 7884} 7885 7886void opcode_f9() // LD SP,HL 7887{ 7888 SP = HL(); 7889} 7890 7891void opcode_fa() // JP M,nn 7892{ 7893 if( F & Sign ) 7894 PC = fetchWord(); 7895 else 7896 PC += 2; 7897} 7898 7899void opcode_fb() // EI 7900{ 7901 iflags_ |= IFF1 | IFF2; 7902} 7903 7904void opcode_fc() // CALL M,nn 7905{ 7906 if( F & Sign ) { 7907 callSub( fetchWord() ); 7908 cycles_ += 2; 7909 } 7910 else { 7911 PC += 2; 7912 } 7913} 7914 7915void opcode_fd() // [IY Prefix] 7916{ 7917 do_opcode_xy( OpInfoFD_ ); 7918 IY &= 0xFFFF; 7919} 7920 7921 7922void opcode_fe() // CP n 7923{ 7924 subByte( fetchByte(), 0 ); 7925} 7926 7927void opcode_ff() // RST 38H 7928{ 7929 callSub( 0x38 ); 7930} 7931 7932 7933/* Executes one instruction */ 7934void step(void) 7935{ 7936 // Update memory refresh register (not strictly needed but...) 7937 R = (R+1) & 0x7F; 7938 7939 if( iflags_ & Halted ) { 7940 // CPU is halted, do a NOP instruction 7941 cycles_ += OpInfo_[0].cycles; // NOP 7942 } 7943 else { 7944 // Get the opcode to execute 7945 unsigned op = fetchByte(); 7946 7947 // Update the cycles counter with the number of cycles for this opcode 7948 cycles_ += OpInfo_[ op ].cycles; 7949 7950 // Execute the opcode handler 7951 OpInfo_[ op ].handler(); 7952 7953 // Update registers 7954 PC &= 0xFFFF; // Clip program counter 7955 SP &= 0xFFFF; // Clip stack pointer 7956 } 7957} 7958 7959/* 7960 Runs the CPU for the specified number of cycles. 7961 7962 Note: the memory refresh register is not updated! 7963*/ 7964unsigned z80_run( unsigned runCycles ) 7965{ 7966 unsigned target_cycles = cycles_ + runCycles; 7967 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; 7975 } 7976 else { 7977 // Get the opcode to execute 7978 unsigned op = fetchByte(); 7979 7980 // Update the cycles counter with the number of cycles for this opcode 7981 cycles_ += OpInfo_[ op ].cycles; 7982 7983 // Execute the opcode handler 7984 OpInfo_[ op ].handler(); 7985 } 7986 } 7987 7988 // Update registers 7989 PC &= 0xFFFF; // Clip program counter 7990 SP &= 0xFFFF; // Clip stack pointer 7991 7992 // Return the number of extra cycles executed 7993 return cycles_ - target_cycles; 7994} 7995 7996/* Interrupt */ 7997void z80_interrupt( unsigned char data ) 7998{ 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); 8003 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; 8017 } 8018 } 8019} 8020 8021/* Non-maskable interrupt */ 8022void nmi(void) 8023{ 8024 // Disable maskable interrupts but preserve IFF2 (that is a copy of IFF1), 8025 // also restart the CPU if halted 8026 iflags_ &= ~(IFF1 | Halted); 8027 8028 callSub( 0x66 ); 8029 8030 cycles_ += 11; 8031} 8032 8033void do_opcode_xy( OpcodeInfo * info ) 8034{ 8035 unsigned op = fetchByte(); 8036 8037 if( (op == 0xDD) || (op == 0xFD) ) { 8038 // Exit now, to avoid possible infinite loops 8039 PC--; 8040 cycles_ += OpInfo_[ 0 ].cycles; // NOP 8041 } 8042 else if( op == 0xED ) { 8043 // IX or IY prefix is ignored for this opcode 8044 opcode_ed(); 8045 } 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(); 8052 } 8053 else { 8054 // Extended opcode not valid, fall back to standard opcode 8055 cycles_ += OpInfo_[ op ].cycles; 8056 OpInfo_[ op ].handler(); 8057 } 8058 } 8059} 8060