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