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