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