3 * @(#)Z80.java 1.1 27/04/97 Adam Davidson & Andrew Pollard
7 * <p>The Z80 class emulates the Zilog Z80 microprocessor.</p>
9 * @version 1.1 27 Apr 1997
10 * @author <A HREF="http://www.odie.demon.co.uk/spectrum">Adam Davidson & Andrew Pollard</A>
16 public class Z80
extends Object
{
18 public Z80( double clockFrequencyInMHz
, int intFreq
) {
19 tstatesPerInterrupt
= (int) ((clockFrequencyInMHz
* 1e6
) / intFreq
);
22 protected int tstatesPerInterrupt
= 0;
24 public static final int IM0
= 0;
25 public static final int IM1
= 1;
26 public static final int IM2
= 2;
28 private static final int F_C
= 0x01;
29 private static final int F_N
= 0x02;
30 private static final int F_PV
= 0x04;
31 private static final int F_3
= 0x08;
32 private static final int F_H
= 0x10;
33 private static final int F_5
= 0x20;
34 private static final int F_Z
= 0x40;
35 private static final int F_S
= 0x80;
37 private static final int PF
= F_PV
;
38 private static final int p_
= 0;
40 private static final boolean parity
[] = new boolean[256];
42 for ( int i
= 0; i
< 256; i
++ ) {
44 for ( int j
= 0; j
< 8; j
++ ) {
45 if ( (i
& (1<<j
)) != 0 ) {
54 private void logCall(int addr) {
55 String name = "0x" + Integer.toString(addr, 16);
56 if (addr==341) name = "zeromem";
57 if (addr==0x7f) name = "hardware_int";
58 if (addr==0xf47) name = "PChange";
59 if (addr==0xa63) name = "FlashBoot";
60 if (addr==0xf6) name = "seg_init";
61 if (addr==0x698) name = "InitCardData";
62 if (addr==0xf61) name = "VChange";
63 if (addr==0x23e) name = "?S_MUL_L02";
64 if (addr==0x5aa) name = "?BANK_CALL_DIRECT";
65 if (addr==0x664) name = "?MEMSET";
66 if (addr==0x14a) name = "copy_mem";
67 if (addr==0x137b) name = "KernelInitalize";
68 if (addr==0x601) name = "?ENT_PARM_DIRECT";
69 if (addr==0x933) name = "ClearEventHandlers";
70 if (addr==0x942) name = "ClearDynamicHandlers";
71 if (addr==0xacb) name = "InitKernelCore";
72 if (addr==0x1b7d) name = "EnableSpeaker";
73 if (addr==0x60d) name = "?ENT_AUTO_DIRECT";
74 if (addr==0x1c7b) name = "CheckMemoryAddress";
75 if (addr==0x1c33) name = "CheckMemoryArea";
76 if (addr==0x2a8) name = "?UL_RSH_L03";
82 System.out.println(spaces.substring(0, 2*pushedPC) + "logCall: calling " + name);
85 int realAddr = A()*8192 + HL();
86 System.out.println(spaces.substring(0, 2*pushedPC) + "logCall: doing a bank call direct to 0x" + Integer.toString(realAddr, 16));
90 void logCall(int addr
) { };
91 void logJump(int addr
) { };
93 final static String spaces
= " ";
97 private void logJump(int addr) {
101 System.out.println(spaces.substring(0, 2*pushedPC) + "logCall: jumping to 0x" + Integer.toString(addr, 16));
102 if (addr==0x621) pushedPC--;
103 if (addr==0x5e2) pushedPC--;
106 /** Main registers */
107 protected int _A
= 0, _HL
= 0, _B
= 0, _C
= 0, _DE
= 0;
108 protected boolean fS
= false, fZ
= false, f5
= false, fH
= false;
109 protected boolean f3
= false, fPV
= false, fN
= false, fC
= false;
111 /** Alternate registers */
112 protected int _AF_
= 0, _HL_
= 0, _BC_
= 0, _DE_
= 0;
114 /** Index registers - ID used as temporary for ix/iy */
115 protected int _IX
= 0, _IY
= 0, _ID
= 0;
117 /** Stack Pointer and Program Counter */
118 protected int _SP
= 0, _PC
= 0;
120 /** Interrupt and Refresh registers */
121 protected int _I
= 0, _R
= 0, _R7
= 0;
123 /** Interrupt flip-flops */
124 protected boolean _IFF1
= true, _IFF2
= true;
125 protected int _IM
= 2;
128 public final int mem
[] = new int[ 65536 ];
130 /** 16 bit register access */
131 public final int AF() { return (A() << 8) | F(); }
132 public final void AF( int word
) {
137 public final int BC() { return (B() << 8) | C(); }
138 public final void BC( int word
) {
143 public final int DE() { return _DE
; }
144 public final void DE( int word
) {
148 public final int HL() { return _HL
; }
149 public final void HL( int word
) {
153 public final int PC() { return _PC
; }
154 public final void PC( int word
) {
158 public final int SP() { return _SP
; }
159 public final void SP( int word
) {
163 public final int ID() { return _ID
; }
164 public final void ID( int word
) {
168 public final int IX() { return _IX
; }
169 public final void IX( int word
) {
173 public final int IY() { return _IY
; }
174 public final void IY( int word
) {
179 /** 8 bit register access */
180 public final int A() { return _A
; }
181 public final void A( int bite
) {
185 public final int F() {
186 return (Sset() ? F_S
: 0) |
191 (PVset() ? F_PV
: 0) |
195 public final void F( int bite
) {
196 fS
= (bite
& F_S
) != 0;
197 fZ
= (bite
& F_Z
) != 0;
198 f5
= (bite
& F_5
) != 0;
199 fH
= (bite
& F_H
) != 0;
200 f3
= (bite
& F_3
) != 0;
201 fPV
= (bite
& F_PV
) != 0;
202 fN
= (bite
& F_N
) != 0;
203 fC
= (bite
& F_C
) != 0;
207 public final int B() { return _B
; }
208 public final void B( int bite
) {
211 public final int C() { return _C
; }
212 public final void C( int bite
) {
216 public final int D() { return (_DE
>> 8); }
217 public final void D( int bite
) {
218 _DE
= (bite
<< 8) | (_DE
& 0x00ff);
220 public final int E() { return (_DE
& 0xff); }
221 public final void E( int bite
) {
222 _DE
= (_DE
& 0xff00) | bite
;
225 public final int H() { return (_HL
>> 8); }
226 public final void H( int bite
) {
227 _HL
= (bite
<< 8) | (_HL
& 0x00ff);
229 public final int L() { return (_HL
& 0xff); }
230 public final void L( int bite
) {
231 _HL
= (_HL
& 0xff00) | bite
;
234 public final int IDH() { return (_ID
>> 8); }
235 public final void IDH( int bite
) {
236 _ID
= (bite
<< 8) | (_ID
& 0x00ff);
238 public final int IDL() { return (_ID
& 0xff); }
239 public final void IDL( int bite
) {
240 _ID
= (_ID
& 0xff00) | bite
;
244 /** Memory refresh register */
245 public final int R7() { return _R7
; }
246 public final int R() { return (_R
& 0x7f) | _R7
; }
247 public final void R( int bite
) {
252 public final void REFRESH( int t
) {
257 /** Interrupt modes/register */
258 public final int I() { return _I
; }
259 public final void I( int bite
) {
263 public final boolean IFF1() { return _IFF1
; }
264 public final void IFF1( boolean iff1
) {
268 public final boolean IFF2() { return _IFF2
; }
269 public final void IFF2( boolean iff2
) {
273 public final int IM() { return _IM
; }
274 public final void IM( int im
) {
280 public final void setZ( boolean f
) { fZ
= f
; }
281 public final void setC( boolean f
) { fC
= f
; }
282 public final void setS( boolean f
) { fS
= f
; }
283 public final void setH( boolean f
) { fH
= f
; }
284 public final void setN( boolean f
) { fN
= f
; }
285 public final void setPV( boolean f
) {fPV
= f
;}
286 public final void set3( boolean f
) { f3
= f
; }
287 public final void set5( boolean f
) { f5
= f
; }
289 public final boolean Zset() { return fZ
; }
290 public final boolean Cset() { return fC
; }
291 public final boolean Sset() { return fS
; }
292 public final boolean Hset() { return fH
; }
293 public final boolean Nset() { return fN
; }
294 public final boolean PVset() { return fPV
; }
298 public int peekb( int addr
) {
301 public void pokeb( int addr
, int newByte
) {
302 mem
[ addr
] = newByte
;
307 public void pokew( int addr
, int word
) {
308 pokeb( addr
, word
& 0xff );
310 pokeb( addr
& 0xffff, word
>> 8 );
312 public int peekw( int addr
) {
313 int t
= peekb( addr
);
315 return t
| (peekb( addr
& 0xffff ) << 8);
319 /** Index register access */
320 private final int ID_d() {
321 return ((ID()+(byte)nxtpcb()) & 0xffff);
326 public final void pushw( int word
) {
327 int sp
= ((SP()-2) & 0xffff);
331 public final int popw() {
335 t
|= (peekb( sp
& 0xffff) << 8);
342 public final void pushpc() { pushw( PC() ); }
343 public final void poppc() { PC( popw() ); }
346 /** Program access */
347 private final int nxtpcb() {
353 private final int nxtpcw() {
356 t
|= ( peekb( ++pc
& 0xffff ) << 8 );
362 /** Reset all registers to power on state */
363 public void reset() {
395 public void outb( int port
, int bite
, int tstates
) {
397 public int inb( int port
) {
401 /** Interrupt handlers */
402 private static final boolean interruptTriggered( int tstates
) {
403 return (tstates
>= 0);
406 public int interrupt() {
407 // If not a non-maskable interrupt
424 int t
= (I()<<8) | 0x00ff;
434 /** Z80 fetch/execute loop */
435 public final void execute() {
436 int local_tstates
= -tstatesPerInterrupt
;
439 if ( interruptTriggered( local_tstates
) ) {
440 local_tstates
-= tstatesPerInterrupt
- interrupt();
445 System
.out
.println(" PC: " + Integer
.toString(PC(), 16) +
446 " HL: " + Integer
.toString(HL(), 16) +
447 " DE: " + Integer
.toString(DE(), 16) +
451 switch ( nxtpcb() ) {
455 local_tstates
+= ( 4 );
458 case 8: /* EX AF,AF' */
461 local_tstates
+= ( 4 );
464 case 16: /* DJNZ dis */
468 B( b
= qdec8( B() ) );
470 byte d
= (byte) nxtpcb();
471 PC( (PC()+d
)&0xffff );
472 local_tstates
+= ( 13 );
476 local_tstates
+= ( 8 );
480 case 24: /* JR dis */
482 byte d
= (byte)nxtpcb();
483 PC( (PC()+d
)&0xffff );
484 local_tstates
+= ( 12 );
488 case 32: /* JR NZ,dis */
491 byte d
= (byte)nxtpcb();
492 PC( (PC()+d
)&0xffff );
493 local_tstates
+= ( 12 );
497 local_tstates
+= ( 7 );
501 case 40: /* JR Z,dis */
504 byte d
= (byte)nxtpcb();
505 PC( (PC()+d
)&0xffff );
506 local_tstates
+= ( 12 );
510 local_tstates
+= ( 7 );
514 case 48: /* JR NC,dis */
517 byte d
= (byte)nxtpcb();
518 PC( (PC()+d
)&0xffff );
519 local_tstates
+= ( 12 );
523 local_tstates
+= ( 7 );
527 case 56: /* JR C,dis */
530 byte d
= (byte)nxtpcb();
531 PC( (PC()+d
)&0xffff );
532 local_tstates
+= ( 12 );
536 local_tstates
+= ( 7 );
541 /* LD rr,nn / ADD HL,rr */
542 case 1: /* LD BC(),nn */
545 local_tstates
+= ( 10 );
548 case 9: /* ADD HL,BC */
550 HL( add16( HL(), BC() ) );
551 local_tstates
+= ( 11 );
554 case 17: /* LD DE,nn */
557 local_tstates
+= ( 10 );
560 case 25: /* ADD HL,DE */
562 HL( add16( HL(), DE() ) );
563 local_tstates
+= ( 11 );
566 case 33: /* LD HL,nn */
569 local_tstates
+= ( 10 );
572 case 41: /* ADD HL,HL */
575 HL( add16( hl
, hl
) );
576 local_tstates
+= ( 11 );
579 case 49: /* LD SP,nn */
582 local_tstates
+= ( 10 );
585 case 57: /* ADD HL,SP */
587 HL( add16( HL(), SP() ) );
588 local_tstates
+= ( 11 );
592 /* LD (**),A/A,(**) */
593 case 2: /* LD (BC),A */
594 { pokeb( BC(), A() ); local_tstates
+= ( 7 ); break; }
595 case 10: /* LD A,(BC) */
596 { A( peekb( BC() ) ); local_tstates
+= ( 7 ); break; }
597 case 18: /* LD (DE),A */
598 { pokeb( DE(), A() ); local_tstates
+= ( 7 ); break; }
599 case 26: /* LD A,(DE) */
600 { A( peekb( DE() ) ); local_tstates
+= ( 7 ); break; }
601 case 34: /* LD (nn),HL */
602 { pokew( nxtpcw(), HL() ); local_tstates
+= ( 16 ); break; }
603 case 42: /* LD HL,(nn) */
604 { HL( peekw( nxtpcw() ) ); local_tstates
+= ( 16 ); break; }
605 case 50: /* LD (nn),A */
606 { pokeb( nxtpcw(), A() ); local_tstates
+= ( 13 ); break; }
607 case 58: /* LD A,(nn) */
608 { A( peekb( nxtpcw() ) ); local_tstates
+= ( 13 ); break; }
612 { BC( inc16( BC() ) ); local_tstates
+= ( 6 ); break; }
613 case 11: /* DEC BC */
614 { BC( dec16( BC() ) ); local_tstates
+= ( 6 ); break; }
615 case 19: /* INC DE */
616 { DE( inc16( DE() ) ); local_tstates
+= ( 6 ); break; }
617 case 27: /* DEC DE */
618 { DE( dec16( DE() ) ); local_tstates
+= ( 6 ); break; }
619 case 35: /* INC HL */
620 { HL( inc16( HL() ) ); local_tstates
+= ( 6 ); break; }
621 case 43: /* DEC HL */
622 { HL( dec16( HL() ) ); local_tstates
+= ( 6 ); break; }
623 case 51: /* INC SP */
624 { SP( inc16( SP() ) ); local_tstates
+= ( 6 ); break; }
625 case 59: /* DEC SP */
626 { SP( dec16( SP() ) ); local_tstates
+= ( 6 ); break; }
630 { B( inc8( B() ) ); local_tstates
+= ( 4 ); break; }
632 { C( inc8( C() ) ); local_tstates
+= ( 4 ); break; }
634 { D( inc8( D() ) ); local_tstates
+= ( 4 ); break; }
636 { E( inc8( E() ) ); local_tstates
+= ( 4 ); break; }
638 { H( inc8( H() ) ); local_tstates
+= ( 4 ); break; }
640 { L( inc8( L() ) ); local_tstates
+= ( 4 ); break; }
641 case 52: /* INC (HL) */
644 pokeb( hl
, inc8( peekb( hl
) ) );
645 local_tstates
+= ( 11 );
648 case 60: /* INC A() */
649 { A( inc8( A() ) ); local_tstates
+= ( 4 ); break; }
653 { B( dec8( B() ) ); local_tstates
+= ( 4 ); break; }
655 { C( dec8( C() ) ); local_tstates
+= ( 4 ); break; }
657 { D( dec8( D() ) ); local_tstates
+= ( 4 ); break; }
659 { E( dec8( E() ) ); local_tstates
+= ( 4 ); break; }
661 { H( dec8( H() ) ); local_tstates
+= ( 4 ); break; }
663 { L( dec8( L() ) ); local_tstates
+= ( 4 ); break; }
664 case 53: /* DEC (HL) */
667 pokeb( hl
, dec8( peekb( hl
) ) );
668 local_tstates
+= ( 11 );
671 case 61: /* DEC A() */
672 { A( dec8( A() ) ); local_tstates
+= ( 4 ); break; }
676 { B( nxtpcb() ); local_tstates
+= ( 7 ); break; }
677 case 14: /* LD C,n */
678 { C( nxtpcb() ); local_tstates
+= ( 7 ); break; }
679 case 22: /* LD D,n */
680 { D( nxtpcb() ); local_tstates
+= ( 7 ); break; }
681 case 30: /* LD E,n */
682 { E( nxtpcb() ); local_tstates
+= ( 7 ); break; }
683 case 38: /* LD H,n */
684 { H( nxtpcb() ); local_tstates
+= ( 7 ); break; }
685 case 46: /* LD L,n */
686 { L( nxtpcb() ); local_tstates
+= ( 7 ); break; }
687 case 54: /* LD (HL),n */
689 pokeb( HL(), nxtpcb() );
690 local_tstates
+= ( 10 );
693 case 62: /* LD A,n */
694 { A( nxtpcb() ); local_tstates
+= ( 7 ); break; }
698 { rlc_a(); local_tstates
+= ( 4 ); break; }
700 { rrc_a(); local_tstates
+= ( 4 ); break; }
702 { rl_a(); local_tstates
+= ( 4 ); break; }
704 { rr_a(); local_tstates
+= ( 4 ); break; }
706 { daa_a(); local_tstates
+= ( 4 ); break; }
708 { cpl_a(); local_tstates
+= ( 4 ); break; }
710 { scf(); local_tstates
+= ( 4 ); break; }
712 { ccf(); local_tstates
+= ( 4 ); break; }
715 case 64: /* LD B,B */
716 { local_tstates
+= ( 4 ); break; }
717 case 65: /* LD B,C */
718 { B( C() ); local_tstates
+= ( 4 ); break; }
719 case 66: /* LD B,D */
720 { B( D() ); local_tstates
+= ( 4 ); break; }
721 case 67: /* LD B,E */
722 { B( E() ); local_tstates
+= ( 4 ); break; }
723 case 68: /* LD B,H */
724 { B( H() ); local_tstates
+= ( 4 ); break; }
725 case 69: /* LD B,L */
726 { B( L() ); local_tstates
+= ( 4 ); break; }
727 case 70: /* LD B,(HL) */
728 { B( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
729 case 71: /* LD B,A */
730 { B( A() ); local_tstates
+= ( 4 ); break; }
733 case 72: /* LD C,B */
734 { C( B() ); local_tstates
+= ( 4 ); break; }
735 case 73: /* LD C,C */
736 { local_tstates
+= ( 4 ); break; }
737 case 74: /* LD C,D */
738 { C( D() ); local_tstates
+= ( 4 ); break; }
739 case 75: /* LD C,E */
740 { C( E() ); local_tstates
+= ( 4 ); break; }
741 case 76: /* LD C,H */
742 { C( H() ); local_tstates
+= ( 4 ); break; }
743 case 77: /* LD C,L */
744 { C( L() ); local_tstates
+= ( 4 ); break; }
745 case 78: /* LD C,(HL) */
746 { C( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
747 case 79: /* LD C,A */
748 { C( A() ); local_tstates
+= ( 4 ); break; }
751 case 80: /* LD D,B */
752 { D( B() ); local_tstates
+= ( 4 ); break; }
753 case 81: /* LD D,C */
754 { D( C() ); local_tstates
+= ( 4 ); break; }
755 case 82: /* LD D,D */
756 { local_tstates
+= ( 4 ); break; }
757 case 83: /* LD D,E */
758 { D( E() ); local_tstates
+= ( 4 ); break; }
759 case 84: /* LD D,H */
760 { D( H() ); local_tstates
+= ( 4 ); break; }
761 case 85: /* LD D,L */
762 { D( L() ); local_tstates
+= ( 4 ); break; }
763 case 86: /* LD D,(HL) */
764 { D( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
765 case 87: /* LD D,A */
766 { D( A() ); local_tstates
+= ( 4 ); break; }
769 case 88: /* LD E,B */
770 { E( B() ); local_tstates
+= ( 4 ); break; }
771 case 89: /* LD E,C */
772 { E( C() ); local_tstates
+= ( 4 ); break; }
773 case 90: /* LD E,D */
774 { E( D() ); local_tstates
+= ( 4 ); break; }
775 case 91: /* LD E,E */
776 { local_tstates
+= ( 4 ); break; }
777 case 92: /* LD E,H */
778 { E( H() ); local_tstates
+= ( 4 ); break; }
779 case 93: /* LD E,L */
780 { E( L() ); local_tstates
+= ( 4 ); break; }
781 case 94: /* LD E,(HL) */
782 { E( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
783 case 95: /* LD E,A */
784 { E( A() ); local_tstates
+= ( 4 ); break; }
787 case 96: /* LD H,B */
788 { H( B() ); local_tstates
+= ( 4 ); break; }
789 case 97: /* LD H,C */
790 { H( C() ); local_tstates
+= ( 4 ); break; }
791 case 98: /* LD H,D */
792 { H( D() ); local_tstates
+= ( 4 ); break; }
793 case 99: /* LD H,E */
794 { H( E() ); local_tstates
+= ( 4 ); break; }
795 case 100: /* LD H,H */
796 { local_tstates
+= ( 4 ); break; }
797 case 101: /* LD H,L */
798 { H( L() ); local_tstates
+= ( 4 ); break; }
799 case 102: /* LD H,(HL) */
800 { H( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
801 case 103: /* LD H,A */
802 { H( A() ); local_tstates
+= ( 4 ); break; }
805 case 104: /* LD L,B */
806 { L( B() ); local_tstates
+= ( 4 ); break; }
807 case 105: /* LD L,C */
808 { L( C() ); local_tstates
+= ( 4 ); break; }
809 case 106: /* LD L,D */
810 { L( D() ); local_tstates
+= ( 4 ); break; }
811 case 107: /* LD L,E */
812 { L( E() ); local_tstates
+= ( 4 ); break; }
813 case 108: /* LD L,H */
814 { L( H() ); local_tstates
+= ( 4 ); break; }
815 case 109: /* LD L,L */
816 { local_tstates
+= ( 4 ); break; }
817 case 110: /* LD L,(HL) */
818 { L( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
819 case 111: /* LD L,A */
820 { L( A() ); local_tstates
+= ( 4 ); break; }
823 case 112: /* LD (HL),B */
824 { pokeb( HL(), B() ); local_tstates
+= ( 7 ); break; }
825 case 113: /* LD (HL),C */
826 { pokeb( HL(), C() ); local_tstates
+= ( 7 ); break; }
827 case 114: /* LD (HL),D */
828 { pokeb( HL(), D() ); local_tstates
+= ( 7 ); break; }
829 case 115: /* LD (HL),E */
830 { pokeb( HL(), E() ); local_tstates
+= ( 7 ); break; }
831 case 116: /* LD (HL),H */
832 { pokeb( HL(), H() ); local_tstates
+= ( 7 ); break; }
833 case 117: /* LD (HL),L */
834 { pokeb( HL(), L() ); local_tstates
+= ( 7 ); break; }
837 int haltsToInterrupt
= (((-local_tstates
-1) / 4)+1);
838 local_tstates
+= (haltsToInterrupt
*4);
839 REFRESH( haltsToInterrupt
-1 );
842 case 119: /* LD (HL),A */
843 { pokeb( HL(), A() ); local_tstates
+= ( 7 ); break; }
846 case 120: /* LD A,B */
847 { A( B() ); local_tstates
+= ( 4 ); break; }
848 case 121: /* LD A,C */
849 { A( C() ); local_tstates
+= ( 4 ); break; }
850 case 122: /* LD A,D */
851 { A( D() ); local_tstates
+= ( 4 ); break; }
852 case 123: /* LD A,E */
853 { A( E() ); local_tstates
+= ( 4 ); break; }
854 case 124: /* LD A,H */
855 { A( H() ); local_tstates
+= ( 4 ); break; }
856 case 125: /* LD A,L */
857 { A( L() ); local_tstates
+= ( 4 ); break; }
858 case 126: /* LD A,(HL) */
859 { A( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
860 case 127: /* LD A,A */
861 { local_tstates
+= ( 4 ); break; }
864 case 128: /* ADD A,B */
865 { add_a( B() ); local_tstates
+= ( 4 ); break; }
866 case 129: /* ADD A,C */
867 { add_a( C() ); local_tstates
+= ( 4 ); break; }
868 case 130: /* ADD A,D */
869 { add_a( D() ); local_tstates
+= ( 4 ); break; }
870 case 131: /* ADD A,E */
871 { add_a( E() ); local_tstates
+= ( 4 ); break; }
872 case 132: /* ADD A,H */
873 { add_a( H() ); local_tstates
+= ( 4 ); break; }
874 case 133: /* ADD A,L */
875 { add_a( L() ); local_tstates
+= ( 4 ); break; }
876 case 134: /* ADD A,(HL) */
877 { add_a( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
878 case 135: /* ADD A,A */
879 { add_a( A() ); local_tstates
+= ( 4 ); break; }
882 case 136: /* ADC A,B */
883 { adc_a( B() ); local_tstates
+= ( 4 ); break; }
884 case 137: /* ADC A,C */
885 { adc_a( C() ); local_tstates
+= ( 4 ); break; }
886 case 138: /* ADC A,D */
887 { adc_a( D() ); local_tstates
+= ( 4 ); break; }
888 case 139: /* ADC A,E */
889 { adc_a( E() ); local_tstates
+= ( 4 ); break; }
890 case 140: /* ADC A,H */
891 { adc_a( H() ); local_tstates
+= ( 4 ); break; }
892 case 141: /* ADC A,L */
893 { adc_a( L() ); local_tstates
+= ( 4 ); break; }
894 case 142: /* ADC A,(HL) */
895 { adc_a( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
896 case 143: /* ADC A,A */
897 { adc_a( A() ); local_tstates
+= ( 4 ); break; }
900 case 144: /* SUB B */
901 { sub_a( B() ); local_tstates
+= ( 4 ); break; }
902 case 145: /* SUB C */
903 { sub_a( C() ); local_tstates
+= ( 4 ); break; }
904 case 146: /* SUB D */
905 { sub_a( D() ); local_tstates
+= ( 4 ); break; }
906 case 147: /* SUB E */
907 { sub_a( E() ); local_tstates
+= ( 4 ); break; }
908 case 148: /* SUB H */
909 { sub_a( H() ); local_tstates
+= ( 4 ); break; }
910 case 149: /* SUB L */
911 { sub_a( L() ); local_tstates
+= ( 4 ); break; }
912 case 150: /* SUB (HL) */
913 { sub_a( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
914 case 151: /* SUB A() */
915 { sub_a( A() ); local_tstates
+= ( 4 ); break; }
918 case 152: /* SBC A,B */
919 { sbc_a( B() ); local_tstates
+= ( 4 ); break; }
920 case 153: /* SBC A,C */
921 { sbc_a( C() ); local_tstates
+= ( 4 ); break; }
922 case 154: /* SBC A,D */
923 { sbc_a( D() ); local_tstates
+= ( 4 ); break; }
924 case 155: /* SBC A,E */
925 { sbc_a( E() ); local_tstates
+= ( 4 ); break; }
926 case 156: /* SBC A,H */
927 { sbc_a( H() ); local_tstates
+= ( 4 ); break; }
928 case 157: /* SBC A,L */
929 { sbc_a( L() ); local_tstates
+= ( 4 ); break; }
930 case 158: /* SBC A,(HL) */
931 { sbc_a( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
932 case 159: /* SBC A,A */
933 { sbc_a( A() ); local_tstates
+= ( 4 ); break; }
936 case 160: /* AND B */
937 { and_a( B() ); local_tstates
+= ( 4 ); break; }
938 case 161: /* AND C */
939 { and_a( C() ); local_tstates
+= ( 4 ); break; }
940 case 162: /* AND D */
941 { and_a( D() ); local_tstates
+= ( 4 ); break; }
942 case 163: /* AND E */
943 { and_a( E() ); local_tstates
+= ( 4 ); break; }
944 case 164: /* AND H */
945 { and_a( H() ); local_tstates
+= ( 4 ); break; }
946 case 165: /* AND L */
947 { and_a( L() ); local_tstates
+= ( 4 ); break; }
948 case 166: /* AND (HL) */
949 { and_a( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
950 case 167: /* AND A() */
951 { and_a( A() ); local_tstates
+= ( 4 ); break; }
954 case 168: /* XOR B */
955 { xor_a( B() ); local_tstates
+= ( 4 ); break; }
956 case 169: /* XOR C */
957 { xor_a( C() ); local_tstates
+= ( 4 ); break; }
958 case 170: /* XOR D */
959 { xor_a( D() ); local_tstates
+= ( 4 ); break; }
960 case 171: /* XOR E */
961 { xor_a( E() ); local_tstates
+= ( 4 ); break; }
962 case 172: /* XOR H */
963 { xor_a( H() ); local_tstates
+= ( 4 ); break; }
964 case 173: /* XOR L */
965 { xor_a( L() ); local_tstates
+= ( 4 ); break; }
966 case 174: /* XOR (HL) */
967 { xor_a( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
968 case 175: /* XOR A() */
969 { xor_a( A() ); local_tstates
+= ( 4 ); break; }
973 { or_a( B() ); local_tstates
+= ( 4 ); break; }
975 { or_a( C() ); local_tstates
+= ( 4 ); break; }
977 { or_a( D() ); local_tstates
+= ( 4 ); break; }
979 { or_a( E() ); local_tstates
+= ( 4 ); break; }
981 { or_a( H() ); local_tstates
+= ( 4 ); break; }
983 { or_a( L() ); local_tstates
+= ( 4 ); break; }
984 case 182: /* OR (HL) */
985 { or_a( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
986 case 183: /* OR A() */
987 { or_a( A() ); local_tstates
+= ( 4 ); break; }
991 { cp_a( B() ); local_tstates
+= ( 4 ); break; }
993 { cp_a( C() ); local_tstates
+= ( 4 ); break; }
995 { cp_a( D() ); local_tstates
+= ( 4 ); break; }
997 { cp_a( E() ); local_tstates
+= ( 4 ); break; }
999 { cp_a( H() ); local_tstates
+= ( 4 ); break; }
1000 case 189: /* CP L */
1001 { cp_a( L() ); local_tstates
+= ( 4 ); break; }
1002 case 190: /* CP (HL) */
1003 { cp_a( peekb( HL() ) ); local_tstates
+= ( 7 ); break; }
1004 case 191: /* CP A() */
1005 { cp_a( A() ); local_tstates
+= ( 4 ); break; }
1008 case 192: /* RET NZ */
1012 local_tstates
+= ( 11 );
1015 local_tstates
+= ( 5 );
1019 case 200: /* RET Z */
1023 local_tstates
+= ( 11 );
1026 local_tstates
+= ( 5 );
1030 case 208: /* RET NC */
1034 local_tstates
+= ( 11 );
1037 local_tstates
+= ( 5 );
1041 case 216: /* RET C */
1045 local_tstates
+= ( 11 );
1048 local_tstates
+= ( 5 );
1052 case 224: /* RET PO */
1056 local_tstates
+= ( 11 );
1059 local_tstates
+= ( 5 );
1063 case 232: /* RET PE */
1067 local_tstates
+= ( 11 );
1070 local_tstates
+= ( 5 );
1074 case 240: /* RET P */
1078 local_tstates
+= ( 11 );
1081 local_tstates
+= ( 5 );
1085 case 248: /* RET M */
1089 local_tstates
+= ( 11 );
1092 local_tstates
+= ( 5 );
1098 case 193: /* POP BC */
1099 { BC( popw() ); local_tstates
+= ( 10 ); break; }
1101 { poppc(); local_tstates
+= ( 10 ); break; }
1102 case 209: /* POP DE */
1103 { DE( popw() ); local_tstates
+= ( 10 ); break; }
1107 local_tstates
+= ( 4 );
1110 case 225: /* POP HL */
1111 { HL( popw() ); local_tstates
+= ( 10 ); break; }
1112 case 233: /* JP (HL) */
1113 { PC( HL() ); local_tstates
+= ( 4 ); break; }
1114 case 241: /* POP AF */
1115 { AF( popw() ); local_tstates
+= ( 10 ); break; }
1116 case 249: /* LD SP,HL */
1117 { SP( HL() ); local_tstates
+= ( 6 ); break; }
1120 case 194: /* JP NZ,nn */
1126 PC( (PC()+2)&0xffff );
1128 local_tstates
+= ( 10 );
1131 case 202: /* JP Z,nn */
1137 PC( (PC()+2)&0xffff );
1139 local_tstates
+= ( 10 );
1142 case 210: /* JP NC,nn */
1148 PC( (PC()+2)&0xffff );
1150 local_tstates
+= ( 10 );
1153 case 218: /* JP C,nn */
1159 PC( (PC()+2)&0xffff );
1161 local_tstates
+= ( 10 );
1164 case 226: /* JP PO,nn */
1170 PC( (PC()+2)&0xffff );
1172 local_tstates
+= ( 10 );
1175 case 234: /* JP PE,nn */
1181 PC( (PC()+2)&0xffff );
1183 local_tstates
+= ( 10 );
1186 case 242: /* JP P,nn */
1192 PC( (PC()+2)&0xffff );
1194 local_tstates
+= ( 10 );
1197 case 250: /* JP M,nn */
1203 PC( (PC()+2)&0xffff );
1205 local_tstates
+= ( 10 );
1211 case 195: /* JP nn */
1212 { logJump(peekw(PC())); PC( peekw( PC() ) ); local_tstates
+= ( 10 ); break; }
1213 case 203: /* prefix CB */
1214 { local_tstates
+= execute_cb(); break; }
1215 case 211: /* OUT (n),A */
1217 outb( nxtpcb(), A(), local_tstates
);
1218 local_tstates
+= ( 11 );
1221 case 219: /* IN A,(n) */
1223 A( inb((A() << 8) | nxtpcb()) );
1224 local_tstates
+= ( 11 );
1227 case 227: /* EX (SP),HL */
1233 local_tstates
+= ( 19 );
1236 case 235: /* EX DE,HL */
1241 local_tstates
+= ( 4 );
1248 local_tstates
+= ( 4 );
1255 local_tstates
+= ( 4 );
1260 case 196: /* CALL NZ,nn */
1267 local_tstates
+= ( 17 );
1270 PC( (PC() + 2)&0xffff );
1271 local_tstates
+= ( 10 );
1275 case 204: /* CALL Z,nn */
1282 local_tstates
+= ( 17 );
1285 PC( (PC() + 2)&0xffff );
1286 local_tstates
+= ( 10 );
1290 case 212: /* CALL NC,nn */
1297 local_tstates
+= ( 17 );
1300 PC( (PC() + 2)&0xffff );
1301 local_tstates
+= ( 10 );
1305 case 220: /* CALL C,nn */
1312 local_tstates
+= ( 17 );
1315 PC( (PC() + 2)&0xffff );
1316 local_tstates
+= ( 10 );
1320 case 228: /* CALL PO,nn */
1327 local_tstates
+= ( 17 );
1330 PC( (PC() + 2)&0xffff );
1331 local_tstates
+= ( 10 );
1335 case 236: /* CALL PE,nn */
1342 local_tstates
+= ( 17 );
1345 PC( (PC() + 2)&0xffff );
1346 local_tstates
+= ( 10 );
1350 case 244: /* CALL P,nn */
1357 local_tstates
+= ( 17 );
1360 PC( (PC() + 2)&0xffff );
1361 local_tstates
+= ( 10 );
1365 case 252: /* CALL M,nn */
1372 local_tstates
+= ( 17 );
1375 PC( (PC() + 2)&0xffff );
1376 local_tstates
+= ( 10 );
1382 case 197: /* PUSH BC */
1383 { pushw( BC() ); local_tstates
+= ( 11 ); break; }
1384 case 205: /* CALL nn */
1390 local_tstates
+= ( 17 );
1393 case 213: /* PUSH DE */
1394 { pushw( DE() ); local_tstates
+= ( 11 ); break; }
1395 case 221: /* prefix IX */
1398 local_tstates
+= execute_id();
1402 case 229: /* PUSH HL */
1403 { pushw( HL() ); local_tstates
+= ( 11 ); break; }
1404 case 237: /* prefix ED */
1405 { local_tstates
+= execute_ed( local_tstates
); break; }
1406 case 245: /* PUSH AF */
1407 { pushw( AF() ); local_tstates
+= ( 11 ); break; }
1408 case 253: /* prefix IY */
1411 local_tstates
+= execute_id();
1417 case 198: /* ADD A,N */
1418 { add_a(nxtpcb()); local_tstates
+= ( 7 ); break; }
1419 case 206: /* ADC A,N */
1420 { adc_a(nxtpcb()); local_tstates
+= ( 7 ); break; }
1421 case 214: /* SUB N */
1422 { sub_a(nxtpcb()); local_tstates
+= ( 7 ); break; }
1423 case 222: /* SBC A,N */
1424 { sbc_a(nxtpcb()); local_tstates
+= ( 7 ); break; }
1425 case 230: /* AND N */
1426 { and_a(nxtpcb()); local_tstates
+= ( 7 ); break; }
1427 case 238: /* XOR N */
1428 { xor_a(nxtpcb()); local_tstates
+= ( 7 ); break; }
1429 case 246: /* OR N */
1430 { or_a(nxtpcb()); local_tstates
+= ( 7 ); break; }
1431 case 254: /* CP N */
1432 { cp_a(nxtpcb()); local_tstates
+= ( 7 ); break; }
1435 case 199: /* RST 0 */
1436 { local_tstates
+= rst(0); break; }
1437 case 207: /* RST 8 */
1438 { local_tstates
+= rst(8); break; }
1439 case 215: /* RST 16 */
1440 { local_tstates
+= rst(16); break; }
1441 case 223: /* RST 24 */
1442 { local_tstates
+= rst(24); break; }
1443 case 231: /* RST 32 */
1444 { local_tstates
+= rst(32); break; }
1445 case 239: /* RST 40 */
1446 { local_tstates
+= rst(40); break; }
1447 case 247: /* RST 48 */
1448 { local_tstates
+= rst(48); break; }
1449 case 255: /* RST 56 */
1450 { local_tstates
+= rst(56); break; }
1456 int rst(int rstNum
) {
1463 private final int execute_ed( int local_tstates
) {
1467 switch ( nxtpcb() ) {
1587 case 64: /* IN B,(c) */
1588 { B( in_bc() ); return ( 12 ); }
1589 case 72: /* IN C,(c) */
1590 { C( in_bc() ); return ( 12 ); }
1591 case 80: /* IN D,(c) */
1592 { D( in_bc() ); return ( 12 ); }
1593 case 88: /* IN E,(c) */
1594 { E( in_bc() ); return ( 12 ); }
1595 case 96: /* IN H,(c) */
1596 { H( in_bc() ); return ( 12 ); }
1597 case 104: /* IN L,(c) */
1598 { L( in_bc() ); return ( 12 ); }
1599 case 112: /* IN (c) */
1600 { in_bc(); return ( 12 ); }
1601 case 120: /* IN A,(c) */
1602 { A( in_bc() ); return ( 12 ); }
1605 case 65: /* OUT (c),B */
1606 { outb( BC(), B(), local_tstates
); return ( 12 ); }
1607 case 73: /* OUT (c),C */
1608 { outb( BC(), C(), local_tstates
); return ( 12 ); }
1609 case 81: /* OUT (c),D */
1610 { outb( BC(), D(), local_tstates
); return ( 12 ); }
1611 case 89: /* OUT (c),E */
1612 { outb( BC(), E(), local_tstates
); return ( 12 ); }
1613 case 97: /* OUT (c),H */
1614 { outb( BC(), H(), local_tstates
); return ( 12 ); }
1615 case 105: /* OUT (c),L */
1616 { outb( BC(), L(), local_tstates
); return ( 12 ); }
1617 case 113: /* OUT (c),0 */
1618 { outb( BC(), 0, local_tstates
); return ( 12 ); }
1619 case 121: /* OUT (c),A */
1620 { outb( BC(), A(), local_tstates
); return ( 12 ); }
1623 case 66: /* SBC HL,BC */
1624 { HL( sbc16( HL(), BC() ) ); return ( 15 ); }
1625 case 74: /* ADC HL,BC */
1626 { HL( adc16( HL(), BC() ) ); return ( 15 ); }
1627 case 82: /* SBC HL,DE */
1628 { HL( sbc16( HL(), DE() ) ); return ( 15 ); }
1629 case 90: /* ADC HL,DE */
1630 { HL( adc16( HL(), DE() ) ); return ( 15 ); }
1631 case 98: /* SBC HL,HL */
1634 HL( sbc16( hl
, hl
) );
1637 case 106: /* ADC HL,HL */
1640 HL( adc16( hl
, hl
) );
1643 case 114: /* SBC HL,SP */
1644 { HL( sbc16( HL(), SP() ) ); return ( 15 ); }
1645 case 122: /* ADC HL,SP */
1646 { HL( adc16( HL(), SP() ) ); return ( 15 ); }
1648 /* LD (nn),ss, LD ss,(nn) */
1649 case 67: /* LD (nn),BC */
1650 { pokew( nxtpcw(), BC() ); return ( 20 ); }
1651 case 75: /* LD BC(),(nn) */
1652 { BC( peekw( nxtpcw() ) ); return ( 20 ); }
1653 case 83: /* LD (nn),DE */
1654 { pokew( nxtpcw(), DE() ); return ( 20 ); }
1655 case 91: /* LD DE,(nn) */
1656 { DE( peekw( nxtpcw() ) ); return ( 20 ); }
1657 case 99: /* LD (nn),HL */
1658 { pokew( nxtpcw(), HL() ); return ( 20 ); }
1659 case 107: /* LD HL,(nn) */
1660 { HL( peekw( nxtpcw() ) ); return ( 20 ); }
1661 case 115: /* LD (nn),SP */
1662 { pokew( nxtpcw(), SP() ); return ( 20 ); }
1663 case 123: /* LD SP,(nn) */
1664 { SP( peekw( nxtpcw() ) ); return ( 20 ); }
1675 { neg_a(); return ( 8 ); }
1680 case 101: /* RETN */
1681 case 117: /* RETN */
1689 case 109: /* RETI */
1690 case 125: /* RETI */
1699 case 102: /* IM 0 */
1700 case 110: /* IM 0 */
1701 { IM( IM0
); return ( 8 ); }
1703 case 118: /* IM 1 */
1704 { IM( IM1
); return ( 8 ); }
1706 case 126: /* IM 2 */
1707 { IM( IM2
); return ( 8 ); }
1709 /* LD A,s / LD s,A / RxD */
1710 case 71: /* LD I,A */
1711 { I( A() ); return ( 9 ); }
1712 case 79: /* LD R,A */
1713 { R( A() ); return ( 9 ); }
1714 case 87: /* LD A,I */
1715 { ld_a_i(); return ( 9 ); }
1716 case 95: /* LD A,R */
1717 { ld_a_r(); return ( 9 ); }
1719 { rrd_a(); return ( 18 ); }
1721 { rld_a(); return ( 18 ); }
1726 pokeb( DE(), peekb( HL() ) );
1727 DE( inc16( DE() ) );
1728 HL( inc16( HL() ) );
1729 BC( dec16( BC() ) );
1741 cp_a( peekb( HL() ) );
1742 HL( inc16( HL() ) );
1743 BC( dec16( BC() ) );
1753 pokeb( HL(), inb( BC() ) );
1754 B( b
= qdec8( B() ) );
1755 HL( inc16( HL() ) );
1762 case 163: /* OUTI */
1765 B( b
= qdec8( B() ) );
1766 outb( BC(), peekb( HL() ), local_tstates
);
1767 HL( inc16( HL() ) );
1778 pokeb( DE(), peekb( HL() ) );
1779 DE( dec16( DE() ) );
1780 HL( dec16( HL() ) );
1781 BC( dec16( BC() ) );
1793 cp_a( peekb( HL() ) );
1794 HL( dec16( HL() ) );
1795 BC( dec16( BC() ) );
1805 pokeb( HL(), inb( BC() ) );
1806 B( b
= qdec8( B() ) );
1807 HL( dec16( HL() ) );
1814 case 171: /* OUTD */
1817 B( b
= qdec8( B() ) );
1818 outb( BC(), peekb( HL() ), local_tstates
);
1819 HL( dec16( HL() ) );
1828 case 176: /* LDIR */
1830 int _local_tstates
= 0;
1831 int count
, dest
, from
;
1838 pokeb(dest
, peekb(from
) );
1839 from
= inc16( from
);
1840 dest
= inc16( dest
);
1841 count
= dec16( count
);
1843 _local_tstates
+= ( 21 );
1845 if ( interruptTriggered( _local_tstates
) ) {
1848 } while (count
!= 0);
1850 PC( (PC()-2)&0xffff );
1856 _local_tstates
+= ( -5 );
1865 return ( _local_tstates
);
1867 case 177: /* CPIR */
1871 cp_a( peekb( HL() ) );
1872 HL( inc16( HL() ) );
1873 BC( dec16( BC() ) );
1875 boolean pv
= (BC() != 0);
1879 if ( pv
&& !Zset() ) {
1880 PC( (PC()-2)&0xffff );
1885 case 178: /* INIR */
1888 pokeb( HL(), inb( BC() ) );
1889 B( b
= qdec8( B() ) );
1890 HL( inc16( HL() ) );
1895 PC( (PC()-2)&0xffff );
1900 case 179: /* OTIR */
1903 B( b
= qdec8( B() ) );
1904 outb( BC(), peekb( HL() ), local_tstates
);
1905 HL( inc16( HL() ) );
1910 PC( (PC()-2)&0xffff );
1917 case 184: /* LDDR */
1919 int _local_tstates
= 0;
1920 int count
, dest
, from
;
1927 pokeb(dest
, peekb(from
));
1928 from
= dec16( from
);
1929 dest
= dec16( dest
);
1930 count
= dec16( count
);
1932 _local_tstates
+= ( 21 );
1934 if ( interruptTriggered( _local_tstates
) ) {
1937 } while (count
!= 0);
1939 PC( (PC()-2)&0xffff );
1945 _local_tstates
+= ( -5 );
1954 return ( _local_tstates
);
1956 case 185: /* CPDR */
1960 cp_a( peekb( HL() ) );
1961 HL( dec16( HL() ) );
1962 BC( dec16( BC() ) );
1964 boolean pv
= (BC() != 0);
1968 if ( pv
&& !Zset() ) {
1969 PC( (PC()-2)&0xffff );
1974 case 186: /* INDR */
1977 pokeb( HL(), inb( BC() ) );
1978 B( b
= qdec8( B() ) );
1979 HL( dec16( HL() ) );
1984 PC( (PC()-2)&0xffff );
1989 case 187: /* OTDR */
1992 B( b
= qdec8( B() ) );
1993 outb( BC(), peekb( HL() ), local_tstates
);
1994 HL( dec16( HL() ) );
1999 PC( (PC()-2)&0xffff );
2011 private final int execute_cb() {
2014 switch ( nxtpcb() ) {
2017 { B( rlc( B() ) ); return ( 8 ); }
2019 { C( rlc( C() ) ); return ( 8 ); }
2021 { D( rlc( D() ) ); return ( 8 ); }
2023 { E( rlc( E() ) ); return ( 8 ); }
2025 { H( rlc( H() ) ); return ( 8 ); }
2027 { L( rlc( L() ) ); return ( 8 ); }
2028 case 6: /* RLC (HL) */
2031 pokeb( hl
, rlc( peekb( hl
) ) );
2035 { A( rlc( A() ) ); return ( 8 ); }
2038 { B( rrc( B() ) ); return ( 8 ); }
2040 { C( rrc( C() ) ); return ( 8 ); }
2041 case 10: /* RRC D */
2042 { D( rrc( D() ) ); return ( 8 ); }
2043 case 11: /* RRC E */
2044 { E( rrc( E() ) ); return ( 8 ); }
2045 case 12: /* RRC H */
2046 { H( rrc( H() ) ); return ( 8 ); }
2047 case 13: /* RRC L */
2048 { L( rrc( L() ) ); return ( 8 ); }
2049 case 14: /* RRC (HL) */
2052 pokeb( hl
, rrc( peekb( hl
) ) );
2055 case 15: /* RRC A */
2056 { A( rrc( A() ) ); return ( 8 ); }
2059 { B( rl( B() ) ); return ( 8 ); }
2061 { C( rl( C() ) ); return ( 8 ); }
2063 { D( rl( D() ) ); return ( 8 ); }
2065 { E( rl( E() ) ); return ( 8 ); }
2067 { H( rl( H() ) ); return ( 8 ); }
2069 { L( rl( L() ) ); return ( 8 ); }
2070 case 22: /* RL (HL) */
2073 pokeb( hl
, rl( peekb( hl
) ) );
2077 { A( rl( A() ) ); return ( 8 ); }
2080 { B( rr( B() ) ); return ( 8 ); }
2082 { C( rr( C() ) ); return ( 8 ); }
2084 { D( rr( D() ) ); return ( 8 ); }
2086 { E( rr( E() ) ); return ( 8 ); }
2088 { H( rr( H() ) ); return ( 8 ); }
2090 { L( rr( L() ) ); return ( 8 ); }
2091 case 30: /* RR (HL) */
2094 pokeb( hl
, rr( peekb( hl
) ) );
2098 { A( rr( A() ) ); return ( 8 ); }
2100 case 32: /* SLA B */
2101 { B( sla( B() ) ); return ( 8 ); }
2102 case 33: /* SLA C */
2103 { C( sla( C() ) ); return ( 8 ); }
2104 case 34: /* SLA D */
2105 { D( sla( D() ) ); return ( 8 ); }
2106 case 35: /* SLA E */
2107 { E( sla( E() ) ); return ( 8 ); }
2108 case 36: /* SLA H */
2109 { H( sla( H() ) ); return ( 8 ); }
2110 case 37: /* SLA L */
2111 { L( sla( L() ) ); return ( 8 ); }
2112 case 38: /* SLA (HL) */
2115 pokeb( hl
, sla( peekb( hl
) ) );
2118 case 39: /* SLA A */
2119 { A( sla( A() ) ); return ( 8 ); }
2121 case 40: /* SRA B */
2122 { B( sra( B() ) ); return ( 8 ); }
2123 case 41: /* SRA C */
2124 { C( sra( C() ) ); return ( 8 ); }
2125 case 42: /* SRA D */
2126 { D( sra( D() ) ); return ( 8 ); }
2127 case 43: /* SRA E */
2128 { E( sra( E() ) ); return ( 8 ); }
2129 case 44: /* SRA H */
2130 { H( sra( H() ) ); return ( 8 ); }
2131 case 45: /* SRA L */
2132 { L( sra( L() ) ); return ( 8 ); }
2133 case 46: /* SRA (HL) */
2136 pokeb( hl
, sra( peekb( hl
) ) );
2139 case 47: /* SRA A */
2140 { A( sra( A() ) ); return ( 8 ); }
2142 case 48: /* SLS B */
2143 { B( sls( B() ) ); return ( 8 ); }
2144 case 49: /* SLS C */
2145 { C( sls( C() ) ); return ( 8 ); }
2146 case 50: /* SLS D */
2147 { D( sls( D() ) ); return ( 8 ); }
2148 case 51: /* SLS E */
2149 { E( sls( E() ) ); return ( 8 ); }
2150 case 52: /* SLS H */
2151 { H( sls( H() ) ); return ( 8 ); }
2152 case 53: /* SLS L */
2153 { L( sls( L() ) ); return ( 8 ); }
2154 case 54: /* SLS (HL) */
2157 pokeb( hl
, sls( peekb( hl
) ) );
2160 case 55: /* SLS A */
2161 { A( sls( A() ) ); return ( 8 ); }
2163 case 56: /* SRL B */
2164 { B( srl( B() ) ); return ( 8 ); }
2165 case 57: /* SRL C */
2166 { C( srl( C() ) ); return ( 8 ); }
2167 case 58: /* SRL D */
2168 { D( srl( D() ) ); return ( 8 ); }
2169 case 59: /* SRL E */
2170 { E( srl( E() ) ); return ( 8 ); }
2171 case 60: /* SRL H */
2172 { H( srl( H() ) ); return ( 8 ); }
2173 case 61: /* SRL L */
2174 { L( srl( L() ) ); return ( 8 ); }
2175 case 62: /* SRL (HL) */
2178 pokeb( hl
, srl( peekb( hl
) ) );
2181 case 63: /* SRL A */
2182 { A( srl( A() ) ); return ( 8 ); }
2184 case 64: /* BIT 0,B */
2185 { bit( 0x01, B() ); return ( 8 ); }
2186 case 65: /* BIT 0,C */
2187 { bit( 0x01, C() ); return ( 8 ); }
2188 case 66: /* BIT 0,D */
2189 { bit( 0x01, D() ); return ( 8 ); }
2190 case 67: /* BIT 0,E */
2191 { bit( 0x01, E() ); return ( 8 ); }
2192 case 68: /* BIT 0,H */
2193 { bit( 0x01, H() ); return ( 8 ); }
2194 case 69: /* BIT 0,L */
2195 { bit( 0x01, L() ); return ( 8 ); }
2196 case 70: /* BIT 0,(HL) */
2197 { bit( 0x01, peekb( HL() ) ); return ( 12 ); }
2198 case 71: /* BIT 0,A */
2199 { bit( 0x01, A() ); return ( 8 ); }
2201 case 72: /* BIT 1,B */
2202 { bit( 0x02, B() ); return ( 8 ); }
2203 case 73: /* BIT 1,C */
2204 { bit( 0x02, C() ); return ( 8 ); }
2205 case 74: /* BIT 1,D */
2206 { bit( 0x02, D() ); return ( 8 ); }
2207 case 75: /* BIT 1,E */
2208 { bit( 0x02, E() ); return ( 8 ); }
2209 case 76: /* BIT 1,H */
2210 { bit( 0x02, H() ); return ( 8 ); }
2211 case 77: /* BIT 1,L */
2212 { bit( 0x02, L() ); return ( 8 ); }
2213 case 78: /* BIT 1,(HL) */
2214 { bit( 0x02, peekb( HL() ) ); return ( 12 ); }
2215 case 79: /* BIT 1,A */
2216 { bit( 0x02, A() ); return ( 8 ); }
2218 case 80: /* BIT 2,B */
2219 { bit( 0x04, B() ); return ( 8 ); }
2220 case 81: /* BIT 2,C */
2221 { bit( 0x04, C() ); return ( 8 ); }
2222 case 82: /* BIT 2,D */
2223 { bit( 0x04, D() ); return ( 8 ); }
2224 case 83: /* BIT 2,E */
2225 { bit( 0x04, E() ); return ( 8 ); }
2226 case 84: /* BIT 2,H */
2227 { bit( 0x04, H() ); return ( 8 ); }
2228 case 85: /* BIT 2,L */
2229 { bit( 0x04, L() ); return ( 8 ); }
2230 case 86: /* BIT 2,(HL) */
2231 { bit( 0x04, peekb( HL() ) ); return ( 12 ); }
2232 case 87: /* BIT 2,A */
2233 { bit( 0x04, A() ); return ( 8 ); }
2235 case 88: /* BIT 3,B */
2236 { bit( 0x08, B() ); return ( 8 ); }
2237 case 89: /* BIT 3,C */
2238 { bit( 0x08, C() ); return ( 8 ); }
2239 case 90: /* BIT 3,D */
2240 { bit( 0x08, D() ); return ( 8 ); }
2241 case 91: /* BIT 3,E */
2242 { bit( 0x08, E() ); return ( 8 ); }
2243 case 92: /* BIT 3,H */
2244 { bit( 0x08, H() ); return ( 8 ); }
2245 case 93: /* BIT 3,L */
2246 { bit( 0x08, L() ); return ( 8 ); }
2247 case 94: /* BIT 3,(HL) */
2248 { bit( 0x08, peekb( HL() ) ); return ( 12 ); }
2249 case 95: /* BIT 3,A */
2250 { bit( 0x08, A() ); return ( 8 ); }
2252 case 96: /* BIT 4,B */
2253 { bit( 0x10, B() ); return ( 8 ); }
2254 case 97: /* BIT 4,C */
2255 { bit( 0x10, C() ); return ( 8 ); }
2256 case 98: /* BIT 4,D */
2257 { bit( 0x10, D() ); return ( 8 ); }
2258 case 99: /* BIT 4,E */
2259 { bit( 0x10, E() ); return ( 8 ); }
2260 case 100: /* BIT 4,H */
2261 { bit( 0x10, H() ); return ( 8 ); }
2262 case 101: /* BIT 4,L */
2263 { bit( 0x10, L() ); return ( 8 ); }
2264 case 102: /* BIT 4,(HL) */
2265 { bit( 0x10, peekb( HL() ) ); return ( 12 ); }
2266 case 103: /* BIT 4,A */
2267 { bit( 0x10, A() ); return ( 8 ); }
2269 case 104: /* BIT 5,B */
2270 { bit( 0x20, B() ); return ( 8 ); }
2271 case 105: /* BIT 5,C */
2272 { bit( 0x20, C() ); return ( 8 ); }
2273 case 106: /* BIT 5,D */
2274 { bit( 0x20, D() ); return ( 8 ); }
2275 case 107: /* BIT 5,E */
2276 { bit( 0x20, E() ); return ( 8 ); }
2277 case 108: /* BIT 5,H */
2278 { bit( 0x20, H() ); return ( 8 ); }
2279 case 109: /* BIT 5,L */
2280 { bit( 0x20, L() ); return ( 8 ); }
2281 case 110: /* BIT 5,(HL) */
2282 { bit( 0x20, peekb( HL() ) ); return ( 12 ); }
2283 case 111: /* BIT 5,A */
2284 { bit( 0x20, A() ); return ( 8 ); }
2286 case 112: /* BIT 6,B */
2287 { bit( 0x40, B() ); return ( 8 ); }
2288 case 113: /* BIT 6,C */
2289 { bit( 0x40, C() ); return ( 8 ); }
2290 case 114: /* BIT 6,D */
2291 { bit( 0x40, D() ); return ( 8 ); }
2292 case 115: /* BIT 6,E */
2293 { bit( 0x40, E() ); return ( 8 ); }
2294 case 116: /* BIT 6,H */
2295 { bit( 0x40, H() ); return ( 8 ); }
2296 case 117: /* BIT 6,L */
2297 { bit( 0x40, L() ); return ( 8 ); }
2298 case 118: /* BIT 6,(HL) */
2299 { bit( 0x40, peekb( HL() ) ); return ( 12 ); }
2300 case 119: /* BIT 6,A */
2301 { bit( 0x40, A() ); return ( 8 ); }
2303 case 120: /* BIT 7,B */
2304 { bit( 0x80, B() ); return ( 8 ); }
2305 case 121: /* BIT 7,C */
2306 { bit( 0x80, C() ); return ( 8 ); }
2307 case 122: /* BIT 7,D */
2308 { bit( 0x80, D() ); return ( 8 ); }
2309 case 123: /* BIT 7,E */
2310 { bit( 0x80, E() ); return ( 8 ); }
2311 case 124: /* BIT 7,H */
2312 { bit( 0x80, H() ); return ( 8 ); }
2313 case 125: /* BIT 7,L */
2314 { bit( 0x80, L() ); return ( 8 ); }
2315 case 126: /* BIT 7,(HL) */
2316 { bit( 0x80, peekb( HL() ) ); return ( 12 ); }
2317 case 127: /* BIT 7,A */
2318 { bit( 0x80, A() ); return ( 8 ); }
2320 case 128: /* RES 0,B */
2321 { B( res( 0x01, B() ) ); return ( 8 ); }
2322 case 129: /* RES 0,C */
2323 { C( res( 0x01, C() ) ); return ( 8 ); }
2324 case 130: /* RES 0,D */
2325 { D( res( 0x01, D() ) ); return ( 8 ); }
2326 case 131: /* RES 0,E */
2327 { E( res( 0x01, E() ) ); return ( 8 ); }
2328 case 132: /* RES 0,H */
2329 { H( res( 0x01, H() ) ); return ( 8 ); }
2330 case 133: /* RES 0,L */
2331 { L( res( 0x01, L() ) ); return ( 8 ); }
2332 case 134: /* RES 0,(HL) */
2335 pokeb( hl
, res( 0x01, peekb( hl
) ) );
2338 case 135: /* RES 0,A */
2339 { A( res( 0x01, A() ) ); return ( 8 ); }
2341 case 136: /* RES 1,B */
2342 { B( res( 0x02, B() ) ); return ( 8 ); }
2343 case 137: /* RES 1,C */
2344 { C( res( 0x02, C() ) ); return ( 8 ); }
2345 case 138: /* RES 1,D */
2346 { D( res( 0x02, D() ) ); return ( 8 ); }
2347 case 139: /* RES 1,E */
2348 { E( res( 0x02, E() ) ); return ( 8 ); }
2349 case 140: /* RES 1,H */
2350 { H( res( 0x02, H() ) ); return ( 8 ); }
2351 case 141: /* RES 1,L */
2352 { L( res( 0x02, L() ) ); return ( 8 ); }
2353 case 142: /* RES 1,(HL) */
2356 pokeb( hl
, res( 0x02, peekb( hl
) ) );
2359 case 143: /* RES 1,A */
2360 { A( res( 0x02, A() ) ); return ( 8 ); }
2362 case 144: /* RES 2,B */
2363 { B( res( 0x04, B() ) ); return ( 8 ); }
2364 case 145: /* RES 2,C */
2365 { C( res( 0x04, C() ) ); return ( 8 ); }
2366 case 146: /* RES 2,D */
2367 { D( res( 0x04, D() ) ); return ( 8 ); }
2368 case 147: /* RES 2,E */
2369 { E( res( 0x04, E() ) ); return ( 8 ); }
2370 case 148: /* RES 2,H */
2371 { H( res( 0x04, H() ) ); return ( 8 ); }
2372 case 149: /* RES 2,L */
2373 { L( res( 0x04, L() ) ); return ( 8 ); }
2374 case 150: /* RES 2,(HL) */
2377 pokeb( hl
, res( 0x04, peekb( hl
) ) );
2380 case 151: /* RES 2,A */
2381 { A( res( 0x04, A() ) ); return ( 8 ); }
2383 case 152: /* RES 3,B */
2384 { B( res( 0x08, B() ) ); return ( 8 ); }
2385 case 153: /* RES 3,C */
2386 { C( res( 0x08, C() ) ); return ( 8 ); }
2387 case 154: /* RES 3,D */
2388 { D( res( 0x08, D() ) ); return ( 8 ); }
2389 case 155: /* RES 3,E */
2390 { E( res( 0x08, E() ) ); return ( 8 ); }
2391 case 156: /* RES 3,H */
2392 { H( res( 0x08, H() ) ); return ( 8 ); }
2393 case 157: /* RES 3,L */
2394 { L( res( 0x08, L() ) ); return ( 8 ); }
2395 case 158: /* RES 3,(HL) */
2398 pokeb( hl
, res( 0x08, peekb( hl
) ) );
2401 case 159: /* RES 3,A */
2402 { A( res( 0x08, A() ) ); return ( 8 ); }
2404 case 160: /* RES 4,B */
2405 { B( res( 0x10, B() ) ); return ( 8 ); }
2406 case 161: /* RES 4,C */
2407 { C( res( 0x10, C() ) ); return ( 8 ); }
2408 case 162: /* RES 4,D */
2409 { D( res( 0x10, D() ) ); return ( 8 ); }
2410 case 163: /* RES 4,E */
2411 { E( res( 0x10, E() ) ); return ( 8 ); }
2412 case 164: /* RES 4,H */
2413 { H( res( 0x10, H() ) ); return ( 8 ); }
2414 case 165: /* RES 4,L */
2415 { L( res( 0x10, L() ) ); return ( 8 ); }
2416 case 166: /* RES 4,(HL) */
2419 pokeb( hl
, res( 0x10, peekb( hl
) ) );
2422 case 167: /* RES 4,A */
2423 { A( res( 0x10, A() ) ); return ( 8 ); }
2425 case 168: /* RES 5,B */
2426 { B( res( 0x20, B() ) ); return ( 8 ); }
2427 case 169: /* RES 5,C */
2428 { C( res( 0x20, C() ) ); return ( 8 ); }
2429 case 170: /* RES 5,D */
2430 { D( res( 0x20, D() ) ); return ( 8 ); }
2431 case 171: /* RES 5,E */
2432 { E( res( 0x20, E() ) ); return ( 8 ); }
2433 case 172: /* RES 5,H */
2434 { H( res( 0x20, H() ) ); return ( 8 ); }
2435 case 173: /* RES 5,L */
2436 { L( res( 0x20, L() ) ); return ( 8 ); }
2437 case 174: /* RES 5,(HL) */
2440 pokeb( hl
, res( 0x20, peekb( hl
) ) );
2443 case 175: /* RES 5,A */
2444 { A( res( 0x20, A() ) ); return ( 8 ); }
2446 case 176: /* RES 6,B */
2447 { B( res( 0x40, B() ) ); return ( 8 ); }
2448 case 177: /* RES 6,C */
2449 { C( res( 0x40, C() ) ); return ( 8 ); }
2450 case 178: /* RES 6,D */
2451 { D( res( 0x40, D() ) ); return ( 8 ); }
2452 case 179: /* RES 6,E */
2453 { E( res( 0x40, E() ) ); return ( 8 ); }
2454 case 180: /* RES 6,H */
2455 { H( res( 0x40, H() ) ); return ( 8 ); }
2456 case 181: /* RES 6,L */
2457 { L( res( 0x40, L() ) ); return ( 8 ); }
2458 case 182: /* RES 6,(HL) */
2461 pokeb( hl
, res( 0x40, peekb( hl
) ) );
2464 case 183: /* RES 6,A */
2465 { A( res( 0x40, A() ) ); return ( 8 ); }
2467 case 184: /* RES 7,B */
2468 { B( res( 0x80, B() ) ); return ( 8 ); }
2469 case 185: /* RES 7,C */
2470 { C( res( 0x80, C() ) ); return ( 8 ); }
2471 case 186: /* RES 7,D */
2472 { D( res( 0x80, D() ) ); return ( 8 ); }
2473 case 187: /* RES 7,E */
2474 { E( res( 0x80, E() ) ); return ( 8 ); }
2475 case 188: /* RES 7,H */
2476 { H( res( 0x80, H() ) ); return ( 8 ); }
2477 case 189: /* RES 7,L */
2478 { L( res( 0x80, L() ) ); return ( 8 ); }
2479 case 190: /* RES 7,(HL) */
2482 pokeb( hl
, res( 0x80, peekb( hl
) ) );
2485 case 191: /* RES 7,A */
2486 { A( res( 0x80, A() ) ); return ( 8 ); }
2488 case 192: /* SET 0,B */
2489 { B( set( 0x01, B() ) ); return ( 8 ); }
2490 case 193: /* SET 0,C */
2491 { C( set( 0x01, C() ) ); return ( 8 ); }
2492 case 194: /* SET 0,D */
2493 { D( set( 0x01, D() ) ); return ( 8 ); }
2494 case 195: /* SET 0,E */
2495 { E( set( 0x01, E() ) ); return ( 8 ); }
2496 case 196: /* SET 0,H */
2497 { H( set( 0x01, H() ) ); return ( 8 ); }
2498 case 197: /* SET 0,L */
2499 { L( set( 0x01, L() ) ); return ( 8 ); }
2500 case 198: /* SET 0,(HL) */
2503 pokeb( hl
, set( 0x01, peekb( hl
) ) );
2506 case 199: /* SET 0,A */
2507 { A( set( 0x01, A() ) ); return ( 8 ); }
2509 case 200: /* SET 1,B */
2510 { B( set( 0x02, B() ) ); return ( 8 ); }
2511 case 201: /* SET 1,C */
2512 { C( set( 0x02, C() ) ); return ( 8 ); }
2513 case 202: /* SET 1,D */
2514 { D( set( 0x02, D() ) ); return ( 8 ); }
2515 case 203: /* SET 1,E */
2516 { E( set( 0x02, E() ) ); return ( 8 ); }
2517 case 204: /* SET 1,H */
2518 { H( set( 0x02, H() ) ); return ( 8 ); }
2519 case 205: /* SET 1,L */
2520 { L( set( 0x02, L() ) ); return ( 8 ); }
2521 case 206: /* SET 1,(HL) */
2524 pokeb( hl
, set( 0x02, peekb( hl
) ) );
2527 case 207: /* SET 1,A */
2528 { A( set( 0x02, A() ) ); return ( 8 ); }
2530 case 208: /* SET 2,B */
2531 { B( set( 0x04, B() ) ); return ( 8 ); }
2532 case 209: /* SET 2,C */
2533 { C( set( 0x04, C() ) ); return ( 8 ); }
2534 case 210: /* SET 2,D */
2535 { D( set( 0x04, D() ) ); return ( 8 ); }
2536 case 211: /* SET 2,E */
2537 { E( set( 0x04, E() ) ); return ( 8 ); }
2538 case 212: /* SET 2,H */
2539 { H( set( 0x04, H() ) ); return ( 8 ); }
2540 case 213: /* SET 2,L */
2541 { L( set( 0x04, L() ) ); return ( 8 ); }
2542 case 214: /* SET 2,(HL) */
2545 pokeb( hl
, set( 0x04, peekb( hl
) ) );
2548 case 215: /* SET 2,A */
2549 { A( set( 0x04, A() ) ); return ( 8 ); }
2551 case 216: /* SET 3,B */
2552 { B( set( 0x08, B() ) ); return ( 8 ); }
2553 case 217: /* SET 3,C */
2554 { C( set( 0x08, C() ) ); return ( 8 ); }
2555 case 218: /* SET 3,D */
2556 { D( set( 0x08, D() ) ); return ( 8 ); }
2557 case 219: /* SET 3,E */
2558 { E( set( 0x08, E() ) ); return ( 8 ); }
2559 case 220: /* SET 3,H */
2560 { H( set( 0x08, H() ) ); return ( 8 ); }
2561 case 221: /* SET 3,L */
2562 { L( set( 0x08, L() ) ); return ( 8 ); }
2563 case 222: /* SET 3,(HL) */
2566 pokeb( hl
, set( 0x08, peekb( hl
) ) );
2569 case 223: /* SET 3,A */
2570 { A( set( 0x08, A() ) ); return ( 8 ); }
2572 case 224: /* SET 4,B */
2573 { B( set( 0x10, B() ) ); return ( 8 ); }
2574 case 225: /* SET 4,C */
2575 { C( set( 0x10, C() ) ); return ( 8 ); }
2576 case 226: /* SET 4,D */
2577 { D( set( 0x10, D() ) ); return ( 8 ); }
2578 case 227: /* SET 4,E */
2579 { E( set( 0x10, E() ) ); return ( 8 ); }
2580 case 228: /* SET 4,H */
2581 { H( set( 0x10, H() ) ); return ( 8 ); }
2582 case 229: /* SET 4,L */
2583 { L( set( 0x10, L() ) ); return ( 8 ); }
2584 case 230: /* SET 4,(HL) */
2587 pokeb( hl
, set( 0x10, peekb( hl
) ) );
2590 case 231: /* SET 4,A */
2591 { A( set( 0x10, A() ) ); return ( 8 ); }
2593 case 232: /* SET 5,B */
2594 { B( set( 0x20, B() ) ); return ( 8 ); }
2595 case 233: /* SET 5,C */
2596 { C( set( 0x20, C() ) ); return ( 8 ); }
2597 case 234: /* SET 5,D */
2598 { D( set( 0x20, D() ) ); return ( 8 ); }
2599 case 235: /* SET 5,E */
2600 { E( set( 0x20, E() ) ); return ( 8 ); }
2601 case 236: /* SET 5,H */
2602 { H( set( 0x20, H() ) ); return ( 8 ); }
2603 case 237: /* SET 5,L */
2604 { L( set( 0x20, L() ) ); return ( 8 ); }
2605 case 238: /* SET 5,(HL) */
2608 pokeb( hl
, set( 0x20, peekb( hl
) ) );
2611 case 239: /* SET 5,A */
2612 { A( set( 0x20, A() ) ); return ( 8 ); }
2614 case 240: /* SET 6,B */
2615 { B( set( 0x40, B() ) ); return ( 8 ); }
2616 case 241: /* SET 6,C */
2617 { C( set( 0x40, C() ) ); return ( 8 ); }
2618 case 242: /* SET 6,D */
2619 { D( set( 0x40, D() ) ); return ( 8 ); }
2620 case 243: /* SET 6,E */
2621 { E( set( 0x40, E() ) ); return ( 8 ); }
2622 case 244: /* SET 6,H */
2623 { H( set( 0x40, H() ) ); return ( 8 ); }
2624 case 245: /* SET 6,L */
2625 { L( set( 0x40, L() ) ); return ( 8 ); }
2626 case 246: /* SET 6,(HL) */
2629 pokeb( hl
, set( 0x40, peekb( hl
) ) );
2632 case 247: /* SET 6,A */
2633 { A( set( 0x40, A() ) ); return ( 8 ); }
2635 case 248: /* SET 7,B */
2636 { B( set( 0x80, B() ) ); return ( 8 ); }
2637 case 249: /* SET 7,C */
2638 { C( set( 0x80, C() ) ); return ( 8 ); }
2639 case 250: /* SET 7,D */
2640 { D( set( 0x80, D() ) ); return ( 8 ); }
2641 case 251: /* SET 7,E */
2642 { E( set( 0x80, E() ) ); return ( 8 ); }
2643 case 252: /* SET 7,H */
2644 { H( set( 0x80, H() ) ); return ( 8 ); }
2645 case 253: /* SET 7,L */
2646 { L( set( 0x80, L() ) ); return ( 8 ); }
2647 case 254: /* SET 7,(HL) */
2650 pokeb( hl
, set( 0x80, peekb( hl
) ) );
2653 case 255: /* SET 7,A */
2654 { A( set( 0x80, A() ) ); return ( 8 ); }
2661 private final int execute_id() {
2665 switch ( nxtpcb() ) {
2856 PC( dec16( PC() ) );
2861 case 9: /* ADD ID,BC */
2862 { ID( add16( ID(), BC() ) ); return ( 15 ); }
2863 case 25: /* ADD ID,DE */
2864 { ID( add16( ID(), DE() ) ); return ( 15 ); }
2865 case 41: /* ADD ID,ID */
2868 ID( add16( id
, id
) );
2871 case 57: /* ADD ID,SP */
2872 { ID( add16( ID(),SP() ) ); return ( 15 ); }
2874 case 33: /* LD ID,nn */
2875 { ID( nxtpcw() ); return ( 14 ); }
2876 case 34: /* LD (nn),ID */
2877 { pokew( nxtpcw(), ID() ); return ( 20 ); }
2878 case 42: /* LD ID,(nn) */
2879 { ID( peekw( nxtpcw() ) ); return ( 20 ); }
2880 case 35:/* INC ID */
2881 { ID( inc16( ID() ) ); return ( 10 ); }
2882 case 43:/* DEC ID */
2883 { ID( dec16( ID() ) ); return ( 10 ); }
2884 case 36:/* INC IDH */
2885 { IDH( inc8( IDH() ) ); return ( 8 ); }
2886 case 44:/* INC IDL */
2887 { IDL( inc8( IDL() ) ); return ( 8 ); }
2888 case 52:/* INC (ID+d) */
2891 pokeb( z
, inc8( peekb(z
) ) );
2894 case 37:/* DEC IDH */
2895 { IDH( dec8( IDH() ) ); return ( 8 ); }
2896 case 45:/* DEC IDL */
2897 { IDL( dec8( IDL() ) ); return ( 8 ); }
2898 case 53:/* DEC (ID+d) */
2901 pokeb( z
, dec8( peekb(z
) ) );
2905 case 38: /* LD IDH,n */
2906 { IDH( nxtpcb() ); return ( 11 ); }
2907 case 46: /* LD IDL,n */
2908 { IDL( nxtpcb() ); return ( 11 ); }
2909 case 54: /* LD (ID+d),n */
2910 { int z
= ID_d(); pokeb(z
,nxtpcb()); return ( 19 ); }
2912 case 68: /* LD B,IDH */
2913 { B( IDH() ); return ( 8 ); }
2914 case 69: /* LD B,IDL */
2915 { B( IDL() ); return ( 8 ); }
2916 case 70: /* LD B,(ID+d) */
2917 { B( peekb( ID_d() ) ); return ( 19 ); }
2919 case 76: /* LD C,IDH */
2920 { C( IDH() ); return ( 8 ); }
2921 case 77: /* LD C,IDL */
2922 { C( IDL() ); return ( 8 ); }
2923 case 78: /* LD C,(ID+d) */
2924 { C( peekb( ID_d() ) ); return ( 19 ); }
2926 case 84: /* LD D,IDH */
2927 { D( IDH() ); return ( 8 ); }
2928 case 85: /* LD D,IDL */
2929 { D( IDL() ); return ( 8 ); }
2930 case 86: /* LD D,(ID+d) */
2931 { D( peekb( ID_d() ) ); return ( 19 ); }
2933 case 92: /* LD E,IDH */
2934 { E( IDH() ); return ( 8 ); }
2935 case 93: /* LD E,IDL */
2936 { E( IDL() ); return ( 8 ); }
2937 case 94: /* LD E,(ID+d) */
2938 { E( peekb( ID_d() ) ); return ( 19 ); }
2940 case 96: /* LD IDH,B */
2941 { IDH( B() ); return ( 8 ); }
2942 case 97: /* LD IDH,C */
2943 { IDH( C() ); return ( 8 ); }
2944 case 98: /* LD IDH,D */
2945 { IDH( D() ); return ( 8 ); }
2946 case 99: /* LD IDH,E */
2947 { IDH( E() ); return ( 8 ); }
2948 case 100: /* LD IDH,IDH */
2950 case 101: /* LD IDH,IDL */
2951 { IDH( IDL() ); return ( 8 ); }
2952 case 102: /* LD H,(ID+d) */
2953 { H( peekb( ID_d() ) ); return ( 19 ); }
2954 case 103: /* LD IDH,A */
2955 { IDH( A() ); return ( 8 ); }
2957 case 104: /* LD IDL,B */
2958 { IDL( B() ); return ( 8 ); }
2959 case 105: /* LD IDL,C */
2960 { IDL( C() ); return ( 8 ); }
2961 case 106: /* LD IDL,D */
2962 { IDL( D() ); return ( 8 ); }
2963 case 107: /* LD IDL,E */
2964 { IDL( E() ); return ( 8 ); }
2965 case 108: /* LD IDL,IDH */
2966 { IDL( IDH() ); return ( 8 ); }
2967 case 109: /* LD IDL,IDL */
2969 case 110: /* LD L,(ID+d) */
2970 { L( peekb( ID_d() ) ); return ( 19 ); }
2971 case 111: /* LD IDL,A */
2972 { IDL( A() ); return ( 8 ); }
2974 case 112: /* LD (ID+d),B */
2975 { pokeb( ID_d(), B() ); return ( 19 ); }
2976 case 113: /* LD (ID+d),C */
2977 { pokeb( ID_d(), C() ); return ( 19 ); }
2978 case 114: /* LD (ID+d),D */
2979 { pokeb( ID_d(), D() ); return ( 19 ); }
2980 case 115: /* LD (ID+d),E */
2981 { pokeb( ID_d(), E() ); return ( 19 ); }
2982 case 116: /* LD (ID+d),H */
2983 { pokeb( ID_d(), H() ); return ( 19 ); }
2984 case 117: /* LD (ID+d),L */
2985 { pokeb( ID_d(), L() ); return ( 19 ); }
2986 case 119: /* LD (ID+d),A */
2987 { pokeb( ID_d(), A() ); return ( 19 ); }
2989 case 124: /* LD A,IDH */
2990 { A( IDH() ); return ( 8 ); }
2991 case 125: /* LD A,IDL */
2992 { A( IDL() ); return ( 8 ); }
2993 case 126: /* LD A,(ID+d) */
2994 { A( peekb( ID_d() ) ); return ( 19 ); }
2996 case 132: /* ADD A,IDH */
2997 { add_a(IDH()); return ( 8 ); }
2998 case 133: /* ADD A,IDL */
2999 { add_a(IDL()); return ( 8 ); }
3000 case 134: /* ADD A,(ID+d) */
3001 { add_a(peekb( ID_d() )); return ( 19 ); }
3003 case 140: /* ADC A,IDH */
3004 { adc_a(IDH()); return ( 8 ); }
3005 case 141: /* ADC A,IDL */
3006 { adc_a(IDL()); return ( 8 ); }
3007 case 142: /* ADC A,(ID+d) */
3008 { adc_a(peekb( ID_d() )); return ( 19 ); }
3010 case 148: /* SUB IDH */
3011 { sub_a(IDH()); return ( 8 ); }
3012 case 149: /* SUB IDL */
3013 { sub_a(IDL()); return ( 8 ); }
3014 case 150: /* SUB (ID+d) */
3015 { sub_a(peekb( ID_d() )); return ( 19 ); }
3017 case 156: /* SBC A,IDH */
3018 { sbc_a(IDH()); return ( 8 ); }
3019 case 157: /* SBC A,IDL */
3020 { sbc_a(IDL()); return ( 8 ); }
3021 case 158: /* SBC A,(ID+d) */
3022 { sbc_a(peekb( ID_d() )); return ( 19 ); }
3024 case 164: /* AND IDH */
3025 { and_a(IDH()); return ( 8 ); }
3026 case 165: /* AND IDL */
3027 { and_a(IDL()); return ( 8 ); }
3028 case 166: /* AND (ID+d) */
3029 { and_a(peekb( ID_d() )); return ( 19 ); }
3031 case 172: /* XOR IDH */
3032 { xor_a(IDH()); return ( 8 ); }
3033 case 173: /* XOR IDL */
3034 { xor_a(IDL()); return ( 8 ); }
3035 case 174: /* XOR (ID+d) */
3036 { xor_a(peekb( ID_d() )); return ( 19 ); }
3038 case 180: /* OR IDH */
3039 { or_a(IDH()); return ( 8 ); }
3040 case 181: /* OR IDL */
3041 { or_a(IDL()); return ( 8 ); }
3042 case 182: /* OR (ID+d) */
3043 { or_a(peekb( ID_d() )); return ( 19 ); }
3045 case 188: /* CP IDH */
3046 { cp_a(IDH()); return ( 8 ); }
3047 case 189: /* CP IDL */
3048 { cp_a(IDL()); return ( 8 ); }
3049 case 190: /* CP (ID+d) */
3050 { cp_a(peekb( ID_d() )); return ( 19 ); }
3052 case 225: /* POP ID */
3053 { ID( popw() ); return ( 14 ); }
3055 case 233: /* JP (ID) */
3056 { PC( ID() ); return ( 8 ); }
3058 case 249: /* LD SP,ID */
3059 { SP( ID() ); return ( 10 ); }
3061 case 203: /* prefix CB */
3063 // Get index address (offset byte is first)
3065 // Opcode comes after offset byte
3067 execute_id_cb( op
, z
);
3068 // Bit instructions take 20 T states, rest 23
3069 return ( (( op
& 0xc0 ) == 0x40) ?
20 : 23 );
3072 case 227: /* EX (SP),ID */
3081 case 229: /* PUSH ID */
3082 { pushw( ID() ); return ( 15 ); }
3090 private final void execute_id_cb(int op
, int z
) {
3095 { B( op
= rlc( peekb( z
) ) ); pokeb( z
, op
); return; }
3097 { C( op
= rlc( peekb( z
) ) ); pokeb( z
, op
); return; }
3099 { D( op
= rlc( peekb( z
) ) ); pokeb( z
, op
); return; }
3101 { E( op
= rlc( peekb( z
) ) ); pokeb( z
, op
); return; }
3103 { H( op
= rlc( peekb( z
) ) ); pokeb( z
, op
); return; }
3105 { L( op
= rlc( peekb( z
) ) ); pokeb( z
, op
); return; }
3106 case 6: /* RLC (HL) */
3107 { pokeb( z
, rlc( peekb( z
) ) ); return; }
3109 { A( op
= rlc( peekb( z
) ) ); pokeb( z
, op
); return; }
3112 { B( op
= rrc( peekb( z
) ) ); pokeb( z
, op
); return; }
3114 { C( op
= rrc( peekb( z
) ) ); pokeb( z
, op
); return; }
3115 case 10: /* RRC D */
3116 { D( op
= rrc( peekb( z
) ) ); pokeb( z
, op
); return; }
3117 case 11: /* RRC E */
3118 { E( op
= rrc( peekb( z
) ) ); pokeb( z
, op
); return; }
3119 case 12: /* RRC H */
3120 { H( op
= rrc( peekb( z
) ) ); pokeb( z
, op
); return; }
3121 case 13: /* RRC L */
3122 { L( op
= rrc( peekb( z
) ) ); pokeb( z
, op
); return; }
3123 case 14: /* RRC (HL) */
3124 { pokeb( z
, rrc( peekb( z
) ) ); return; }
3125 case 15: /* RRC A */
3126 { A( op
= rrc( peekb( z
) ) ); pokeb( z
, op
); return; }
3129 { B( op
= rl( peekb( z
) ) ); pokeb( z
, op
); return; }
3131 { C( op
= rl( peekb( z
) ) ); pokeb( z
, op
); return; }
3133 { D( op
= rl( peekb( z
) ) ); pokeb( z
, op
); return; }
3135 { E( op
= rl( peekb( z
) ) ); pokeb( z
, op
); return; }
3137 { H( op
= rl( peekb( z
) ) ); pokeb( z
, op
); return; }
3139 { L( op
= rl( peekb( z
) ) ); pokeb( z
, op
); return; }
3140 case 22: /* RL (HL) */
3141 { pokeb( z
, rl( peekb( z
) ) ); return; }
3143 { A( op
= rl( peekb( z
) ) ); pokeb( z
, op
); return; }
3146 { B( op
= rr( peekb( z
) ) ); pokeb( z
, op
); return; }
3148 { C( op
= rr( peekb( z
) ) ); pokeb( z
, op
); return; }
3150 { D( op
= rr( peekb( z
) ) ); pokeb( z
, op
); return; }
3152 { E( op
= rr( peekb( z
) ) ); pokeb( z
, op
); return; }
3154 { H( op
= rr( peekb( z
) ) ); pokeb( z
, op
); return; }
3156 { L( op
= rr( peekb( z
) ) ); pokeb( z
, op
); return; }
3157 case 30: /* RR (HL) */
3158 { pokeb( z
, rr( peekb( z
) ) ); return; }
3160 { A( op
= rr( peekb( z
) ) ); pokeb( z
, op
); return; }
3162 case 32: /* SLA B */
3163 { B( op
= sla( peekb( z
) ) ); pokeb( z
, op
); return; }
3164 case 33: /* SLA C */
3165 { C( op
= sla( peekb( z
) ) ); pokeb( z
, op
); return; }
3166 case 34: /* SLA D */
3167 { D( op
= sla( peekb( z
) ) ); pokeb( z
, op
); return; }
3168 case 35: /* SLA E */
3169 { E( op
= sla( peekb( z
) ) ); pokeb( z
, op
); return; }
3170 case 36: /* SLA H */
3171 { H( op
= sla( peekb( z
) ) ); pokeb( z
, op
); return; }
3172 case 37: /* SLA L */
3173 { L( op
= sla( peekb( z
) ) ); pokeb( z
, op
); return; }
3174 case 38: /* SLA (HL) */
3175 { pokeb( z
, sla( peekb( z
) ) ); return; }
3176 case 39: /* SLA A */
3177 { A( op
= sla( peekb( z
) ) ); pokeb( z
, op
); return; }
3179 case 40: /* SRA B */
3180 { B( op
= sra( peekb( z
) ) ); pokeb( z
, op
); return; }
3181 case 41: /* SRA C */
3182 { C( op
= sra( peekb( z
) ) ); pokeb( z
, op
); return; }
3183 case 42: /* SRA D */
3184 { D( op
= sra( peekb( z
) ) ); pokeb( z
, op
); return; }
3185 case 43: /* SRA E */
3186 { E( op
= sra( peekb( z
) ) ); pokeb( z
, op
); return; }
3187 case 44: /* SRA H */
3188 { H( op
= sra( peekb( z
) ) ); pokeb( z
, op
); return; }
3189 case 45: /* SRA L */
3190 { L( op
= sra( peekb( z
) ) ); pokeb( z
, op
); return; }
3191 case 46: /* SRA (HL) */
3192 { pokeb( z
, sra( peekb( z
) ) ); return; }
3193 case 47: /* SRA A */
3194 { A( op
= sra( peekb( z
) ) ); pokeb( z
, op
); return; }
3196 case 48: /* SLS B */
3197 { B( op
= sls( peekb( z
) ) ); pokeb( z
, op
); return; }
3198 case 49: /* SLS C */
3199 { C( op
= sls( peekb( z
) ) ); pokeb( z
, op
); return; }
3200 case 50: /* SLS D */
3201 { D( op
= sls( peekb( z
) ) ); pokeb( z
, op
); return; }
3202 case 51: /* SLS E */
3203 { E( op
= sls( peekb( z
) ) ); pokeb( z
, op
); return; }
3204 case 52: /* SLS H */
3205 { H( op
= sls( peekb( z
) ) ); pokeb( z
, op
); return; }
3206 case 53: /* SLS L */
3207 { L( op
= sls( peekb( z
) ) ); pokeb( z
, op
); return; }
3208 case 54: /* SLS (HL) */
3209 { pokeb( z
, sls( peekb( z
) ) ); return; }
3210 case 55: /* SLS A */
3211 { A( op
= sls( peekb( z
) ) ); pokeb( z
, op
); return; }
3213 case 56: /* SRL B */
3214 { B( op
= srl( peekb( z
) ) ); pokeb( z
, op
); return; }
3215 case 57: /* SRL C */
3216 { C( op
= srl( peekb( z
) ) ); pokeb( z
, op
); return; }
3217 case 58: /* SRL D */
3218 { D( op
= srl( peekb( z
) ) ); pokeb( z
, op
); return; }
3219 case 59: /* SRL E */
3220 { E( op
= srl( peekb( z
) ) ); pokeb( z
, op
); return; }
3221 case 60: /* SRL H */
3222 { H( op
= srl( peekb( z
) ) ); pokeb( z
, op
); return; }
3223 case 61: /* SRL L */
3224 { L( op
= srl( peekb( z
) ) ); pokeb( z
, op
); return; }
3225 case 62: /* SRL (HL) */
3226 { pokeb( z
, srl( peekb( z
) ) ); return; }
3227 case 63: /* SRL A */
3228 { A( op
= srl( peekb( z
) ) ); pokeb( z
, op
); return; }
3230 case 64: /* BIT 0,B */
3231 case 65: /* BIT 0,B */
3232 case 66: /* BIT 0,B */
3233 case 67: /* BIT 0,B */
3234 case 68: /* BIT 0,B */
3235 case 69: /* BIT 0,B */
3236 case 70: /* BIT 0,B */
3237 case 71: /* BIT 0,B */
3238 { bit( 0x01, peekb( z
) ); return; }
3240 case 72: /* BIT 1,B */
3241 case 73: /* BIT 1,B */
3242 case 74: /* BIT 1,B */
3243 case 75: /* BIT 1,B */
3244 case 76: /* BIT 1,B */
3245 case 77: /* BIT 1,B */
3246 case 78: /* BIT 1,B */
3247 case 79: /* BIT 1,B */
3248 { bit( 0x02, peekb( z
) ); return; }
3250 case 80: /* BIT 2,B */
3251 case 81: /* BIT 2,B */
3252 case 82: /* BIT 2,B */
3253 case 83: /* BIT 2,B */
3254 case 84: /* BIT 2,B */
3255 case 85: /* BIT 2,B */
3256 case 86: /* BIT 2,B */
3257 case 87: /* BIT 2,B */
3258 { bit( 0x04, peekb( z
) ); return; }
3260 case 88: /* BIT 3,B */
3261 case 89: /* BIT 3,B */
3262 case 90: /* BIT 3,B */
3263 case 91: /* BIT 3,B */
3264 case 92: /* BIT 3,B */
3265 case 93: /* BIT 3,B */
3266 case 94: /* BIT 3,B */
3267 case 95: /* BIT 3,B */
3268 { bit( 0x08, peekb( z
) ); return; }
3270 case 96: /* BIT 4,B */
3271 case 97: /* BIT 4,B */
3272 case 98: /* BIT 4,B */
3273 case 99: /* BIT 4,B */
3274 case 100: /* BIT 4,B */
3275 case 101: /* BIT 4,B */
3276 case 102: /* BIT 4,B */
3277 case 103: /* BIT 4,B */
3278 { bit( 0x10, peekb( z
) ); return; }
3280 case 104: /* BIT 5,B */
3281 case 105: /* BIT 5,B */
3282 case 106: /* BIT 5,B */
3283 case 107: /* BIT 5,B */
3284 case 108: /* BIT 5,B */
3285 case 109: /* BIT 5,B */
3286 case 110: /* BIT 5,B */
3287 case 111: /* BIT 5,B */
3288 { bit( 0x20, peekb( z
) ); return; }
3290 case 112: /* BIT 6,B */
3291 case 113: /* BIT 6,B */
3292 case 114: /* BIT 6,B */
3293 case 115: /* BIT 6,B */
3294 case 116: /* BIT 6,B */
3295 case 117: /* BIT 6,B */
3296 case 118: /* BIT 6,B */
3297 case 119: /* BIT 6,B */
3298 { bit( 0x40, peekb( z
) ); return; }
3300 case 120: /* BIT 7,B */
3301 case 121: /* BIT 7,B */
3302 case 122: /* BIT 7,B */
3303 case 123: /* BIT 7,B */
3304 case 124: /* BIT 7,B */
3305 case 125: /* BIT 7,B */
3306 case 126: /* BIT 7,B */
3307 case 127: /* BIT 7,B */
3308 { bit( 0x80, peekb( z
) ); return; }
3310 case 128: /* RES 0,B */
3311 { B( op
= res( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3312 case 129: /* RES 0,C */
3313 { C( op
= res( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3314 case 130: /* RES 0,D */
3315 { D( op
= res( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3316 case 131: /* RES 0,E */
3317 { E( op
= res( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3318 case 132: /* RES 0,H */
3319 { H( op
= res( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3320 case 133: /* RES 0,L */
3321 { L( op
= res( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3322 case 134: /* RES 0,(HL) */
3323 { pokeb( z
, res( 0x01, peekb( z
) ) ); return; }
3324 case 135: /* RES 0,A */
3325 { A( op
= res( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3327 case 136: /* RES 1,B */
3328 { B( op
= res( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3329 case 137: /* RES 1,C */
3330 { C( op
= res( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3331 case 138: /* RES 1,D */
3332 { D( op
= res( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3333 case 139: /* RES 1,E */
3334 { E( op
= res( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3335 case 140: /* RES 1,H */
3336 { H( op
= res( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3337 case 141: /* RES 1,L */
3338 { L( op
= res( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3339 case 142: /* RES 1,(HL) */
3340 { pokeb( z
, res( 0x02, peekb( z
) ) ); return; }
3341 case 143: /* RES 1,A */
3342 { A( op
= res( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3344 case 144: /* RES 2,B */
3345 { B( op
= res( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3346 case 145: /* RES 2,C */
3347 { C( op
= res( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3348 case 146: /* RES 2,D */
3349 { D( op
= res( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3350 case 147: /* RES 2,E */
3351 { E( op
= res( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3352 case 148: /* RES 2,H */
3353 { H( op
= res( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3354 case 149: /* RES 2,L */
3355 { L( op
= res( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3356 case 150: /* RES 2,(HL) */
3357 { pokeb( z
, res( 0x04, peekb( z
) ) ); return; }
3358 case 151: /* RES 2,A */
3359 { A( op
= res( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3361 case 152: /* RES 3,B */
3362 { B( op
= res( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3363 case 153: /* RES 3,C */
3364 { C( op
= res( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3365 case 154: /* RES 3,D */
3366 { D( op
= res( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3367 case 155: /* RES 3,E */
3368 { E( op
= res( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3369 case 156: /* RES 3,H */
3370 { H( op
= res( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3371 case 157: /* RES 3,L */
3372 { L( op
= res( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3373 case 158: /* RES 3,(HL) */
3374 { pokeb( z
, res( 0x08, peekb( z
) ) ); return; }
3375 case 159: /* RES 3,A */
3376 { A( op
= res( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3378 case 160: /* RES 4,B */
3379 { B( op
= res( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3380 case 161: /* RES 4,C */
3381 { C( op
= res( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3382 case 162: /* RES 4,D */
3383 { D( op
= res( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3384 case 163: /* RES 4,E */
3385 { E( op
= res( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3386 case 164: /* RES 4,H */
3387 { H( op
= res( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3388 case 165: /* RES 4,L */
3389 { L( op
= res( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3390 case 166: /* RES 4,(HL) */
3391 { pokeb( z
, res( 0x10, peekb( z
) ) ); return; }
3392 case 167: /* RES 4,A */
3393 { A( op
= res( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3395 case 168: /* RES 5,B */
3396 { B( op
= res( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3397 case 169: /* RES 5,C */
3398 { C( op
= res( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3399 case 170: /* RES 5,D */
3400 { D( op
= res( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3401 case 171: /* RES 5,E */
3402 { E( op
= res( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3403 case 172: /* RES 5,H */
3404 { H( op
= res( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3405 case 173: /* RES 5,L */
3406 { L( op
= res( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3407 case 174: /* RES 5,(HL) */
3408 { pokeb( z
, res( 0x20, peekb( z
) ) ); return; }
3409 case 175: /* RES 5,A */
3410 { A( op
= res( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3412 case 176: /* RES 6,B */
3413 { B( op
= res( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3414 case 177: /* RES 6,C */
3415 { C( op
= res( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3416 case 178: /* RES 6,D */
3417 { D( op
= res( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3418 case 179: /* RES 6,E */
3419 { E( op
= res( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3420 case 180: /* RES 6,H */
3421 { H( op
= res( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3422 case 181: /* RES 6,L */
3423 { L( op
= res( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3424 case 182: /* RES 6,(HL) */
3425 { pokeb( z
, res( 0x40, peekb( z
) ) ); return; }
3426 case 183: /* RES 6,A */
3427 { A( op
= res( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3429 case 184: /* RES 7,B */
3430 { B( op
= res( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3431 case 185: /* RES 7,C */
3432 { C( op
= res( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3433 case 186: /* RES 7,D */
3434 { D( op
= res( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3435 case 187: /* RES 7,E */
3436 { E( op
= res( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3437 case 188: /* RES 7,H */
3438 { H( op
= res( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3439 case 189: /* RES 7,L */
3440 { L( op
= res( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3441 case 190: /* RES 7,(HL) */
3442 { pokeb( z
, res( 0x80, peekb( z
) ) ); return; }
3443 case 191: /* RES 7,A */
3444 { A( op
= res( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3446 case 192: /* SET 0,B */
3447 { B( op
= set( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3448 case 193: /* SET 0,C */
3449 { C( op
= set( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3450 case 194: /* SET 0,D */
3451 { D( op
= set( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3452 case 195: /* SET 0,E */
3453 { E( op
= set( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3454 case 196: /* SET 0,H */
3455 { H( op
= set( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3456 case 197: /* SET 0,L */
3457 { L( op
= set( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3458 case 198: /* SET 0,(HL) */
3459 { pokeb( z
, set( 0x01, peekb( z
) ) ); return; }
3460 case 199: /* SET 0,A */
3461 { A( op
= set( 0x01, peekb( z
) ) ); pokeb( z
, op
); return; }
3463 case 200: /* SET 1,B */
3464 { B( op
= set( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3465 case 201: /* SET 1,C */
3466 { C( op
= set( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3467 case 202: /* SET 1,D */
3468 { D( op
= set( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3469 case 203: /* SET 1,E */
3470 { E( op
= set( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3471 case 204: /* SET 1,H */
3472 { H( op
= set( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3473 case 205: /* SET 1,L */
3474 { L( op
= set( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3475 case 206: /* SET 1,(HL) */
3476 { pokeb( z
, set( 0x02, peekb( z
) ) ); return; }
3477 case 207: /* SET 1,A */
3478 { A( op
= set( 0x02, peekb( z
) ) ); pokeb( z
, op
); return; }
3480 case 208: /* SET 2,B */
3481 { B( op
= set( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3482 case 209: /* SET 2,C */
3483 { C( op
= set( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3484 case 210: /* SET 2,D */
3485 { D( op
= set( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3486 case 211: /* SET 2,E */
3487 { E( op
= set( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3488 case 212: /* SET 2,H */
3489 { H( op
= set( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3490 case 213: /* SET 2,L */
3491 { L( op
= set( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3492 case 214: /* SET 2,(HL) */
3493 { pokeb( z
, set( 0x04, peekb( z
) ) ); return; }
3494 case 215: /* SET 2,A */
3495 { A( op
= set( 0x04, peekb( z
) ) ); pokeb( z
, op
); return; }
3497 case 216: /* SET 3,B */
3498 { B( op
= set( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3499 case 217: /* SET 3,C */
3500 { C( op
= set( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3501 case 218: /* SET 3,D */
3502 { D( op
= set( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3503 case 219: /* SET 3,E */
3504 { E( op
= set( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3505 case 220: /* SET 3,H */
3506 { H( op
= set( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3507 case 221: /* SET 3,L */
3508 { L( op
= set( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3509 case 222: /* SET 3,(HL) */
3510 { pokeb( z
, set( 0x08, peekb( z
) ) ); return; }
3511 case 223: /* SET 3,A */
3512 { A( op
= set( 0x08, peekb( z
) ) ); pokeb( z
, op
); return; }
3514 case 224: /* SET 4,B */
3515 { B( op
= set( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3516 case 225: /* SET 4,C */
3517 { C( op
= set( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3518 case 226: /* SET 4,D */
3519 { D( op
= set( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3520 case 227: /* SET 4,E */
3521 { E( op
= set( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3522 case 228: /* SET 4,H */
3523 { H( op
= set( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3524 case 229: /* SET 4,L */
3525 { L( op
= set( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3526 case 230: /* SET 4,(HL) */
3527 { pokeb( z
, set( 0x10, peekb( z
) ) ); return; }
3528 case 231: /* SET 4,A */
3529 { A( op
= set( 0x10, peekb( z
) ) ); pokeb( z
, op
); return; }
3531 case 232: /* SET 5,B */
3532 { B( op
= set( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3533 case 233: /* SET 5,C */
3534 { C( op
= set( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3535 case 234: /* SET 5,D */
3536 { D( op
= set( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3537 case 235: /* SET 5,E */
3538 { E( op
= set( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3539 case 236: /* SET 5,H */
3540 { H( op
= set( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3541 case 237: /* SET 5,L */
3542 { L( op
= set( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3543 case 238: /* SET 5,(HL) */
3544 { pokeb( z
, set( 0x20, peekb( z
) ) ); return; }
3545 case 239: /* SET 5,A */
3546 { A( op
= set( 0x20, peekb( z
) ) ); pokeb( z
, op
); return; }
3548 case 240: /* SET 6,B */
3549 { B( op
= set( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3550 case 241: /* SET 6,C */
3551 { C( op
= set( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3552 case 242: /* SET 6,D */
3553 { D( op
= set( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3554 case 243: /* SET 6,E */
3555 { E( op
= set( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3556 case 244: /* SET 6,H */
3557 { H( op
= set( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3558 case 245: /* SET 6,L */
3559 { L( op
= set( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3560 case 246: /* SET 6,(HL) */
3561 { pokeb( z
, set( 0x40, peekb( z
) ) ); return; }
3562 case 247: /* SET 6,A */
3563 { A( op
= set( 0x40, peekb( z
) ) ); pokeb( z
, op
); return; }
3565 case 248: /* SET 7,B */
3566 { B( op
= set( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3567 case 249: /* SET 7,C */
3568 { C( op
= set( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3569 case 250: /* SET 7,D */
3570 { D( op
= set( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3571 case 251: /* SET 7,E */
3572 { E( op
= set( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3573 case 252: /* SET 7,H */
3574 { H( op
= set( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3575 case 253: /* SET 7,L */
3576 { L( op
= set( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3577 case 254: /* SET 7,(HL) */
3578 { pokeb( z
, set( 0x80, peekb( z
) ) ); return; }
3579 case 255: /* SET 7,A */
3580 { A( op
= set( 0x80, peekb( z
) ) ); pokeb( z
, op
); return; }
3586 private final int in_bc() {
3587 int ans
= inb( BC() );
3590 setS( (ans
& F_S
)!=0 );
3591 set3( (ans
& F_3
)!=0 );
3592 set5( (ans
& F_5
)!=0 );
3593 setPV( parity
[ ans
] );
3600 /** Add with carry - alters all flags (CHECKED) */
3605 int c
= Cset() ?
1 : 0;
3606 int wans
= a
+ b
+ c
;
3607 int ans
= wans
& 0xff;
3609 setS( (ans
& F_S
) != 0 );
3610 set3( (ans
& F_3
) != 0 );
3611 set5( (ans
& F_5
) != 0 );
3613 setC( (wans
&0x100) != 0 );
3614 setPV( ((a ^ ~b
) & (a ^ ans
) & 0x80) != 0 );
3615 setH( (((a
& 0x0f) + (b
& 0x0f) + c
) & F_H
) != 0 );
3621 /** Add - alters all flags (CHECKED) */
3627 int ans
= wans
& 0xff;
3629 setS( (ans
& F_S
) != 0 );
3630 set3( (ans
& F_3
) != 0 );
3631 set5( (ans
& F_5
) != 0 );
3633 setC( (wans
&0x100) != 0 );
3634 setPV( ((a ^ ~b
) & (a ^ ans
) & 0x80) != 0 );
3635 setH( (((a
& 0x0f) + (b
& 0x0f)) & F_H
) != 0 );
3641 /** Subtract with carry - alters all flags (CHECKED) */
3646 int c
= Cset() ?
1 : 0;
3647 int wans
= a
- b
- c
;
3648 int ans
= wans
& 0xff;
3650 setS( (ans
& F_S
) != 0 );
3651 set3( (ans
& F_3
) != 0 );
3652 set5( (ans
& F_5
) != 0 );
3654 setC( (wans
&0x100) != 0 );
3655 setPV( ((a ^ b
) & (a ^ ans
) & 0x80) != 0 );
3656 setH( (((a
& 0x0f) - (b
& 0x0f) - c
) & F_H
) != 0 );
3662 /** Subtract - alters all flags (CHECKED) */
3668 int ans
= wans
& 0xff;
3670 setS( (ans
& F_S
) != 0 );
3671 set3( (ans
& F_3
) != 0 );
3672 set5( (ans
& F_5
) != 0 );
3674 setC( (wans
&0x100) != 0 );
3675 setPV( ((a ^ b
) & (a ^ ans
) & 0x80) != 0 );
3676 setH( (((a
& 0x0f) - (b
& 0x0f)) & F_H
) != 0 );
3682 /** Rotate Left - alters H N C 3 5 flags (CHECKED) */
3687 boolean c
= (ans
& 0x80) != 0;
3690 ans
= (ans
<< 1)|0x01;
3696 set3( (ans
& F_3
) != 0 );
3697 set5( (ans
& F_5
) != 0 );
3705 /** Rotate Right - alters H N C 3 5 flags (CHECKED) */
3710 boolean c
= (ans
& 0x01) != 0;
3713 ans
= (ans
>> 1)|0x80;
3718 set3( (ans
& F_3
) != 0 );
3719 set5( (ans
& F_5
) != 0 );
3727 /** Rotate Left through Carry - alters H N C 3 5 flags (CHECKED) */
3732 boolean c
= (ans
& 0x80) != 0;
3735 ans
= (ans
<< 1) | 0x01;
3742 set3( (ans
& F_3
) != 0 );
3743 set5( (ans
& F_5
) != 0 );
3751 /** Rotate Right through Carry - alters H N C 3 5 flags (CHECKED) */
3756 boolean c
= (ans
& 0x01) != 0;
3759 ans
= (ans
>> 1) | 0x80;
3764 set3( (ans
& F_3
) != 0 );
3765 set5( (ans
& F_5
) != 0 );
3773 /** Compare - alters all flags (CHECKED) */
3779 int ans
= wans
& 0xff;
3781 setS( (ans
& F_S
) != 0 );
3782 set3( (b
& F_3
) != 0 );
3783 set5( (b
& F_5
) != 0 );
3786 setC( (wans
& 0x100)!=0 );
3787 setH( (((a
& 0x0f) - (b
& 0x0f)) & F_H
) != 0 );
3788 setPV( ((a ^ b
) & (a ^ ans
) & 0x80) != 0 );
3791 /** Bitwise and - alters all flags (CHECKED) */
3797 setS( (ans
& F_S
) != 0 );
3798 set3( (ans
& F_3
) != 0 );
3799 set5( (ans
& F_5
) != 0 );
3801 setPV( parity
[ ans
] );
3809 /** Bitwise or - alters all flags (CHECKED) */
3815 setS( (ans
& F_S
) != 0 );
3816 set3( (ans
& F_3
) != 0 );
3817 set5( (ans
& F_5
) != 0 );
3819 setPV( parity
[ ans
] );
3827 /** Bitwise exclusive or - alters all flags (CHECKED) */
3831 int ans
= (A() ^ b
) & 0xff;
3833 setS( (ans
& F_S
) != 0 );
3834 set3( (ans
& F_3
) != 0 );
3835 set5( (ans
& F_5
) != 0 );
3837 setPV( parity
[ ans
] );
3845 /** Negate (Two's complement) - alters all flags (CHECKED) */
3855 /** One's complement - alters N H 3 5 flags (CHECKED) */
3859 int ans
= A() ^
0xff;
3861 set3( (ans
& F_3
) != 0 );
3862 set5( (ans
& F_5
) != 0 );
3869 /** Decimal Adjust Accumulator - alters all flags (CHECKED) */
3875 boolean carry
= Cset();
3877 if ((Hset()) || ((ans
& 0x0f) > 0x09)) {
3880 if (carry
|| (ans
> 0x9f) || ((ans
> 0x8f) && ((ans
& 0x0f) > 0x09))) {
3895 setPV( parity
[ ans
] );
3898 /** Load a with i - (NOT CHECKED) */
3904 setS( (ans
& F_S
) != 0 );
3905 set3( (ans
& F_3
) != 0 );
3906 set5( (ans
& F_5
) != 0 );
3915 /** Load a with r - (NOT CHECKED) */
3921 setS( (ans
& F_S
) != 0 );
3922 set3( (ans
& F_3
) != 0 );
3923 set5( (ans
& F_5
) != 0 );
3932 /** Rotate right through a and (hl) - (NOT CHECKED) */
3937 int t
= peekb( HL() );
3940 t
= (t
>> 4) | (ans
<< 4);
3941 ans
= (ans
& 0xf0) | (q
& 0x0f);
3944 setS( (ans
& F_S
) != 0 );
3945 set3( (ans
& F_3
) != 0 );
3946 set5( (ans
& F_5
) != 0 );
3955 /** Rotate left through a and (hl) - (NOT CHECKED) */
3960 int t
= peekb( HL() );
3963 t
= (t
<< 4) | (ans
& 0x0f);
3964 ans
= (ans
& 0xf0) | (q
>> 4);
3965 pokeb( HL(), (t
& 0xff) );
3967 setS( (ans
& F_S
) != 0 );
3968 set3( (ans
& F_3
) != 0 );
3969 set5( (ans
& F_5
) != 0 );
3978 /** Test bit - alters all but C flag (CHECKED) */
3982 boolean bitSet
= ((r
& b
) != 0);
3986 set3( (r
& F_3
) != 0 );
3987 set5( (r
& F_5
) != 0 );
3988 setS( (b
== F_S
) ? bitSet
: false );
3993 /** Set carry flag - alters N H 3 5 C flags (CHECKED) */
3999 set3( (ans
& F_3
) != 0 );
4000 set5( (ans
& F_5
) != 0 );
4006 /** Complement carry flag - alters N 3 5 C flags (CHECKED) */
4012 set3( (ans
& F_3
) != 0 );
4013 set5( (ans
& F_5
) != 0 );
4015 setC( Cset() ?
false : true );
4018 /** Rotate left - alters all flags (CHECKED) */
4022 boolean c
= (ans
& 0x80) != 0;
4025 ans
= (ans
<< 1)|0x01;
4031 setS( (ans
& F_S
) != 0 );
4032 set3( (ans
& F_3
) != 0 );
4033 set5( (ans
& F_5
) != 0 );
4035 setPV( parity
[ ans
] );
4043 /** Rotate right - alters all flags (CHECKED) */
4047 boolean c
= (ans
& 0x01) != 0;
4050 ans
= (ans
>> 1)|0x80;
4055 setS( (ans
& F_S
) != 0 );
4056 set3( (ans
& F_3
) != 0 );
4057 set5( (ans
& F_5
) != 0 );
4059 setPV( parity
[ ans
] );
4067 /** Rotate left through carry - alters all flags (CHECKED) */
4071 boolean c
= (ans
& 0x80) != 0;
4074 ans
= (ans
<< 1) | 0x01;
4080 setS( (ans
& F_S
) != 0 );
4081 set3( (ans
& F_3
) != 0 );
4082 set5( (ans
& F_5
) != 0 );
4084 setPV( parity
[ ans
] );
4092 /** Rotate right through carry - alters all flags (CHECKED) */
4096 boolean c
= (ans
& 0x01) != 0;
4099 ans
= (ans
>> 1) | 0x80;
4104 setS( (ans
& F_S
) != 0 );
4105 set3( (ans
& F_3
) != 0 );
4106 set5( (ans
& F_5
) != 0 );
4108 setPV( parity
[ ans
] );
4116 /** Shift Left Arithmetically - alters all flags (CHECKED) */
4120 boolean c
= (ans
& 0x80) != 0;
4121 ans
= (ans
<< 1) & 0xff;
4123 setS( (ans
& F_S
) != 0 );
4124 set3( (ans
& F_3
) != 0 );
4125 set5( (ans
& F_5
) != 0 );
4127 setPV( parity
[ ans
] );
4135 /** Shift Left and Set - alters all flags (CHECKED) */
4139 boolean c
= (ans
& 0x80) != 0;
4140 ans
= ((ans
<< 1) | 0x01) & 0xff;
4142 setS( (ans
& F_S
) != 0 );
4143 set3( (ans
& F_3
) != 0 );
4144 set5( (ans
& F_5
) != 0 );
4146 setPV( parity
[ ans
] );
4154 /** Shift Right Arithmetically - alters all flags (CHECKED) */
4158 boolean c
= (ans
& 0x01) != 0;
4159 ans
= (ans
>> 1) | (ans
& 0x80);
4161 setS( (ans
& F_S
) != 0 );
4162 set3( (ans
& F_3
) != 0 );
4163 set5( (ans
& F_5
) != 0 );
4165 setPV( parity
[ ans
] );
4173 /** Shift Right Logically - alters all flags (CHECKED) */
4174 private final int srl( int ans
) {
4175 boolean c
= (ans
& 0x01) != 0;
4178 setS( (ans
& F_S
) != 0 );
4179 set3( (ans
& F_3
) != 0 );
4180 set5( (ans
& F_5
) != 0 );
4182 setPV( parity
[ ans
] );
4190 /** Decrement - alters all but C flag (CHECKED) */
4191 private final int dec8( int ans
) {
4192 boolean pv
= (ans
== 0x80);
4193 boolean h
= (((ans
& 0x0f) - 1) & F_H
) != 0;
4194 ans
= (ans
- 1) & 0xff;
4196 setS( (ans
& F_S
) != 0 );
4197 set3( (ans
& F_3
) != 0 );
4198 set5( (ans
& F_5
) != 0 );
4207 /** Increment - alters all but C flag (CHECKED) */
4208 private final int inc8( int ans
) {
4209 boolean pv
= (ans
== 0x7f);
4210 boolean h
= (((ans
& 0x0f) + 1) & F_H
) != 0;
4211 ans
= (ans
+ 1) & 0xff;
4213 setS( (ans
& F_S
) != 0 );
4214 set3( (ans
& F_3
) != 0 );
4215 set5( (ans
& F_5
) != 0 );
4224 /** Add with carry - (NOT CHECKED) */
4225 private final int adc16( int a
, int b
) {
4226 int c
= Cset() ?
1 : 0;
4227 int lans
= a
+ b
+ c
;
4228 int ans
= lans
& 0xffff;
4230 setS( (ans
& (F_S
<<8)) != 0 );
4231 set3( (ans
& (F_3
<<8)) != 0 );
4232 set5( (ans
& (F_5
<<8)) != 0 );
4234 setC( (lans
& 0x10000)!=0 );
4235 setPV( ((a ^ ~b
) & (a ^ ans
) & 0x8000)!=0 );
4236 setH( (((a
& 0x0fff) + (b
& 0x0fff) + c
) & 0x1000)!=0 );
4242 /** Add - (NOT CHECKED) */
4243 private final int add16( int a
, int b
) {
4245 int ans
= lans
& 0xffff;
4247 set3( (ans
& (F_3
<<8)) != 0 );
4248 set5( (ans
& (F_5
<<8)) != 0 );
4249 setC( (lans
& 0x10000)!=0 );
4250 setH( (((a
& 0x0fff) + (b
& 0x0fff)) & 0x1000)!=0 );
4256 /** Add with carry - (NOT CHECKED) */
4257 private final int sbc16( int a
, int b
) {
4258 int c
= Cset() ?
1 : 0;
4259 int lans
= a
- b
- c
;
4260 int ans
= lans
& 0xffff;
4262 setS( (ans
& (F_S
<<8)) != 0 );
4263 set3( (ans
& (F_3
<<8)) != 0 );
4264 set5( (ans
& (F_5
<<8)) != 0 );
4266 setC( (lans
& 0x10000)!=0 );
4267 setPV( ((a ^ b
) & (a ^ ans
) & 0x8000)!=0 );
4268 setH( (((a
& 0x0fff) - (b
& 0x0fff) - c
) & 0x1000)!=0 );
4275 public final void exx() {
4292 public final void ex_af_af() {
4294 t
= AF(); AF( _AF_
); _AF_
= t
;
4297 /** Quick Increment : no flags */
4298 private static final int inc16( int a
) { return (a
+ 1) & 0xffff; }
4299 private static final int qinc8( int a
) { return (a
+ 1) & 0xff; }
4301 /** Quick Decrement : no flags */
4302 private static final int dec16( int a
) { return (a
- 1) & 0xffff; }
4303 private static final int qdec8( int a
) { return (a
- 1) & 0xff; }
4306 private static final int res( int bit
, int val
) { return val
& ~bit
; }
4307 private static final int set( int bit
, int val
) { return val
| bit
; }