diff --git a/src/HexManiac.Core/Models/Code/ThumbParser.cs b/src/HexManiac.Core/Models/Code/ThumbParser.cs index 1daad154..619107e1 100644 --- a/src/HexManiac.Core/Models/Code/ThumbParser.cs +++ b/src/HexManiac.Core/Models/Code/ThumbParser.cs @@ -1,13 +1,10 @@ -using HavenSoft.HexManiac.Core.Models.Runs; -using HavenSoft.HexManiac.Core.ViewModels.DataFormats; +using HavenSoft.HexManiac.Core.ViewModels.DataFormats; using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; -using System.Runtime.InteropServices; using System.Text; -using System.Threading.Tasks; namespace HavenSoft.HexManiac.Core.Models.Code { public class LabelLibrary { @@ -15,8 +12,13 @@ namespace HavenSoft.HexManiac.Core.Models.Code { private readonly IDictionary labels; public LabelLibrary(IDataModel data, IDictionary additionalLabels) => (model, labels) = (data, additionalLabels); public int ResolveLabel(string label) { - if (labels.TryGetValue(label, out int result)) return result; - return model.GetAddressFromAnchor(new NoDataChangeDeltaModel(), -1, label); + var offset = 0; + if (label.Split("+") is string[] parts && parts.Length == 2) { + label = parts[0]; + int.TryParse(parts[1], NumberStyles.HexNumber, CultureInfo.CurrentCulture, out offset); + } + if (labels.TryGetValue(label, out int result)) return result + offset; + return model.GetAddressFromAnchor(new NoDataChangeDeltaModel(), -1, label) + offset; } } diff --git a/src/HexManiac.Tests/Before_Baseclass/ToolTests.cs b/src/HexManiac.Tests/Before_Baseclass/ToolTests.cs index 41c01f81..baedcc7c 100644 --- a/src/HexManiac.Tests/Before_Baseclass/ToolTests.cs +++ b/src/HexManiac.Tests/Before_Baseclass/ToolTests.cs @@ -396,6 +396,7 @@ namespace HavenSoft.HexManiac.Tests { [InlineData("ldrh r1, [r2]", 0b10001_00000_010_001)] [InlineData("str r1, [sp]", 0b10010_001_00000000)] [InlineData("ldr r1, [sp]", 0b10011_001_00000000)] + [InlineData(".word ", 0b0000_1000_0000_0000_0000_0000_1001_0000)] // test that we can use anchors + offset to get pointer locations (in base 16) public void ThumbCompilerTests(string input, uint output) { var bytes = new List { (byte)output, (byte)(output >> 8) }; var model = new PokemonModel(new byte[0x200]);