Added disassembly stuff

This commit is contained in:
Zellyn Hunter 2013-04-21 16:49:28 -07:00
parent 73ca1c8195
commit 986acf6917
2 changed files with 29 additions and 0 deletions

View File

@ -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
View 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