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