From 7b645c7f5ee450489b90af1e2edfa135402587d4 Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 20 Feb 2020 19:06:26 +0100 Subject: New disassembler --- ddt180.z80 | 1729 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 777 insertions(+), 952 deletions(-) diff --git a/ddt180.z80 b/ddt180.z80 index f683e46..3cdf550 100644 --- a/ddt180.z80 +++ b/ddt180.z80 @@ -1484,7 +1484,7 @@ l063eh: call outbl6 push hl push de - ld iy,(reg.pc) + ld de,(reg.pc) call p_disas_instr pop de pop hl @@ -2761,835 +2761,817 @@ l190fh: ;------------------------------------------------------------------------------- cmdl_p_line: - push hl +; push hl call out_hl call outbl2 sub a ld (con_col),a - push hl - pop iy + ex de,hl call p_disas_instr call crlf - pop hl - ld c,b - ld b,0 - add hl,bc + ex de,hl ld (last_L),hl ret -;------------------------------------------------------------------------------- - p_disas_instr: - call disas_get_instrlen - jr nc,l197fh - push bc - ld a,(con_col) - add a,5 - ld c,a - call pstr ;print mnemonic - call p_goto_col - call pr_instr_args ;print arguments - pop bc - scf - ret - -l197fh: - call pstr_inl - DC '???' - ld b,1 - sub a - ret - -;------------------------------------------------------------------------------- - -disas_get_instrlen: - sub a - ld (isprefix_ixiy),a - ld a,(iy+000h) - cp 0edh - jr z,disas_pfx.ED - cp 0ddh - jr z,l19abh - cp 0fdh - jr z,l19afh -sub_19a0h: - ld a,(iy+000h) - cp 0cbh - jr z,disas_pfx.CB - jr disas_nopfx -l19abh: - ld a,1 - jr l19b1h -l19afh: - ld a,2 -l19b1h: - ld (isprefix_ixiy),a - call disas_pfx.DDFD - ret nc - push bc - call sub_19a0h - pop af - add a,b - ld b,a - scf - ret + call dis_decode + jp pstr ;print instruction text ;------------------------------------------------------------------------------- -disas_nopfx: - ld hl,b_1b54_start ;2 byte opcodes - call lookup_op_arg - ld b,2 - ret c - ld hl,b_1ab6_start ;1 byte opcodes (no parameters) - call lookup_op - ld b,1 - ret c - ld hl,b_1ad1_start ;1 byte opcodes - call lookup_op_arg - ld b,1 - ret c - ld hl,b_1b9b_start ;3 byte opcodes - call lookup_op_arg - ld b,3 - ret - -;------------------------------------------------------------------------------- - -disas_pfx.ED: - inc iy - ld hl,l228bh - call lookup_op_arg - ld b,3 - ret c - ld hl,b_1c40_start - call lookup_op_arg - ld b,4 - ret c - - ld hl,b_1bc9_start ;1 byte opcode, no arguments - call lookup_op - jr c,da_ed1 - - ld hl,b_1bf4_start - call lookup_op_arg - ret nc +; Enter with DE pointing to the instruction - ld a,e - cp a_noarg - jr nz,da_ed0 - ld c,(iy+0) - ld a,c - rra - and 0ch - ld b,a - ld a,c - and 03h - call str_sel_ab - -da_ed0: - scf -da_ed1: - ld b,2 - ret - -;------------------------------------------------------------------------------- - -disas_pfx.CB: - push iy - inc iy - ld a,(isprefix_ixiy) - and a - jr z,l1a42h - inc iy -l1a42h: - ld hl,b_1c55_start - call lookup_op_arg - pop iy - ld b,2 - ret +dis_decode: + LD BC,0000h + PUSH BC + pop iy + PUSH BC ;workspace (4 bytes) + PUSH BC + ADD iy,SP ;workspace pointer to iy + + LD HL,GROUP3 + +TRYNDX: + CALL FETCH + + LD B,C ;First check whether this + CP 0EDh ;is an "ED" instruction + JR Z,CONFLG ;Yes, clear the index flag + + INC B ; + CP 0DDh + JR Z,CONFLG + + INC B + CP 0FDh + JR NZ,NOTNDX + +CONFLG: + LD (iy+1),B ;Condition the index flag + INC B ;Repeat index tests if the + DJNZ TRYNDX ;pre-byte was 0DDH or 0FDH + JR NXBYTE ;Otherwise continue + +NOTNDX: + LD C,A ;Save opcode byte; check if + LD A,(iy+1) ;index flag was set (allows any + OR A ;series of 0DDH and or 0FDH + JR Z,NODISP ;bytes, as per Zilog spec) + + LD A,C ;If so, check for presence + CP 0CBh ;of any displacement + JR Z,GETDIS ;0CBH needs a displacement + + AND 044h ;A displacement is required + CP 004h ;if opcode has bit 6 reset + JR Z,GETDIS ;and bit 2 set + + LD A,C ;A displacement is required + AND 0C0h ;if opcode has bit 6 set + CP 040h ;and bit 7 reset + JR NZ,NODISP + +GETDIS: + CALL FETCH ;Get displacement if needed + LD (iy+2),A ;and save it in workspace + +NODISP: + LD HL,GROUP1 ;"Main" instruction group + LD A,C ;Recover opcode and check + CP 0CBh ;for 0CBH + JR NZ,NEWMSK ;No, start the search + LD HL,GROUP2 ;Yes, point to "CB" group + +NXBYTE: + CALL FETCH ;Fetch the last non-data byte + LD C,A ;and store it in C + +NEWMSK: + LD A,(HL) ;Fetch a mask from table + OR A ;End of table? + JR Z,TABEND ; + + AND C ;Mask opcode + INC HL ;-> mode byte + +NEWMOD: + LD B,(HL) ;Fetch mode byte + INC HL ;-> match byte + INC B ;mode = 0FFH ? + JR Z,NEWMSK + +TRYMAT: + CP (HL) ;Is the masked opcode + INC HL ;equal to the match byte? + JR Z,GETNDX + + BIT 7,(HL) ;index byte bit 7 is set if + INC HL ;address mode changes + JR Z,TRYMAT + JR NEWMOD ;Change, get a new mode + +GETNDX: + LD A,(HL) ;Matched, fetch mnemonic index + AND 07Fh + DEC B ;Restore the mode byte + +TABEND: + push af + PUSH DE ;save source pointer + ld de,disasbuf ;buffer pointer + LD HL,MONICS + CALL XTRACT ;copy mnemonic to buffer -;------------------------------------------------------------------------------- + ex de,hl + LD DE,disasbuf+5 +da_spaces: + ld (hl),' ' + inc hl + call cp_hl_de + jr c,da_spaces + POP DE ;source pointer + pop af + or a + jr z,OPDONE1 -disas_pfx.DDFD: - inc iy - ld hl,b_19ef_start - call test_DDFD - ld b,002h - ret c - ld hl,l1a0ah - call test_DDFD - ld b,001h - ret c - ld a,(iy+000h) - cp 0cbh - jr nz,l19edh - ld a,(iy+002h) - cp 036h - ret z - and 007h - cp 006h - jr nz,l19edh - ld b,002h - scf - ret -l19edh: - and a - ret + LD A,B ;test + AND 0F0h ;if any "first" operand + JR Z,SECOND ;is present -;------------------------------------------------------------------------------- -; DD/FD 3 byte (ix+d)/(iy+d) -b_19ef_start: - db 034h - db 035h - db 036h - db 046h - db 04eh - db 056h - db 05eh - db 066h - db 06eh - db 070h - db 071h - db 072h - db 073h - db 074h - db 075h - db 077h - db 07eh - db 086h - db 08eh - db 096h - db 09eh - db 0a6h - db 0aeh - db 0b6h - db 0beh - db 0 + RRA + RRA + RRA + RRA + PUSH BC ;Save operand byte and opcode -; DD/FD 2 byte -l1a0ah: - db 009h - db 019h - db 021h - db 022h - db 023h - db 029h - db 02ah - db 02bh - db 039h - db 0e1h - db 0e3h - db 0e5h - db 0e9h - db 0f9h - db 0 + LD B,A ;save operand index + LD A,C ;get opcode + CALL OPRND1 ;process operand -;------------------------------------------------------------------------------- + POP BC ;Restore operand byte and opcode + LD A,B ;Test low-order B for any + AND 00Fh ;"second" operand + JR Z,OPDONE -test_DDFD: - ld a,(hl) - and a - ret z - inc hl - cp (iy+000h) - jr nz,test_DDFD - scf - ret + LD (HL),',' ;comma before second operand + INC HL -lookup_op: - ld a,(hl) - inc hl - cp 0ffh - ret z - cp (iy+000h) - jr z,l1a7fh - inc hl - jr lookup_op -l1a7fh: - ld b,(hl) - ld e,a_noarg - jr get_mnemonic +SECOND: + LD A,B + AND 00Fh -lookup_op_arg: - call lookup_branch_op - ret nc - ld a,e - ld e,d - cp a,0ffh - ret z ;carry clear - ld b,a + LD B,A ;operand index in B + LD A,C ;ocode in A + CALL NZ,OPRND2 -get_mnemonic: - ld hl,t_MNEMONICS - bit 7,b - jr z,get_m1 - res 7,b - ld a,(iy+000h) - rra - rra - rra - and 07h -str_sel_ab: - add b - ld b,a -get_m1: - call str_sel +OPDONE: + or 0ffh +OPDONE1: + ld (hl),0 ;Terminate output buffer + ld hl,disasbuf ;Return output buffer + POP bc ;Discard workspace and + POP bc ;put number of bytes fetched in b + ret z ;Return carry clear on error scf ret ;------------------------------------------------------------------------------- -; 1 byte opcodes (no parameters) -; Format: db opcode, t_MNEMONICS-index -b_1ab6_start: - db 076h,i_HALT ;halt - db 0d9h,i_EXX ;exx - db 0f3h,i_DI ;di - db 0fbh,i_EI ;ei - db 000h,i_NOP ;nop -; db 007h,i_RLCA ;rlca -; db 00fh,i_RRCA ;rrca -; db 017h,i_RLA ;rla -; db 01fh,i_RRA ;rra -; db 027h,i_DAA ;daa -; db 02fh,i_CPL ;cpl -; db 037h,i_SCF ;scf -; db 03fh,i_CCF ;ccf - db 0c9h,i_RET ;ret - db 0ffh - - -; 1 byte opcodes -; Format: db mask, match, t_MNEMONICS-index -; dw argument formating function -b_1ad1_start: - db 0c0h,040h,i_LD ;ld r[y],r[z] - db a_rr - - db 0c0h,080h,i_ADD+080h ;add a,r[z] - db a_r - -; db 0f8h,080h,i_ADD ;add a,r[z] -; db a_ar -; db 0f8h,088h,i_ADC ;adc a,r[z] -; db a_ar -; db 0f8h,090h,i_SUB ;sub r[z] -; db a_r -; db 0f8h,098h,i_SBC ;sbc a,r[z] -; db a_ar -; db 0f8h,0a0h,i_AND ;and r[z] -; db a_r -; db 0f8h,0a8h,i_XOR ;xor r[z] -; db a_r -; db 0f8h,0b0h,i_OR ;or r[z] -; db a_r -; db 0f8h,0b8h,i_CP ;cp r[z] -; db a_r - - db 0c7h,0c0h,i_RET ;ret cc - db a_cc - db 0c7h,0c7h,i_RST ;rst - db a_rst - db 0cfh,0c1h,i_POP ;pop rp2 - db a_p2 - db 0cfh,0c5h,i_PUSH ;push rp2 - db a_p2 - db 0ffh,0e3h,i_EX ;ex (sp),hl - db a_esphl - db 0ffh,0e9h,i_JP ;jp (hl) - db a_hl - db 0ffh,0ebh,i_EX ;ex de,hl - db a_dehl - db 0ffh,0f9h,i_LD ;ld sp,hl - db a_lsphl - db 0cfh,003h,i_INC ;inc rp - db a_p - db 0cfh,00bh,i_DEC ;dec rp - db a_p - db 0c7h,004h,i_INC ;inc r[y] - db a_ry - db 0c7h,005h,i_DEC ;dec r[y] - db a_ry - db 0ffh,008h,i_EX ;ex af,af' - db a_eaf - db 0cfh,009h,i_ADD ;add hl,rp - db a_hlp - db 0efh,002h,i_LD ;ld (rp),a ;rp=bc,de - db a_pa - db 0efh,00ah,i_LD ;ld a,(rp) ;rp=bc,de - db a_ap - - db 0c7h,007h,i_RLCA+080h;rlca - db a_noarg - - db 0 - -; 2 byte opcodes -b_1b54_start: - db 0c7h,006h,i_LD ;ld r[y],nn - db a_rn - - db 0c7h,0c6h,i_ADD+080h ;add a,r[z] - db a_n - -; db 0ffh,0c6h,i_ADD ;add a,nn -; db a_an -; db 0ffh,0ceh,i_ADC ;adc a,nn -; db a_an -; db 0ffh,0d6h,i_SUB ;sub nn -; db a_n -; db 0ffh,0deh,i_SBC ;sbc a,nn -; db a_an -; db 0ffh,0e6h,i_AND ;and nn -; db a_n -; db 0ffh,0eeh,i_XOR ;xor nn -; db a_n -; db 0ffh,0f6h,i_OR ;or nn -; db a_n -; db 0ffh,0feh,i_CP ;cp nn -; db a_n - - db 0ffh,010h,i_DJNZ ;djnz - db a_j - db 0ffh,018h,i_JR ;jr - db a_j - db 0e7h,020h,i_JR ;jr cc, - db a_ccj - db 0ffh,0d3h,i_OUT ;out (nn),a - db a_ma - db 0ffh,0dbh,i_IN ;in a,(nn) - db a_am - db 0 - -; 3 byte opcodes -b_1b9b_start: - db 0c7h,0c2h,i_JP ;jp cc,mn - db a_ccnn - db 0c7h,0c4h,i_CALL ;call cc,mn - db a_ccnn - db 0cfh,001h,i_LD ;ld ww,mn - db a_rnn - db 0ffh,0c3h,i_JP ;jp mn - db a_nn - db 0ffh,0cdh,i_CALL ;call mn - db a_nn - db 0ffh,022h,i_LD ;ld (mn),hl - db a_mmhl - db 0ffh,02ah,i_LD ;ld hl,(mn) - db a_hlmm - db 0ffh,032h,i_LD ;ld (mn),a - db a_mma - db 0ffh,03ah,i_LD ;ld a,(mn) - db a_amm - db 0 - -; Prefix ED + 1 byte opcode, no arguments -; Format: opcode, t_MNEMONICS index -b_1bc9_start: - db 044h,i_NEG ;neg - db 045h,i_RETN ;retn - db 04dh,i_RETI ;reti - db 067h,i_RRD ;rrd - db 06fh,i_RLD ;rld -; db 0a0h,i_LDI ;ldi -; db 0a1h,i_CPI ;cpi -; db 0a2h,i_INI ;ini -; db 0a3h,i_OUTI ;outi -; db 0a8h,i_LDD ;ldd -; db 0a9h,i_CPD ;cpd -; db 0aah,i_IND ;ind -; db 0abh,i_OUTD ;outd -; db 0b0h,i_LDIR ;ldir -; db 0b1h,i_CPIR ;cpir -; db 0b2h,i_INIR ;inir -; db 0b3h,i_OTIR ;otir -; db 0b8h,i_LDDR ;lddr -; db 0b9h,i_CPDR ;cpdr -; db 0bah,i_INDR ;indr -; db 0bbh,i_OTDR ;otdr - db 08bh,i_OTDM ;otdm - db 09bh,i_OTDMR ;otdmr - db 083h,i_OTIM ;otim - db 093h,i_OTIMR ;otimr - db 076h,i_SLP ;slp - db 0ffh ; - -b_1bf4_start: - db 0e4h,0a0h,i_LDI - db a_noarg - db 0ffh,070h,i_IN ;in (c) ; - db a_c - db 0c7h,040h,i_IN ;in r,(c) ;r=b,c,d,e,h,l,a - db a_rc - db 0ffh,071h,0ffh ;out (c),0 ; - db a_cr - db 0c7h,041h,i_OUT ;out (c),r ;r=b,c,d,e,h,l,a - db a_cr - db 0cfh,042h,i_SBC ;sbc hl,rp - db a_hlp - db 0cfh,04ah,i_ADC ;adc hl,rp - db a_hlp - db 0ffh,046h,i_IM ;im 0 - db a_im0 - db 0ffh,056h,i_IM ;im 1 - db a_im1 - db 0ffh,05eh,i_IM ;im 2 - db a_im2 - db 0e7h,047h,i_LD ;ld i,a ... ld a,r - db a_ai - db 0cfh,04ch,i_MLT ;mlt rr - db a_p - db 0c7h,004h,i_TST ;tst r - db a_ry - db 0 +; +; GROUP2, GROUP1 and GROUP3 are instruction decoding tables and have +; the following structure: +; +; [ mask { mode ( match , index ) } 0FFH ] 0. +; +; The repeating group ( match , index ) terminates when the MSB of the +; index byte is set. The interpretation of the "mode" byte is +; explained in the documentation to datasheet OPRNDZ. +; -l228bh: - db 0ffh,030h,i_IN0 ;in0 (m) - db a_m - db 0c7h,000h,i_IN0 ;in0 r,(m) ;r=b,c,d,e,h,l,a - db a_rm - db 0ffh,031h,0ffh ;out0 (m),0 - db a_mr - db 0c7h,001h,i_OUT0 ;out0 (m),r ;r=b,c,d,e - db a_mr - db 0ffh,064h,i_TST ;tst m - db a_n - db 0ffh,074h,i_TSTIO ;tstio m - db a_n - db 0 +; CB group + +GROUP2: + DB 0C0h,036h ;mask, mode + DB 040h,004h ; bit b,g + DB 080h,02Dh ; res b,g + DB 0C0h,0BEh ; set b,g + DB 0FFh ; + DB 0F8h,006h ;mask, mode + DB 000h,033h ; rlc g + DB 008h,038h ; rrc g + DB 010h,035h ; rl g + DB 018h,03Ah ; rr g + DB 020h,03Fh ; sla g + DB 028h,040h ; sra g + DB 030h,000h ;(sll g) + DB 038h,0C1h ; srl g + +; Main group + +GROUP1: + DB 0FFh,000h ;mask, mode + DB 000h,024h ; NOP + DB 007h,032h ; RLCA + DB 00Fh,037h ; RRCA + DB 017h,031h ; RLA + DB 01Fh,036h ; RRA + DB 027h,00Dh ; DAA + DB 02Fh,00Bh ; CPL + DB 037h,03Dh ; SCF + DB 03Fh,006h ; CCF + DB 076h,014h ; HALT + DB 0C9h,030h ; RET + DB 0D9h,012h ; EXX + DB 0F3h,00Fh ; DI + DB 0FBh,091h ; EI + + DB 072h + DB 0C6h,002h + DB 0CEh,001h + DB 0DEh,0BCh + + DB 002h + DB 0D6h,042h + DB 0E6h,003h + DB 0EEh,043h + DB 0F6h,025h + DB 0FEh,08Ch + + DB 004h + DB 008h,093h + + DB 001h + DB 010h,010h + DB 018h,09Dh + + DB 0AFh + DB 022h,0A2h + + DB 0FAh + DB 02Ah,0A2h + + DB 0A7h + DB 032h,0A2h + DB 07Ah + DB 03Ah,0A2h + + DB 003h + DB 0C3h,01Ch + DB 0CDh,085h + + DB 097h + DB 0D3h,0AAh + DB 079h + DB 0DBh,09Bh + DB 05Fh + DB 0E3h,093h + DB 00Eh + DB 0E9h,09Ch + DB 005h + DB 0EBh,093h + DB 0DFh + DB 0F9h,0A2h + DB 0FFh + + DB 0C0h + DB 0B6h, + DB 040h,0A2h + DB 0FFh + + DB 0F8h + DB 076h, + DB 080h,002h + DB 088h,001h + DB 098h,0BCh + + DB 006h + DB 090h,042h + DB 0A0h,003h + DB 0A8h,043h + DB 0B0h,025h + DB 0B8h,08Ch + DB 0FFh + + DB 0C7h + DB 00Bh + DB 004h,016h + DB 005h,08Eh + DB 0B2h, + DB 006h,0A2h + DB 020h + DB 0C0h,0B0h + DB 023h + DB 0C2h,01Ch + DB 0C4h,085h + DB 010h + DB 0C7h,0BBh + DB 0FFh + + DB 0CFh + DB 0D3h + DB 001h,0A2h + DB 00Dh + DB 003h,016h + DB 00Bh,08Eh + DB 0FDh + DB 009h,082h + DB 060h + DB 0C1h,02Bh + DB 0C5h,0ACh + DB 0FFh + + DB 0E7h + DB 021h + DB 020h,09Dh + DB 0FFh + + DB 0EFh + DB 0E7h + DB 002h,0A2h + DB 07Eh + DB 00Ah,0A2h + +; ED group + +GROUP3: + DB 0FFh,000h ; + DB 044h,023h ;NEG + DB 045h,02Fh ;RETN + DB 04Dh,02Eh ;RETI + DB 04Eh,000h ;(IM 0) + DB 067h,039h ;RRD + DB 06Fh,034h ;RLD +; DB 070h,000h ;(IN (C)) + DB 071h,000h ;(OUT (C),0) + DB 0A0h,021h ;LDI + DB 0A1h,00Ah ;CPI + DB 0A2h,01Ah ;INI + DB 0A3h,029h ;OUTI + DB 0A8h,01Fh ;LDD + DB 0A9h,008h ;CPD + DB 0AAh,018h ;IND + DB 0ABh,028h ;OUTD + DB 0B0h,020h ;LDIR + DB 0B1h,009h ;CPIR + DB 0B2h,019h ;INIR + DB 0B3h,027h ;OTIR + DB 0B8h,01Eh ;LDDR + DB 0B9h,007h ;CPDR + DB 0BAh,017h ;INDR + DB 0BBh,0A6h ;OTDR + DB 0FFh + + DB 0FFh + DB 080h + DB 070h,09Bh ;IN (C) + DB 0FFh + + DB 0C7h + DB 0B8h + DB 040h,09Bh ;IN r,(C) + DB 08Bh ; + DB 041h,0AAh ;OUT (C),r + DB 0FFh ; + ; + DB 0CFh ; + DB 0FDh ; + DB 042h,03Ch ;sbc hl,rp + DB 04Ah,081h ;adc hl,rp + DB 0ADh ; + DB 043h,0A2h ;LD (nn),rp + DB 0DAh ; + DB 04Bh,0A2h ;LD rp,(nn) + DB 0FFh ; + ; + DB 0E7h ; + DB 040h ; + DB 046h,095h ;IM x + DB 0FFh ; + ; + DB 0F7h ; + DB 0C7h ; + DB 047h,0A2h ;LD i|r,A + DB 07Ch ; + DB 057h,0A2h ;LD A,i|r + DB 0FFh + DB 000h + +;_______________ + +MONICS: + DC 0BFh ; 0 ? + DC 'ADC' ; 1 ADC + DC 'ADD' ; 2 ADD + DC 'AND' ; 3 AND + DC 'BIT' ; 4 BIT + DC 'CALL' ; 5 CALL + DC 'CCF' ; 6 CCF + DC 'CPDR' ; 7 CPDR + DC 'CPD' ; 8 CPD + DC 'CPIR' ; 9 CPIR + DC 'CPI' ;10 CPI + DC 'CPL' ;11 CPL + DC 'CP' ;12 CP + DC 'DAA' ;13 DAA + DC 'DEC' ;14 DEC + DC 'DI' ;15 DI + DC 'DJNZ' ;16 DJNZ + DC 'EI' ;17 EI + DC 'EXX' ;18 EXX + DC 'EX' ;19 EX + DC 'HALT' ;20 HALT + DC 'IM' ;21 IM + DC 'INC' ;22 INC + DC 'INDR' ;23 INDR + DC 'IND' ;24 IND + DC 'INIR' ;25 INIR + DC 'INI' ;26 INI + DC 'IN' ;27 IN + DC 'JP' ;28 JP + DC 'JR' ;29 JR + DC 'LDDR' ;30 LDDR + DC 'LDD' ;31 LDD + DC 'LDIR' ;32 LDIR + DC 'LDI' ;33 LDI + DC 'LD' ;34 LD + DC 'NEG' ;35 NEG + DC 'NOP' ;36 NOP + DC 'OR' ;37 OR + DC 'OTDR' ;38 OTDR + DC 'OTIR' ;39 OTIR + DC 'OUTD' ;40 OUTD + DC 'OUTI' ;41 OUTI + DC 'OUT' ;42 OUT + DC 'POP' ;43 POP + DC 'PUSH' ;44 PUSH + DC 'RES' ;45 RES + DC 'RETI' ;46 RETI + DC 'RETN' ;47 RETN + DC 'RET' ;48 RET + DC 'RLA' ;49 RLA + DC 'RLCA' ;50 RLCA + DC 'RLC' ;51 RLC + DC 'RLD' ;52 RLD + DC 'RL' ;53 RL + DC 'RRA' ;54 RRA + DC 'RRCA' ;55 RA + DC 'RRC' ;56 RRC + DC 'RRD' ;57 RRD + DC 'RR' ;58 RR + DC 'RST' ;59 RST + DC 'SBC' ;60 SBC + DC 'SCF' ;61 SCF + DC 'SET' ;62 SET + DC 'SLA' ;63 SLA + DC 'SRA' ;64 SRA + DC 'SRL' ;65 SRL + DC 'SUB' ;66 SUB + DC 'XOR' ;67 XOR +;Z180 + DC 'IN0' ;68 IN0 + DC 'MLP' ;69 MLP + DC 'OTDM' ;70 OTDM + DC 'OTDMR' ;71 OTDMR + DC 'OTIM' ;72 OTIM + DC 'OTIMR' ;73 OTIMR + DC 'OUT0' ;74 OUT0 + DC 'SLP' ;75 SLP + DC 'TST' ;76 TST + DC 'TSTIO' ;77 TSTIO -; Prefix ED + 1 byte opcode + 2 byte address -; Format: db mask, match, t_MNEMONICS-index -; dw argument formating function -b_1c40_start: - db 0cfh,043h,i_LD ;ld (mn),ww ;ww=bc,de,hl,sp - db a_mmp - db 0cfh,04bh,i_LD ;ld ww,(mn) ;ww=bc,de,hl,sp - db a_pmm - db 0 - -; CB -b_1c55_start: - db 0c0h,000h,i_RLC+080h ;rlc g - db a_cbr - -; db 0f8h,000h,i_RLC ;rlc g -; db a_cbr -; db 0f8h,008h,i_RRC ;rrc g -; db a_cbr -; db 0f8h,010h,i_RL ;rl g -; db a_cbr -; db 0f8h,018h,i_RR ;rr g -; db a_cbr -; db 0f8h,020h,i_SLA ;sla g -; db a_cbr -; db 0f8h,028h,i_SRA ;sra g -; db a_cbr -; db 0f8h,038h,i_SRL ;srl g -; db a_cbr - db 0c0h,040h,i_BIT ;bit b,g - db a_bcbr - db 0c0h,080h,i_RES ;res b,g - db a_bcbr - db 0c0h,0c0h,i_SET ;set b,g - db a_bcbr - db 0 ;------------------------------------------------------------------------------- -;------------------------------------------------------------------------------- - - -pr_instr_args: - ld hl,t_argf - ld d,0 - add hl,de -pria_l: - ld a,(hl) ;get next token - inc hl - or a - ret z ; - jp m,pria_1 - call outchar ;print as normal character - jr pria_l - -pria_1: ; - push hl - ld hl,do_arg_n - and 07fh - call add_hl_a2 - ld a,(hl) - inc hl - ld h,(hl) - ld l,a - ld a,(iy+000h) - call CALL_HL - pop hl - jr pria_l - ; -; http://www.z80.info/decoding.htm +; Disassemble and output Z80 machine code operand +; +; Index OPRND1 OPRND2 +; ----------------------------------------------------------- +; 1 RST address Relative address +; 2 Condition Immediate byte +; 3 Bit number Immediate word +; 4 Interrupt mode AF,AF' +; 5 (SP) DE,HL +; 6 Register pair 8-bit source +; ----------------------------------------------------------- +; 7 A +; 8 (C) +; 9 (port number) +; A (Absolute address) +; B 8-bit destination +; C I or R +; D 16-bit register +; E Address in 16-bit register +; F Index register +; +; Input: +; A: opcode +; B: operand index +; DE: Address of next instruction byte +; HL: Address of next free byte in output buffer +; (iy+1): index register flag (1=IX, 2=IY, else 0) +; (iy+2): displacement for any indexed instruction +; (iy+3): no. of instraction bytes fetched +; +; Output: +; Operand in output buffer +; DE, HL updated +; AF, BC destroyed ; -; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -; | x | y | z | -; | p | q | ; - -t_argf: -; 1 byte opcodes -a_rr equ $-t_argf - db fi_ry,',' ;ld r[y],r[z] -a_r equ $-t_argf - db fi_rz,0 ;op r[z] -;a_ar equ $-t_argf -; db 'A,',fi_rz,0 ;op A,r[z] -a_cc equ $-t_argf - db fi_ccy,0 ;op cc[y] -a_rst equ $-t_argf - db fi_rst,0 ;rst y*8 -a_p2 equ $-t_argf - db fi_rp2,0 ;rp2[p] -a_esphl equ $-t_argf - db '(SP),',fi_hlixiy,0 ;ex (sp),hl -a_hl equ $-t_argf - db '(',fi_hlixiy,')',0 ;jp (hl) -a_dehl equ $-t_argf - db 'DE,HL',0 -a_lsphl equ $-t_argf - db 'SP,',fi_hlixiy,0 ;ld SP,HL -a_eaf equ $-t_argf - db 'AF,AF''',0 ;ex af,af' -a_hlp equ $-t_argf - db fi_hlixiy,',' ;add hl,rp -a_p equ $-t_argf - db fi_rp,0 ;rp[p] -a_pa equ $-t_argf - db '(',fi_rp,'),A',0 ;ld (rp),a ;rp=bc,de -a_ap equ $-t_argf - db 'A,(',fi_rp,')',0 ;ld a,(rp) ;rp=bc,de - -; 2 byte opcodes -a_rn equ $-t_argf - db fi_ry,',',fi_n,0 ;ld r[y],n -;a_an equ $-t_argf -; db 'A,' ;op a,n -a_n equ $-t_argf - db fi_n,0 ;op n -a_ccj equ $-t_argf - db fi_ccy2,',' ;jr cc,j ;cc = nz,z,nc,c -a_j equ $-t_argf - db fi_j,0 ;jr j -a_ma equ $-t_argf - db '(',fi_n,'),A',0 ;out (n),a -a_am equ $-t_argf - db 'A,(',fi_n,')',0 ;in a,(n) - -; 3 byte opcodes -a_ccnn equ $-t_argf - db fi_ccy,',',fi_nn,0 ;op cc[y],nn -a_rnn equ $-t_argf - db fi_rp,',' ;ld rp[p],nn -a_nn equ $-t_argf - db fi_nn,0 ;jp nn -a_mmhl equ $-t_argf - db '(',fi_nn,'),',fi_hlixiy,0 ;ld (nn),hl -a_hlmm equ $-t_argf - db fi_hlixiy,',(',fi_nn,')',0 ;ld hl,(nn) -a_mma equ $-t_argf - db '(',fi_nn,'),A',0 ;ld (nn),a -a_amm equ $-t_argf - db 'A,(',fi_nn,')',0 ;ld a,(nn) - -; Prefix ED + 1 byte opcode -a_rc equ $-t_argf - db fi_ry,',' ;in r[y],(c) -a_c equ $-t_argf - db '(C)',0 ;in (c) -a_cr equ $-t_argf - db '(C),' ;out (c),r[y] -a_ry equ $-t_argf - db fi_ry,0 ;inc r[y] -a_im0 equ $-t_argf - db '0',0 ;im 0 -a_im1 equ $-t_argf - db '1',0 ;im 1 -a_im2 equ $-t_argf - db '2',0 ;im 2 -a_ai equ $-t_argf - db fi_ir,0 ;ld a,i ... r,a - -; Prefix ED + 2 byte (opcode + immediate) -a_rm equ $-t_argf - db fi_ry,',' ;in0 r[y],(n) -a_m equ $-t_argf - db '(',fi_n,')',0 ;in0 (n) -a_mr equ $-t_argf - db '(',fi_n,'),',fi_ry,0 ;out0 (n),r[y] - -; Prefix ED + 3 byte (opcode + address) -a_mmp equ $-t_argf - db '(',fi_nn,'),',fi_rp,0 ;ld (nn),rp -a_pmm equ $-t_argf - db fi_rp,',(',fi_nn,')',0 ;ld rp,(nn) - -; Prefix CB + 1 byte opcode -a_bcbr equ $-t_argf - db fi_y,',' ;op y,r[z] -a_cbr equ $-t_argf - db fi_rz_cb,0 ;op r[z] -a_noarg equ $-t_argf - db 0 - - ;------------------------------------------------------------------------------- -argpf_index defl 0 - -argpf macro x -fi_&x equ 80h+argpf_index - dw p_&x -argpf_index defl argpf_index+1 - endm - -do_arg_n: - argpf ry - argpf rz - argpf ccy - argpf ccy2 - argpf rst - argpf rp - argpf rp2 - argpf hlixiy - argpf n - argpf j - argpf nn - argpf ir - argpf rz_cb - argpf y - - -p_n: - ld a,(isprefix_ixiy) - and a - ld a,(iy+001h) - jr z,out_hex_0 - ld a,(iy+002h) - jr out_hex_0 +RGSTRS: + DC 'B' ; 0 + DC 'C' ; + DC 'D' ; + DC 'E' ; + DC 'H' ; + DC 'L' ; + DC '(C)' ; 6 + DC 'A' ; + DC 'I' ; 8 + DC 'R' ; + DC 'AF,AF''' ;10 + DC 'DE,HL' ; + DC 'BC' ;12 + DC 'DE' ; + DC 'AF' ; + DC 'SP' ; + DC 'HL' ;16 + DC 'IX' ; + DC 'IY' ; + DC '(SP)' ;19 + DC 'NZ' ;20 + DC 'Z' ; + DC 'NC' ; + DC 'C' ; + DC 'PO' ; + DC 'PE' ; + DC 'P' ; + DC 'M' ; + DC '0' ;28 + DC '?' ; + DC '1' ; + DC '2' ; + +;------------------------------------------------------------------------------- + +OPRND1: ;First enty point + DJNZ CONDIT ;1? +;RSTADR: ;Op1 i1: Mode is RST address + AND 038h ; + JR DA + +OPRND2: + DJNZ DAT8 ;1? +;RELADR: + CALL FETCH + LD C,A + RLA + SBC A,A + LD B,A + EX DE,HL + PUSH HL + ADD HL,BC + JR DHL + +CONDIT: + RRA + RRA + RRA + DJNZ BITNUM ;2? + ;Op1 i2: Condition + BIT 4,A + JR NZ,ABS + AND 3 +ABS: + AND 7 + ADD A,20 + JR PS1 + +DAT8: + DJNZ DAT16 +D8: + CALL FETCH +DA: + EX DE,HL + call conv_hex + EX DE,HL + RET + +BITNUM: + DJNZ INTMOD ;3? + AND 7 + EX DE,HL + call conv_dgt + EX DE,HL + RET + +DAT16: + DJNZ EXAF +D16: + CALL FETCH + LD C,A + CALL FETCH +;DAC: + EX DE,HL + PUSH HL + LD H,A + LD L,C + +DHL: + CALL conv_hl + POP HL + EX DE,HL + RET + + +INTMOD: + DJNZ STKTOP ;4? + AND 3 + ADD A,28 +PS1: + JR PS3 + +STKTOP: + LD C,19 + DEC B + JR Z,PS2 + +;REG16P: + DJNZ COMMON ;5? + RRA + AND 3 + CP 3 + JR NZ,RX + + DEC A + JR RNX + +EXAF: + LD C,10 + DEC B + JR Z,PS2 + +;EXDE: + INC C + DEC B + JR Z,PS2 + +;REG8S: + DJNZ ACCUM + +R8: + AND 7 + CP 6 + JR NZ,PS3 + + LD (HL),'(' + INC HL + CALL REGX + LD A,(iy+1) + OR A + JR Z,RP + LD A,(iy+2) + LD (HL),'+' + RLCA + RRCA + JR NC,POS + LD (HL),'-' + NEG +POS: + INC HL + call DA + JR RP + +ACCUM: + RRA + RRA + RRA +COMMON: + LD C,7 + DEC B ;6? + JR Z,PS2 +;PORTC: + DEC C + DJNZ IDAT8 ;7? +PS2: + LD A,C +PS3: + JR PS4 + +IDAT8: + DJNZ IDAT16 ;8? + LD (HL),'(' + INC HL + CALL D8 + JR RP -p_rst: - and 038h -out_hex_0: - jp out_hex +IDAT16: + DJNZ REG8 ;9? + LD (HL),'(' + INC HL + CALL D16 + JR RP + +REG8: + DEC B ;A? + JR Z,R8 + +;IPAREF: + DJNZ REG16 ;B? + AND 9 + JR PS4 + +REG16: + RRA + DJNZ IREG16 ;C? + +R16: + AND 3 +RX: + CP 2 + JR Z,REGX + +RNX: + ADD A,12 + JR PS4 + +IREG16: + DJNZ REGX ;D? + LD (HL),'(' + INC HL + CALL R16 +RP: + LD (HL),')' + INC HL + RET +REGX: + LD A,(iy+1) + ADD A,16 +PS4: + EX DE,HL + PUSH HL + LD HL,RGSTRS + CALL XTRACT + POP HL + EX DE,HL + RET -p_j: - ld c,(iy+001h) - ld a,c - rla - sbc a,a - ld b,a - push iy - pop hl - add hl,bc - inc hl - inc hl - jr out_hl_0 - -p_nn: - ld l,(iy+001h) - ld h,(iy+002h) -out_hl_0: - jp out_hl +;------------------------------------------------------------------------------- -p_ir: +conv_hl: + ld a,h + call conv_hex + ld a,l +conv_hex: + push af + rra rra rra rra - and 03 - ld hl,t_arg_IR - jr p_arg + call conv_dgt + pop af +conv_dgt: + or 0f0h + daa + add a,0a0h + adc a,040h + LD (DE),A + INC DE + ret +;------------------------------------------------------------------------------- -get_cb_opc: - ld a,(isprefix_ixiy) - and a - ld a,(iy+001h) - ret z - ld a,(iy+002h) - ret +XTRACT: + OR A + JR Z,COPY +SKIP: + BIT 7,(HL) + INC HL + JR Z,SKIP -p_y: - call get_cb_opc - rra - rra - rra - and 007h - jp out_dgt + DEC A + JR NZ,SKIP +COPY: + LD A,(HL) + RLCA + SRL A + LD (DE),A + INC DE + INC HL + JR NC,COPY + RET -p_rz_cb: - call get_cb_opc - jr p_rz +;------------------------------------------------------------------------------- -p_ry: - rra - rra - rra -p_rz: - and 007h - cp 006h - ld b,a - ld hl,t_arg_r - jr nz,p_arg0 - ld a,(isprefix_ixiy) - and a - jr z,p_arg0 - ld hl,t_lp_IXIY - dec a - call p_arg - ld a,(iy+001h) - push af - rlca - ld a,'+' - jr nc,l1e61h - pop af - neg - push af - ld a,'-' -l1e61h: - call outchar - pop af - call out_hex - ld a,')' - jp outchar +FETCH: + INC (iy+3) + LD A,(DE) + INC DE + RET -p_rp2: - ld hl,t_arg_rp2 - db 0ddh ;swallow t_arg_rp in ix -p_rp: - ld hl,t_arg_rp - rra - rra - rra - rra - and 003h - cp 002h - jr nz,p_arg -p_hlixiy: - ld a,(isprefix_ixiy) - ld hl,t_HL.IX.IY - jr p_arg - -p_ccy2: - and 018h -p_ccy: - rra - rra - rra - and 007h - ld hl,t_arg_cc -p_arg: - ld b,a -p_arg0: - ;fall thru +;------------------------------------------------------------------------------- pstr_sel: call str_sel @@ -3611,167 +3593,12 @@ pstr_inl: ;------------------------------------------------------------------------------- -opc macro x - -i_&x equ opc_index -;o_&x equ $-opc_tabstart - dc '&x' -opc_index defl opc_index+1 - endm - -t_MNEMONICS: -;opc_tabstart defl $ -opc_index defl 0 -; 1-byte other - opc NOP - opc LD - opc INC - opc DEC - opc DJNZ - opc JR - opc HALT - - opc RLCA - opc RRCA - opc RLA - opc RRA - opc DAA - opc CPL - opc SCF - opc CCF - -; 1-byte "alu" - opc ADD - opc ADC - opc SUB - opc SBC - opc AND - opc XOR - opc OR - opc CP - - opc RET - opc POP - opc JP - opc CALL - opc PUSH - opc RST - opc OUT - opc EXX - opc IN - opc EX - opc DI - opc EI -; CB - opc RLC - opc RRC - opc RL - opc RR - opc SLA - opc SRA - opc SLL - opc SRL - opc BIT - opc RES - opc SET - -; ED - opc NEG - opc RETN - opc RETI - opc IM - opc RRD - opc RLD - -; Block instructions - opc LDI - opc CPI - opc INI - opc OUTI - opc LDD - opc CPD - opc IND - opc OUTD - opc LDIR - opc CPIR - opc INIR - opc OTIR - opc LDDR - opc CPDR - opc INDR - opc OTDR - -; Z180 - opc IN0 - opc OUT0 - opc TST - opc MLT - opc TSTIO - opc SLP - opc OTIM - opc OTDM - opc OTIMR - opc OTDMR - - DB 0 - -t_arg_r: - DC 'B' - DC 'C' - DC 'D' - DC 'E' - DC 'H' - DC 'L' - DC '(HL)' - DC 'A' - DB 0 -t_arg_rp: - DC 'BC' - DC 'DE' - DC 'HL' - DC 'SP' - DB 0 -t_arg_rp2: - DC 'BC' - DC 'DE' - DC 'HL' - DC 'AF' - DB 0 -t_HL.IX.IY: - DC 'HL' - DC 'IX' - DC 'IY' - DB 0 -t_arg_cc: - DC 'NZ' - DC 'Z' - DC 'NC' - DC 'C' - DC 'PO' - DC 'PE' - DC 'P' - DC 'M' - DB 0 - -t_lp_IXIY: - DC '(IX' - DC '(IY' - -t_arg_IR: - DC 'I,A' - DC 'R,A' - DC 'A,I' - DC 'A,R' - db 0 - -;------------------------------------------------------------------------------- - lookup_branch_op: ld a,(hl) and a ret z inc hl - and (iy+000h) + and b cp (hl) inc hl ld e,(hl) @@ -3794,15 +3621,14 @@ tc_set_bp: sbc hl,de ld hl,l20edh ;set break after BDOS call jr z,l2031h - ld iy,(reg.pc) - call disas_get_instrlen + ld de,(reg.pc) + call dis_decode jp nc,ERROR - ld c,b - ld b,0 - ld hl,(reg.pc) - add hl,bc + ex de,hl call bp_trace_enter ld iy,(reg.pc) + ld b,(iy+0) + ld c,(iy+1) ld hl,t_op_branch call lookup_branch_op ccf @@ -3855,14 +3681,13 @@ l2080h: ; jp mn jp cc,mn l208bh: - ld l,(iy+001h) + ld l,c ld h,(iy+002h) scf ret ;jr, djnz l2093h: - ld c,(iy+001h) ld a,c rla sbc a,a @@ -3888,7 +3713,7 @@ l20a7h: l20ach: ld hl,(reg.iy) l20afh: - ld a,(iy+001h) + ld a,c cp 0e9h ; jp (ix); jp (iy) scf ret z @@ -3897,7 +3722,7 @@ l20afh: ; Prefix ED l20b8h: - ld a,(iy+001h) + ld a,c cp 04dh ; reti jr z,l20dch cp 045h ; retn @@ -3907,7 +3732,7 @@ l20b8h: ;ret cc l20c5h: - ld a,(iy+000h) + ld a,b ld (l20d7h),a ld hl,(reg.f) push hl @@ -3940,9 +3765,9 @@ l2115h: ;rst n l20f9h: ld a,(l0003h) - cp (iy+000h) + cp b ret z - ld a,(iy+000h) + ld a,b and 038h ld l,a ld h,000h @@ -4024,8 +3849,6 @@ high_load: max_load: dw TPA -isprefix_ixiy: - db 0 last_L: dw TPA @@ -4040,6 +3863,8 @@ bitmap_end: conbuf: ds CONBUF_SIZE+1 +disasbuf equ conbuf+1 + ;------------------------------------------------------------------------------- rept (STACK_SIZE+3)/4 -- cgit v1.2.3