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