struct / union in initializer, RFE #901.
[sdcc.git] / sdcc-extra / emu / rose / Z80.java
bloba8d2548466ed8f1d25b7a6d92119aca4cfd4f528
2 /*
3 * @(#)Z80.java 1.1 27/04/97 Adam Davidson & Andrew Pollard
4 */
6 /**
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>
12 * @see Jasper
13 * @see Spectrum
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];
41 static {
42 for ( int i = 0; i < 256; i++ ) {
43 boolean p = true;
44 for ( int j = 0; j < 8; j++ ) {
45 if ( (i & (1<<j)) != 0 ) {
46 p = !p;
49 parity[ i ] = p;
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";
78 if (addr==0) {
79 pushedPC = 0;
81 if (addr!=0x5aa) {
82 System.out.println(spaces.substring(0, 2*pushedPC) + "logCall: calling " + name);
84 else {
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));
87 pushedPC++;
89 }*/
90 void logCall(int addr) { };
91 void logJump(int addr) { };
93 final static String spaces = " ";
94 int pushedPC = 0;
97 private void logJump(int addr) {
98 if (addr==0) {
99 pushedPC = 0;
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;
127 /** Memory */
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 ) {
133 A( word >> 8 );
134 F( word & 0xff );
137 public final int BC() { return (B() << 8) | C(); }
138 public final void BC( int word ) {
139 B( word >> 8 );
140 C( word & 0xff );
143 public final int DE() { return _DE; }
144 public final void DE( int word ) {
145 _DE = word;
148 public final int HL() { return _HL; }
149 public final void HL( int word ) {
150 _HL = word;
153 public final int PC() { return _PC; }
154 public final void PC( int word ) {
155 _PC = word;
158 public final int SP() { return _SP; }
159 public final void SP( int word ) {
160 _SP = word;
163 public final int ID() { return _ID; }
164 public final void ID( int word ) {
165 _ID = word;
168 public final int IX() { return _IX; }
169 public final void IX( int word ) {
170 _IX = word;
173 public final int IY() { return _IY; }
174 public final void IY( int word ) {
175 _IY = word;
179 /** 8 bit register access */
180 public final int A() { return _A; }
181 public final void A( int bite ) {
182 _A = bite;
185 public final int F() {
186 return (Sset() ? F_S : 0) |
187 (Zset() ? F_Z : 0) |
188 (f5 ? F_5 : 0) |
189 (Hset() ? F_H : 0) |
190 (f3 ? F_3 : 0) |
191 (PVset() ? F_PV : 0) |
192 (Nset() ? F_N : 0) |
193 (Cset() ? F_C : 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 ) {
209 _B = bite;
211 public final int C() { return _C; }
212 public final void C( int bite ) {
213 _C = 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 ) {
248 _R = bite;
249 _R7 = bite & 0x80;
252 public final void REFRESH( int t ) {
253 _R += t;
257 /** Interrupt modes/register */
258 public final int I() { return _I; }
259 public final void I( int bite ) {
260 _I = bite;
263 public final boolean IFF1() { return _IFF1; }
264 public final void IFF1( boolean iff1 ) {
265 _IFF1 = iff1;
268 public final boolean IFF2() { return _IFF2; }
269 public final void IFF2( boolean iff2 ) {
270 _IFF2 = iff2;
273 public final int IM() { return _IM; }
274 public final void IM( int im ) {
275 _IM = im;
279 /** Flag access */
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; }
297 /** Byte access */
298 public int peekb( int addr ) {
299 return mem[ addr ];
301 public void pokeb( int addr, int newByte ) {
302 mem[ addr ] = newByte;
306 /** Word access */
307 public void pokew( int addr, int word ) {
308 pokeb( addr, word & 0xff );
309 addr++;
310 pokeb( addr & 0xffff, word >> 8 );
312 public int peekw( int addr ) {
313 int t = peekb( addr );
314 addr++;
315 return t | (peekb( addr & 0xffff ) << 8);
319 /** Index register access */
320 private final int ID_d() {
321 return ((ID()+(byte)nxtpcb()) & 0xffff);
325 /** Stack access */
326 public final void pushw( int word ) {
327 int sp = ((SP()-2) & 0xffff);
328 SP( sp );
329 pokew( sp, word );
331 public final int popw() {
332 int sp = SP();
333 int t = peekb( sp );
334 sp++;
335 t |= (peekb( sp & 0xffff) << 8);
336 SP( ++sp & 0xffff );
337 return t;
341 /** Call stack */
342 public final void pushpc() { pushw( PC() ); }
343 public final void poppc() { PC( popw() ); }
346 /** Program access */
347 private final int nxtpcb() {
348 int pc = PC();
349 int t = peekb( pc );
350 PC( ++pc & 0xffff );
351 return t;
353 private final int nxtpcw() {
354 int pc = PC();
355 int t = peekb( pc );
356 t |= ( peekb( ++pc & 0xffff ) << 8 );
357 PC( ++pc & 0xffff );
358 return t;
362 /** Reset all registers to power on state */
363 public void reset() {
364 PC( 0 );
365 SP( 0 );
367 A( 0 );
368 F( 0 );
369 BC( 0 );
370 DE( 0 );
371 HL( 0 );
373 exx();
374 ex_af_af();
376 A( 0 );
377 F( 0 );
378 BC( 0 );
379 DE( 0 );
380 HL( 0 );
382 IX( 0 );
383 IY( 0 );
385 R( 0 );
387 I( 0 );
388 IFF1( false );
389 IFF2( false );
390 IM( IM0 );
394 /** IO ports */
395 public void outb( int port, int bite, int tstates ) {
397 public int inb( int port ) {
398 return 0xff;
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
408 if ( !IFF1() ) {
409 return 0;
411 switch( IM() ) {
412 case IM0:
413 case IM1:
414 pushpc();
415 IFF1( false );
416 IFF2( false );
417 logCall(56);
418 PC( 56 );
419 return 13;
420 case IM2:
421 pushpc();
422 IFF1( false );
423 IFF2( false );
424 int t = (I()<<8) | 0x00ff;
425 logCall(peekw(t));
426 PC( peekw(t) );
427 return 19;
430 return 0;
434 /** Z80 fetch/execute loop */
435 public final void execute() {
436 int local_tstates = -tstatesPerInterrupt;
437 while ( true ) {
439 if ( interruptTriggered( local_tstates ) ) {
440 local_tstates -= tstatesPerInterrupt - interrupt();
443 REFRESH( 1 );
444 if (false) {
445 System.out.println(" PC: " + Integer.toString(PC(), 16) +
446 " HL: " + Integer.toString(HL(), 16) +
447 " DE: " + Integer.toString(DE(), 16) +
448 "");
451 switch ( nxtpcb() ) {
453 case 0: /* NOP */
455 local_tstates += ( 4 );
456 break;
458 case 8: /* EX AF,AF' */
460 ex_af_af();
461 local_tstates += ( 4 );
462 break;
464 case 16: /* DJNZ dis */
466 int b;
468 B( b = qdec8( B() ) );
469 if (b != 0) {
470 byte d = (byte) nxtpcb();
471 PC( (PC()+d)&0xffff );
472 local_tstates += ( 13 );
474 else {
475 PC( inc16( PC() ) );
476 local_tstates += ( 8 );
478 break;
480 case 24: /* JR dis */
482 byte d = (byte)nxtpcb();
483 PC( (PC()+d)&0xffff );
484 local_tstates += ( 12 );
485 break;
487 /* JR cc,dis */
488 case 32: /* JR NZ,dis */
490 if (!Zset()) {
491 byte d = (byte)nxtpcb();
492 PC( (PC()+d)&0xffff );
493 local_tstates += ( 12 );
495 else {
496 PC( inc16( PC() ) );
497 local_tstates += ( 7 );
499 break;
501 case 40: /* JR Z,dis */
503 if ( Zset()) {
504 byte d = (byte)nxtpcb();
505 PC( (PC()+d)&0xffff );
506 local_tstates += ( 12 );
508 else {
509 PC( inc16( PC() ) );
510 local_tstates += ( 7 );
512 break;
514 case 48: /* JR NC,dis */
516 if (!Cset()) {
517 byte d = (byte)nxtpcb();
518 PC( (PC()+d)&0xffff );
519 local_tstates += ( 12 );
521 else {
522 PC( inc16( PC() ) );
523 local_tstates += ( 7 );
525 break;
527 case 56: /* JR C,dis */
529 if ( Cset()) {
530 byte d = (byte)nxtpcb();
531 PC( (PC()+d)&0xffff );
532 local_tstates += ( 12 );
534 else {
535 PC( inc16( PC() ) );
536 local_tstates += ( 7 );
538 break;
541 /* LD rr,nn / ADD HL,rr */
542 case 1: /* LD BC(),nn */
544 BC( nxtpcw() );
545 local_tstates += ( 10 );
546 break;
548 case 9: /* ADD HL,BC */
550 HL( add16( HL(), BC() ) );
551 local_tstates += ( 11 );
552 break;
554 case 17: /* LD DE,nn */
556 DE( nxtpcw() );
557 local_tstates += ( 10 );
558 break;
560 case 25: /* ADD HL,DE */
562 HL( add16( HL(), DE() ) );
563 local_tstates += ( 11 );
564 break;
566 case 33: /* LD HL,nn */
568 HL( nxtpcw() );
569 local_tstates += ( 10 );
570 break;
572 case 41: /* ADD HL,HL */
574 int hl = HL();
575 HL( add16( hl, hl ) );
576 local_tstates += ( 11 );
577 break;
579 case 49: /* LD SP,nn */
581 SP( nxtpcw() );
582 local_tstates += ( 10 );
583 break;
585 case 57: /* ADD HL,SP */
587 HL( add16( HL(), SP() ) );
588 local_tstates += ( 11 );
589 break;
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; }
610 /* INC/DEC * */
611 case 3: /* INC BC */
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; }
628 /* INC * */
629 case 4: /* INC B */
630 { B( inc8( B() ) ); local_tstates += ( 4 ); break; }
631 case 12: /* INC C */
632 { C( inc8( C() ) ); local_tstates += ( 4 ); break; }
633 case 20: /* INC D */
634 { D( inc8( D() ) ); local_tstates += ( 4 ); break; }
635 case 28: /* INC E */
636 { E( inc8( E() ) ); local_tstates += ( 4 ); break; }
637 case 36: /* INC H */
638 { H( inc8( H() ) ); local_tstates += ( 4 ); break; }
639 case 44: /* INC L */
640 { L( inc8( L() ) ); local_tstates += ( 4 ); break; }
641 case 52: /* INC (HL) */
643 int hl = HL();
644 pokeb( hl, inc8( peekb( hl ) ) );
645 local_tstates += ( 11 );
646 break;
648 case 60: /* INC A() */
649 { A( inc8( A() ) ); local_tstates += ( 4 ); break; }
651 /* DEC * */
652 case 5: /* DEC B */
653 { B( dec8( B() ) ); local_tstates += ( 4 ); break; }
654 case 13: /* DEC C */
655 { C( dec8( C() ) ); local_tstates += ( 4 ); break; }
656 case 21: /* DEC D */
657 { D( dec8( D() ) ); local_tstates += ( 4 ); break; }
658 case 29: /* DEC E */
659 { E( dec8( E() ) ); local_tstates += ( 4 ); break; }
660 case 37: /* DEC H */
661 { H( dec8( H() ) ); local_tstates += ( 4 ); break; }
662 case 45: /* DEC L */
663 { L( dec8( L() ) ); local_tstates += ( 4 ); break; }
664 case 53: /* DEC (HL) */
666 int hl = HL();
667 pokeb( hl, dec8( peekb( hl ) ) );
668 local_tstates += ( 11 );
669 break;
671 case 61: /* DEC A() */
672 { A( dec8( A() ) ); local_tstates += ( 4 ); break; }
674 /* LD *,N */
675 case 6: /* LD B,n */
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 );
691 break;
693 case 62: /* LD A,n */
694 { A( nxtpcb() ); local_tstates += ( 7 ); break; }
696 /* R**A */
697 case 7: /* RLCA */
698 { rlc_a(); local_tstates += ( 4 ); break; }
699 case 15: /* RRCA */
700 { rrc_a(); local_tstates += ( 4 ); break; }
701 case 23: /* RLA */
702 { rl_a(); local_tstates += ( 4 ); break; }
703 case 31: /* RRA */
704 { rr_a(); local_tstates += ( 4 ); break; }
705 case 39: /* DAA */
706 { daa_a(); local_tstates += ( 4 ); break; }
707 case 47: /* CPL */
708 { cpl_a(); local_tstates += ( 4 ); break; }
709 case 55: /* SCF */
710 { scf(); local_tstates += ( 4 ); break; }
711 case 63: /* CCF */
712 { ccf(); local_tstates += ( 4 ); break; }
714 /* LD B,* */
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; }
732 /* LD C,* */
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; }
750 /* LD D,* */
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; }
768 /* LD E,* */
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; }
786 /* LD H,* */
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; }
804 /* LD L,* */
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; }
822 /* LD (HL),* */
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; }
835 case 118: /* HALT */
837 int haltsToInterrupt = (((-local_tstates-1) / 4)+1);
838 local_tstates += (haltsToInterrupt*4);
839 REFRESH( haltsToInterrupt-1 );
840 break;
842 case 119: /* LD (HL),A */
843 { pokeb( HL(), A() ); local_tstates += ( 7 ); break; }
845 /* LD A,* */
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; }
863 /* ADD A,* */
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; }
881 /* ADC A,* */
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; }
899 /* SUB * */
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; }
917 /* SBC A,* */
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; }
935 /* AND * */
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; }
953 /* XOR * */
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; }
971 /* OR * */
972 case 176: /* OR B */
973 { or_a( B() ); local_tstates += ( 4 ); break; }
974 case 177: /* OR C */
975 { or_a( C() ); local_tstates += ( 4 ); break; }
976 case 178: /* OR D */
977 { or_a( D() ); local_tstates += ( 4 ); break; }
978 case 179: /* OR E */
979 { or_a( E() ); local_tstates += ( 4 ); break; }
980 case 180: /* OR H */
981 { or_a( H() ); local_tstates += ( 4 ); break; }
982 case 181: /* OR L */
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; }
989 /* CP * */
990 case 184: /* CP B */
991 { cp_a( B() ); local_tstates += ( 4 ); break; }
992 case 185: /* CP C */
993 { cp_a( C() ); local_tstates += ( 4 ); break; }
994 case 186: /* CP D */
995 { cp_a( D() ); local_tstates += ( 4 ); break; }
996 case 187: /* CP E */
997 { cp_a( E() ); local_tstates += ( 4 ); break; }
998 case 188: /* CP H */
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; }
1007 /* RET cc */
1008 case 192: /* RET NZ */
1010 if(!Zset()) {
1011 poppc();
1012 local_tstates += ( 11 );
1014 else {
1015 local_tstates += ( 5 );
1017 break;
1019 case 200: /* RET Z */
1021 if(Zset()) {
1022 poppc();
1023 local_tstates += ( 11 );
1025 else {
1026 local_tstates += ( 5 );
1028 break;
1030 case 208: /* RET NC */
1032 if(!Cset()) {
1033 poppc();
1034 local_tstates += ( 11 );
1036 else {
1037 local_tstates += ( 5 );
1039 break;
1041 case 216: /* RET C */
1043 if(Cset()) {
1044 poppc();
1045 local_tstates += ( 11 );
1047 else {
1048 local_tstates += ( 5 );
1050 break;
1052 case 224: /* RET PO */
1054 if(!PVset()) {
1055 poppc();
1056 local_tstates += ( 11 );
1058 else {
1059 local_tstates += ( 5 );
1061 break;
1063 case 232: /* RET PE */
1065 if(PVset()) {
1066 poppc();
1067 local_tstates += ( 11 );
1069 else {
1070 local_tstates += ( 5 );
1072 break;
1074 case 240: /* RET P */
1076 if(!Sset()) {
1077 poppc();
1078 local_tstates += ( 11 );
1080 else {
1081 local_tstates += ( 5 );
1083 break;
1085 case 248: /* RET M */
1087 if(Sset()) {
1088 poppc();
1089 local_tstates += ( 11 );
1091 else {
1092 local_tstates += ( 5 );
1094 break;
1097 /* POP,Various */
1098 case 193: /* POP BC */
1099 { BC( popw() ); local_tstates += ( 10 ); break; }
1100 case 201: /* RET */
1101 { poppc(); local_tstates += ( 10 ); break; }
1102 case 209: /* POP DE */
1103 { DE( popw() ); local_tstates += ( 10 ); break; }
1104 case 217: /* EXX */
1106 exx();
1107 local_tstates += ( 4 );
1108 break;
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; }
1119 /* JP cc,nn */
1120 case 194: /* JP NZ,nn */
1122 if(!Zset()) {
1123 PC( nxtpcw() );
1125 else {
1126 PC( (PC()+2)&0xffff );
1128 local_tstates += ( 10 );
1129 break;
1131 case 202: /* JP Z,nn */
1133 if( Zset()) {
1134 PC( nxtpcw() );
1136 else {
1137 PC( (PC()+2)&0xffff );
1139 local_tstates += ( 10 );
1140 break;
1142 case 210: /* JP NC,nn */
1144 if(!Cset()) {
1145 PC( nxtpcw() );
1147 else {
1148 PC( (PC()+2)&0xffff );
1150 local_tstates += ( 10 );
1151 break;
1153 case 218: /* JP C,nn */
1155 if( Cset()) {
1156 PC( nxtpcw() );
1158 else {
1159 PC( (PC()+2)&0xffff );
1161 local_tstates += ( 10 );
1162 break;
1164 case 226: /* JP PO,nn */
1166 if(!PVset()) {
1167 PC( nxtpcw() );
1169 else {
1170 PC( (PC()+2)&0xffff );
1172 local_tstates += ( 10 );
1173 break;
1175 case 234: /* JP PE,nn */
1177 if( PVset()) {
1178 PC( nxtpcw() );
1180 else {
1181 PC( (PC()+2)&0xffff );
1183 local_tstates += ( 10 );
1184 break;
1186 case 242: /* JP P,nn */
1188 if(!Sset()) {
1189 PC( nxtpcw() );
1191 else {
1192 PC( (PC()+2)&0xffff );
1194 local_tstates += ( 10 );
1195 break;
1197 case 250: /* JP M,nn */
1199 if( Sset()) {
1200 PC( nxtpcw() );
1202 else {
1203 PC( (PC()+2)&0xffff );
1205 local_tstates += ( 10 );
1206 break;
1210 /* Various */
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 );
1219 break;
1221 case 219: /* IN A,(n) */
1223 A( inb((A() << 8) | nxtpcb()) );
1224 local_tstates += ( 11 );
1225 break;
1227 case 227: /* EX (SP),HL */
1229 int t = HL();
1230 int sp = SP();
1231 HL( peekw( sp ) );
1232 pokew( sp, t );
1233 local_tstates += ( 19 );
1234 break;
1236 case 235: /* EX DE,HL */
1238 int t = HL();
1239 HL( DE() );
1240 DE( t );
1241 local_tstates += ( 4 );
1242 break;
1244 case 243: /* DI */
1246 IFF1( false );
1247 IFF2( false );
1248 local_tstates += ( 4 );
1249 break;
1251 case 251: /* EI */
1253 IFF1( true );
1254 IFF2( true );
1255 local_tstates += ( 4 );
1256 break;
1259 /* CALL cc,nn */
1260 case 196: /* CALL NZ,nn */
1262 if( !Zset() ) {
1263 int t = nxtpcw();
1264 pushpc();
1265 logCall(t);
1266 PC( t );
1267 local_tstates += ( 17 );
1269 else {
1270 PC( (PC() + 2)&0xffff );
1271 local_tstates += ( 10 );
1273 break;
1275 case 204: /* CALL Z,nn */
1277 if( Zset() ) {
1278 int t = nxtpcw();
1279 pushpc();
1280 logCall(t);
1281 PC( t );
1282 local_tstates += ( 17 );
1284 else {
1285 PC( (PC() + 2)&0xffff );
1286 local_tstates += ( 10 );
1288 break;
1290 case 212: /* CALL NC,nn */
1292 if( !Cset() ) {
1293 int t = nxtpcw();
1294 pushpc();
1295 logCall(t);
1296 PC( t );
1297 local_tstates += ( 17 );
1299 else {
1300 PC( (PC() + 2)&0xffff );
1301 local_tstates += ( 10 );
1303 break;
1305 case 220: /* CALL C,nn */
1307 if( Cset() ) {
1308 int t = nxtpcw();
1309 pushpc();
1310 logCall(t);
1311 PC( t );
1312 local_tstates += ( 17 );
1314 else {
1315 PC( (PC() + 2)&0xffff );
1316 local_tstates += ( 10 );
1318 break;
1320 case 228: /* CALL PO,nn */
1322 if( !PVset() ) {
1323 int t = nxtpcw();
1324 pushpc();
1325 logCall(t);
1326 PC( t );
1327 local_tstates += ( 17 );
1329 else {
1330 PC( (PC() + 2)&0xffff );
1331 local_tstates += ( 10 );
1333 break;
1335 case 236: /* CALL PE,nn */
1337 if( PVset() ) {
1338 int t = nxtpcw();
1339 pushpc();
1340 logCall(t);
1341 PC( t );
1342 local_tstates += ( 17 );
1344 else {
1345 PC( (PC() + 2)&0xffff );
1346 local_tstates += ( 10 );
1348 break;
1350 case 244: /* CALL P,nn */
1352 if( !Sset() ) {
1353 int t = nxtpcw();
1354 pushpc();
1355 logCall(t);
1356 PC( t );
1357 local_tstates += ( 17 );
1359 else {
1360 PC( (PC() + 2)&0xffff );
1361 local_tstates += ( 10 );
1363 break;
1365 case 252: /* CALL M,nn */
1367 if( Sset() ) {
1368 int t = nxtpcw();
1369 pushpc();
1370 logCall(t);
1371 PC( t );
1372 local_tstates += ( 17 );
1374 else {
1375 PC( (PC() + 2)&0xffff );
1376 local_tstates += ( 10 );
1378 break;
1381 /* PUSH,Various */
1382 case 197: /* PUSH BC */
1383 { pushw( BC() ); local_tstates += ( 11 ); break; }
1384 case 205: /* CALL nn */
1386 int t = nxtpcw();
1387 pushpc();
1388 logCall(t);
1389 PC( t );
1390 local_tstates += ( 17 );
1391 break;
1393 case 213: /* PUSH DE */
1394 { pushw( DE() ); local_tstates += ( 11 ); break; }
1395 case 221: /* prefix IX */
1397 ID( IX() );
1398 local_tstates += execute_id();
1399 IX( ID() );
1400 break;
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 */
1410 ID( IY() );
1411 local_tstates += execute_id();
1412 IY( ID() );
1413 break;
1416 /* op A,N */
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; }
1434 /* RST n */
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; }
1453 } // end while
1456 int rst(int rstNum) {
1457 pushpc();
1458 logCall(rstNum);
1459 PC(rstNum);
1460 return 11;
1463 private final int execute_ed( int local_tstates ) {
1465 REFRESH( 1 );
1467 switch ( nxtpcb() ) {
1469 case 0: /* NOP */
1470 case 1:
1471 case 2:
1472 case 3:
1473 case 4:
1474 case 5:
1475 case 6:
1476 case 7:
1477 case 8:
1478 case 9:
1479 case 10:
1480 case 11:
1481 case 12:
1482 case 13:
1483 case 14:
1484 case 15:
1485 case 16:
1486 case 17:
1487 case 18:
1488 case 19:
1489 case 20:
1490 case 21:
1491 case 22:
1492 case 23:
1493 case 24:
1494 case 25:
1495 case 26:
1496 case 27:
1497 case 28:
1498 case 29:
1499 case 30:
1500 case 31:
1501 case 32:
1502 case 33:
1503 case 34:
1504 case 35:
1505 case 36:
1506 case 37:
1507 case 38:
1508 case 39:
1509 case 40:
1510 case 41:
1511 case 42:
1512 case 43:
1513 case 44:
1514 case 45:
1515 case 46:
1516 case 47:
1517 case 48:
1518 case 49:
1519 case 50:
1520 case 51:
1521 case 52:
1522 case 53:
1523 case 54:
1524 case 55:
1525 case 56:
1526 case 57:
1527 case 58:
1528 case 59:
1529 case 60:
1530 case 61:
1531 case 62:
1532 case 63:
1534 case 127:
1535 case 128:
1536 case 129:
1537 case 130:
1538 case 131:
1539 case 132:
1540 case 133:
1541 case 134:
1542 case 135:
1543 case 136:
1544 case 137:
1545 case 138:
1546 case 139:
1547 case 140:
1548 case 141:
1549 case 142:
1550 case 143:
1551 case 144:
1552 case 145:
1553 case 146:
1554 case 147:
1555 case 148:
1556 case 149:
1557 case 150:
1558 case 151:
1559 case 152:
1560 case 153:
1561 case 154:
1562 case 155:
1563 case 156:
1564 case 157:
1565 case 158:
1566 case 159:
1568 case 164:
1569 case 165:
1570 case 166:
1571 case 167:
1573 case 172:
1574 case 173:
1575 case 174:
1576 case 175:
1578 case 180:
1579 case 181:
1580 case 182:
1581 case 183:
1583 return ( 8 );
1586 /* IN r,(c) */
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 ); }
1604 /* OUT (c),r */
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 ); }
1622 /* SBC/ADC HL,ss */
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 */
1633 int hl = HL();
1634 HL( sbc16( hl, hl ) );
1635 return ( 15 );
1637 case 106: /* ADC HL,HL */
1639 int hl = HL();
1640 HL( adc16( hl, hl ) );
1641 return ( 15 );
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 ); }
1666 /* NEG */
1667 case 68: /* NEG */
1668 case 76: /* NEG */
1669 case 84: /* NEG */
1670 case 92: /* NEG */
1671 case 100: /* NEG */
1672 case 108: /* NEG */
1673 case 116: /* NEG */
1674 case 124: /* NEG */
1675 { neg_a(); return ( 8 ); }
1677 /* RETn */
1678 case 69: /* RETN */
1679 case 85: /* RETN */
1680 case 101: /* RETN */
1681 case 117: /* RETN */
1683 IFF1( IFF2() );
1684 poppc();
1685 return ( 14 );
1687 case 77: /* RETI */
1688 case 93: /* RETI */
1689 case 109: /* RETI */
1690 case 125: /* RETI */
1692 poppc();
1693 return ( 14 );
1696 /* IM x */
1697 case 70: /* IM 0 */
1698 case 78: /* IM 0 */
1699 case 102: /* IM 0 */
1700 case 110: /* IM 0 */
1701 { IM( IM0 ); return ( 8 ); }
1702 case 86: /* IM 1 */
1703 case 118: /* IM 1 */
1704 { IM( IM1 ); return ( 8 ); }
1705 case 94: /* IM 2 */
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 ); }
1718 case 103: /* RRD */
1719 { rrd_a(); return ( 18 ); }
1720 case 111: /* RLD */
1721 { rld_a(); return ( 18 ); }
1723 /* xxI */
1724 case 160: /* LDI */
1726 pokeb( DE(), peekb( HL() ) );
1727 DE( inc16( DE() ) );
1728 HL( inc16( HL() ) );
1729 BC( dec16( BC() ) );
1731 setPV( BC() != 0 );
1732 setH( false );
1733 setN( false );
1735 return ( 16 );
1737 case 161: /* CPI */
1739 boolean c = Cset();
1741 cp_a( peekb( HL() ) );
1742 HL( inc16( HL() ) );
1743 BC( dec16( BC() ) );
1745 setPV( BC() != 0 );
1746 setC( c );
1748 return ( 16 );
1750 case 162: /* INI */
1752 int b;
1753 pokeb( HL(), inb( BC() ) );
1754 B( b = qdec8( B() ) );
1755 HL( inc16( HL() ) );
1757 setZ( b == 0 );
1758 setN( true );
1760 return ( 16 );
1762 case 163: /* OUTI */
1764 int b;
1765 B( b = qdec8( B() ) );
1766 outb( BC(), peekb( HL() ), local_tstates );
1767 HL( inc16( HL() ) );
1769 setZ( b == 0 );
1770 setN( true );
1772 return ( 16 );
1775 /* xxD */
1776 case 168: /* LDD */
1778 pokeb( DE(), peekb( HL() ) );
1779 DE( dec16( DE() ) );
1780 HL( dec16( HL() ) );
1781 BC( dec16( BC() ) );
1783 setPV( BC() != 0 );
1784 setH( false );
1785 setN( false );
1787 return ( 16 );
1789 case 169: /* CPD */
1791 boolean c = Cset();
1793 cp_a( peekb( HL() ) );
1794 HL( dec16( HL() ) );
1795 BC( dec16( BC() ) );
1797 setPV( BC() != 0 );
1798 setC( c );
1800 return ( 16 );
1802 case 170: /* IND */
1804 int b;
1805 pokeb( HL(), inb( BC() ) );
1806 B( b = qdec8( B() ) );
1807 HL( dec16( HL() ) );
1809 setZ( b == 0 );
1810 setN( true );
1812 return ( 16 );
1814 case 171: /* OUTD */
1816 int b;
1817 B( b = qdec8( B() ) );
1818 outb( BC(), peekb( HL() ), local_tstates );
1819 HL( dec16( HL() ) );
1821 setZ( b == 0 );
1822 setN( true );
1824 return ( 16 );
1827 /* xxIR */
1828 case 176: /* LDIR */
1830 int _local_tstates = 0;
1831 int count, dest, from;
1833 count = BC();
1834 dest = DE();
1835 from = HL();
1836 REFRESH( -2 );
1837 do {
1838 pokeb(dest, peekb(from) );
1839 from = inc16( from );
1840 dest = inc16( dest );
1841 count = dec16( count );
1843 _local_tstates += ( 21 );
1844 REFRESH( 2 );
1845 if ( interruptTriggered( _local_tstates ) ) {
1846 break;
1848 } while (count != 0);
1849 if (count != 0) {
1850 PC( (PC()-2)&0xffff );
1851 setH( false );
1852 setN( false );
1853 setPV( true );
1855 else {
1856 _local_tstates += ( -5 );
1857 setH( false );
1858 setN( false );
1859 setPV( false );
1861 DE( dest );
1862 HL( from );
1863 BC( count );
1865 return ( _local_tstates );
1867 case 177: /* CPIR */
1869 boolean c = Cset();
1871 cp_a( peekb( HL() ) );
1872 HL( inc16( HL() ) );
1873 BC( dec16( BC() ) );
1875 boolean pv = (BC() != 0);
1877 setPV( pv );
1878 setC( c );
1879 if ( pv && !Zset() ) {
1880 PC( (PC()-2)&0xffff );
1881 return ( 21 );
1883 return ( 16 );
1885 case 178: /* INIR */
1887 int b;
1888 pokeb( HL(), inb( BC() ) );
1889 B( b = qdec8( B() ) );
1890 HL( inc16( HL() ) );
1892 setZ( true );
1893 setN( true );
1894 if (b != 0) {
1895 PC( (PC()-2)&0xffff );
1896 return ( 21 );
1898 return ( 16 );
1900 case 179: /* OTIR */
1902 int b;
1903 B( b = qdec8( B() ) );
1904 outb( BC(), peekb( HL() ), local_tstates );
1905 HL( inc16( HL() ) );
1907 setZ( true );
1908 setN( true );
1909 if (b != 0) {
1910 PC( (PC()-2)&0xffff );
1911 return ( 21 );
1913 return ( 16 );
1916 /* xxDR */
1917 case 184: /* LDDR */
1919 int _local_tstates = 0;
1920 int count, dest, from;
1922 count = BC();
1923 dest = DE();
1924 from = HL();
1925 REFRESH ( -2 );
1926 do {
1927 pokeb(dest, peekb(from));
1928 from = dec16( from );
1929 dest = dec16( dest );
1930 count = dec16( count );
1932 _local_tstates += ( 21 );
1933 REFRESH( 2 );
1934 if ( interruptTriggered( _local_tstates ) ) {
1935 break;
1937 } while (count != 0);
1938 if (count != 0) {
1939 PC( (PC()-2)&0xffff );
1940 setH( false );
1941 setN( false );
1942 setPV( true );
1944 else {
1945 _local_tstates += ( -5 );
1946 setH( false );
1947 setN( false );
1948 setPV( false );
1950 DE( dest );
1951 HL( from );
1952 BC( count );
1954 return ( _local_tstates );
1956 case 185: /* CPDR */
1958 boolean c = Cset();
1960 cp_a( peekb( HL() ) );
1961 HL( dec16( HL() ) );
1962 BC( dec16( BC() ) );
1964 boolean pv = (BC() != 0);
1966 setPV( pv );
1967 setC( c );
1968 if ( pv && !Zset() ) {
1969 PC( (PC()-2)&0xffff );
1970 return ( 21 );
1972 return ( 16 );
1974 case 186: /* INDR */
1976 int b;
1977 pokeb( HL(), inb( BC() ) );
1978 B( b = qdec8( B() ) );
1979 HL( dec16( HL() ) );
1981 setZ( true );
1982 setN( true );
1983 if (b != 0) {
1984 PC( (PC()-2)&0xffff );
1985 return ( 21 );
1987 return ( 16 );
1989 case 187: /* OTDR */
1991 int b;
1992 B( b = qdec8( B() ) );
1993 outb( BC(), peekb( HL() ), local_tstates );
1994 HL( dec16( HL() ) );
1996 setZ( true );
1997 setN( true );
1998 if (b != 0) {
1999 PC( (PC()-2)&0xffff );
2000 return ( 21 );
2002 return ( 16 );
2005 } // end switch
2007 // NOP
2008 return ( 8 );
2011 private final int execute_cb() {
2012 REFRESH( 1 );
2014 switch ( nxtpcb() ) {
2016 case 0: /* RLC B */
2017 { B( rlc( B() ) ); return ( 8 ); }
2018 case 1: /* RLC C */
2019 { C( rlc( C() ) ); return ( 8 ); }
2020 case 2: /* RLC D */
2021 { D( rlc( D() ) ); return ( 8 ); }
2022 case 3: /* RLC E */
2023 { E( rlc( E() ) ); return ( 8 ); }
2024 case 4: /* RLC H */
2025 { H( rlc( H() ) ); return ( 8 ); }
2026 case 5: /* RLC L */
2027 { L( rlc( L() ) ); return ( 8 ); }
2028 case 6: /* RLC (HL) */
2030 int hl = HL();
2031 pokeb( hl, rlc( peekb( hl ) ) );
2032 return ( 15 );
2034 case 7: /* RLC A */
2035 { A( rlc( A() ) ); return ( 8 ); }
2037 case 8: /* RRC B */
2038 { B( rrc( B() ) ); return ( 8 ); }
2039 case 9: /* RRC C */
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) */
2051 int hl = HL();
2052 pokeb( hl, rrc( peekb( hl ) ) );
2053 return ( 15 );
2055 case 15: /* RRC A */
2056 { A( rrc( A() ) ); return ( 8 ); }
2058 case 16: /* RL B */
2059 { B( rl( B() ) ); return ( 8 ); }
2060 case 17: /* RL C */
2061 { C( rl( C() ) ); return ( 8 ); }
2062 case 18: /* RL D */
2063 { D( rl( D() ) ); return ( 8 ); }
2064 case 19: /* RL E */
2065 { E( rl( E() ) ); return ( 8 ); }
2066 case 20: /* RL H */
2067 { H( rl( H() ) ); return ( 8 ); }
2068 case 21: /* RL L */
2069 { L( rl( L() ) ); return ( 8 ); }
2070 case 22: /* RL (HL) */
2072 int hl = HL();
2073 pokeb( hl, rl( peekb( hl ) ) );
2074 return ( 15 );
2076 case 23: /* RL A */
2077 { A( rl( A() ) ); return ( 8 ); }
2079 case 24: /* RR B */
2080 { B( rr( B() ) ); return ( 8 ); }
2081 case 25: /* RR C */
2082 { C( rr( C() ) ); return ( 8 ); }
2083 case 26: /* RR D */
2084 { D( rr( D() ) ); return ( 8 ); }
2085 case 27: /* RR E */
2086 { E( rr( E() ) ); return ( 8 ); }
2087 case 28: /* RR H */
2088 { H( rr( H() ) ); return ( 8 ); }
2089 case 29: /* RR L */
2090 { L( rr( L() ) ); return ( 8 ); }
2091 case 30: /* RR (HL) */
2093 int hl = HL();
2094 pokeb( hl, rr( peekb( hl ) ) );
2095 return ( 15 );
2097 case 31: /* RR A */
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) */
2114 int hl = HL();
2115 pokeb( hl, sla( peekb( hl ) ) );
2116 return ( 15 );
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) */
2135 int hl = HL();
2136 pokeb( hl, sra( peekb( hl ) ) );
2137 return ( 15 );
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) */
2156 int hl = HL();
2157 pokeb( hl, sls( peekb( hl ) ) );
2158 return ( 15 );
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) */
2177 int hl = HL();
2178 pokeb( hl, srl( peekb( hl ) ) );
2179 return ( 15 );
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) */
2334 int hl = HL();
2335 pokeb( hl, res( 0x01, peekb( hl ) ) );
2336 return ( 15 );
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) */
2355 int hl = HL();
2356 pokeb( hl, res( 0x02, peekb( hl ) ) );
2357 return ( 15 );
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) */
2376 int hl = HL();
2377 pokeb( hl, res( 0x04, peekb( hl ) ) );
2378 return ( 15 );
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) */
2397 int hl = HL();
2398 pokeb( hl, res( 0x08, peekb( hl ) ) );
2399 return ( 15 );
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) */
2418 int hl = HL();
2419 pokeb( hl, res( 0x10, peekb( hl ) ) );
2420 return ( 15 );
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) */
2439 int hl = HL();
2440 pokeb( hl, res( 0x20, peekb( hl ) ) );
2441 return ( 15 );
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) */
2460 int hl = HL();
2461 pokeb( hl, res( 0x40, peekb( hl ) ) );
2462 return ( 15 );
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) */
2481 int hl = HL();
2482 pokeb( hl, res( 0x80, peekb( hl ) ) );
2483 return ( 15 );
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) */
2502 int hl = HL();
2503 pokeb( hl, set( 0x01, peekb( hl ) ) );
2504 return ( 15 );
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) */
2523 int hl = HL();
2524 pokeb( hl, set( 0x02, peekb( hl ) ) );
2525 return ( 15 );
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) */
2544 int hl = HL();
2545 pokeb( hl, set( 0x04, peekb( hl ) ) );
2546 return ( 15 );
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) */
2565 int hl = HL();
2566 pokeb( hl, set( 0x08, peekb( hl ) ) );
2567 return ( 15 );
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) */
2586 int hl = HL();
2587 pokeb( hl, set( 0x10, peekb( hl ) ) );
2588 return ( 15 );
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) */
2607 int hl = HL();
2608 pokeb( hl, set( 0x20, peekb( hl ) ) );
2609 return ( 15 );
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) */
2628 int hl = HL();
2629 pokeb( hl, set( 0x40, peekb( hl ) ) );
2630 return ( 15 );
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) */
2649 int hl = HL();
2650 pokeb( hl, set( 0x80, peekb( hl ) ) );
2651 return ( 15 );
2653 case 255: /* SET 7,A */
2654 { A( set( 0x80, A() ) ); return ( 8 ); }
2656 } // end switch
2658 return 0;
2661 private final int execute_id() {
2663 REFRESH( 1 );
2665 switch ( nxtpcb() ) {
2667 case 0: /* NOP */
2668 case 1:
2669 case 2:
2670 case 3:
2671 case 4:
2672 case 5:
2673 case 6:
2674 case 7:
2675 case 8:
2677 case 10:
2678 case 11:
2679 case 12:
2680 case 13:
2681 case 14:
2682 case 15:
2683 case 16:
2684 case 17:
2685 case 18:
2686 case 19:
2687 case 20:
2688 case 21:
2689 case 22:
2690 case 23:
2691 case 24:
2693 case 26:
2694 case 27:
2695 case 28:
2696 case 29:
2697 case 30:
2698 case 31:
2699 case 32:
2701 case 39:
2702 case 40:
2704 case 47:
2705 case 48:
2706 case 49:
2707 case 50:
2708 case 51:
2710 case 55:
2711 case 56:
2713 case 58:
2714 case 59:
2715 case 60:
2716 case 61:
2717 case 62:
2718 case 63:
2719 case 64:
2720 case 65:
2721 case 66:
2722 case 67:
2724 case 71:
2725 case 72:
2726 case 73:
2727 case 74:
2728 case 75:
2730 case 79:
2731 case 80:
2732 case 81:
2733 case 82:
2734 case 83:
2736 case 87:
2737 case 88:
2738 case 89:
2739 case 90:
2740 case 91:
2742 case 95:
2744 case 120:
2745 case 121:
2746 case 122:
2747 case 123:
2749 case 127:
2750 case 128:
2751 case 129:
2752 case 130:
2753 case 131:
2755 case 135:
2756 case 136:
2757 case 137:
2758 case 138:
2759 case 139:
2761 case 143:
2762 case 144:
2763 case 145:
2764 case 146:
2765 case 147:
2767 case 151:
2768 case 152:
2769 case 153:
2770 case 154:
2771 case 155:
2773 case 159:
2774 case 160:
2775 case 161:
2776 case 162:
2777 case 163:
2779 case 167:
2780 case 168:
2781 case 169:
2782 case 170:
2783 case 171:
2785 case 175:
2786 case 176:
2787 case 177:
2788 case 178:
2789 case 179:
2791 case 183:
2792 case 184:
2793 case 185:
2794 case 186:
2795 case 187:
2797 case 191:
2798 case 192:
2799 case 193:
2800 case 194:
2801 case 195:
2802 case 196:
2803 case 197:
2804 case 198:
2805 case 199:
2806 case 200:
2807 case 201:
2808 case 202:
2810 case 204:
2811 case 205:
2812 case 206:
2813 case 207:
2814 case 208:
2815 case 209:
2816 case 210:
2817 case 211:
2818 case 212:
2819 case 213:
2820 case 214:
2821 case 215:
2822 case 216:
2823 case 217:
2824 case 218:
2825 case 219:
2826 case 220:
2827 case 221:
2828 case 222:
2829 case 223:
2830 case 224:
2832 case 226:
2834 case 228:
2836 case 230:
2837 case 231:
2838 case 232:
2840 case 234:
2841 case 235:
2842 case 236:
2843 case 237:
2844 case 238:
2845 case 239:
2846 case 240:
2847 case 241:
2848 case 242:
2849 case 243:
2850 case 244:
2851 case 245:
2852 case 246:
2853 case 247:
2854 case 248:
2856 PC( dec16( PC() ) );
2857 REFRESH( -1 );
2858 return ( 4 );
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 */
2867 int id = ID();
2868 ID( add16( id, id ) );
2869 return ( 15 );
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) */
2890 int z = ID_d();
2891 pokeb( z, inc8( peekb(z) ) );
2892 return ( 23 );
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) */
2900 int z = ID_d();
2901 pokeb( z, dec8( peekb(z) ) );
2902 return ( 23 );
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 */
2949 { return ( 8 ); }
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 */
2968 { return ( 8 ); }
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)
3064 int z = ID_d();
3065 // Opcode comes after offset byte
3066 int op = nxtpcb();
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 */
3074 int t = ID();
3075 int sp = SP();
3076 ID( peekw( sp ) );
3077 pokew( sp, t );
3078 return ( 23 );
3081 case 229: /* PUSH ID */
3082 { pushw( ID() ); return ( 15 ); }
3084 } // end switch
3086 return 0;
3090 private final void execute_id_cb(int op, int z) {
3092 switch ( op ) {
3094 case 0: /* RLC B */
3095 { B( op = rlc( peekb( z ) ) ); pokeb( z, op ); return; }
3096 case 1: /* RLC C */
3097 { C( op = rlc( peekb( z ) ) ); pokeb( z, op ); return; }
3098 case 2: /* RLC D */
3099 { D( op = rlc( peekb( z ) ) ); pokeb( z, op ); return; }
3100 case 3: /* RLC E */
3101 { E( op = rlc( peekb( z ) ) ); pokeb( z, op ); return; }
3102 case 4: /* RLC H */
3103 { H( op = rlc( peekb( z ) ) ); pokeb( z, op ); return; }
3104 case 5: /* RLC L */
3105 { L( op = rlc( peekb( z ) ) ); pokeb( z, op ); return; }
3106 case 6: /* RLC (HL) */
3107 { pokeb( z, rlc( peekb( z ) ) ); return; }
3108 case 7: /* RLC A */
3109 { A( op = rlc( peekb( z ) ) ); pokeb( z, op ); return; }
3111 case 8: /* RRC B */
3112 { B( op = rrc( peekb( z ) ) ); pokeb( z, op ); return; }
3113 case 9: /* RRC C */
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; }
3128 case 16: /* RL B */
3129 { B( op = rl( peekb( z ) ) ); pokeb( z, op ); return; }
3130 case 17: /* RL C */
3131 { C( op = rl( peekb( z ) ) ); pokeb( z, op ); return; }
3132 case 18: /* RL D */
3133 { D( op = rl( peekb( z ) ) ); pokeb( z, op ); return; }
3134 case 19: /* RL E */
3135 { E( op = rl( peekb( z ) ) ); pokeb( z, op ); return; }
3136 case 20: /* RL H */
3137 { H( op = rl( peekb( z ) ) ); pokeb( z, op ); return; }
3138 case 21: /* RL L */
3139 { L( op = rl( peekb( z ) ) ); pokeb( z, op ); return; }
3140 case 22: /* RL (HL) */
3141 { pokeb( z, rl( peekb( z ) ) ); return; }
3142 case 23: /* RL A */
3143 { A( op = rl( peekb( z ) ) ); pokeb( z, op ); return; }
3145 case 24: /* RR B */
3146 { B( op = rr( peekb( z ) ) ); pokeb( z, op ); return; }
3147 case 25: /* RR C */
3148 { C( op = rr( peekb( z ) ) ); pokeb( z, op ); return; }
3149 case 26: /* RR D */
3150 { D( op = rr( peekb( z ) ) ); pokeb( z, op ); return; }
3151 case 27: /* RR E */
3152 { E( op = rr( peekb( z ) ) ); pokeb( z, op ); return; }
3153 case 28: /* RR H */
3154 { H( op = rr( peekb( z ) ) ); pokeb( z, op ); return; }
3155 case 29: /* RR L */
3156 { L( op = rr( peekb( z ) ) ); pokeb( z, op ); return; }
3157 case 30: /* RR (HL) */
3158 { pokeb( z, rr( peekb( z ) ) ); return; }
3159 case 31: /* RR A */
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; }
3582 } // end switch
3586 private final int in_bc() {
3587 int ans = inb( BC() );
3589 setZ( ans == 0 );
3590 setS( (ans & F_S)!=0 );
3591 set3( (ans & F_3)!=0 );
3592 set5( (ans & F_5)!=0 );
3593 setPV( parity[ ans ] );
3594 setN( false );
3595 setH( false );
3597 return ans;
3600 /** Add with carry - alters all flags (CHECKED) */
3601 private final void
3602 adc_a( int b )
3604 int a = A();
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 );
3612 setZ( (ans) == 0 );
3613 setC( (wans&0x100) != 0 );
3614 setPV( ((a ^ ~b) & (a ^ ans) & 0x80) != 0 );
3615 setH( (((a & 0x0f) + (b & 0x0f) + c) & F_H) != 0 );
3616 setN( false );
3618 A( ans );
3621 /** Add - alters all flags (CHECKED) */
3622 private final void
3623 add_a( int b )
3625 int a = A();
3626 int wans = a + b;
3627 int ans = wans & 0xff;
3629 setS( (ans & F_S) != 0 );
3630 set3( (ans & F_3) != 0 );
3631 set5( (ans & F_5) != 0 );
3632 setZ( (ans) == 0 );
3633 setC( (wans&0x100) != 0 );
3634 setPV( ((a ^ ~b) & (a ^ ans) & 0x80) != 0 );
3635 setH( (((a & 0x0f) + (b & 0x0f)) & F_H) != 0 );
3636 setN( false );
3638 A( ans );
3641 /** Subtract with carry - alters all flags (CHECKED) */
3642 private final void
3643 sbc_a( int b )
3645 int a = A();
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 );
3653 setZ( (ans) == 0 );
3654 setC( (wans&0x100) != 0 );
3655 setPV( ((a ^ b) & (a ^ ans) & 0x80) != 0 );
3656 setH( (((a & 0x0f) - (b & 0x0f) - c) & F_H) != 0 );
3657 setN( true );
3659 A( ans );
3662 /** Subtract - alters all flags (CHECKED) */
3663 private final void
3664 sub_a( int b )
3666 int a = A();
3667 int wans = a - b;
3668 int ans = wans & 0xff;
3670 setS( (ans & F_S) != 0 );
3671 set3( (ans & F_3) != 0 );
3672 set5( (ans & F_5) != 0 );
3673 setZ( (ans) == 0 );
3674 setC( (wans&0x100) != 0 );
3675 setPV( ((a ^ b) & (a ^ ans) & 0x80) != 0 );
3676 setH( (((a & 0x0f) - (b & 0x0f)) & F_H) != 0 );
3677 setN( true );
3679 A( ans );
3682 /** Rotate Left - alters H N C 3 5 flags (CHECKED) */
3683 private final void
3684 rlc_a()
3686 int ans = A();
3687 boolean c = (ans & 0x80) != 0;
3689 if ( c ) {
3690 ans = (ans << 1)|0x01;
3691 } else {
3692 ans <<= 1;
3694 ans &= 0xff;
3696 set3( (ans & F_3) != 0 );
3697 set5( (ans & F_5) != 0 );
3698 setN( false );
3699 setH( false );
3700 setC( c );
3702 A( ans );
3705 /** Rotate Right - alters H N C 3 5 flags (CHECKED) */
3706 private final void
3707 rrc_a()
3709 int ans = A();
3710 boolean c = (ans & 0x01) != 0;
3712 if ( c ) {
3713 ans = (ans >> 1)|0x80;
3714 } else {
3715 ans >>= 1;
3718 set3( (ans & F_3) != 0 );
3719 set5( (ans & F_5) != 0 );
3720 setN( false );
3721 setH( false );
3722 setC( c );
3724 A( ans );
3727 /** Rotate Left through Carry - alters H N C 3 5 flags (CHECKED) */
3728 private final void
3729 rl_a()
3731 int ans = A();
3732 boolean c = (ans & 0x80) != 0;
3734 if ( Cset() ) {
3735 ans = (ans << 1) | 0x01;
3736 } else {
3737 ans <<= 1;
3740 ans &= 0xff;
3742 set3( (ans & F_3) != 0 );
3743 set5( (ans & F_5) != 0 );
3744 setN( false );
3745 setH( false );
3746 setC( c );
3748 A( ans );
3751 /** Rotate Right through Carry - alters H N C 3 5 flags (CHECKED) */
3752 private final void
3753 rr_a()
3755 int ans = A();
3756 boolean c = (ans & 0x01) != 0;
3758 if ( Cset() ) {
3759 ans = (ans >> 1) | 0x80;
3760 } else {
3761 ans >>= 1;
3764 set3( (ans & F_3) != 0 );
3765 set5( (ans & F_5) != 0 );
3766 setN( false );
3767 setH( false );
3768 setC( c );
3770 A( ans );
3773 /** Compare - alters all flags (CHECKED) */
3774 private final void
3775 cp_a( int b )
3777 int a = A();
3778 int wans = a - b;
3779 int ans = wans & 0xff;
3781 setS( (ans & F_S) != 0 );
3782 set3( (b & F_3) != 0 );
3783 set5( (b & F_5) != 0 );
3784 setN( true );
3785 setZ( ans == 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) */
3792 private final void
3793 and_a( int b )
3795 int ans = A() & b;
3797 setS( (ans & F_S) != 0 );
3798 set3( (ans & F_3) != 0 );
3799 set5( (ans & F_5) != 0 );
3800 setH( true );
3801 setPV( parity[ ans ] );
3802 setZ( ans == 0 );
3803 setN( false );
3804 setC( false );
3806 A( ans );
3809 /** Bitwise or - alters all flags (CHECKED) */
3810 private final void
3811 or_a( int b )
3813 int ans = A() | b;
3815 setS( (ans & F_S) != 0 );
3816 set3( (ans & F_3) != 0 );
3817 set5( (ans & F_5) != 0 );
3818 setH( false );
3819 setPV( parity[ ans ] );
3820 setZ( ans == 0 );
3821 setN( false );
3822 setC( false );
3824 A( ans );
3827 /** Bitwise exclusive or - alters all flags (CHECKED) */
3828 private final void
3829 xor_a( int b )
3831 int ans = (A() ^ b) & 0xff;
3833 setS( (ans & F_S) != 0 );
3834 set3( (ans & F_3) != 0 );
3835 set5( (ans & F_5) != 0 );
3836 setH( false );
3837 setPV( parity[ ans ] );
3838 setZ( ans == 0 );
3839 setN( false );
3840 setC( false );
3842 A( ans );
3845 /** Negate (Two's complement) - alters all flags (CHECKED) */
3846 private final void
3847 neg_a()
3849 int t = A();
3851 A( 0 );
3852 sub_a(t);
3855 /** One's complement - alters N H 3 5 flags (CHECKED) */
3856 private final void
3857 cpl_a()
3859 int ans = A() ^ 0xff;
3861 set3( (ans & F_3) != 0 );
3862 set5( (ans & F_5) != 0 );
3863 setH( true );
3864 setN( true );
3866 A( ans );
3869 /** Decimal Adjust Accumulator - alters all flags (CHECKED) */
3870 private final void
3871 daa_a()
3873 int ans = A();
3874 int incr = 0;
3875 boolean carry = Cset();
3877 if ((Hset()) || ((ans & 0x0f) > 0x09)) {
3878 incr |= 0x06;
3880 if (carry || (ans > 0x9f) || ((ans > 0x8f) && ((ans & 0x0f) > 0x09))) {
3881 incr |= 0x60;
3883 if (ans > 0x99) {
3884 carry = true;
3886 if (Nset()) {
3887 sub_a(incr);
3888 } else {
3889 add_a(incr);
3892 ans = A();
3894 setC( carry );
3895 setPV( parity[ ans ] );
3898 /** Load a with i - (NOT CHECKED) */
3899 private final void
3900 ld_a_i()
3902 int ans = I();
3904 setS( (ans & F_S) != 0 );
3905 set3( (ans & F_3) != 0 );
3906 set5( (ans & F_5) != 0 );
3907 setZ( ans == 0 );
3908 setPV( IFF2() );
3909 setH( false );
3910 setN( false );
3912 A( ans );
3915 /** Load a with r - (NOT CHECKED) */
3916 private final void
3917 ld_a_r()
3919 int ans = R();
3921 setS( (ans & F_S) != 0 );
3922 set3( (ans & F_3) != 0 );
3923 set5( (ans & F_5) != 0 );
3924 setZ( ans == 0 );
3925 setPV( IFF2() );
3926 setH( false );
3927 setN( false );
3929 A( ans );
3932 /** Rotate right through a and (hl) - (NOT CHECKED) */
3933 private final void
3934 rrd_a()
3936 int ans = A();
3937 int t = peekb( HL() );
3938 int q = t;
3940 t = (t >> 4) | (ans << 4);
3941 ans = (ans & 0xf0) | (q & 0x0f);
3942 pokeb( HL(), t );
3944 setS( (ans & F_S) != 0 );
3945 set3( (ans & F_3) != 0 );
3946 set5( (ans & F_5) != 0 );
3947 setZ( ans == 0 );
3948 setPV( IFF2() );
3949 setH( false );
3950 setN( false );
3952 A( ans );
3955 /** Rotate left through a and (hl) - (NOT CHECKED) */
3956 private final void
3957 rld_a()
3959 int ans = A();
3960 int t = peekb( HL() );
3961 int q = t;
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 );
3970 setZ( ans == 0 );
3971 setPV( IFF2() );
3972 setH( false );
3973 setN( false );
3975 A( ans );
3978 /** Test bit - alters all but C flag (CHECKED) */
3979 private final void
3980 bit( int b, int r )
3982 boolean bitSet = ((r & b) != 0);
3984 setN( false );
3985 setH( true );
3986 set3( (r & F_3) != 0 );
3987 set5( (r & F_5) != 0 );
3988 setS( (b == F_S) ? bitSet : false );
3989 setZ( !bitSet );
3990 setPV( !bitSet );
3993 /** Set carry flag - alters N H 3 5 C flags (CHECKED) */
3994 private final void
3995 scf()
3997 int ans = A();
3999 set3( (ans & F_3) != 0 );
4000 set5( (ans & F_5) != 0 );
4001 setN( false );
4002 setH( false );
4003 setC( true );
4006 /** Complement carry flag - alters N 3 5 C flags (CHECKED) */
4007 private final void
4008 ccf()
4010 int ans = A();
4012 set3( (ans & F_3) != 0 );
4013 set5( (ans & F_5) != 0 );
4014 setN( false );
4015 setC( Cset() ? false : true );
4018 /** Rotate left - alters all flags (CHECKED) */
4019 private final int
4020 rlc( int ans )
4022 boolean c = (ans & 0x80) != 0;
4024 if ( c ) {
4025 ans = (ans << 1)|0x01;
4026 } else {
4027 ans <<= 1;
4029 ans &= 0xff;
4031 setS( (ans & F_S) != 0 );
4032 set3( (ans & F_3) != 0 );
4033 set5( (ans & F_5) != 0 );
4034 setZ( (ans) == 0 );
4035 setPV( parity[ ans ] );
4036 setH( false );
4037 setN( false );
4038 setC( c );
4040 return(ans);
4043 /** Rotate right - alters all flags (CHECKED) */
4044 private final int
4045 rrc( int ans )
4047 boolean c = (ans & 0x01) != 0;
4049 if ( c ) {
4050 ans = (ans >> 1)|0x80;
4051 } else {
4052 ans >>= 1;
4055 setS( (ans & F_S) != 0 );
4056 set3( (ans & F_3) != 0 );
4057 set5( (ans & F_5) != 0 );
4058 setZ( (ans) == 0 );
4059 setPV( parity[ ans ] );
4060 setH( false );
4061 setN( false );
4062 setC( c );
4064 return(ans);
4067 /** Rotate left through carry - alters all flags (CHECKED) */
4068 private final int
4069 rl( int ans )
4071 boolean c = (ans & 0x80) != 0;
4073 if ( Cset() ) {
4074 ans = (ans << 1) | 0x01;
4075 } else {
4076 ans <<= 1;
4078 ans &= 0xff;
4080 setS( (ans & F_S) != 0 );
4081 set3( (ans & F_3) != 0 );
4082 set5( (ans & F_5) != 0 );
4083 setZ( (ans) == 0 );
4084 setPV( parity[ ans ] );
4085 setH( false );
4086 setN( false );
4087 setC( c );
4089 return(ans);
4092 /** Rotate right through carry - alters all flags (CHECKED) */
4093 private final int
4094 rr( int ans )
4096 boolean c = (ans & 0x01) != 0;
4098 if ( Cset() ) {
4099 ans = (ans >> 1) | 0x80;
4100 } else {
4101 ans >>= 1;
4104 setS( (ans & F_S) != 0 );
4105 set3( (ans & F_3) != 0 );
4106 set5( (ans & F_5) != 0 );
4107 setZ( (ans) == 0 );
4108 setPV( parity[ ans ] );
4109 setH( false );
4110 setN( false );
4111 setC( c );
4113 return(ans);
4116 /** Shift Left Arithmetically - alters all flags (CHECKED) */
4117 private final int
4118 sla( int ans )
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 );
4126 setZ( (ans) == 0 );
4127 setPV( parity[ ans ] );
4128 setH( false );
4129 setN( false );
4130 setC( c );
4132 return(ans);
4135 /** Shift Left and Set - alters all flags (CHECKED) */
4136 private final int
4137 sls( int ans )
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 );
4145 setZ( (ans) == 0 );
4146 setPV( parity[ ans ] );
4147 setH( false );
4148 setN( false );
4149 setC( c );
4151 return(ans);
4154 /** Shift Right Arithmetically - alters all flags (CHECKED) */
4155 private final int
4156 sra( int ans )
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 );
4164 setZ( (ans) == 0 );
4165 setPV( parity[ ans ] );
4166 setH( false );
4167 setN( false );
4168 setC( c );
4170 return(ans);
4173 /** Shift Right Logically - alters all flags (CHECKED) */
4174 private final int srl( int ans ) {
4175 boolean c = (ans & 0x01) != 0;
4176 ans = ans >> 1;
4178 setS( (ans & F_S) != 0 );
4179 set3( (ans & F_3) != 0 );
4180 set5( (ans & F_5) != 0 );
4181 setZ( (ans) == 0 );
4182 setPV( parity[ ans ] );
4183 setH( false );
4184 setN( false );
4185 setC( c );
4187 return(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 );
4199 setZ( (ans) == 0 );
4200 setPV( pv );
4201 setH( h );
4202 setN( true );
4204 return(ans);
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 );
4216 setZ( (ans) == 0 );
4217 setPV( pv );
4218 setH( h );
4219 setN( false );
4221 return(ans);
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 );
4233 setZ( (ans) == 0 );
4234 setC( (lans & 0x10000)!=0 );
4235 setPV( ((a ^ ~b) & (a ^ ans) & 0x8000)!=0 );
4236 setH( (((a & 0x0fff) + (b & 0x0fff) + c) & 0x1000)!=0 );
4237 setN( false );
4239 return(ans);
4242 /** Add - (NOT CHECKED) */
4243 private final int add16( int a, int b ) {
4244 int lans = a + 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 );
4251 setN( false );
4253 return(ans);
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 );
4265 setZ( (ans) == 0 );
4266 setC( (lans & 0x10000)!=0 );
4267 setPV( ((a ^ b) & (a ^ ans) & 0x8000)!=0 );
4268 setH( (((a & 0x0fff) - (b & 0x0fff) - c) & 0x1000)!=0 );
4269 setN( true );
4271 return(ans);
4274 /** EXX */
4275 public final void exx() {
4276 int t;
4278 t = HL();
4279 HL( _HL_ );
4280 _HL_ = t;
4282 t = DE();
4283 DE( _DE_ );
4284 _DE_ = t;
4286 t = BC();
4287 BC( _BC_ );
4288 _BC_ = t;
4291 /** EX AF,AF' */
4292 public final void ex_af_af() {
4293 int t;
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; }
4305 /** Bit toggling */
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; }