Skip to content

Commit

Permalink
add -binary option to read raw binary files without header
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelk committed Nov 5, 2024
1 parent 4a8135a commit a32b5b4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*.asm
*.o
*.dbg
*.bin
*.nes
.testCoverage
nesgodisasm
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,25 @@ ld65 example.o -t nes -o example.nes
usage: nesgodisasm [options] <file to disassemble>
-a string
Assembler compatibility of the generated .asm file (asm6/ca65/nesasm) (default "ca65")
Assembler compatibility of the generated .asm file (asm6/ca65/nesasm) (default "ca65")
-batch string
process a batch of given path and file mask and automatically .asm file naming, for example *.nes
process a batch of given path and file mask and automatically .asm file naming, for example *.nes
-binary
read input file as raw binary file without any header
-c string
Config file name to write output to for ca65 assembler
Config file name to write output to for ca65 assembler
-cdl string
name of the .cdl Code/Data log file to load
name of the .cdl Code/Data log file to load
-debug
enable debugging options for extended logging
enable debugging options for extended logging
-nohexcomments
do not output opcode bytes as hex values in comments
do not output opcode bytes as hex values in comments
-nooffsets
do not output offsets in comments
do not output offsets in comments
-o string
name of the output .asm file, printed on console if no name given
-q perform operations quietly
name of the output .asm file, printed on console if no name given
-q perform operations quietly
-verify
verify the generated output by assembling with ca65 and check if it matches the input
-z output the trailing zero bytes of banks
verify the generated output by assembling with ca65 and check if it matches the input
-z output the trailing zero bytes of banks
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/retroenv/nesgodisasm

go 1.22

require github.com/retroenv/retrogolib v0.0.0-20240429170148-9ce0db22ccb0
require github.com/retroenv/retrogolib v0.0.0-20241105003543-931e147416dc
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/retroenv/retrogolib v0.0.0-20240304170601-1176bfc2fb7c h1:D9vm2K2Po+MTs0t/UdGY/hLzI8YSfwxLxpVxA5EQuaM=
github.com/retroenv/retrogolib v0.0.0-20240304170601-1176bfc2fb7c/go.mod h1:kvmonrBF8P56SmAZwPA29fWgNEhFNHQ9cxXpy/w8Uio=
github.com/retroenv/retrogolib v0.0.0-20240429170148-9ce0db22ccb0 h1:Yc5x58s3NvQJjsgEQ+fyleW9oAYe/vBadMB++bO8VUA=
github.com/retroenv/retrogolib v0.0.0-20240429170148-9ce0db22ccb0/go.mod h1:HZ3Y8NA+pJQrTLDJ6VSg/X6Oo4jWxz2S9ZMSvv8Zm1o=
github.com/retroenv/retrogolib v0.0.0-20241105003543-931e147416dc h1:hRuZBHYI/K0w0PTQEJrJ8o5hwW9s1wqWqEogdBL8Z3o=
github.com/retroenv/retrogolib v0.0.0-20241105003543-931e147416dc/go.mod h1:8pe9mEjbKL9Z5L4FFzYGSk1Ovhrq1LR6ucwRFj5CIXs=
8 changes: 7 additions & 1 deletion internal/disasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ func (dis *Disasm) initializeIrqHandlers() {
dis.handlers.NMI = "NMI"
}

reset := dis.readMemoryWord(irqStartAddress + 2)
var reset uint16
if dis.options.Binary {
reset = uint16(nes.CodeBaseAddress)
} else {
reset = dis.readMemoryWord(irqStartAddress + 2)
}

dis.logger.Debug("Reset handler", log.String("address", fmt.Sprintf("0x%04X", reset)))
offsetInfo := dis.mapper.offsetInfo(reset)
if offsetInfo != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Program struct {
Output string

AssembleTest bool
Binary bool
Debug bool
Quiet bool

Expand All @@ -28,6 +29,7 @@ type Disassembler struct {
Assembler string // what assembler to use
CodeDataLog io.ReadCloser // Code/Data log file to parse

Binary bool
CodeOnly bool
HexComments bool
OffsetComments bool
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func initializeApp() (*log.Logger, *options.Program, *options.Disassembler) {
var zeroBytes bool

flags.StringVar(&opts.Assembler, "a", "ca65", "Assembler compatibility of the generated .asm file (asm6/ca65/nesasm)")
flags.BoolVar(&opts.Binary, "binary", false, "read input file as raw binary file without any header")
flags.StringVar(&opts.Batch, "batch", "", "process a batch of given path and file mask and automatically .asm file naming, for example *.nes")
flags.StringVar(&opts.Config, "c", "", "Config file name to write output to for ca65 assembler")
flags.BoolVar(&opts.Debug, "debug", false, "enable debugging options for extended logging")
Expand Down Expand Up @@ -150,7 +151,14 @@ func disasmFile(logger *log.Logger, opts *options.Program, disasmOptions *option
return fmt.Errorf("opening file '%s': %w", opts.Input, err)
}

cart, err := cartridge.LoadFile(file)
disasmOptions.Binary = opts.Binary
var cart *cartridge.Cartridge

if opts.Binary {
cart, err = cartridge.LoadBuffer(file)
} else {
cart, err = cartridge.LoadFile(file)
}
if err != nil {
return fmt.Errorf("reading file: %w", err)
}
Expand Down

0 comments on commit a32b5b4

Please sign in to comment.