diff --git a/.golangci.yml b/.golangci.yml index 8c15b98..68dc06a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -71,16 +71,10 @@ linters-settings: min-complexity: 8 revive: rules: - - name: dot-imports - disabled: true - name: exported disabled: true - name: var-naming disabled: true - stylecheck: - checks: - - "all" - - "-ST1001" # should not use dot imports whitespace: multi-if: true # Enforces newlines (or comments) after every multi-line if statement multi-func: true # Enforces newlines (or comments) after every multi-line function signature diff --git a/go.mod b/go.mod index ebc5ffe..ea5087e 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/retroenv/nesgodisasm go 1.22 -require github.com/retroenv/retrogolib v0.0.0-20241211024829-974a9c462c2d +require github.com/retroenv/retrogolib v0.0.0-20241218182911-894f1c8e84e3 diff --git a/go.sum b/go.sum index 1aca7d0..e73792d 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ 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= +github.com/retroenv/retrogolib v0.0.0-20241218182911-894f1c8e84e3 h1:cBz3rYoG9I91H/U4MsfRft7VvEe5XtlnDl41Oa/FK+8= +github.com/retroenv/retrogolib v0.0.0-20241218182911-894f1c8e84e3/go.mod h1:zyJCaDI509lBE90xkZJxc0vGZGK5MnY9NIL3ckK2MEE= diff --git a/internal/const.go b/internal/const.go index 9e44573..fc63028 100644 --- a/internal/const.go +++ b/internal/const.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - . "github.com/retroenv/retrogolib/addressing" "github.com/retroenv/retrogolib/arch/cpu/m6502" "github.com/retroenv/retrogolib/arch/nes/register" ) @@ -52,19 +51,19 @@ func buildConstMap() (map[uint16]constTranslation, error) { return m, nil } -func mergeConstantsMaps(destination map[uint16]constTranslation, source map[uint16]AccessModeConstant) error { +func mergeConstantsMaps(destination map[uint16]constTranslation, source map[uint16]m6502.AccessModeConstant) error { for address, constantInfo := range source { translation := destination[address] translation.address = address - if constantInfo.Mode&ReadAccess != 0 { + if constantInfo.Mode&m6502.ReadAccess != 0 { if translation.Read != "" { return fmt.Errorf("constant with address 0x%04X and read mode is defined twice", address) } translation.Read = constantInfo.Constant } - if constantInfo.Mode&WriteAccess != 0 { + if constantInfo.Mode&m6502.WriteAccess != 0 { if translation.Write != "" { return fmt.Errorf("constant with address 0x%04X and write mode is defined twice", address) } diff --git a/internal/jumpengine.go b/internal/jumpengine.go index 86e79b5..6460be7 100644 --- a/internal/jumpengine.go +++ b/internal/jumpengine.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/retroenv/nesgodisasm/internal/program" - . "github.com/retroenv/retrogolib/addressing" "github.com/retroenv/retrogolib/arch/cpu/m6502" "github.com/retroenv/retrogolib/log" ) @@ -27,7 +26,7 @@ type jumpEngineCaller struct { // This can be found in some official games like Super Mario Bros. func (dis *Disasm) checkForJumpEngineJmp(jumpAddress uint16, offsetInfo *offset) error { instruction := offsetInfo.opcode.Instruction - if instruction.Name != m6502.Jmp.Name || offsetInfo.opcode.Addressing != IndirectAddressing { + if instruction.Name != m6502.Jmp.Name || offsetInfo.opcode.Addressing != m6502.IndirectAddressing { return nil } @@ -150,7 +149,7 @@ func (dis *Disasm) jumpContextInfo(jumpAddress uint16, offsetInfo *offset) ([]*o // checkForJumpEngineCall checks if the current instruction is a call into a jump engine function. func (dis *Disasm) checkForJumpEngineCall(address uint16, offsetInfo *offset) error { instruction := offsetInfo.opcode.Instruction - if instruction.Name != m6502.Jsr.Name || offsetInfo.opcode.Addressing != AbsoluteAddressing { + if instruction.Name != m6502.Jsr.Name || offsetInfo.opcode.Addressing != m6502.AbsoluteAddressing { return nil } diff --git a/internal/memory.go b/internal/memory.go index 65f800d..60d3169 100644 --- a/internal/memory.go +++ b/internal/memory.go @@ -3,7 +3,7 @@ package disasm import ( "fmt" - . "github.com/retroenv/retrogolib/addressing" + "github.com/retroenv/retrogolib/arch/cpu/m6502" "github.com/retroenv/retrogolib/arch/nes" ) @@ -42,7 +42,7 @@ func (dis *Disasm) readMemoryWord(address uint16) (uint16, error) { // readOpParam reads the opcode parameters after the first opcode byte // and translates it into emulator specific types. -func (dis *Disasm) readOpParam(addressing Mode, address uint16) (any, []byte, error) { +func (dis *Disasm) readOpParam(addressing m6502.AddressingMode, address uint16) (any, []byte, error) { fun, ok := paramReader[addressing] if !ok { return nil, nil, fmt.Errorf("unsupported addressing mode %00x", addressing) diff --git a/internal/params.go b/internal/params.go index 95de7fe..a920162 100644 --- a/internal/params.go +++ b/internal/params.go @@ -1,25 +1,25 @@ package disasm import ( - . "github.com/retroenv/retrogolib/addressing" + "github.com/retroenv/retrogolib/arch/cpu/m6502" ) type paramReaderFunc func(dis *Disasm, address uint16) (any, []byte, error) -var paramReader = map[Mode]paramReaderFunc{ - ImpliedAddressing: paramReaderImplied, - ImmediateAddressing: paramReaderImmediate, - AccumulatorAddressing: paramReaderAccumulator, - AbsoluteAddressing: paramReaderAbsolute, - AbsoluteXAddressing: paramReaderAbsoluteX, - AbsoluteYAddressing: paramReaderAbsoluteY, - ZeroPageAddressing: paramReaderZeroPage, - ZeroPageXAddressing: paramReaderZeroPageX, - ZeroPageYAddressing: paramReaderZeroPageY, - RelativeAddressing: paramReaderRelative, - IndirectAddressing: paramReaderIndirect, - IndirectXAddressing: paramReaderIndirectX, - IndirectYAddressing: paramReaderIndirectY, +var paramReader = map[m6502.AddressingMode]paramReaderFunc{ + m6502.ImpliedAddressing: paramReaderImplied, + m6502.ImmediateAddressing: paramReaderImmediate, + m6502.AccumulatorAddressing: paramReaderAccumulator, + m6502.AbsoluteAddressing: paramReaderAbsolute, + m6502.AbsoluteXAddressing: paramReaderAbsoluteX, + m6502.AbsoluteYAddressing: paramReaderAbsoluteY, + m6502.ZeroPageAddressing: paramReaderZeroPage, + m6502.ZeroPageXAddressing: paramReaderZeroPageX, + m6502.ZeroPageYAddressing: paramReaderZeroPageY, + m6502.RelativeAddressing: paramReaderRelative, + m6502.IndirectAddressing: paramReaderIndirect, + m6502.IndirectXAddressing: paramReaderIndirectX, + m6502.IndirectYAddressing: paramReaderIndirectY, } func paramReaderImplied(*Disasm, uint16) (any, []byte, error) { @@ -36,7 +36,7 @@ func paramReaderImmediate(dis *Disasm, address uint16) (any, []byte, error) { } func paramReaderAccumulator(*Disasm, uint16) (any, []byte, error) { - return Accumulator(0), nil, nil + return m6502.Accumulator(0), nil, nil } func paramReaderAbsolute(dis *Disasm, address uint16) (any, []byte, error) { @@ -45,7 +45,7 @@ func paramReaderAbsolute(dis *Disasm, address uint16) (any, []byte, error) { return nil, nil, err } - return Absolute(w), opcodes, nil + return m6502.Absolute(w), opcodes, nil } func paramReaderAbsoluteX(dis *Disasm, address uint16) (any, []byte, error) { @@ -53,7 +53,7 @@ func paramReaderAbsoluteX(dis *Disasm, address uint16) (any, []byte, error) { if err != nil { return nil, nil, err } - return AbsoluteX(w), opcodes, nil + return m6502.AbsoluteX(w), opcodes, nil } func paramReaderAbsoluteY(dis *Disasm, address uint16) (any, []byte, error) { @@ -61,7 +61,7 @@ func paramReaderAbsoluteY(dis *Disasm, address uint16) (any, []byte, error) { if err != nil { return nil, nil, err } - return AbsoluteY(w), opcodes, nil + return m6502.AbsoluteY(w), opcodes, nil } func paramReaderZeroPage(dis *Disasm, address uint16) (any, []byte, error) { @@ -70,7 +70,7 @@ func paramReaderZeroPage(dis *Disasm, address uint16) (any, []byte, error) { return nil, nil, err } opcodes := []byte{b} - return ZeroPage(b), opcodes, nil + return m6502.ZeroPage(b), opcodes, nil } func paramReaderZeroPageX(dis *Disasm, address uint16) (any, []byte, error) { @@ -79,7 +79,7 @@ func paramReaderZeroPageX(dis *Disasm, address uint16) (any, []byte, error) { return nil, nil, err } opcodes := []byte{b} - return ZeroPageX(b), opcodes, nil + return m6502.ZeroPageX(b), opcodes, nil } func paramReaderZeroPageY(dis *Disasm, address uint16) (any, []byte, error) { @@ -88,7 +88,7 @@ func paramReaderZeroPageY(dis *Disasm, address uint16) (any, []byte, error) { return nil, nil, err } opcodes := []byte{b} - return ZeroPageY(b), opcodes, nil + return m6502.ZeroPageY(b), opcodes, nil } func paramReaderRelative(dis *Disasm, address uint16) (any, []byte, error) { @@ -105,7 +105,7 @@ func paramReaderRelative(dis *Disasm, address uint16) (any, []byte, error) { } opcodes := []byte{byte(offset)} - return Absolute(address), opcodes, nil + return m6502.Absolute(address), opcodes, nil } func paramReaderIndirect(dis *Disasm, address uint16) (any, []byte, error) { @@ -114,7 +114,7 @@ func paramReaderIndirect(dis *Disasm, address uint16) (any, []byte, error) { if err != nil { return nil, nil, err } - return Indirect(w), opcodes, nil + return m6502.Indirect(w), opcodes, nil } func paramReaderIndirectX(dis *Disasm, address uint16) (any, []byte, error) { @@ -123,7 +123,7 @@ func paramReaderIndirectX(dis *Disasm, address uint16) (any, []byte, error) { return nil, nil, err } opcodes := []byte{b} - return IndirectX(b), opcodes, nil + return m6502.IndirectX(b), opcodes, nil } func paramReaderIndirectY(dis *Disasm, address uint16) (any, []byte, error) { @@ -132,7 +132,7 @@ func paramReaderIndirectY(dis *Disasm, address uint16) (any, []byte, error) { return nil, nil, err } opcodes := []byte{b} - return IndirectY(b), opcodes, nil + return m6502.IndirectY(b), opcodes, nil } func paramReadWord(dis *Disasm, address uint16) (uint16, []byte, error) { diff --git a/internal/parser.go b/internal/parser.go index 3f02f77..9ce59c5 100644 --- a/internal/parser.go +++ b/internal/parser.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/retroenv/nesgodisasm/internal/program" - . "github.com/retroenv/retrogolib/addressing" "github.com/retroenv/retrogolib/arch/cpu/m6502" "github.com/retroenv/retrogolib/arch/nes" "github.com/retroenv/retrogolib/arch/nes/parameter" @@ -42,7 +41,7 @@ func (dis *Disasm) followExecutionFlow() error { instruction := offsetInfo.opcode.Instruction - if offsetInfo.opcode.Addressing == ImpliedAddressing { + if offsetInfo.opcode.Addressing == m6502.ImpliedAddressing { offsetInfo.Code = instruction.Name } else { params, err := dis.processParamInstruction(dis.pc, offsetInfo) @@ -150,7 +149,7 @@ func (dis *Disasm) processParamInstruction(address uint16, offsetInfo *offset) ( paramAsString = dis.replaceParamByAlias(address, opcode, param, paramAsString) if _, ok := m6502.BranchingInstructions[opcode.Instruction.Name]; ok { - addr, ok := param.(Absolute) + addr, ok := param.(m6502.Absolute) if ok { dis.addAddressToParse(uint16(addr), offsetInfo.context, dis.pc, opcode.Instruction, true) } @@ -288,23 +287,23 @@ func (dis *Disasm) handleInstructionIRQOverlap(address uint16, offsetInfo *offse // getAddressingParam returns the address of the param if it references an address. func getAddressingParam(param any) (uint16, bool) { switch val := param.(type) { - case Absolute: + case m6502.Absolute: return uint16(val), true - case AbsoluteX: + case m6502.AbsoluteX: return uint16(val), true - case AbsoluteY: + case m6502.AbsoluteY: return uint16(val), true - case Indirect: + case m6502.Indirect: return uint16(val), true - case IndirectX: + case m6502.IndirectX: return uint16(val), true - case IndirectY: + case m6502.IndirectY: return uint16(val), true - case ZeroPage: + case m6502.ZeroPage: return uint16(val), true - case ZeroPageX: + case m6502.ZeroPageX: return uint16(val), true - case ZeroPageY: + case m6502.ZeroPageY: return uint16(val), true default: return 0, false @@ -315,10 +314,10 @@ func getAddressingParam(param any) (uint16, bool) { // and forces variable usage. func checkBranchingParam(address uint16, opcode m6502.Opcode) (bool, bool) { switch { - case opcode.Instruction.Name == m6502.Jmp.Name && opcode.Addressing == IndirectAddressing: + case opcode.Instruction.Name == m6502.Jmp.Name && opcode.Addressing == m6502.IndirectAddressing: return true, false case opcode.Instruction.Name == m6502.Jmp.Name || opcode.Instruction.Name == m6502.Jsr.Name: - if opcode.Addressing == AbsoluteAddressing && address < nes.CodeBaseAddress { + if opcode.Addressing == m6502.AbsoluteAddressing && address < nes.CodeBaseAddress { return true, true } } diff --git a/internal/vars.go b/internal/vars.go index 3944f95..a43580f 100644 --- a/internal/vars.go +++ b/internal/vars.go @@ -5,7 +5,6 @@ import ( "sort" "github.com/retroenv/nesgodisasm/internal/program" - . "github.com/retroenv/retrogolib/addressing" "github.com/retroenv/retrogolib/arch/cpu/m6502" "github.com/retroenv/retrogolib/arch/nes" "github.com/retroenv/retrogolib/arch/nes/parameter" @@ -70,9 +69,9 @@ func (dis *Disasm) addVariableReference(addressReference, usageAddress uint16, } switch opcode.Addressing { - case ZeroPageXAddressing, ZeroPageYAddressing, - AbsoluteXAddressing, AbsoluteYAddressing, - IndirectXAddressing, IndirectYAddressing: + case m6502.ZeroPageXAddressing, m6502.ZeroPageYAddressing, + m6502.AbsoluteXAddressing, m6502.AbsoluteYAddressing, + m6502.IndirectXAddressing, m6502.IndirectYAddressing: varInfo.indexedUsage = true } } @@ -120,11 +119,11 @@ func (dis *Disasm) processVariables() error { } switch offsetInfo.opcode.Addressing { - case ZeroPageAddressing, ZeroPageXAddressing, ZeroPageYAddressing: + case m6502.ZeroPageAddressing, m6502.ZeroPageXAddressing, m6502.ZeroPageYAddressing: offsetInfo.Code = fmt.Sprintf("%s %s", offsetInfo.opcode.Instruction.Name, converted) - case AbsoluteAddressing, AbsoluteXAddressing, AbsoluteYAddressing: + case m6502.AbsoluteAddressing, m6502.AbsoluteXAddressing, m6502.AbsoluteYAddressing: offsetInfo.Code = fmt.Sprintf("%s %s", offsetInfo.opcode.Instruction.Name, converted) - case IndirectAddressing, IndirectXAddressing, IndirectYAddressing: + case m6502.IndirectAddressing, m6502.IndirectXAddressing, m6502.IndirectYAddressing: offsetInfo.Code = fmt.Sprintf("%s %s", offsetInfo.opcode.Instruction.Name, converted) } }