main
z80.cpu
1info
2 prefix z80_
3 opcode_size 8
4 extra_tables cb ed dded fded ddcb fdcb dd fd
5 body z80_run_op
6 sync_cycle z80_sync_cycle
7 interrupt z80_interrupt
8 include z80_util.c
9 header z80.h
10
11declare
12 void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, memmap_chunk const * io_chunks, uint32_t num_io_chunks, uint32_t clock_divider, uint32_t io_address_mask);
13 z80_context * init_z80_context(z80_options *options);
14 void z80_run(z80_context *context, uint32_t target_cycle);
15 void z80_assert_reset(z80_context * context, uint32_t cycle);
16 void z80_clear_reset(z80_context * context, uint32_t cycle);
17 void z80_assert_busreq(z80_context * context, uint32_t cycle);
18 void z80_clear_busreq(z80_context * context, uint32_t cycle);
19 void z80_assert_nmi(z80_context *context, uint32_t cycle);
20 uint8_t z80_get_busack(z80_context * context, uint32_t cycle);
21 void z80_invalidate_code_range(z80_context *context, uint32_t start, uint32_t end);
22 void z80_adjust_cycles(z80_context * context, uint32_t deduction);
23 void z80_serialize(z80_context *context, serialize_buffer *buf);
24 void z80_deserialize(deserialize_buffer *buf, void *vcontext);
25 void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler);
26 void zremove_breakpoint(z80_context * context, uint16_t address);
27 void z80_options_free(z80_options *opts);
28 void z80_sync_cycle(z80_context *context, uint32_t target_cycle);
29
30regs
31 main 8 b c d e h l f a
32 alt 8 b' c' d' e' h' l' f' a'
33 i 8
34 r 8
35 rhigh 8
36 iff1 8
37 iff2 8
38 imode 8
39 sp 16
40 ix 16
41 iy 16
42 pc 16
43 wz 16
44 nflag 8
45 last_flag_result 8
46 pvflag 8
47 chflags 8
48 zflag 8
49 scratch1 16
50 scratch2 16
51 busreq 8
52 busack 8
53 reset 8
54 io_map ptrmemmap_chunk
55 io_chunks 32
56 io_mask 32
57 int_cycle 32
58 int_end_cycle 32
59 int_value 8
60 nmi_cycle 32
61 system ptrvoid
62 fastread ptr8 64
63 fastwrite ptr8 64
64 mem_pointers ptr8 4
65
66flags
67 register f
68 S 7 sign last_flag_result.7
69 Z 6 zero zflag
70 Y 5 bit-5 last_flag_result.5
71 H 4 half-carry chflags.3
72 P 2 parity pvflag
73 V 2 overflow pvflag
74 X 3 bit-3 last_flag_result.3
75 N 1 none nflag
76 C 0 carry chflags.7
77
78
79z80_op_fetch
80 cycles 1
81 add 1 r r
82 mov pc scratch1
83 ocall read_8
84 add 1 pc pc
85
86z80_run_op
87 #printf "Z80: %X @ %d\n" pc cycles
88 #printf "Z80: %X - A: %X, B: %X, C: %X D: %X, E: %X, H: %X, L: %X, SP: %X, IX: %X, IY: %X @ %d\n" pc a b c d e h l sp ix iy cycles
89 z80_op_fetch
90 dispatch scratch1
91
92z80_interrupt
93 cmp int_cycle cycles
94 if >=U
95
96 mov 0 iff1
97 mov 0 iff2
98 cycles 6
99 update_sync
100
101 switch imode
102 case 0
103 dispatch int_value
104
105 case 1
106 dispatch 0xFF
107
108 case 2
109 lsl i 8 pc
110 or int_value pc pc
111 #CD is call
112 dispatch 0xCD
113 end
114
115 else
116
117 cmp nmi_cycle cycles
118 if >=U
119
120 mov 0xFFFFFFFF nmi_cycle
121 mov 0 iff1
122 local pch 8
123 lsr pc 8 pch
124 meta high pch
125 meta low pc
126 z80_push
127 mov 0x66 pc
128 update_sync
129
130 end
131 end
132
133
13411001011 cb_prefix
135 z80_op_fetch
136 dispatch scratch1 cb
137
13811011101 dd_prefix
139 z80_op_fetch
140 dispatch scratch1 dd
141
14211101101 ed_prefix
143 z80_op_fetch
144 dispatch scratch1 ed
145
14611111101 fd_prefix
147 z80_op_fetch
148 dispatch scratch1 fd
149
150dd 11001011 ddcb_prefix
151 z80_calc_index ix
152 cycles 2
153 mov pc scratch1
154 ocall read_8
155 add 1 pc pc
156 dispatch scratch1 ddcb
157
158fd 11001011 fdcb_prefix
159 z80_calc_index iy
160 cycles 2
161 mov pc scratch1
162 ocall read_8
163 add 1 pc pc
164 dispatch scratch1 fdcb
165
166z80_check_cond
167 arg cond 8
168 local invert 8
169 switch cond
170 case 0
171 meta istrue invert
172 lnot zflag invert
173
174 case 1
175 meta istrue zflag
176
177 case 2
178 meta istrue invert
179 not chflags invert
180 and 0x80 invert invert
181
182 case 3
183 meta istrue invert
184 and 0x80 chflags invert
185
186 case 4
187 meta istrue invert
188 lnot pvflag invert
189
190 case 5
191 meta istrue pvflag
192
193 case 6
194 meta istrue invert
195 not last_flag_result invert
196 and 0x80 invert invert
197
198 case 7
199 meta istrue invert
200 and 0x80 last_flag_result invert
201
202 end
203
204z80_fetch_hl
205 lsl h 8 scratch1
206 or l scratch1 scratch1
207 ocall read_8
208
209z80_store_hl
210 lsl h 8 scratch2
211 or l scratch2 scratch2
212 ocall write_8
213
214z80_fetch_immed
215 mov pc scratch1
216 ocall read_8
217 add 1 pc pc
218
219z80_fetch_immed16
220 mov pc scratch1
221 ocall read_8
222 mov scratch1 wz
223 add 1 pc pc
224 mov pc scratch1
225 ocall read_8
226 add 1 pc pc
227 lsl scratch1 8 scratch1
228 or scratch1 wz wz
229
230z80_fetch_immed_reg16
231 mov pc scratch1
232 ocall read_8
233 mov scratch1 low
234 add 1 pc pc
235 mov pc scratch1
236 ocall read_8
237 mov scratch1 high
238 add 1 pc pc
239
240z80_fetch_immed_to_reg16
241 mov pc scratch1
242 ocall read_8
243 mov scratch1 reg
244 add 1 pc pc
245 mov pc scratch1
246 ocall read_8
247 add 1 pc pc
248 lsl scratch1 8 scratch1
249 or scratch1 reg reg
250
25101RRR110 ld_from_hl
252 z80_fetch_hl
253 mov scratch1 main.R
254
25501DDDSSS ld_from_reg
256 mov main.S main.D
257
258dd 01DDD100 ld_from_ixh
259 invalid D 6
260 lsr ix 8 main.D
261
262dd 01100SSS ld_to_ixh
263 invalid S 6
264 local tmp 16
265 and 0xFF ix ix
266 lsl main.S 8 tmp
267 or tmp ix ix
268
269dd 0110D10S ld_ixb_to_ixb
270
271dd 01DDD101 ld_from_ixl
272 invalid D 6
273 mov ix main.D
274
275dd 01101SSS ld_to_ixl
276 invalid S 6
277 and 0xFF00 ix ix
278 or main.S ix ix
279
280dd 01100101 ld_ixl_to_ixh
281 local tmp 16
282 lsl ix 8 tmp
283 and 0xFF ix ix
284 or tmp ix ix
285
286dd 01101100 ld_ixh_to_ixl
287 local tmp 16
288 lsr ix 8 tmp
289 and 0xFF00 ix ix
290 or tmp ix ix
291
292fd 01DDD100 ld_from_iyh
293 invalid D 6
294 lsr iy 8 main.D
295
296fd 01100SSS ld_to_iyh
297 invalid S 6
298 local tmp 16
299 and 0xFF iy iy
300 lsl main.S 8 tmp
301 or tmp iy iy
302
303fd 0110D10S ld_iyb_to_iyb
304
305fd 01DDD101 ld_from_iyl
306 invalid D 6
307 mov iy main.D
308
309fd 01101SSS ld_to_iyl
310 invalid S 6
311 and 0xFF00 iy iy
312 or main.S iy iy
313
314fd 01100101 ld_iyl_to_iyh
315 local tmp 16
316 lsl iy 8 tmp
317 and 0xFF iy iy
318 or tmp iy iy
319
320fd 01101100 ld_iyh_to_iyl
321 local tmp 16
322 lsr iy 8 tmp
323 and 0xFF00 iy iy
324 or tmp iy iy
325
326z80_calc_index
327 arg index 16
328 mov index wz
329 z80_fetch_immed
330 sext 16 scratch1 scratch1
331 add scratch1 wz wz
332
333z80_fetch_index
334 arg index 16
335 z80_calc_index index
336 mov wz scratch1
337 cycles 5
338 ocall read_8
339
340z80_store_index
341 mov wz scratch2
342 ocall write_8
343
344dd 01RRR110 ld_from_ix
345 z80_fetch_index ix
346 mov scratch1 main.R
347
348fd 01RRR110 ld_from_iy
349 z80_fetch_index iy
350 mov scratch1 main.R
351
35200RRR110 ld_immed
353 z80_fetch_immed
354 mov scratch1 main.R
355
356dd 00100110 ld_immed_ixh
357 z80_fetch_immed
358 lsl scratch1 8 scratch1
359 and 0xFF ix ix
360 or scratch1 ix ix
361
362dd 00101110 ld_immed_ixl
363 z80_fetch_immed
364 and 0xFF00 ix ix
365 or scratch1 ix ix
366
367fd 00100110 ld_immed_iyh
368 z80_fetch_immed
369 lsl scratch1 8 scratch1
370 and 0xFF iy iy
371 or scratch1 iy iy
372
373fd 00101110 ld_immed_iyl
374 z80_fetch_immed
375 and 0xFF00 iy iy
376 or scratch1 iy iy
377
37801110RRR ld_to_hl
379 mov main.R scratch1
380 z80_store_hl
381
382dd 01110RRR ld_to_ix
383 z80_calc_index ix
384 mov wz scratch2
385 mov main.R scratch1
386 cycles 5
387 ocall write_8
388
389fd 01110RRR ld_to_iy
390 z80_calc_index iy
391 mov wz scratch2
392 mov main.R scratch1
393 cycles 5
394 ocall write_8
395
39600110110 ld_to_hl_immed
397 z80_fetch_immed
398 z80_store_hl
399
400dd 00110110 ld_to_ixd_immed
401 z80_calc_index ix
402 z80_fetch_immed
403 cycles 2
404 mov wz scratch2
405 ocall write_8
406
407fd 00110110 ld_to_iyd_immed
408 z80_calc_index iy
409 z80_fetch_immed
410 cycles 2
411 mov wz scratch2
412 ocall write_8
413
41400001010 ld_a_from_bc
415 lsl b 8 wz
416 or c wz wz
417 mov wz scratch1
418 add 1 wz wz
419 ocall read_8
420 mov scratch1 a
421
42200011010 ld_a_from_de
423 lsl d 8 wz
424 or e wz wz
425 mov wz scratch1
426 add 1 wz wz
427 ocall read_8
428 mov scratch1 a
429
43000111010 ld_a_from_immed
431 z80_fetch_immed16
432 mov wz scratch1
433 add 1 wz wz
434 ocall read_8
435 mov scratch1 a
436
43700000010 ld_a_to_bc
438 local tmp 8
439 lsl b 8 scratch2
440 or c scratch2 scratch2
441 mov a scratch1
442 add c 1 tmp
443 lsl a 8 wz
444 or tmp wz wz
445 ocall write_8
446
44700010010 ld_a_to_de
448 local tmp 8
449 lsl d 8 scratch2
450 or e scratch2 scratch2
451 mov a scratch1
452 add e 1 tmp
453 lsl a 8 wz
454 or tmp wz wz
455 ocall write_8
456
45700110010 ld_a_to_immed
458 local tmp 16
459 z80_fetch_immed16
460 mov wz scratch2
461 mov a scratch1
462 add 1 wz wz
463 ocall write_8
464 and 0xFF wz wz
465 lsl a 8 tmp
466 or tmp wz wz
467
468ed 01000111 ld_i_a
469 mov a i
470 cycles 1
471
472ed 01001111 ld_r_a
473 mov a r
474 and 0x80 a rhigh
475 cycles 1
476
477ed 01011111 ld_a_r
478 cycles 1
479 and 0x7F r a
480 or rhigh a a
481 update_flags SZYH0XN0
482 mov iff2 pvflag
483
484ed 01010111 ld_a_i
485 cycles 1
486 mov i a
487 update_flags SZYH0XN0
488 mov iff2 pvflag
489
49000000001 ld_bc_immed
491 meta high b
492 meta low c
493 z80_fetch_immed_reg16
494
49500010001 ld_de_immed
496 meta high d
497 meta low e
498 z80_fetch_immed_reg16
499
50000100001 ld_hl_immed
501 meta high h
502 meta low l
503 z80_fetch_immed_reg16
504
50500110001 ld_sp_immed
506 meta reg sp
507 z80_fetch_immed_to_reg16
508
509dd 00100001 ld_ix_immed
510 meta reg ix
511 z80_fetch_immed_to_reg16
512
513fd 00100001 ld_iy_immed
514 meta reg iy
515 z80_fetch_immed_to_reg16
516
517z80_fetch16_from_immed
518 z80_fetch_immed16
519 mov wz scratch1
520 ocall read_8
521 mov scratch1 low
522 add 1 wz wz
523 mov wz scratch1
524 ocall read_8
525 mov scratch1 high
526 add 1 wz wz
527
52800101010 ld_hl_from_immed
529 meta low l
530 meta high h
531 z80_fetch16_from_immed
532
533ed 01001011 ld_bc_from_immed
534 meta low c
535 meta high b
536 z80_fetch16_from_immed
537
538ed 01011011 ld_de_from_immed
539 meta low e
540 meta high d
541 z80_fetch16_from_immed
542
543ed 01101011 ld_hl_from_immed_slow
544 meta low l
545 meta high h
546 z80_fetch16_from_immed
547
548z80_fetch_reg16_from_immed
549 z80_fetch_immed16
550 mov wz scratch1
551 ocall read_8
552 mov scratch1 reg
553 add 1 wz wz
554 mov wz scratch1
555 ocall read_8
556 lsl scratch1 8 scratch1
557 or scratch1 reg reg
558 add 1 wz wz
559
560ed 01111011 ld_sp_from_immed
561 meta reg sp
562 z80_fetch_reg16_from_immed
563
564dd 00101010 ld_ix_from_immed
565 meta reg ix
566 z80_fetch_reg16_from_immed
567
568fd 00101010 ld_iy_from_immed
569 meta reg iy
570 z80_fetch_reg16_from_immed
571
57200100010 ld_hl_to_immed
573 z80_fetch_immed16
574 mov wz scratch2
575 mov l scratch1
576 ocall write_8
577 add 1 wz wz
578 mov wz scratch2
579 mov h scratch1
580 ocall write_8
581 add 1 wz wz
582
583dd 00100010 ld_ix_to_immed
584 z80_fetch_immed16
585 mov wz scratch2
586 mov ix scratch1
587 ocall write_8
588 add 1 wz wz
589 mov wz scratch2
590 lsr ix 8 scratch1
591 ocall write_8
592 add 1 wz wz
593
594fd 00100010 ld_iy_to_immed
595 z80_fetch_immed16
596 mov wz scratch2
597 mov iy scratch1
598 ocall write_8
599 add 1 wz wz
600 mov wz scratch2
601 lsr iy 8 scratch1
602 ocall write_8
603 add 1 wz wz
604
605z80_regpair_to_immed
606 z80_fetch_immed16
607 mov wz scratch2
608 mov low scratch1
609 ocall write_8
610 add 1 wz wz
611 mov high scratch1
612 mov wz scratch2
613 ocall write_8
614 add 1 wz wz
615
616ed 01000011 ld_bc_to_immed
617 meta low c
618 meta high b
619 z80_regpair_to_immed
620
621ed 01010011 ld_de_to_immed
622 meta low e
623 meta high d
624 z80_regpair_to_immed
625
626ed 01100011 ld_hl_to_immed_slow
627 meta low l
628 meta high h
629 z80_regpair_to_immed
630
631ed 01110011 ld_sp_to_immed
632 meta low sp
633 local sph 8
634 lsr sp 8 sph
635 meta high sph
636 z80_regpair_to_immed
637
63811111001 ld_sp_hl
639 cycles 2
640 lsl h 8 sp
641 or l sp sp
642
643dd 11111001 ld_sp_ix
644 cycles 2
645 mov ix sp
646
647fd 11111001 ld_sp_iy
648 cycles 2
649 mov iy sp
650
651z80_push
652 cycles 1
653 sub 1 sp sp
654 mov sp scratch2
655 mov high scratch1
656 ocall write_8
657 sub 1 sp sp
658 mov sp scratch2
659 mov low scratch1
660 ocall write_8
661
66211000101 push_bc
663 meta high b
664 meta low c
665 z80_push
666
66711010101 push_de
668 meta high d
669 meta low e
670 z80_push
671
67211100101 push_hl
673 meta high h
674 meta low l
675 z80_push
676
67711110101 push_af
678 meta high a
679 meta low f
680 z80_push
681
682dd 11100101 push_ix
683 local ixh 8
684 lsr ix 8 ixh
685 meta high ixh
686 meta low ix
687 z80_push
688
689fd 11100101 push_iy
690 local iyh 8
691 lsr iy 8 iyh
692 meta high iyh
693 meta low iy
694 z80_push
695
696z80_pop
697 mov sp scratch1
698 ocall read_8
699 add 1 sp sp
700 mov scratch1 low
701 mov sp scratch1
702 ocall read_8
703 add 1 sp sp
704 mov scratch1 high
705
70611000001 pop_bc
707 meta high b
708 meta low c
709 z80_pop
710
71111010001 pop_de
712 meta high d
713 meta low e
714 z80_pop
715
71611100001 pop_hl
717 meta high h
718 meta low l
719 z80_pop
720
72111110001 pop_af
722 meta high a
723 meta low f
724 z80_pop
725
726dd 11100001 pop_ix
727 local ixh 16
728 meta high ixh
729 meta low ix
730 z80_pop
731 lsl ixh 8 ixh
732 or ixh ix ix
733
734fd 11100001 pop_iy
735 local iyh 16
736 meta high iyh
737 meta low iy
738 z80_pop
739 lsl iyh 8 iyh
740 or iyh iy iy
741
74211101011 ex_de_hl
743 xchg e l
744 xchg d h
745
74600001000 ex_af_af
747 xchg a a'
748 xchg f f'
749
75011011001 exx
751 xchg b b'
752 xchg c c'
753 xchg d d'
754 xchg e e'
755 xchg h h'
756 xchg l l'
757
75811100011 ex_sp_hl
759 mov sp scratch1
760 ocall read_8
761 xchg l scratch1
762 cycles 1
763 mov sp scratch2
764 ocall write_8
765 add 1 sp scratch1
766 ocall read_8
767 xchg h scratch1
768 cycles 2
769 add 1 sp scratch2
770 ocall write_8
771 lsl h 8 wz
772 or l wz wz
773
774dd 11100011 ex_sp_ix
775 mov sp scratch1
776 ocall read_8
777 mov scratch1 wz
778 mov ix scratch1
779 cycles 1
780 mov sp scratch2
781 ocall write_8
782 add 1 sp scratch1
783 ocall read_8
784 lsl scratch1 8 scratch1
785 or scratch1 wz wz
786 lsr ix 8 scratch1
787 cycles 2
788 add 1 sp scratch2
789 ocall write_8
790 mov wz ix
791
792fd 11100011 ex_sp_iy
793 mov sp scratch1
794 ocall read_8
795 mov scratch1 wz
796 mov iy scratch1
797 cycles 1
798 mov sp scratch2
799 ocall write_8
800 add 1 sp scratch1
801 ocall read_8
802 lsl scratch1 8 scratch1
803 or scratch1 wz wz
804 lsr iy 8 scratch1
805 cycles 2
806 add 1 sp scratch2
807 ocall write_8
808 mov wz iy
809
81010000RRR add_reg
811 add a main.R a
812 update_flags SZYHVXN0C
813
814dd 10000100 add_ixh
815 lsr ix 8 scratch1
816 add a scratch1 a
817 update_flags SZYHVXN0C
818
819dd 10000101 add_ixl
820 and ix 0xFF scratch1
821 add a scratch1 a
822 update_flags SZYHVXN0C
823
824fd 10000100 add_iyh
825 lsr iy 8 scratch1
826 add a scratch1 a
827 update_flags SZYHVXN0C
828
829fd 10000101 add_iyl
830 and iy 0xFF scratch1
831 add a scratch1 a
832 update_flags SZYHVXN0C
833
83410000110 add_hl
835 z80_fetch_hl
836 add a scratch1 a
837 update_flags SZYHVXN0C
838
839dd 10000110 add_ixd
840 z80_fetch_index ix
841 add a scratch1 a
842 update_flags SZYHVXN0C
843
844fd 10000110 add_iyd
845 z80_fetch_index iy
846 add a scratch1 a
847 update_flags SZYHVXN0C
848
84911000110 add_immed
850 z80_fetch_immed
851 add a scratch1 a
852 update_flags SZYHVXN0C
853
854z80_add16_hl
855 arg src 16
856 lsl h 8 hlt
857 or l hlt hlt
858 add 1 hlt wz
859 add src hlt hlt
860 update_flags YHXN0C
861 mov hlt l
862 lsr hlt 8 h
863 cycles 7
864
86500001001 add_hl_bc
866 local hlw 16
867 local bcw 16
868 meta hlt hlw
869 lsl b 8 bcw
870 or c bcw bcw
871 z80_add16_hl bcw
872
87300011001 add_hl_de
874 local hlw 16
875 local dew 16
876 meta hlt hlw
877 lsl d 8 dew
878 or e dew dew
879 z80_add16_hl dew
880
88100101001 add_hl_hl
882 local hlw 16
883 meta hlt hlw
884 z80_add16_hl hlw
885
88600111001 add_hl_sp
887 local hlw 16
888 meta hlt hlw
889 z80_add16_hl sp
890
891dd 00001001 add_ix_bc
892 lsl b 8 scratch1
893 or c scratch1 scratch1
894 add scratch1 ix ix
895 update_flags YHXN0C
896 cycles 7
897
898dd 00011001 add_ix_de
899 lsl d 8 scratch1
900 or e scratch1 scratch1
901 add scratch1 ix ix
902 update_flags YHXN0C
903 cycles 7
904
905dd 00101001 add_ix_ix
906 add ix ix ix
907 update_flags YHXN0C
908 cycles 7
909
910dd 00111001 add_ix_sp
911 add sp ix ix
912 update_flags YHXN0C
913 cycles 7
914
915fd 00001001 add_iy_bc
916 lsl b 8 scratch1
917 or c scratch1 scratch1
918 add scratch1 iy iy
919 update_flags YHXN0C
920 cycles 7
921
922fd 00011001 add_iy_de
923 lsl d 8 scratch1
924 or e scratch1 scratch1
925 add scratch1 iy iy
926 update_flags YHXN0C
927 cycles 7
928
929fd 00101001 add_iy_iy
930 add iy iy iy
931 update_flags YHXN0C
932 cycles 7
933
934fd 00111001 add_iy_sp
935 add sp iy iy
936 update_flags YHXN0C
937 cycles 7
938
93910001RRR adc_reg
940 adc a main.R a
941 update_flags SZYHVXN0C
942
943dd 10001100 adc_ixh
944 lsr ix 8 scratch1
945 adc a scratch1 a
946 update_flags SZYHVXN0C
947
948dd 10001101 adc_ixl
949 and ix 0xFF scratch1
950 adc a scratch1 a
951 update_flags SZYHVXN0C
952
953fd 10001100 adc_iyh
954 lsr iy 8 scratch1
955 adc a scratch1 a
956 update_flags SZYHVXN0C
957
958fd 10001101 adc_iyl
959 and iy 0xFF scratch1
960 adc a scratch1 a
961 update_flags SZYHVXN0C
962
96310001110 adc_hl
964 z80_fetch_hl
965 adc a scratch1 a
966 update_flags SZYHVXN0C
967
968dd 10001110 adc_ixd
969 z80_fetch_index ix
970 adc a scratch1 a
971 update_flags SZYHVXN0C
972
973fd 10001110 adc_iyd
974 z80_fetch_index iy
975 adc a scratch1 a
976 update_flags SZYHVXN0C
977
97811001110 adc_immed
979 z80_fetch_immed
980 adc a scratch1 a
981 update_flags SZYHVXN0C
982
983z80_adc16_hl
984 arg src 16
985 lsl h 8 hlt
986 or l hlt hlt
987 add 1 hlt wz
988 adc src hlt hlt
989 update_flags SZYHVXN0C
990 mov hlt l
991 lsr hlt 8 h
992 cycles 7
993
994ed 01001010 adc_hl_bc
995 local hlw 16
996 local bcw 16
997 meta hlt hlw
998 lsl b 8 bcw
999 or c bcw bcw
1000 z80_adc16_hl bcw
1001
1002ed 01011010 adc_hl_de
1003 local hlw 16
1004 local dew 16
1005 meta hlt hlw
1006 lsl d 8 dew
1007 or e dew dew
1008 z80_adc16_hl dew
1009
1010ed 01101010 adc_hl_hl
1011 local hlw 16
1012 meta hlt hlw
1013 z80_adc16_hl hlw
1014
1015
1016ed 01111010 adc_hl_sp
1017 local hlw 16
1018 meta hlt hlw
1019 z80_adc16_hl sp
1020
102110010RRR sub_reg
1022 sub main.R a a
1023 update_flags SZYHVXN1C
1024
1025dd 10010100 sub_ixh
1026 lsr ix 8 scratch1
1027 sub scratch1 a a
1028 update_flags SZYHVXN1C
1029
1030dd 10010101 sub_ixl
1031 and ix 0xFF scratch1
1032 sub scratch1 a a
1033 update_flags SZYHVXN1C
1034
1035fd 10010100 sub_iyh
1036 lsr iy 8 scratch1
1037 sub scratch1 a a
1038 update_flags SZYHVXN1C
1039
1040fd 10010101 sub_iyl
1041 and iy 0xFF scratch1
1042 sub scratch1 a a
1043 update_flags SZYHVXN1C
1044
104510010110 sub_hl
1046 z80_fetch_hl
1047 sub scratch1 a a
1048 update_flags SZYHVXN1C
1049
1050dd 10010110 sub_ixd
1051 z80_fetch_index ix
1052 sub scratch1 a a
1053 update_flags SZYHVXN1C
1054
1055fd 10010110 sub_iyd
1056 z80_fetch_index iy
1057 sub scratch1 a a
1058 update_flags SZYHVXN1C
1059
106011010110 sub_immed
1061 z80_fetch_immed
1062 sub scratch1 a a
1063 update_flags SZYHVXN1C
1064
106510011RRR sbc_reg
1066 sbc main.R a a
1067 update_flags SZYHVXN1C
1068
1069dd 10011100 sbc_ixh
1070 lsr ix 8 scratch1
1071 sbc scratch1 a a
1072 update_flags SZYHVXN1C
1073
1074dd 10011101 sbc_ixl
1075 and ix 0xFF scratch1
1076 sbc scratch1 a a
1077 update_flags SZYHVXN1C
1078
1079fd 10011100 sbc_iyh
1080 lsr iy 8 scratch1
1081 sbc scratch1 a a
1082 update_flags SZYHVXN1C
1083
1084fd 10011101 sbc_iyl
1085 and iy 0xFF scratch1
1086 sbc scratch1 a a
1087 update_flags SZYHVXN1C
1088
1089
109010011110 sbc_hl
1091 z80_fetch_hl
1092 sbc scratch1 a a
1093 update_flags SZYHVXN1C
1094
1095dd 10011110 sbc_ixd
1096 z80_fetch_index ix
1097 sbc scratch1 a a
1098 update_flags SZYHVXN1C
1099
1100fd 10011110 sbc_iyd
1101 z80_fetch_index iy
1102 sbc scratch1 a a
1103 update_flags SZYHVXN1C
1104
110511011110 sbc_immed
1106 z80_fetch_immed
1107 sbc scratch1 a a
1108 update_flags SZYHVXN1C
1109
1110z80_sbc16_hl
1111 arg src 16
1112 lsl h 8 hlt
1113 or l hlt hlt
1114 add 1 hlt wz
1115 sbc src hlt hlt
1116 update_flags SZYHVXN1C
1117 mov hlt l
1118 lsr hlt 8 h
1119 cycles 7
1120
1121ed 01000010 sbc_hl_bc
1122 local hlw 16
1123 local bcw 16
1124 meta hlt hlw
1125 lsl b 8 bcw
1126 or c bcw bcw
1127 z80_sbc16_hl bcw
1128
1129ed 01010010 sbc_hl_de
1130 local hlw 16
1131 local dew 16
1132 meta hlt hlw
1133 lsl d 8 dew
1134 or e dew dew
1135 z80_sbc16_hl dew
1136
1137ed 01100010 sbc_hl_hl
1138 local hlw 16
1139 meta hlt hlw
1140 z80_sbc16_hl hlw
1141
1142
1143ed 01110010 sbc_hl_sp
1144 local hlw 16
1145 meta hlt hlw
1146 z80_sbc16_hl sp
1147
114810100RRR and_reg
1149 and a main.R a
1150 update_flags SZYH1PXN0C0
1151
1152dd 10100100 and_ixh
1153 lsr ix 8 scratch1
1154 and scratch1 a a
1155 update_flags SZYH1PXN0C0
1156
1157dd 10100101 and_ixl
1158 and ix a a
1159 update_flags SZYH1PXN0C0
1160
1161fd 10100100 and_iyh
1162 lsr iy 8 scratch1
1163 and scratch1 a a
1164 update_flags SZYH1PXN0C0
1165
1166fd 10100101 and_iyl
1167 and iy a a
1168 update_flags SZYH1PXN0C0
1169
117010100110 and_hl
1171 z80_fetch_hl
1172 and a scratch1 a
1173 update_flags SZYH1PXN0C0
1174
1175dd 10100110 and_ixd
1176 z80_fetch_index ix
1177 and a scratch1 a
1178 update_flags SZYH1PXN0C0
1179
1180fd 10100110 and_iyd
1181 z80_fetch_index iy
1182 and a scratch1 a
1183 update_flags SZYH1PXN0C0
1184
118511100110 and_immed
1186 z80_fetch_immed
1187 and a scratch1 a
1188 update_flags SZYH1PXN0C0
1189
119010110RRR or_reg
1191 or a main.R a
1192 update_flags SZYH0PXN0C0
1193
1194dd 10110100 or_ixh
1195 lsr ix 8 scratch1
1196 or scratch1 a a
1197 update_flags SZYH0PXN0C0
1198
1199dd 10110101 or_ixl
1200 or ix a a
1201 update_flags SZYH0PXN0C0
1202
1203fd 10110100 or_iyh
1204 lsr iy 8 scratch1
1205 or scratch1 a a
1206 update_flags SZYH0PXN0C0
1207
1208fd 10110101 or_iyl
1209 or iy a a
1210 update_flags SZYH0PXN0C0
1211
121210110110 or_hl
1213 z80_fetch_hl
1214 or a scratch1 a
1215 update_flags SZYH0PXN0C0
1216
1217dd 10110110 or_ixd
1218 z80_fetch_index ix
1219 or a scratch1 a
1220 update_flags SZYH0PXN0C0
1221
1222fd 10110110 or_iyd
1223 z80_fetch_index iy
1224 or a scratch1 a
1225 update_flags SZYH0PXN0C0
1226
122711110110 or_immed
1228 z80_fetch_immed
1229 or a scratch1 a
1230 update_flags SZYH0PXN0C0
1231
123210101RRR xor_reg
1233 xor a main.R a
1234 update_flags SZYH0PXN0C0
1235
1236dd 10101100 xor_ixh
1237 lsr ix 8 scratch1
1238 xor scratch1 a a
1239 update_flags SZYH0PXN0C0
1240
1241dd 10101101 xor_ixl
1242 xor ix a a
1243 update_flags SZYH0PXN0C0
1244
1245fd 10101100 xor_iyh
1246 lsr iy 8 scratch1
1247 xor scratch1 a a
1248 update_flags SZYH0PXN0C0
1249
1250fd 10101101 xor_iyl
1251 xor iy a a
1252 update_flags SZYH0PXN0C0
1253
125410101110 xor_hl
1255 z80_fetch_hl
1256 xor a scratch1 a
1257 update_flags SZYH0PXN0C0
1258
1259dd 10101110 xor_ixd
1260 z80_fetch_index ix
1261 xor a scratch1 a
1262 update_flags SZYH0PXN0C0
1263
1264fd 10101110 xor_iyd
1265 z80_fetch_index iy
1266 xor a scratch1 a
1267 update_flags SZYH0PXN0C0
1268
126911101110 xor_immed
1270 z80_fetch_immed
1271 xor a scratch1 a
1272 update_flags SZYH0PXN0C0
1273
127410111RRR cp_reg
1275 mov main.R last_flag_result
1276 cmp main.R a
1277 update_flags SZHVN1C
1278
1279dd 10111100 cp_ixh
1280 local tmp 8
1281 lsr ix 8 tmp
1282 mov tmp last_flag_result
1283 cmp tmp a
1284 update_flags SZHVN1C
1285
1286dd 10111101 cp_ixl
1287 local tmp 8
1288 mov ix tmp
1289 mov ix last_flag_result
1290 cmp tmp a
1291 update_flags SZHVN1C
1292
1293fd 10111100 cp_iyh
1294 local tmp 8
1295 lsr iy 8 tmp
1296 mov tmp last_flag_result
1297 cmp tmp a
1298 update_flags SZHVN1C
1299
1300fd 10111101 cp_iyl
1301 local tmp 8
1302 mov iy tmp
1303 mov iy last_flag_result
1304 cmp tmp a
1305 update_flags SZHVN1C
1306
130710111110 cp_hl
1308 local tmp 8
1309 z80_fetch_hl
1310 mov scratch1 tmp
1311 mov scratch1 last_flag_result
1312 cmp tmp a
1313 update_flags SZHVN1C
1314
1315dd 10111110 cp_ixd
1316 local tmp 8
1317 z80_fetch_index ix
1318 mov scratch1 tmp
1319 mov scratch1 last_flag_result
1320 cmp tmp a
1321 update_flags SZHVN1C
1322
1323fd 10111110 cp_iyd
1324 local tmp 8
1325 z80_fetch_index iy
1326 mov scratch1 tmp
1327 mov scratch1 last_flag_result
1328 cmp tmp a
1329 update_flags SZHVN1C
1330
133111111110 cp_immed
1332 local tmp 8
1333 z80_fetch_immed
1334 mov scratch1 tmp
1335 mov scratch1 last_flag_result
1336 cmp tmp a
1337 update_flags SZHVN1C
1338
133900RRR100 inc_reg
1340 add 1 main.R main.R
1341 update_flags SZYHVXN0
1342
1343dd 00100100 inc_ixh
1344 add 0x100 ix ix
1345 update_flags SZYHVXN0
1346
1347dd 00101100 inc_ixl
1348 local tmp 8
1349 mov ix tmp
1350 add 1 tmp tmp
1351 update_flags SZYHVXN0
1352 and 0xFF00 ix ix
1353 or tmp ix ix
1354
1355fd 00100100 inc_iyh
1356 add 0x100 iy iy
1357 update_flags SZYHVXN0
1358
1359fd 00101100 inc_iyl
1360 local tmp 8
1361 mov iy tmp
1362 add 1 tmp tmp
1363 update_flags SZYHVXN0
1364 and 0xFF00 iy iy
1365 or tmp iy iy
1366
136700110100 inc_hl
1368 local tmp 8
1369 z80_fetch_hl
1370 #TODO: Either make DSL compiler smart enough to optimize these unnecessary moves out
1371 #or add some syntax to force a certain size on an operation so they are unnecessary
1372 mov scratch1 tmp
1373 add 1 tmp tmp
1374 update_flags SZYHVXN0
1375 mov tmp scratch1
1376 cycles 1
1377 z80_store_hl
1378
1379dd 00110100 inc_ixd
1380 local tmp 8
1381 z80_fetch_index ix
1382 #TODO: Either make DSL compiler smart enough to optimize these unnecessary moves out
1383 #or add some syntax to force a certain size on an operation so they are unnecessary
1384 mov scratch1 tmp
1385 add 1 tmp tmp
1386 update_flags SZYHVXN0
1387 mov tmp scratch1
1388 cycles 1
1389 z80_store_index
1390
1391fd 00110100 inc_iyd
1392 local tmp 8
1393 z80_fetch_index iy
1394 #TODO: Either make DSL compiler smart enough to optimize these unnecessary moves out
1395 #or add some syntax to force a certain size on an operation so they are unnecessary
1396 mov scratch1 tmp
1397 add 1 tmp tmp
1398 update_flags SZYHVXN0
1399 mov tmp scratch1
1400 cycles 1
1401 z80_store_index
1402
1403z80_inc_pair
1404 arg high 8
1405 arg low 8
1406 cycles 2
1407 local word 16
1408 lsl high 8 word
1409 or low word word
1410 add 1 word word
1411 mov word low
1412 lsr word 8 high
1413
141400000011 inc_bc
1415 z80_inc_pair b c
1416
141700010011 inc_de
1418 z80_inc_pair d e
1419
142000100011 inc16_hl
1421 z80_inc_pair h l
1422
142300110011 inc_sp
1424 add 1 sp sp
1425
1426dd 00100011 inc_ix
1427 add 1 ix ix
1428
1429fd 00100011 inc_iy
1430 add 1 iy iy
1431
143200RRR101 dec_reg
1433 sub 1 main.R main.R
1434 update_flags SZYHVXN1
1435
1436dd 00100101 dec_ixh
1437 sub 0x100 ix ix
1438 update_flags SZYHVXN1
1439
1440dd 00101101 dec_ixl
1441 local tmp 8
1442 mov ix tmp
1443 sub 1 tmp tmp
1444 update_flags SZYHVXN1
1445 and 0xFF00 ix ix
1446 or tmp ix ix
1447
1448fd 00100101 dec_iyh
1449 sub 0x100 iy iy
1450 update_flags SZYHVXN1
1451
1452fd 00101101 dec_iyl
1453 local tmp 8
1454 mov iy tmp
1455 sub 1 tmp tmp
1456 update_flags SZYHVXN1
1457 and 0xFF00 iy iy
1458 or tmp iy iy
1459
146000110101 dec_hl
1461 local tmp 8
1462 z80_fetch_hl
1463 #TODO: Either make DSL compiler smart enough to optimize these unnecessary moves out
1464 #or add some syntax to force a certain size on an operation so they are unnecessary
1465 mov scratch1 tmp
1466 sub 1 tmp tmp
1467 update_flags SZYHVXN1
1468 mov tmp scratch1
1469 cycles 1
1470 z80_store_hl
1471
1472dd 00110101 dec_ixd
1473 local tmp 8
1474 z80_fetch_index ix
1475 #TODO: Either make DSL compiler smart enough to optimize these unnecessary moves out
1476 #or add some syntax to force a certain size on an operation so they are unnecessary
1477 mov scratch1 tmp
1478 sub 1 tmp tmp
1479 update_flags SZYHVXN1
1480 mov tmp scratch1
1481 cycles 1
1482 z80_store_index
1483
1484fd 00110101 dec_iyd
1485 local tmp 8
1486 z80_fetch_index iy
1487 #TODO: Either make DSL compiler smart enough to optimize these unnecessary moves out
1488 #or add some syntax to force a certain size on an operation so they are unnecessary
1489 mov scratch1 tmp
1490 sub 1 tmp tmp
1491 update_flags SZYHVXN1
1492 mov tmp scratch1
1493 cycles 1
1494 z80_store_index
1495
1496z80_dec_pair
1497 arg high 8
1498 arg low 8
1499 local word 16
1500 lsl high 8 word
1501 or low word word
1502 sub 1 word word
1503 mov word low
1504 lsr word 8 high
1505 cycles 2
1506
150700001011 dec_bc
1508 z80_dec_pair b c
1509
151000011011 dec_de
1511 z80_dec_pair d e
1512
151300101011 dec16_hl
1514 z80_dec_pair h l
1515
151600111011 dec_sp
1517 sub 1 sp sp
1518
1519dd 00101011 dec_ix
1520 sub 1 ix ix
1521
1522fd 00101011 dec_iy
1523 sub 1 iy iy
1524
152500101111 cpl
1526 not a a
1527 update_flags YH1XN1
1528
1529ed 01DDD100 neg
1530 neg a a
1531 update_flags SZYHVXN1C
1532
153300111111 ccf
1534 local tmp 8
1535 and 0x80 last_flag_result last_flag_result
1536 and 0x7F a tmp
1537 or tmp last_flag_result last_flag_result
1538 and 0x80 chflags chflags
1539 lsr chflags 4 tmp
1540 or tmp chflags chflags
1541 xor 0x80 chflags chflags
1542 update_flags N0
1543
154400110111 scf
1545 local tmp 8
1546 and 0x80 last_flag_result last_flag_result
1547 and 0x7F a tmp
1548 or tmp last_flag_result last_flag_result
1549 update_flags H0N0C1
1550
155100000000 nop
1552
155301110110 halt
1554 cmp nmi_cycle cycles
1555 if >=U
1556
1557 else
1558 cmp int_cycle cycles
1559 if >=U
1560
1561 if iff1
1562 else
1563 sub 1 pc pc
1564 end
1565
1566 else
1567 sub 1 pc pc
1568 end
1569 end
1570
157111110011 di
1572 mov 0 iff1
1573 mov 0 iff2
1574 update_sync
1575
157611111011 ei
1577 mov 1 iff1
1578 mov 1 iff2
1579 update_sync
1580 cmp int_cycle cycles
1581 if >=U
1582
1583 add 1 cycles int_cycle
1584
1585 end
1586
1587ed 01D00110 im0
1588 mov 0 imode
1589
1590ed 01D10110 im1
1591 mov 1 imode
1592
1593ed 01D11110 im2
1594 mov 2 imode
1595
1596ed 01D01110 im3
1597 #some sources call this mode 0/1, but unclear
1598 #if the behavior is really different from im 0
1599 mov 0 imode
1600
160111000011 jp
1602 z80_fetch_immed16
1603 mov wz pc
1604
160511101001 jp_hl
1606 lsl h 8 pc
1607 or l pc pc
1608
1609dd 11101001 jp_ix
1610 mov ix pc
1611
1612fd 11101001 jp_iy
1613 mov iy pc
1614
161511CCC010 jp_cc
1616 z80_check_cond C
1617 z80_fetch_immed16
1618 if istrue
1619
1620 mov wz pc
1621
1622 end
1623
162400011000 jr
1625 z80_fetch_immed
1626 #TODO: determine if this updates wz
1627 sext 16 scratch1 scratch1
1628 add scratch1 pc pc
1629 cycles 5
1630
1631001CC000 jr_cc
1632 z80_check_cond C
1633 z80_fetch_immed
1634
1635 if istrue
1636
1637 sext 16 scratch1 scratch1
1638 add scratch1 pc pc
1639 cycles 5
1640
1641 end
1642
164300010000 djnz
1644 cycles 1
1645 z80_fetch_immed
1646 sub 1 b b
1647
1648 if b
1649
1650 sext 16 scratch1 scratch1
1651 add scratch1 pc pc
1652 cycles 5
1653
1654 end
1655
1656
165711001101 call_uncond
1658 z80_fetch_immed16
1659 local pch 8
1660 lsr pc 8 pch
1661 meta high pch
1662 meta low pc
1663 z80_push
1664 mov wz pc
1665
166611CCC100 call_cond
1667 local pch 8
1668 z80_fetch_immed16
1669 z80_check_cond C
1670
1671 if istrue
1672
1673 lsr pc 8 pch
1674 meta high pch
1675 meta low pc
1676 z80_push
1677 mov wz pc
1678
1679 end
1680
168111TTT111 rst
1682 local pch 8
1683 lsr pc 8 pch
1684 meta high pch
1685 meta low pc
1686 z80_push
1687 lsl T 3 scratch1
1688 mov scratch1 pc
1689
169011001001 ret
1691 local pch 16
1692 meta high pch
1693 meta low pc
1694 z80_pop
1695 lsl pch 8 pch
1696 or pch pc pc
1697
1698ed 01001101 reti
1699 local pch 16
1700 cycles 1
1701 meta high pch
1702 meta low pc
1703 z80_pop
1704 lsl pch 8 pch
1705 or pch pc pc
1706
1707ed 01NN1101 retn
1708 mov iff2 iff1
1709 local pch 16
1710 cycles 1
1711 meta high pch
1712 meta low pc
1713 z80_pop
1714 lsl pch 8 pch
1715 or pch pc pc
1716
171711CCC000 ret_cond
1718 local pch 16
1719 cycles 1
1720 z80_check_cond C
1721 if istrue
1722
1723 meta high pch
1724 meta low pc
1725 z80_pop
1726 lsl pch 8 pch
1727 or pch pc pc
1728
1729 end
1730
173111011011 in_abs
1732 z80_fetch_immed
1733 ocall io_read8
1734 mov scratch1 a
1735
1736ed 01RRR000 in_bc
1737 lsl b 8 scratch1
1738 or c scratch1 scratch1
1739 ocall io_read8
1740 mov scratch1 main.R
1741
1742z80_ini_ind
1743 arg change 16
1744 local tmp 8
1745 cycles 1
1746
1747 lsl 8 b wz
1748 or c wz wz
1749 add change wz wz
1750
1751 sub 1 b b
1752 update_flags SZYX
1753
1754 lsl b 8 scratch1
1755 or c scratch1 scratch1
1756 ocall io_read8
1757
1758 and 0x80 scratch1 nflag
1759
1760 mov wz tmp
1761 add tmp scratch1 tmp
1762 update_flags C
1763
1764 z80_store_hl
1765
1766 lsl h 8 scratch2
1767 or l scratch2 scratch2
1768 add change scratch2 scratch2
1769 mov scratch2 l
1770 lsr scratch2 8 h
1771
1772 and 7 tmp tmp
1773 xor b tmp tmp
1774 update_flags P
1775 lsr chflags 4 tmp
1776 or tmp chflags chflags
1777
1778ed 10100010 ini
1779 z80_ini_ind 1
1780
1781ed 10110010 inir
1782 z80_ini_ind 1
1783 if zflag
1784 else
1785 sub 2 pc pc
1786 cycles 5
1787 end
1788
1789ed 10101010 ind
1790 z80_ini_ind -1
1791
1792ed 10111010 indr
1793 z80_ini_ind -1
1794 if zflag
1795 else
1796 sub 2 pc pc
1797 cycles 5
1798 end
1799
180011010011 out_abs
1801 z80_fetch_immed
1802 mov scratch1 scratch2
1803 mov a scratch1
1804 ocall io_write8
1805
1806ed 01RRR001 out_bc
1807 lsl b 8 scratch2
1808 or c scratch2 scratch2
1809 mov main.R scratch1
1810 ocall io_write8
1811
1812z80_outi_outd
1813 arg change 16
1814 local tmp 8
1815 cycles 1
1816 z80_fetch_hl
1817
1818 and 0x80 scratch1 nflag
1819
1820 lsl h 8 scratch2
1821 or l scratch2 scratch2
1822 add change scratch2 scratch2
1823 mov scratch2 l
1824 lsr scratch2 8 h
1825
1826 add l scratch1 tmp
1827 update_flags C
1828 and 7 tmp tmp
1829
1830 lsl b 8 scratch2
1831 or c scratch2 scratch2
1832 ocall io_write8
1833
1834 sub 1 b b
1835 update_flags SZYX
1836
1837 lsl 8 b wz
1838 or c wz wz
1839 add change wz wz
1840
1841 xor b tmp tmp
1842 update_flags P
1843 lsr chflags 4 tmp
1844 or tmp chflags chflags
1845
1846ed 10100011 outi
1847 z80_outi_outd 1
1848
1849ed 10110011 otir
1850 z80_outi_outd 1
1851 if zflag
1852 else
1853 sub 2 pc pc
1854 cycles 5
1855 end
1856
1857ed 10101011 outd
1858 z80_outi_outd -1
1859
1860ed 10111011 otdr
1861 z80_outi_outd -1
1862 if zflag
1863 else
1864 sub 2 pc pc
1865 cycles 5
1866 end
1867
186800000111 rlca
1869 rol a 1 a
1870 update_flags YH0XN0C
1871
187200010111 rla
1873 rlc a 1 a
1874 update_flags YH0XN0C
1875
187600001111 rrca
1877 ror a 1 a
1878 update_flags YH0XN0C
1879
188000011111 rra
1881 rrc a 1 a
1882 update_flags YH0XN0C
1883
1884cb 00000RRR rlc
1885 rol main.R 1 main.R
1886 update_flags SZYH0PXN0C
1887
1888cb 00000110 rlc_hl
1889 local tmp 8
1890 z80_fetch_hl
1891 mov scratch1 tmp
1892 rol tmp 1 tmp
1893 update_flags SZYH0PXN0C
1894 mov tmp scratch1
1895 z80_store_hl
1896
1897z80_rlc_index
1898 arg tmp 8
1899 mov wz scratch1
1900 ocall read_8
1901 cycles 1
1902 mov scratch1 tmp
1903 rol tmp 1 tmp
1904 update_flags SZYH0PXN0C
1905 mov tmp scratch1
1906 z80_store_index
1907
1908ddcb 00000110 rlc_ixd
1909 local tmp 8
1910 z80_rlc_index tmp
1911
1912ddcb 00000RRR rlc_ixd_reg
1913 z80_rlc_index main.R
1914
1915fdcb 00000110 rlc_iyd
1916 local tmp 8
1917 z80_rlc_index tmp
1918
1919fdcb 00000RRR rlc_iyd_reg
1920 z80_rlc_index main.R
1921
1922cb 00010RRR rl
1923 rlc main.R 1 main.R
1924 update_flags SZYH0PXN0C
1925
1926cb 00010110 rl_hl
1927 local tmp 8
1928 z80_fetch_hl
1929 mov scratch1 tmp
1930 rlc tmp 1 tmp
1931 update_flags SZYH0PXN0C
1932 mov tmp scratch1
1933 z80_store_hl
1934
1935z80_rl_index
1936 arg tmp 8
1937 mov wz scratch1
1938 ocall read_8
1939 cycles 1
1940 mov scratch1 tmp
1941 rlc tmp 1 tmp
1942 update_flags SZYH0PXN0C
1943 mov tmp scratch1
1944 z80_store_index
1945
1946ddcb 00010110 rl_ixd
1947 local tmp 8
1948 z80_rl_index tmp
1949
1950fdcb 00010110 rl_iyd
1951 local tmp 8
1952 z80_rl_index tmp
1953
1954
1955ddcb 00010RRR rl_ixd_reg
1956 z80_rl_index main.R
1957
1958fdcb 00010RRR rl_iyd_reg
1959 z80_rl_index main.R
1960
1961cb 00001RRR rrc
1962 ror main.R 1 main.R
1963 update_flags SZYH0PXN0C
1964
1965cb 00001110 rrc_hl
1966 local tmp 8
1967 z80_fetch_hl
1968 mov scratch1 tmp
1969 ror tmp 1 tmp
1970 update_flags SZYH0PXN0C
1971 mov tmp scratch1
1972 z80_store_hl
1973
1974z80_rrc_index
1975 arg tmp 8
1976 mov wz scratch1
1977 ocall read_8
1978 cycles 1
1979 mov scratch1 tmp
1980 ror tmp 1 tmp
1981 update_flags SZYH0PXN0C
1982 mov tmp scratch1
1983 z80_store_index
1984
1985ddcb 00001110 rrc_ixd
1986 local tmp 8
1987 z80_rrc_index tmp
1988
1989ddcb 00001RRR rrc_ixd_reg
1990 z80_rrc_index main.R
1991
1992fdcb 00001110 rrc_iyd
1993 local tmp 8
1994 z80_rrc_index tmp
1995
1996fdcb 00001RRR rrc_iyd_reg
1997 z80_rrc_index main.R
1998
1999cb 00011RRR rr
2000 rrc main.R 1 main.R
2001 update_flags SZYH0PXN0C
2002
2003cb 00011110 rr_hl
2004 local tmp 8
2005 z80_fetch_hl
2006 mov scratch1 tmp
2007 rrc tmp 1 tmp
2008 update_flags SZYH0PXN0C
2009 mov tmp scratch1
2010 z80_store_hl
2011
2012z80_rr_index
2013 arg tmp 8
2014 mov wz scratch1
2015 ocall read_8
2016 cycles 1
2017 mov scratch1 tmp
2018 rrc tmp 1 tmp
2019 update_flags SZYH0PXN0C
2020 mov tmp scratch1
2021 z80_store_index
2022
2023ddcb 00011110 rr_ixd
2024 local tmp 8
2025 z80_rr_index tmp
2026
2027ddcb 00011RRR rr_ixd_reg
2028 z80_rr_index main.R
2029
2030fdcb 00011110 rr_iyd
2031 local tmp 8
2032 z80_rr_index tmp
2033
2034fdcb 00011RRR rr_iyd_reg
2035 z80_rr_index main.R
2036
2037cb 00100RRR sla
2038 lsl main.R 1 main.R
2039 update_flags SZYH0PXN0C
2040
2041cb 00100110 sla_hl
2042 local tmp 8
2043 z80_fetch_hl
2044 mov scratch1 tmp
2045 lsl tmp 1 tmp
2046 update_flags SZYH0PXN0C
2047 mov tmp scratch1
2048 z80_store_hl
2049
2050z80_sla_index
2051 arg tmp 8
2052 mov wz scratch1
2053 ocall read_8
2054 cycles 1
2055 mov scratch1 tmp
2056 lsl tmp 1 tmp
2057 update_flags SZYH0PXN0C
2058 mov tmp scratch1
2059 z80_store_index
2060
2061ddcb 00100110 sla_ixd
2062 local tmp 8
2063 z80_sla_index tmp
2064
2065ddcb 00100RRR sla_ixd_reg
2066 z80_sla_index main.R
2067
2068fdcb 00100110 sla_iyd
2069 local tmp 8
2070 z80_sla_index tmp
2071
2072fdcb 00100RRR sla_iyd_reg
2073 z80_sla_index main.R
2074
2075cb 00101RRR sra
2076 asr main.R 1 main.R
2077 update_flags SZYH0PXN0C
2078
2079cb 00101110 sra_hl
2080 local tmp 8
2081 z80_fetch_hl
2082 mov scratch1 tmp
2083 asr tmp 1 tmp
2084 update_flags SZYH0PXN0C
2085 mov tmp scratch1
2086 z80_store_hl
2087
2088z80_sra_index
2089 arg tmp 8
2090 mov wz scratch1
2091 ocall read_8
2092 cycles 1
2093 mov scratch1 tmp
2094 asr tmp 1 tmp
2095 update_flags SZYH0PXN0C
2096 mov tmp scratch1
2097 z80_store_index
2098
2099ddcb 00101110 sra_ixd
2100 local tmp 8
2101 z80_sra_index tmp
2102
2103ddcb 00101RRR sra_ixd_reg
2104 z80_sra_index main.R
2105
2106fdcb 00101110 sra_iyd
2107 local tmp 8
2108 z80_sra_index tmp
2109
2110fdcb 00101RRR sra_iyd_reg
2111 z80_sra_index main.R
2112
2113cb 00110RRR sll
2114 lsl main.R 1 main.R
2115 update_flags SZ0YH0XN0C
2116 or 1 main.R main.R
2117 update_flags P
2118
2119cb 00110110 sll_hl
2120 local tmp 8
2121 z80_fetch_hl
2122 mov scratch1 tmp
2123 lsl tmp 1 tmp
2124 update_flags SZ0YH0XN0C
2125 or 1 tmp tmp
2126 update_flags P
2127 mov tmp scratch1
2128 z80_store_hl
2129
2130z80_sll_index
2131 arg tmp 8
2132 mov wz scratch1
2133 ocall read_8
2134 cycles 1
2135 mov scratch1 tmp
2136 lsl tmp 1 tmp
2137 update_flags SZ0YH0XN0C
2138 or 1 tmp tmp
2139 update_flags P
2140 mov tmp scratch1
2141 z80_store_index
2142
2143ddcb 00110110 sll_ixd
2144 local tmp 8
2145 z80_sll_index tmp
2146
2147ddcb 00110RRR sll_ixd_reg
2148 z80_sll_index main.R
2149
2150fdcb 00110110 sll_iyd
2151 local tmp 8
2152 z80_sll_index tmp
2153
2154fdcb 00110RRR sll_iyd_reg
2155 z80_sll_index main.R
2156
2157cb 00111RRR srl
2158 lsr main.R 1 main.R
2159 update_flags SZYH0PXN0C
2160
2161cb 00111110 srl_hl
2162 local tmp 8
2163 z80_fetch_hl
2164 mov scratch1 tmp
2165 lsr tmp 1 tmp
2166 update_flags SZYH0PXN0C
2167 mov tmp scratch1
2168 z80_store_hl
2169
2170z80_srl_index
2171 arg tmp 8
2172 mov wz scratch1
2173 ocall read_8
2174 cycles 1
2175 mov scratch1 tmp
2176 lsr tmp 1 tmp
2177 update_flags SZYH0PXN0C
2178 mov tmp scratch1
2179 z80_store_index
2180
2181ddcb 00111110 srl_ixd
2182 local tmp 8
2183 z80_srl_index tmp
2184
2185ddcb 00111RRR srl_ixd_reg
2186 z80_srl_index main.R
2187
2188fdcb 00111110 srl_iyd
2189 local tmp 8
2190 z80_srl_index tmp
2191
2192fdcb 00111RRR srl_iyd_reg
2193 z80_srl_index main.R
2194
2195cb 01BBBRRR bit_reg
2196 local tmp 8
2197 lsl 1 B tmp
2198 mov main.R last_flag_result
2199 and main.R tmp tmp
2200 update_flags SZH1PN0
2201
2202cb 01BBB110 bit_hl
2203 local tmp 8
2204 z80_fetch_hl
2205 cycles 1
2206 lsl 1 B tmp
2207 lsr wz 8 last_flag_result
2208 and scratch1 tmp tmp
2209 update_flags SZH1PN0
2210
2211
2212ddcb 01BBBRRR bit_ixd
2213 local tmp 8
2214 mov wz scratch1
2215 ocall read_8
2216 cycles 1
2217 lsl 1 B tmp
2218 lsr wz 8 last_flag_result
2219 and scratch1 tmp tmp
2220 update_flags SZH1PN0
2221
2222fdcb 01BBBRRR bit_iyd
2223 local tmp 8
2224 mov wz scratch1
2225 ocall read_8
2226 cycles 1
2227 lsl 1 B tmp
2228 lsr wz 8 last_flag_result
2229 and scratch1 tmp tmp
2230 update_flags SZH1PN0
2231
2232cb 10BBBRRR res_reg
2233 local tmp 8
2234 lsl 1 B tmp
2235 not tmp tmp
2236 and main.R tmp main.R
2237
2238cb 10BBB110 res_hl
2239 z80_fetch_hl
2240 cycles 1
2241 local tmp 8
2242 lsl 1 B tmp
2243 not tmp tmp
2244 and scratch1 tmp scratch1
2245 z80_store_hl
2246
2247z80_res_index
2248 arg bit 8
2249 arg tmp 8
2250 lsl 1 bit tmp
2251 not tmp tmp
2252 mov wz scratch1
2253 ocall read_8
2254 cycles 1
2255 and scratch1 tmp tmp
2256 mov tmp scratch1
2257 z80_store_index
2258
2259ddcb 10BBB110 res_ixd
2260 local tmp 8
2261 z80_res_index B tmp
2262
2263ddcb 10BBBRRR res_ixd_reg
2264 z80_res_index B main.R
2265
2266fdcb 10BBB110 res_iyd
2267 local tmp 8
2268 z80_res_index B tmp
2269
2270fdcb 10BBBRRR res_iyd_reg
2271 z80_res_index B main.R
2272
2273cb 11BBBRRR set_reg
2274 local tmp 8
2275 lsl 1 B tmp
2276 or main.R tmp main.R
2277
2278cb 11BBB110 set_hl
2279 z80_fetch_hl
2280 cycles 1
2281 local tmp 8
2282 lsl 1 B tmp
2283 or scratch1 tmp scratch1
2284 z80_store_hl
2285
2286z80_set_index
2287 arg bit 8
2288 arg tmp 8
2289 lsl 1 bit tmp
2290 mov wz scratch1
2291 ocall read_8
2292 cycles 1
2293 or scratch1 tmp tmp
2294 mov tmp scratch1
2295 z80_store_index
2296
2297ddcb 11BBB110 set_ixd
2298 local tmp 8
2299 z80_set_index B tmp
2300
2301ddcb 11BBBRRR set_ixd_reg
2302 z80_set_index B main.R
2303
2304fdcb 11BBB110 set_iyd
2305 local tmp 8
2306 z80_set_index B tmp
2307
2308fdcb 11BBBRRR set_iyd_reg
2309 z80_set_index B main.R
2310
2311z80_fetch_mod_hl
2312 local tmp 16
2313 arg change 16
2314 lsl h 8 tmp
2315 or l tmp tmp
2316 mov tmp scratch1
2317 add change tmp tmp
2318 mov tmp l
2319 lsr tmp 8 h
2320 ocall read_8
2321 cycles 2
2322
2323z80_ldd_ldi
2324 arg change 16
2325 local tmp 16
2326 local tmp8 8
2327 z80_fetch_mod_hl change
2328
2329 add a scratch1 tmp8
2330 update_flags H0XN0
2331
2332 and 0x2 tmp8 tmp8
2333 lsl tmp8 4 tmp8
2334 and 0x88 last_flag_result last_flag_result
2335 or tmp8 last_flag_result last_flag_result
2336
2337 lsl d 8 tmp
2338 or e tmp tmp
2339 mov tmp scratch2
2340 add change tmp tmp
2341 mov tmp e
2342 lsr tmp 8 d
2343 ocall write_8
2344
2345 lsl b 8 tmp
2346 or c tmp tmp
2347 sub 1 tmp tmp
2348
2349 mov tmp c
2350 lsr tmp 8 b
2351 mov c pvflag
2352 or b pvflag pvflag
2353
2354
2355ed 10100000 ldi
2356 z80_ldd_ldi 1
2357
2358ed 10101000 ldd
2359 z80_ldd_ldi -1
2360
2361ed 10110000 ldir
2362 z80_ldd_ldi 1
2363 if pvflag
2364
2365 add 1 pc wz
2366 sub 2 pc pc
2367 cycles 5
2368
2369 end
2370
2371ed 10111000 lddr
2372 z80_ldd_ldi -1
2373 if pvflag
2374
2375 add 1 pc wz
2376 sub 2 pc pc
2377 cycles 5
2378
2379 end
2380
2381z80_cpd_cpi
2382 local tmp 16
2383 local tmp8 8
2384 local hf 8
2385 arg change 16
2386
2387 z80_fetch_mod_hl change
2388 sub scratch1 a tmp8
2389 update_flags SZHN1
2390
2391 lsr chflags 3 hf
2392 and 1 hf hf
2393
2394 sub hf tmp8 tmp8
2395 update_flags X
2396
2397 and 0x2 tmp8 tmp8
2398 lsl tmp8 4 tmp8
2399 and 0x88 last_flag_result last_flag_result
2400 or tmp8 last_flag_result last_flag_result
2401
2402 lsl b 8 tmp
2403 or c tmp tmp
2404 sub 1 tmp tmp
2405
2406 mov tmp c
2407 lsr tmp 8 b
2408 mov c pvflag
2409 or b pvflag pvflag
2410
2411 cycles 5
2412
2413ed 10100001 cpi
2414 z80_cpd_cpi 1
2415
2416ed 10101001 cpd
2417 z80_cpd_cpi -1
2418
2419ed 10110001 cpir
2420 z80_cpd_cpi 1
2421 if pvflag
2422
2423 if zflag
2424
2425 else
2426
2427 add 1 pc wz
2428 sub 2 pc pc
2429 cycles 5
2430
2431 end
2432 end
2433
2434ed 10111001 cpdr
2435 z80_cpd_cpi -1
2436 if pvflag
2437
2438 if zflag
2439
2440 else
2441
2442 add 1 pc wz
2443 sub 2 pc pc
2444 cycles 5
2445
2446 end
2447 end
2448
244900100111 daa
2450 local diff 8
2451 local tmp 8
2452 local low 8
2453 and 0xF a low
2454 and 0x8 chflags tmp
2455 if tmp
2456
2457 mov 6 diff
2458
2459 else
2460
2461 cmp 0xA low
2462 if >=U
2463 mov 6 diff
2464 else
2465 mov 0 diff
2466 end
2467
2468 end
2469
2470 and 0x80 chflags tmp
2471 if tmp
2472
2473 or 0x60 diff diff
2474 update_flags C1
2475
2476 else
2477
2478 cmp 0x9A a
2479 if >=U
2480 or 0x60 diff diff
2481 update_flags C1
2482 else
2483 update_flags C0
2484 end
2485 end
2486
2487 if nflag
2488
2489 sub diff a a
2490 update_flags SZYHPX
2491
2492 else
2493
2494 add diff a a
2495 update_flags SZYHPX
2496
2497 end
2498
2499dd OOOOOOOO dd_normal
2500 dispatch O
2501
2502fd OOOOOOOO fd_normal
2503 dispatch O
2504
2505ed 01101111 rld
2506 local tmp 8
2507 local tmp2 8
2508 z80_fetch_hl
2509 cycles 4
2510
2511 lsr scratch1 4 tmp
2512
2513 lsl scratch1 4 scratch1
2514
2515 and 0xF a tmp2
2516 or tmp2 scratch1 scratch1
2517
2518 and 0xF0 a a
2519 or tmp a a
2520 update_flags SZYH0XPN0
2521 z80_store_hl
2522
2523ed 01100111 rrd
2524 local tmp 8
2525 local tmp2 8
2526 z80_fetch_hl
2527 cycles 4
2528
2529 and 0xF scratch1 tmp
2530 lsr scratch1 4 scratch1
2531
2532 lsl a 4 tmp2
2533 or tmp2 scratch1 scratch1
2534
2535 and 0xF0 a a
2536 or tmp a a
2537 update_flags SZYH0XPN0
2538 z80_store_hl
2539