working on disasm

This commit is contained in:
Zellyn Hunter 2014-08-05 22:17:11 -07:00
parent b78face2fe
commit d42a92879b

View File

@ -19,9 +19,13 @@ Disasm is a very simple disassembler for 6502 binary files.
}
var disasmAddress uint // disasm -a flag
var symbolFile string // disasm -s flag
var printLabels bool // disasm -p flag
func init() {
cmdDisasm.Flag.UintVar(&disasmAddress, "a", 0, "The starting memory address.")
cmdDisasm.Flag.StringVar(&symbolFile, "s", "", "File of symbol definitions.")
cmdDisasm.Flag.BoolVar(&printLabels, "p", false, "Print labels for symbols.")
}
func runDisasm(cmd *commander.Command, args []string) error {
@ -32,7 +36,7 @@ func runDisasm(cmd *commander.Command, args []string) error {
bytes, err := ioutil.ReadFile(args[0])
if err != nil {
return nil
return err
}
if len(bytes) > 0x10000 {
return fmt.Errorf("File %s is %04X bytes long, which is more than $10000.", args[0], len(bytes))
@ -42,6 +46,18 @@ func runDisasm(cmd *commander.Command, args []string) error {
disasmAddress, len(bytes), int(disasmAddress)+len(bytes))
}
asm.DisasmBlock(bytes, uint16(disasmAddress), os.Stdout)
var s asm.Symbols
if symbolFile != "" {
s, err = asm.ReadSymbols(symbolFile)
if err != nil {
return err
}
} else {
if printLabels {
return fmt.Errorf("-p (print labels) specified without -s (symbol table file")
}
}
asm.DisasmBlock(bytes, uint16(disasmAddress), os.Stdout, s, 2, printLabels)
return nil
}