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