From 5548469ba16e8005483ad645e652de892a311677 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 2 Jan 2020 13:09:18 -0800 Subject: [PATCH] Show large adjustments in hex We emit address adjustments like "LDA thing+1", which are usually small values. Sometimes they're large, e.g. "LDA thing-61440", which is harder to understand than "LDA thing-$F000". So now we show small adjustments in decimal, and large adjustments in hex. The current definition of "small" is abs(adjust) < 256. --- Asm65/Formatter.cs | 19 ++++++++--- .../Expected/2007-labels-and-symbols_64tass.S | 8 ++--- .../2007-labels-and-symbols_Merlin32.S | 32 +++++++++---------- .../Expected/2007-labels-and-symbols_cc65.S | 8 ++--- .../Expected/2021-external-symbols_64tass.S | 4 +-- .../Expected/2021-external-symbols_Merlin32.S | 6 ++-- .../Expected/2021-external-symbols_acme.S | 4 +-- .../Expected/2021-external-symbols_cc65.S | 4 +-- 8 files changed, 47 insertions(+), 38 deletions(-) diff --git a/Asm65/Formatter.cs b/Asm65/Formatter.cs index 580df13..0db2066 100644 --- a/Asm65/Formatter.cs +++ b/Asm65/Formatter.cs @@ -639,18 +639,27 @@ namespace Asm65 { } /// - /// Formats an adjustment, as "+decimal" or "-decimal". If no adjustment - /// is required, an empty string is returned. + /// Formats an adjustment. Small values are formatted as "+decimal" or "-decimal", + /// larger values are formatted as hex. If no adjustment is required, an empty string + /// is returned. /// /// Adjustment value. /// Formatted string. public string FormatAdjustment(int adjValue) { if (adjValue == 0) { return string.Empty; + } else if (Math.Abs(adjValue) >= 256) { + // not using mHexPrefix here, since dec vs. hex matters + if (adjValue < 0) { + return "-$" + (-adjValue).ToString(mHexValueFormats[0]); + } else { + return "+$" + adjValue.ToString(mHexValueFormats[0]); + } + } else { + // This formats in decimal with a leading '+' or '-'. To avoid adding a plus + // on zero, we'd use "+#;-#;0", but we took care of the zero case above. + return adjValue.ToString("+0;-#"); } - // This formats in decimal with a leading '+' or '-'. To avoid adding a plus - // on zero, we'd use "+#;-#;0", but we took care of the zero case above. - return adjValue.ToString("+0;-#"); } /// diff --git a/SourceGen/SGTestData/Expected/2007-labels-and-symbols_64tass.S b/SourceGen/SGTestData/Expected/2007-labels-and-symbols_64tass.S index f1e5fe3..2349f07 100644 --- a/SourceGen/SGTestData/Expected/2007-labels-and-symbols_64tass.S +++ b/SourceGen/SGTestData/Expected/2007-labels-and-symbols_64tass.S @@ -65,12 +65,12 @@ start clc lda #zip+64 lda #absl lda #(absl >> 8) - lda #absl-4096 + lda #absl-$1000 lda #(absl >> 8)-16 lda #(absl >> 16) lda #absh lda #(absh >> 8) - lda #absh-61440 + lda #absh-$f000 lda #(absh >> 8)+16 lda #(absh >> 16)+1 lda #(start & $ffff) @@ -90,11 +90,11 @@ start clc .word zip .word absl .word 0+(absl >> 8) - .word absl-4096 + .word absl-$1000 .word 0+(absl >> 8)-16 .word absh .word 0+(absh >> 8) - .word absh-61440 + .word absh-$f000 .word 0+(absh >> 8)+16 .word 0+(start & $ffff) .word 0+(start >> 8) diff --git a/SourceGen/SGTestData/Expected/2007-labels-and-symbols_Merlin32.S b/SourceGen/SGTestData/Expected/2007-labels-and-symbols_Merlin32.S index f43b390..83ca95a 100644 --- a/SourceGen/SGTestData/Expected/2007-labels-and-symbols_Merlin32.S +++ b/SourceGen/SGTestData/Expected/2007-labels-and-symbols_Merlin32.S @@ -19,11 +19,11 @@ start clc lda #absh lda #absh+256 + lda #>absh+$100 lda #absl lda #absl-256 + lda #>absl-$100 lda #start lda #^start @@ -59,14 +59,14 @@ start clc lda #zip+64 lda #absl lda #>absl - lda #absl-4096 - lda #>absl-4096 + lda #absl-$1000 + lda #>absl-$1000 lda #^absl lda #absh lda #>absh - lda #absh+4096 - lda #>absh+4096 - lda #^absh+65536 + lda #absh+$1000 + lda #>absh+$1000 + lda #^absh+$10000 lda #start lda #>start lda #^start @@ -84,12 +84,12 @@ start clc dw zip dw absl dw >absl - dw absl-4096 - dw >absl-4096 + dw absl-$1000 + dw >absl-$1000 dw absh dw >absh - dw absh+4096 - dw >absh+4096 + dw absh+$1000 + dw >absh+$1000 dw start dw >start dw ^start @@ -110,9 +110,9 @@ start clc adrl >start adrl ^start -:skipdata lda #^biggie-65536 - mvn #^biggie,#^biggie-1114112 - mvp #^start,#^start+1114112 +:skipdata lda #^biggie-$10000 + mvn #^biggie,#^biggie-$110000 + mvp #^start,#^start+$110000 mvn #18,#1 mvp #%00000001,#%00010010 per :skipdata @@ -189,12 +189,12 @@ start clc asc 'he quick brown fox jumps over the lazy dogs.' :L118E lda #thirty2+768 + lda #>thirty2+$300 lda #^thirty2 rep #$30 mx %00 lda #thirty2+3 - lda #>thirty2+1024 + lda #>thirty2+$400 lda #^thirty2 rts diff --git a/SourceGen/SGTestData/Expected/2007-labels-and-symbols_cc65.S b/SourceGen/SGTestData/Expected/2007-labels-and-symbols_cc65.S index 4839e32..04a52b2 100644 --- a/SourceGen/SGTestData/Expected/2007-labels-and-symbols_cc65.S +++ b/SourceGen/SGTestData/Expected/2007-labels-and-symbols_cc65.S @@ -64,12 +64,12 @@ start: clc lda #zip+64 lda #absl lda #absl >> 8 - lda #absl-4096 + lda #absl-$1000 lda #absl >> 8 -16 lda #absl >> 16 lda #absh lda #absh >> 8 - lda #absh-61440 + lda #absh-$f000 lda #absh >> 8 +16 lda #absh >> 16 +1 lda #start & $ffff @@ -89,11 +89,11 @@ start: clc .word zip .word absl .word absl >> 8 - .word absl-4096 + .word absl-$1000 .word absl >> 8 -16 .word absh .word absh >> 8 - .word absh-61440 + .word absh-$f000 .word absh >> 8 +16 .word start & $ffff .word start >> 8 diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S b/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S index ca01061..5aab27b 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S @@ -36,8 +36,8 @@ L1000 lda CodeWrap+255 ldx L1000 ldy L1000+1 lda _L1148 - lda CodeWrap+585 - lda CodeWrap+592 + lda CodeWrap+$249 + lda CodeWrap+$250 nop lda $1ffe lda SameName1-1 diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S b/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S index dfc4dc0..7db01be 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S @@ -35,8 +35,8 @@ L1000 lda CodeWrap+255 ldx L1000 ldy L1000+1 lda :L1148 - lda CodeWrap+585 - lda CodeWrap+592 + lda CodeWrap+$249 + lda CodeWrap+$250 nop lda $1ffe lda SameName1-1 @@ -112,7 +112,7 @@ L1000 lda CodeWrap+255 lda $4000 lda $4001 lda BankWrap+8 - lda