home *** CD-ROM | disk | FTP | other *** search
- \ DISEVM.SEQ 6805 EVM Disassembler by Andrew McKewan
-
- \ From DIS8086 by Charles Curley
- \ Prefix conversion by Bill Muench 9 September 88
- \ conversion to TCOM and symbolic additions by Tom Zimmer 03/07/90
- \ conversion to 6805 by Andrew McKewan 12/17/90
-
-
- ONLY FORTH ALSO DEFINITIONS
-
- : .ID| ( nfa -- ) \ Display name without trailing space
- DUP 1+ DUP YC@ ROT YC@ 31 AND 0
- ?DO DUP 127 AND FEMIT 128 AND
- IF ASCII _ 128 OR ELSE 1+ DUP YC@ THEN
- LOOP 2DROP ;
-
- : .ID|N ( nfa n -- ) \ Display name max n characters
- >r DUP 1+ DUP YC@ ROT YC@ 31 AND r> min 0
- ?DO DUP 127 AND FEMIT 128 AND
- IF ASCII _ 128 OR ELSE 1+ DUP YC@ THEN
- LOOP 2DROP ;
-
- : COL ( n ) #OUT @ - SPACES ;
-
- VOCABULARY DISASSEMBLER DISASSEMBLER DEFINITIONS
-
- DEFER TC@ ' C@ IS TC@ \ fetch target memory byte
- DEFER T@ ' @ IS T@ \ fetch target memory word
-
- DEFER ?SYMBOL ( adr -- nfa t | f ) \ find symbol
-
- : no drop false ; ' no is ?symbol
-
- : .symbol ( a1 -- ) \ display symbol or address
- dup ?symbol
- if .id|
- ." [" 0 .r ." ]"
- else 0 u.r
- then ;
-
- : nextb ( a1 -- a2 n ) dup 1+ swap tc@ ;
- : nextw ( a1 -- a2 w ) dup 2+ swap t@ ;
-
- : bit# ( opcode -- bit# ) 2/ 7 and ;
- : b>w ( byte -- n ) dup 128 and if 256 - then ;
-
- comment:
- \ disassembly format:
- \ 1 2 3 4
- \ 01234567890123456789012345678901234567890123456789
- \ AAAA LABEL OPC OPERAND OBJECT
-
- : column ( col ) create , does> @ col ; \ modify with =:
-
- 0 column >address \ column for address display
- 6 column >label \ column for label display
- 18 column >opcode \ column for opcode display
- 24 column >operand \ column for operand display
- 40 column >object \ column for object code display
-
-
- : .address ( adr -- )
- >address
- 0 <# # # # # #> type ;
-
- : .label ( adr -- )
- >label
- ?symbol
- if 10 .id|n
- then ;
-
- : .object ( end start -- )
- >object
- ?do i tc@ 0 <# # # #> type
- loop ;
- comment;
-
-
- 6 value opwid \ width of opcode field
- 0 value out0 \ #out at beginning of opcode
-
- : >op \ go to operand field
- out0 opwid + #out @ - spaces ;
-
- : .SELF ( Self-doc! )
- CREATE DOES> COUNT TYPE ;
-
- .self ??? ," ???"
-
- .self NEG ," NEG" .self COM ," COM" .self LSR ," LSR"
- .self ROR ," ROR" .self ASR ," ASR" .self LSL ," LSL"
- .self ROL ," ROL" .self DEC ," DEC" .self INC ," INC"
- .self TST ," TST" .self CLR ," CLR" .self SUB ," SUB"
- .self CMP ," CMP" .self SBC ," SBC" .self CPX ," CPX"
- .self UND ," AND" .self BIT ," BIT" .self LDA ," LDA"
- .self STA ," STA" .self EOR ," EOR" .self ADC ," ADC"
- .self ORA ," ORA" .self ADD ," ADD" .self JMP ," JMP"
- .self JSR ," JSR" .self LDX ," LDX" .self STX ," STX"
-
- .self BRA ," BRA" .self BRN ," BRN" .self BHI ," BHI"
- .self BLS ," BLS" .self BCC ," BCC" .self BCS ," BCS"
- .self BNE ," BNE" .self BEQ ," BEQ" .self BHCC ," BHCC"
- .self BHCS ," BHCS" .self BPL ," BPL" .self BMI ," BMI"
- .self BMC ," BMC" .self BMS ," BMS" .self BIL ," BIL"
- .self BIH ," BIH"
-
- \ Address Modes
-
- : dir ( a1 -- a2 ) nextb .symbol ;
- : ext ( a1 -- a2 ) nextw .symbol ;
- : imm ( a1 -- a2 ) ." #" dir ;
- : ix ( a1 -- a2 ) ." ,X" ;
- : ix1 ( a1 -- a2 ) dir ." ,X" ;
- : ix2 ( a1 -- a2 ) ext ." ,X" ;
- : rel ( a1 -- a2 ) nextb b>w over + .symbol ;
- : bsc ( a1 op -- a2 ) bit# 0 .r ." ," dir ;
- : btb ( a1 op -- a2 ) bsc ." ," rel ;
- : inha ( -- ) ." A" ;
- : inhx ( -- ) ." X" ;
-
- \ Opcode Types
-
- : .brset ( a1 opcode -- a2 )
- dup 1 and if ." BRCLR" else ." BRSET" then >op btb ;
-
-
- : .bset ( a1 opcode -- a2 )
- dup 1 and if ." BCLR" else ." BSET" then >op bsc ;
-
-
- : .bop ( opcode -- )
- 15 and exec: bra brn bhi bls bcc bcs bne beq
- bhcc bhcs bpl bmi bmc bms bil bih ;
-
- : .bran ( a1 opcode -- a2 )
- .bop >op rel ;
-
-
- : op1 ( opcode -- )
- 15 and exec: sub cmp sbc cpx und bit lda sta
- eor adc ora add jmp jsr ldx stx ;
-
- : mode1 ( a1 mode -- a2 )
- 10 - 5 min exec: imm dir ext ix2 ix1 ix ;
-
- : arith ( a1 opcode mode -- a2 )
- over $ad = if 2drop ." BSR" >op rel exit then
- swap op1 >op mode1 ;
-
-
- : op2 ( opcode -- )
- 15 and exec: neg ??? ??? com lsr ??? ror asr
- lsl rol dec ??? inc tst ??? clr ;
-
- : mode2 ( a1 mode -- a2 )
- 3 - 4 min
- dup 1 2 between ( inherant ) not if >op then
- exec: dir inha inhx ix1 ix ;
-
- : rmw ( a1 opcode mode -- a2 )
- over $42 = if ." MUL" 2drop exit then
- swap op2 mode2 ;
-
-
- : misc ( opcode -- )
- case
- $80 of ." RTI" endof $81 of ." RTS" endof
- $83 of ." SWI" endof $8e of ." STOP" endof
- $8f of ." WAIT" endof $97 of ." TAX" endof
- $98 of ." CLC" endof $99 of ." SEC" endof
- $9a of ." CLI" endof $9b of ." SEI" endof
- $9c of ." RSP" endof $9d of ." NOP" endof
- $9f of ." TXA" endof
- ??? drop endcase ;
-
-
- : .inst ( a1 opcode -- a2 ) \ Display one instruction
- dup 16 /
- dup 0= if drop .brset exit then
- dup 1 = if drop .bset exit then
- dup 2 = if drop .bran exit then
- dup 3 7 between if rmw exit then
- dup 8 9 between if drop misc exit then
- arith ;
-
-
- ONLY FORTH ALSO DEFINITIONS
-
- : INST ( a1 -- a2 ) \ display opcode, advancing address as needed
- [ disassembler ]
- #out @ =: out0
- nextb .inst ;
-
- : DIS ( a n -- )
- 0 ?do cr inst loop drop ;
-
-
-
-