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 jmp utsta0 ; Set condition codes
81 ; -------------------------------------------------------------------------
93 ldy BufIndex ; Get current line pointer
94 cpy BufLen ; Be sure not to overflow the buffer
96 sta (BufPtr),y ; store character
99 PC9: ldy YSave ; get old value
102 ; Print the 16 bit hex value in X/Y
109 ; Print 8 bit value in A, save X and Y
135 ; -------------------------------------------------------------------------
136 ; Eine Zeile disassemblieren
141 jsr PutHex16 ; Print the address
142 jsr Put2Spaces ; Add some space
144 lda (MemPtr),y ; Get the opcode from memory...
145 jsr AnalyzeOPCode ; ...and analyze it
147 ldx OperandLen ; Number of bytes
149 ; Print the bytes that make up the instruction
153 bpl L208C ; Print the instruction bytes
154 jsr Put3Spaces ; If none left, print spaces instead
156 L208C: lda (MemPtr),y ; Get a byte from memory
157 jsr PutHex8 ; ...and print it
158 jsr PutSpace ; Add some space
160 L2094: iny ; Next one...
161 cpy #$03 ; Maximum is three
164 jsr Put2Spaces ; Add some space after bytes
166 ; Print the assembler mnemonic
168 pla ; Get mnemonic code
170 jsr PutMnemo ; Print the mnemonic
180 L20AC: lda AdrFlagBuf
182 lda (MemPtr),y ; Get branch offset
183 bcs GetBranchAdr ; If branch: Calculate address
184 jsr PutHex8 ; Otherwise print 8bit value
188 L20BA: asl AdrFlagBuf
200 ; If the instruction is a branch, calculate the absolute address of the
201 ; branch target and print it.
210 jmp PutHex16 ; Output address
221 ; -------------------------------------------------------------------------
222 ; Subroutine to analyze an opcode byte in A. Will return a byte that
223 ; encodes the mnemonic, and will set the number of bytes needed for this
224 ; instruction in OperandLen
273 ; -------------------------------------------------------------------------
274 ; Print the mnemonic with code in A (that code was returned by
284 ldy #$05 ; 3*5 bits in two bytes
285 L213E: asl MnemoBuf+1