Skip to content

Commit

Permalink
use new retrogolib constants
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelk committed Dec 11, 2024
1 parent d5c5705 commit 225b3cb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
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-20241210033726-b294e4b1cc68
require github.com/retroenv/retrogolib v0.0.0-20241211024829-974a9c462c2d
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/retroenv/retrogolib v0.0.0-20241210033726-b294e4b1cc68 h1:woI2bmTWznMA9UX0iR5kZs7QfRaF4ZVM+B8mMHaTLCg=
github.com/retroenv/retrogolib v0.0.0-20241210033726-b294e4b1cc68/go.mod h1:8pe9mEjbKL9Z5L4FFzYGSk1Ovhrq1LR6ucwRFj5CIXs=
github.com/retroenv/retrogolib v0.0.0-20241211024829-974a9c462c2d h1:m4nCFBbox2t++8XPAIwJb5+6Z42lZuWQOKankkKVzSc=
github.com/retroenv/retrogolib v0.0.0-20241211024829-974a9c462c2d/go.mod h1:8pe9mEjbKL9Z5L4FFzYGSk1Ovhrq1LR6ucwRFj5CIXs=
4 changes: 2 additions & 2 deletions internal/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (dis *Disasm) handleJumpIntoInstruction(address uint16) {
// bytes being assembled and make the resulting ROM not matching the original.
func (dis *Disasm) handleDisambiguousInstructions(address uint16, offsetInfo *offset) bool {
instruction := offsetInfo.opcode.Instruction
if !instruction.Unofficial || address >= irqStartAddress {
if !instruction.Unofficial || address >= m6502.InterruptVectorStartAddress {
return false
}

Expand All @@ -112,7 +112,7 @@ func (dis *Disasm) handleDisambiguousInstructions(address uint16, offsetInfo *of

// changeAddressRangeToCode sets a range of code addresses to code types.
func (dis *Disasm) changeAddressRangeToCode(address uint16, data []byte) {
for i := 0; i < len(data) && int(address)+i < irqStartAddress; i++ {
for i := 0; i < len(data) && int(address)+i < m6502.InterruptVectorStartAddress; i++ {
offsetInfo := dis.mapper.offsetInfo(address + uint16(i))
offsetInfo.SetType(program.CodeOffset)
}
Expand Down
10 changes: 4 additions & 6 deletions internal/disasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/retroenv/retrogolib/log"
)

const irqStartAddress = 0xfffa

type fileWriterConstructor func(app *program.Program, options *options.Disassembler,
mainWriter io.Writer, newBankWriter assembler.NewBankWriter) writer.AssemblerWriter

Expand Down Expand Up @@ -196,7 +194,7 @@ func (dis *Disasm) initializeCompatibleMode(assemblerName string) error {
// initializeIrqHandlers reads the 3 IRQ handler addresses and adds them to the addresses to be
// followed for execution flow. Multiple handler can point to the same address.
func (dis *Disasm) initializeIrqHandlers() {
nmi := dis.readMemoryWord(irqStartAddress)
nmi := dis.readMemoryWord(m6502.NMIAddress)
if nmi != 0 {
dis.logger.Debug("NMI handler", log.String("address", fmt.Sprintf("0x%04X", nmi)))
offsetInfo := dis.mapper.offsetInfo(nmi)
Expand All @@ -211,7 +209,7 @@ func (dis *Disasm) initializeIrqHandlers() {
if dis.options.Binary {
reset = uint16(nes.CodeBaseAddress)
} else {
reset = dis.readMemoryWord(irqStartAddress + 2)
reset = dis.readMemoryWord(m6502.ResetAddress)
}

dis.logger.Debug("Reset handler", log.String("address", fmt.Sprintf("0x%04X", reset)))
Expand All @@ -224,7 +222,7 @@ func (dis *Disasm) initializeIrqHandlers() {
offsetInfo.SetType(program.CallDestination)
}

irq := dis.readMemoryWord(irqStartAddress + 4)
irq := dis.readMemoryWord(m6502.IrqAddress)
if irq != 0 {
dis.logger.Debug("IRQ handler", log.String("address", fmt.Sprintf("0x%04X", irq)))
offsetInfo = dis.mapper.offsetInfo(irq)
Expand Down Expand Up @@ -262,7 +260,7 @@ func (dis *Disasm) initializeIrqHandlers() {
func (dis *Disasm) calculateCodeBaseAddress(resetHandler uint16) {
halfPrg := len(dis.cart.PRG) % 0x8000
dis.codeBaseAddress = uint16(0x8000 + halfPrg)
dis.vectorsStartAddress = uint16(irqStartAddress)
dis.vectorsStartAddress = uint16(m6502.InterruptVectorStartAddress)

// fix up calculated code base address for half sized PRG ROMs that have a different
// code base address configured in the assembler, like "M.U.S.C.L.E."
Expand Down
4 changes: 2 additions & 2 deletions internal/jumpengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (dis *Disasm) getContextDataReferences(offsets []*offset, addresses []uint1

param, _ := dis.readOpParam(opcode.Addressing, address)
reference, ok := getAddressingParam(param)
if ok && reference >= dis.codeBaseAddress && reference < irqStartAddress {
if ok && reference >= dis.codeBaseAddress && reference < m6502.InterruptVectorStartAddress {
dataReferences = append(dataReferences, reference)
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (dis *Disasm) processJumpEngineEntry(address uint16, jumpEngine *jumpEngine

// verify that the destination is in valid code address range
destination := dis.readMemoryWord(address)
if destination < dis.codeBaseAddress || destination >= irqStartAddress {
if destination < dis.codeBaseAddress || destination >= m6502.InterruptVectorStartAddress {
jumpEngine.terminated = true
return false
}
Expand Down
12 changes: 6 additions & 6 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (dis *Disasm) followExecutionFlow() error {
// in case the current instruction overlaps with an already existing instruction,
// cut the current one short.
func (dis *Disasm) checkInstructionOverlap(address uint16, offsetInfo *offset) {
for i := 1; i < len(offsetInfo.OpcodeBytes) && int(address)+i < irqStartAddress; i++ {
for i := 1; i < len(offsetInfo.OpcodeBytes) && int(address)+i < m6502.InterruptVectorStartAddress; i++ {
offsetInfoFollowing := dis.mapper.offsetInfo(address + uint16(i))
if !offsetInfoFollowing.IsType(program.CodeOffset) {
continue
Expand All @@ -91,7 +91,7 @@ func (dis *Disasm) initializeOffsetInfo(offsetInfo *offset) bool {
}

b := dis.readMemory(dis.pc)
offsetInfo.OpcodeBytes = make([]byte, 1, 3)
offsetInfo.OpcodeBytes = make([]byte, 1, m6502.MaxOpcodeSize)
offsetInfo.OpcodeBytes[0] = b

if offsetInfo.IsType(program.DataOffset) {
Expand All @@ -116,7 +116,7 @@ func (dis *Disasm) processParamInstruction(address uint16, offsetInfo *offset) (
param, opcodes := dis.readOpParam(opcode.Addressing, dis.pc)
offsetInfo.OpcodeBytes = append(offsetInfo.OpcodeBytes, opcodes...)

if address+uint16(len(offsetInfo.OpcodeBytes)) > irqStartAddress {
if address+uint16(len(offsetInfo.OpcodeBytes)) > m6502.InterruptVectorStartAddress {
return "", errInstructionOverlapsIRQHandlers
}

Expand All @@ -142,7 +142,7 @@ func (dis *Disasm) processParamInstruction(address uint16, offsetInfo *offset) (
func (dis *Disasm) replaceParamByAlias(address uint16, opcode m6502.Opcode, param any, paramAsString string) string {
forceVariableUsage := false
addressReference, addressValid := getAddressingParam(param)
if !addressValid || addressReference >= irqStartAddress {
if !addressValid || addressReference >= m6502.InterruptVectorStartAddress {
return paramAsString
}

Expand Down Expand Up @@ -245,11 +245,11 @@ func (dis *Disasm) addAddressToParse(address, context, from uint16, currentInstr
// handleInstructionIRQOverlap handles an instruction overlapping with the start of the IRQ handlers.
// The opcodes are cut until the start of the IRQ handlers and the offset is converted to type data.
func (dis *Disasm) handleInstructionIRQOverlap(address uint16, offsetInfo *offset) {
if address > irqStartAddress {
if address > m6502.InterruptVectorStartAddress {
return
}

keepLength := int(irqStartAddress - address)
keepLength := int(m6502.InterruptVectorStartAddress - address)
offsetInfo.OpcodeBytes = offsetInfo.OpcodeBytes[:keepLength]

for i := range keepLength {
Expand Down

0 comments on commit 225b3cb

Please sign in to comment.