1 /* ASSEMBLING FUNCTIONS */
2
3 #include "execute_token"
4 #include "regs.h"
5 #include "asm.h"
6
7 #include <stdio.h>
8
9 /* adc and sbc instructions */
10 /* offset: code of adc(sbc) A,B */
11 /* d: x in adc(sbc) HL,.. ED 4x */
12 /* return value: 0=OK, 1-7=invalid argument, 8=value out of range,9 offset out of r. */
13
14 int
c_adc_sbc(int first,int type,int second,int offset,int d)15 c_adc_sbc(int first,int type,int second,int offset,int d)
16 {
17 if (first==R_A)
18 {
19 if (type==A_PODLE_REG&&second==R_HL){out(offset+6);return 0;}
20 if (type==A_NUM)
21 {
22 out(offset+70);out(second);
23 return second>255 ? 8 : 0;
24 }
25 if (type==A_PODLE_IX_PLUS)
26 {
27 out(0xdd);out(offset+6);out(second);
28 if (second>127||second<-128) return 9;
29 return 0;
30 }
31 if (type==A_PODLE_IY_PLUS)
32 {
33 out(0xfd);out(offset+6);out(second);
34 if (second>127||second<-128)return 9;
35 return 0;
36 }
37 }
38
39 if (type==A_REG)
40 {
41 switch (first)
42 {
43 case R_A:
44 switch (second)
45 {
46 case R_A:
47 out(offset+7);
48 break;
49 case R_B:
50 out(offset);
51 break;
52 case R_C:
53 out(offset+1);
54 break;
55 case R_D:
56 out(offset+2);
57 break;
58 case R_E:
59 out(offset+3);
60 break;
61 case R_H:
62 out(offset+4);
63 break;
64 case R_L:
65 out(offset+5);
66 break;
67 default:
68 return 1;
69 }
70 break;
71
72 case R_HL:
73 switch (second)
74 {
75 case R_BC:
76 out(0xed);out(0x40+d);
77 break;
78 case R_DE:
79 out(0xed);out(0x50+d);
80 break;
81 case R_HL:
82 out(0xed);out(0x60+d);
83 break;
84 case R_SP:
85 out(0xed);out(0x70+d);
86 break;
87 default:
88 return 1;
89 }
90 break;
91
92 default:
93 return 1;
94 }
95 return 0;
96 }
97 return 1;
98 }
99
100
101 /* return value: 0=OK, 1=invalid argument, 8=value out of range,9=offset out of range */
102
103 int
c_add(int first,int type,int second)104 c_add(int first,int type,int second)
105 {
106 if (first==R_A)
107 {
108 if (type==A_PODLE_REG&&second==R_HL){out(0x86);return 0;}
109 if (type==A_NUM)
110 {
111 out(0xc6);out(second);
112 return second>255 ? 8 : 0;
113 }
114 if (type==A_PODLE_IX_PLUS)
115 {
116 out(0xdd);out(0x86);out(second);
117 if (second>127||second<-128)return 9;
118 return 0;
119 }
120 if (type==A_PODLE_IY_PLUS)
121 {
122 out(0xfd);out(0x86);out(second);
123 if (second>127||second<-128)return 9;
124 return 0;
125 }
126 }
127
128 if (type==A_REG)
129 {
130 switch (first)
131 {
132 case R_A:
133 switch (second)
134 {
135 case R_A:
136 out(0x87);
137 break;
138 case R_B:
139 out(0x80);
140 break;
141 case R_C:
142 out(0x81);
143 break;
144 case R_D:
145 out(0x82);
146 break;
147 case R_E:
148 out(0x83);
149 break;
150 case R_H:
151 out(0x84);
152 break;
153 case R_L:
154 out(0x85);
155 break;
156 default:
157 return 1;
158 }
159 break;
160
161 case R_HL:
162 switch (second)
163 {
164 case R_BC:
165 out(0x09);
166 break;
167 case R_DE:
168 out(0x19);
169 break;
170 case R_HL:
171 out(0x29);
172 break;
173 case R_SP:
174 out(0x39);
175 break;
176 default:
177 return 1;
178 }
179 break;
180
181 case R_IX:
182 switch (second)
183 {
184 case R_BC:
185 out(0xdd);out(0x09);
186 break;
187 case R_DE:
188 out(0xdd);out(0x19);
189 break;
190 case R_IX:
191 out(0xdd);out(0x29);
192 break;
193 case R_SP:
194 out(0xdd);out(0x39);
195 break;
196 default:
197 return 1;
198 }
199 break;
200
201 case R_IY:
202 switch (second)
203 {
204 case R_BC:
205 out(0xfd);out(0x09);
206 break;
207 case R_DE:
208 out(0xfd);out(0x19);
209 break;
210 case R_IY:
211 out(0xfd);out(0x29);
212 break;
213 case R_SP:
214 out(0xfd);out(0x39);
215 break;
216 default:
217 return 1;
218 }
219 break;
220
221 default:
222 return 1;
223 }
224 return 0;
225 }
226 return 1;
227 }
228
229
230 /* logical instructions: and,or,xor and instructions cp,sub */
231 /* offset: code of and(or,....) B */
232 /* return value: 0=OK, 1=invalid argument, 8=value out of range */
233
234 int
c_logical(int type,int value,int offset)235 c_logical(int type,int value,int offset)
236 {
237 switch(type)
238 {
239 case A_REG:
240 switch(value)
241 {
242 case R_A:
243 out(offset+7);
244 break;
245 case R_B:
246 out(offset);
247 break;
248 case R_C:
249 out(offset+1);
250 break;
251 case R_D:
252 out(offset+2);
253 break;
254 case R_E:
255 out(offset+3);
256 break;
257 case R_H:
258 out(offset+4);
259 break;
260 case R_L:
261 out(offset+5);
262 break;
263 default:
264 return 1;
265 }
266 break;
267
268 case A_PODLE_REG:
269 if (value!=R_HL) return 1;
270 out(offset+6);
271 break;
272
273 case A_PODLE_IX_PLUS:
274 out(0xdd);out(offset+6);out(value);
275 if (value>127||value<-128)return 9;
276 break;
277
278 case A_PODLE_IY_PLUS:
279 out(0xfd);out(offset+6);out(value);
280 if (value>127||value<-128)return 9;
281 break;
282
283 case A_NUM:
284 out(0x46+offset);out(value);
285 if (value>255) return 8;
286 break;
287
288 default:
289 return 1;
290 }
291 return 0;
292 }
293
294
295 int
c_ex(int t1,int v1,int v2)296 c_ex(int t1,int v1,int v2)
297 {
298 switch(t1)
299 {
300 case A_REG:
301 if (v1==R_DE&&v2==R_HL){out(0xeb);return 0;}
302 if (v1==R_AF&&v2==R_AF_){out(0x08);return 0;}
303 return 1;
304
305 case A_PODLE_REG:
306 if (v1!=R_SP)return 1;
307 switch (v2)
308 {
309 case R_HL:
310 out(0xe3);
311 break;
312 case R_IX:
313 out(0xdd);out(0xe3);
314 break;
315 case R_IY:
316 out(0xfd);out(0xe3);
317 break;
318 default:
319 return 1;
320 }
321 break;
322
323 default:
324 return 1;
325 }
326 return 0;
327 }
328
329
330 void
c_im(int v)331 c_im(int v)
332 {
333 out(0xed);
334 switch (v)
335 {
336 case 0:
337 out(0x46);
338 break;
339
340 case 1:
341 out(0x56);
342 break;
343
344 case 2:
345 out(0x5e);
346 break;
347 }
348 }
349
350
351 /* return value: 0=OK, 1=invalid argument, 8=value out of range */
352
353 int
c_in(int v1,int t2,int v2)354 c_in(int v1,int t2,int v2)
355 {
356 if (t2==A_PODLE_NUM)
357 {
358 if (v1==R_A)
359 { out(0xdb); out(v2);
360 return v2>255 ? 8 : 0 ;
361 }
362 else return 1;
363 }
364 if (t2==A_PODLE_REG&&v2==R_C)
365 {
366 switch(v1)
367 {
368 case R_A:
369 out(0xed);out(0x78);
370 break;
371 case R_B:
372 out(0xed);out(0x40);
373 break;
374 case R_C:
375 out(0xed);out(0x48);
376 break;
377 case R_D:
378 out(0xed);out(0x50);
379 break;
380 case R_E:
381 out(0xed);out(0x58);
382 break;
383 case R_H:
384 out(0xed);out(0x60);
385 break;
386 case R_L:
387 out(0xed);out(0x68);
388 break;
389 default:
390 return 1;
391 }
392 return 0;
393 }
394 return 1;
395 }
396
397
398 /* instructions inc and dec */
399 /* offs1: code of inc(dec) B */
400 /* offs2: code of inc(dec) BC */
401 /* return value: 0=OK, 1=invalid argument, 8=value out of range */
402
403 int
c_inc_dec(int type,int value,int offs1,int offs2)404 c_inc_dec(int type,int value,int offs1,int offs2)
405 {
406 switch(type)
407 {
408 case A_REG:
409 switch(value)
410 {
411 case R_A:
412 out(0x38+offs1);
413 break;
414 case R_B:
415 out(offs1);
416 break;
417 case R_C:
418 out(0x08+offs1);
419 break;
420 case R_D:
421 out(0x10+offs1);
422 break;
423 case R_E:
424 out(0x18+offs1);
425 break;
426 case R_H:
427 out(0x20+offs1);
428 break;
429 case R_L:
430 out(0x28+offs1);
431 break;
432 case R_BC:
433 out(offs2);
434 break;
435 case R_DE:
436 out(0x10+offs2);
437 break;
438 case R_HL:
439 out(0x20+offs2);
440 break;
441 case R_IX:
442 out(0xdd);out(0x20+offs2);
443 break;
444 case R_IY:
445 out(0xfd);out(0x20+offs2);
446 break;
447 case R_SP:
448 out(0x30+offs2);
449 break;
450 default:
451 return 1;
452 }
453 break;
454
455 case A_PODLE_REG:
456 if (value!=R_HL) return 1;
457 out(0x30+offs1);
458 break;
459
460 case A_PODLE_IX_PLUS:
461 out(0xdd);out(0x30+offs1);out(value);
462 if (value>127||value<-128)return 9;
463 break;
464
465 case A_PODLE_IY_PLUS:
466 out(0xfd);out(0x30+offs1);out(value);
467 if (value>127||value<-128)return 9;
468 break;
469
470 default:
471 return 1;
472 }
473 return 0;
474 }
475
476
477 /* return value: 0=OK, 1=invalid argument, 8=value out of range */
478
479 int
c_out(int t1,int v1,int v2)480 c_out(int t1,int v1,int v2)
481 {
482 if (t1==A_PODLE_NUM)
483 {
484 if (v2==R_A)
485 { out(0xd3);out(v1);
486 return v1>255 ? 8 : 0 ;
487 }
488 else return 1;
489 }
490 if (t1==A_PODLE_REG&&v1==R_C)
491 {
492 switch(v2)
493 {
494 case R_A:
495 out(0xed);out(0x79);
496 break;
497 case R_B:
498 out(0xed);out(0x41);
499 break;
500 case R_C:
501 out(0xed);out(0x49);
502 break;
503 case R_D:
504 out(0xed);out(0x51);
505 break;
506 case R_E:
507 out(0xed);out(0x59);
508 break;
509 case R_H:
510 out(0xed);out(0x61);
511 break;
512 case R_L:
513 out(0xed);out(0x69);
514 break;
515 default:
516 return 1;
517 }
518 return 0;
519 }
520 return 1;
521 }
522
523
524 /* instructions for push & pop */
525 /* offset: x in push(pop) AF 0xfx */
526
527 int
c_push_pop(int v,int offset)528 c_push_pop(int v,int offset)
529 {
530 switch (v)
531 {
532 case R_AF:
533 out(0xf0+offset);
534 break;
535
536 case R_BC:
537 out(offset+0xc0);
538 break;
539
540 case R_DE:
541 out(offset+0xd0);
542 break;
543
544 case R_HL:
545 out(offset+0xe0);
546 break;
547
548 case R_IX:
549 out(0xdd);out(offset+0xe0);
550 break;
551
552 case R_IY:
553 out(0xfd);out(offset+0xe0);
554 break;
555
556 default:
557 return 1;
558 }
559 return 0;
560 }
561
562
563 int
c_ret(int value)564 c_ret(int value)
565 {
566 switch (value)
567 {
568 case F_NZ:
569 out(0xc0);
570 break;
571 case F_Z:
572 out(0xc8);
573 break;
574 case F_NC:
575 out(0xd0);
576 break;
577 case F_C:
578 out(0xd8);
579 break;
580 case F_PO:
581 out(0xe0);
582 break;
583 case F_PE:
584 out(0xe8);
585 break;
586 case F_P:
587 out(0xf0);
588 break;
589 case F_M:
590 out(0xf8);
591 break;
592 default:
593 return 1;
594 }
595 return 0;
596 }
597
598
599 int
c_rst(int value)600 c_rst(int value)
601 {
602 switch(value)
603 {
604 case 0:
605 out(0xc7);
606 break;
607
608 case 8:
609 out(0xcf);
610 break;
611
612 case 0x10:
613 out(0xd7);
614 break;
615
616 case 0x18:
617 out(0xdf);
618 break;
619
620 case 0x20:
621 out(0xe7);
622 break;
623
624 case 0x28:
625 out(0xef);
626 break;
627
628 case 0x30:
629 out(0xf7);
630 break;
631
632 case 0x38:
633 out(0xff);
634 break;
635
636 default:
637 return 1;
638 }
639 return 0;
640 }
641
642
643 /* bit operations: set,res,bit */
644 /* offset: code of set(res,bit) x,B */
645 /* return value: 0=OK, 1=invalid argument, 8=value out of range */
646
647 int
c_bit(int b,int type,int value,int offset)648 c_bit(int b,int type,int value,int offset)
649 {
650 switch(type)
651 {
652 case A_REG:
653 switch(value)
654 {
655 case R_A:
656 out(0xcb);out(offset+7+(b<<3));
657 break;
658 case R_B:
659 out(0xcb);out(offset+(b<<3));
660 break;
661 case R_C:
662 out(0xcb);out(offset+1+(b<<3));
663 break;
664 case R_D:
665 out(0xcb);out(offset+2+(b<<3));
666 break;
667 case R_E:
668 out(0xcb);out(offset+3+(b<<3));
669 break;
670 case R_H:
671 out(0xcb);out(offset+4+(b<<3));
672 break;
673 case R_L:
674 out(0xcb);out(offset+5+(b<<3));
675 break;
676 default:
677 return 1;
678 }
679 break;
680
681 case A_PODLE_REG:
682 if (value!=R_HL)return 1;
683 out(0xcb);out(offset+6+(b<<3));
684 break;
685
686 case A_PODLE_IX_PLUS:
687 out(0xdd);out(0xcb);out(value);out(offset+6+(b<<3));
688 if (value>127||value<-128)return 9;
689 break;
690
691 case A_PODLE_IY_PLUS:
692 out(0xfd);out(0xcb);out(value);out(offset+6+(b<<3));
693 if (value>127||value<-128)return 9;
694 break;
695
696 default:
697 return 1;
698 }
699 return 0;
700 }
701
702
703 /* shift and rotation instructions */
704 /* rr,rl,rrc,rlc,sla,sra,srl,sll */
705 /* offset: code of rr(rl,...) B */
706 /* return value: 0=OK, 1=invalid argument, 8=value out of range */
707
708 int
c_shift_rot(int type,int value,int offset)709 c_shift_rot(int type,int value,int offset)
710 {
711 switch(type)
712 {
713 case A_REG:
714 switch(value)
715 {
716 case R_A:
717 out(0xcb);out(offset+7);
718 break;
719 case R_B:
720 out(0xcb);out(offset);
721 break;
722 case R_C:
723 out(0xcb);out(offset+1);
724 break;
725 case R_D:
726 out(0xcb);out(offset+2);
727 break;
728 case R_E:
729 out(0xcb);out(offset+3);
730 break;
731 case R_H:
732 out(0xcb);out(offset+4);
733 break;
734 case R_L:
735 out(0xcb);out(offset+5);
736 break;
737 default:
738 return 1;
739 }
740 break;
741
742 case A_PODLE_REG:
743 if (value!=R_HL) return 1;
744 out(0xcb);out(offset+6);
745 break;
746
747 case A_PODLE_IX_PLUS:
748 out(0xdd);out(0xcb);out(value);out(offset+6);
749 if (value>127||value<-128)return 9;
750 break;
751
752 case A_PODLE_IY_PLUS:
753 out(0xfd);out(0xcb);out(value);out(offset+6);
754 if (value>127||value<-128)return 9;
755 break;
756
757 default:
758 return 1;
759 }
760 return 0;
761 }
762
763
764 int
c_jp(int t1,int v1,int t2,int v2)765 c_jp(int t1,int v1,int t2,int v2)
766 {
767 if (t2==A_EMPTY)
768 switch (t1)
769 {
770 case A_REG:
771 case A_PODLE_REG:
772 switch(v1)
773 {
774 case R_HL:
775 out(0xe9);
776 break;
777 case R_IX:
778 out(0xdd);out(0xe9);
779 break;
780 case R_IY:
781 out(0xfd);out(0xe9);
782 break;
783 default:
784 return 1;
785 }
786 break;
787
788 case A_NUM:
789 out (0xc3);out(v1&255);out((v1>>8)&255);
790 break;
791
792 default:
793 return 1;
794 }
795 else
796 {
797 if (t1==A_REG)
798 {
799 if (v1!=R_C)return 1;
800 }
801 else {if (t1!=A_FLAG)return 1;}
802 if (t2!=A_NUM) return 1;
803 switch (v1)
804 {
805 case F_NZ:
806 out(0xc2);
807 break;
808 case F_Z:
809 out(0xca);
810 break;
811 case F_NC:
812 out(0xd2);
813 break;
814 case F_C:
815 out(0xda);
816 break;
817 case F_PO:
818 out(0xe2);
819 break;
820 case F_PE:
821 out(0xea);
822 break;
823 case F_P:
824 out(0xf2);
825 break;
826 case F_M:
827 out(0xfa);
828 break;
829 default:
830 return 1;
831 }
832 out(v2&255);
833 out((v2>>8)&255);
834 }
835 return 0;
836 }
837
838
839 int
c_call(int t1,int v1,int t2,int v2)840 c_call(int t1,int v1,int t2,int v2)
841 {
842 if (t2==A_EMPTY)
843 switch (t1)
844 {
845 case A_NUM:
846 out (0xcd);out(v1&255);out((v1>>8)&255);
847 break;
848
849 default:
850 return 1;
851 }
852
853 else
854 {
855 if (t1==A_REG)
856 {
857 if (v1!=R_C)return 1;
858 }
859 else {if (t1!=A_FLAG)return 1;}
860 if (t2!=A_NUM) return 1;
861 switch (v1)
862 {
863 case F_NZ:
864 out(0xc4);
865 break;
866 case F_Z:
867 out(0xcc);
868 break;
869 case F_NC:
870 out(0xd4);
871 break;
872 case F_C:
873 out(0xdc);
874 break;
875 case F_PO:
876 out(0xe4);
877 break;
878 case F_PE:
879 out(0xec);
880 break;
881 case F_P:
882 out(0xf4);
883 break;
884 case F_M:
885 out(0xfc);
886 break;
887 default:
888 return 1;
889 }
890 out(v2&255);
891 out((v2>>8)&255);
892 }
893 return 0;
894 }
895
896
897 /* return value: 0=OK, 1=invalid argument, 8=value out of range */
898
899 int
c_djnz(int t1,int v1)900 c_djnz(int t1,int v1)
901 {
902 int a;
903
904 switch (t1)
905 {
906 case A_NUM:
907 a=v1;
908 break;
909
910 default:
911 return 1;
912 }
913 out(0x10);
914 out ((char)a);
915 if (a>127||a<-128)return 9;
916 return 0;
917 }
918
919
920 /* return value: 0=OK, 1=invalid argument, 8=value out of range */
921
922 int
c_jr(int t1,int v1,int t2,int v2)923 c_jr(int t1,int v1,int t2,int v2)
924 {
925 int a,c;
926
927 if (t2==A_EMPTY)
928 {
929 switch (t1)
930 {
931 case A_NUM:
932 a=v1;
933 break;
934
935 default:
936 return 1;
937 }
938 out(0x18);
939 out ((char)a);
940 if (a>127||a<-128) return 9;
941 }
942 else
943 {
944 if (t1==A_REG)
945 {
946 if (v1!=R_C)return 1;
947 }
948 else {if (t1!=A_FLAG)return 1;}
949 switch(v1)
950 {
951 case F_NZ:
952 c=0x20;
953 break;
954 case F_Z:
955 c=0x28;
956 break;
957 case F_NC:
958 c=0x30;
959 break;
960 case F_C:
961 c=0x38;
962 break;
963 default:
964 return 1;
965 }
966 switch (t2)
967 {
968 case A_NUM:
969 a=v2;
970 break;
971
972 default:
973 return 1;
974 }
975 out(c);
976 out ((char)a);
977 if (a>127||a<-128) return 9;
978 }
979 return 0;
980 }
981
982
983 int
reg_num(int reg)984 reg_num(int reg)
985 {
986 switch(reg)
987 {
988 case R_A:
989 return 7;
990 case R_B:
991 return 0;
992 case R_C:
993 return 1;
994 case R_D:
995 return 2;
996 case R_E:
997 return 3;
998 case R_H:
999 return 4;
1000 case R_L:
1001 return 5;
1002 default:
1003 return 16;
1004 }
1005 }
1006
1007
1008 int
c_ld(int t1,int v1,int t2,int v2)1009 c_ld(int t1,int v1,int t2,int v2)
1010 {
1011 int a=0,b=0;
1012 switch (t1)
1013 {
1014 case A_REG: /* ld 8b-reg,?? */
1015 if (v1==R_A||v1==R_B||v1==R_C||v1==R_D||v1==R_E||v1==R_H||v1==R_L||v1==R_I||v1==R_R)
1016 switch (t2)
1017 {
1018 case A_REG: /* ld 8b-reg,8b-reg */
1019 if (v1==R_A&&v2==R_I){out(0xed);out(0x57);return 0;}
1020 if (v1==R_A&&v2==R_R){out(0xed);out(0x5f);return 0;}
1021 if (v2==R_A&&v1==R_I){out(0xed);out(0x47);return 0;}
1022 if (v2==R_A&&v1==R_R){out(0xed);out(0x4f);return 0;}
1023 a=reg_num(v1);
1024 b=reg_num(v2);
1025 if (a==16||b==16)return 1;
1026 out (b+(a<<3)+64);
1027 return 0;
1028
1029 case A_NUM: /* ld 8b-reg,num */
1030 a=reg_num(v1);
1031 if (a==16)return 1;
1032 out (6+(a<<3));out(v2);
1033 return v2>255 ? 8 : 0 ;
1034
1035 case A_PODLE_REG: /* ld 8b-reg,(16b-reg) */
1036 if (v1==R_A)
1037 {
1038 if (v2==R_BC){out (0x0a);return 0;}
1039 if (v2==R_DE){out (0x1a);return 0;}
1040 }
1041 if (v2!=R_HL)return 1;
1042 a=reg_num(v1);
1043 if (a==16)return 1;
1044 out (70+(a<<3));
1045 return 0;
1046
1047 case A_PODLE_NUM: /* ld 8b-reg,(addr) */
1048 if (v1!=R_A)return 1;
1049 out(0x3a);out(v2&255);out((v2>>8)&255);
1050 return 0;
1051
1052 case A_PODLE_IY_PLUS: /* ld 8b-reg,(ix/iy+num) */
1053 b=0xfd;
1054 case A_PODLE_IX_PLUS:
1055 if (!b)b=0xdd;
1056 a=reg_num(v1);
1057 if (a==16)return 1;
1058 out (b);out (70+(a<<3));out(v2);
1059 if (v2>127||v2<-128) return 9;
1060 return 0;
1061 }
1062
1063 switch (v1) /* ld 16b-reg,XX or ld 16b-reg,(XX) */
1064 {
1065 case R_BC:
1066 a=0;b=0;
1067 break;
1068 case R_DE:
1069 a=0x10;b=0;
1070 break;
1071 case R_HL:
1072 a=0x20;b=0;
1073 break;
1074 case R_IX:
1075 a=0x20;b=0xdd;
1076 break;
1077 case R_IY:
1078 b=0xfd;a=0x20;
1079 break;
1080 case R_SP:
1081 if (t2==A_REG) /* ld sp,hl/ix/iy */
1082 {
1083 if (v2==R_HL){out(0xf9);return 0;}
1084 if (v2==R_IX){out(0xdd);out(0xf9);return 0;}
1085 if (v2==R_IY){out(0xfd);out(0xf9);return 0;}
1086 return 1;
1087 }
1088 b=0;a=0x30;
1089 break;
1090 }
1091 switch (t2)
1092 {
1093 case A_NUM:
1094 if (b)out(b);
1095 out(a+1);out(v2&255);out((v2>>8)&255);
1096 return 0;
1097
1098 case A_PODLE_NUM:
1099 if (b){out(b);out(0xa+a);}
1100 else if (a==0x20) {out(0x2a);}
1101 else {out(0xed);out(0x4b+a);}
1102 out(v2&255);out((v2>>8)&255);
1103 return 0;
1104 }
1105 return 1;
1106
1107 case A_PODLE_REG: /* ld (16b-reg),?? */
1108 if (v1==R_HL&&t2==A_REG) /* ld (hl),8b-reg */
1109 {
1110 a=reg_num(v2);
1111 if (a==16)return 1;
1112 out (0x70+a);
1113 return 0;
1114 }
1115 if (v1==R_HL&&t2==A_NUM) /* ld (hl),num */
1116 {
1117 out(0x36);out(v2);
1118 return v2>255 ? 8 : 0 ;
1119 }
1120 if (t2==A_REG&&v2==R_A) /* ld (bc/de),a */
1121 {
1122 if (v1==R_BC){out(0x02);return 0;}
1123 if (v1==R_DE){out(0x12);return 0;}
1124 return 1;
1125 }
1126 return 1;
1127
1128 case A_PODLE_IX_PLUS: /* ld (ix+num),?? */
1129 a=0xdd;
1130 case A_PODLE_IY_PLUS:
1131 if (!a)a=0xfd;
1132 if (t2==A_REG) /* ld (ix/iy+num),8b-reg */
1133 {
1134 b=reg_num(v2);
1135 if (b==16)return 1;
1136 out (a);out(0x70+b);out(v1);
1137 if (v1>127||v1<-128) return 9;
1138 return 0;
1139 }
1140 if (t2==A_NUM) /* ld (ix/iy+num),num */
1141 {
1142 out (a);out(0x36);out(v1);out(v2);
1143 if (v1>127||v1<-128) return 9;
1144 return v2>255 ? 8 : 0 ;
1145 }
1146 return 1;
1147
1148 case A_PODLE_NUM: /* ld (addr),reg */
1149 if (t2!=A_REG)return 1;
1150 switch(v2)
1151 {
1152 case R_BC:
1153 out(0xed);out(0x43);
1154 break;
1155
1156 case R_A:
1157 out(0x32);
1158 break;
1159
1160 case R_DE:
1161 out(0xed);out(0x53);
1162 break;
1163
1164 case R_HL:
1165 out(0x22);
1166 break;
1167
1168 case R_IX:
1169 out(0xdd);out(0x22);
1170 break;
1171
1172 case R_IY:
1173 out(0xfd);out(0x22);
1174 break;
1175
1176 case R_SP:
1177 out (0xed);out(0x73);
1178 break;
1179
1180 default:
1181 return 1;
1182 }
1183 out(v1&255);
1184 out((v1>>8)&255);
1185 return 0;
1186 }
1187 return 1;
1188 }
1189