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