From bef664ae7e680ea04926da352c071d79212a8a87 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sat, 23 Nov 2019 16:27:06 -0800 Subject: [PATCH] Don't do nearby SYM-1 for zero-page values It's pretty common for code to access BUFFER-1,X, but it's rare for the buffer to live on zero page memory. More often than not we're auto-formatting zero-page operands with a nearby symbol when they're just simple variables. It's more confusing than useful, so we don't do that anymore. --- SourceGen/DisasmProject.cs | 7 ++++++- .../SGTestData/Expected/2021-external-symbols_64tass.S | 2 +- .../SGTestData/Expected/2021-external-symbols_Merlin32.S | 2 +- SourceGen/SGTestData/Expected/2021-external-symbols_acme.S | 2 +- SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs index c19c4e1..9e6b216 100644 --- a/SourceGen/DisasmProject.cs +++ b/SourceGen/DisasmProject.cs @@ -1343,7 +1343,12 @@ namespace SourceGen { // 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 && (address & 0xffff) < 0xffff && checkNearby) { + // + // Don't do this for zero-page locations, because those are usually + // individual variables that aren't accessed via addr-1. There are + // exceptions, but more often than not it's just distracting. + if (sym == null && checkNearby && (address & 0xffff) < 0xffff && + address > 0x0000ff) { sym = SymbolTable.FindNonVariableByAddress(address + 1, accType); if (sym != null && sym.SymbolSource != Symbol.Source.Project && sym.SymbolSource != Symbol.Source.Platform) { diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S b/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S index e7a368a..ca01061 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S @@ -102,7 +102,7 @@ L1000 lda CodeWrap+255 nop LocalVar .var $41 ldx $3e - ldx OverVar-1 + ldx $3f ldx OverVar ldx LocalVar ldx LocalVar+1 diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S b/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S index 2996220..dfc4dc0 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S @@ -101,7 +101,7 @@ L1000 lda CodeWrap+255 nop ]LocalVar equ $41 ldx $3e - ldx OverVar-1 + ldx $3f ldx OverVar ldx ]LocalVar ldx ]LocalVar+1 diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_acme.S b/SourceGen/SGTestData/Expected/2021-external-symbols_acme.S index 2209996..a82ea16 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_acme.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_acme.S @@ -103,7 +103,7 @@ L1000 lda CodeWrap+255 !zone Z0000c0 .LocalVar = $41 ldx $3e - ldx OverVar-1 + ldx $3f ldx OverVar ldx .LocalVar ldx .LocalVar+1 diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S b/SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S index fbd5a85..4866060 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S @@ -103,7 +103,7 @@ L1000: lda CodeWrap+255 nop LocalVar .set $41 ldx $3e - ldx OverVar-1 + ldx $3f ldx OverVar ldx LocalVar ldx LocalVar+1