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
46 ?const: jp 0 ; return console input status
47 ?conin: jp 0 ; return console input character
48 ?cono: jp 0 ; send console output character
50 ;-------------------------------------------------------------------------------
59 ;-------------------------------------------------------------------------------
70 ; Determine current position
78 ld sp,028h ;rst instr needs a minimal stack
79 ld hl,0e9e1h ;opcpdes pop hl/jp (hl)
85 ld de,-(wearehere-ddtz_base)
91 ex de,hl ; de: reloc offset
101 ld hl,ddtz_end ;start of reloc bitmap
107 ld bc,0108h ;init bit counter b (c==reload val)
111 add hl,de ;--> ddtz_base
116 ld b,c ;reload bit counter
117 LD e,(HL) ;get next 8 relocation bits
138 ;-------------------------------------------------------------------------------
144 ld hl,(1) ;wboot addr
165 ld de,prog_size+bitmap_size-1
185 ;-------------------------------------------------------------------------------
188 ; dw ERROR ;cmd_@ ;examine/substitute the displacement register @
189 ; dw ERROR ;cmd_A ;Assemble
190 dw cmd_B ;Breakpoints display/set/clear
191 dw ERROR ;cmd_C ;trace over Calls
192 dw cmd_D ;Display memory in hex and ascii
193 dw cmd_E ;rElocate debugger
194 dw ERROR ;cmd_F ;specify Filename and command line
196 dw cmd_H ;compute Hex and other expressions
197 dw cmd_I ;Input a byte from port
200 dw cmd_L ;List disassembled code
201 dw cmd_M ;Move memory [and verify]
203 dw cmd_O ;Output a byte to port
205 dw cmd_Q ;Qery memory for byte string
206 dw cmd_R ;Read binary or hex file
207 dw cmd_S ;Substitute memory
210 dw cmd_V ;Verify (compare) two memory areas
211 dw ERROR ;cmd_W ;Write a file to disk
212 dw cmd_X ;eXamine [and substitute] registers
213 dw ERROR ;cmd_Y ;examine [and substitute] Y variables
214 dw cmd_Z ;Zap (fill) memory with a byte string
223 call bp_clr_temporary
253 ;-------------------------------------------------------------------------------
272 defb 03eh ;ld a,.. swallow push hl
405 ;-------------------------------------------------------------------------------
412 ;-------------------------------------------------------------------------------
431 ;-------------------------------------------------------------------------------
455 ;-------------------------------------------------------------------------------
467 jr z,inl_e ;Accept line
469 jr z,inl_e ;Accept line
476 call DELC ;Delete Char
481 call DELL ;Delete Line
491 ld a,'^' ;Controll characters
508 ;-------------------------------------------------------------------------------
521 ;-------------------------------------------------------------------------------
532 ;-------------------------------------------------------------------------------
548 ;-------------------------------------------------------------------------------
555 ld de,stack-(STACK_SIZE-28)
562 ;-------------------------------------------------------------------------------
579 ;-------------------------------------------------------------------------------
659 get_arg_range_target:
698 defb 0e6h ;and a,.. clear carry
710 defb 03eh ;ld a,.. swallow pop af
752 jr z,error0 ;'S', but no expression following
756 ;-------------------------------------------------------------------------------
839 ; de: x (x shifted out, q shifted in)
841 ; hl: r (initially 0)
915 ;-------------------------------------------------------------------------------
960 ;-------------------------------------------------------------------------------
1047 ;-------------------------------------------------------------------------------
1155 ;-------------------------------------------------------------------------------
1199 ld hl,t_flag_names+7
1294 ;-------------------------------------------------------------------------------
1296 ; relocate debugger to addr
1298 ; relocate just below addr
1300 ; Move debugger to given address and restart.
1301 ; New location must not overlap with current location.
1312 ld bc,prog_size+bitmap_size
1317 ld ix,cmde_clr-ddtz_base
1320 ld hl,ddtz_base ;hl = src
1325 call c,neg.hl ;abs(distance)
1337 ;-------------------------------------------------------------------------------
1338 ; > G [startaddr] [;breakp..]
1339 ; Go [to start] [with temporary breakpoints]
1343 ld (bp_p_cpu_flag),a
1358 ;-------------------------------------------------------------------------------
1364 ld (pbl_loop_adr),hl
1377 ld hl,(pbl_loop_adr)
1391 ;-------------------------------------------------------------------------------
1393 ; display all breakpoints
1394 ; > B breakp [breakp..]
1397 ; clear all breakpoints
1398 ; > BX breakp [breakp..]
1401 ; breakp can be any valid expression
1461 ;-------------------------------------------------------------------------------
1462 ; Add break points to list
1463 ; A = 1 Permanent (B command)
1464 ; A = 2 Temporary (G command)
1481 call bp_get_freeslot
1503 ;-------------------------------------------------------------------------------
1504 ; Breakpoint handling routine.
1538 call inchar ;Keyboard hit?
1546 call bp_clr_temporary
1559 ld (bp_p_cpu_flag),a
1616 call bp_get_freeslot
1655 ;-------------------------------------------------------------------------------
1660 ld a,(bp_p_cpu_flag)
1690 ;-------------------------------------------------------------------------------
1692 ; examine all Y variables
1694 ; examine (and substitute) an Y variable
1697 ;-------------------------------------------------------------------------------
1699 ; eXamine (display) all cpu registers and
1700 ; the instruction at the current program counter
1702 ; eXamine (and substitute) a register
1911 ;-------------------------------------------------------------------------------
1917 call get_lastarg_def
1951 ;-------------------------------------------------------------------------------
1953 ; examine (substitute) displacement register @
1957 ;-------------------------------------------------------------------------------
1959 ; Input a byte from port
1964 call get_lastarg_def
1976 ;-------------------------------------------------------------------------------
1978 ; Output a byte to a port
1989 call get_lastarg_def
1997 ;-------------------------------------------------------------------------------
1998 ; > V startaddr endaddr targetaddr
1999 ; Verify (compare) two memory areas
2002 call get_arg_range_target
2029 ;-------------------------------------------------------------------------------
2030 ; > M startaddr endaddr destaddr
2034 call get_arg_range_target
2049 ;-------------------------------------------------------------------------------
2051 ; display Highest load address of last filed loaded, Maximum "High"
2052 ; off all loaded files, and Top address of available memory
2054 ; evaluate expression and display result in hex, decimal and other formats
2074 ;-------------------------------------------------------------------------------
2075 ; > Q[J] startaddr endaddr bytes
2076 ; Query memory for a byte string [Justified]
2116 ;-------------------------------------------------------------------------------
2117 ; > Z startaddr endaddr bytes
2118 ; Zap (fill) memory with a byte string
2152 sub_0ef7h: ;from cmd_Q, cmd_Z
2153 db 0e6h ;and 037h (clear carry)
2154 sub_0ef8h: ;from cmd_S
2202 ;-------------------------------------------------------------------------------
2203 ; >>D [startaddr] [endaddr]
2204 ; Display memory in hex and ASCII
2272 ;-------------------------------------------------------------------------------
2274 ; specifiy filenames and command line
2278 ;-------------------------------------------------------------------------------
2279 ; > R [displacement]
2280 ; Read Intel Hex File from console [add displacement]
2284 call get_lastarg_def ;get offset from command line
2293 ld c,0 ;init checksum
2294 call i.gethexbyte ;record len
2296 call i.gethexbyte ;address high
2298 call i.gethexbyte ;address low
2300 call i.gethexbyte ;record type (ignored)
2302 and a ;record len == 0?
2313 djnz l16c6h ;repeat for record len
2314 call i.gethexbyte ;checksum
2317 jr nz,error2 ;exit if checksum error
2318 jr w_recstart ;next record
2356 ld de,TPA ;lowest allowed load address
2359 ld de,(BDOS+1) ;highest allowed load address
2374 ld (hl),a ;store byte
2377 ;-------------------------------------------------------------------------------
2396 ;-------------------------------------------------------------------------------
2397 ; > Wstartaddr endaddr
2398 ; Write a file to disk
2402 ;-------------------------------------------------------------------------------
2404 ; Assemble Zilog Z180 mnemonics
2408 ;-------------------------------------------------------------------------------
2409 ; >>L [startaddr] [endaddr]
2410 ; List disassembled code
2444 ;-------------------------------------------------------------------------------
2463 ;-------------------------------------------------------------------------------
2466 call disas_get_instrlen
2472 call pstr ;print mnemonic
2474 call pr_instr_args ;print arguments
2488 ld (isprefix_ixiy),a
2507 ld (isprefix_ixiy),a
2518 ;-------------------------------------------------------------------------------
2521 ld hl,b_1b54_start ;2 byte opcodes
2525 ld hl,b_1ab6_start ;1 byte opcodes (no parameters)
2529 ld hl,b_1ad1_start ;1 byte opcodes
2533 ld hl,b_1b9b_start ;3 byte opcodes
2538 ;-------------------------------------------------------------------------------
2551 ld hl,b_1bc9_start ;1 byte opcode, no arguments
2577 ;-------------------------------------------------------------------------------
2582 ld a,(isprefix_ixiy)
2593 ;-------------------------------------------------------------------------------
2621 ;-------------------------------------------------------------------------------
2622 ; DD/FD 3 byte (ix+d)/(iy+d)
2669 ;-------------------------------------------------------------------------------
2696 call lookup_branch_op
2722 lookup_branch_op ;TODO
2742 ;-------------------------------------------------------------------------------
2743 ; 1 byte opcodes (no parameters)
2744 ; Format: db opcode, t_MNEMONICS-index
2746 db 076h,i_HALT ;halt
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
2764 ; Format: db mask, match, t_MNEMONICS-index
2765 ; dw argument formating function
2767 db 0c0h,040h,i_LD ;ld r[y],r[z]
2770 db 0c0h,080h,i_ADD+080h ;add a,r[z]
2773 ; db 0f8h,080h,i_ADD ;add a,r[z]
2775 ; db 0f8h,088h,i_ADC ;adc a,r[z]
2777 ; db 0f8h,090h,i_SUB ;sub r[z]
2779 ; db 0f8h,098h,i_SBC ;sbc a,r[z]
2781 ; db 0f8h,0a0h,i_AND ;and r[z]
2783 ; db 0f8h,0a8h,i_XOR ;xor r[z]
2785 ; db 0f8h,0b0h,i_OR ;or r[z]
2787 ; db 0f8h,0b8h,i_CP ;cp r[z]
2790 db 0c7h,0c0h,i_RET ;ret cc
2792 db 0c7h,0c7h,i_RST ;rst
2794 db 0cfh,0c1h,i_POP ;pop rp2
2796 db 0cfh,0c5h,i_PUSH ;push rp2
2798 db 0ffh,0e3h,i_EX ;ex (sp),hl
2800 db 0ffh,0e9h,i_JP ;jp (hl)
2802 db 0ffh,0ebh,i_EX ;ex de,hl
2804 db 0ffh,0f9h,i_LD ;ld sp,hl
2806 db 0cfh,003h,i_INC ;inc rp
2808 db 0cfh,00bh,i_DEC ;dec rp
2810 db 0c7h,004h,i_INC ;inc r[y]
2812 db 0c7h,005h,i_DEC ;dec r[y]
2814 db 0ffh,008h,i_EX ;ex af,af'
2816 db 0cfh,009h,i_ADD ;add hl,rp
2818 db 0efh,002h,i_LD ;ld (rp),a ;rp=bc,de
2820 db 0efh,00ah,i_LD ;ld a,(rp) ;rp=bc,de
2823 db 0c7h,007h,i_RLCA+080h;rlca
2830 db 0c7h,006h,i_LD ;ld r[y],nn
2833 db 0c7h,0c6h,i_ADD+080h ;add a,r[z]
2836 ; db 0ffh,0c6h,i_ADD ;add a,nn
2838 ; db 0ffh,0ceh,i_ADC ;adc a,nn
2840 ; db 0ffh,0d6h,i_SUB ;sub nn
2842 ; db 0ffh,0deh,i_SBC ;sbc a,nn
2844 ; db 0ffh,0e6h,i_AND ;and nn
2846 ; db 0ffh,0eeh,i_XOR ;xor nn
2848 ; db 0ffh,0f6h,i_OR ;or nn
2850 ; db 0ffh,0feh,i_CP ;cp nn
2853 db 0ffh,010h,i_DJNZ ;djnz
2855 db 0ffh,018h,i_JR ;jr
2857 db 0e7h,020h,i_JR ;jr cc,
2859 db 0ffh,0d3h,i_OUT ;out (nn),a
2861 db 0ffh,0dbh,i_IN ;in a,(nn)
2867 db 0c7h,0c2h,i_JP ;jp cc,mn
2869 db 0c7h,0c4h,i_CALL ;call cc,mn
2871 db 0cfh,001h,i_LD ;ld ww,mn
2873 db 0ffh,0c3h,i_JP ;jp mn
2875 db 0ffh,0cdh,i_CALL ;call mn
2877 db 0ffh,022h,i_LD ;ld (mn),hl
2879 db 0ffh,02ah,i_LD ;ld hl,(mn)
2881 db 0ffh,032h,i_LD ;ld (mn),a
2883 db 0ffh,03ah,i_LD ;ld a,(mn)
2887 ; Prefix ED + 1 byte opcode, no arguments
2888 ; Format: opcode, t_MNEMONICS index
2891 db 045h,i_RETN ;retn
2892 db 04dh,i_RETI ;reti
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
2921 db 0ffh,070h,i_IN ;in (c) ;
2923 db 0c7h,040h,i_IN ;in r,(c) ;r=b,c,d,e,h,l,a
2925 db 0ffh,071h,0ffh ;out (c),0 ;
2927 db 0c7h,041h,i_OUT ;out (c),r ;r=b,c,d,e,h,l,a
2929 db 0cfh,042h,i_SBC ;sbc hl,rp
2931 db 0cfh,04ah,i_ADC ;adc hl,rp
2933 db 0ffh,046h,i_IM ;im 0
2935 db 0ffh,056h,i_IM ;im 1
2937 db 0ffh,05eh,i_IM ;im 2
2939 db 0e7h,047h,i_LD ;ld i,a ... ld a,r
2941 db 0cfh,04ch,i_MLT ;mlt rr
2943 db 0c7h,004h,i_TST ;tst r
2948 db 0ffh,030h,i_IN0 ;in0 (m)
2950 db 0c7h,000h,i_IN0 ;in0 r,(m) ;r=b,c,d,e,h,l,a
2952 db 0ffh,031h,0ffh ;out0 (m),0
2954 db 0c7h,001h,i_OUT0 ;out0 (m),r ;r=b,c,d,e
2956 db 0ffh,064h,i_TST ;tst m
2958 db 0ffh,074h,i_TSTIO ;tstio m
2962 ; Prefix ED + 1 byte opcode + 2 byte address
2963 ; Format: db mask, match, t_MNEMONICS-index
2964 ; dw argument formating function
2966 db 0cfh,043h,i_LD ;ld (mn),ww ;ww=bc,de,hl,sp
2968 db 0cfh,04bh,i_LD ;ld ww,(mn) ;ww=bc,de,hl,sp
2974 db 0c0h,000h,i_RLC+080h ;rlc g
2977 ; db 0f8h,000h,i_RLC ;rlc g
2979 ; db 0f8h,008h,i_RRC ;rrc g
2981 ; db 0f8h,010h,i_RL ;rl g
2983 ; db 0f8h,018h,i_RR ;rr g
2985 ; db 0f8h,020h,i_SLA ;sla g
2987 ; db 0f8h,028h,i_SRA ;sra g
2989 ; db 0f8h,038h,i_SRL ;srl g
2991 db 0c0h,040h,i_BIT ;bit b,g
2993 db 0c0h,080h,i_RES ;res b,g
2995 db 0c0h,0c0h,i_SET ;set b,g
2999 ;-------------------------------------------------------------------------------
3000 ;-------------------------------------------------------------------------------
3008 ld a,(hl) ;get next token
3013 call outchar ;print as normal character
3031 ; http://www.z80.info/decoding.htm
3033 ; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
3041 db fi_ry,',' ;ld r[y],r[z]
3045 ; db 'A,',fi_rz,0 ;op A,r[z]
3047 db fi_ccy,0 ;op cc[y]
3049 db fi_rst,0 ;rst y*8
3052 a_esphl equ $-t_argf
3053 db '(SP),',fi_hlixiy,0 ;ex (sp),hl
3055 db '(',fi_hlixiy,')',0 ;jp (hl)
3058 a_lsphl equ $-t_argf
3059 db 'SP,',fi_hlixiy,0 ;ld SP,HL
3061 db 'AF,AF''',0 ;ex af,af'
3063 db fi_hlixiy,',' ;add hl,rp
3067 db '(',fi_rp,'),A',0 ;ld (rp),a ;rp=bc,de
3069 db 'A,(',fi_rp,')',0 ;ld a,(rp) ;rp=bc,de
3073 db fi_ry,',',fi_n,0 ;ld r[y],n
3079 db fi_ccy2,',' ;jr cc,j ;cc = nz,z,nc,c
3083 db '(',fi_n,'),A',0 ;out (n),a
3085 db 'A,(',fi_n,')',0 ;in a,(n)
3089 db fi_ccy,',',fi_nn,0 ;op cc[y],nn
3091 db fi_rp,',' ;ld rp[p],nn
3095 db '(',fi_nn,'),',fi_hlixiy,0 ;ld (nn),hl
3097 db fi_hlixiy,',(',fi_nn,')',0 ;ld hl,(nn)
3099 db '(',fi_nn,'),A',0 ;ld (nn),a
3101 db 'A,(',fi_nn,')',0 ;ld a,(nn)
3103 ; Prefix ED + 1 byte opcode
3105 db fi_ry,',' ;in r[y],(c)
3109 db '(C),' ;out (c),r[y]
3111 db fi_ry,0 ;inc r[y]
3119 db fi_ir,0 ;ld a,i ... r,a
3121 ; Prefix ED + 2 byte (opcode + immediate)
3123 db fi_ry,',' ;in0 r[y],(n)
3125 db '(',fi_n,')',0 ;in0 (n)
3127 db '(',fi_n,'),',fi_ry,0 ;out0 (n),r[y]
3129 ; Prefix ED + 3 byte (opcode + address)
3131 db '(',fi_nn,'),',fi_rp,0 ;ld (nn),rp
3133 db fi_rp,',(',fi_nn,')',0 ;ld rp,(nn)
3135 ; Prefix CB + 1 byte opcode
3137 db fi_y,',' ;op y,r[z]
3139 db fi_rz_cb,0 ;op r[z]
3140 a_noarg equ $-t_argf
3144 ;-------------------------------------------------------------------------------
3149 fi_&x equ 80h+argpf_index
3151 argpf_index defl argpf_index+1
3172 ld a,(isprefix_ixiy)
3214 ld a,(isprefix_ixiy)
3243 ld a,(isprefix_ixiy)
3267 db 0ddh ;swallow t_arg_rp in ix
3278 ld a,(isprefix_ixiy)
3313 ;-------------------------------------------------------------------------------
3318 ;o_&x equ $-opc_tabstart
3320 opc_index defl opc_index+1
3324 ;opc_tabstart defl $
3387 ; Block instructions
3469 ;-------------------------------------------------------------------------------
3479 ld hl,l20edh ;set break after BDOS call
3482 call disas_get_instrlen
3491 call lookup_branch_op
3497 call c,bp_trace_enter
3502 ;-------------------------------------------------------------------------------
3505 db 0ffh,0ddh ;Prefix DD
3507 db 0ffh,0fdh ;Prefix FD
3509 db 0ffh,0edh ;Prefix ED
3512 db 0ffh,0cdh ;call mn
3524 db 0c7h,0c4h ;call cc,mn
3526 db 0f7h,010h ;djnz d; jr d
3528 db 0e7h,020h ;jr cc,d
3530 db 0c7h,0c2h ;jp cc,mn
3532 db 0c7h,0c0h ;ret cc
3536 ;-------------------------------------------------------------------------------
3537 ; call mn call cc,mn
3575 cp 0e9h ; jp (ix); jp (iy)
3609 ld hl,(reg_sp) ;break on return address
3633 ;-------------------------------------------------------------------------------
3635 ; >>C[N][J] W expression
3636 ; >>C[N][J] U expression
3637 ; trace over Calls [No list] [Jumps only] /.While./.Until.
3640 ;-------------------------------------------------------------------------------
3642 ; >>T[N][J] W expression
3643 ; >>T[N][J] U expression
3644 ; Trace [no List] [Jumps only] / .While. / .Until.
3648 ld hl,1 ;default: 1 step
3649 call get_lastarg_def
3650 ld (trace_cnt_or_ptr),hl
3652 ld (bp_p_cpu_flag),a
3657 call bp_clr_temporary
3658 ld hl,(trace_cnt_or_ptr)
3660 ld (trace_cnt_or_ptr),hl
3668 ld (bp_p_cpu_flag),a
3672 ;-------------------------------------------------------------------------------
3677 ;-------------------------------------------------------------------------------
3694 ;-------------------------------------------------------------------------------
3723 ;-------------------------------------------------------------------------------
3728 ;-------------------------------------------------------------------------------
3730 rept (STACK_SIZE+3)/4
3731 db 0deh,0adh,0beh,0efh
3762 ;-------------------------------------------------------------------------------
3764 ddtz_size equ $-ddtz_base
3765 prog_size equ $-start
3768 ;-------------------------------------------------------------------------------