struct / union in initializer, RFE #901.
[sdcc.git] / sdcc-extra / emu / rrgb / z80ops.c
blob3285b46814611153359c2b4632222ad0a23bf68a
1 /* Emulations of the Z80 CPU instruction set - part of xz80.
2 * Copyright (C) 1994 Ian Collier.
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.
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.
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.
19 /* PENDING: Forward definitions. */
20 void handleRST08(struct sregs *pregs);
22 #define instr(opcode,cycles) case opcode: {tstates+=cycles
23 #define endinstr }; break
25 enum {
26 /** Carry */
27 CBIT = 0x01,
28 NBIT = 0x02,
29 /** Parity/Overflow */
30 VBIT = 0x04,
31 /** Half carry */
32 HBIT = 0x10,
33 /** Zero */
34 ZBIT = 0x40,
35 /** Sign */
36 SBIT = 0x80
39 enum {
40 /** Carry */
41 CLOG = 0,
42 NLOG = 1,
43 /** Parity/Overflow */
44 VLOG = 2,
45 /** Half carry */
46 HLOG = 4,
47 /** Zero */
48 ZLOG = 6,
49 /** Sign */
50 SLOG = 7
53 #define cy (f&1)
55 #define xh (h)
56 #define xl (l)
58 #define setxh(x) (h=(x))
59 #define setxl(x) (l=(x))
60 #define inc(var) /* 8-bit increment */ ( var++,\
61 f=(f&1)|(var&0xa8)|\
62 ((!(var&15))<<4)|((!var)<<6)|\
63 ((var==128)<<2)\
65 #define dec(var) /* 8-bit decrement */ ( f=(f&1)|((!(var&15))<<4)|2,\
66 --var,\
67 f|=(var&0xa8)|((var==127)<<2)|\
68 ((!var)<<6)\
70 #define swap(x,y) {unsigned char t=x; x=y; y=t;}
71 #define addhl(hi,lo) /* 16-bit add */ do {\
72 unsigned short t;\
73 l=t=l+(lo);\
74 f=(f&0xc4)|(((t>>=8)+(h&0x0f)+((hi)&0x0f)>15)<<4);\
75 h=t+=h+(hi);\
76 f|=(h&0x28)|(t>>8); } while(0)
78 #define adda(x,c) /* 8-bit add */ do{unsigned short y;\
79 unsigned char z=(x);\
80 y=a+z+(c);\
81 f=(y&0xa8)|(y>>8)|(((a&0x0f)+(z&0x0f)+(c)>15)<<4)|\
82 (((~a^z)&0x80&(y^a))>>5);\
83 f|=(!(a=y))<<6;\
84 } while(0)
85 #define suba(x,c) /* 8-bit subtract */ do{unsigned short y;\
86 unsigned char z=(x);\
87 y=(a-z-(c))&0x1ff;\
88 f=(y&0xa8)|(y>>8)|(((a&0x0f)<(z&0x0f)+(c))<<4)|\
89 (((a^z)&0x80&(y^a))>>5)|2;\
90 f|=(!(a=y))<<6;\
91 } while(0)
92 #define cpa(x) /* 8-bit compare */ do{unsigned short y;\
93 unsigned char z=(x);\
94 y=(a-z)&0x1ff;\
95 f=(y&0xa8)|(y>>8)|(((a&0x0f)<(z&0x0f))<<4)|\
96 (((a^z)&0x80&(y^a))>>5)|2|((!y)<<6);\
97 } while(0)
98 #define anda(x) /* logical and */ do{\
99 a&=(x);\
100 f=(a&0xa8)|((!a)<<6)|0x10;\
101 } while(0)
102 #define xora(x) /* logical xor */ do{\
103 a^=(x);\
104 f=(a&0xa8)|((!a)<<6);\
105 } while(0)
106 #define ora(x) /* logical or */ do{\
107 a|=(x);\
108 f=(a&0xa8)|((!a)<<6);\
109 } while(0)
111 #define jr /* execute relative jump */ do{int j=(signed char)fetch(pc);\
112 pc+=j+1;\
113 } while(0)
114 #define jp /* execute jump */ (pc=fetch2(pc))
115 #define call /* execute call */ do{\
116 push2(pc+2);\
117 if (flags&DPROFILE) \
118 push_callback(fetch2(pc));\
119 jp;\
120 } while(0)
121 #define ret /* execute return */ do{\
122 if (flags&DPROFILE) \
123 pop_callback();\
124 pop2(pc);\
125 } while(0)
126 #define pop2(var) /* pop 16-bit register */ (var=fetch2(sp),sp+=2)
127 #define pop1(v1,v2) /* pop register pair */ (v2=fetch(sp),\
128 v1=fetch(sp+1),sp+=2)
129 #define push2(val) /* push 16-bit register */ do{sp-=2;store2(sp,(val));}\
130 while(0)
131 #define push1(v1,v2) /* push register pair */ do{sp-=2;\
132 store2b(sp,v1,v2);\
133 }while(0)
135 instr(0,4);
136 /* nop */
137 endinstr;
139 instr(1,12);
140 c=fetch(pc),pc++;
141 b=fetch(pc),pc++;
142 endinstr;
144 instr(2,8);
145 store(bc,a);
146 endinstr;
148 instr(3,8);
149 if(!++c)b++;
150 endinstr;
152 instr(4,4);
153 inc(b);
154 endinstr;
156 instr(5,4);
157 dec(b);
158 endinstr;
160 instr(6,8);
161 b=fetch(pc),pc++;
162 endinstr;
164 instr(7,4);
165 a=(a<<1)|(a>>7);
166 f=(f&0xc4)|(a&0x29);
167 endinstr;
169 instr(8,20); /* Old Ex AF,AF' - new LD (nnnn),SP NYT */
171 unsigned addr=fetch2(pc);
172 store2(addr,sp);
173 pc+=2;
175 endinstr;
177 instr(9,8);
178 addhl(b,c);
179 endinstr;
181 instr(10,8);
182 a=fetch(bc);
183 endinstr;
185 instr(11,8);
186 if(!c--)b--;
187 endinstr;
189 instr(12,4);
190 inc(c);
191 endinstr;
193 instr(13,4);
194 dec(c);
195 endinstr;
197 instr(14,8);
198 c=fetch(pc),pc++;
199 endinstr;
201 instr(15,4);
202 f=(f&0xc4)|(a&1);
203 a=(a>>1)|(a<<7);
204 f|=a&0x28;
205 endinstr;
207 instr(16,4); /* Old DJNZ - new STOP (taken as abort) */
208 /* if(!--b)pc++;
209 else jr;*/
210 cpuRunning=0;
211 endinstr;
213 instr(17,12);
214 e=fetch(pc),pc++;
215 d=fetch(pc),pc++;
216 endinstr;
218 instr(18,8);
219 store(de,a);
220 endinstr;
222 instr(19,8);
223 if(!++e)d++;
224 endinstr;
226 instr(20,4);
227 inc(d);
228 endinstr;
230 instr(21,4);
231 dec(d);
232 endinstr;
234 instr(22,8);
235 d=fetch(pc),pc++;
236 endinstr;
238 instr(23,4);
239 {int t=a>>7;
240 a=(a<<1)|(f&1);
241 f=(f&0xc4)|(a&0x28)|t;
243 endinstr;
245 instr(24,8);
247 endinstr;
249 instr(25,8);
250 addhl(d,e);
251 endinstr;
253 instr(26,8);
254 a=fetch(de);
255 endinstr;
257 instr(27,8);
258 if(!e--)d--;
259 endinstr;
261 instr(28,4);
262 inc(e);
263 endinstr;
265 instr(29,4);
266 dec(e);
267 endinstr;
269 instr(30,8);
270 e=fetch(pc),pc++;
271 endinstr;
273 instr(31,4);
274 {int t=a&1;
275 a=(a>>1)|(f<<7);
276 f=(f&0xc4)|(a&0x28)|t;
278 endinstr;
280 instr(32,8);
281 if(f&0x40)pc++;
282 else jr;
283 endinstr;
285 instr(33,12);
286 l=fetch(pc),pc++;
287 h=fetch(pc),pc++;
288 endinstr;
290 instr(34,8); /* LD (HL+),A */
291 store(hl,a);
292 if(!++l)h++;
293 endinstr;
295 instr(35,8); /* INC HL */
296 if(!++l)h++;
297 endinstr;
299 instr(36,4);
300 inc(h);
301 endinstr;
303 instr(37,4);
304 dec(h);
305 endinstr;
307 instr(38,8);
308 setxh(fetch(pc));
309 pc++;
310 endinstr;
312 instr(39,4);
314 unsigned char incr=0, carry=cy;
315 if((f&0x10) || (a&0x0f)>9) incr=6;
316 if((f&1) || (a>>4)>9) incr|=0x60;
317 if(f&2)suba(incr,0);
318 else {
319 if(a>0x90 && (a&15)>9)incr|=0x60;
320 adda(incr,0);
322 f=((f|carry)&0xfb);
324 endinstr;
326 instr(40,8);
327 if(f&0x40)jr;
328 else pc++;
329 endinstr;
331 instr(41,8);
332 addhl(h,l);
333 endinstr;
335 instr(0x2A,8); /* LD A,(HL+) */
336 a=fetch(hl);
337 if (!++l)h++;
338 endinstr;
340 instr(43,8); /* DEC HL */
341 if(!l--)h--;
342 endinstr;
344 instr(44,4);
345 inc(l);
346 endinstr;
348 instr(45,4);
349 dec(l);
350 endinstr;
352 instr(46,8);
353 setxl(fetch(pc));
354 pc++;
355 endinstr;
357 instr(47,4);
358 a=~a;
359 f=(f&0xc5)|(a&0x28)|0x12;
360 endinstr;
362 instr(0x030,8);
363 if(f&1)pc++;
364 else jr;
365 endinstr;
367 instr(49,12);
368 sp=fetch2(pc);
369 pc+=2;
370 endinstr;
372 instr(50,8); /* LD (HL-),A */
373 store(hl,a);
374 if(!l--)h--;
375 endinstr;
377 instr(51,8);
378 sp++;
379 endinstr;
381 instr(52,12);
382 {unsigned char t=fetch(hl);
383 inc(t);
384 store(hl,t);
386 endinstr;
388 instr(53,12);
389 {unsigned char t=fetch(hl);
390 dec(t);
391 store(hl,t);
393 endinstr;
395 instr(54,12);
396 store(hl,fetch(pc));
397 pc++;
398 endinstr;
400 instr(55,4);
401 f=(f&0xc4)|1|(a&0x28);
402 endinstr;
404 instr(56,8);
405 if(f&1)jr;
406 else pc++;
407 endinstr;
409 instr(57,8);
410 addhl((sp>>8),(sp&0xff));
411 endinstr;
413 instr(58,8); /* LD A,(HL-) */
414 a=fetch(hl);
415 if(!l--)h--;
416 endinstr;
418 instr(59,8);
419 sp--;
420 endinstr;
422 instr(60,4);
423 inc(a);
424 endinstr;
426 instr(61,4);
427 dec(a);
428 endinstr;
430 instr(62,8);
431 a=fetch(pc),pc++;
432 endinstr;
434 instr(63,4);
435 f=(f&0xc4)|(cy^1)|(cy<<4)|(a&0x28);
436 endinstr;
438 instr(0x40,4);
439 /* ld b,b */
440 endinstr;
442 instr(0x41,4);
443 b=c;
444 endinstr;
446 instr(0x42,4);
447 b=d;
448 endinstr;
450 instr(0x43,4);
451 b=e;
452 endinstr;
454 instr(0x44,4);
455 b=xh;
456 endinstr;
458 instr(0x45,4);
459 b=xl;
460 endinstr;
462 instr(0x46,8);
463 b=fetch(hl);
464 endinstr;
466 instr(0x47,4);
467 b=a;
468 endinstr;
470 instr(0x48,4);
471 c=b;
472 endinstr;
474 instr(0x49,4);
475 /* ld c,c */
476 endinstr;
478 instr(0x4a,4);
479 c=d;
480 endinstr;
482 instr(0x4b,4);
483 c=e;
484 endinstr;
486 instr(0x4c,4);
487 c=xh;
488 endinstr;
490 instr(0x4d,4);
491 c=xl;
492 endinstr;
494 instr(0x4e,8);
495 c=fetch(hl);
496 endinstr;
498 instr(0x4f,4);
499 c=a;
500 endinstr;
502 instr(0x50,4);
503 d=b;
504 endinstr;
506 instr(0x51,4);
507 d=c;
508 endinstr;
510 instr(0x52,4);
511 /* ld d,d */
512 endinstr;
514 instr(0x53,4);
515 d=e;
516 endinstr;
518 instr(0x54,4);
519 d=xh;
520 endinstr;
522 instr(0x55,4);
523 d=xl;
524 endinstr;
526 instr(0x56,8);
527 d=fetch(hl);
528 endinstr;
530 instr(0x57,4);
531 d=a;
532 endinstr;
534 instr(0x58,4);
535 e=b;
536 endinstr;
538 instr(0x59,4);
539 e=c;
540 endinstr;
542 instr(0x5a,4);
543 e=d;
544 endinstr;
546 instr(0x5b,4);
547 /* ld e,e */
548 endinstr;
550 instr(0x5c,4);
551 e=xh;
552 endinstr;
554 instr(0x5d,4);
555 e=xl;
556 endinstr;
558 instr(0x5e,8);
559 e=fetch(hl);
560 endinstr;
562 instr(0x5f,4);
563 e=a;
564 endinstr;
566 instr(0x60,4);
567 setxh(b);
568 endinstr;
570 instr(0x61,4);
571 setxh(c);
572 endinstr;
574 instr(0x62,4);
575 setxh(d);
576 endinstr;
578 instr(0x63,4);
579 setxh(e);
580 endinstr;
582 instr(0x64,4);
583 /* ld h,h */
584 endinstr;
586 instr(0x65,4);
587 setxh(xl);
588 endinstr;
590 instr(0x66,8);
591 h=fetch(hl);
592 endinstr;
594 instr(0x67,4);
595 setxh(a);
596 endinstr;
598 instr(0x68,4);
599 setxl(b);
600 endinstr;
602 instr(0x69,4);
603 setxl(c);
604 endinstr;
606 instr(0x6a,4);
607 setxl(d);
608 endinstr;
610 instr(0x6b,4);
611 setxl(e);
612 endinstr;
614 instr(0x6c,4);
615 setxl(xh);
616 endinstr;
618 instr(0x6d,4);
619 /* ld l,l */
620 endinstr;
622 instr(0x6e,8);
623 l=fetch(hl);
624 endinstr;
626 instr(0x6f,4);
627 setxl(a);
628 endinstr;
630 instr(0x70,8);
631 store(hl,b);
632 endinstr;
634 instr(0x71,8);
635 store(hl,c);
636 endinstr;
638 instr(0x72,8);
639 store(hl,d);
640 endinstr;
642 instr(0x73,8);
643 store(hl,e);
644 endinstr;
646 instr(0x74,8);
647 store(hl,h);
648 endinstr;
650 instr(0x75,8);
651 store(hl,l);
652 endinstr;
654 instr(0x76,4);
655 /* no interrupt support, so effectively a nop */
656 endinstr;
658 instr(0x77,8);
659 store(hl,a);
660 endinstr;
662 instr(0x78,4);
663 a=b;
664 endinstr;
666 instr(0x79,4);
667 a=c;
668 endinstr;
670 instr(0x7a,4);
671 a=d;
672 endinstr;
674 instr(0x7b,4);
675 a=e;
676 endinstr;
678 instr(0x7c,4);
679 a=xh;
680 endinstr;
682 instr(0x7d,4);
683 a=xl;
684 endinstr;
686 instr(0x7e,8); /* LD A,(HL) */
687 a=fetch(hl);
688 endinstr;
690 instr(0x7f,4);
691 /* ld a,a */
692 endinstr;
694 instr(0x80,4);
695 adda(b,0);
696 endinstr;
698 instr(0x81,4);
699 adda(c,0);
700 endinstr;
702 instr(0x82,4);
703 adda(d,0);
704 endinstr;
706 instr(0x83,4);
707 adda(e,0);
708 endinstr;
710 instr(0x84,4);
711 adda(xh,0);
712 endinstr;
714 instr(0x85,4);
715 adda(xl,0);
716 endinstr;
718 instr(0x86,8);
719 adda(fetch(hl),0);
720 endinstr;
722 instr(0x87,4);
723 adda(a,0);
724 endinstr;
726 instr(0x88,4);
727 adda(b,cy);
728 endinstr;
730 instr(0x89,4);
731 adda(c,cy);
732 endinstr;
734 instr(0x8a,4);
735 adda(d,cy);
736 endinstr;
738 instr(0x8b,4);
739 adda(e,cy);
740 endinstr;
742 instr(0x8c,4);
743 adda(xh,cy);
744 endinstr;
746 instr(0x8d,4);
747 adda(xl,cy);
748 endinstr;
750 instr(0x8e,8);
751 adda(fetch(hl),cy);
752 endinstr;
754 instr(0x8f,4);
755 adda(a,cy);
756 endinstr;
758 instr(0x90,4);
759 suba(b,0);
760 endinstr;
762 instr(0x91,4);
763 suba(c,0);
764 endinstr;
766 instr(0x92,4);
767 suba(d,0);
768 endinstr;
770 instr(0x93,4);
771 suba(e,0);
772 endinstr;
774 instr(0x94,4);
775 suba(xh,0);
776 endinstr;
778 instr(0x95,4);
779 suba(xl,0);
780 endinstr;
782 instr(0x96,8);
783 suba(fetch(hl),0);
784 endinstr;
786 instr(0x97,4);
787 suba(a,0);
788 endinstr;
790 instr(0x98,4);
791 suba(b,cy);
792 endinstr;
794 instr(0x99,4);
795 suba(c,cy);
796 endinstr;
798 instr(0x9a,4);
799 suba(d,cy);
800 endinstr;
802 instr(0x9b,4);
803 suba(e,cy);
804 endinstr;
806 instr(0x9c,4);
807 suba(xh,cy);
808 endinstr;
810 instr(0x9d,4);
811 suba(xl,cy);
812 endinstr;
814 instr(0x9e,8);
815 suba(fetch(hl),cy);
816 endinstr;
818 instr(0x9f,4);
819 suba(a,cy);
820 endinstr;
822 instr(0xa0,4);
823 anda(b);
824 endinstr;
826 instr(0xa1,4);
827 anda(c);
828 endinstr;
830 instr(0xa2,4);
831 anda(d);
832 endinstr;
834 instr(0xa3,4);
835 anda(e);
836 endinstr;
838 instr(0xa4,4);
839 anda(xh);
840 endinstr;
842 instr(0xa5,4);
843 anda(xl);
844 endinstr;
846 instr(0xa6,8);
847 anda(fetch(hl));
848 endinstr;
850 instr(0xa7,4);
851 anda(a);
852 endinstr;
854 instr(0xa8,4);
855 xora(b);
856 endinstr;
858 instr(0xa9,4);
859 xora(c);
860 endinstr;
862 instr(0xaa,4);
863 xora(d);
864 endinstr;
866 instr(0xab,4);
867 xora(e);
868 endinstr;
870 instr(0xac,4);
871 xora(xh);
872 endinstr;
874 instr(0xad,4);
875 xora(xl);
876 endinstr;
878 instr(0xae,8);
879 xora(fetch(hl));
880 endinstr;
882 instr(0xaf,4);
883 xora(a);
884 endinstr;
886 instr(0xb0,4);
887 ora(b);
888 endinstr;
890 instr(0xb1,4);
891 ora(c);
892 endinstr;
894 instr(0xb2,4);
895 ora(d);
896 endinstr;
898 instr(0xb3,4);
899 ora(e);
900 endinstr;
902 instr(0xb4,4);
903 ora(xh);
904 endinstr;
906 instr(0xb5,4);
907 ora(xl);
908 endinstr;
910 instr(0xb6,8);
911 ora(fetch(hl));
912 endinstr;
914 instr(0xb7,4);
915 ora(a);
916 endinstr;
918 instr(0xb8,4);
919 cpa(b);
920 endinstr;
922 instr(0xb9,4);
923 cpa(c);
924 endinstr;
926 instr(0xba,4);
927 cpa(d);
928 endinstr;
930 instr(0xbb,4);
931 cpa(e);
932 endinstr;
934 instr(0xbc,4);
935 cpa(xh);
936 endinstr;
938 instr(0xbd,4);
939 cpa(xl);
940 endinstr;
942 instr(0xbe,8);
943 cpa(fetch(hl));
944 endinstr;
946 instr(0xbf,4);
947 cpa(a);
948 endinstr;
950 instr(0xc0,8);
951 if(!(f&0x40))ret;
952 endinstr;
954 instr(0xc1,12);
955 pop1(b,c);
956 endinstr;
958 instr(0xc2,12);
959 if(!(f&0x40))jp;
960 else pc+=2;
961 endinstr;
963 instr(0xc3,12);
965 endinstr;
967 instr(0xc4,12);
968 if(!(f&0x40))call;
969 else pc+=2;
970 endinstr;
972 instr(0xc5,16);
973 push1(b,c);
974 endinstr;
976 instr(0xc6,8);
977 adda(fetch(pc),0);
978 pc++;
979 endinstr;
981 instr(0xc7,32); /* Old RST 00 - new End emulator */
982 /* push2(pc);
983 pc=0; */
984 cpuRunning=0;
985 endinstr;
987 instr(0xc8,8);
988 if(f&0x40)ret;
989 endinstr;
991 instr(0xc9,8);
992 ret;
993 endinstr;
995 instr(0xca,12);
996 if(f&0x40)jp;
997 else pc+=2;
998 endinstr;
1000 instr(0xcb,8);
1001 #include "cbops.c"
1002 endinstr;
1004 instr(0xcc,12);
1005 if(f&0x40)call;
1006 else pc+=2;
1007 endinstr;
1009 instr(0xcd,12);
1010 call;
1011 endinstr;
1013 instr(0xce,8);
1014 adda(fetch(pc),cy);
1015 pc++;
1016 endinstr;
1018 instr(0xcf,32); /* Old RST 08 - new print following string */
1020 handleRST08(&regs);
1022 endinstr;
1024 instr(0xd0,8);
1025 if(!cy)ret;
1026 endinstr;
1028 instr(0xd1,12);
1029 pop1(d,e);
1030 endinstr;
1032 instr(0xd2,12);
1033 if(!cy)jp;
1034 else pc+=2;
1035 endinstr;
1037 instr(0xd3,8); /* Old OUT (nn),a */
1038 /* tstates+=out(a,fetch(pc),a);
1039 pc++; */
1040 endinstr;
1042 instr(0xd4,12);
1043 if(!cy)call;
1044 else pc+=2;
1045 endinstr;
1047 instr(0xd5,16);
1048 push1(d,e);
1049 endinstr;
1051 instr(0xd6,8);
1052 suba(fetch(pc),0);
1053 pc++;
1054 endinstr;
1056 instr(0xd7,32); /* Old RST 10 */
1057 push2(pc);
1058 pc=16;
1059 endinstr;
1061 instr(0xd8,8);
1062 if(cy)ret;
1063 endinstr;
1065 instr(0xd9,8); /* Old EXX - now RETI */
1066 ret; /* xxx not what the GB really does */
1067 endinstr;
1069 instr(0xda,12);
1070 if(cy)jp;
1071 else pc+=2;
1072 endinstr;
1074 #ifdef INCLUDE_UNIMP
1075 /* Old IN A,(nn) */
1076 /*instr(0xdb,8);
1077 {unsigned short t;
1078 a=t=in(a,fetch(pc));
1079 tstates+=t>>8;
1080 pc++;
1082 endinstr;*/
1083 #endif
1085 instr(0xdc,12);
1086 if(cy)call;
1087 else pc+=2;
1088 endinstr;
1090 #ifdef INCLUDE_UNIMP
1091 /* Old IX/IY commands */
1092 /*instr(0xdd,4);
1093 endinstr;*/
1094 #endif
1096 instr(0xde,8);
1097 suba(fetch(pc),cy); /* SBC A,nn */
1098 pc++;
1099 endinstr;
1101 instr(0xdf,32); /* Old RST 18 - new start timing */
1102 startTime = tstates;
1103 /* push2(pc);
1104 pc=24;*/
1105 endinstr;
1107 #ifdef INCLUDE_UNIMP
1108 instr(0xe0,12); /* Old RET PO - now LD ($FF00+nn),A */
1109 /* if(!(f&4))ret; */
1110 endinstr;
1111 #endif
1113 instr(0xe1,12); /* POP HL */
1114 pop1(h,l);
1115 endinstr;
1117 #ifdef INCLUDE_UNIMP
1118 instr(0xe2,8); /* Old JP PO - now LD ($FF00+C),A */
1119 /* if(!(f&4))jp;
1120 else pc+=2; */
1121 endinstr;
1122 #endif
1124 /* Old EX (SP),HL */
1125 /*instr(0xe3,19);
1126 if(!ixoriy){
1127 unsigned short t=fetch2(sp);
1128 store2b(sp,h,l);
1129 l=t;
1130 h=t>>8;
1132 else if(ixoriy==1){
1133 unsigned short t=fetch2(sp);
1134 store2(sp,ix);
1135 ix=t;
1137 else{
1138 unsigned short t=fetch2(sp);
1139 store2(sp,iy);
1140 iy=t;
1142 endinstr;*/
1144 /* Old CALL PO */
1145 /*instr(0xe4,10);
1146 if(!(f&4))call;
1147 else pc+=2;
1148 endinstr;*/
1150 instr(0xe5,16);
1151 push1(h,l);
1152 endinstr;
1154 instr(0xe6,8);
1155 anda(fetch(pc));
1156 pc++;
1157 endinstr;
1159 instr(0xe7,32); /* Old RST 20 - new print time */
1160 /* push2(pc);
1161 pc=32;*/
1162 printf("Time: %lu\n", tstates-startTime);
1163 endinstr;
1165 instr(0xe8,16); /* Old RET PE - now ADD SP,shortint */
1166 sp+=(signed char)fetch(pc);
1167 pc++;
1168 /* if(f&4)ret; */
1169 endinstr;
1171 instr(0xe9,4);
1172 pc=hl;
1173 endinstr;
1175 instr(0xea,16); /* Old JP PE - now LD (nnnn),A */
1176 {unsigned short addr=fetch2(pc);
1177 pc+=2;
1178 store(addr,a);
1180 endinstr;
1182 /* Old EX DE,HL */
1183 /*instr(0xeb,4);
1184 swap(h,d);
1185 swap(e,l);
1186 endinstr;*/
1188 /* Old CALL PE */
1189 /*instr(0xec,10);
1190 if(f&4)call;
1191 else pc+=2;
1192 endinstr;*/
1194 /* Old ED commands */
1195 /*instr(0xed,4);
1196 endinstr;*/
1198 instr(0xee,8);
1199 xora(fetch(pc));
1200 pc++;
1201 endinstr;
1203 instr(0xef,32); /* Old RST 28 - new print float */
1204 /* push2(pc);
1205 pc=40;*/
1206 endinstr;
1208 #ifdef INCLUDE_UNIMP
1209 instr(0xf0,12); /* Old RET P - now LD A,($FF00+nn) NYI */
1210 /* if(!(f&0x80))ret; */
1211 endinstr;
1212 #endif
1214 instr(0xf1,12);
1215 pop1(a,f);
1216 endinstr;
1218 #ifdef INCLUDE_UNIMP
1219 instr(0xf2,8); /* Old JP P - now LD A,(C) NYT */
1220 a=fetch(c);
1221 /* if(!(f&0x80))jp;
1222 else pc+=2; */
1223 endinstr;
1224 #endif
1226 instr(0xf3,4);
1227 iff1=iff2=0;
1228 intsample=0;
1229 endinstr;
1231 /* Old CALL P */
1232 /*instr(0xf4,10);
1233 if(!(f&0x80))call;
1234 else pc+=2;
1235 endinstr;*/
1237 instr(0xf5,16);
1238 push1(a,f);
1239 endinstr;
1241 instr(0xf6,8);
1242 ora(fetch(pc));
1243 pc++;
1244 endinstr;
1246 instr(0xf7,32); /* Old RST 30 - new switch bank */
1247 /* push2(pc);
1248 pc=48;*/
1249 switchBank( a, hl );
1250 endinstr;
1252 instr(0xf8,12); /* Old RET M - new LD HL,SP+nn NYT */
1254 unsigned j = (unsigned)(sp+(signed char)fetch(pc));
1255 h=j>>8; l=j&0x0ff;
1256 /* Clear Z and N */
1257 f &= ~(ZBIT | NBIT | CBIT | HBIT);
1258 /* Set carry and half carry as appropriate */
1259 /* PENDING: Set half carry. */
1260 f |= (j>>8);
1261 pc++;
1263 /* if(f&0x80)ret; */
1264 endinstr;
1266 instr(0xf9,8);
1267 sp=hl;
1268 endinstr;
1270 instr(0xfa,16); /* Old JP M - new LD A,(nnnn) */
1271 {unsigned short addr=fetch2(pc);
1272 pc+=2;
1273 a=fetch(addr);
1275 /* if(f&0x80)jp;
1276 else pc+=2; */
1277 endinstr;
1279 instr(0xfb,4);
1280 iff1=iff2=1;
1281 intsample=0;
1282 endinstr;
1283 /* Old CALL M */
1284 /*instr(0xfc,10);
1285 if(f&0x80)call;
1286 else pc+=2;
1287 endinstr;*/
1289 /* Old IY prefix */
1290 /*instr(0xfd,4);
1291 new_ixoriy=2;
1292 intsample=0;
1293 endinstr;*/
1295 instr(0xfe,8);
1296 cpa(fetch(pc));
1297 pc++;
1298 endinstr;
1300 instr(0xff,32); /* Old RST 38 - New system call */
1301 /* push2(pc);
1302 pc=0x038;*/
1303 a=handle_sys(a,hl);
1304 endinstr;