intel_8080_kit/dis/
mod.rs1use super::op::*;
5use std::fmt;
6
7#[derive(Debug, Clone)]
8pub struct OpError(usize);
9
10impl fmt::Display for OpError {
11 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12 write!(f, "expected {} bytes", self.0)
13 }
14}
15
16pub fn disassemble_raw(bin: &[u8]) -> Result<Vec<RawOpcode>, OpError> {
17 let mut ops = Vec::new();
18
19 let mut i = 0;
20 while i < bin.len() {
21 ops.push(match bin[i] {
22 0x00 => {
23 i += 1;
24 RawOpcode::NOP
25 }
26 0x01 => {
27 i += 3;
28 if i >= bin.len() {
29 return Err(OpError(i - bin.len()));
30 } else {
31 RawOpcode::LXI_B
32 }
33 }
34 0x02 => {
35 i += 1;
36 RawOpcode::STAX_B
37 }
38 0x03 => {
39 i += 1;
40 RawOpcode::INX_B
41 }
42 0x04 => {
43 i += 1;
44 RawOpcode::INR_B
45 }
46 0x05 => {
47 i += 1;
48 RawOpcode::DCR_B
49 }
50 0x06 => {
51 i += 2;
52 if i >= bin.len() {
53 return Err(OpError(i - bin.len()));
54 } else {
55 RawOpcode::MVI_B
56 }
57 }
58 0x07 => {
59 i += 1;
60 RawOpcode::RLC
61 }
62 0x09 => {
63 i += 1;
64 RawOpcode::DAD_B
65 }
66 0x0a => {
67 i += 1;
68 RawOpcode::LDAX_B
69 }
70 0x0b => {
71 i += 1;
72 RawOpcode::DCX_B
73 }
74 0x0c => {
75 i += 1;
76 RawOpcode::INR_C
77 }
78 0x0d => {
79 i += 1;
80 RawOpcode::DCR_C
81 }
82 0x0e => {
83 i += 2;
84 if i >= bin.len() {
85 return Err(OpError(i - bin.len()));
86 } else {
87 RawOpcode::MVI_C
88 }
89 }
90 0x0f => {
91 i += 1;
92 RawOpcode::RRC
93 }
94 0x11 => {
95 i += 3;
96 if i >= bin.len() {
97 return Err(OpError(i - bin.len()));
98 } else {
99 RawOpcode::LXI_D
100 }
101 }
102 0x12 => {
103 i += 1;
104 RawOpcode::STAX_D
105 }
106 0x13 => {
107 i += 1;
108 RawOpcode::INX_D
109 }
110 0x14 => {
111 i += 1;
112 RawOpcode::INR_D
113 }
114 0x15 => {
115 i += 1;
116 RawOpcode::DCR_D
117 }
118 0x16 => {
119 i += 2;
120 if i >= bin.len() {
121 return Err(OpError(i - bin.len()));
122 } else {
123 RawOpcode::MVI_D
124 }
125 }
126 0x17 => {
127 i += 1;
128 RawOpcode::RAL
129 }
130 0x19 => {
131 i += 1;
132 RawOpcode::DAD_D
133 }
134 0x1a => {
135 i += 1;
136 RawOpcode::LDAX_D
137 }
138 0x1b => {
139 i += 1;
140 RawOpcode::DCX_D
141 }
142 0x1c => {
143 i += 1;
144 RawOpcode::INR_E
145 }
146 0x1d => {
147 i += 1;
148 RawOpcode::DCR_E
149 }
150 0x1e => {
151 i += 2;
152 if i >= bin.len() {
153 return Err(OpError(i - bin.len()));
154 } else {
155 RawOpcode::MVI_E
156 }
157 }
158 0x1f => {
159 i += 1;
160 RawOpcode::RAR
161 }
162 0x21 => {
163 i += 3;
164 if i >= bin.len() {
165 return Err(OpError(i - bin.len()));
166 } else {
167 RawOpcode::LXI_H
168 }
169 }
170 0x22 => {
171 i += 3;
172 if i >= bin.len() {
173 return Err(OpError(i - bin.len()));
174 } else {
175 RawOpcode::SHLD
176 }
177 }
178 0x23 => {
179 i += 1;
180 RawOpcode::INX_H
181 }
182 0x24 => {
183 i += 1;
184 RawOpcode::INR_H
185 }
186 0x25 => {
187 i += 1;
188 RawOpcode::DCR_H
189 }
190 0x26 => {
191 i += 2;
192 if i >= bin.len() {
193 return Err(OpError(i - bin.len()));
194 } else {
195 RawOpcode::MVI_H
196 }
197 }
198 0x27 => {
199 i += 1;
200 RawOpcode::DAA
201 }
202 0x29 => {
203 i += 1;
204 RawOpcode::DAD_H
205 }
206 0x2a => {
207 i += 3;
208 if i >= bin.len() {
209 return Err(OpError(i - bin.len()));
210 } else {
211 RawOpcode::LHLD
212 }
213 }
214 0x2b => {
215 i += 1;
216 RawOpcode::DCX_H
217 }
218 0x2c => {
219 i += 1;
220 RawOpcode::INR_L
221 }
222 0x2d => {
223 i += 1;
224 RawOpcode::DCR_L
225 }
226 0x2e => {
227 i += 2;
228 if i >= bin.len() {
229 return Err(OpError(i - bin.len()));
230 } else {
231 RawOpcode::MVI_L
232 }
233 }
234 0x2f => {
235 i += 1;
236 RawOpcode::CMA
237 }
238 0x31 => {
239 i += 3;
240 if i >= bin.len() {
241 return Err(OpError(i - bin.len()));
242 } else {
243 RawOpcode::LXI_SP
244 }
245 }
246 0x32 => {
247 i += 3;
248 if i >= bin.len() {
249 return Err(OpError(i - bin.len()));
250 } else {
251 RawOpcode::STA
252 }
253 }
254 0x33 => {
255 i += 1;
256 RawOpcode::INX_SP
257 }
258 0x34 => {
259 i += 1;
260 RawOpcode::INR_M
261 }
262 0x35 => {
263 i += 1;
264 RawOpcode::DCR_M
265 }
266 0x36 => {
267 i += 2;
268 if i >= bin.len() {
269 return Err(OpError(i - bin.len()));
270 } else {
271 RawOpcode::MVI_M
272 }
273 }
274 0x37 => {
275 i += 1;
276 RawOpcode::STC
277 }
278 0x39 => {
279 i += 1;
280 RawOpcode::DAD_SP
281 }
282 0x3a => {
283 i += 3;
284 if i >= bin.len() {
285 return Err(OpError(i - bin.len()));
286 } else {
287 RawOpcode::LDA
288 }
289 }
290 0x3b => {
291 i += 1;
292 RawOpcode::DCX_SP
293 }
294 0x3c => {
295 i += 1;
296 RawOpcode::INR_A
297 }
298 0x3d => {
299 i += 1;
300 RawOpcode::DCR_A
301 }
302 0x3e => {
303 i += 2;
304 if i >= bin.len() {
305 return Err(OpError(i - bin.len()));
306 } else {
307 RawOpcode::MVI_A
308 }
309 }
310 0x3f => {
311 i += 1;
312 RawOpcode::CMC
313 }
314 0x40 => {
315 i += 1;
316 RawOpcode::MOV_B_B
317 }
318 0x41 => {
319 i += 1;
320 RawOpcode::MOV_B_C
321 }
322 0x42 => {
323 i += 1;
324 RawOpcode::MOV_B_D
325 }
326 0x43 => {
327 i += 1;
328 RawOpcode::MOV_B_E
329 }
330 0x44 => {
331 i += 1;
332 RawOpcode::MOV_B_H
333 }
334 0x45 => {
335 i += 1;
336 RawOpcode::MOV_B_L
337 }
338 0x46 => {
339 i += 1;
340 RawOpcode::MOV_B_M
341 }
342 0x47 => {
343 i += 1;
344 RawOpcode::MOV_B_A
345 }
346 0x48 => {
347 i += 1;
348 RawOpcode::MOV_C_B
349 }
350 0x49 => {
351 i += 1;
352 RawOpcode::MOV_C_C
353 }
354 0x4a => {
355 i += 1;
356 RawOpcode::MOV_C_D
357 }
358 0x4b => {
359 i += 1;
360 RawOpcode::MOV_C_E
361 }
362 0x4c => {
363 i += 1;
364 RawOpcode::MOV_C_H
365 }
366 0x4d => {
367 i += 1;
368 RawOpcode::MOV_C_L
369 }
370 0x4e => {
371 i += 1;
372 RawOpcode::MOV_C_M
373 }
374 0x4f => {
375 i += 1;
376 RawOpcode::MOV_C_A
377 }
378 0x50 => {
379 i += 1;
380 RawOpcode::MOV_D_B
381 }
382 0x51 => {
383 i += 1;
384 RawOpcode::MOV_D_C
385 }
386 0x52 => {
387 i += 1;
388 RawOpcode::MOV_D_D
389 }
390 0x53 => {
391 i += 1;
392 RawOpcode::MOV_D_E
393 }
394 0x54 => {
395 i += 1;
396 RawOpcode::MOV_D_H
397 }
398 0x55 => {
399 i += 1;
400 RawOpcode::MOV_D_L
401 }
402 0x56 => {
403 i += 1;
404 RawOpcode::MOV_D_M
405 }
406 0x57 => {
407 i += 1;
408 RawOpcode::MOV_D_A
409 }
410 0x58 => {
411 i += 1;
412 RawOpcode::MOV_E_B
413 }
414 0x59 => {
415 i += 1;
416 RawOpcode::MOV_E_C
417 }
418 0x5a => {
419 i += 1;
420 RawOpcode::MOV_E_D
421 }
422 0x5b => {
423 i += 1;
424 RawOpcode::MOV_E_E
425 }
426 0x5c => {
427 i += 1;
428 RawOpcode::MOV_E_H
429 }
430 0x5d => {
431 i += 1;
432 RawOpcode::MOV_E_L
433 }
434 0x5e => {
435 i += 1;
436 RawOpcode::MOV_E_M
437 }
438 0x5f => {
439 i += 1;
440 RawOpcode::MOV_E_A
441 }
442 0x60 => {
443 i += 1;
444 RawOpcode::MOV_H_B
445 }
446 0x61 => {
447 i += 1;
448 RawOpcode::MOV_H_C
449 }
450 0x62 => {
451 i += 1;
452 RawOpcode::MOV_H_D
453 }
454 0x63 => {
455 i += 1;
456 RawOpcode::MOV_H_E
457 }
458 0x64 => {
459 i += 1;
460 RawOpcode::MOV_H_H
461 }
462 0x65 => {
463 i += 1;
464 RawOpcode::MOV_H_L
465 }
466 0x66 => {
467 i += 1;
468 RawOpcode::MOV_H_M
469 }
470 0x67 => {
471 i += 1;
472 RawOpcode::MOV_H_A
473 }
474 0x68 => {
475 i += 1;
476 RawOpcode::MOV_L_B
477 }
478 0x69 => {
479 i += 1;
480 RawOpcode::MOV_L_C
481 }
482 0x6a => {
483 i += 1;
484 RawOpcode::MOV_L_D
485 }
486 0x6b => {
487 i += 1;
488 RawOpcode::MOV_L_E
489 }
490 0x6c => {
491 i += 1;
492 RawOpcode::MOV_L_H
493 }
494 0x6d => {
495 i += 1;
496 RawOpcode::MOV_L_L
497 }
498 0x6e => {
499 i += 1;
500 RawOpcode::MOV_L_M
501 }
502 0x6f => {
503 i += 1;
504 RawOpcode::MOV_L_A
505 }
506 0x70 => {
507 i += 1;
508 RawOpcode::MOV_M_B
509 }
510 0x71 => {
511 i += 1;
512 RawOpcode::MOV_M_C
513 }
514 0x72 => {
515 i += 1;
516 RawOpcode::MOV_M_D
517 }
518 0x73 => {
519 i += 1;
520 RawOpcode::MOV_M_E
521 }
522 0x74 => {
523 i += 1;
524 RawOpcode::MOV_M_H
525 }
526 0x75 => {
527 i += 1;
528 RawOpcode::MOV_M_L
529 }
530 0x76 => {
531 i += 1;
532 RawOpcode::HLT
533 }
534 0x77 => {
535 i += 1;
536 RawOpcode::MOV_M_A
537 }
538 0x78 => {
539 i += 1;
540 RawOpcode::MOV_A_B
541 }
542 0x79 => {
543 i += 1;
544 RawOpcode::MOV_A_C
545 }
546 0x7a => {
547 i += 1;
548 RawOpcode::MOV_A_D
549 }
550 0x7b => {
551 i += 1;
552 RawOpcode::MOV_A_E
553 }
554 0x7c => {
555 i += 1;
556 RawOpcode::MOV_A_H
557 }
558 0x7d => {
559 i += 1;
560 RawOpcode::MOV_A_L
561 }
562 0x7e => {
563 i += 1;
564 RawOpcode::MOV_A_M
565 }
566 0x7f => {
567 i += 1;
568 RawOpcode::MOV_A_A
569 }
570 0x80 => {
571 i += 1;
572 RawOpcode::ADD_B
573 }
574 0x81 => {
575 i += 1;
576 RawOpcode::ADD_C
577 }
578 0x82 => {
579 i += 1;
580 RawOpcode::ADD_D
581 }
582 0x83 => {
583 i += 1;
584 RawOpcode::ADD_E
585 }
586 0x84 => {
587 i += 1;
588 RawOpcode::ADD_H
589 }
590 0x85 => {
591 i += 1;
592 RawOpcode::ADD_L
593 }
594 0x86 => {
595 i += 1;
596 RawOpcode::ADD_M
597 }
598 0x87 => {
599 i += 1;
600 RawOpcode::ADD_A
601 }
602 0x88 => {
603 i += 1;
604 RawOpcode::ADC_B
605 }
606 0x89 => {
607 i += 1;
608 RawOpcode::ADC_C
609 }
610 0x8a => {
611 i += 1;
612 RawOpcode::ADC_D
613 }
614 0x8b => {
615 i += 1;
616 RawOpcode::ADC_E
617 }
618 0x8c => {
619 i += 1;
620 RawOpcode::ADC_H
621 }
622 0x8d => {
623 i += 1;
624 RawOpcode::ADC_L
625 }
626 0x8e => {
627 i += 1;
628 RawOpcode::ADC_M
629 }
630 0x8f => {
631 i += 1;
632 RawOpcode::ADC_A
633 }
634 0x90 => {
635 i += 1;
636 RawOpcode::SUB_B
637 }
638 0x91 => {
639 i += 1;
640 RawOpcode::SUB_C
641 }
642 0x92 => {
643 i += 1;
644 RawOpcode::SUB_D
645 }
646 0x93 => {
647 i += 1;
648 RawOpcode::SUB_E
649 }
650 0x94 => {
651 i += 1;
652 RawOpcode::SUB_H
653 }
654 0x95 => {
655 i += 1;
656 RawOpcode::SUB_L
657 }
658 0x96 => {
659 i += 1;
660 RawOpcode::SUB_M
661 }
662 0x97 => {
663 i += 1;
664 RawOpcode::SUB_A
665 }
666 0x98 => {
667 i += 1;
668 RawOpcode::SBB_B
669 }
670 0x99 => {
671 i += 1;
672 RawOpcode::SBB_C
673 }
674 0x9a => {
675 i += 1;
676 RawOpcode::SBB_D
677 }
678 0x9b => {
679 i += 1;
680 RawOpcode::SBB_E
681 }
682 0x9c => {
683 i += 1;
684 RawOpcode::SBB_H
685 }
686 0x9d => {
687 i += 1;
688 RawOpcode::SBB_L
689 }
690 0x9e => {
691 i += 1;
692 RawOpcode::SBB_M
693 }
694 0x9f => {
695 i += 1;
696 RawOpcode::SBB_A
697 }
698 0xa0 => {
699 i += 1;
700 RawOpcode::ANA_B
701 }
702 0xa1 => {
703 i += 1;
704 RawOpcode::ANA_C
705 }
706 0xa2 => {
707 i += 1;
708 RawOpcode::ANA_D
709 }
710 0xa3 => {
711 i += 1;
712 RawOpcode::ANA_E
713 }
714 0xa4 => {
715 i += 1;
716 RawOpcode::ANA_H
717 }
718 0xa5 => {
719 i += 1;
720 RawOpcode::ANA_L
721 }
722 0xa6 => {
723 i += 1;
724 RawOpcode::ANA_M
725 }
726 0xa7 => {
727 i += 1;
728 RawOpcode::ANA_A
729 }
730 0xa8 => {
731 i += 1;
732 RawOpcode::XRA_B
733 }
734 0xa9 => {
735 i += 1;
736 RawOpcode::XRA_C
737 }
738 0xaa => {
739 i += 1;
740 RawOpcode::XRA_D
741 }
742 0xab => {
743 i += 1;
744 RawOpcode::XRA_E
745 }
746 0xac => {
747 i += 1;
748 RawOpcode::XRA_H
749 }
750 0xad => {
751 i += 1;
752 RawOpcode::XRA_L
753 }
754 0xae => {
755 i += 1;
756 RawOpcode::XRA_M
757 }
758 0xaf => {
759 i += 1;
760 RawOpcode::XRA_A
761 }
762 0xb0 => {
763 i += 1;
764 RawOpcode::ORA_B
765 }
766 0xb1 => {
767 i += 1;
768 RawOpcode::ORA_C
769 }
770 0xb2 => {
771 i += 1;
772 RawOpcode::ORA_D
773 }
774 0xb3 => {
775 i += 1;
776 RawOpcode::ORA_E
777 }
778 0xb4 => {
779 i += 1;
780 RawOpcode::ORA_H
781 }
782 0xb5 => {
783 i += 1;
784 RawOpcode::ORA_L
785 }
786 0xb6 => {
787 i += 1;
788 RawOpcode::ORA_M
789 }
790 0xb7 => {
791 i += 1;
792 RawOpcode::ORA_A
793 }
794 0xb8 => {
795 i += 1;
796 RawOpcode::CMP_B
797 }
798 0xb9 => {
799 i += 1;
800 RawOpcode::CMP_C
801 }
802 0xba => {
803 i += 1;
804 RawOpcode::CMP_D
805 }
806 0xbb => {
807 i += 1;
808 RawOpcode::CMP_E
809 }
810 0xbc => {
811 i += 1;
812 RawOpcode::CMP_H
813 }
814 0xbd => {
815 i += 1;
816 RawOpcode::CMP_L
817 }
818 0xbe => {
819 i += 1;
820 RawOpcode::CMP_M
821 }
822 0xbf => {
823 i += 1;
824 RawOpcode::CMP_A
825 }
826 0xc0 => {
827 i += 1;
828 RawOpcode::RNZ
829 }
830 0xc1 => {
831 i += 1;
832 RawOpcode::POP_B
833 }
834 0xc2 => {
835 i += 3;
836 if i >= bin.len() {
837 return Err(OpError(i - bin.len()));
838 } else {
839 RawOpcode::JNZ
840 }
841 }
842 0xc3 => {
843 i += 3;
844 if i >= bin.len() {
845 return Err(OpError(i - bin.len()));
846 } else {
847 RawOpcode::JMP
848 }
849 }
850 0xc4 => {
851 i += 3;
852 if i >= bin.len() {
853 return Err(OpError(i - bin.len()));
854 } else {
855 RawOpcode::CNZ
856 }
857 }
858 0xc5 => {
859 i += 1;
860 RawOpcode::PUSH_B
861 }
862 0xc6 => {
863 i += 2;
864 if i >= bin.len() {
865 return Err(OpError(i - bin.len()));
866 } else {
867 RawOpcode::ADI
868 }
869 }
870 0xc7 => {
871 i += 1;
872 RawOpcode::RST_0
873 }
874 0xc8 => {
875 i += 1;
876 RawOpcode::RZ
877 }
878 0xc9 => {
879 i += 1;
880 RawOpcode::RET
881 }
882 0xca => {
883 i += 3;
884 if i >= bin.len() {
885 return Err(OpError(i - bin.len()));
886 } else {
887 RawOpcode::JZ
888 }
889 }
890 0xcc => {
891 i += 3;
892 if i >= bin.len() {
893 return Err(OpError(i - bin.len()));
894 } else {
895 RawOpcode::CZ
896 }
897 }
898 0xcd => {
899 i += 3;
900 if i >= bin.len() {
901 return Err(OpError(i - bin.len()));
902 } else {
903 RawOpcode::CALL
904 }
905 }
906 0xce => {
907 i += 2;
908 if i >= bin.len() {
909 return Err(OpError(i - bin.len()));
910 } else {
911 RawOpcode::ACI
912 }
913 }
914 0xcf => {
915 i += 1;
916 RawOpcode::RST_1
917 }
918 0xd0 => {
919 i += 1;
920 RawOpcode::RNC
921 }
922 0xd1 => {
923 i += 1;
924 RawOpcode::POP_D
925 }
926 0xd2 => {
927 i += 3;
928 if i >= bin.len() {
929 return Err(OpError(i - bin.len()));
930 } else {
931 RawOpcode::JNC
932 }
933 }
934 0xd3 => {
935 i += 2;
936 if i >= bin.len() {
937 return Err(OpError(i - bin.len()));
938 } else {
939 RawOpcode::OUT
940 }
941 }
942 0xd4 => {
943 i += 3;
944 if i >= bin.len() {
945 return Err(OpError(i - bin.len()));
946 } else {
947 RawOpcode::CNC
948 }
949 }
950 0xd5 => {
951 i += 1;
952 RawOpcode::PUSH_D
953 }
954 0xd6 => {
955 i += 2;
956 if i >= bin.len() {
957 return Err(OpError(i - bin.len()));
958 } else {
959 RawOpcode::SUI
960 }
961 }
962 0xd7 => {
963 i += 1;
964 RawOpcode::RST_2
965 }
966 0xd8 => {
967 i += 1;
968 RawOpcode::RC
969 }
970 0xda => {
971 i += 3;
972 if i >= bin.len() {
973 return Err(OpError(i - bin.len()));
974 } else {
975 RawOpcode::JC
976 }
977 }
978 0xdb => {
979 i += 2;
980 if i >= bin.len() {
981 return Err(OpError(i - bin.len()));
982 } else {
983 RawOpcode::IN
984 }
985 }
986 0xdc => {
987 i += 3;
988 if i >= bin.len() {
989 return Err(OpError(i - bin.len()));
990 } else {
991 RawOpcode::CC
992 }
993 }
994 0xde => {
995 i += 2;
996 if i >= bin.len() {
997 return Err(OpError(i - bin.len()));
998 } else {
999 RawOpcode::SBI
1000 }
1001 }
1002 0xdf => {
1003 i += 1;
1004 RawOpcode::RST_3
1005 }
1006 0xe0 => {
1007 i += 1;
1008 RawOpcode::RPO
1009 }
1010 0xe1 => {
1011 i += 1;
1012 RawOpcode::POP_H
1013 }
1014 0xe2 => {
1015 i += 3;
1016 if i >= bin.len() {
1017 return Err(OpError(i - bin.len()));
1018 } else {
1019 RawOpcode::JPO
1020 }
1021 }
1022 0xe3 => {
1023 i += 1;
1024 RawOpcode::XTHL
1025 }
1026 0xe4 => {
1027 i += 3;
1028 if i >= bin.len() {
1029 return Err(OpError(i - bin.len()));
1030 } else {
1031 RawOpcode::CPO
1032 }
1033 }
1034 0xe5 => {
1035 i += 1;
1036 RawOpcode::PUSH_H
1037 }
1038 0xe6 => {
1039 i += 2;
1040 if i >= bin.len() {
1041 return Err(OpError(i - bin.len()));
1042 } else {
1043 RawOpcode::ANI
1044 }
1045 }
1046 0xe7 => {
1047 i += 1;
1048 RawOpcode::RST_4
1049 }
1050 0xe8 => {
1051 i += 1;
1052 RawOpcode::RPE
1053 }
1054 0xe9 => {
1055 i += 1;
1056 RawOpcode::PCHL
1057 }
1058 0xea => {
1059 i += 3;
1060 if i >= bin.len() {
1061 return Err(OpError(i - bin.len()));
1062 } else {
1063 RawOpcode::JPE
1064 }
1065 }
1066 0xeb => {
1067 i += 1;
1068 RawOpcode::XCHG
1069 }
1070 0xec => {
1071 i += 3;
1072 if i >= bin.len() {
1073 return Err(OpError(i - bin.len()));
1074 } else {
1075 RawOpcode::CPE
1076 }
1077 }
1078 0xee => {
1079 i += 2;
1080 if i >= bin.len() {
1081 return Err(OpError(i - bin.len()));
1082 } else {
1083 RawOpcode::XRI
1084 }
1085 }
1086 0xef => {
1087 i += 1;
1088 RawOpcode::RST_5
1089 }
1090 0xf0 => {
1091 i += 1;
1092 RawOpcode::RP
1093 }
1094 0xf1 => {
1095 i += 1;
1096 RawOpcode::POP_PSW
1097 }
1098 0xf2 => {
1099 i += 3;
1100 if i >= bin.len() {
1101 return Err(OpError(i - bin.len()));
1102 } else {
1103 RawOpcode::JP
1104 }
1105 }
1106 0xf3 => {
1107 i += 1;
1108 RawOpcode::DI
1109 }
1110 0xf4 => {
1111 i += 3;
1112 if i >= bin.len() {
1113 return Err(OpError(i - bin.len()));
1114 } else {
1115 RawOpcode::CP
1116 }
1117 }
1118 0xf5 => {
1119 i += 1;
1120 RawOpcode::PUSH_PSW
1121 }
1122 0xf6 => {
1123 i += 2;
1124 if i >= bin.len() {
1125 return Err(OpError(i - bin.len()));
1126 } else {
1127 RawOpcode::ORI
1128 }
1129 }
1130 0xf7 => {
1131 i += 1;
1132 RawOpcode::RST_6
1133 }
1134 0xf8 => {
1135 i += 1;
1136 RawOpcode::RM
1137 }
1138 0xf9 => {
1139 i += 1;
1140 RawOpcode::SPHL
1141 }
1142 0xfa => {
1143 i += 3;
1144 if i >= bin.len() {
1145 return Err(OpError(i - bin.len()));
1146 } else {
1147 RawOpcode::JM
1148 }
1149 }
1150 0xfb => {
1151 i += 1;
1152 RawOpcode::EI
1153 }
1154 0xfc => {
1155 i += 3;
1156 if i >= bin.len() {
1157 return Err(OpError(i - bin.len()));
1158 } else {
1159 RawOpcode::CM
1160 }
1161 }
1162 0xfe => {
1163 i += 2;
1164 if i >= bin.len() {
1165 return Err(OpError(i - bin.len()));
1166 } else {
1167 RawOpcode::CPI
1168 }
1169 }
1170 0xff => {
1171 i += 1;
1172 RawOpcode::RST_7
1173 }
1174 _ => {
1175 i += 1;
1176 RawOpcode::NOP
1177 }
1178 });
1179 }
1180
1181 Ok(ops)
1182}
1183
1184pub fn disassemble(bin: &[u8]) -> Result<Vec<Opcode>, OpError> {
1185 let mut ops = Vec::new();
1186
1187 let mut i = 0;
1188 while i < bin.len() {
1189 ops.push(match bin[i] {
1190 0x00 => {
1191 i += 1;
1192 Opcode::Nop
1193 }
1194 0x01 => {
1195 i += 3;
1196 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1197 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1198 Opcode::LxiB(*b2, *b1)
1199 }
1200 0x02 => {
1201 i += 1;
1202 Opcode::StaxB
1203 }
1204 0x03 => {
1205 i += 1;
1206 Opcode::InxB
1207 }
1208 0x04 => {
1209 i += 1;
1210 Opcode::InrB
1211 }
1212 0x05 => {
1213 i += 1;
1214 Opcode::DcrB
1215 }
1216 0x06 => {
1217 i += 2;
1218 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1219 Opcode::MviB(*b1)
1220 }
1221 0x07 => {
1222 i += 1;
1223 Opcode::Rlc
1224 }
1225 0x09 => {
1226 i += 1;
1227 Opcode::DadB
1228 }
1229 0x0a => {
1230 i += 1;
1231 Opcode::LdaxB
1232 }
1233 0x0b => {
1234 i += 1;
1235 Opcode::DcxB
1236 }
1237 0x0c => {
1238 i += 1;
1239 Opcode::InrC
1240 }
1241 0x0d => {
1242 i += 1;
1243 Opcode::DcrC
1244 }
1245 0x0e => {
1246 i += 2;
1247 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1248 Opcode::MviC(*b1)
1249 }
1250 0x0f => {
1251 i += 1;
1252 Opcode::Rrc
1253 }
1254 0x11 => {
1255 i += 3;
1256 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1257 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1258 Opcode::LxiD(*b2, *b1)
1259 }
1260 0x12 => {
1261 i += 1;
1262 Opcode::StaxD
1263 }
1264 0x13 => {
1265 i += 1;
1266 Opcode::InxD
1267 }
1268 0x14 => {
1269 i += 1;
1270 Opcode::InrD
1271 }
1272 0x15 => {
1273 i += 1;
1274 Opcode::DcrD
1275 }
1276 0x16 => {
1277 i += 2;
1278 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1279 Opcode::MviD(*b1)
1280 }
1281 0x17 => {
1282 i += 1;
1283 Opcode::Ral
1284 }
1285 0x19 => {
1286 i += 1;
1287 Opcode::DadD
1288 }
1289 0x1a => {
1290 i += 1;
1291 Opcode::LdaxD
1292 }
1293 0x1b => {
1294 i += 1;
1295 Opcode::DcxD
1296 }
1297 0x1c => {
1298 i += 1;
1299 Opcode::InrE
1300 }
1301 0x1d => {
1302 i += 1;
1303 Opcode::DcrE
1304 }
1305 0x1e => {
1306 i += 2;
1307 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1308 Opcode::MviE(*b1)
1309 }
1310 0x1f => {
1311 i += 1;
1312 Opcode::Rar
1313 }
1314 0x21 => {
1315 i += 3;
1316 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1317 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1318 Opcode::LxiH(*b2, *b1)
1319 }
1320 0x22 => {
1321 i += 3;
1322 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1323 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1324 Opcode::Shld(u16::from_le_bytes([*b1, *b2]))
1325 }
1326 0x23 => {
1327 i += 1;
1328 Opcode::InxH
1329 }
1330 0x24 => {
1331 i += 1;
1332 Opcode::InrH
1333 }
1334 0x25 => {
1335 i += 1;
1336 Opcode::DcrH
1337 }
1338 0x26 => {
1339 i += 2;
1340 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1341 Opcode::MviH(*b1)
1342 }
1343 0x27 => {
1344 i += 1;
1345 Opcode::Daa
1346 }
1347 0x29 => {
1348 i += 1;
1349 Opcode::DadH
1350 }
1351 0x2a => {
1352 i += 3;
1353 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1354 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1355 Opcode::Lhld(u16::from_le_bytes([*b1, *b2]))
1356 }
1357 0x2b => {
1358 i += 1;
1359 Opcode::DcxH
1360 }
1361 0x2c => {
1362 i += 1;
1363 Opcode::InrL
1364 }
1365 0x2d => {
1366 i += 1;
1367 Opcode::DcrL
1368 }
1369 0x2e => {
1370 i += 2;
1371 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1372 Opcode::MviL(*b1)
1373 }
1374 0x2f => {
1375 i += 1;
1376 Opcode::Cma
1377 }
1378 0x31 => {
1379 i += 3;
1380 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1381 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1382 Opcode::LxiSp(*b2, *b1)
1383 }
1384 0x32 => {
1385 i += 3;
1386 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1387 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1388 Opcode::Sta(u16::from_le_bytes([*b1, *b2]))
1389 }
1390 0x33 => {
1391 i += 1;
1392 Opcode::InxSp
1393 }
1394 0x34 => {
1395 i += 1;
1396 Opcode::InrM
1397 }
1398 0x35 => {
1399 i += 1;
1400 Opcode::DcrM
1401 }
1402 0x36 => {
1403 i += 2;
1404 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1405 Opcode::MviM(*b1)
1406 }
1407 0x37 => {
1408 i += 1;
1409 Opcode::Stc
1410 }
1411 0x39 => {
1412 i += 1;
1413 Opcode::DadSp
1414 }
1415 0x3a => {
1416 i += 3;
1417 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1418 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1419 Opcode::Lda(u16::from_le_bytes([*b1, *b2]))
1420 }
1421 0x3b => {
1422 i += 1;
1423 Opcode::DcxSp
1424 }
1425 0x3c => {
1426 i += 1;
1427 Opcode::InrA
1428 }
1429 0x3d => {
1430 i += 1;
1431 Opcode::DcrA
1432 }
1433 0x3e => {
1434 i += 2;
1435 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1436 Opcode::MviA(*b1)
1437 }
1438 0x3f => {
1439 i += 1;
1440 Opcode::Cmc
1441 }
1442 0x40 => {
1443 i += 1;
1444 Opcode::MovBB
1445 }
1446 0x41 => {
1447 i += 1;
1448 Opcode::MovBC
1449 }
1450 0x42 => {
1451 i += 1;
1452 Opcode::MovBD
1453 }
1454 0x43 => {
1455 i += 1;
1456 Opcode::MovBE
1457 }
1458 0x44 => {
1459 i += 1;
1460 Opcode::MovBH
1461 }
1462 0x45 => {
1463 i += 1;
1464 Opcode::MovBL
1465 }
1466 0x46 => {
1467 i += 1;
1468 Opcode::MovBM
1469 }
1470 0x47 => {
1471 i += 1;
1472 Opcode::MovBA
1473 }
1474 0x48 => {
1475 i += 1;
1476 Opcode::MovCB
1477 }
1478 0x49 => {
1479 i += 1;
1480 Opcode::MovCC
1481 }
1482 0x4a => {
1483 i += 1;
1484 Opcode::MovCD
1485 }
1486 0x4b => {
1487 i += 1;
1488 Opcode::MovCE
1489 }
1490 0x4c => {
1491 i += 1;
1492 Opcode::MovCH
1493 }
1494 0x4d => {
1495 i += 1;
1496 Opcode::MovCL
1497 }
1498 0x4e => {
1499 i += 1;
1500 Opcode::MovCM
1501 }
1502 0x4f => {
1503 i += 1;
1504 Opcode::MovCA
1505 }
1506 0x50 => {
1507 i += 1;
1508 Opcode::MovDB
1509 }
1510 0x51 => {
1511 i += 1;
1512 Opcode::MovDC
1513 }
1514 0x52 => {
1515 i += 1;
1516 Opcode::MovDD
1517 }
1518 0x53 => {
1519 i += 1;
1520 Opcode::MovDE
1521 }
1522 0x54 => {
1523 i += 1;
1524 Opcode::MovDH
1525 }
1526 0x55 => {
1527 i += 1;
1528 Opcode::MovDL
1529 }
1530 0x56 => {
1531 i += 1;
1532 Opcode::MovDM
1533 }
1534 0x57 => {
1535 i += 1;
1536 Opcode::MovDA
1537 }
1538 0x58 => {
1539 i += 1;
1540 Opcode::MovEB
1541 }
1542 0x59 => {
1543 i += 1;
1544 Opcode::MovEC
1545 }
1546 0x5a => {
1547 i += 1;
1548 Opcode::MovED
1549 }
1550 0x5b => {
1551 i += 1;
1552 Opcode::MovEE
1553 }
1554 0x5c => {
1555 i += 1;
1556 Opcode::MovEH
1557 }
1558 0x5d => {
1559 i += 1;
1560 Opcode::MovEL
1561 }
1562 0x5e => {
1563 i += 1;
1564 Opcode::MovEM
1565 }
1566 0x5f => {
1567 i += 1;
1568 Opcode::MovEA
1569 }
1570 0x60 => {
1571 i += 1;
1572 Opcode::MovHB
1573 }
1574 0x61 => {
1575 i += 1;
1576 Opcode::MovHC
1577 }
1578 0x62 => {
1579 i += 1;
1580 Opcode::MovHD
1581 }
1582 0x63 => {
1583 i += 1;
1584 Opcode::MovHE
1585 }
1586 0x64 => {
1587 i += 1;
1588 Opcode::MovHH
1589 }
1590 0x65 => {
1591 i += 1;
1592 Opcode::MovHL
1593 }
1594 0x66 => {
1595 i += 1;
1596 Opcode::MovHM
1597 }
1598 0x67 => {
1599 i += 1;
1600 Opcode::MovHA
1601 }
1602 0x68 => {
1603 i += 1;
1604 Opcode::MovLB
1605 }
1606 0x69 => {
1607 i += 1;
1608 Opcode::MovLC
1609 }
1610 0x6a => {
1611 i += 1;
1612 Opcode::MovLD
1613 }
1614 0x6b => {
1615 i += 1;
1616 Opcode::MovLE
1617 }
1618 0x6c => {
1619 i += 1;
1620 Opcode::MovLH
1621 }
1622 0x6d => {
1623 i += 1;
1624 Opcode::MovLL
1625 }
1626 0x6e => {
1627 i += 1;
1628 Opcode::MovLM
1629 }
1630 0x6f => {
1631 i += 1;
1632 Opcode::MovLA
1633 }
1634 0x70 => {
1635 i += 1;
1636 Opcode::MovMB
1637 }
1638 0x71 => {
1639 i += 1;
1640 Opcode::MovMC
1641 }
1642 0x72 => {
1643 i += 1;
1644 Opcode::MovMD
1645 }
1646 0x73 => {
1647 i += 1;
1648 Opcode::MovME
1649 }
1650 0x74 => {
1651 i += 1;
1652 Opcode::MovMH
1653 }
1654 0x75 => {
1655 i += 1;
1656 Opcode::MovML
1657 }
1658 0x76 => {
1659 i += 1;
1660 Opcode::Hlt
1661 }
1662 0x77 => {
1663 i += 1;
1664 Opcode::MovMA
1665 }
1666 0x78 => {
1667 i += 1;
1668 Opcode::MovAB
1669 }
1670 0x79 => {
1671 i += 1;
1672 Opcode::MovAC
1673 }
1674 0x7a => {
1675 i += 1;
1676 Opcode::MovAD
1677 }
1678 0x7b => {
1679 i += 1;
1680 Opcode::MovAE
1681 }
1682 0x7c => {
1683 i += 1;
1684 Opcode::MovAH
1685 }
1686 0x7d => {
1687 i += 1;
1688 Opcode::MovAL
1689 }
1690 0x7e => {
1691 i += 1;
1692 Opcode::MovAM
1693 }
1694 0x7f => {
1695 i += 1;
1696 Opcode::MovAA
1697 }
1698 0x80 => {
1699 i += 1;
1700 Opcode::AddB
1701 }
1702 0x81 => {
1703 i += 1;
1704 Opcode::AddC
1705 }
1706 0x82 => {
1707 i += 1;
1708 Opcode::AddD
1709 }
1710 0x83 => {
1711 i += 1;
1712 Opcode::AddE
1713 }
1714 0x84 => {
1715 i += 1;
1716 Opcode::AddH
1717 }
1718 0x85 => {
1719 i += 1;
1720 Opcode::AddL
1721 }
1722 0x86 => {
1723 i += 1;
1724 Opcode::AddM
1725 }
1726 0x87 => {
1727 i += 1;
1728 Opcode::AddA
1729 }
1730 0x88 => {
1731 i += 1;
1732 Opcode::AdcB
1733 }
1734 0x89 => {
1735 i += 1;
1736 Opcode::AdcC
1737 }
1738 0x8a => {
1739 i += 1;
1740 Opcode::AdcD
1741 }
1742 0x8b => {
1743 i += 1;
1744 Opcode::AdcE
1745 }
1746 0x8c => {
1747 i += 1;
1748 Opcode::AdcH
1749 }
1750 0x8d => {
1751 i += 1;
1752 Opcode::AdcL
1753 }
1754 0x8e => {
1755 i += 1;
1756 Opcode::AdcM
1757 }
1758 0x8f => {
1759 i += 1;
1760 Opcode::AdcA
1761 }
1762 0x90 => {
1763 i += 1;
1764 Opcode::SubB
1765 }
1766 0x91 => {
1767 i += 1;
1768 Opcode::SubC
1769 }
1770 0x92 => {
1771 i += 1;
1772 Opcode::SubD
1773 }
1774 0x93 => {
1775 i += 1;
1776 Opcode::SubE
1777 }
1778 0x94 => {
1779 i += 1;
1780 Opcode::SubH
1781 }
1782 0x95 => {
1783 i += 1;
1784 Opcode::SubL
1785 }
1786 0x96 => {
1787 i += 1;
1788 Opcode::SubM
1789 }
1790 0x97 => {
1791 i += 1;
1792 Opcode::SubA
1793 }
1794 0x98 => {
1795 i += 1;
1796 Opcode::SbbB
1797 }
1798 0x99 => {
1799 i += 1;
1800 Opcode::SbbC
1801 }
1802 0x9a => {
1803 i += 1;
1804 Opcode::SbbD
1805 }
1806 0x9b => {
1807 i += 1;
1808 Opcode::SbbE
1809 }
1810 0x9c => {
1811 i += 1;
1812 Opcode::SbbH
1813 }
1814 0x9d => {
1815 i += 1;
1816 Opcode::SbbL
1817 }
1818 0x9e => {
1819 i += 1;
1820 Opcode::SbbM
1821 }
1822 0x9f => {
1823 i += 1;
1824 Opcode::SbbA
1825 }
1826 0xa0 => {
1827 i += 1;
1828 Opcode::AnaB
1829 }
1830 0xa1 => {
1831 i += 1;
1832 Opcode::AnaC
1833 }
1834 0xa2 => {
1835 i += 1;
1836 Opcode::AnaD
1837 }
1838 0xa3 => {
1839 i += 1;
1840 Opcode::AnaE
1841 }
1842 0xa4 => {
1843 i += 1;
1844 Opcode::AnaH
1845 }
1846 0xa5 => {
1847 i += 1;
1848 Opcode::AnaL
1849 }
1850 0xa6 => {
1851 i += 1;
1852 Opcode::AnaM
1853 }
1854 0xa7 => {
1855 i += 1;
1856 Opcode::AnaA
1857 }
1858 0xa8 => {
1859 i += 1;
1860 Opcode::XraB
1861 }
1862 0xa9 => {
1863 i += 1;
1864 Opcode::XraC
1865 }
1866 0xaa => {
1867 i += 1;
1868 Opcode::XraD
1869 }
1870 0xab => {
1871 i += 1;
1872 Opcode::XraE
1873 }
1874 0xac => {
1875 i += 1;
1876 Opcode::XraH
1877 }
1878 0xad => {
1879 i += 1;
1880 Opcode::XraL
1881 }
1882 0xae => {
1883 i += 1;
1884 Opcode::XraM
1885 }
1886 0xaf => {
1887 i += 1;
1888 Opcode::XraA
1889 }
1890 0xb0 => {
1891 i += 1;
1892 Opcode::OraB
1893 }
1894 0xb1 => {
1895 i += 1;
1896 Opcode::OraC
1897 }
1898 0xb2 => {
1899 i += 1;
1900 Opcode::OraD
1901 }
1902 0xb3 => {
1903 i += 1;
1904 Opcode::OraE
1905 }
1906 0xb4 => {
1907 i += 1;
1908 Opcode::OraH
1909 }
1910 0xb5 => {
1911 i += 1;
1912 Opcode::OraL
1913 }
1914 0xb6 => {
1915 i += 1;
1916 Opcode::OraM
1917 }
1918 0xb7 => {
1919 i += 1;
1920 Opcode::OraA
1921 }
1922 0xb8 => {
1923 i += 1;
1924 Opcode::CmpB
1925 }
1926 0xb9 => {
1927 i += 1;
1928 Opcode::CmpC
1929 }
1930 0xba => {
1931 i += 1;
1932 Opcode::CmpD
1933 }
1934 0xbb => {
1935 i += 1;
1936 Opcode::CmpE
1937 }
1938 0xbc => {
1939 i += 1;
1940 Opcode::CmpH
1941 }
1942 0xbd => {
1943 i += 1;
1944 Opcode::CmpL
1945 }
1946 0xbe => {
1947 i += 1;
1948 Opcode::CmpM
1949 }
1950 0xbf => {
1951 i += 1;
1952 Opcode::CmpA
1953 }
1954 0xc0 => {
1955 i += 1;
1956 Opcode::Rnz
1957 }
1958 0xc1 => {
1959 i += 1;
1960 Opcode::PopB
1961 }
1962 0xc2 => {
1963 i += 3;
1964 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1965 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1966 Opcode::Jnz(u16::from_le_bytes([*b1, *b2]))
1967 }
1968 0xc3 => {
1969 i += 3;
1970 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1971 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1972 Opcode::Jmp(u16::from_le_bytes([*b1, *b2]))
1973 }
1974 0xc4 => {
1975 i += 3;
1976 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
1977 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
1978 Opcode::Cnz(u16::from_le_bytes([*b1, *b2]))
1979 }
1980 0xc5 => {
1981 i += 1;
1982 Opcode::PushB
1983 }
1984 0xc6 => {
1985 i += 2;
1986 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
1987 Opcode::Adi(*b1)
1988 }
1989 0xc7 => {
1990 i += 1;
1991 Opcode::Rst0
1992 }
1993 0xc8 => {
1994 i += 1;
1995 Opcode::Rz
1996 }
1997 0xc9 => {
1998 i += 1;
1999 Opcode::Ret
2000 }
2001 0xca => {
2002 i += 3;
2003 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2004 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2005 Opcode::Jz(u16::from_le_bytes([*b1, *b2]))
2006 }
2007 0xcc => {
2008 i += 3;
2009 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2010 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2011 Opcode::Cz(u16::from_le_bytes([*b1, *b2]))
2012 }
2013 0xcd => {
2014 i += 3;
2015 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2016 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2017 Opcode::Call(u16::from_le_bytes([*b1, *b2]))
2018 }
2019 0xce => {
2020 i += 2;
2021 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2022 Opcode::Aci(*b1)
2023 }
2024 0xcf => {
2025 i += 1;
2026 Opcode::Rst1
2027 }
2028 0xd0 => {
2029 i += 1;
2030 Opcode::Rnc
2031 }
2032 0xd1 => {
2033 i += 1;
2034 Opcode::PopD
2035 }
2036 0xd2 => {
2037 i += 3;
2038 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2039 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2040 Opcode::Jnc(u16::from_le_bytes([*b1, *b2]))
2041 }
2042 0xd3 => {
2043 i += 2;
2044 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2045 Opcode::Out(*b1)
2046 }
2047 0xd4 => {
2048 i += 3;
2049 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2050 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2051 Opcode::Cnc(u16::from_le_bytes([*b1, *b2]))
2052 }
2053 0xd5 => {
2054 i += 1;
2055 Opcode::PushD
2056 }
2057 0xd6 => {
2058 i += 2;
2059 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2060 Opcode::Sui(*b1)
2061 }
2062 0xd7 => {
2063 i += 1;
2064 Opcode::Rst2
2065 }
2066 0xd8 => {
2067 i += 1;
2068 Opcode::Rc
2069 }
2070 0xda => {
2071 i += 3;
2072 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2073 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2074 Opcode::Jc(u16::from_le_bytes([*b1, *b2]))
2075 }
2076 0xdb => {
2077 i += 2;
2078 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2079 Opcode::In(*b1)
2080 }
2081 0xdc => {
2082 i += 3;
2083 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2084 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2085 Opcode::Cc(u16::from_le_bytes([*b1, *b2]))
2086 }
2087 0xde => {
2088 i += 2;
2089 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2090 Opcode::Sbi(*b1)
2091 }
2092 0xdf => {
2093 i += 1;
2094 Opcode::Rst3
2095 }
2096 0xe0 => {
2097 i += 1;
2098 Opcode::Rpo
2099 }
2100 0xe1 => {
2101 i += 1;
2102 Opcode::PopH
2103 }
2104 0xe2 => {
2105 i += 3;
2106 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2107 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2108 Opcode::Jpo(u16::from_le_bytes([*b1, *b2]))
2109 }
2110 0xe3 => {
2111 i += 1;
2112 Opcode::Xthl
2113 }
2114 0xe4 => {
2115 i += 3;
2116 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2117 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2118 Opcode::Cpo(u16::from_le_bytes([*b1, *b2]))
2119 }
2120 0xe5 => {
2121 i += 1;
2122 Opcode::PushH
2123 }
2124 0xe6 => {
2125 i += 2;
2126 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2127 Opcode::Ani(*b1)
2128 }
2129 0xe7 => {
2130 i += 1;
2131 Opcode::Rst4
2132 }
2133 0xe8 => {
2134 i += 1;
2135 Opcode::Rpe
2136 }
2137 0xe9 => {
2138 i += 1;
2139 Opcode::Pchl
2140 }
2141 0xea => {
2142 i += 3;
2143 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2144 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2145 Opcode::Jpe(u16::from_le_bytes([*b1, *b2]))
2146 }
2147 0xeb => {
2148 i += 1;
2149 Opcode::Xchg
2150 }
2151 0xec => {
2152 i += 3;
2153 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2154 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2155 Opcode::Cpe(u16::from_le_bytes([*b1, *b2]))
2156 }
2157 0xee => {
2158 i += 2;
2159 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2160 Opcode::Xri(*b1)
2161 }
2162 0xef => {
2163 i += 1;
2164 Opcode::Rst5
2165 }
2166 0xf0 => {
2167 i += 1;
2168 Opcode::Rp
2169 }
2170 0xf1 => {
2171 i += 1;
2172 Opcode::PopPsw
2173 }
2174 0xf2 => {
2175 i += 3;
2176 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2177 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2178 Opcode::Jp(u16::from_le_bytes([*b1, *b2]))
2179 }
2180 0xf3 => {
2181 i += 1;
2182 Opcode::Di
2183 }
2184 0xf4 => {
2185 i += 3;
2186 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2187 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2188 Opcode::Cp(u16::from_le_bytes([*b1, *b2]))
2189 }
2190 0xf5 => {
2191 i += 1;
2192 Opcode::PushPsw
2193 }
2194 0xf6 => {
2195 i += 2;
2196 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2197 Opcode::Ori(*b1)
2198 }
2199 0xf7 => {
2200 i += 1;
2201 Opcode::Rst6
2202 }
2203 0xf8 => {
2204 i += 1;
2205 Opcode::Rm
2206 }
2207 0xf9 => {
2208 i += 1;
2209 Opcode::Sphl
2210 }
2211 0xfa => {
2212 i += 3;
2213 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2214 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2215 Opcode::Jm(u16::from_le_bytes([*b1, *b2]))
2216 }
2217 0xfb => {
2218 i += 1;
2219 Opcode::Ei
2220 }
2221 0xfc => {
2222 i += 3;
2223 let b1 = bin.get(i - 2).ok_or(OpError(2))?;
2224 let b2 = bin.get(i - 1).ok_or(OpError(1))?;
2225 Opcode::Cm(u16::from_le_bytes([*b1, *b2]))
2226 }
2227 0xfe => {
2228 i += 2;
2229 let b1 = bin.get(i - 1).ok_or(OpError(1))?;
2230 Opcode::Cpi(*b1)
2231 }
2232 0xff => {
2233 i += 1;
2234 Opcode::Rst7
2235 }
2236 _ => {
2237 i += 1;
2238 Opcode::Nop
2239 }
2240 });
2241 }
2242
2243 Ok(ops)
2244}