From d42a92879bcdbcd061d6b322728d2640f218719d Mon Sep 17 00:00:00 2001 From: Zellyn Hunter Date: Tue, 5 Aug 2014 22:17:11 -0700 Subject: [PATCH] working on disasm --- a2/disasm.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/a2/disasm.go b/a2/disasm.go index f05d841..807b632 100644 --- a/a2/disasm.go +++ b/a2/disasm.go @@ -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 }