1 /* Emulations of the Z80 CPU instruction set - part of xz80.
2  * Copyright (C) 1994 Ian Collier.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #define instr(opcode,cycles) case opcode: {tstates+=cycles
20 #define HLinstr(opcode,cycles,morecycles) \
21                              case opcode: {unsigned short addr; \
22                                 tstates+=cycles; \
23                                 if(ixoriy==0)addr=hl; \
24                                 else tstates+=morecycles, \
25                                    addr=(ixoriy==1?ix:iy)+ \
26                                         (signed char)fetch(pc),\
27                                    pc++
28 #define endinstr             }; break
29 
30 #define cy (f&1)
31 
32 #define xh (ixoriy==0?h:ixoriy==1?(ix>>8):(iy>>8))
33 #define xl (ixoriy==0?l:ixoriy==1?(ix&0xff):(iy&0xff))
34 
35 #define setxh(x) (ixoriy==0?(h=(x)):ixoriy==1?(ix=(ix&0xff)|((x)<<8)):\
36                   (iy=(iy&0xff)|((x)<<8)))
37 #define setxl(x) (ixoriy==0?(l=(x)):ixoriy==1?(ix=(ix&0xff00)|(x)):\
38                   (iy=(iy&0xff00)|(x)))
39 
40 #define inc(var) /* 8-bit increment */ ( var++,\
41                                          f=(f&1)|(var&0xa8)|\
42                                            ((!(var&15))<<4)|((!var)<<6)|\
43                                            ((var==128)<<2)\
44                                        )
45 #define dec(var) /* 8-bit decrement */ ( f=(f&1)|((!(var&15))<<4)|2,\
46                                          --var,\
47                                          f|=(var&0xa8)|((var==127)<<2)|\
48                                             ((!var)<<6)\
49                                        )
50 #define swap(x,y) {unsigned char t=x; x=y; y=t;}
51 #define addhl(hi,lo) /* 16-bit add */ if(!ixoriy){\
52                       unsigned short t;\
53                       l=t=l+(lo);\
54                       f=(f&0xc4)|(((t>>=8)+(h&0x0f)+((hi)&0x0f)>15)<<4);\
55                       h=t+=h+(hi);\
56                       f|=(h&0x28)|(t>>8);\
57                    }\
58                    else do{unsigned long t=(ixoriy==1?ix:iy);\
59                       f=(f&0xc4)|(((t&0xfff)+((hi<<8)|lo)>0xfff)<<4);\
60                       t+=(hi<<8)|lo;\
61                       if(ixoriy==1)ix=t; else iy=t;\
62                       f|=((t>>8)&0x28)|(t>>16);\
63                    } while(0)
64 #define adda(x,c) /* 8-bit add */ do{unsigned short y;\
65                       unsigned char z=(x);\
66                       y=a+z+(c);\
67                       f=(y&0xa8)|(y>>8)|(((a&0x0f)+(z&0x0f)+(c)>15)<<4)|\
68                         (((~a^z)&0x80&(y^a))>>5);\
69                       f|=(!(a=y))<<6;\
70                    } while(0)
71 #define suba(x,c) /* 8-bit subtract */ do{unsigned short y;\
72                       unsigned char z=(x);\
73                       y=(a-z-(c))&0x1ff;\
74                       f=(y&0xa8)|(y>>8)|(((a&0x0f)<(z&0x0f)+(c))<<4)|\
75                         (((a^z)&0x80&(y^a))>>5)|2;\
76                       f|=(!(a=y))<<6;\
77                    } while(0)
78 #define cpa(x) /* 8-bit compare */ do{unsigned short y;\
79                       unsigned char z=(x);\
80                       y=(a-z)&0x1ff;\
81                       f=(y&0xa8)|(y>>8)|(((a&0x0f)<(z&0x0f))<<4)|\
82                         (((a^z)&0x80&(y^a))>>5)|2|((!y)<<6);\
83                    } while(0)
84 #define anda(x) /* logical and */ do{\
85                       a&=(x);\
86                       f=(a&0xa8)|((!a)<<6)|0x10|parity(a);\
87                    } while(0)
88 #define xora(x) /* logical xor */ do{\
89                       a^=(x);\
90                       f=(a&0xa8)|((!a)<<6)|parity(a);\
91                    } while(0)
92 #define ora(x) /* logical or */ do{\
93                       a|=(x);\
94                       f=(a&0xa8)|((!a)<<6)|parity(a);\
95                    } while(0)
96 
97 #define jr /* execute relative jump */ do{int j=(signed char)fetch(pc);\
98                       pc+=j+1;\
99                       tstates+=5;\
100                    } while(0)
101 #define jp /* execute jump */ (pc=fetch2(pc))
102 #define call /* execute call */ do{\
103                       tstates+=7;\
104                       push2(pc+2);\
105                       jp;\
106                    } while(0)
107 #define ret /* execute return */ do{\
108                       tstates+=6;\
109                       pop2(pc);\
110                    } while(0)
111 #define pop2(var) /* pop 16-bit register */ (var=fetch2(sp),sp+=2)
112 #define pop1(v1,v2) /* pop register pair */ (v2=fetch(sp),\
113                                              v1=fetch(sp+1),sp+=2)
114 #define push2(val) /* push 16-bit register */ do{sp-=2;store2(sp,(val));}\
115                                               while(0)
116 #define push1(v1,v2) /* push register pair */ do{sp-=2;\
117                                                  store2b(sp,v1,v2);\
118                                               }while(0)
119 
120 instr(0,4);
121    /* nop */
122 endinstr;
123 
124 instr(1,10);
125    c=fetch(pc),pc++;
126    b=fetch(pc),pc++;
127 endinstr;
128 
129 instr(2,7);
130    store(bc,a);
131 endinstr;
132 
133 instr(3,6);
134    if(!++c)b++;
135 endinstr;
136 
137 instr(4,4);
138    inc(b);
139 endinstr;
140 
141 instr(5,4);
142    dec(b);
143 endinstr;
144 
145 instr(6,7);
146    b=fetch(pc),pc++;
147 endinstr;
148 
149 instr(7,4);
150    a=(a<<1)|(a>>7);
151    f=(f&0xc4)|(a&0x29);
152 endinstr;
153 
154 instr(8,4);
155    swap(a,a1);
156    swap(f,f1);
157 endinstr;
158 
159 instr(9,11);
160    addhl(b,c);
161 endinstr;
162 
163 instr(10,7);
164    a=fetch(bc);
165 endinstr;
166 
167 instr(11,6);
168    if(!c--)b--;
169 endinstr;
170 
171 instr(12,4);
172    inc(c);
173 endinstr;
174 
175 instr(13,4);
176    dec(c);
177 endinstr;
178 
179 instr(14,4);
180    c=fetch(pc),pc++;
181 endinstr;
182 
183 instr(15,4);
184    f=(f&0xc4)|(a&1);
185    a=(a>>1)|(a<<7);
186    f|=a&0x28;
187 endinstr;
188 
189 instr(16,8);
190    if(!--b)pc++;
191    else jr;
192 endinstr;
193 
194 instr(17,10);
195    e=fetch(pc),pc++;
196    d=fetch(pc),pc++;
197 endinstr;
198 
199 instr(18,7);
200    store(de,a);
201 endinstr;
202 
203 instr(19,6);
204    if(!++e)d++;
205 endinstr;
206 
207 instr(20,4);
208    inc(d);
209 endinstr;
210 
211 instr(21,4);
212    dec(d);
213 endinstr;
214 
215 instr(22,7);
216    d=fetch(pc),pc++;
217 endinstr;
218 
219 instr(23,4);
220   {int t=a>>7;
221    a=(a<<1)|(f&1);
222    f=(f&0xc4)|(a&0x28)|t;
223   }
224 endinstr;
225 
226 instr(24,7);
227    jr;
228 endinstr;
229 
230 instr(25,11);
231    addhl(d,e);
232 endinstr;
233 
234 instr(26,7);
235    a=fetch(de);
236 endinstr;
237 
238 instr(27,6);
239    if(!e--)d--;
240 endinstr;
241 
242 instr(28,4);
243    inc(e);
244 endinstr;
245 
246 instr(29,4);
247    dec(e);
248 endinstr;
249 
250 instr(30,4);
251    e=fetch(pc),pc++;
252 endinstr;
253 
254 instr(31,4);
255   {int t=a&1;
256    a=(a>>1)|(f<<7);
257    f=(f&0xc4)|(a&0x28)|t;
258   }
259 endinstr;
260 
261 instr(32,7);
262   if(f&0x40)pc++;
263   else jr;
264 endinstr;
265 
266 instr(33,10);
267    if(!ixoriy){
268       l=fetch(pc),pc++;
269       h=fetch(pc),pc++;
270    }
271    else {
272       if(ixoriy==1)ix=fetch2(pc);
273       else iy=fetch2(pc);
274       pc+=2;
275    }
276 endinstr;
277 
278 instr(34,16);
279    {unsigned short addr=fetch2(pc);
280     pc+=2;
281     if(!ixoriy)store2b(addr,h,l);
282     else if(ixoriy==1)store2(addr,ix);
283     else store2(addr,iy);
284    }
285 endinstr;
286 
287 instr(35,6);
288    if(!ixoriy){if(!++l)h++;}
289    else if(ixoriy==1)ix++;
290    else iy++;
291 endinstr;
292 
293 instr(36,4);
294    if(ixoriy==0)inc(h);
295    else{unsigned char t;
296       t=(ixoriy==1?ix:iy)>>8;
297       inc(t);
298       if(ixoriy==1)ix=(ix&0xff)|(t<<8);
299       else iy=(iy&0xff)|(t<<8);
300    }
301 endinstr;
302 
303 instr(37,4);
304    if(ixoriy==0)dec(h);
305    else{unsigned char t;
306       t=(ixoriy==1?ix:iy)>>8;
307       dec(t);
308       if(ixoriy==1)ix=(ix&0xff)|(t<<8);
309       else iy=(iy&0xff)|(t<<8);
310    }
311 endinstr;
312 
313 instr(38,7);
314    setxh(fetch(pc));
315    pc++;
316 endinstr;
317 
318 instr(39,4);
319    {
320       unsigned char incr=0, carry=cy;
321       if((f&0x10) || (a&0x0f)>9) incr=6;
322       if((f&1) || (a>>4)>9) incr|=0x60;
323       if(f&2)suba(incr,0);
324       else {
325          if(a>0x90 && (a&15)>9)incr|=0x60;
326          adda(incr,0);
327       }
328       f=((f|carry)&0xfb)|parity(a);
329    }
330 endinstr;
331 
332 instr(40,7);
333    if(f&0x40)jr;
334    else pc++;
335 endinstr;
336 
337 instr(41,11);
338    if(!ixoriy)addhl(h,l);
339    else if(ixoriy==1)addhl((ix>>8),(ix&0xff));
340    else addhl((iy>>8),(iy&0xff));
341 endinstr;
342 
343 instr(42,16);
344   {unsigned short addr=fetch2(pc);
345    pc+=2;
346    if(!ixoriy){
347       l=fetch(addr);
348       h=fetch(addr+1);
349    }
350    else if(ixoriy==1)ix=fetch2(addr);
351    else iy=fetch2(addr);
352   }
353 endinstr;
354 
355 instr(43,6);
356    if(!ixoriy){if(!l--)h--;}
357    else if(ixoriy==1)ix--;
358    else iy--;
359 endinstr;
360 
361 instr(44,4);
362    if(!ixoriy)inc(l);
363    else {unsigned char t;
364       t=(ixoriy==1?ix:iy);
365       inc(t);
366       if(ixoriy==1)ix=(ix&0xff00)|t;
367       else iy=(iy&0xff00)|t;
368    }
369 endinstr;
370 
371 instr(45,4);
372    if(!ixoriy)dec(l);
373    else {unsigned char t;
374       t=(ixoriy==1?ix:iy);
375       dec(t);
376       if(ixoriy==1)ix=(ix&0xff00)|t;
377       else iy=(iy&0xff00)|t;
378    }
379 endinstr;
380 
381 instr(46,4);
382    setxl(fetch(pc));
383    pc++;
384 endinstr;
385 
386 instr(47,4);
387    a=~a;
388    f=(f&0xc5)|(a&0x28)|0x12;
389 endinstr;
390 
391 instr(48,7);
392    if(f&1)pc++;
393    else jr;
394 endinstr;
395 
396 instr(49,10);
397    sp=fetch2(pc);
398    pc+=2;
399 endinstr;
400 
401 instr(50,13);
402   {unsigned short addr=fetch2(pc);
403    pc+=2;
404    store(addr,a);
405   }
406 endinstr;
407 
408 instr(51,6);
409    sp++;
410 endinstr;
411 
412 HLinstr(52,11,8);
413   {unsigned char t=fetch(addr);
414    inc(t);
415    store(addr,t);
416   }
417 endinstr;
418 
419 HLinstr(53,11,8);
420   {unsigned char t=fetch(addr);
421    dec(t);
422    store(addr,t);
423   }
424 endinstr;
425 
426 HLinstr(54,10,5);
427    store(addr,fetch(pc));
428    pc++;
429 endinstr;
430 
431 instr(55,4);
432    f=(f&0xc4)|1|(a&0x28);
433 endinstr;
434 
435 instr(56,7);
436    if(f&1)jr;
437    else pc++;
438 endinstr;
439 
440 instr(57,11);
441    addhl((sp>>8),(sp&0xff));
442 endinstr;
443 
444 instr(58,13);
445   {unsigned short addr=fetch2(pc);
446    pc+=2;
447    a=fetch(addr);
448   }
449 endinstr;
450 
451 instr(59,6);
452    sp--;
453 endinstr;
454 
455 instr(60,4);
456    inc(a);
457 endinstr;
458 
459 instr(61,4);
460    dec(a);
461 endinstr;
462 
463 instr(62,4);
464    a=fetch(pc),pc++;
465 endinstr;
466 
467 instr(63,4);
468    f=(f&0xc4)|(cy^1)|(cy<<4)|(a&0x28);
469 endinstr;
470 
471 instr(0x40,4);
472    /* ld b,b */
473 endinstr;
474 
475 instr(0x41,4);
476    b=c;
477 endinstr;
478 
479 instr(0x42,4);
480    b=d;
481 endinstr;
482 
483 instr(0x43,4);
484    b=e;
485 endinstr;
486 
487 instr(0x44,4);
488    b=xh;
489 endinstr;
490 
491 instr(0x45,4);
492    b=xl;
493 endinstr;
494 
495 HLinstr(0x46,7,8);
496    b=fetch(addr);
497 endinstr;
498 
499 instr(0x47,4);
500    b=a;
501 endinstr;
502 
503 instr(0x48,4);
504    c=b;
505 endinstr;
506 
507 instr(0x49,4);
508    /* ld c,c */
509 endinstr;
510 
511 instr(0x4a,4);
512    c=d;
513 endinstr;
514 
515 instr(0x4b,4);
516    c=e;
517 endinstr;
518 
519 instr(0x4c,4);
520    c=xh;
521 endinstr;
522 
523 instr(0x4d,4);
524    c=xl;
525 endinstr;
526 
527 HLinstr(0x4e,7,8);
528    c=fetch(addr);
529 endinstr;
530 
531 instr(0x4f,4);
532    c=a;
533 endinstr;
534 
535 instr(0x50,4);
536    d=b;
537 endinstr;
538 
539 instr(0x51,4);
540    d=c;
541 endinstr;
542 
543 instr(0x52,4);
544    /* ld d,d */
545 endinstr;
546 
547 instr(0x53,4);
548    d=e;
549 endinstr;
550 
551 instr(0x54,4);
552    d=xh;
553 endinstr;
554 
555 instr(0x55,4);
556    d=xl;
557 endinstr;
558 
559 HLinstr(0x56,7,8);
560    d=fetch(addr);
561 endinstr;
562 
563 instr(0x57,4);
564    d=a;
565 endinstr;
566 
567 instr(0x58,4);
568    e=b;
569 endinstr;
570 
571 instr(0x59,4);
572    e=c;
573 endinstr;
574 
575 instr(0x5a,4);
576    e=d;
577 endinstr;
578 
579 instr(0x5b,4);
580    /* ld e,e */
581 endinstr;
582 
583 instr(0x5c,4);
584    e=xh;
585 endinstr;
586 
587 instr(0x5d,4);
588    e=xl;
589 endinstr;
590 
591 HLinstr(0x5e,7,8);
592    e=fetch(addr);
593 endinstr;
594 
595 instr(0x5f,4);
596    e=a;
597 endinstr;
598 
599 instr(0x60,4);
600    setxh(b);
601 endinstr;
602 
603 instr(0x61,4);
604    setxh(c);
605 endinstr;
606 
607 instr(0x62,4);
608    setxh(d);
609 endinstr;
610 
611 instr(0x63,4);
612    setxh(e);
613 endinstr;
614 
615 instr(0x64,4);
616    /* ld h,h */
617 endinstr;
618 
619 instr(0x65,4);
620    setxh(xl);
621 endinstr;
622 
623 HLinstr(0x66,7,8);
624    h=fetch(addr);
625 endinstr;
626 
627 instr(0x67,4);
628    setxh(a);
629 endinstr;
630 
631 instr(0x68,4);
632    setxl(b);
633 endinstr;
634 
635 instr(0x69,4);
636    setxl(c);
637 endinstr;
638 
639 instr(0x6a,4);
640    setxl(d);
641 endinstr;
642 
643 instr(0x6b,4);
644    setxl(e);
645 endinstr;
646 
647 instr(0x6c,4);
648    setxl(xh);
649 endinstr;
650 
651 instr(0x6d,4);
652    /* ld l,l */
653 endinstr;
654 
655 HLinstr(0x6e,7,8);
656    l=fetch(addr);
657 endinstr;
658 
659 instr(0x6f,4);
660    setxl(a);
661 endinstr;
662 
663 HLinstr(0x70,7,8);
664    store(addr,b);
665 endinstr;
666 
667 HLinstr(0x71,7,8);
668    store(addr,c);
669 endinstr;
670 
671 HLinstr(0x72,7,8);
672    store(addr,d);
673 endinstr;
674 
675 HLinstr(0x73,7,8);
676    store(addr,e);
677 endinstr;
678 
679 HLinstr(0x74,7,8);
680    store(addr,h);
681 endinstr;
682 
683 HLinstr(0x75,7,8);
684    store(addr,l);
685 endinstr;
686 
687 instr(0x76,4);
688 pc--;		/* keep nopping until int */
689 endinstr;
690 
691 HLinstr(0x77,7,8);
692    store(addr,a);
693 endinstr;
694 
695 instr(0x78,4);
696    a=b;
697 endinstr;
698 
699 instr(0x79,4);
700    a=c;
701 endinstr;
702 
703 instr(0x7a,4);
704    a=d;
705 endinstr;
706 
707 instr(0x7b,4);
708    a=e;
709 endinstr;
710 
711 instr(0x7c,4);
712    a=xh;
713 endinstr;
714 
715 instr(0x7d,4);
716    a=xl;
717 endinstr;
718 
719 HLinstr(0x7e,7,8);
720    a=fetch(addr);
721 endinstr;
722 
723 instr(0x7f,4);
724    /* ld a,a */
725 endinstr;
726 
727 instr(0x80,4);
728    adda(b,0);
729 endinstr;
730 
731 instr(0x81,4);
732    adda(c,0);
733 endinstr;
734 
735 instr(0x82,4);
736    adda(d,0);
737 endinstr;
738 
739 instr(0x83,4);
740    adda(e,0);
741 endinstr;
742 
743 instr(0x84,4);
744    adda(xh,0);
745 endinstr;
746 
747 instr(0x85,4);
748    adda(xl,0);
749 endinstr;
750 
751 HLinstr(0x86,7,8);
752    adda(fetch(addr),0);
753 endinstr;
754 
755 instr(0x87,4);
756    adda(a,0);
757 endinstr;
758 
759 instr(0x88,4);
760    adda(b,cy);
761 endinstr;
762 
763 instr(0x89,4);
764    adda(c,cy);
765 endinstr;
766 
767 instr(0x8a,4);
768    adda(d,cy);
769 endinstr;
770 
771 instr(0x8b,4);
772    adda(e,cy);
773 endinstr;
774 
775 instr(0x8c,4);
776    adda(xh,cy);
777 endinstr;
778 
779 instr(0x8d,4);
780    adda(xl,cy);
781 endinstr;
782 
783 HLinstr(0x8e,7,8);
784    adda(fetch(addr),cy);
785 endinstr;
786 
787 instr(0x8f,4);
788    adda(a,cy);
789 endinstr;
790 
791 instr(0x90,4);
792    suba(b,0);
793 endinstr;
794 
795 instr(0x91,4);
796    suba(c,0);
797 endinstr;
798 
799 instr(0x92,4);
800    suba(d,0);
801 endinstr;
802 
803 instr(0x93,4);
804    suba(e,0);
805 endinstr;
806 
807 instr(0x94,4);
808    suba(xh,0);
809 endinstr;
810 
811 instr(0x95,4);
812    suba(xl,0);
813 endinstr;
814 
815 HLinstr(0x96,7,8);
816    suba(fetch(addr),0);
817 endinstr;
818 
819 instr(0x97,4);
820    suba(a,0);
821 endinstr;
822 
823 instr(0x98,4);
824    suba(b,cy);
825 endinstr;
826 
827 instr(0x99,4);
828    suba(c,cy);
829 endinstr;
830 
831 instr(0x9a,4);
832    suba(d,cy);
833 endinstr;
834 
835 instr(0x9b,4);
836    suba(e,cy);
837 endinstr;
838 
839 instr(0x9c,4);
840    suba(xh,cy);
841 endinstr;
842 
843 instr(0x9d,4);
844    suba(xl,cy);
845 endinstr;
846 
847 HLinstr(0x9e,7,8);
848    suba(fetch(addr),cy);
849 endinstr;
850 
851 instr(0x9f,4);
852    suba(a,cy);
853 endinstr;
854 
855 instr(0xa0,4);
856    anda(b);
857 endinstr;
858 
859 instr(0xa1,4);
860    anda(c);
861 endinstr;
862 
863 instr(0xa2,4);
864    anda(d);
865 endinstr;
866 
867 instr(0xa3,4);
868    anda(e);
869 endinstr;
870 
871 instr(0xa4,4);
872    anda(xh);
873 endinstr;
874 
875 instr(0xa5,4);
876    anda(xl);
877 endinstr;
878 
879 HLinstr(0xa6,7,8);
880    anda(fetch(addr));
881 endinstr;
882 
883 instr(0xa7,4);
884    anda(a);
885 endinstr;
886 
887 instr(0xa8,4);
888    xora(b);
889 endinstr;
890 
891 instr(0xa9,4);
892    xora(c);
893 endinstr;
894 
895 instr(0xaa,4);
896    xora(d);
897 endinstr;
898 
899 instr(0xab,4);
900    xora(e);
901 endinstr;
902 
903 instr(0xac,4);
904    xora(xh);
905 endinstr;
906 
907 instr(0xad,4);
908    xora(xl);
909 endinstr;
910 
911 HLinstr(0xae,7,8);
912    xora(fetch(addr));
913 endinstr;
914 
915 instr(0xaf,4);
916    xora(a);
917 endinstr;
918 
919 instr(0xb0,4);
920    ora(b);
921 endinstr;
922 
923 instr(0xb1,4);
924    ora(c);
925 endinstr;
926 
927 instr(0xb2,4);
928    ora(d);
929 endinstr;
930 
931 instr(0xb3,4);
932    ora(e);
933 endinstr;
934 
935 instr(0xb4,4);
936    ora(xh);
937 endinstr;
938 
939 instr(0xb5,4);
940    ora(xl);
941 endinstr;
942 
943 HLinstr(0xb6,7,8);
944    ora(fetch(addr));
945 endinstr;
946 
947 instr(0xb7,4);
948    ora(a);
949 endinstr;
950 
951 instr(0xb8,4);
952    cpa(b);
953 endinstr;
954 
955 instr(0xb9,4);
956    cpa(c);
957 endinstr;
958 
959 instr(0xba,4);
960    cpa(d);
961 endinstr;
962 
963 instr(0xbb,4);
964    cpa(e);
965 endinstr;
966 
967 instr(0xbc,4);
968    cpa(xh);
969 endinstr;
970 
971 instr(0xbd,4);
972    cpa(xl);
973 endinstr;
974 
975 HLinstr(0xbe,7,8);
976    cpa(fetch(addr));
977 endinstr;
978 
979 instr(0xbf,4);
980    cpa(a);
981 endinstr;
982 
983 instr(0xc0,5);
984    if(!(f&0x40))ret;
985 endinstr;
986 
987 instr(0xc1,10);
988    pop1(b,c);
989 endinstr;
990 
991 instr(0xc2,10);
992    if(!(f&0x40))jp;
993    else pc+=2;
994 endinstr;
995 
996 instr(0xc3,10);
997    jp;
998 endinstr;
999 
1000 instr(0xc4,10);
1001    if(!(f&0x40))call;
1002    else pc+=2;
1003 endinstr;
1004 
1005 instr(0xc5,11);
1006    push1(b,c);
1007 endinstr;
1008 
1009 instr(0xc6,7);
1010    adda(fetch(pc),0);
1011    pc++;
1012 endinstr;
1013 
1014 instr(0xc7,11);
1015    push2(pc);
1016    pc=0;
1017 endinstr;
1018 
1019 instr(0xc8,5);
1020    if(f&0x40)ret;
1021 endinstr;
1022 
1023 instr(0xc9,4);
1024    ret;
1025 endinstr;
1026 
1027 instr(0xca,10);
1028    if(f&0x40)jp;
1029    else pc+=2;
1030 endinstr;
1031 
1032 instr(0xcb,4);
1033 #include "cbops.c"
1034 endinstr;
1035 
1036 instr(0xcc,10);
1037    if(f&0x40)call;
1038    else pc+=2;
1039 endinstr;
1040 
1041 instr(0xcd,10);
1042    call;
1043 endinstr;
1044 
1045 instr(0xce,7);
1046    adda(fetch(pc),cy);
1047    pc++;
1048 endinstr;
1049 
1050 instr(0xcf,11);
1051    push2(pc);
1052    pc=8;
1053 endinstr;
1054 
1055 instr(0xd0,5);
1056    if(!cy)ret;
1057 endinstr;
1058 
1059 instr(0xd1,10);
1060    pop1(d,e);
1061 endinstr;
1062 
1063 instr(0xd2,10);
1064    if(!cy)jp;
1065    else pc+=2;
1066 endinstr;
1067 
1068 instr(0xd3,11);
1069    tstates+=out(a,fetch(pc),a);
1070    pc++;
1071 endinstr;
1072 
1073 instr(0xd4,10);
1074    if(!cy)call;
1075    else pc+=2;
1076 endinstr;
1077 
1078 instr(0xd5,11);
1079    push1(d,e);
1080 endinstr;
1081 
1082 instr(0xd6,7);
1083    suba(fetch(pc),0);
1084    pc++;
1085 endinstr;
1086 
1087 instr(0xd7,11);
1088    push2(pc);
1089    pc=16;
1090 endinstr;
1091 
1092 instr(0xd8,5);
1093    if(cy)ret;
1094 endinstr;
1095 
1096 instr(0xd9,4);
1097    swap(b,b1);
1098    swap(c,c1);
1099    swap(d,d1);
1100    swap(e,e1);
1101    swap(h,h1);
1102    swap(l,l1);
1103 endinstr;
1104 
1105 instr(0xda,10);
1106    if(cy)jp;
1107    else pc+=2;
1108 endinstr;
1109 
1110 instr(0xdb,11);
1111    {unsigned short t;
1112       a=t=in(a,fetch(pc));
1113       tstates+=t>>8;
1114       pc++;
1115    }
1116 endinstr;
1117 
1118 instr(0xdc,10);
1119    if(cy)call;
1120    else pc+=2;
1121 endinstr;
1122 
1123 instr(0xdd,4);
1124    new_ixoriy=1;
1125    intsample=0;
1126 endinstr;
1127 
1128 instr(0xde,7);
1129    suba(fetch(pc),cy);
1130    pc++;
1131 endinstr;
1132 
1133 instr(0xdf,11);
1134    push2(pc);
1135    pc=24;
1136 endinstr;
1137 
1138 instr(0xe0,5);
1139    if(!(f&4))ret;
1140 endinstr;
1141 
1142 instr(0xe1,10);
1143    if(!ixoriy)pop1(h,l);
1144    else if(ixoriy==1)pop2(ix);
1145    else pop2(iy);
1146 endinstr;
1147 
1148 instr(0xe2,10);
1149    if(!(f&4))jp;
1150    else pc+=2;
1151 endinstr;
1152 
1153 instr(0xe3,19);
1154    if(!ixoriy){
1155       unsigned short t=fetch2(sp);
1156       store2b(sp,h,l);
1157       l=t;
1158       h=t>>8;
1159    }
1160    else if(ixoriy==1){
1161       unsigned short t=fetch2(sp);
1162       store2(sp,ix);
1163       ix=t;
1164    }
1165    else{
1166       unsigned short t=fetch2(sp);
1167       store2(sp,iy);
1168       iy=t;
1169    }
1170 endinstr;
1171 
1172 instr(0xe4,10);
1173    if(!(f&4))call;
1174    else pc+=2;
1175 endinstr;
1176 
1177 instr(0xe5,11);
1178    if(!ixoriy)push1(h,l);
1179    else if(ixoriy==1)push2(ix);
1180    else push2(iy);
1181 endinstr;
1182 
1183 instr(0xe6,7);
1184    anda(fetch(pc));
1185    pc++;
1186 endinstr;
1187 
1188 instr(0xe7,11);
1189    push2(pc);
1190    pc=32;
1191 endinstr;
1192 
1193 instr(0xe8,5);
1194    if(f&4)ret;
1195 endinstr;
1196 
1197 instr(0xe9,4);
1198    pc=!ixoriy?hl:ixoriy==1?ix:iy;
1199 endinstr;
1200 
1201 instr(0xea,10);
1202    if(f&4)jp;
1203    else pc+=2;
1204 endinstr;
1205 
1206 instr(0xeb,4);
1207    swap(h,d);
1208    swap(e,l);
1209 endinstr;
1210 
1211 instr(0xec,10);
1212    if(f&4)call;
1213    else pc+=2;
1214 endinstr;
1215 
1216 instr(0xed,4);
1217 #include"edops.c"
1218 endinstr;
1219 
1220 instr(0xee,7);
1221    xora(fetch(pc));
1222    pc++;
1223 endinstr;
1224 
1225 instr(0xef,11);
1226    push2(pc);
1227    pc=40;
1228 endinstr;
1229 
1230 instr(0xf0,5);
1231    if(!(f&0x80))ret;
1232 endinstr;
1233 
1234 instr(0xf1,10);
1235    pop1(a,f);
1236 endinstr;
1237 
1238 instr(0xf2,10);
1239    if(!(f&0x80))jp;
1240    else pc+=2;
1241 endinstr;
1242 
1243 instr(0xf3,4);
1244    iff1=iff2=0;
1245    intsample=0;
1246 endinstr;
1247 
1248 instr(0xf4,10);
1249    if(!(f&0x80))call;
1250    else pc+=2;
1251 endinstr;
1252 
1253 instr(0xf5,11);
1254    push1(a,f);
1255 endinstr;
1256 
1257 instr(0xf6,7);
1258    ora(fetch(pc));
1259    pc++;
1260 endinstr;
1261 
1262 instr(0xf7,11);
1263    push2(pc);
1264    pc=48;
1265 endinstr;
1266 
1267 instr(0xf8,5);
1268    if(f&0x80)ret;
1269 endinstr;
1270 
1271 instr(0xf9,6);
1272    sp=!ixoriy?hl:ixoriy==1?ix:iy;
1273 endinstr;
1274 
1275 instr(0xfa,10);
1276    if(f&0x80)jp;
1277    else pc+=2;
1278 endinstr;
1279 
1280 instr(0xfb,4);
1281    iff1=iff2=1;
1282    intsample=0;
1283 endinstr;
1284 
1285 instr(0xfc,10);
1286    if(f&0x80)call;
1287    else pc+=2;
1288 endinstr;
1289 
1290 instr(0xfd,4);
1291    new_ixoriy=2;
1292    intsample=0;
1293 endinstr;
1294 
1295 instr(0xfe,7);
1296    cpa(fetch(pc));
1297    pc++;
1298 endinstr;
1299 
1300 instr(0xff,11);
1301    push2(pc);
1302    pc=56;
1303 endinstr;
1304 
1305