2 ; Ullrich von Bassewitz, 07.08.1998
4 ; unsigned DbgDisAsm (char* buf, unsigned addr);
5 ; unsigned DbgDisAsm (unsigned addr);
8 ; Part of this code is taken from the Plus/4 machine language monitor
13 .import __hextab, OffsetTab, AdrFlagTab
14 .import SymbolTab1, SymbolTab2, MnemoTab1, MnemoTab2
18 ; -------------------------------------------------------------------------
19 ; Equates for better readability
21 .importzp sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3
23 BufIndex = tmp1 ; Index into output buffer
24 OperandLen = tmp2 ; Length of operand
25 BufLen = tmp3 ; Length of output buffer
26 AdrFlagBuf = tmp4 ; Flag for addressing mode
27 YSave = sreg ; Temp storage
29 BufPtr = ptr1 ; Pointer to output buffer
30 MemPtr = ptr2 ; Pointer to memory to disassemble
31 MnemoBuf = ptr3 ; Buffer for decoding mnemonic
34 ; -------------------------------------------------------------------------
37 .export _DbgDisAsm, _DbgDisAsmLen
40 sta BufLen ; Save the buffer length
41 jsr popax ; Get the buffer pointer
44 jsr popax ; Get the address
48 sta BufIndex ; Initialize index into buffer
49 jsr DisAssLine ; Disassemble one line into the buffer
51 lda BufLen ; Get requested length
57 lda #$20 ; Get a space
62 L2: lda #0 ; Add C string terminator
70 sta MemPtr ; Save address
73 lda (MemPtr),y ; Get the opcode from memory...
74 jsr AnalyzeOPCode ; ...and analyze it
76 ldx OperandLen ; Get length of operand
77 inx ; Adjust for opcode byte
79 ldx #$00 ; Clear high byte
82 ; -------------------------------------------------------------------------
94 ldy BufIndex ; Get current line pointer
95 cpy BufLen ; Be sure not to overflow the buffer
97 sta (BufPtr),y ; store character
100 PC9: ldy YSave ; get old value
103 ; Print the 16 bit hex value in X/Y
110 ; Print 8 bit value in A, save X and Y
136 ; -------------------------------------------------------------------------
137 ; Disassemble one line
142 jsr PutHex16 ; Print the address
143 jsr Put2Spaces ; Add some space
145 lda (MemPtr),y ; Get the opcode from memory...
146 jsr AnalyzeOPCode ; ...and analyze it
148 ldx OperandLen ; Number of bytes
150 ; Print the bytes that make up the instruction
154 bpl L208C ; Print the instruction bytes
155 jsr Put3Spaces ; If none left, print spaces instead
157 L208C: lda (MemPtr),y ; Get a byte from memory
158 jsr PutHex8 ; ...and print it
159 jsr PutSpace ; Add some space
161 L2094: iny ; Next one...
162 cpy #$03 ; Maximum is three
165 jsr Put2Spaces ; Add some space after bytes
167 ; Print the assembler mnemonic
169 pla ; Get mnemonic code
171 jsr PutMnemo ; Print the mnemonic
181 L20AC: lda AdrFlagBuf
183 lda (MemPtr),y ; Get branch offset
184 bcs GetBranchAdr ; If branch: Calculate address
185 jsr PutHex8 ; Otherwise print 8bit value
189 L20BA: asl AdrFlagBuf
201 ; If the instruction is a branch, calculate the absolute address of the
202 ; branch target and print it.
211 jmp PutHex16 ; Output address
222 ; -------------------------------------------------------------------------
223 ; Subroutine to analyze an opcode byte in A. Will return a byte that
224 ; encodes the mnemonic, and will set the number of bytes needed for this
225 ; instruction in OperandLen
274 ; -------------------------------------------------------------------------
275 ; Print the mnemonic with code in A (that code was returned by
285 ldy #$05 ; 3*5 bits in two bytes
286 L213E: asl MnemoBuf+1