]> cloudbase.mooo.com Git - ddt180.git/blob - ddt180.z80
Remove Y variables (cmd_Y)
[ddt180.git] / ddt180.z80
1 ; Disassembled ddtz.com, version "DDT/Z [8101]"
2 ; with modified relocater.
3 ;
4 ; Build steps:
5 ; - Assemble to a .REL file with M80 or a compatible assembler.
6 ; - Use Digital Research Link-80 to generate a .PRL file (op switch).
7 ; - Cut the .PRL header (first 256 byte) end rename the result to DDTZ.COM.
8
9 ;-------------------------------------------------------------------------------
10 ; Relocation loader
11 ;
12 TPA equ 0100h
13 cseg
14 .phase TPA
15
16 jp start
17 ds 3
18
19 ldr_end:
20 ldr_size equ $ - TPA
21 current_phase defl $
22
23 .dephase
24 current_cseg defl $
25
26 ;-------------------------------------------------------------------------------
27 ; DDT/Z core
28 ;
29
30 ; Some greneral definitions
31
32 TAB equ 9
33 LF equ 10
34 CR equ 13
35
36 ; CP/M memory layout
37
38 BDOS equ 5
39 dfcb1 equ 05ch
40 dfcb2 equ 06ch
41 DMA_BUF equ 080h
42 TPA equ 0100h
43
44 ; BDOS function calls
45
46 BDOS_CIN equ 1 ;Console Input
47 BDOS_COUT equ 2 ;Console Output
48 BDOS_PSTR equ 9 ;Print String
49 BDOS_CBUF equ 10 ;Read Console Buffer
50 BDOS_CSTAT equ 11 ;Get Console Status
51 BDOS_OPEN equ 15 ;Open File
52 BDOS_CLOSE equ 16 ;Close File
53 BDOS_DELETE equ 19 ;Delete File
54 BDOS_READ equ 20 ;Read Sequential
55 BDOS_WRITE equ 21 ;Write Sequential
56 BDOS_CREATE equ 22 ;Make File
57 BDOS_SETDMA equ 26 ;Set DMA Address
58
59 ; ddtz specific definitions
60
61 STACK_SIZE equ 80 ;ddtz internal stack
62 CONBUF_SIZE equ 80 ;Size of console input buffer
63 EXPR_BUF_SIZE equ 128 ;expressen buffer for conditional breakpoints
64 BP_CNT equ 12 ;Number of breakpoints
65 BP_SIZE equ 8 ;Size of a breakpoint record
66
67 ;-------------------------------------------------------------------------------
68
69 ddtz_base:
70 jp ddtz_bdos
71 l0003h:
72 rst 30h
73 di_or_ei:
74 nop
75 ret
76 ddtz_bdos:
77 jp 0
78
79 current_cseg defl $ - current_cseg
80 .phase current_phase + current_cseg
81 signon:
82 db 'DDTZ/180'
83 db ' - Version '
84 maclib version.inc
85 defvers
86 db CR,LF,'$'
87 msgz80:
88 db 'Z80 or better required!',cr,lf,'$'
89
90 current_phase defl $
91 .dephase
92 current_cseg defl $
93 ds STACK_SIZE - (current_phase - signon)
94
95
96 stack:
97 reg.l2: db 000h
98 reg.h2: db 000h
99 reg.e2: db 000h
100 reg.d2: db 000h
101 reg.c2: db 000h
102 reg.b2: db 000h
103 reg.f2: db 000h
104 reg.a2: db 000h
105 l004eh: db 000h
106 reg.i: db 000h
107 reg.iy: dw 0000h
108 reg.ix: dw 0000h
109 reg.f: db 000h
110 reg.a: db 000h
111 reg.c: db 000h
112 reg.b: db 000h
113 reg.e: db 000h
114 reg.d: db 000h
115 reg.l: db 000h
116 reg.h: db 000h
117 reg_sp: dw TPA
118 reg.iff:
119 db 0f3h
120 db 0c3h
121 reg.pc: dw TPA
122 var.$: dw 0000h
123 var.@: dw 0
124
125 cmd_rpt:dw mainloop
126
127 ;-------------------------------------------------------------------------------
128
129 conbuf:
130 db CONBUF_SIZE
131
132 ld sp,stack
133 exx
134 ld de,ddtz_base
135 or a
136 sbc hl,de
137 add hl,de
138 jr c,l0079h
139 ex de,hl
140 l0079h:
141 ld de,TPA
142 l007ch:
143 dec hl
144 ld (hl),000h
145 ld a,h
146 sub d
147 ld b,a
148 ld a,l
149 sub e
150 or b
151 jr nz,l007ch
152 ld a,i
153 ld (reg.i),a
154 ld a,0f3h
155 jp po,l0093h
156 ld a,0fbh
157 l0093h:
158 ld (reg.iff),a
159 call di_or_ei
160 ld hl,ddtz_base
161 ld l,000h
162 ld (reg_sp),hl
163 ld a,(dfcb1+1)
164 cp ' '
165 ld hl,0
166 call nz,read_file
167 jr mainloop
168
169 ds CONBUF_SIZE + 3 - ($ - conbuf)
170
171 ;-------------------------------------------------------------------------------
172
173 CMDTAB:
174 dw cmd_@ ;examine/substitute the displacement register @
175 dw ERROR ;cmd_A ;Assemble
176 dw cmd_B ;Breakpoints display/set/clear
177 dw cmd_C ;trace over Calls
178 dw cmd_D ;Display memory in hex and ascii
179 dw ERROR ;
180 dw cmd_F ;specify Filename and command line
181 dw cmd_G ;Go
182 dw cmd_H ;compute Hex and other expressions
183 dw cmd_I ;Input a byte from port
184 dw ERROR ;
185 dw ERROR ;
186 dw cmd_L ;List disassembled code
187 dw cmd_M ;Move memory [and verify]
188 dw ERROR ;
189 dw cmd_O ;Output a byte to port
190 dw ERROR ;
191 dw cmd_Q ;Qery memory for byte string
192 dw cmd_R ;Read binary or hex file
193 dw cmd_S ;Substitute memory
194 dw cmd_T ;Trace
195 dw ERROR ;
196 dw cmd_V ;Verify (compare) two memory areas
197 dw cmd_W ;Write a file to disk
198 dw cmd_X ;eXamine [and substitute] registers
199 dw ERROR ;cmd_Y ;examine [and substitute] Y variables
200 dw cmd_Z ;Zap (fill) memory with a byte string
201
202 ERROR:
203 p_msg_error:
204 call pstr_inl
205 dc '?',CR,LF
206 ;fall thru
207 mainloop:
208 ld sp,stack
209 ld hl,(reg.pc)
210 ld (var.$),hl
211 call bp_clr_temporary
212 ld hl,(cmd_rpt)
213 ld de,mainloop
214 call cp_hl_de
215 ld a,'>'
216 call outchar
217 call nz,outchar
218 call z,outbl
219 call get_line
220 call skipbl
221 jr z,exe_hl
222 ld hl,mainloop
223 ld (cmd_rpt),hl
224 inc de
225 sub '@'
226 jr c,ERROR
227 cp 'Z'+1-'@'
228 jr nc,ERROR
229 add a,a
230 ld hl,CMDTAB
231 call add_hl_a
232 ld a,(hl)
233 inc hl
234 ld h,(hl)
235 ld l,a
236
237 exe_hl:
238 call CALL_HL
239 jr mainloop
240
241 ;-------------------------------------------------------------------------------
242
243 crlf:
244 call pstr_inl
245 dc CR,LF
246 call inchar
247 ld a,0
248 ld (con_col),a
249 jr c,mainloop
250 ret
251
252 out.hl.@:
253 call out_hl
254 push de
255 push hl
256 ld de,(var.@)
257 ld a,d
258 or e
259 jr z,l01bfh
260 call outbl
261 call pstr_inl
262 dc '@'
263 and a
264 sbc hl,de
265 call out_hl
266 l01bfh:
267 pop hl
268 pop de
269 ret
270
271 sub_01d9h:
272 call pstr_inl
273 dc '-'
274 dec hl
275 jp cpl.hl
276
277 out_hl_dec_neg:
278 push hl
279 call sub_01d9h
280 defb 03eh ;ld a,.. swallow push hl
281 out.hl.dec:
282 push hl
283 ld b,006h
284 call sub_01f9h
285 pop hl
286 call pstr_inl
287 dc '.'
288 l01f3h:
289 call outbl
290 djnz l01f3h
291 ret
292
293 sub_01f9h:
294 dec b
295 push de
296 ld de,10
297 call div_hl_de
298 ld a,h
299 or l
300 call nz,sub_01f9h
301 ld a,e
302 pop de
303 jr out_dgt
304
305 out_hl_neg:
306 push hl
307 call sub_01d9h
308 call out_hl
309 pop hl
310 ret
311
312 out_hl:
313 ld a,h
314 call out_hex
315 ld a,l
316
317 out_hex:
318 push af
319 rra
320 rra
321 rra
322 rra
323 call out_dgt
324 pop af
325
326 out_dgt:
327 or 0f0h
328 daa
329 add a,0a0h
330 adc a,040h
331 jr outchar
332
333 out.bin.w:
334 ld a,h
335 call out.bin.b
336 ld a,l
337 out.bin.b:
338 ld b,8
339 l01c9h:
340 rlca
341 push af
342 ld a,'0'/2
343 adc a,a
344 call outchar
345 pop af
346 djnz l01c9h
347 ld a,'"'
348 jr outchar
349
350 out.ascii:
351 push bc
352 ld c,a
353 res 7,a
354 cp ' '
355 push af
356 call nc,outbl
357 call outquote
358 pop af
359 jr nc,l0242h
360 sub 0c0h
361 ld b,a
362 call pstr_inl
363 dc '^'
364 ld a,b
365 l0242h:
366 call outchar
367 cp ''''
368 call z,outchar
369 call outquote
370 sla c
371 pop bc
372 ret nc
373 ld a,'.'
374 jr outchar
375
376 outbl6:
377 call outbl2
378 outbl4:
379 call outbl2
380 outbl2:
381 call outbl
382 outbl:
383 ld a,' '
384 jr outchar
385
386 outquote:
387 ld a,''''
388 outchar:
389 push ix
390 push iy
391 push hl
392 push de
393 push bc
394 push af
395 and 07fh
396 ld e,a
397 ld c,BDOS_COUT
398 call ddtz_bdos
399 ld hl,con_col
400 inc (hl)
401 pop af
402 pop bc
403 pop de
404 pop hl
405 pop iy
406 pop ix
407 ret
408
409 pstr:
410 ld a,(hl)
411 inc hl
412 and a
413 ret z
414 call outchar
415 and a
416 ret m
417 jr pstr
418
419 pstr_inl:
420 ex (sp),hl
421 call pstr
422 ex (sp),hl
423 ret
424
425 p_goto_col:
426 ld a,(con_col)
427 cp c
428 ret nc
429 ret z
430 call outbl
431 jr p_goto_col
432
433 ;-------------------------------------------------------------------------------
434
435 inchar:
436 push ix
437 push hl
438 push de
439 push bc
440 ld c,BDOS_CSTAT
441 call ddtz_bdos
442 and a
443 jr z,l0284h
444 ld c,BDOS_CIN
445 call ddtz_bdos
446 scf
447 l0284h:
448 pop bc
449 pop de
450 pop hl
451 pop ix
452 ret
453
454 get_line:
455 push hl
456 ld de,conbuf
457 ld c,BDOS_CBUF
458 call ddtz_bdos
459 call crlf
460 ld hl,conbuf+1
461 ld e,(hl)
462 xor a
463 ld d,a
464 inc hl
465 ex de,hl
466 add hl,de
467 ld (hl),a
468 pop hl
469 ret
470
471 ;-------------------------------------------------------------------------------
472
473 get_char_upper:
474 ld a,(de)
475 toupper:
476 cp 'a'
477 ret c
478 cp 'z'+1
479 ccf
480 ret c
481 and 05fh
482 ret
483
484 ;-------------------------------------------------------------------------------
485
486 skipbl0:
487 inc de
488 skipbl:
489 call get_char_upper
490 call test_whitespace
491 jr z,skipbl0
492 or a
493 ret
494
495 next_arg:
496 call skipbl
497 cp ','
498 ret nz
499 inc de
500 call skipbl
501 cp a
502 ret
503
504 assert_eol:
505 call skipbl
506 ret z
507 to_error:
508 jp ERROR
509
510 ;-------------------------------------------------------------------------------
511
512 chk_stack:
513 push hl
514 push de
515 ld hl,0
516 add hl,sp
517 ld de,stack-(STACK_SIZE-28)
518 call cp_hl_de
519 pop de
520 pop hl
521 jr c,to_error
522 ret
523
524 ;-------------------------------------------------------------------------------
525
526 add_hl_a:
527 add a,l
528 ld l,a
529 ret nc
530 inc h
531 ret
532
533 cp_hl_de:
534 and a
535 sbc hl,de
536 add hl,de
537 ret
538 ;-------------------------------------------------------------------------------
539
540 lookupch:
541 ld b,0
542 l02f5h:
543 ld a,(hl)
544 and a
545 ret z
546 call get_char_upper
547 cp (hl)
548 jr z,l0300h
549 inc hl
550 inc b
551 jr l02f5h
552 l0300h:
553 scf
554 inc de
555 ret
556
557 sub_0303h:
558 ld hl,t_reg_names
559 ld b,07fh
560 jr l030ch
561
562 sub_030ah:
563 ld b,0ffh
564 l030ch:
565 inc b
566 ld a,(hl)
567 and a
568 ret z
569 call sub_031ch
570 jr nc,l030ch
571 res 7,b
572 ret
573
574 sub_0318h:
575 push bc
576 res 7,b
577 defb 03eh ;ld a,nn
578 sub_031ch:
579 push bc
580 push de
581 l031eh:
582 call get_char_upper
583 xor (hl)
584 and 07fh
585 jr nz,l0336h
586 bit 7,(hl)
587 inc hl
588 inc de
589 jr z,l031eh
590 scf
591 bit 7,b
592 call z,sub_060ch
593 jr nc,l0339h
594 pop af
595 scf
596 pop bc
597 ret
598 l0336h:
599 call sub_0345h
600 l0339h:
601 pop de
602 and a
603 pop bc
604 ret
605
606 sel_dc_string:
607 inc b
608 l033eh:
609 dec b
610 ret z
611 call sub_0345h
612 jr l033eh
613
614 sub_0345h:
615 ld a,(hl)
616 and a
617 ret z
618 l0348h:
619 ld a,(hl)
620 inc hl
621 and a
622 ret m
623 jr l0348h
624
625 sub_034eh:
626 call get_arg_range
627 push hl
628 push bc
629 call next_arg
630 call sub_0363h
631 ex de,hl
632 pop bc
633 pop hl
634 ret
635
636 sub_035dh:
637 call expr
638 jr c,error0
639 ret
640
641 sub_0363h:
642 call sub_035dh
643 l0366h:
644 jp assert_eol
645
646 get_lastarg_def:
647 call get_arg_def
648 jr l0366h
649
650 get_arg_def:
651 push hl
652 call expr
653 jr c,l0375h
654 ex (sp),hl
655 l0375h:
656 pop hl
657 ret
658
659 sub_0377h:
660 call b_037c_start
661 jr l0366h
662
663 b_037c_start:
664 defb 0e6h ;and a,.. clear carry
665 get_arg_range:
666 scf
667 ex af,af'
668 push bc
669 push hl
670 call expr
671 jr nc,l038ch
672 ex af,af'
673 jr c,error0
674 ex af,af'
675 pop hl
676 defb 03eh ;ld a,.. swallow pop af
677 l038ch:
678 pop af
679 call get_range
680 jr nc,l0398h
681 ex af,af'
682 pop bc
683 ret nc
684 error0:
685 jp ERROR
686 l0398h:
687 pop af
688 ret
689
690 get_range:
691 call next_arg
692 cp 'S'
693 jr nz,l03a2h
694 inc de
695 l03a2h:
696 push hl
697 push af ;'S' flag
698 call expr
699 jr c,l03b8h
700 ld b,h
701 ld c,l
702 pop af
703 pop hl
704 jr z,l03b6h ;'S'?
705 ld a,c
706 sub l
707 ld c,a
708 ld a,b
709 sbc a,h
710 ld b,a
711 inc bc
712 l03b6h:
713 and a
714 ret
715 l03b8h:
716 pop af
717 pop hl
718 jr z,error0 ;'S', but no expression following
719 scf
720 ret
721
722 ;-------------------------------------------------------------------------------
723
724 expr:
725 call skipbl
726 expr1:
727 call do_subexpr
728 ret c
729 call do_rel_op
730 ret nc
731 push bc
732 push hl
733 call do_subexpr
734 jr c,error0
735 ex de,hl
736 ex (sp),hl
737 and a
738 sbc hl,de
739 ld hl,0ffffh
740 pop de
741 ret
742
743 ;-------------------------------------------------------------------------------
744
745 do_op_eq:
746 jr z,l03edh
747 jr l03ech
748 do_op_ne:
749 jr nz,l03edh
750 jr l03ech
751 do_op_le:
752 jr z,l03edh
753 do_op_lt:
754 jr c,l03edh
755 jr l03ech
756 do_op_gt:
757 jr z,l03ech
758 do_op_ge:
759 jr nc,l03edh
760 l03ech:
761 inc hl
762 l03edh:
763 and a
764 ret
765 do_rel_op:
766 push hl
767 ld hl,tab_eq_le_ge
768 call lookupch
769 jr nc,l041dh
770 ld a,b
771 or a
772 jr z,l0411h
773 ld a,(de)
774 cp '='
775 jr nz,l0406h
776 inc de
777 inc b
778 inc b
779 jr l0411h
780 l0406h:
781 bit 0,b
782 jr z,l0411h
783 cp '>'
784 jr nz,l0411h
785 inc de
786 ld b,005h
787 l0411h:
788 ld hl,tab_func_eqlege
789 ld a,b
790 add a,a
791 call add_hl_a
792 ld c,(hl)
793 inc hl
794 ld b,(hl)
795 scf
796 l041dh:
797 pop hl
798 ret
799
800 tab_eq_le_ge:
801 db '=<>',0
802
803 tab_func_eqlege:
804 dw do_op_eq
805 dw do_op_lt
806 dw do_op_gt
807 dw do_op_le
808 dw do_op_ge
809 dw do_op_ne
810
811 do_subexpr:
812 call do_factor
813 ret c
814 l0433h:
815 call do_binary_op
816 push hl
817 push bc
818 call do_factor
819 pop bc
820 ex de,hl
821 ex (sp),hl
822 jr nc,l0447h
823 pop de
824 ld a,b
825 or c
826 ret z
827 jp ERROR
828
829 l0447h:
830 ld a,b
831 or c
832 push bc
833 ret nz
834 pop bc
835
836 doop_add:
837 add hl,de
838 l044dh:
839 pop de
840 jr l0433h
841
842 doop_sub:
843 and a
844 sbc hl,de
845 jr l044dh
846
847 doop_mlt:
848 push bc
849 ld b,h
850 ld c,l
851 ld hl,0
852 ld a,010h
853 l045dh:
854 add hl,hl
855 ex de,hl
856 add hl,hl
857 ex de,hl
858 jr nc,l0464h
859 add hl,bc
860 l0464h:
861 dec a
862 jr nz,l045dh
863 pop bc
864 jr l044dh
865
866 doop_div:
867 call div_hl_de
868 jr l044dh
869
870 doop_mod:
871 call div_hl_de
872 ex de,hl
873 jr l044dh
874
875 ; divide x/y
876 ; hl: x
877 ; de: y
878 ; return:
879 ; hl: q (x/y)
880 ; de: r (x%y)
881
882 div_hl_de:
883 push bc
884 ex de,hl ;de: x
885 ld b,h ;bc: y
886 ld c,l
887 ld hl,0 ;hl: r
888 ld a,16
889
890 ; de: x (x shifted out, q shifted in)
891 ; bc: y
892 ; hl: r (initially 0)
893
894 div_lp:
895 ex de,hl
896 add hl,hl ;x <<= 1
897 ex de,hl
898 adc hl,hl ;r <<= 1
899 inc de
900 or a
901 sbc hl,bc
902 jr nc,div_norestore
903 dec de
904 add hl,bc
905 div_norestore:
906 dec a
907 jr nz,div_lp
908 ex de,hl
909 pop bc
910 ret
911
912 doop_and:
913 ld a,h
914 and d
915 ld h,a
916 ld a,l
917 and e
918 ld l,a
919 jr l044dh
920
921 doop_or:
922 ld a,h
923 or d
924 ld h,a
925 ld a,l
926 or e
927 ld l,a
928 jr l044dh
929
930 doop_xor:
931 ld a,h
932 xor d
933 ld h,a
934 ld a,l
935 xor e
936 ld l,a
937 jr l044dh
938
939 do_binary_op:
940 push hl
941 ld hl,tab_op_a
942 call lookupch
943 ld a,b
944 ld hl,tblf_opa
945 add a,a
946 call add_hl_a
947 ld c,(hl)
948 inc hl
949 ld b,(hl)
950 pop hl
951 ret
952
953 tab_op_a:
954 DB '+-*/%&!#',0
955
956 tblf_opa:
957 dw doop_add
958 dw doop_sub
959 dw doop_mlt
960 dw doop_div
961 dw doop_mod
962 dw doop_and
963 dw doop_or
964 dw doop_xor
965 dw 0
966
967 ;-------------------------------------------------------------------------------
968
969 fact_factor:
970 call do_factor
971 ret nc
972 jp ERROR
973
974 do_factor:
975 call chk_stack
976 call get.number
977 ret nc
978 inc de
979 ld hl,(BDOS+1)
980 cp 'T'
981 ret z
982 ld hl,(high_load)
983 cp 'H'
984 ret z
985 ld hl,(max_load)
986 cp 'M'
987 ret z
988 ld hl,TPA
989 cp 'L'
990 ret z
991 ld hl,(var.@)
992 cp '@'
993 ret z
994 ld hl,(var.$)
995 cp '$'
996 ret z
997 ld hl,ddtz_base
998 cp 'Z'
999 ret z
1000 cp '-'
1001 jr z,fact_factneg
1002 cp '~'
1003 jr z,fact_factinv
1004 cp '+'
1005 jr z,fact_factor
1006 cp '^'
1007 jr z,fact_reg.CPU
1008 cp '('
1009 jr z,fact_mem
1010 cp '['
1011 jr z,expr_brckt
1012 cp ''''
1013 jr z,fact_factstring
1014 dec de
1015 scf
1016 ret
1017
1018 ;-------------------------------------------------------------------------------
1019
1020 fact_factstring:
1021 ld hl,0
1022 l054bh:
1023 ld a,(de)
1024 cp ''''
1025 jr z,l0557h
1026 and a
1027 ret z
1028 l0552h:
1029 ld h,l
1030 ld l,a
1031 inc de
1032 jr l054bh
1033 l0557h:
1034 inc de
1035 ld a,(de)
1036 cp ''''
1037 jr z,l0552h
1038 sub '.'
1039 or a
1040 ret nz
1041 inc de
1042 set 7,l
1043 ret
1044
1045 fact_reg.CPU:
1046 call sub_0caeh
1047 jr nc,error1
1048 ld a,(hl)
1049 inc hl
1050 ld h,(hl)
1051 ld l,a
1052 and a
1053 bit 0,c
1054 ret nz
1055 ld h,000h
1056 ret
1057
1058 fact_factneg:
1059 call fact_factor
1060 dec hl
1061 cpl.hl:
1062 ld a,h
1063 cpl
1064 ld h,a
1065 ld a,l
1066 cpl
1067 ld l,a
1068 ret
1069
1070 fact_factinv:
1071 call fact_factor
1072 jr cpl.hl
1073
1074 fact_mem:
1075 call expr1
1076 jr c,error1
1077 ld a,(de)
1078 cp ')'
1079 jr nz,error1
1080 inc de
1081 ld a,(hl)
1082 inc hl
1083 ld h,(hl)
1084 ld l,a
1085 ld a,(de)
1086 inc de
1087 cp '.'
1088 ret z
1089 dec de
1090 xor a
1091 ld h,a
1092 ret
1093
1094 expr_brckt:
1095 call expr1
1096 jr c,error1
1097 ld a,(de)
1098 cp ']'
1099 inc de
1100 ret z
1101 error1:
1102 jp ERROR
1103
1104 ;-------------------------------------------------------------------------------
1105
1106 get.number:
1107 call get.hexdigit
1108 ret c
1109 push de
1110 test_number:
1111 inc de
1112 call get.hexdigit
1113 jr nc,test_number
1114 pop de
1115 cp '.'
1116 jr z,get_dec_number
1117 cp '"'
1118 jr z,get_bin_number
1119 ld hl,0
1120 next_hexdigit:
1121 call get.hexdigit
1122 jr c,hexnum_done
1123 add hl,hl
1124 add hl,hl
1125 add hl,hl
1126 add hl,hl
1127 call add_hl_a
1128 inc de
1129 jr next_hexdigit
1130
1131 hexnum_done:
1132 xor 'H'
1133 ret nz
1134 inc de
1135 ret
1136
1137 get_bin_number:
1138 ld hl,0
1139 next_bindigit:
1140 call get.bindigit
1141 l05dbh:
1142 inc de
1143 jr c,l05e4h
1144 add hl,hl
1145 call add_hl_a
1146 jr next_bindigit
1147 l05e4h:
1148 cp '"'
1149 jr nz,error11
1150 call get.bindigit
1151 jr nc,l05dbh
1152 or a
1153 ret
1154
1155 get_dec_number:
1156 ld hl,0
1157 next_decdigit:
1158 call get.decdigit
1159 inc de
1160 jr c,decnum_done
1161 push bc
1162 add hl,hl
1163 ld b,h
1164 ld c,l
1165 add hl,hl
1166 add hl,hl
1167 add hl,bc
1168 pop bc
1169 call add_hl_a
1170 jr next_decdigit
1171 decnum_done:
1172 cp '.'
1173 ret z
1174 error11:
1175 jp ERROR
1176
1177 sub_060ch:
1178 call get_char_upper
1179 cp 'Z'+1
1180 jr l0614h
1181
1182 get.hexdigit:
1183 ld a,(de)
1184 hex_digit:
1185 call toupper
1186 cp 'F'+1
1187 l0614h:
1188 ccf
1189 ret c
1190 cp 'A'
1191 jr c,l061eh
1192 sub 'A'-10
1193 ret
1194
1195 get.decdigit:
1196 call get_char_upper
1197 l061eh:
1198 cp '9'+1
1199 jr l0625h
1200
1201 get.bindigit:
1202 call get_char_upper
1203 cp '1'+1
1204 l0625h:
1205 ccf
1206 ret c
1207 cp '0'
1208 ret c
1209 sub '0'
1210 ret
1211
1212 ;-------------------------------------------------------------------------------
1213
1214 p_cpustat0:
1215 call assert_eol
1216 p_cpustat:
1217 call p_f
1218 call outbl2
1219 ld hl,b_06e9_start
1220 ld de,b_0709_start
1221 ld b,6
1222 l063eh:
1223 call p_regs
1224 djnz l063eh
1225 push hl
1226 push de
1227 ld iy,(reg.pc)
1228 call p_disas_instr
1229 pop de
1230 ex (sp),hl
1231 push af
1232 call crlf
1233 call p_f2
1234 call outbl2
1235 ld b,7
1236 l065bh:
1237 call p_regs
1238 djnz l065bh
1239 pop af
1240 pop hl
1241 call nz,outbl6
1242 call nz,p_offset
1243 jp crlf
1244
1245 p_f:
1246 ld a,(reg.f)
1247 call p_flags
1248 ld a,(reg.iff)
1249 cp 0f3h
1250 jp z,outbl
1251 ld a,'E'
1252 jp outchar
1253 p_f2:
1254 ld a,(reg.f2)
1255 call p_flags
1256 jp outbl
1257
1258 p_flags:
1259 push hl
1260 ld hl,t_flag_names+7
1261 ld c,a
1262 ld b,8
1263 fl_loop:
1264 ld a,' '
1265 cp (hl)
1266 ld a,c
1267 rlca
1268 ld c,a
1269 jr z,fl_skip
1270 ld a,(hl)
1271 call c,outchar
1272 call nc,outbl
1273 fl_skip:
1274 dec hl
1275 djnz fl_loop
1276 pop hl
1277 ret
1278
1279 p_regs:
1280 push de
1281 call pstr
1282 call pstr_inl
1283 dc '='
1284 ex (sp),hl
1285 ld e,(hl)
1286 inc hl
1287 ld d,(hl)
1288 inc hl
1289 ld a,(hl)
1290 inc hl
1291 push hl
1292 and a
1293 jr z,l06deh
1294 ex de,hl
1295 ld e,(hl)
1296 inc hl
1297 ld d,(hl)
1298 ex de,hl
1299 dec a
1300 jr z,l06d9h
1301 call out.hl.@
1302 call z,outbl6
1303 jr l06e2h
1304 l06d9h:
1305 call out_hl
1306 jr l06e2h
1307 l06deh:
1308 ld a,(de)
1309 call out_hex
1310 l06e2h:
1311 call outbl
1312 pop de
1313 pop hl
1314 ret
1315
1316 b_06e9_start:
1317 DC 'A '
1318 DC 'BC '
1319 DC 'DE '
1320 DC 'HL '
1321 DC 'SP'
1322 DC 'PC'
1323 DC 'a'''
1324 DC 'bc'''
1325 DC 'de'''
1326 DC 'hl'''
1327 DC 'IX'
1328 DC 'IY'
1329 DC 'I'
1330 DB 0
1331
1332 b_0709_start:
1333 dw reg.a
1334 db 000h
1335 dw reg.c
1336 db 001h
1337 dw reg.e
1338 db 001h
1339 dw reg.l
1340 db 001h
1341 dw reg_sp
1342 db 001h
1343 dw reg.pc
1344 db 002h
1345 dw reg.a2
1346 db 000h
1347 dw reg.c2
1348 db 001h
1349 dw reg.e2
1350 db 001h
1351 dw reg.l2
1352 db 001h
1353 dw reg.ix
1354 db 001h
1355 dw reg.iy
1356 db 001h
1357 dw reg.i
1358 db 000h
1359 db 000h
1360
1361 ;-------------------------------------------------------------------------------
1362 ; > G [startaddr] [;breakp..]
1363 ; Go [to start] [with temporary breakpoints]
1364
1365 cmd_G:
1366 sub a
1367 ld (trace_call_flag),a
1368 ld (bp_p_cpu_flag),a
1369 call expr
1370 jr c,l0740h
1371 ld (reg.pc),hl
1372 l0740h:
1373 call skipbl
1374 jr z,user_go0
1375 cp ';'
1376 jp nz,ERROR
1377 inc de
1378 ld a,002h
1379 call bp_enter
1380 user_go0:
1381 jp user_go
1382
1383 ;-------------------------------------------------------------------------------
1384
1385 bpl_init:
1386 ld b,BP_CNT
1387 ld ix,bp_tab
1388 ex (sp),hl
1389 ld (pbl_loop_adr),hl
1390 ex (sp),hl
1391 ret
1392
1393 bpl_next:
1394 ld de,BP_SIZE
1395 push af
1396 add ix,de
1397 pop af
1398 dec b
1399 ret z
1400
1401 ex (sp),hl
1402 ld hl,(pbl_loop_adr)
1403 ex (sp),hl
1404 ret
1405
1406 bp_clr_temporary:
1407 call bpl_init
1408
1409 ld a,(ix+000h)
1410 and 0f1h
1411 ld (ix+000h),a
1412 call bp_clr_condition
1413
1414 call bpl_next
1415 ret
1416
1417 ;-------------------------------------------------------------------------------
1418 ; > B
1419 ; display all breakpoints
1420 ; > B breakp [breakp..]
1421 ; set breakpoints
1422 ; > BX
1423 ; clear all breakpoints
1424 ; > BX address [address..]
1425 ; clear breakpoints
1426 ;
1427 ; where breakp is:
1428 ; [R] expression [I condition]
1429
1430 cmd_B:
1431 call skipbl
1432 jr z,bp_print
1433 inc de
1434 cp 'X'
1435 jr z,bp_clr0
1436 dec de
1437 ld a,001h
1438 jp bp_enter
1439
1440 bp_clr0:
1441 call skipbl
1442 jr z,bp_clr_all
1443 bp_clr_next:
1444 call expr
1445 jp c,assert_eol
1446 push de
1447 call bp_clr
1448 pop de
1449 call next_arg
1450 jr bp_clr_next
1451
1452 bp_clr_all:
1453 scf
1454 bp_clr:
1455 call bpl_init
1456
1457 push af
1458 jr c,l07a7h
1459 ld e,(ix+002h)
1460 ld d,(ix+003h)
1461 call cp_hl_de
1462 jr nz,l07aeh
1463 l07a7h:
1464 ld (ix+000h),000h
1465 call bp_clr_condition
1466 l07aeh:
1467 pop af
1468 call bpl_next
1469 ret
1470
1471 bp_print:
1472 call bpl_init
1473
1474 bit 0,(ix+000h)
1475 jr z,bp_pr_cont
1476 ld a,'R'
1477 bit 4,(ix+000h)
1478 jr nz,l07cdh
1479 ld a,' '
1480 l07cdh:
1481 call outchar
1482 call outbl
1483 ld l,(ix+002h)
1484 ld h,(ix+003h)
1485 call out.hl.@
1486 call pstr_inl
1487 dc ' :'
1488 ld l,(ix+004h)
1489 ld h,(ix+005h)
1490 call out_hl
1491 ld l,(ix+006h)
1492 ld h,(ix+007h)
1493 ld a,h
1494 or l
1495 jr z,l0805h
1496 call outbl4
1497 call pstr_inl
1498 dc 'I '
1499 call pstr
1500 l0805h:
1501 call crlf
1502 bp_pr_cont:
1503 call bpl_next
1504 ret
1505
1506 ;-------------------------------------------------------------------------------
1507 ; Add break points to list
1508 ; A = 1 Permanent (B command)
1509 ; A = 2 Temporary (G command)
1510
1511 bp_enter:
1512 ld b,a
1513 call skipbl
1514 ret z
1515 cp 'R'
1516 jr nz,bp_e_1
1517 inc de
1518 set 4,b
1519 bp_e_1:
1520 push bc
1521 call expr
1522 jr c,error12
1523 pop bc
1524 bit 0,b
1525 push bc
1526 push de
1527 push hl
1528 call nz,bp_clr
1529 pop hl
1530 call bp_get_freeslot
1531 pop de
1532 ld (ix+002h),l
1533 ld (ix+003h),h
1534 call bp_get_count
1535 ld (ix+004h),l
1536 ld (ix+005h),h
1537 call bp_get_condition
1538 ld (ix+006h),l
1539 ld (ix+007h),h
1540 call next_arg
1541 pop af
1542 ld (ix+000h),a
1543 and 00fh
1544 jr bp_enter
1545
1546 bp_get_freeslot:
1547 call bpl_init
1548
1549 ld a,(ix+000h)
1550 and 00fh
1551 ret z
1552
1553 call bpl_next
1554 error12
1555 jp ERROR
1556
1557 bp_get_count:
1558 call skipbl
1559 ld hl,1
1560 cp ':'
1561 ret nz
1562 inc de
1563 call expr
1564 jr c,error12
1565 ret
1566
1567 bp_get_condition:
1568 call skipbl
1569 cp 'I'
1570 ld hl,0
1571 ret nz
1572 inc de
1573 call skipbl
1574 push de
1575 call expr
1576 jr c,error12
1577 ex de,hl
1578 pop de
1579 push de
1580 sbc hl,de
1581 ld b,h
1582 ld c,l
1583 ld hl,(expr_p1)
1584 push hl
1585 add hl,bc
1586 ld de,expr_bufe
1587 call cp_hl_de
1588 jr nc,error12
1589 pop de
1590 pop hl
1591 push de
1592 ldir
1593 ex de,hl
1594 ld (hl),c ; trailing 0
1595 inc hl
1596 ld (expr_p1),hl
1597 pop hl
1598 ret
1599
1600 ;-------------------------------------------------------------------------------
1601 ; Breakpoint handling routine.
1602
1603 bpddtz:
1604 ld (reg.l),hl
1605 pop hl
1606 dec hl
1607 ld (reg.pc),hl
1608 ld (reg_sp),sp
1609 ld sp,reg.l
1610 push de
1611 push bc
1612 push af
1613 push ix
1614 push iy
1615 ld a,i
1616 call di_or_ei
1617 ld h,a
1618 ld l,000h
1619 push hl
1620 ld a,0f3h ; EI
1621 jp po,l08dfh
1622 ld a,0fbh ; DI
1623 l08dfh:
1624 ld (reg.iff),a
1625 ex af,af'
1626 push af
1627 exx
1628 push bc
1629 push de
1630 push hl
1631 call bp_restore_mem
1632 ld a,(b_21e2_start)
1633 dec a
1634 jr z,l090bh
1635 call inchar ;Keyboard hit?
1636 jr c,do_break ;yes
1637 call sub_0913h
1638 and a
1639 jp z,user_go
1640 and 083h
1641 jp z,l2151h
1642 do_break:
1643 call bp_clr_temporary
1644 call p_cpustat
1645 jp mainloop
1646
1647 l090bh:
1648 ld (b_21e2_start),a
1649 ld c,007h
1650 jp l0a41h
1651
1652 sub_0913h:
1653 ld a,080h
1654 ex af,af'
1655 sub a
1656 ld (bp_p_cpu_flag),a
1657 call bpl_init
1658
1659 ld a,(ix+000h)
1660 and 007h
1661 jr z,l0938h
1662 ld e,(ix+002h)
1663 ld d,(ix+003h)
1664 ld hl,(reg.pc)
1665 call cp_hl_de
1666 push bc
1667 call z,sub_0942h
1668 pop bc
1669 l0938h:
1670
1671 call bpl_next
1672 ex af,af'
1673 ret
1674
1675 sub_0942h:
1676 ex af,af'
1677 res 7,a
1678 ex af,af'
1679 ld e,(ix+006h)
1680 ld d,(ix+007h)
1681 ld a,d
1682 or e
1683 ld hl,0ffffh
1684 call nz,expr
1685 ld a,h
1686 or l
1687 jr z,l0969h
1688 ld e,(ix+004h)
1689 ld d,(ix+005h)
1690 dec de
1691 ld a,d
1692 or e
1693 jr z,l0974h
1694 ld (ix+004h),e
1695 ld (ix+005h),d
1696 l0969h:
1697 bit 4,(ix+000h)
1698 ret z
1699 ld a,001h
1700 ld (bp_p_cpu_flag),a
1701 ret
1702 l0974h:
1703 ex af,af'
1704 or (ix+000h)
1705 ex af,af'
1706 ret
1707
1708 bp_restore_mem:
1709 call bpl_init
1710
1711 bit 5,(ix+000h)
1712 res 5,(ix+000h)
1713 jr z,l099ah
1714 ld l,(ix+002h)
1715 ld h,(ix+003h)
1716 ld a,(l0003h)
1717 cp (hl)
1718 jr nz,l099ah
1719 ld a,(ix+001h)
1720 ld (hl),a
1721 l099ah:
1722 res 3,(ix+000h)
1723
1724 call bpl_next
1725 ret
1726
1727 bp_tst_@pc:
1728 call bpl_init
1729
1730 ld a,(ix+000h)
1731 and 003h
1732 jr z,bp_tst_e
1733 ld e,(ix+002h)
1734 ld d,(ix+003h)
1735 ld hl,(reg.pc)
1736 call cp_hl_de
1737 ret z
1738 bp_tst_e:
1739 call bpl_next
1740 sub a
1741 inc a
1742 ret
1743
1744 bp_trace_enter:
1745 call bp_get_freeslot
1746 ld (ix+004h),001h
1747 ld (ix+005h),000h
1748 ld (ix+002h),l
1749 ld (ix+003h),h
1750 ld (ix+006h),000h
1751 ld (ix+007h),000h
1752 ld a,(b_21e2_start)
1753 and a
1754 ld a,008h
1755 jr nz,bp_t_e
1756 rra
1757 bp_t_e:
1758 ld (ix+000h),a
1759 ret
1760
1761 bp_set_to_mem:
1762 call bpl_init
1763
1764 ld a,(ix+000h)
1765 and c
1766 jr z,l0a1dh
1767 set 5,(ix+000h)
1768 ld l,(ix+002h)
1769 ld h,(ix+003h)
1770 ld a,(hl)
1771 ld (ix+001h),a
1772 ld a,(l0003h)
1773 ld (hl),a
1774 and 038h
1775 ld h,000h
1776 ld l,a
1777 ld (hl),0c3h
1778 inc hl
1779 ld de,bpddtz
1780 ld (hl),e
1781 inc hl
1782 ld (hl),d
1783 l0a1dh:
1784
1785 call bpl_next
1786 ret
1787
1788 ;-------------------------------------------------------------------------------
1789
1790 user_go:
1791 sub a
1792 ld (b_21e2_start),a
1793 ld a,(bp_p_cpu_flag)
1794 and a
1795 call nz,p_cpustat
1796 call bp_tst_@pc
1797 ld c,007h
1798 jr nz,l0a41h
1799 ld a,001h
1800 ld (b_21e2_start),a
1801 call tc_set_bp
1802 ld c,008h
1803 l0a41h:
1804 call bp_set_to_mem
1805 ld sp,reg.l2
1806 pop hl
1807 pop de
1808 pop bc
1809 pop af
1810 exx
1811 ex af,af'
1812 pop af
1813 ld i,a
1814 pop iy
1815 pop ix
1816 pop af
1817 pop bc
1818 pop de
1819 pop hl
1820 ld sp,(reg_sp)
1821 jp reg.iff
1822
1823 ;-------------------------------------------------------------------------------
1824
1825 bp_clr_condition:
1826 ld a,(ix+000h)
1827 and 003h
1828 ret nz
1829 ld e,(ix+006h)
1830 ld d,(ix+007h)
1831 ld a,d
1832 or e
1833 ret z
1834 push bc
1835 ld h,d
1836 ld l,e
1837 sub a
1838 ld (ix+006h),a
1839 ld (ix+007h),a
1840 ld bc,0ffffh
1841 cpir
1842 l0a7dh:
1843 push de
1844 ld de,(expr_p1)
1845 call cp_hl_de
1846 pop de
1847 jr nc,l0a93h
1848 call sub_0a99h
1849 l0a8bh:
1850 ld a,(hl)
1851 ldi
1852 and a
1853 jr nz,l0a8bh
1854 jr l0a7dh
1855 l0a93h:
1856 ld (expr_p1),de
1857 pop bc
1858 ret
1859
1860 sub_0a99h:
1861 ld iy,bp_tab
1862 push de
1863 l0a9eh:
1864 ld e,(iy+006h)
1865 ld d,(iy+007h)
1866 call cp_hl_de
1867 jr z,l0ab0h
1868 ld de,BP_SIZE
1869 add iy,de
1870 jr l0a9eh
1871 l0ab0h:
1872 pop de
1873 ld (iy+006h),e
1874 ld (iy+007h),d
1875 ret
1876
1877 ;-------------------------------------------------------------------------------
1878 ; > Y
1879 ; examine all Y variables
1880 ; > Y[0..9]
1881 ; examine (and substitute) an Y variable
1882
1883
1884 ;-------------------------------------------------------------------------------
1885 ; > X
1886 ; eXamine (display) all cpu registers and
1887 ; the instruction at the current program counter
1888 ; > X register
1889 ; eXamine (and substitute) a register
1890
1891
1892 cmd_X:
1893 call skipbl
1894 call sub_0caeh
1895 jp nc,p_cpustat0
1896 call assert_eol
1897 ld a,b
1898 cp 01eh
1899 jr z,l0c5fh
1900 cp 01fh
1901 jr z,l0c4fh
1902 cp 01dh
1903 jp z,ERROR
1904 ex de,hl
1905 ld hl,t_reg_names
1906 call sel_dc_string
1907 l0c12h:
1908 call l0c33h
1909 l0c15h:
1910 call outbl
1911 push de
1912 push bc
1913 call get_line
1914 call skipbl
1915 jr z,l0c30h
1916 call sub_0363h
1917 ex de,hl
1918 pop bc
1919 pop hl
1920 ld (hl),e
1921 bit 0,c
1922 ret z
1923 inc hl
1924 ld (hl),d
1925 ret
1926 l0c30h:
1927 pop af
1928 pop hl
1929 ret
1930
1931 l0c33h:
1932 call pstr
1933 call pstr_inl
1934 dc '='
1935 ld a,(de)
1936 bit 0,c
1937 jp z,out_hex
1938 ld l,a
1939 inc de
1940 ld a,(de)
1941 dec de
1942 ld h,a
1943 bit 1,c
1944 jp z,out_hl
1945 jp out.hl.@
1946
1947 l0c4fh:
1948 call p_f
1949 ld a,0f3h
1950 ld (reg.iff),a
1951 scf
1952 call sub_0c6ah
1953 ld (reg.f),a
1954 ret
1955 l0c5fh:
1956 call p_f2
1957 and a
1958 call sub_0c6ah
1959 ld (reg.f2),a
1960 ret
1961
1962 sub_0c6ah:
1963 push af
1964 call outbl
1965 call assert_eol
1966 call get_line
1967 pop af
1968 ex af,af'
1969 ld b,0
1970 l0c76h:
1971 call skipbl
1972 ld a,b
1973 ret z
1974 push bc
1975 ld hl,t_flag_names
1976 call lookupch
1977 jp nc,ERROR
1978 inc b
1979 xor a
1980 scf
1981 nxt_f:
1982 rla
1983 djnz nxt_f
1984 pop bc
1985 jr c,l0c97h
1986 or b
1987 ld b,a
1988 jr l0c76h
1989
1990 l0c97h:
1991 ex af,af'
1992 jp nc,ERROR
1993 ex af,af'
1994 ld a,0fbh
1995 ld (reg.iff),a
1996 jr l0c76h
1997
1998 t_flag_names:
1999 db 'CNV H ZSE',0
2000
2001 sub_0caeh:
2002 call sub_0303h
2003 ret nc
2004 ld a,b
2005 add a,b
2006 add a,b
2007 ld hl,b_0cfa_start
2008 call add_hl_a
2009 ld c,(hl)
2010 inc hl
2011 ld a,(hl)
2012 inc hl
2013 ld h,(hl)
2014 ld l,a
2015 scf
2016 ret
2017
2018 t_reg_names:
2019 DC 'BC'''
2020 DC 'DE'''
2021 DC 'HL'''
2022 DC 'BC'
2023 DC 'DE'
2024 DC 'HL'
2025 DC 'A'''
2026 DC 'B'''
2027 DC 'C'''
2028 DC 'D'''
2029 DC 'E'''
2030 DC 'H'''
2031 DC 'L'''
2032 DC 'A'
2033 DC 'B'
2034 DC 'C'
2035 DC 'D'
2036 DC 'E'
2037 DC 'H'
2038 DC 'L'
2039 DC 'IX'
2040 DC 'IY'
2041 DC 'SP'
2042 DC 'PC'
2043 DC 'X'
2044 DC 'Y'
2045 DC 'S'
2046 DC 'P'
2047 DC 'I'
2048 DC 'IP'
2049 DC 'F'''
2050 DC 'F'
2051 DB 0
2052
2053 b_0cfa_start:
2054 db 003h
2055 dw reg.c2
2056 db 003h
2057 dw reg.e2
2058 db 003h
2059 dw reg.l2
2060 db 003h
2061 dw reg.c
2062 db 003h
2063 dw reg.e
2064 db 003h
2065 dw reg.l
2066 db 000h
2067 dw reg.a2
2068 db 000h
2069 dw reg.b2
2070 db 000h
2071 dw reg.c2
2072 db 000h
2073 dw reg.d2
2074 db 000h
2075 dw reg.e2
2076 db 000h
2077 dw reg.h2
2078 db 000h
2079 dw reg.l2
2080 db 000h
2081 dw reg.a
2082 db 000h
2083 dw reg.b
2084 db 000h
2085 dw reg.c
2086 db 000h
2087 dw reg.d
2088 db 000h
2089 dw reg.e
2090 db 000h
2091 dw reg.h
2092 db 000h
2093 dw reg.l
2094 db 003h
2095 dw reg.ix
2096 db 003h
2097 dw reg.iy
2098 db 003h
2099 dw reg_sp
2100 db 003h
2101 dw reg.pc
2102 db 003h
2103 dw reg.ix
2104 db 003h
2105 dw reg.iy
2106 db 003h
2107 dw reg_sp
2108 db 003h
2109 dw reg.pc
2110 db 000h
2111 dw reg.i
2112 db 003h
2113 dw l004eh
2114 db 000h
2115 dw reg.f2
2116 db 000h
2117 dw reg.f
2118
2119 ;-------------------------------------------------------------------------------
2120 ; > S [startaddr]
2121 ; Substitute memory
2122
2123 cmd_S:
2124 ld hl,(last_S)
2125 call get_lastarg_def
2126 l0d60h:
2127 ld (last_S),hl
2128 call out.hl.@
2129 call outbl
2130 ld a,(hl)
2131 call out_hex
2132 call outbl2
2133 call get_line
2134 call skipbl
2135 inc hl
2136 jr z,l0d60h
2137 dec hl
2138 inc de
2139 cp '.'
2140 jr nz,cmds_dash
2141 call get_char_upper
2142 or a
2143 jr nz,l0d8ah
2144 ret
2145 cmds_dash:
2146 jp z,assert_eol
2147 cp '-'
2148 jr nz,l0d8ah
2149 call get_char_upper
2150 or a
2151 dec hl
2152 jr z,l0d60h
2153 inc hl
2154 l0d8ah:
2155 dec de
2156 call sub_0ef8h
2157 jr l0d60h
2158
2159 ;-------------------------------------------------------------------------------
2160 ; > @
2161 ; examine (substitute) displacement register @
2162
2163 cmd_@:
2164 call assert_eol
2165 ld hl,msg_@
2166 ld de,var.@
2167 ld c,001h
2168 jp l0c12h
2169
2170 msg_@:
2171 dc '@'
2172
2173 ;-------------------------------------------------------------------------------
2174 ; >>I [port]
2175 ; Input a byte from port
2176
2177 cmd_I:
2178 ld hl,cmd_I
2179 ld (cmd_rpt),hl
2180 ld hl,(last_I)
2181 call get_lastarg_def
2182 ld (last_I),hl
2183 ld b,h
2184 ld c,l
2185 in a,(c)
2186 push af
2187 call out_hex
2188 call outbl4
2189 pop af
2190 call out.bin.b
2191 jp crlf
2192
2193 ;-------------------------------------------------------------------------------
2194 ; >>O [byte] [port]
2195 ; Output a byte to a port
2196
2197 cmd_O:
2198 ld hl,cmd_O
2199 ld (cmd_rpt),hl
2200 ld hl,(last_O_val)
2201 call get_arg_def
2202 ld a,l
2203 ld (last_O_val),a
2204 push af
2205 call next_arg
2206 ld hl,(last_O_addr)
2207 call get_lastarg_def
2208 ld (last_O_addr),hl
2209 ld b,h
2210 ld c,l
2211 pop af
2212 out (c),a
2213 ret
2214
2215 ;-------------------------------------------------------------------------------
2216 ; > Vstartaddr endaddr targetaddr
2217 ; Verify (compare) two memory areas
2218
2219 cmd_V:
2220 call sub_034eh
2221 l0dedh:
2222 push bc
2223 ld a,(de)
2224 ld b,(hl)
2225 cp b
2226 jr z,l0e10h
2227 ld c,a
2228 call out.hl.@
2229 call outbl
2230 ld a,b
2231 call out_hex
2232 call outbl2
2233 ld a,c
2234 call out_hex
2235 call outbl
2236 ex de,hl
2237 call out.hl.@
2238 ex de,hl
2239 call crlf
2240 l0e10h:
2241 pop bc
2242 inc hl
2243 inc de
2244 dec bc
2245 ld a,b
2246 or c
2247 jr nz,l0dedh
2248 ret
2249
2250 ;-------------------------------------------------------------------------------
2251 ; > M[V] startaddr endaddr destaddr
2252 ; Move memory [and verify]
2253
2254 cmd_M:
2255 call get_char_upper
2256 cp 'V'
2257 jr nz,l0e1fh
2258 inc de
2259 l0e1fh:
2260 push af
2261 call sub_034eh
2262 push hl
2263 push de
2264 push bc
2265 call cp_hl_de
2266 jr nc,cmdm_up
2267 add hl,bc
2268 ex de,hl
2269 add hl,bc
2270 ex de,hl
2271 dec hl
2272 dec de
2273 lddr
2274 db 01h ;swallow ldir instruction (ld bc,...)
2275 cmdm_up:
2276 ldir
2277 pop bc
2278 pop de
2279 pop hl
2280 pop af
2281 jr z,l0dedh
2282 ret
2283
2284 ;-------------------------------------------------------------------------------
2285 ; > H
2286 ; display Highest load address of last filed loaded, Maximum "High"
2287 ; off all loaded files, and Top address of available memory
2288 ; > H expression
2289 ; evaluate expression and display result in hex, decimal and other formats
2290 ; > H expression expression
2291 ; display sum und difference of expressions
2292
2293 cmd_H:
2294 call expr
2295 jp c,p_max_high0
2296 call next_arg
2297 push hl
2298 call expr
2299 push af
2300 call assert_eol
2301 pop af
2302 ex de,hl
2303 pop hl
2304 jr c,l0e5eh
2305 push hl
2306 push de
2307 add hl,de
2308 call l0e5eh
2309 pop de
2310 pop hl
2311 and a
2312 sbc hl,de
2313 l0e5eh:
2314 call out_hl
2315 call outbl2
2316 call out_hl_neg
2317 call outbl4
2318 call out.hl.dec
2319 call outbl2
2320 call out_hl_dec_neg
2321 call outbl4
2322 call out.bin.w
2323 call outbl2
2324 ld a,l
2325 call out.ascii
2326 jp crlf
2327
2328 ;-------------------------------------------------------------------------------
2329 ; > Q[J] startaddr endaddr bytes
2330 ; Query memory for a byte string [Justified]
2331
2332 cmd_Q:
2333 call get_char_upper
2334 sub 'J'
2335 ld (cmd_Q_jopt),a
2336 jr nz,l0e8dh
2337 inc de
2338 l0e8dh:
2339 call get_arg_range
2340 push bc
2341 push hl
2342 call sub_0ee6h
2343 pop hl
2344 l0e96h:
2345 call sub_0ed7h
2346 jr nz,l0eb0h
2347 push bc
2348 push hl
2349 ld a,(cmd_Q_jopt)
2350 or a
2351 jr nz,l0ea7h
2352 ld bc,-8
2353 add hl,bc
2354 l0ea7h:
2355 ld bc,16
2356 and a
2357 call sub_0f58h
2358 pop hl
2359 pop bc
2360 l0eb0h:
2361 inc hl
2362 ex (sp),hl
2363 dec hl
2364 ld a,h
2365 or l
2366 ex (sp),hl
2367 jr nz,l0e96h
2368 pop bc
2369 ret
2370
2371 ;-------------------------------------------------------------------------------
2372 ; > Z startaddr endaddr bytes
2373 ; Zap (fill) memory with a byte string
2374
2375 cmd_Z:
2376 call get_arg_range
2377 push bc
2378 push hl
2379 call sub_0ee6h
2380 ld a,b
2381 pop hl
2382 pop bc
2383 push hl
2384 ex de,hl
2385 l0ec7h:
2386 ldi
2387 jp po,l0ed3h
2388 dec a
2389 jr nz,l0ec7h
2390 pop hl
2391 ldir
2392 ret
2393 l0ed3h:
2394 pop hl
2395 ret
2396
2397 sub_0ed7h:
2398 push hl
2399 push de
2400 push bc
2401 l0edah:
2402 ld a,(de)
2403 cp (hl)
2404 jr nz,l0ee2h
2405 inc de
2406 inc hl
2407 djnz l0edah
2408 l0ee2h:
2409 pop bc
2410 pop de
2411 pop hl
2412 ret
2413
2414 sub_0ee6h:
2415 ld hl,conbuf+1
2416 call sub_0ef7h
2417 ld de,conbuf+1
2418 and a
2419 sbc hl,de
2420 ld b,l
2421 ret nz
2422 jp ERROR
2423
2424 sub_0ef7h:
2425 db 0e6h ; and 037h (clear carry)
2426 sub_0ef8h:
2427 scf
2428 l0ef9h:
2429 push af
2430 call next_arg
2431 cp 'W'
2432 jr nz,l0f0eh
2433 inc de
2434 push hl
2435 call sub_035dh
2436 ex de,hl
2437 ex (sp),hl
2438 ld (hl),e
2439 inc hl
2440 ld a,d
2441 pop de
2442 jr l0f1ah
2443 l0f0eh:
2444 cp ''''
2445 jr z,l0f1eh
2446 push hl
2447 call expr
2448 ld a,l
2449 pop hl
2450 jr c,l0f42h
2451 l0f1ah:
2452 ld (hl),a
2453 inc hl
2454 jr l0f3ah
2455 l0f1eh:
2456 inc de
2457 ld a,(de)
2458 cp ''''
2459 jr z,l0f2bh
2460 or a
2461 jr z,l0f42h
2462 l0f27h:
2463 ld (hl),a
2464 inc hl
2465 jr l0f1eh
2466 l0f2bh:
2467 inc de
2468 ld a,(de)
2469 cp ''''
2470 jr z,l0f27h
2471 cp '.'
2472 jr nz,l0f3ah
2473 inc de
2474 dec hl
2475 set 7,(hl)
2476 inc hl
2477 l0f3ah:
2478 pop af
2479 jr nc,l0ef9h
2480 ld (last_S),hl
2481 jr l0ef9h
2482 l0f42h:
2483 pop af
2484 ret nc
2485 ld (last_S),hl
2486 ret
2487
2488 ;-------------------------------------------------------------------------------
2489 ; >>D [startaddr] [endaddr]
2490 ; Display memory in hex and ASCII
2491
2492 cmd_D:
2493 ld hl,cmd_D
2494 ld (cmd_rpt),hl
2495 ld hl,(last_D)
2496 ld bc,128
2497 call sub_0377h
2498 scf
2499 sub_0f58h:
2500 push bc
2501 push de
2502 push hl
2503 push af
2504 l0f5ch:
2505 call out.hl.@
2506 call z,outbl2
2507 call outbl
2508 ld de,0
2509 l0f68h:
2510 ld a,(hl)
2511 inc hl
2512 call out_hex
2513 call outbl
2514 dec bc
2515 inc e
2516 ld a,e
2517 cp 010h
2518 jr z,l0f80h
2519 and 003h
2520 call z,outbl
2521 ld a,b
2522 or c
2523 jr nz,l0f68h
2524 l0f80h:
2525 call outbl
2526 and a
2527 sbc hl,de
2528 l0f86h:
2529 ld a,(hl)
2530 call sub_0fa3h
2531 call outchar
2532 inc hl
2533 dec e
2534 jr nz,l0f86h
2535 pop af
2536 push af
2537 jr nc,l0f97h
2538 ld (last_D),hl
2539 l0f97h:
2540 call crlf
2541 ld a,b
2542 or c
2543 jr nz,l0f5ch
2544 pop af
2545 pop hl
2546 pop de
2547 pop bc
2548 ret
2549
2550 sub_0fa3h:
2551 and 07fh
2552 cp 07fh
2553 jr z,l0fach
2554 cp ' '
2555 ret nc
2556 l0fach:
2557 ld a,'.'
2558 ret
2559
2560 ;-------------------------------------------------------------------------------
2561 ; > Fcommandline
2562 ; specifiy filenames and command line
2563
2564 cmd_F:
2565 push de
2566 ld hl,DMA_BUF+1
2567 ld (hl),' '
2568 inc hl
2569 l0fb6h:
2570 call get_char_upper
2571 ld (hl),a
2572 inc hl
2573 inc de
2574 and a
2575 jr nz,l0fb6h
2576 ld a,l
2577 sub DMA_BUF+2
2578 ld (DMA_BUF),a
2579 pop hl
2580 ld de,dfcb1
2581 call parse_filename
2582 ld de,dfcb2
2583 ;fall thru
2584
2585 parse_filename:
2586 call sub_102ch
2587 push de
2588 push bc
2589 ld b,(hl)
2590 inc hl
2591 ld a,(hl)
2592 cp ':'
2593 jr nz,l0fe1h
2594 inc hl
2595 ld a,b
2596 sub 040h
2597 and 01fh
2598 jr l0fe3h
2599 l0fe1h:
2600 dec hl
2601 xor a
2602 l0fe3h:
2603 ld (de),a
2604 inc de
2605 ld b,8
2606 call sub_0ff2h
2607 ld b,3
2608 call sub_0ff2h
2609 pop bc
2610 pop de
2611 ret
2612
2613 sub_0ff2h:
2614 call sub_1012h
2615 jr z,l0ffeh
2616 inc hl
2617 ld (de),a
2618 inc de
2619 djnz sub_0ff2h
2620 jr l1003h
2621 l0ffeh:
2622 ld a,c
2623 l0fffh:
2624 ld (de),a
2625 inc de
2626 djnz l0fffh
2627 l1003h:
2628 call sub_1012h
2629 inc hl
2630 jr nz,l1003h
2631 cp '*'
2632 jr z,l1003h
2633 cp '.'
2634 ret z
2635 dec hl
2636 ret
2637
2638 sub_1012h:
2639 ld a,(hl)
2640 ld c,' '
2641 and 01fh
2642 ret z
2643 ld a,(hl)
2644 cp ' '
2645 ret z
2646 call sub_1043h
2647 ret z
2648 cp '/'
2649 ret z
2650 cp '.'
2651 ret z
2652 ld c,'?'
2653 call toupper
2654 cp '*'
2655 ret
2656
2657 l102bh:
2658 inc hl
2659 sub_102ch:
2660 ld a,(hl)
2661 cp '/'
2662 jr z,l103bh
2663 call sub_1043h
2664 jr z,l102bh
2665 l1036h:
2666 cp ' '
2667 jr z,l102bh
2668 ret
2669
2670 l103bh:
2671 ld a,(hl)
2672 cp ' '+1
2673 jr c,l1036h
2674 inc hl
2675 jr l103bh
2676
2677 sub_1043h:
2678 cp '='
2679 ret z
2680 cp '_'
2681 ret z
2682 cp ','
2683 ret
2684
2685 ;-------------------------------------------------------------------------------
2686
2687 setup_fcb:
2688 push de
2689 ld hl,12
2690 add hl,de
2691 xor a
2692 ld b,21
2693 l1052h:
2694 ld (hl),a
2695 inc hl
2696 djnz l1052h
2697 ld de,DMA_BUF
2698 ld c,BDOS_SETDMA
2699 call ddtz_bdos
2700 pop de
2701 ret
2702
2703 ;-------------------------------------------------------------------------------
2704
2705 file_open:
2706 ld (cur_fcb),de
2707 call setup_fcb
2708 ld c,BDOS_OPEN
2709 call ddtz_bdos
2710 inc a
2711 jp z,ERROR
2712 ld a,080h
2713 ld (cmdR_rindex),a
2714 ret
2715
2716 read_byte:
2717 ld a,(cmdR_rindex)
2718 cp 080h
2719 jr nz,l1111h
2720 call read_sector
2721 ld a,01ah
2722 ret z
2723 sub a
2724 l1111h:
2725 inc a
2726 ld (cmdR_rindex),a
2727 push hl
2728 add a,07fh
2729 ld l,a
2730 ld h,000h
2731 ld a,(hl)
2732 pop hl
2733 cp 01ah
2734 ret
2735
2736 read_sector:
2737 push hl
2738 push de
2739 push bc
2740 ld de,(cur_fcb)
2741 ld c,BDOS_READ
2742 call ddtz_bdos
2743 sub a,1
2744 jr z,l1132h
2745 jr nc,error2
2746 l1132h:
2747 pop bc
2748 pop de
2749 pop hl
2750 ret
2751
2752 cmdR_storebyte:
2753 push af
2754 push de
2755 ld de,TPA
2756 call cp_hl_de
2757 jr c,error2
2758 ld de,(BDOS+1)
2759 call cp_hl_de
2760 jr nc,error2
2761 ld de,(high_load)
2762 call cp_hl_de
2763 jr c,l1157h
2764 ld (high_load),hl
2765 l1157h:
2766 ld de,(max_load)
2767 call cp_hl_de
2768 jr c,l1163h
2769 ld (max_load),hl
2770 l1163h:
2771 pop de
2772 pop af
2773 ld (hl),a
2774 ret
2775
2776 strncmp:
2777 ld a,(de)
2778 cp (hl)
2779 inc de
2780 inc hl
2781 ret nz
2782 djnz strncmp
2783 ret
2784
2785 str_hex:
2786 db 'HEX'
2787
2788 read_hexchar:
2789 call read_hexdigit
2790 rlca
2791 rlca
2792 rlca
2793 rlca
2794 ld d,a
2795 call read_hexdigit
2796 add a,d
2797 ld d,a
2798 add a,c
2799 ld c,a
2800 ld a,d
2801 ret
2802
2803 read_hexdigit:
2804 call read_byte
2805 jr z,error2
2806 hex_digit_v:
2807 call hex_digit
2808 ret nc
2809 error2:
2810 jp ERROR
2811
2812 ;-------------------------------------------------------------------------------
2813 ; > R [displacement]
2814 ; Read a binary or hex file [add displacement]
2815
2816 cmd_R:
2817 ld hl,0
2818 call get_lastarg_def
2819 read_file:
2820 ld de,dfcb1
2821 push hl
2822 ld hl,0
2823 ld (high_load),hl
2824 call file_open
2825 ld hl,dfcb1+9
2826 ld de,str_hex
2827 ld b,3
2828 call strncmp
2829 pop hl
2830 jr z,read_hexfile
2831 ld de,TPA
2832 push hl
2833 add hl,de
2834 l108eh:
2835 call read_sector
2836 jr nz,read_file_nxt
2837 pop hl
2838 jp p_max_high
2839
2840 read_file_nxt:
2841 ld de,DMA_BUF
2842 ld b,080h
2843 l109ah:
2844 ld a,(de)
2845 call cmdR_storebyte
2846 inc de
2847 inc hl
2848 djnz l109ah
2849 jr l108eh
2850
2851 read_hexfile:
2852 push hl
2853 l10aeh:
2854 call read_byte ; RECORD MARK
2855 jr z,rdhex_done
2856 cp ':'
2857 jr nz,l10aeh
2858 ld c,0
2859 call read_hexchar ; RECLEN
2860 ld b,a
2861 call read_hexchar ; LOAD ADDR H
2862 ld h,a
2863 call read_hexchar ; LOAD ADDR L
2864 ld l,a
2865 ld a,b
2866 and a
2867 jr z,rdhex_done
2868 call read_hexchar ; RECTYP
2869 l10cch:
2870 call read_hexchar ; DATA
2871 pop de
2872 push de
2873 push hl
2874 add hl,de
2875 call cmdR_storebyte
2876 pop hl
2877 inc hl
2878 djnz l10cch
2879 call read_hexchar ; CHKSUM
2880 ld a,c
2881 and a
2882 jp nz,ERROR
2883 jr l10aeh
2884 rdhex_done:
2885 pop hl
2886 jp p_max_high
2887
2888 test_whitespace:
2889 cp ' '
2890 ret z
2891 cp TAB
2892 ret
2893
2894 ;-------------------------------------------------------------------------------
2895
2896 p_max_high0:
2897 call assert_eol
2898 p_max_high:
2899 call pstr_inl
2900 DC 'High = '
2901 ld hl,(high_load)
2902 call out_hl
2903 call pstr_inl
2904 DC ' Max = '
2905 ld hl,(max_load)
2906 call out_hl
2907 call pstr_inl
2908 DC ' Top = '
2909 ld hl,(BDOS+1)
2910 call out_hl
2911 jp crlf
2912
2913 ;-------------------------------------------------------------------------------
2914 ; > Wstartaddr endaddr
2915 ; Write a file to disk
2916
2917 cmd_W:
2918 call get_arg_range
2919 call assert_eol
2920 push hl
2921 ld a,c
2922 add a,07fh
2923 jr nc,l11adh
2924 inc b
2925 l11adh:
2926 and 080h
2927 ld c,a
2928 push bc
2929 ld a,(dfcb1+1)
2930 cp ' '
2931 jr z,error4
2932 ld de,dfcb1
2933 call setup_fcb
2934 push de
2935 ld c,BDOS_DELETE
2936 call ddtz_bdos
2937 pop de
2938 ld c,BDOS_CREATE
2939 call ddtz_bdos
2940 inc a
2941 jr z,error4
2942 pop bc
2943 pop hl
2944 l11cch:
2945 ld a,b
2946 or c
2947 jr z,close_file
2948 push bc
2949 ld de,080h ; DMA_BUF
2950 ld b,d
2951 ld c,e
2952 ldir
2953 call write_sector
2954 ex (sp),hl
2955 ld bc,0ff80h
2956 add hl,bc
2957 ex (sp),hl
2958 pop bc
2959 jr l11cch
2960
2961 write_sector:
2962 push hl
2963 ld de,dfcb1
2964 ld c,BDOS_WRITE
2965 call ddtz_bdos
2966 pop hl
2967 and a
2968 ret z
2969 call close_file
2970 error4:
2971 jp ERROR
2972
2973 close_file:
2974 ld de,dfcb1
2975 ld c,BDOS_CLOSE
2976 jp ddtz_bdos
2977
2978 ;-------------------------------------------------------------------------------
2979 ; > A [startaddr]
2980 ; Assemble Zilog Z180 mnemonics
2981
2982 ;cmd_A:
2983
2984
2985 CALL_HL:
2986 jp (hl)
2987
2988 ;-------------------------------------------------------------------------------
2989
2990
2991
2992
2993 b_176d_start:
2994 DC 'AF,AF'''
2995 l1773h:
2996 DC 'DE,HL'
2997 DC '(SP),HL'
2998 DC '(SP),IX'
2999 DC '(SP),IY'
3000 db 0
3001
3002 ;-------------------------------------------------------------------------------
3003 ; >>L [startaddr] [endaddr]
3004 ; List disassembled code
3005
3006 cmd_L:
3007 ld hl,cmd_L
3008 ld (cmd_rpt),hl
3009 call expr
3010 jr nc,l18dbh
3011 ld hl,(last_L)
3012 l18dbh:
3013 call next_arg
3014 call get_range
3015 jr nc,l1905h
3016 call assert_eol
3017 ld b,16
3018 l18ebh:
3019 push bc
3020 call cmdl_p_line
3021 pop bc
3022 djnz l18ebh
3023 ret
3024
3025 l1905h:
3026 call assert_eol
3027 ld d,h
3028 ld e,l
3029 add hl,bc
3030 ex de,hl
3031 l190fh:
3032 push de
3033 call cmdl_p_line
3034 pop de
3035 call cp_hl_de
3036 jr c,l190fh
3037 ret
3038
3039 ;-------------------------------------------------------------------------------
3040
3041 cmdl_p_line:
3042 push hl
3043 call p_disas_line
3044 call crlf
3045 pop hl
3046 ld c,b
3047 ld b,0
3048 add hl,bc
3049 ld (last_L),hl
3050 ret
3051
3052 p_disas_line:
3053 call outbl2
3054 call out.hl.@
3055 call z,outbl
3056 call outbl
3057 sub a
3058 ld (con_col),a
3059 push hl
3060 pop iy
3061 call p_disas_instr
3062 ret z
3063
3064 ld c,15
3065 call p_goto_col
3066 ; fall thru
3067 ;-------------------------------------------------------------------------------
3068
3069 p_offset:
3070 ld de,(var.@)
3071 ld a,d
3072 or e
3073 ret z
3074 call pstr_inl
3075 dc '(@'
3076 and a
3077 sbc hl,de
3078 call out_hl
3079 add hl,de
3080 jp out_rparen
3081
3082 ;-------------------------------------------------------------------------------
3083
3084 p_disas_instr:
3085 sub a
3086 ld (disas_argtype),a
3087 call disas_get_instrlen
3088 jr nc,l197fh
3089 push bc
3090 ld a,(con_col)
3091 add a,5
3092 ld c,a
3093 call pstr
3094 call p_goto_col
3095 ex de,hl
3096 call call_hl
3097 pop bc
3098 ld a,(disas_argtype)
3099 ld hl,(disas_arg_16)
3100 or a
3101 scf
3102 ret
3103
3104 l197fh:
3105 call pstr_inl
3106 DC '???'
3107 ld b,1
3108 sub a
3109 ret
3110
3111 disas_get_instrlen:
3112 sub a
3113 ld (isprefix_ixiy),a
3114 ld a,(iy+000h)
3115 cp 0edh
3116 jp z,disas_pfx.ED
3117 cp 0ddh
3118 jr z,l19abh
3119 cp 0fdh
3120 jr z,l19afh
3121 sub_19a0h:
3122 ld a,(iy+000h)
3123 cp 0cbh
3124 jp z,disas_pfx.CB
3125 jp disas_nopfx
3126 l19abh:
3127 ld a,1
3128 jr l19b1h
3129 l19afh:
3130 ld a,2
3131 l19b1h:
3132 ld (isprefix_ixiy),a
3133 call disas_pfx.DDFD
3134 ret nc
3135 push bc
3136 call sub_19a0h
3137 pop af
3138 add a,b
3139 ld b,a
3140 scf
3141 ret
3142
3143 ;-------------------------------------------------------------------------------
3144
3145 disas_pfx.DDFD:
3146 inc iy
3147 ld hl,b_19ef_start
3148 call test_DDFD
3149 ld b,002h
3150 ret c
3151 ld hl,l1a0ah
3152 call test_DDFD
3153 ld b,001h
3154 ret c
3155 ld a,(iy+000h)
3156 cp 0cbh
3157 jr nz,l19edh
3158 ld a,(iy+002h)
3159 cp 036h
3160 ret z
3161 and 007h
3162 cp 006h
3163 jr nz,l19edh
3164 ld b,002h
3165 scf
3166 ret
3167 l19edh:
3168 and a
3169 ret
3170
3171 ;-------------------------------------------------------------------------------
3172 ; DD/FD 3 byte (ix+d)/(iy+d)
3173 b_19ef_start:
3174 db 034h
3175 db 035h
3176 db 036h
3177 db 046h
3178 db 04eh
3179 db 056h
3180 db 05eh
3181 db 066h
3182 db 06eh
3183 db 070h
3184 db 071h
3185 db 072h
3186 db 073h
3187 db 074h
3188 db 075h
3189 db 077h
3190 db 07eh
3191 db 086h
3192 db 08eh
3193 db 096h
3194 db 09eh
3195 db 0a6h
3196 db 0aeh
3197 db 0b6h
3198 db 0beh
3199 db 0
3200
3201 ; DD/FD 2 byte
3202 l1a0ah:
3203 db 009h
3204 db 019h
3205 db 021h
3206 db 022h
3207 db 023h
3208 db 029h
3209 db 02ah
3210 db 02bh
3211 db 039h
3212 db 0e1h
3213 db 0e3h
3214 db 0e5h
3215 db 0e9h
3216 db 0f9h
3217 db 0
3218
3219 ;-------------------------------------------------------------------------------
3220
3221 disas_pfx.ED:
3222 inc iy
3223 ld hl,b_1bc9_start
3224 call sub_1a72h
3225 ld b,2
3226 ret c
3227 ld hl,b_1bf4_start
3228 call lookup_opc
3229 ld b,2
3230 ret c
3231
3232 ld hl,l228bh
3233 call lookup_opc
3234 ld b,3
3235 ret c
3236 ld hl,b_1c40_start
3237 call lookup_opc
3238 ld b,4
3239 ret
3240
3241 ;-------------------------------------------------------------------------------
3242
3243 disas_pfx.CB:
3244 push iy
3245 inc iy
3246 ld a,(isprefix_ixiy)
3247 and a
3248 jr z,l1a42h
3249 inc iy
3250 l1a42h:
3251 ld hl,b_1c55_start
3252 call lookup_opc
3253 pop iy
3254 ld b,2
3255 ret
3256
3257 ;-------------------------------------------------------------------------------
3258
3259 disas_nopfx:
3260 ld hl,b_1b54_start
3261 call lookup_opc
3262 ld b,2
3263 ret c
3264 ld hl,b_1ab6_start
3265 call sub_1a72h
3266 ld b,1
3267 ret c
3268 ld hl,b_1ad1_start
3269 call lookup_opc
3270 ld b,1
3271 ret c
3272 ld hl,b_1b9b_start
3273 call lookup_opc
3274 ret nc
3275 ld b,3
3276 ret
3277
3278 ;-------------------------------------------------------------------------------
3279
3280 sub_1a72h:
3281 ld a,(hl)
3282 cp 0ffh
3283 ret z
3284 cp (iy+000h)
3285 jr z,l1a7fh
3286 inc hl
3287 inc hl
3288 jr sub_1a72h
3289 l1a7fh:
3290 ld de,l1c97h
3291 inc hl
3292 ld c,(hl)
3293 jr get_mnemonic
3294
3295
3296 test_DDFD:
3297 ld a,(hl)
3298 and a
3299 ret z
3300 inc hl
3301 cp (iy+000h)
3302 jr nz,test_DDFD
3303 scf
3304 ret
3305
3306 lookup_opc:
3307 ld a,(iy+000h)
3308 and (hl)
3309 inc hl
3310 cp (hl)
3311 jr z,l1aa8h
3312 inc hl
3313 inc hl
3314 inc hl
3315 inc hl
3316 ld a,(hl)
3317 and a
3318 jr nz,lookup_opc
3319 ret
3320
3321 l1aa8h:
3322 inc hl
3323 ld c,(hl)
3324 inc hl
3325 ld e,(hl)
3326 inc hl
3327 ld d,(hl)
3328 get_mnemonic:
3329 ld hl,t_MNEMONICS
3330 ld b,0
3331 add hl,bc
3332 scf
3333 ret
3334
3335 ;-------------------------------------------------------------------------------
3336 ; 1 byte opcodes (no parameters)
3337 ; Format: db opcode, t_MNEMONICS-index
3338 b_1ab6_start:
3339 db 076h,039h ;halt
3340 db 0d9h,036h ;exx
3341 db 0f3h,02ch ;di
3342 db 0fbh,032h ;ei
3343 db 000h,069h ;nop
3344 db 007h,09eh ;rlca
3345 db 00fh,0adh ;rrca
3346 db 017h,098h ;rla
3347 db 01fh,0a7h ;rra
3348 db 027h,026h ;daa
3349 db 02fh,023h ;cpl
3350 db 037h,0bah ;scf
3351 db 03fh,010h ;ccf
3352 db 0ffh
3353
3354
3355 ; 1 byte opcodes
3356 ; Format: db mask, match, t_MNEMONICS-index
3357 ; dw argument formating fuction
3358 b_1ad1_start:
3359 db 0c0h,040h,056h ;ld r,r
3360 dw p_arg_r_r
3361 db 0f8h,080h,003h ;add a,r
3362 dw p_arg_a_r
3363 db 0f8h,088h,000h ;adc a,r
3364 dw p_arg_a_r
3365 db 0f8h,090h,0c9h ;sub r
3366 dw p_arg_rs
3367 db 0f8h,098h,0b7h ;sbc a,r
3368 dw p_arg_a_r
3369 db 0f8h,0a0h,006h ;and r
3370 dw p_arg_rs
3371 db 0f8h,0a8h,0cch ;xor r
3372 dw p_arg_rs
3373 db 0f8h,0b0h,06ch ;or r
3374 dw p_arg_rs
3375 db 0f8h,0b8h,013h ;cp r
3376 dw p_arg_rs
3377 db 0c7h,0c0h,08bh ;ret cc
3378 dw p_arg_cc
3379 db 0c7h,0c7h,0b4h ;rst
3380 dw l1c98h
3381 db 0ffh,0c9h,08bh ;ret
3382 dw l1c97h
3383 db 0cfh,0c1h,081h ;pop rr
3384 dw p_arg_zz
3385 db 0cfh,0c5h,084h ;push rr
3386 dw p_arg_zz
3387 db 0ffh,0e3h,034h ;ex (sp),hl
3388 dw l1ca0h
3389 db 0ffh,0e9h,052h ;jp (hl)
3390 dw l1caeh
3391 db 0ffh,0ebh,034h ;ex de,hl
3392 dw p_arg_ex_dehl
3393 db 0ffh,0f9h,056h ;ld sp,hl
3394 dw l1cc1h
3395 db 0cfh,003h,041h ;inc rr
3396 dw p_arg_ww
3397 db 0cfh,00bh,029h ;dec rr
3398 dw p_arg_ww
3399 db 0c7h,004h,041h ;inc r
3400 dw p_arg_r
3401 db 0c7h,005h,029h ;dec r
3402 dw p_arg_r
3403 db 0ffh,008h,034h ;ex af,af'
3404 dw p_arg_ex_afaf
3405 db 0cfh,009h,003h ;add hl,rr
3406 dw l1cd3h
3407 db 0efh,002h,056h ;ld (rr),a ;rr=bc,de
3408 dw l1cdch
3409 db 0efh,00ah,056h ;ld a,(rr) ;rr=bc,de
3410 dw l1ce5h
3411 db 0
3412
3413 ; 2 byte opdodes
3414 b_1b54_start:
3415 db 0c7h,006h,056h ;ld r,nn
3416 dw l1cfah
3417 db 0ffh,0c6h,003h ;add a,nn
3418 dw l1cf5h
3419 db 0ffh,0ceh,000h ;adc a,nn
3420 dw l1cf5h
3421 db 0ffh,0d6h,0c9h ;sub a,nn
3422 dw l1d09h
3423 db 0ffh,0deh,0b7h ;sbc a,nn
3424 dw l1cf5h
3425 db 0ffh,0e6h,006h ;and a,nn
3426 dw l1d09h
3427 db 0ffh,0eeh,0cch ;xor nn
3428 dw l1d09h
3429 db 0ffh,0f6h,06ch ;or nn
3430 dw l1d09h
3431 db 0ffh,0feh,013h ;cp a,nn
3432 dw l1d09h
3433 db 0ffh,010h,02eh ;djnz
3434 dw p_arg_jrel
3435 db 0ffh,018h,054h ;jr
3436 dw p_arg_jrel
3437 db 0e7h,020h,054h ;jr cc,
3438 dw p_arg_cc_jrel
3439 db 0ffh,0d3h,076h ;out (nn),a
3440 dw l1d37h
3441 db 0ffh,0dbh,03fh ;in a,(nn)
3442 dw l1d29h
3443 db 0
3444
3445 ; 3 byte opcodes
3446 b_1b9b_start:
3447 db 0c7h,0c2h,052h ;jp cc,mn
3448 dw p_arg_cc_mn
3449 db 0c7h,0c4h,00ch ;call cc,mn
3450 dw p_arg_cc_mn
3451 db 0cfh,001h,056h ;ld ww,mn
3452 dw p_arg_ww_mn
3453 db 0ffh,0c3h,052h ;jp mn
3454 dw p_arg_mn
3455 db 0ffh,0cdh,00ch ;call mn
3456 dw p_arg_mn
3457 db 0ffh,022h,056h ;ld (mn),hl
3458 dw p_arg_addr_hl
3459 db 0ffh,02ah,056h ;ld hl,(mn)
3460 dw p_arg_hl_addr
3461 db 0ffh,032h,056h ;ld (mn),a
3462 dw p_arg_addr_a
3463 db 0ffh,03ah,056h ;ld a,(mn)
3464 dw p_arg_a_addr
3465 db 0
3466
3467 ; Prefix ED + 1 byte opcode, no arguments
3468 ; Format: opcode, t_MNEMONICS index
3469 b_1bc9_start:
3470 db 044h,066h ;neg
3471 db 045h,092h ;retn
3472 db 04dh,08eh ;reti
3473 db 067h,0b1h ;rrd
3474 db 06fh,0a2h ;rld
3475 db 0a0h,05fh ;ldi
3476 db 0a1h,01ch ;cpi
3477 db 0a2h,04bh ;ini
3478 db 0a3h,07dh ;outi
3479 db 0a8h,058h ;ldd
3480 db 0a9h,015h ;cpd
3481 db 0aah,044h ;ind
3482 db 0abh,079h ;outd
3483 db 0b0h,062h ;ldir
3484 db 0b1h,01fh ;cpir
3485 db 0b2h,04eh ;inir
3486 db 0b3h,072h ;otir
3487 db 0b8h,05bh ;lddr
3488 db 0b9h,018h ;cpdr
3489 db 0bah,047h ;indr
3490 db 0bbh,06eh ;otdr
3491 db 08bh,0d5h ;otdm
3492 db 09bh,0d9h ;otdmr
3493 db 083h,0deh ;otim
3494 db 093h,0e2h ;otimr
3495 db 076h,0ebh ;slp
3496 db 0ffh ;<end mark>
3497
3498 b_1bf4_start:
3499 db 0e7h,040h,03fh ;in r,(c) ;r=b,c,d,e
3500 dw p_arg_in_c ;
3501 db 0f7h,060h,03fh ;in r,(c) ;r=h,l
3502 dw p_arg_in_c ;
3503 db 0ffh,078h,03fh ;in r,(c) ;r=a
3504 dw p_arg_in_c ;
3505 db 0e7h,041h,076h ;out (c),r ;r=b,c,d,e
3506 dw p_arg_out_c ;
3507 db 0f7h,061h,076h ;out (c),r ;r=h,l
3508 dw p_arg_out_c ;
3509 db 0ffh,079h,076h ;out (c),r ;r=a
3510 dw p_arg_out_c ;
3511 db 0cfh,042h,0b7h ;sbc hl,rr
3512 dw l1dcah ;
3513 db 0cfh,04ah,000h ;adc hl,rr
3514 dw l1dcah ;
3515 db 0ffh,046h,03dh ;im 0
3516 dw l1d85h ;
3517 db 0ffh,056h,03dh ;im 1
3518 dw l1d89h ;
3519 db 0ffh,05eh,03dh ;im 2
3520 dw l1d8dh ;
3521 db 0ffh,047h,056h ;ld i,a
3522 dw l1d92h ;
3523 db 0ffh,057h,056h ;ld a,i
3524 dw l1d97h ;
3525 db 0ffh,04fh,056h ;ld r,a
3526 dw l1d9ch ;
3527 db 0ffh,05fh,056h ;ld a,r
3528 dw l1da1h
3529 db 0cfh,04ch,0d2h ;mlt rr
3530 dw p_arg_ww
3531 db 0c7h,004h,0eeh ;tst r
3532 dw p_arg_r
3533 db 0
3534
3535 l228bh:
3536 db 0e7h,000h,0cfh ;in0 r,(m) ;r=b,c,d,e
3537 dw p_arg_r_m
3538 db 0f7h,020h,0cfh ;in0 r,(m) ;r=h,l
3539 dw p_arg_r_m
3540 db 0ffh,038h,0cfh ;in0 a,(m)
3541 dw p_arg_r_m
3542 db 0e7h,001h,0e7h ;out0 (m),r ;r=b,c,d,e
3543 dw p_arg_m_r
3544 db 0f7h,021h,0e7h ;out0 (m),r ;r=h,l
3545 dw p_arg_m_r
3546 db 0ffh,039h,0e7h ;out0 (m),a
3547 dw p_arg_m_r
3548 db 0ffh,064h,0eeh ;tst m
3549 dw l1d09h
3550 db 0ffh,074h,0f1h ;tstio m
3551 dw l1d09h
3552 db 0
3553
3554 b_1c40_start:
3555 db 0efh,043h,056h ;ld (mn),ww ;ww=bc,de
3556 dw p_arg_addr_ww
3557 db 0ffh,073h,056h ;ld (mn),sp
3558 dw p_arg_addr_ww
3559 db 0efh,04bh,056h ;ld ww,(mn) ;ww=bc,de
3560 dw p_arg_ww_addr
3561 db 0ffh,07bh,056h ;ld sp,(mn)
3562 dw p_arg_ww_addr
3563 db 0
3564
3565 ; CB
3566 b_1c55_start:
3567 db 0f8h,000h,09bh ;rlc g
3568 dw l1e03h
3569 db 0f8h,008h,0aah ;rrc g
3570 dw l1e03h
3571 db 0f8h,010h,096h ;rl g
3572 dw l1e03h
3573 db 0f8h,018h,0a5h ;rr g
3574 dw l1e03h
3575 db 0f8h,020h,0c0h ;sla g
3576 dw l1e03h
3577 db 0f8h,028h,0c3h ;sra g
3578 dw l1e03h
3579 db 0f8h,038h,0c6h ;srl g
3580 dw l1e03h
3581 db 0c0h,040h,009h ;bit b,g
3582 dw p_arg_bitop
3583 db 0c0h,080h,088h ;res b,g
3584 dw p_arg_bitop
3585 db 0c0h,0c0h,0bdh ;set b,g
3586 dw p_arg_bitop
3587 db 0
3588
3589 ;-------------------------------------------------------------------------------
3590
3591 p_arg_r_r:
3592 call p_arg_r
3593 call p_char_comma
3594 jp p_arg_rs
3595 p_arg_a_r:
3596 call p_A_comma
3597 jp p_arg_rs
3598 l1c97h:
3599 ret
3600
3601 p_arg_r_m:
3602 call p_arg_r
3603 call p_char_comma
3604 jp sub_1d2ch
3605
3606 p_arg_m_r:
3607 call sub_1d2ch
3608 call p_char_comma
3609 jp p_arg_r
3610
3611 l1c98h:
3612 ld a,(iy+000h)
3613 and 038h
3614 jp out_hex
3615
3616 l1ca0h:
3617 call pstr_inl
3618 DC '(SP),'
3619 jp p_arg_hlixiy
3620
3621 l1caeh:
3622 call p_char_lparen
3623 call p_arg_hlixiy
3624 jr out_rparen
3625
3626 p_arg_ex_dehl:
3627 ld hl,l1773h
3628 jp pstr
3629
3630 l1cc1h:
3631 call pstr_inl
3632 DC 'SP,'
3633 jp p_arg_hlixiy
3634
3635 p_arg_ex_afaf:
3636 ld hl,b_176d_start
3637 jp pstr
3638
3639 l1cd3h:
3640 call p_arg_hlixiy
3641 call p_char_comma
3642 jp p_arg_ww
3643 l1cdch:
3644 call sub_1ce8h
3645 call p_char_comma
3646 jp p_char_A
3647
3648 l1ce5h:
3649 call p_A_comma
3650 sub_1ce8h:
3651 call p_char_lparen
3652 call p_arg_ww
3653 jr out_rparen
3654
3655 l1cf5h:
3656 call p_A_comma
3657 jr l1d09h
3658 l1cfah:
3659 call p_arg_r
3660 call p_char_comma
3661 ld a,(isprefix_ixiy)
3662 and a
3663 ld a,(iy+002h)
3664 jr nz,l1d0ch
3665 l1d09h:
3666 ld a,(iy+001h)
3667 l1d0ch:
3668 jp out_hex
3669
3670 p_arg_cc_jrel:
3671 ld a,(iy+000h)
3672 and 018h
3673 call p_arg_cc0
3674 call p_char_comma
3675 p_arg_jrel:
3676 ld c,(iy+001h)
3677 ld a,c
3678 rla
3679 sbc a,a
3680 ld b,a
3681 push iy
3682 pop hl
3683 add hl,bc
3684 inc hl
3685 inc hl
3686 jr l1d4eh
3687
3688 l1d29h:
3689 call p_A_comma
3690 sub_1d2ch:
3691 call p_char_lparen
3692 ld a,(iy+001h)
3693 p_arg_nn_rp:
3694 call out_hex
3695 out_rparen:
3696 jr p_char_rparen
3697
3698 l1d37h:
3699 call sub_1d2ch
3700 jr p_char_comma_A
3701
3702 p_arg_cc_mn:
3703 call p_arg_cc
3704 call p_char_comma
3705 p_arg_mn:
3706 ld l,(iy+001h)
3707 ld h,(iy+002h)
3708 l1d4eh:
3709 ld a,002h
3710 sub_1d50h:
3711 ld (disas_argtype),a
3712 ld (disas_arg_16),hl
3713 jp out_hl
3714
3715 p_arg_ww_mn:
3716 call p_arg_ww
3717 call p_char_comma
3718 jr p_arg_mn
3719
3720 p_arg_addr_hl:
3721 call p_arg_addr
3722 call p_char_comma
3723 jp p_arg_hlixiy
3724
3725 p_arg_hl_addr:
3726 call p_arg_hlixiy
3727 call p_char_comma
3728 jp p_arg_addr
3729
3730 p_arg_addr_a:
3731 call p_arg_addr
3732 p_char_comma_A:
3733 call p_char_comma
3734 jr p_char_A
3735
3736 p_A_comma:
3737 call p_char_A
3738 p_char_comma:
3739 ld a,','
3740 db 021h
3741 p_char_A:
3742 ld a,'A'
3743 db 021h
3744 l1d85h:
3745 ld a,'0'
3746 db 021h
3747 l1d89h:
3748 ld a,'1'
3749 db 021h
3750 l1d8dh:
3751 ld a,'2'
3752 db 021h
3753 p_char_rparen:
3754 ld a,')'
3755 db 021h
3756 p_char_lparen:
3757 ld a,'('
3758 jp outchar
3759
3760 l1d92h:
3761 ld hl,b_1da7_start
3762 jr l1da4h
3763 l1d97h:
3764 ld hl,l1daah
3765 jr l1da4h
3766 l1d9ch:
3767 ld hl,l1dadh
3768 jr l1da4h
3769 l1da1h:
3770 ld hl,l1db0h
3771 l1da4h:
3772 jp pstr
3773
3774 b_1da7_start:
3775 DC 'I,A'
3776 l1daah:
3777 DC 'A,I'
3778 l1dadh:
3779 DC 'R,A'
3780 l1db0h:
3781 DC 'A,R'
3782
3783 p_arg_in_c:
3784 call p_arg_r
3785 call p_char_comma
3786 ld hl,t__C_
3787 jp pstr
3788
3789 p_arg_out_c:
3790 ld hl,t__C_
3791 call pstr
3792 call p_char_comma
3793 jr p_arg_r
3794
3795 l1dcah:
3796 call p_arg_hlixiy
3797 call p_char_comma
3798 jp p_arg_ww
3799
3800 p_arg_addr_ww:
3801 call p_arg_addr
3802 call p_char_comma
3803 jp p_arg_ww
3804
3805 p_arg_ww_addr:
3806 call p_arg_ww
3807 call p_char_comma
3808 jr p_arg_addr
3809
3810 p_arg_a_addr:
3811 call p_A_comma
3812 p_arg_addr:
3813 call p_char_lparen
3814 ld l,(iy+001h)
3815 ld h,(iy+002h)
3816 ld a,001h
3817 call sub_1d50h
3818 jr p_char_rparen
3819
3820 p_arg_bitop:
3821 ld a,(isprefix_ixiy)
3822 and a
3823 jr nz,l1defh
3824 ld a,(iy+001h)
3825 jr l1df2h
3826 l1defh:
3827 ld a,(iy+002h)
3828 l1df2h:
3829 push af
3830 rra
3831 rra
3832 rra
3833 and 007h
3834 add a,'0'
3835 call outchar
3836 call p_char_comma
3837 pop af
3838 jr p_arg_r0
3839
3840 l1e03h:
3841 ld a,(isprefix_ixiy)
3842 and a
3843 jr nz,l1e0eh
3844 ld a,(iy+001h)
3845 jr l1e11h
3846 l1e0eh:
3847 ld a,(iy+002h)
3848 l1e11h:
3849 jr p_arg_r0
3850
3851 p_arg_r:
3852 ld a,(iy+000h)
3853 rra
3854 rra
3855 rra
3856 jr p_arg_r0
3857 p_arg_rs:
3858 ld a,(iy+000h)
3859 p_arg_r0:
3860 and 007h
3861 cp 006h
3862 jr nz,p_arg_r1
3863 ld a,(isprefix_ixiy)
3864 and a
3865 ld a,006h
3866 jr z,p_arg_r1
3867 ld hl,b_1e78_start
3868 ld a,(isprefix_ixiy)
3869 dec a
3870 jr z,l1e4dh
3871 ld hl,l1e7bh
3872 l1e4dh:
3873 call pstr
3874 ld a,(iy+001h)
3875 push af
3876 rlca
3877 ld a,'+'
3878 jr nc,l1e61h
3879 pop af
3880 neg
3881 push af
3882 ld a,'-'
3883 l1e61h:
3884 call outchar
3885 pop af
3886 jp p_arg_nn_rp
3887
3888 p_arg_r1:
3889 ld hl,t_BCDEHL_HL_A
3890 jr p_arg
3891
3892 b_1e78_start:
3893 DC '(IX'
3894 l1e7bh:
3895 DC '(IY'
3896
3897 p_arg_hlixiy:
3898 ld a,(isprefix_ixiy)
3899 ld hl,t_HL.IX.IY
3900 jr p_arg
3901 p_arg_zz:
3902 ld hl,t_BC.DE.HL.AF
3903 jr l1e8eh
3904 p_arg_ww:
3905 ld hl,t_BC.DE.HL.SP
3906 l1e8eh:
3907 ld a,(iy+000h)
3908 rra
3909 rra
3910 rra
3911 rra
3912 and 003h
3913 cp 002h
3914 jr z,p_arg_hlixiy
3915 jr p_arg
3916
3917 p_arg_cc:
3918 ld a,(iy+000h)
3919 p_arg_cc0:
3920 rra
3921 rra
3922 rra
3923 and 007h
3924 ld hl,t_tstfl_ZCPS
3925 p_arg:
3926 ld b,a
3927 call sel_dc_string
3928 jp pstr
3929
3930 ;-------------------------------------------------------------------------------
3931
3932 t_MNEMONICS:
3933 DC 'ADC'
3934 DC 'ADD'
3935 DC 'AND'
3936 DC 'BIT'
3937 DC 'CALL'
3938 DC 'CCF'
3939 DC 'CP'
3940 DC 'CPD'
3941 DC 'CPDR'
3942 DC 'CPI'
3943 DC 'CPIR'
3944 DC 'CPL'
3945 DC 'DAA'
3946 DC 'DEC'
3947 DC 'DI'
3948 DC 'DJNZ'
3949 DC 'EI'
3950 DC 'EX'
3951 DC 'EXX'
3952 DC 'HALT'
3953 DC 'IM'
3954 DC 'IN'
3955 DC 'INC'
3956 DC 'IND'
3957 DC 'INDR'
3958 DC 'INI'
3959 DC 'INIR'
3960 DC 'JP'
3961 DC 'JR'
3962 DC 'LD'
3963 DC 'LDD'
3964 DC 'LDDR'
3965 DC 'LDI'
3966 DC 'LDIR'
3967 DC 'NEG'
3968 DC 'NOP'
3969 DC 'OR'
3970 DC 'OTDR'
3971 DC 'OTIR'
3972 DC 'OUT'
3973 DC 'OUTD'
3974 DC 'OUTI'
3975 DC 'POP'
3976 DC 'PUSH'
3977 DC 'RES'
3978 DC 'RET'
3979 DC 'RETI'
3980 DC 'RETN'
3981 DC 'RL'
3982 DC 'RLA'
3983 DC 'RLC'
3984 DC 'RLCA'
3985 DC 'RLD'
3986 DC 'RR'
3987 DC 'RRA'
3988 DC 'RRC'
3989 DC 'RRCA'
3990 DC 'RRD'
3991 DC 'RST'
3992 DC 'SBC'
3993 DC 'SCF'
3994 DC 'SET'
3995 DC 'SLA'
3996 DC 'SRA'
3997 DC 'SRL'
3998 DC 'SUB'
3999 DC 'XOR'
4000 DC 'IN0'
4001 DC 'MLT'
4002 DC 'OTDM'
4003 DC 'OTDMR'
4004 DC 'OTIM'
4005 DC 'OTIMR'
4006 DC 'OUT0'
4007 DC 'SLP'
4008 DC 'TST'
4009 DC 'TSTIO'
4010 DB 0
4011
4012 t_BCDEHL_HL_A:
4013 DC 'B'
4014 DC 'C'
4015 DC 'D'
4016 DC 'E'
4017 DC 'H'
4018 DC 'L'
4019 DC '(HL)'
4020 DC 'A'
4021 DB 0
4022 t_BC.DE.HL.SP:
4023 DC 'BC'
4024 DC 'DE'
4025 DC 'HL'
4026 DC 'SP'
4027 DB 0
4028 t_BC.DE.HL.AF:
4029 DC 'BC'
4030 DC 'DE'
4031
4032 DC 'HL'
4033 DC 'AF'
4034 DB 0
4035 t_HL.IX.IY:
4036 DC 'HL'
4037
4038 DC 'IX'
4039 DC 'IY'
4040 DB 0
4041 t_tstfl_ZCPS:
4042 DC 'NZ'
4043 DC 'Z'
4044 DC 'NC'
4045 DC 'C'
4046 DC 'PO'
4047 DC 'PE'
4048 DC 'P'
4049 DC 'M'
4050 DC 'NE'
4051 DC 'EQ'
4052 DC 'GE'
4053 DC 'LT'
4054 DC 'NV'
4055 DC 'V'
4056 DB 0
4057 t__C_:
4058 DC '(C)'
4059 DB 0
4060
4061 ;-------------------------------------------------------------------------------
4062
4063 tc_set_bp:
4064 ld hl,(reg.pc)
4065 ld a,h
4066 or l
4067 jr z,l2037h
4068 ld de,BDOS
4069 and a
4070 sbc hl,de
4071 ld hl,l20edh
4072 jr z,l2031h
4073 ld iy,(reg.pc)
4074 call disas_get_instrlen
4075 jp nc,ERROR
4076 ld c,b
4077 ld b,0
4078 ld hl,(reg.pc)
4079 add hl,bc
4080 call bp_trace_enter
4081 ld iy,(reg.pc)
4082 ld hl,b_2039_start
4083 call lookup_opc
4084 ccf
4085 ret c
4086 ex de,hl
4087 l2031h:
4088 call CALL_HL
4089 call c,bp_trace_enter
4090 l2037h:
4091 scf
4092 ret
4093
4094 ;-------------------------------------------------------------------------------
4095
4096 b_2039_start:
4097 db 0ffh,0ddh,000h ;Prefix DD
4098 dw l20a7h
4099 db 0ffh,0fdh,000h ;Prefix FD
4100 dw l20ach
4101 db 0ffh,0edh,000h ;Prefix ED
4102 dw l20b8h
4103
4104 b_2048_start:
4105 db 0ffh,0cdh,000h ;call mn
4106 dw l2080h
4107 db 0ffh,0c3h,000h ;jp mn
4108 dw l208bh
4109 db 0ffh,0e9h,000h ;jp ()
4110 dw l20a2h
4111 db 0ffh,0c9h,000h ;ret
4112 dw l20dch
4113 db 0ffh,0cfh,000h ;rst 8
4114 dw l2115h
4115 db 0c7h,0c7h,000h ;rst n
4116 dw l20f9h
4117 db 0c7h,0c4h,000h ;call cc,mn
4118 dw l2080h
4119 db 0f7h,010h,000h ;djnz d; jr d
4120 dw l2093h
4121 db 0e7h,020h,000h ;jr cc,d
4122 dw l2093h
4123 db 0c7h,0c2h,000h ;jp cc,mn
4124 dw l208bh
4125 db 0c7h,0c0h,000h ;ret cc
4126 dw l20c5h
4127 db 0
4128
4129 ;-------------------------------------------------------------------------------
4130 ; call mn call cc,mn
4131 l2080h:
4132 ld a,(b_21e2_start)
4133 and a
4134 jr nz,l208bh
4135 ld a,(trace_call_flag)
4136 and a
4137 ret nz
4138
4139 ; jp mn jp cc,mn
4140 l208bh:
4141 ld l,(iy+001h)
4142 ld h,(iy+002h)
4143 scf
4144 ret
4145
4146 l2093h:
4147 ld c,(iy+001h)
4148 ld a,c
4149 rla
4150 sbc a,a
4151 ld b,a
4152 ld hl,(reg.pc)
4153 add hl,bc
4154 inc hl
4155 inc hl
4156 scf
4157 ret
4158
4159 ; jp (hl)
4160 l20a2h:
4161 ld hl,(reg.l)
4162 scf
4163 ret
4164
4165 ; Prefix DD
4166 l20a7h:
4167 ld hl,(reg.ix)
4168 jr l20afh
4169 ; Prefix FD
4170 l20ach:
4171 ld hl,(reg.iy)
4172 l20afh:
4173 ld a,(iy+001h)
4174 cp 0e9h ; jp (ix); jp (iy)
4175 scf
4176 ret z
4177 and a
4178 ret
4179
4180 ; Prefix ED
4181 l20b8h:
4182 ld a,(iy+001h)
4183 cp 04dh ; reti
4184 jr z,l20dch
4185 cp 045h ; retn
4186 jr z,l20dch
4187 and a
4188 ret
4189 l20c5h:
4190 ld a,(iy+000h)
4191 ld (l20d7h),a
4192 ld hl,(reg.f)
4193 push hl
4194 pop af
4195 call l20d7h
4196 scf
4197 jr c,l20dch
4198 ret
4199 l20d7h:
4200 nop
4201 and a
4202 pop hl
4203 inc hl
4204 jp (hl)
4205
4206 l20dch:
4207 ld a,(b_21e2_start)
4208 and a
4209 jr nz,l20edh
4210 ld a,(trace_call_flag)
4211 and a
4212 jr z,l20edh
4213 call l20edh
4214 pop hl
4215 ret
4216 l20edh:
4217 ld hl,(reg_sp)
4218 ld e,(hl)
4219 inc hl
4220 ld d,(hl)
4221 ex de,hl
4222 call bp_trace_enter
4223 l2115h:
4224 and a
4225 ret
4226
4227 l20f9h:
4228 ld a,(l0003h)
4229 cp (iy+000h)
4230 ret z
4231 ld a,(iy+000h)
4232 and 038h
4233 ld l,a
4234 ld h,000h
4235 ld a,(b_21e2_start)
4236 and a
4237 jr nz,l2113h
4238 ld a,(trace_call_flag)
4239 and a
4240 ret nz
4241 l2113h:
4242 scf
4243 ret
4244
4245 ;-------------------------------------------------------------------------------
4246 ; >>C[N][J] [steps]
4247 ; >>C[N][J] W expression
4248 ; >>C[N][J] U expression
4249 ; trace over Calls [No list] [Jumps only] /.While./.Until.
4250
4251 cmd_C:
4252 ld hl,cmd_C
4253 ld a,1
4254 jr cmd_tc
4255
4256 ;-------------------------------------------------------------------------------
4257 ; >>T[N][J] [steps]
4258 ; >>T[N][J] W expression
4259 ; >>T[N][J] U expression
4260 ; Trace [no List] [Jumps only] / .While. / .Until.
4261
4262 cmd_T:
4263 xor a
4264 ld hl,cmd_T
4265 cmd_tc:
4266 ld (cmd_rpt),hl
4267 ld (trace_call_flag),a
4268 call get_char_upper
4269 sub 'N'
4270 jr nz,tc_non
4271 inc de
4272 tc_non:
4273 ld (trace_N_flag),a
4274 call get_char_upper
4275 sub 'J'
4276 jr nz,tc_noj
4277 inc de
4278 tc_noj:
4279 ld (trace_J_flag),a
4280 call tc_chk_u_or_w
4281 jr z,tc_save_uw_expr_ptr
4282 ld hl,1 ;default: 1 step
4283 call get_lastarg_def
4284 tc_save_uw_expr_ptr:
4285 ld (trace_cnt_or_ptr),hl
4286 sub a
4287 ld (bp_p_cpu_flag),a
4288 l214ch:
4289 call tc_set_bp
4290 jr user_go1
4291
4292 l2151h:
4293 call bp_clr_temporary
4294 ld a,(trace_J_flag)
4295 and a
4296 jr nz,l216bh
4297 ld iy,(reg.pc)
4298 call sub_21c8h
4299 jr z,l216bh
4300 ld hl,b_2048_start
4301 call lookup_opc
4302 jr nc,l214ch
4303 l216bh:
4304 ld a,(trace_UW_flag) ;0 or 'U' or 'W'
4305 and a
4306 jr z,tc_cnt ;flag is 0, check for step count.
4307 ld de,(trace_cnt_or_ptr)
4308 call expr
4309 ld a,h
4310 or l
4311 add a,0ffh
4312 sbc a,a
4313 ld hl,trace_UW_flag ;'U' or 'W'
4314 xor (hl)
4315 bit 1,a ;'U' = 55H, 'W' = 57H
4316 jr z,l2193h
4317 do_break0: ;print registers and go to main loop
4318 jp do_break
4319
4320 tc_cnt:
4321 ld hl,(trace_cnt_or_ptr)
4322 dec hl
4323 ld (trace_cnt_or_ptr),hl
4324 ld a,h
4325 or l
4326 jr z,do_break0
4327 l2193h:
4328 call tc_set_bp
4329 jr nc,do_break0
4330 ld a,(trace_N_flag)
4331 ld b,a
4332 ld a,(bp_p_cpu_flag)
4333 or b
4334 ld (bp_p_cpu_flag),a
4335 user_go1:
4336 jp user_go
4337
4338 tc_chk_u_or_w:
4339 call skipbl
4340 xor a
4341 ld (trace_UW_flag),a
4342 call get_char_upper
4343 cp 'U'
4344 jr z,l21b5h
4345 cp 'W'
4346 ret nz
4347 l21b5h:
4348 inc de
4349 push af
4350 push de
4351 call expr
4352 jp c,ERROR
4353 call assert_eol
4354 pop hl
4355 pop af
4356 ld (trace_UW_flag),a
4357 sub a
4358 ret
4359
4360 sub_21c8h:
4361 ld a,(iy+000h)
4362 cp 0edh
4363 jr z,l21dah
4364 and 0dfh
4365 cp 0ddh
4366 ret nz
4367 ld a,(iy+001h)
4368 cp 0e9h
4369 ret
4370 l21dah:
4371 ld a,(iy+001h)
4372 and 0f7h
4373 cp 045h
4374 ret
4375
4376 ;-------------------------------------------------------------------------------
4377
4378 con_col:
4379 db 0
4380
4381 ;-------------------------------------------------------------------------------
4382
4383 b_21e2_start:
4384 db 0
4385 trace_call_flag:
4386 db 0 ;1=call, 0=trace
4387 trace_UW_flag:
4388 db 0 ;0 or 'U' or 'W'
4389 trace_cnt_or_ptr:
4390 dw 0
4391 trace_N_flag:
4392 db 0 ;0 if 'N'
4393 trace_J_flag:
4394 db 0 ;0 if 'J'
4395
4396 bp_p_cpu_flag:
4397 db 0
4398
4399 bp_tab:
4400 rept BP_CNT
4401 rept BP_SIZE
4402 db 0
4403 endm
4404 endm
4405
4406 expr_p1:
4407 dw expr_buf
4408
4409 expr_buf:
4410 current_cseg defl $ - current_cseg
4411 .phase current_phase + current_cseg
4412
4413 start:
4414 LD SP,ldr_end+(stack-ddtz_base)
4415 LD DE,signon ;ldr_end+(expr_buf-ddtz_base)
4416 LD C,BDOS_PSTR
4417 CALL BDOS
4418
4419 xor a
4420 dec a
4421 jp po,reloc
4422 ld de,msgz80
4423 LD C,BDOS_PSTR
4424 CALL BDOS
4425 jp 0
4426
4427 reloc:
4428 LD HL,ldr_end+ddtz_size ;start of reloc bitmap
4429 ld bc,0108h ;init bit counter
4430
4431 EXX
4432 LD HL,(BDOS+1)
4433 LD (ldr_end+(ddtz_bdos+1-ddtz_base)),HL
4434 LD BC,ddtz_size-1
4435 LD D,B
4436 LD E,0FFH
4437 INC DE ;size rounded up to next page boundary
4438 INC BC ;ddtz_size
4439 OR A
4440 SBC HL,DE ;BDOS - size
4441 LD (BDOS+1),HL ;-> new BDOS entry
4442
4443 push hl
4444 PUSH BC
4445 ld de,ldr_end
4446 sbc hl,de
4447 EX DE,HL ;-> DE
4448 LD HL,ldr_size
4449 add hl,bc
4450 ld b,h
4451 ld c,l
4452 LD HL,TPA
4453 reloc_lp:
4454 EXX
4455 djnz reloc_nl
4456 ld b,c ;reload bit counter
4457 LD e,(HL) ;get next 8 relocation bits
4458 INC HL
4459 reloc_nl:
4460 sla e
4461 EXX
4462 JR NC,reloc_next
4463 DEC HL
4464 LD A,(HL)
4465 ADD A,E
4466 LD (HL),A
4467 INC HL
4468 LD A,(HL)
4469 ADC A,D
4470 LD (HL),A
4471 reloc_next:
4472 cpi
4473 jp pe,reloc_lp
4474 dec hl
4475
4476 POP BC
4477 pop de
4478 EX DE,HL
4479 ADD HL,BC
4480 EX DE,HL
4481 DEC DE
4482 LDDR
4483 LD HL,conbuf+2-ddtz_base
4484 ADD HL,DE
4485 JP (HL)
4486
4487 current_phase defl $
4488 .dephase
4489 current_cseg defl $
4490
4491 ds EXPR_BUF_SIZE - ($ - expr_buf)
4492 expr_bufe:
4493
4494 ;-------------------------------------------------------------------------------
4495
4496 last_S:
4497 dw TPA
4498
4499 last_I:
4500 dw 0
4501
4502 last_O_addr:
4503 dw 0
4504 last_O_val:
4505 db 0
4506
4507 cmd_Q_jopt:
4508 db -1
4509
4510 last_D:
4511 dw TPA
4512
4513 cmdR_rindex:
4514 db 0
4515
4516 high_load:
4517 dw TPA
4518 max_load:
4519 dw TPA
4520
4521 isprefix_ixiy:
4522 db 0
4523 last_L:
4524 dw TPA
4525 disas_arg_16:
4526 dw 0
4527 disas_argtype:
4528 db 0
4529
4530 pbl_loop_adr:
4531 dw 0
4532
4533 cur_fcb:
4534 dw 0
4535
4536 ddtz_size equ $-ddtz_base
4537 ddtz_end:
4538
4539 ;-------------------------------------------------------------------------------
4540
4541 end