diff options
author | Astatin <[email protected]> | 2025-01-07 16:20:52 +0900 |
---|---|---|
committer | Astatin <[email protected]> | 2025-01-07 16:20:52 +0900 |
commit | b5b9637ff2d222841632b8644b94835ec1c93359 (patch) | |
tree | e7239875fd331effe67e62c62569c0cff5b8c1d0 /parameters.go | |
parent | e4c337519fb9842de5eb12e5975f50efa02784d0 (diff) |
Add label offset + allow to use labels with .DB macro + relative labels
Diffstat (limited to 'parameters.go')
-rw-r--r-- | parameters.go | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/parameters.go b/parameters.go index 4c787f3..ddb4532 100644 --- a/parameters.go +++ b/parameters.go @@ -121,11 +121,30 @@ func Raw16(labels *Labels, defs *Definitions, param string) (uint16, error) { } if strings.HasPrefix(param, "=") { + var offset uint16 = 0 + labelWithoutOffset := param + + if strings.Contains(param, "+") { + labelParts := strings.Split(param, "+") + if len(labelParts) != 2 { + return 0, fmt.Errorf( + "Labels with offset should have exactly 1 offset (in \"%s\")", + param, + ) + } + labelWithoutOffset = labelParts[0] + o, err := strconv.ParseUint(labelParts[1], 0, 16) + if err != nil { + return 0, fmt.Errorf("Error while parsing label offset: %w", err) + } + offset = uint16(o) + } + if labels == nil { return 0, nil } - label := strings.ToUpper(strings.TrimPrefix(param, "=")) + label := strings.ToUpper(strings.TrimPrefix(labelWithoutOffset, "=")) labelValue, ok := (*labels)[label] if !ok { return 0, fmt.Errorf("Label \"%s\" not found", label) @@ -136,7 +155,7 @@ func Raw16(labels *Labels, defs *Definitions, param string) (uint16, error) { panic("Switchable ROM banks are not implemented yet") } - return uint16(labelValue), nil + return uint16(labelValue) + offset, nil } res, err := strconv.ParseUint(param, 0, 16) @@ -144,6 +163,16 @@ func Raw16(labels *Labels, defs *Definitions, param string) (uint16, error) { return uint16(res), err } +func Raw16MacroRelativeLabel(labels *Labels, defs *Definitions, param string) (uint16, error) { + if !strings.HasPrefix(param, "=$") { + return 0, fmt.Errorf( + "label \"%s\" is external to the macro", + param, + ) + } + return Raw16(labels, defs, param) +} + func Reg16Indirect(_ *Labels, _ *Definitions, param string) (uint16, error) { switch param { case "(BC)": |