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