mirror of
https://github.com/zellyn/go6502.git
synced 2025-03-13 20:35:22 +00:00
Added disassembly stuff
This commit is contained in:
parent
73ca1c8195
commit
986acf6917
@ -5,6 +5,7 @@ package asm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/zellyn/go6502/opcodes"
|
||||
)
|
||||
@ -73,3 +74,23 @@ func Disasm(pc uint16, byte0, byte1, byte2 byte) (string, string, int) {
|
||||
addr := addrString(pc, byte1, byte2, length, op.Mode)
|
||||
return bytes, op.Name + " " + addr, length
|
||||
}
|
||||
|
||||
// DisasmBlock disassembles an entire block, writing out the disassembly.
|
||||
func DisasmBlock(block []byte, startAddr uint16, w io.Writer) {
|
||||
l := len(block)
|
||||
for i := 0; i < l; i++ {
|
||||
byte0 := block[i]
|
||||
byte1 := byte(0xFF)
|
||||
byte2 := byte(0xFF)
|
||||
if i+1 < l {
|
||||
byte1 = block[i+1]
|
||||
}
|
||||
if i+2 < l {
|
||||
byte2 = block[i+2]
|
||||
}
|
||||
addr := uint16(i) + startAddr
|
||||
bytes, op, length := Disasm(addr, byte0, byte1, byte2)
|
||||
fmt.Fprintf(w, "$%04X: %s %s\n", addr, bytes, op)
|
||||
i += length - 1
|
||||
}
|
||||
}
|
||||
|
8
docs/assembler.org
Normal file
8
docs/assembler.org
Normal file
@ -0,0 +1,8 @@
|
||||
$C030 - hex number
|
||||
|
||||
Line - Label - Opcode - Operand - Comments
|
||||
1000 TONE LDA $C030
|
||||
1010 LOOP DEY
|
||||
1020 BNE LOOP
|
||||
1030 JMP TONE
|
||||
|
Loading…
x
Reference in New Issue
Block a user