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