From 1631cd77f6f0e9feee918e40444dfcd015e46af9 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 12 Sep 2019 14:24:09 -0700 Subject: [PATCH] Check both directions for project/platform "nearby" matches If a symbol is defined at , and we counter STA -1,Y, we want to use the symbol in the operand. This worked for labels but not project/platform symbols. Also, fixed a crash that happened if you tried to delete an auto label. --- SourceGen/DisasmProject.cs | 15 +++++++++++++++ SourceGen/MainController.cs | 15 +++++++++++---- .../Expected/2008-address-changes_64tass.S | 4 ++-- .../Expected/2008-address-changes_Merlin32.S | 4 ++-- .../Expected/2008-address-changes_acme.S | 4 ++-- .../Expected/2008-address-changes_cc65.S | 4 ++-- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs index 395a1a7..e418f40 100644 --- a/SourceGen/DisasmProject.cs +++ b/SourceGen/DisasmProject.cs @@ -1075,6 +1075,21 @@ namespace SourceGen { if (sym == null && (attr.OperandAddress & 0xffff) > 1 && checkNearby) { sym = SymbolTable.FindAddressByValue(attr.OperandAddress - 2); } + // Still nothing, try addr+1. Sometimes indexed addressing will use + // "STA addr-1,y". This will also catch "STA addr-1" when addr is the + // very start of a segment, which means we're actually finding a label + // reference rather than project/platform symbol; only works if the + // location already has a label. + if (sym == null && (attr.OperandAddress & 0xffff) < 0xffff && checkNearby) { + sym = SymbolTable.FindAddressByValue(attr.OperandAddress + 1); + if (sym != null && sym.SymbolSource != Symbol.Source.Project && + sym.SymbolSource != Symbol.Source.Platform) { + Debug.WriteLine("Applying non-platform in GeneratePlatform: " + sym); + // should be okay to do this + } + } + + // If we found something, and it's not a variable, create a descriptor. if (sym != null && !sym.IsVariable) { mAnattribs[offset].DataDescriptor = FormatDescriptor.Create(mAnattribs[offset].Length, diff --git a/SourceGen/MainController.cs b/SourceGen/MainController.cs index 73e4fbe..74dee5b 100644 --- a/SourceGen/MainController.cs +++ b/SourceGen/MainController.cs @@ -1624,10 +1624,17 @@ namespace SourceGen { if (mProject.UserLabels.ContainsKey(offset)) { oldUserValue = mProject.UserLabels[offset]; } - UndoableChange uc = UndoableChange.CreateLabelChange(offset, - oldUserValue, dlg.LabelSym); - ChangeSet cs = new ChangeSet(uc); - ApplyUndoableChanges(cs); + if (oldUserValue == dlg.LabelSym) { + // Only expected when attr.Symbol is Auto + Debug.Assert(attr.Symbol.SymbolSource == Symbol.Source.Auto); + Debug.Assert(oldUserValue == null); + Debug.WriteLine("Ignoring attempt to delete an auto label"); + } else { + UndoableChange uc = UndoableChange.CreateLabelChange(offset, + oldUserValue, dlg.LabelSym); + ChangeSet cs = new ChangeSet(uc); + ApplyUndoableChanges(cs); + } } } diff --git a/SourceGen/SGTestData/Expected/2008-address-changes_64tass.S b/SourceGen/SGTestData/Expected/2008-address-changes_64tass.S index 533ffb9..99e9878 100644 --- a/SourceGen/SGTestData/Expected/2008-address-changes_64tass.S +++ b/SourceGen/SGTestData/Expected/2008-address-changes_64tass.S @@ -55,8 +55,8 @@ L2080 bit L2080 jsr offend lda offend+1 jsr offend+1 - lda $207f - jsr $207f + lda L2080-1 + jsr L2080-1 lda L2080 jsr L2080 lda $00 diff --git a/SourceGen/SGTestData/Expected/2008-address-changes_Merlin32.S b/SourceGen/SGTestData/Expected/2008-address-changes_Merlin32.S index 74e6322..a31ce7c 100644 --- a/SourceGen/SGTestData/Expected/2008-address-changes_Merlin32.S +++ b/SourceGen/SGTestData/Expected/2008-address-changes_Merlin32.S @@ -47,8 +47,8 @@ L2080 bit L2080 jsr offend lda offend+1 jsr offend+1 - lda $207f - jsr $207f + lda L2080-1 + jsr L2080-1 lda L2080 jsr L2080 lda $00 diff --git a/SourceGen/SGTestData/Expected/2008-address-changes_acme.S b/SourceGen/SGTestData/Expected/2008-address-changes_acme.S index 02d34e5..4c0d479 100644 --- a/SourceGen/SGTestData/Expected/2008-address-changes_acme.S +++ b/SourceGen/SGTestData/Expected/2008-address-changes_acme.S @@ -55,8 +55,8 @@ L2080 bit L2080 jsr offend lda offend+1 jsr offend+1 - lda $207f - jsr $207f + lda L2080-1 + jsr L2080-1 lda L2080 jsr L2080 lda $00 diff --git a/SourceGen/SGTestData/Expected/2008-address-changes_cc65.S b/SourceGen/SGTestData/Expected/2008-address-changes_cc65.S index e52de68..6c68a60 100644 --- a/SourceGen/SGTestData/Expected/2008-address-changes_cc65.S +++ b/SourceGen/SGTestData/Expected/2008-address-changes_cc65.S @@ -57,8 +57,8 @@ L2080: bit L2080 jsr offend lda offend+1 jsr offend+1 - lda $207f - jsr $207f + lda L2080-1 + jsr L2080-1 lda L2080 jsr L2080 lda $00