1 ; Disassembled ddtz.com, version "DDT/Z [8101]"
2 ; with modified relocater.
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.
10 ; Some greneral definitions
24 ; ddtz specific definitions
26 STACK_SIZE equ 80 ;ddtz internal stack
27 CONBUF_SIZE equ 80 ;Size of console input buffer
28 BP_CNT equ 12 ;Number of breakpoints
29 BP_SIZE equ 4 ;Size of a breakpoint record
31 bitmap_size equ (prog_size+7)/8
33 ;-------------------------------------------------------------------------------
41 rst 30h ;rst used by ddtz
42 di_or_ei: ;ints enabled/disabled while ddtz is running
47 const: jp cist ; return console input status
48 conin: jp ci ; return console input character
49 conout: jp co ; send console output character
51 ;-------------------------------------------------------------------------------
60 ;-------------------------------------------------------------------------------
71 ; Determine current position
79 ld sp,028h ;rst instr needs a minimal stack
80 ld hl,0e9e1h ;opcpdes pop hl/jp (hl)
86 ld de,-(wearehere-ddtz_base)
92 ex de,hl ; de: reloc offset
102 ld hl,ddtz_end ;start of reloc bitmap
108 ld bc,0108h ;init bit counter b (c==reload val)
112 add hl,de ;--> ddtz_base
117 ld b,c ;reload bit counter
118 LD e,(HL) ;get next 8 relocation bits
139 ;-------------------------------------------------------------------------------
145 ld hl,(1) ;wboot addr
166 ld de,prog_size+bitmap_size-1
186 ;-------------------------------------------------------------------------------
194 ;-------------------------------------------------------------------------------
197 ; dw ERROR ;cmd_@ ;examine/substitute the displacement register @
198 ; dw ERROR ;cmd_A ;Assemble
199 dw cmd_B ;Breakpoints display/set/clear
200 dw ERROR ;cmd_C ;trace over Calls
201 dw cmd_D ;Display memory in hex and ascii
202 dw cmd_E ;rElocate debugger
203 dw ERROR ;cmd_F ;specify Filename and command line
205 dw cmd_H ;compute Hex and other expressions
206 dw cmd_I ;Input a byte from port
209 dw cmd_L ;List disassembled code
210 dw cmd_M ;Move memory [and verify]
212 dw cmd_O ;Output a byte to port
214 dw cmd_Q ;Qery memory for byte string
215 dw cmd_R ;Read binary or hex file
216 dw cmd_S ;Substitute memory
219 dw cmd_V ;Verify (compare) two memory areas
220 dw ERROR ;cmd_W ;Write a file to disk
221 dw cmd_X ;eXamine [and substitute] registers
222 dw ERROR ;cmd_Y ;examine [and substitute] Y variables
223 dw cmd_Z ;Zap (fill) memory with a byte string
232 call bp_clr_temporary
262 ;-------------------------------------------------------------------------------
281 defb 03eh ;ld a,.. swallow push hl
414 ;-------------------------------------------------------------------------------
421 ;-------------------------------------------------------------------------------
440 ;-------------------------------------------------------------------------------
464 ;-------------------------------------------------------------------------------
476 jr z,inl_e ;Accept line
478 jr z,inl_e ;Accept line
485 call DELC ;Delete Char
490 call DELL ;Delete Line
500 ld a,'^' ;Controll characters
517 ;-------------------------------------------------------------------------------
530 ;-------------------------------------------------------------------------------
541 ;-------------------------------------------------------------------------------
557 ;-------------------------------------------------------------------------------
564 ld de,stack-(STACK_SIZE-28)
571 ;-------------------------------------------------------------------------------
588 ;-------------------------------------------------------------------------------
668 get_arg_range_target:
707 defb 0e6h ;and a,.. clear carry
719 defb 03eh ;ld a,.. swallow pop af
761 jr z,error0 ;'S', but no expression following
765 ;-------------------------------------------------------------------------------
848 ; de: x (x shifted out, q shifted in)
850 ; hl: r (initially 0)
924 ;-------------------------------------------------------------------------------
969 ;-------------------------------------------------------------------------------
1056 ;-------------------------------------------------------------------------------
1164 ;-------------------------------------------------------------------------------
1208 ld hl,t_flag_names+7
1303 ;-------------------------------------------------------------------------------
1305 ; relocate debugger to addr
1307 ; relocate just below addr
1309 ; Move debugger to given address and restart.
1310 ; New location must not overlap with current location.
1321 ld bc,prog_size+bitmap_size
1326 ld ix,cmde_clr-ddtz_base
1329 ld hl,ddtz_base ;hl = src
1334 call c,neg.hl ;abs(distance)
1346 ;-------------------------------------------------------------------------------
1347 ; > G [startaddr] [;breakp..]
1348 ; Go [to start] [with temporary breakpoints]
1352 ld (bp_p_cpu_flag),a
1367 ;-------------------------------------------------------------------------------
1373 ld (pbl_loop_adr),hl
1386 ld hl,(pbl_loop_adr)
1400 ;-------------------------------------------------------------------------------
1402 ; display all breakpoints
1403 ; > B breakp [breakp..]
1406 ; clear all breakpoints
1407 ; > BX breakp [breakp..]
1410 ; breakp can be any valid expression
1470 ;-------------------------------------------------------------------------------
1471 ; Add break points to list
1472 ; A = 1 Permanent (B command)
1473 ; A = 2 Temporary (G command)
1490 call bp_get_freeslot
1512 ;-------------------------------------------------------------------------------
1513 ; Breakpoint handling routine.
1547 call inchar ;Keyboard hit?
1555 call bp_clr_temporary
1568 ld (bp_p_cpu_flag),a
1625 call bp_get_freeslot
1664 ;-------------------------------------------------------------------------------
1669 ld a,(bp_p_cpu_flag)
1699 ;-------------------------------------------------------------------------------
1701 ; examine all Y variables
1703 ; examine (and substitute) an Y variable
1706 ;-------------------------------------------------------------------------------
1708 ; eXamine (display) all cpu registers and
1709 ; the instruction at the current program counter
1711 ; eXamine (and substitute) a register
1920 ;-------------------------------------------------------------------------------
1926 call get_lastarg_def
1960 ;-------------------------------------------------------------------------------
1962 ; examine (substitute) displacement register @
1966 ;-------------------------------------------------------------------------------
1968 ; Input a byte from port
1973 call get_lastarg_def
1985 ;-------------------------------------------------------------------------------
1987 ; Output a byte to a port
1998 call get_lastarg_def
2006 ;-------------------------------------------------------------------------------
2007 ; > V startaddr endaddr targetaddr
2008 ; Verify (compare) two memory areas
2011 call get_arg_range_target
2038 ;-------------------------------------------------------------------------------
2039 ; > M startaddr endaddr destaddr
2043 call get_arg_range_target
2058 ;-------------------------------------------------------------------------------
2060 ; display Highest load address of last filed loaded, Maximum "High"
2061 ; off all loaded files, and Top address of available memory
2063 ; evaluate expression and display result in hex, decimal and other formats
2083 ;-------------------------------------------------------------------------------
2084 ; > Q[J] startaddr endaddr bytes
2085 ; Query memory for a byte string [Justified]
2125 ;-------------------------------------------------------------------------------
2126 ; > Z startaddr endaddr bytes
2127 ; Zap (fill) memory with a byte string
2161 sub_0ef7h: ;from cmd_Q, cmd_Z
2162 db 0e6h ;and 037h (clear carry)
2163 sub_0ef8h: ;from cmd_S
2211 ;-------------------------------------------------------------------------------
2212 ; >>D [startaddr] [endaddr]
2213 ; Display memory in hex and ASCII
2281 ;-------------------------------------------------------------------------------
2283 ; specifiy filenames and command line
2287 ;-------------------------------------------------------------------------------
2288 ; > R [displacement]
2289 ; Read Intel Hex File from console [add displacement]
2293 call get_lastarg_def ;get offset from command line
2302 ld c,0 ;init checksum
2303 call i.gethexbyte ;record len
2305 call i.gethexbyte ;address high
2307 call i.gethexbyte ;address low
2309 call i.gethexbyte ;record type (ignored)
2311 and a ;record len == 0?
2322 djnz l16c6h ;repeat for record len
2323 call i.gethexbyte ;checksum
2326 jr nz,error2 ;exit if checksum error
2327 jr w_recstart ;next record
2365 ld de,TPA ;lowest allowed load address
2368 ld de,(BDOS+1) ;highest allowed load address
2383 ld (hl),a ;store byte
2386 ;-------------------------------------------------------------------------------
2405 ;-------------------------------------------------------------------------------
2406 ; > Wstartaddr endaddr
2407 ; Write a file to disk
2411 ;-------------------------------------------------------------------------------
2413 ; Assemble Zilog Z180 mnemonics
2417 ;-------------------------------------------------------------------------------
2418 ; >>L [startaddr] [endaddr]
2419 ; List disassembled code
2453 ;-------------------------------------------------------------------------------
2472 ;-------------------------------------------------------------------------------
2475 call disas_get_instrlen
2481 call pstr ;print mnemonic
2483 call pr_instr_args ;print arguments
2497 ld (isprefix_ixiy),a
2516 ld (isprefix_ixiy),a
2527 ;-------------------------------------------------------------------------------
2530 ld hl,b_1b54_start ;2 byte opcodes
2534 ld hl,b_1ab6_start ;1 byte opcodes (no parameters)
2538 ld hl,b_1ad1_start ;1 byte opcodes
2542 ld hl,b_1b9b_start ;3 byte opcodes
2547 ;-------------------------------------------------------------------------------
2560 ld hl,b_1bc9_start ;1 byte opcode, no arguments
2586 ;-------------------------------------------------------------------------------
2591 ld a,(isprefix_ixiy)
2602 ;-------------------------------------------------------------------------------
2630 ;-------------------------------------------------------------------------------
2631 ; DD/FD 3 byte (ix+d)/(iy+d)
2678 ;-------------------------------------------------------------------------------
2705 call lookup_branch_op
2731 lookup_branch_op ;TODO
2751 ;-------------------------------------------------------------------------------
2752 ; 1 byte opcodes (no parameters)
2753 ; Format: db opcode, t_MNEMONICS-index
2755 db 076h,i_HALT ;halt
2760 ; db 007h,i_RLCA ;rlca
2761 ; db 00fh,i_RRCA ;rrca
2762 ; db 017h,i_RLA ;rla
2763 ; db 01fh,i_RRA ;rra
2764 ; db 027h,i_DAA ;daa
2765 ; db 02fh,i_CPL ;cpl
2766 ; db 037h,i_SCF ;scf
2767 ; db 03fh,i_CCF ;ccf
2773 ; Format: db mask, match, t_MNEMONICS-index
2774 ; dw argument formating function
2776 db 0c0h,040h,i_LD ;ld r[y],r[z]
2779 db 0c0h,080h,i_ADD+080h ;add a,r[z]
2782 ; db 0f8h,080h,i_ADD ;add a,r[z]
2784 ; db 0f8h,088h,i_ADC ;adc a,r[z]
2786 ; db 0f8h,090h,i_SUB ;sub r[z]
2788 ; db 0f8h,098h,i_SBC ;sbc a,r[z]
2790 ; db 0f8h,0a0h,i_AND ;and r[z]
2792 ; db 0f8h,0a8h,i_XOR ;xor r[z]
2794 ; db 0f8h,0b0h,i_OR ;or r[z]
2796 ; db 0f8h,0b8h,i_CP ;cp r[z]
2799 db 0c7h,0c0h,i_RET ;ret cc
2801 db 0c7h,0c7h,i_RST ;rst
2803 db 0cfh,0c1h,i_POP ;pop rp2
2805 db 0cfh,0c5h,i_PUSH ;push rp2
2807 db 0ffh,0e3h,i_EX ;ex (sp),hl
2809 db 0ffh,0e9h,i_JP ;jp (hl)
2811 db 0ffh,0ebh,i_EX ;ex de,hl
2813 db 0ffh,0f9h,i_LD ;ld sp,hl
2815 db 0cfh,003h,i_INC ;inc rp
2817 db 0cfh,00bh,i_DEC ;dec rp
2819 db 0c7h,004h,i_INC ;inc r[y]
2821 db 0c7h,005h,i_DEC ;dec r[y]
2823 db 0ffh,008h,i_EX ;ex af,af'
2825 db 0cfh,009h,i_ADD ;add hl,rp
2827 db 0efh,002h,i_LD ;ld (rp),a ;rp=bc,de
2829 db 0efh,00ah,i_LD ;ld a,(rp) ;rp=bc,de
2832 db 0c7h,007h,i_RLCA+080h;rlca
2839 db 0c7h,006h,i_LD ;ld r[y],nn
2842 db 0c7h,0c6h,i_ADD+080h ;add a,r[z]
2845 ; db 0ffh,0c6h,i_ADD ;add a,nn
2847 ; db 0ffh,0ceh,i_ADC ;adc a,nn
2849 ; db 0ffh,0d6h,i_SUB ;sub nn
2851 ; db 0ffh,0deh,i_SBC ;sbc a,nn
2853 ; db 0ffh,0e6h,i_AND ;and nn
2855 ; db 0ffh,0eeh,i_XOR ;xor nn
2857 ; db 0ffh,0f6h,i_OR ;or nn
2859 ; db 0ffh,0feh,i_CP ;cp nn
2862 db 0ffh,010h,i_DJNZ ;djnz
2864 db 0ffh,018h,i_JR ;jr
2866 db 0e7h,020h,i_JR ;jr cc,
2868 db 0ffh,0d3h,i_OUT ;out (nn),a
2870 db 0ffh,0dbh,i_IN ;in a,(nn)
2876 db 0c7h,0c2h,i_JP ;jp cc,mn
2878 db 0c7h,0c4h,i_CALL ;call cc,mn
2880 db 0cfh,001h,i_LD ;ld ww,mn
2882 db 0ffh,0c3h,i_JP ;jp mn
2884 db 0ffh,0cdh,i_CALL ;call mn
2886 db 0ffh,022h,i_LD ;ld (mn),hl
2888 db 0ffh,02ah,i_LD ;ld hl,(mn)
2890 db 0ffh,032h,i_LD ;ld (mn),a
2892 db 0ffh,03ah,i_LD ;ld a,(mn)
2896 ; Prefix ED + 1 byte opcode, no arguments
2897 ; Format: opcode, t_MNEMONICS index
2900 db 045h,i_RETN ;retn
2901 db 04dh,i_RETI ;reti
2904 ; db 0a0h,i_LDI ;ldi
2905 ; db 0a1h,i_CPI ;cpi
2906 ; db 0a2h,i_INI ;ini
2907 ; db 0a3h,i_OUTI ;outi
2908 ; db 0a8h,i_LDD ;ldd
2909 ; db 0a9h,i_CPD ;cpd
2910 ; db 0aah,i_IND ;ind
2911 ; db 0abh,i_OUTD ;outd
2912 ; db 0b0h,i_LDIR ;ldir
2913 ; db 0b1h,i_CPIR ;cpir
2914 ; db 0b2h,i_INIR ;inir
2915 ; db 0b3h,i_OTIR ;otir
2916 ; db 0b8h,i_LDDR ;lddr
2917 ; db 0b9h,i_CPDR ;cpdr
2918 ; db 0bah,i_INDR ;indr
2919 ; db 0bbh,i_OTDR ;otdr
2920 db 08bh,i_OTDM ;otdm
2921 db 09bh,i_OTDMR ;otdmr
2922 db 083h,i_OTIM ;otim
2923 db 093h,i_OTIMR ;otimr
2930 db 0ffh,070h,i_IN ;in (c) ;
2932 db 0c7h,040h,i_IN ;in r,(c) ;r=b,c,d,e,h,l,a
2934 db 0ffh,071h,0ffh ;out (c),0 ;
2936 db 0c7h,041h,i_OUT ;out (c),r ;r=b,c,d,e,h,l,a
2938 db 0cfh,042h,i_SBC ;sbc hl,rp
2940 db 0cfh,04ah,i_ADC ;adc hl,rp
2942 db 0ffh,046h,i_IM ;im 0
2944 db 0ffh,056h,i_IM ;im 1
2946 db 0ffh,05eh,i_IM ;im 2
2948 db 0e7h,047h,i_LD ;ld i,a ... ld a,r
2950 db 0cfh,04ch,i_MLT ;mlt rr
2952 db 0c7h,004h,i_TST ;tst r
2957 db 0ffh,030h,i_IN0 ;in0 (m)
2959 db 0c7h,000h,i_IN0 ;in0 r,(m) ;r=b,c,d,e,h,l,a
2961 db 0ffh,031h,0ffh ;out0 (m),0
2963 db 0c7h,001h,i_OUT0 ;out0 (m),r ;r=b,c,d,e
2965 db 0ffh,064h,i_TST ;tst m
2967 db 0ffh,074h,i_TSTIO ;tstio m
2971 ; Prefix ED + 1 byte opcode + 2 byte address
2972 ; Format: db mask, match, t_MNEMONICS-index
2973 ; dw argument formating function
2975 db 0cfh,043h,i_LD ;ld (mn),ww ;ww=bc,de,hl,sp
2977 db 0cfh,04bh,i_LD ;ld ww,(mn) ;ww=bc,de,hl,sp
2983 db 0c0h,000h,i_RLC+080h ;rlc g
2986 ; db 0f8h,000h,i_RLC ;rlc g
2988 ; db 0f8h,008h,i_RRC ;rrc g
2990 ; db 0f8h,010h,i_RL ;rl g
2992 ; db 0f8h,018h,i_RR ;rr g
2994 ; db 0f8h,020h,i_SLA ;sla g
2996 ; db 0f8h,028h,i_SRA ;sra g
2998 ; db 0f8h,038h,i_SRL ;srl g
3000 db 0c0h,040h,i_BIT ;bit b,g
3002 db 0c0h,080h,i_RES ;res b,g
3004 db 0c0h,0c0h,i_SET ;set b,g
3008 ;-------------------------------------------------------------------------------
3009 ;-------------------------------------------------------------------------------
3017 ld a,(hl) ;get next token
3022 call outchar ;print as normal character
3040 ; http://www.z80.info/decoding.htm
3042 ; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
3050 db fi_ry,',' ;ld r[y],r[z]
3054 ; db 'A,',fi_rz,0 ;op A,r[z]
3056 db fi_ccy,0 ;op cc[y]
3058 db fi_rst,0 ;rst y*8
3061 a_esphl equ $-t_argf
3062 db '(SP),',fi_hlixiy,0 ;ex (sp),hl
3064 db '(',fi_hlixiy,')',0 ;jp (hl)
3067 a_lsphl equ $-t_argf
3068 db 'SP,',fi_hlixiy,0 ;ld SP,HL
3070 db 'AF,AF''',0 ;ex af,af'
3072 db fi_hlixiy,',' ;add hl,rp
3076 db '(',fi_rp,'),A',0 ;ld (rp),a ;rp=bc,de
3078 db 'A,(',fi_rp,')',0 ;ld a,(rp) ;rp=bc,de
3082 db fi_ry,',',fi_n,0 ;ld r[y],n
3088 db fi_ccy2,',' ;jr cc,j ;cc = nz,z,nc,c
3092 db '(',fi_n,'),A',0 ;out (n),a
3094 db 'A,(',fi_n,')',0 ;in a,(n)
3098 db fi_ccy,',',fi_nn,0 ;op cc[y],nn
3100 db fi_rp,',' ;ld rp[p],nn
3104 db '(',fi_nn,'),',fi_hlixiy,0 ;ld (nn),hl
3106 db fi_hlixiy,',(',fi_nn,')',0 ;ld hl,(nn)
3108 db '(',fi_nn,'),A',0 ;ld (nn),a
3110 db 'A,(',fi_nn,')',0 ;ld a,(nn)
3112 ; Prefix ED + 1 byte opcode
3114 db fi_ry,',' ;in r[y],(c)
3118 db '(C),' ;out (c),r[y]
3120 db fi_ry,0 ;inc r[y]
3128 db fi_ir,0 ;ld a,i ... r,a
3130 ; Prefix ED + 2 byte (opcode + immediate)
3132 db fi_ry,',' ;in0 r[y],(n)
3134 db '(',fi_n,')',0 ;in0 (n)
3136 db '(',fi_n,'),',fi_ry,0 ;out0 (n),r[y]
3138 ; Prefix ED + 3 byte (opcode + address)
3140 db '(',fi_nn,'),',fi_rp,0 ;ld (nn),rp
3142 db fi_rp,',(',fi_nn,')',0 ;ld rp,(nn)
3144 ; Prefix CB + 1 byte opcode
3146 db fi_y,',' ;op y,r[z]
3148 db fi_rz_cb,0 ;op r[z]
3149 a_noarg equ $-t_argf
3153 ;-------------------------------------------------------------------------------
3158 fi_&x equ 80h+argpf_index
3160 argpf_index defl argpf_index+1
3181 ld a,(isprefix_ixiy)
3223 ld a,(isprefix_ixiy)
3252 ld a,(isprefix_ixiy)
3276 db 0ddh ;swallow t_arg_rp in ix
3287 ld a,(isprefix_ixiy)
3322 ;-------------------------------------------------------------------------------
3327 ;o_&x equ $-opc_tabstart
3329 opc_index defl opc_index+1
3333 ;opc_tabstart defl $
3396 ; Block instructions
3478 ;-------------------------------------------------------------------------------
3488 ld hl,l20edh ;set break after BDOS call
3491 call disas_get_instrlen
3500 call lookup_branch_op
3506 call c,bp_trace_enter
3511 ;-------------------------------------------------------------------------------
3514 db 0ffh,0ddh ;Prefix DD
3516 db 0ffh,0fdh ;Prefix FD
3518 db 0ffh,0edh ;Prefix ED
3521 db 0ffh,0cdh ;call mn
3533 db 0c7h,0c4h ;call cc,mn
3535 db 0f7h,010h ;djnz d; jr d
3537 db 0e7h,020h ;jr cc,d
3539 db 0c7h,0c2h ;jp cc,mn
3541 db 0c7h,0c0h ;ret cc
3545 ;-------------------------------------------------------------------------------
3546 ; call mn call cc,mn
3584 cp 0e9h ; jp (ix); jp (iy)
3618 ld hl,(reg_sp) ;break on return address
3642 ;-------------------------------------------------------------------------------
3644 ; >>C[N][J] W expression
3645 ; >>C[N][J] U expression
3646 ; trace over Calls [No list] [Jumps only] /.While./.Until.
3649 ;-------------------------------------------------------------------------------
3651 ; >>T[N][J] W expression
3652 ; >>T[N][J] U expression
3653 ; Trace [no List] [Jumps only] / .While. / .Until.
3657 ld hl,1 ;default: 1 step
3658 call get_lastarg_def
3659 ld (trace_cnt_or_ptr),hl
3661 ld (bp_p_cpu_flag),a
3666 call bp_clr_temporary
3667 ld hl,(trace_cnt_or_ptr)
3669 ld (trace_cnt_or_ptr),hl
3677 ld (bp_p_cpu_flag),a
3681 ;-------------------------------------------------------------------------------
3686 ;-------------------------------------------------------------------------------
3703 ;-------------------------------------------------------------------------------
3732 ;-------------------------------------------------------------------------------
3737 ;-------------------------------------------------------------------------------
3739 rept (STACK_SIZE+3)/4
3740 db 0deh,0adh,0beh,0efh
3771 ;-------------------------------------------------------------------------------
3773 ddtz_size equ $-ddtz_base
3774 prog_size equ $-start
3777 ;-------------------------------------------------------------------------------