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