diff options
author | Astatin <[email protected]> | 2025-06-10 18:27:56 +0200 |
---|---|---|
committer | Astatin <[email protected]> | 2025-06-10 18:27:56 +0200 |
commit | 501b255423d9a08ab5d9765c3feb5bf3a6b7b0af (patch) | |
tree | c2f7573b409bf591dad3302ec6816878842d24d2 | |
parent | a7d6e62878245810323787eeb5458e418371b89f (diff) |
Add ASSERT macro + fix label substractions banks + add . for current address
-rw-r--r-- | instructions.go | 5 | ||||
-rw-r--r-- | macros.go | 25 | ||||
-rw-r--r-- | parameters.go | 21 |
3 files changed, 49 insertions, 2 deletions
diff --git a/instructions.go b/instructions.go index 80bedec..ff87e44 100644 --- a/instructions.go +++ b/instructions.go @@ -13,6 +13,7 @@ type InstructionParams struct { Wildcard bool MacroForbidden bool LabelsBeforeOnly bool + SkipFirstPass bool } type InstructionSet map[string][]InstructionParams @@ -525,6 +526,10 @@ func (set InstructionSet) Parse( var rejectedErrors error instruction_param_loop: for _, instrParam := range instruction { + if instrParam.SkipFirstPass && isFirstPass { + return []byte{}, nil + } + if !instrParam.Wildcard && len(instrParam.Types) != len(params) { continue } @@ -43,6 +43,31 @@ func NewInstructionSetMacros() InstructionSet { }, } + result[".ASSERT"] = []InstructionParams{ + { + Types: []ParamType{Raw8, Raw8}, + Assembler: func(currentAddress uint32, args []uint32) ([]byte, error) { + if args[0] != args[1] { + return nil, fmt.Errorf("ASSERTION FAILED, %v != %v", args[0], args[1]) + } + return []byte{}, nil + }, + MacroForbidden: false, + SkipFirstPass: true, + }, + { + Types: []ParamType{Raw16, Raw16}, + Assembler: func(currentAddress uint32, args []uint32) ([]byte, error) { + if args[0] != args[1] { + return nil, fmt.Errorf("ASSERTION FAILED, %v != %v", args[0], args[1]) + } + return []byte{}, nil + }, + MacroForbidden: false, + SkipFirstPass: true, + }, + } + result[".DB"] = []InstructionParams{ { Types: []ParamType{Raw8}, diff --git a/parameters.go b/parameters.go index 5dffc1c..b812fef 100644 --- a/parameters.go +++ b/parameters.go @@ -234,17 +234,29 @@ func Raw16( if strings.Contains(param, "-") { spl := strings.Split(param, "-") - v, err := Raw16(labels, lastAbsoluteLabel, defs, currentAddress, spl[0]) + v, err := ROMAddress(labels, lastAbsoluteLabel, defs, currentAddress, spl[0]) if err != nil { return 0, err } + + bank := v / 0x4000 result := v for _, arg := range spl[1:] { - v, err := Raw16(labels, lastAbsoluteLabel, defs, currentAddress, arg) + v, err := ROMAddress(labels, lastAbsoluteLabel, defs, currentAddress, arg) if err != nil { return 0, err } + otherBank := v / 0x4000 + if bank != otherBank { + return 0, fmt.Errorf( + "Cannot get distance between rom addresses in different banks (%s is in bank %v, %s is in bank %v)", + spl[0], + bank, + arg, + otherBank, + ) + } result -= v } @@ -293,6 +305,7 @@ func Raw16( currentBank := currentAddress / 0x4000 romAddrBank := romAddr / 0x4000 + // TODO: Forbidding calls from other banks to bank 0 if romAddrBank == 0 { return romAddr, nil } @@ -422,6 +435,10 @@ func ROMAddress( currentAddress uint32, param string, ) (uint32, error) { + if param == "." { + return currentAddress, nil + } + if strings.HasPrefix(param, "=") { labelWithoutOffset, offset, err := parseOffset(param[1:]) if err != nil { |