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.
9 ;-------------------------------------------------------------------------------
26 ;-------------------------------------------------------------------------------
30 ; Some greneral definitions
46 BDOS_PSTR equ 9 ;Print String
48 ; ddtz specific definitions
50 STACK_SIZE equ 80 ;ddtz internal stack
51 CONBUF_SIZE equ 80 ;Size of console input buffer
52 EXPR_BUF_SIZE equ 128 ;expressen buffer for conditional breakpoints
53 BP_CNT equ 12 ;Number of breakpoints
54 BP_SIZE equ 4 ;Size of a breakpoint record
56 ;-------------------------------------------------------------------------------
68 current_cseg defl $ - current_cseg
69 .phase current_phase + current_cseg
77 db 'Z80 or better required!',cr,lf,'$'
82 ds STACK_SIZE - (current_phase - signon)
114 ;-------------------------------------------------------------------------------
149 ld hl,(1) ;wboot addr
167 ds CONBUF_SIZE + 3 - ($ - conbuf)
169 ;-------------------------------------------------------------------------------
171 ?const: jp 0 ; return console input status
172 ?conin: jp 0 ; return console input character
173 ?cono: jp 0 ; send console output character
174 ?list: jp 0 ; send list output character
175 ?auxo: jp 0 ; send auxiliary output character
176 ?auxi: jp 0 ; return auxiliary input character
179 dw ERROR ;cmd_@ ;examine/substitute the displacement register @
180 dw ERROR ;cmd_A ;Assemble
181 dw cmd_B ;Breakpoints display/set/clear
182 dw ERROR ;cmd_C ;trace over Calls
183 dw cmd_D ;Display memory in hex and ascii
185 dw ERROR ;cmd_F ;specify Filename and command line
187 dw cmd_H ;compute Hex and other expressions
188 dw cmd_I ;Input a byte from port
191 dw cmd_L ;List disassembled code
192 dw cmd_M ;Move memory [and verify]
194 dw cmd_O ;Output a byte to port
196 dw cmd_Q ;Qery memory for byte string
197 dw cmd_R ;Read binary or hex file
198 dw cmd_S ;Substitute memory
201 dw cmd_V ;Verify (compare) two memory areas
202 dw ERROR ;cmd_W ;Write a file to disk
203 dw cmd_X ;eXamine [and substitute] registers
204 dw ERROR ;cmd_Y ;examine [and substitute] Y variables
205 dw cmd_Z ;Zap (fill) memory with a byte string
214 call bp_clr_temporary
244 ;-------------------------------------------------------------------------------
264 defb 03eh ;ld a,.. swallow push hl
398 ;-------------------------------------------------------------------------------
405 ;-------------------------------------------------------------------------------
424 ;-------------------------------------------------------------------------------
449 ;-------------------------------------------------------------------------------
464 jr z,inl_e ;Accept line
466 jr z,inl_e ;Accept line
473 call DELC ;Delete Char
478 call DELL ;Delete Line
488 ld a,'^' ;Controll characters
509 ;-------------------------------------------------------------------------------
522 ;-------------------------------------------------------------------------------
533 ;-------------------------------------------------------------------------------
549 ;-------------------------------------------------------------------------------
556 ld de,stack-(STACK_SIZE-28)
563 ;-------------------------------------------------------------------------------
580 ;-------------------------------------------------------------------------------
699 defb 0e6h ;and a,.. clear carry
711 defb 03eh ;ld a,.. swallow pop af
753 jr z,error0 ;'S', but no expression following
757 ;-------------------------------------------------------------------------------
840 ; de: x (x shifted out, q shifted in)
842 ; hl: r (initially 0)
916 ;-------------------------------------------------------------------------------
958 ;-------------------------------------------------------------------------------
1044 ;-------------------------------------------------------------------------------
1152 ;-------------------------------------------------------------------------------
1196 ld hl,t_flag_names+7
1291 ;-------------------------------------------------------------------------------
1292 ; > G [startaddr] [;breakp..]
1293 ; Go [to start] [with temporary breakpoints]
1297 ld (bp_p_cpu_flag),a
1312 ;-------------------------------------------------------------------------------
1318 ld (pbl_loop_adr),hl
1331 ld hl,(pbl_loop_adr)
1345 ;-------------------------------------------------------------------------------
1347 ; display all breakpoints
1348 ; > B breakp [breakp..]
1351 ; clear all breakpoints
1352 ; > BX breakp [breakp..]
1355 ; breakp can be any valid expression
1415 ;-------------------------------------------------------------------------------
1416 ; Add break points to list
1417 ; A = 1 Permanent (B command)
1418 ; A = 2 Temporary (G command)
1435 call bp_get_freeslot
1457 ;-------------------------------------------------------------------------------
1458 ; Breakpoint handling routine.
1492 call inchar ;Keyboard hit?
1500 call bp_clr_temporary
1513 ld (bp_p_cpu_flag),a
1570 call bp_get_freeslot
1609 ;-------------------------------------------------------------------------------
1614 ld a,(bp_p_cpu_flag)
1644 ;-------------------------------------------------------------------------------
1646 ; examine all Y variables
1648 ; examine (and substitute) an Y variable
1651 ;-------------------------------------------------------------------------------
1653 ; eXamine (display) all cpu registers and
1654 ; the instruction at the current program counter
1656 ; eXamine (and substitute) a register
1865 ;-------------------------------------------------------------------------------
1871 call get_lastarg_def
1905 ;-------------------------------------------------------------------------------
1907 ; examine (substitute) displacement register @
1911 ;-------------------------------------------------------------------------------
1913 ; Input a byte from port
1918 call get_lastarg_def
1930 ;-------------------------------------------------------------------------------
1932 ; Output a byte to a port
1943 call get_lastarg_def
1951 ;-------------------------------------------------------------------------------
1952 ; > Vstartaddr endaddr targetaddr
1953 ; Verify (compare) two memory areas
1983 ;-------------------------------------------------------------------------------
1984 ; > M startaddr endaddr destaddr
1998 db 01h ;swallow ldir instruction (ld bc,...)
2003 ;-------------------------------------------------------------------------------
2005 ; display Highest load address of last filed loaded, Maximum "High"
2006 ; off all loaded files, and Top address of available memory
2008 ; evaluate expression and display result in hex, decimal and other formats
2028 ;-------------------------------------------------------------------------------
2029 ; > Q[J] startaddr endaddr bytes
2030 ; Query memory for a byte string [Justified]
2070 ;-------------------------------------------------------------------------------
2071 ; > Z startaddr endaddr bytes
2072 ; Zap (fill) memory with a byte string
2106 sub_0ef7h: ;from cmd_Q, cmd_Z
2107 db 0e6h ;and 037h (clear carry)
2108 sub_0ef8h: ;from cmd_S
2156 ;-------------------------------------------------------------------------------
2157 ; >>D [startaddr] [endaddr]
2158 ; Display memory in hex and ASCII
2226 ;-------------------------------------------------------------------------------
2228 ; specifiy filenames and command line
2232 ;-------------------------------------------------------------------------------
2233 ; > R [displacement]
2234 ; Read Intel Hex File from console [add displacement]
2238 call get_lastarg_def ;get offset from command line
2247 ld c,0 ;init checksum
2248 call i.gethexbyte ;record len
2250 call i.gethexbyte ;address high
2252 call i.gethexbyte ;address low
2254 call i.gethexbyte ;record type (ignored)
2256 and a ;record len == 0?
2267 djnz l16c6h ;repeat for record len
2268 call i.gethexbyte ;checksum
2271 jr nz,error2 ;exit if checksum error
2272 jr w_recstart ;next record
2310 ld de,TPA ;lowest allowed load address
2313 ld de,(BDOS+1) ;highest allowed load address
2328 ld (hl),a ;store byte
2331 ;-------------------------------------------------------------------------------
2350 ;-------------------------------------------------------------------------------
2351 ; > Wstartaddr endaddr
2352 ; Write a file to disk
2356 ;-------------------------------------------------------------------------------
2358 ; Assemble Zilog Z180 mnemonics
2362 ;-------------------------------------------------------------------------------
2363 ; >>L [startaddr] [endaddr]
2364 ; List disassembled code
2398 ;-------------------------------------------------------------------------------
2417 ;-------------------------------------------------------------------------------
2420 call disas_get_instrlen
2426 call pstr ;print mnemonic
2428 call pr_instr_args ;print arguments
2442 ld (isprefix_ixiy),a
2461 ld (isprefix_ixiy),a
2472 ;-------------------------------------------------------------------------------
2475 ld hl,b_1b54_start ;2 byte opcodes
2479 ld hl,b_1ab6_start ;1 byte opcodes (no parameters)
2483 ld hl,b_1ad1_start ;1 byte opcodes
2487 ld hl,b_1b9b_start ;3 byte opcodes
2492 ;-------------------------------------------------------------------------------
2505 ld hl,b_1bc9_start ;1 byte opcode, no arguments
2531 ;-------------------------------------------------------------------------------
2536 ld a,(isprefix_ixiy)
2547 ;-------------------------------------------------------------------------------
2575 ;-------------------------------------------------------------------------------
2576 ; DD/FD 3 byte (ix+d)/(iy+d)
2623 ;-------------------------------------------------------------------------------
2650 call lookup_branch_op
2676 lookup_branch_op ;TODO
2696 ;-------------------------------------------------------------------------------
2697 ; 1 byte opcodes (no parameters)
2698 ; Format: db opcode, t_MNEMONICS-index
2700 db 076h,i_HALT ;halt
2705 ; db 007h,i_RLCA ;rlca
2706 ; db 00fh,i_RRCA ;rrca
2707 ; db 017h,i_RLA ;rla
2708 ; db 01fh,i_RRA ;rra
2709 ; db 027h,i_DAA ;daa
2710 ; db 02fh,i_CPL ;cpl
2711 ; db 037h,i_SCF ;scf
2712 ; db 03fh,i_CCF ;ccf
2718 ; Format: db mask, match, t_MNEMONICS-index
2719 ; dw argument formating function
2721 db 0c0h,040h,i_LD ;ld r[y],r[z]
2724 db 0c0h,080h,i_ADD+080h ;add a,r[z]
2727 ; db 0f8h,080h,i_ADD ;add a,r[z]
2729 ; db 0f8h,088h,i_ADC ;adc a,r[z]
2731 ; db 0f8h,090h,i_SUB ;sub r[z]
2733 ; db 0f8h,098h,i_SBC ;sbc a,r[z]
2735 ; db 0f8h,0a0h,i_AND ;and r[z]
2737 ; db 0f8h,0a8h,i_XOR ;xor r[z]
2739 ; db 0f8h,0b0h,i_OR ;or r[z]
2741 ; db 0f8h,0b8h,i_CP ;cp r[z]
2744 db 0c7h,0c0h,i_RET ;ret cc
2746 db 0c7h,0c7h,i_RST ;rst
2748 db 0cfh,0c1h,i_POP ;pop rp2
2750 db 0cfh,0c5h,i_PUSH ;push rp2
2752 db 0ffh,0e3h,i_EX ;ex (sp),hl
2754 db 0ffh,0e9h,i_JP ;jp (hl)
2756 db 0ffh,0ebh,i_EX ;ex de,hl
2758 db 0ffh,0f9h,i_LD ;ld sp,hl
2760 db 0cfh,003h,i_INC ;inc rp
2762 db 0cfh,00bh,i_DEC ;dec rp
2764 db 0c7h,004h,i_INC ;inc r[y]
2766 db 0c7h,005h,i_DEC ;dec r[y]
2768 db 0ffh,008h,i_EX ;ex af,af'
2770 db 0cfh,009h,i_ADD ;add hl,rp
2772 db 0efh,002h,i_LD ;ld (rp),a ;rp=bc,de
2774 db 0efh,00ah,i_LD ;ld a,(rp) ;rp=bc,de
2777 db 0c7h,007h,i_RLCA+080h;rlca
2784 db 0c7h,006h,i_LD ;ld r[y],nn
2787 db 0c7h,0c6h,i_ADD+080h ;add a,r[z]
2790 ; db 0ffh,0c6h,i_ADD ;add a,nn
2792 ; db 0ffh,0ceh,i_ADC ;adc a,nn
2794 ; db 0ffh,0d6h,i_SUB ;sub nn
2796 ; db 0ffh,0deh,i_SBC ;sbc a,nn
2798 ; db 0ffh,0e6h,i_AND ;and nn
2800 ; db 0ffh,0eeh,i_XOR ;xor nn
2802 ; db 0ffh,0f6h,i_OR ;or nn
2804 ; db 0ffh,0feh,i_CP ;cp nn
2807 db 0ffh,010h,i_DJNZ ;djnz
2809 db 0ffh,018h,i_JR ;jr
2811 db 0e7h,020h,i_JR ;jr cc,
2813 db 0ffh,0d3h,i_OUT ;out (nn),a
2815 db 0ffh,0dbh,i_IN ;in a,(nn)
2821 db 0c7h,0c2h,i_JP ;jp cc,mn
2823 db 0c7h,0c4h,i_CALL ;call cc,mn
2825 db 0cfh,001h,i_LD ;ld ww,mn
2827 db 0ffh,0c3h,i_JP ;jp mn
2829 db 0ffh,0cdh,i_CALL ;call mn
2831 db 0ffh,022h,i_LD ;ld (mn),hl
2833 db 0ffh,02ah,i_LD ;ld hl,(mn)
2835 db 0ffh,032h,i_LD ;ld (mn),a
2837 db 0ffh,03ah,i_LD ;ld a,(mn)
2841 ; Prefix ED + 1 byte opcode, no arguments
2842 ; Format: opcode, t_MNEMONICS index
2845 db 045h,i_RETN ;retn
2846 db 04dh,i_RETI ;reti
2849 ; db 0a0h,i_LDI ;ldi
2850 ; db 0a1h,i_CPI ;cpi
2851 ; db 0a2h,i_INI ;ini
2852 ; db 0a3h,i_OUTI ;outi
2853 ; db 0a8h,i_LDD ;ldd
2854 ; db 0a9h,i_CPD ;cpd
2855 ; db 0aah,i_IND ;ind
2856 ; db 0abh,i_OUTD ;outd
2857 ; db 0b0h,i_LDIR ;ldir
2858 ; db 0b1h,i_CPIR ;cpir
2859 ; db 0b2h,i_INIR ;inir
2860 ; db 0b3h,i_OTIR ;otir
2861 ; db 0b8h,i_LDDR ;lddr
2862 ; db 0b9h,i_CPDR ;cpdr
2863 ; db 0bah,i_INDR ;indr
2864 ; db 0bbh,i_OTDR ;otdr
2865 db 08bh,i_OTDM ;otdm
2866 db 09bh,i_OTDMR ;otdmr
2867 db 083h,i_OTIM ;otim
2868 db 093h,i_OTIMR ;otimr
2875 db 0ffh,070h,i_IN ;in (c) ;
2877 db 0c7h,040h,i_IN ;in r,(c) ;r=b,c,d,e,h,l,a
2879 db 0ffh,071h,0ffh ;out (c),0 ;
2881 db 0c7h,041h,i_OUT ;out (c),r ;r=b,c,d,e,h,l,a
2883 db 0cfh,042h,i_SBC ;sbc hl,rp
2885 db 0cfh,04ah,i_ADC ;adc hl,rp
2887 db 0ffh,046h,i_IM ;im 0
2889 db 0ffh,056h,i_IM ;im 1
2891 db 0ffh,05eh,i_IM ;im 2
2893 db 0e7h,047h,i_LD ;ld i,a ... ld a,r
2895 db 0cfh,04ch,i_MLT ;mlt rr
2897 db 0c7h,004h,i_TST ;tst r
2902 db 0ffh,030h,i_IN0 ;in0 (m)
2904 db 0c7h,000h,i_IN0 ;in0 r,(m) ;r=b,c,d,e,h,l,a
2906 db 0ffh,031h,0ffh ;out0 (m),0
2908 db 0c7h,001h,i_OUT0 ;out0 (m),r ;r=b,c,d,e
2910 db 0ffh,064h,i_TST ;tst m
2912 db 0ffh,074h,i_TSTIO ;tstio m
2916 ; Prefix ED + 1 byte opcode + 2 byte address
2917 ; Format: db mask, match, t_MNEMONICS-index
2918 ; dw argument formating function
2920 db 0cfh,043h,i_LD ;ld (mn),ww ;ww=bc,de,hl,sp
2922 db 0cfh,04bh,i_LD ;ld ww,(mn) ;ww=bc,de,hl,sp
2928 db 0c0h,000h,i_RLC+080h ;rlc g
2931 ; db 0f8h,000h,i_RLC ;rlc g
2933 ; db 0f8h,008h,i_RRC ;rrc g
2935 ; db 0f8h,010h,i_RL ;rl g
2937 ; db 0f8h,018h,i_RR ;rr g
2939 ; db 0f8h,020h,i_SLA ;sla g
2941 ; db 0f8h,028h,i_SRA ;sra g
2943 ; db 0f8h,038h,i_SRL ;srl g
2945 db 0c0h,040h,i_BIT ;bit b,g
2947 db 0c0h,080h,i_RES ;res b,g
2949 db 0c0h,0c0h,i_SET ;set b,g
2953 ;-------------------------------------------------------------------------------
2954 ;-------------------------------------------------------------------------------
2962 ld a,(hl) ;get next token
2967 call outchar ;print as normal character
2985 ; http://www.z80.info/decoding.htm
2987 ; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
2995 db fi_ry,',' ;ld r[y],r[z]
2999 ; db 'A,',fi_rz,0 ;op A,r[z]
3001 db fi_ccy,0 ;op cc[y]
3003 db fi_rst,0 ;rst y*8
3006 a_esphl equ $-t_argf
3007 db '(SP),',fi_hlixiy,0 ;ex (sp),hl
3009 db '(',fi_hlixiy,')',0 ;jp (hl)
3012 a_lsphl equ $-t_argf
3013 db 'SP,',fi_hlixiy,0 ;ld SP,HL
3015 db 'AF,AF''',0 ;ex af,af'
3017 db fi_hlixiy,',' ;add hl,rp
3021 db '(',fi_rp,'),A',0 ;ld (rp),a ;rp=bc,de
3023 db 'A,(',fi_rp,')',0 ;ld a,(rp) ;rp=bc,de
3027 db fi_ry,',',fi_n,0 ;ld r[y],n
3033 db fi_ccy2,',' ;jr cc,j ;cc = nz,z,nc,c
3037 db '(',fi_n,'),A',0 ;out (n),a
3039 db 'A,(',fi_n,')',0 ;in a,(n)
3043 db fi_ccy,',',fi_nn,0 ;op cc[y],nn
3045 db fi_rp,',' ;ld rp[p],nn
3049 db '(',fi_nn,'),',fi_hlixiy,0 ;ld (nn),hl
3051 db fi_hlixiy,',(',fi_nn,')',0 ;ld hl,(nn)
3053 db '(',fi_nn,'),A',0 ;ld (nn),a
3055 db 'A,(',fi_nn,')',0 ;ld a,(nn)
3057 ; Prefix ED + 1 byte opcode
3059 db fi_ry,',' ;in r[y],(c)
3063 db '(C),' ;out (c),r[y]
3065 db fi_ry,0 ;inc r[y]
3073 db fi_ir,0 ;ld a,i ... r,a
3075 ; Prefix ED + 2 byte (opcode + immediate)
3077 db fi_ry,',' ;in0 r[y],(n)
3079 db '(',fi_n,')',0 ;in0 (n)
3081 db '(',fi_n,'),',fi_ry,0 ;out0 (n),r[y]
3083 ; Prefix ED + 3 byte (opcode + address)
3085 db '(',fi_nn,'),',fi_rp,0 ;ld (nn),rp
3087 db fi_rp,',(',fi_nn,')',0 ;ld rp,(nn)
3089 ; Prefix CB + 1 byte opcode
3091 db fi_y,',' ;op y,r[z]
3093 db fi_rz_cb,0 ;op r[z]
3094 a_noarg equ $-t_argf
3098 ;-------------------------------------------------------------------------------
3103 fi_&x equ 80h+argpf_index
3105 argpf_index defl argpf_index+1
3126 ld a,(isprefix_ixiy)
3168 ld a,(isprefix_ixiy)
3197 ld a,(isprefix_ixiy)
3221 db 0ddh ;swallow t_arg_rp in ix
3232 ld a,(isprefix_ixiy)
3267 ;-------------------------------------------------------------------------------
3272 ;o_&x equ $-opc_tabstart
3274 opc_index defl opc_index+1
3278 ;opc_tabstart defl $
3341 ; Block instructions
3423 ;-------------------------------------------------------------------------------
3433 ld hl,l20edh ;set break after BDOS call
3436 call disas_get_instrlen
3445 call lookup_branch_op
3451 call c,bp_trace_enter
3456 ;-------------------------------------------------------------------------------
3459 db 0ffh,0ddh ;Prefix DD
3461 db 0ffh,0fdh ;Prefix FD
3463 db 0ffh,0edh ;Prefix ED
3466 db 0ffh,0cdh ;call mn
3478 db 0c7h,0c4h ;call cc,mn
3480 db 0f7h,010h ;djnz d; jr d
3482 db 0e7h,020h ;jr cc,d
3484 db 0c7h,0c2h ;jp cc,mn
3486 db 0c7h,0c0h ;ret cc
3490 ;-------------------------------------------------------------------------------
3491 ; call mn call cc,mn
3529 cp 0e9h ; jp (ix); jp (iy)
3563 ld hl,(reg_sp) ;break on return address
3587 ;-------------------------------------------------------------------------------
3589 ; >>C[N][J] W expression
3590 ; >>C[N][J] U expression
3591 ; trace over Calls [No list] [Jumps only] /.While./.Until.
3594 ;-------------------------------------------------------------------------------
3596 ; >>T[N][J] W expression
3597 ; >>T[N][J] U expression
3598 ; Trace [no List] [Jumps only] / .While. / .Until.
3602 ld hl,1 ;default: 1 step
3603 call get_lastarg_def
3604 ld (trace_cnt_or_ptr),hl
3606 ld (bp_p_cpu_flag),a
3611 call bp_clr_temporary
3612 ld hl,(trace_cnt_or_ptr)
3614 ld (trace_cnt_or_ptr),hl
3622 ld (bp_p_cpu_flag),a
3626 ;-------------------------------------------------------------------------------
3631 ;-------------------------------------------------------------------------------
3649 current_cseg defl $ - current_cseg
3650 .phase current_phase + current_cseg
3653 LD SP,ldr_end+(stack-ddtz_base)
3654 LD DE,signon ;ldr_end+(expr_buf-ddtz_base)
3667 LD HL,ldr_end+ddtz_size ;start of reloc bitmap
3668 ld bc,0108h ;init bit counter
3672 LD (ldr_end+(ddtz_bdos+1-ddtz_base)),HL
3676 INC DE ;size rounded up to next page boundary
3679 SBC HL,DE ;BDOS - size
3680 LD (BDOS+1),HL ;-> new BDOS entry
3695 ld b,c ;reload bit counter
3696 LD e,(HL) ;get next 8 relocation bits
3722 LD HL,conbuf+2-ddtz_base
3726 current_phase defl $
3730 ds EXPR_BUF_SIZE - ($ - expr_buf)
3733 ;-------------------------------------------------------------------------------
3762 ddtz_size equ $-ddtz_base
3765 ;-------------------------------------------------------------------------------