From 70353c82e160fbc6a516cca7cb04aeee492e8af6 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sun, 27 Oct 2019 12:26:34 -0700 Subject: [PATCH] Limit value range of project address symbols Project symbol address values are now limited to positive 24-bit integers, just as they are for platform symbols. Constants may still be 32-bit values. --- SourceGen/PlatformSymbols.cs | 3 ++- SourceGen/RuntimeData/Help/advanced.html | 3 ++- SourceGen/RuntimeData/Help/intro.html | 4 ++-- SourceGen/WpfGui/EditDefSymbol.xaml | 4 +++- SourceGen/WpfGui/EditDefSymbol.xaml.cs | 13 ++++++++++++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/SourceGen/PlatformSymbols.cs b/SourceGen/PlatformSymbols.cs index cba57e5..86947af 100644 --- a/SourceGen/PlatformSymbols.cs +++ b/SourceGen/PlatformSymbols.cs @@ -173,7 +173,8 @@ namespace SourceGen { bool parseOk; string valueStr = matches[0].Groups[GROUP_VALUE].Value; if (isConst) { - // Allow various numeric options, and preserve the value. + // Allow various numeric options, and preserve the value. We + // don't limit the value range. parseOk = Asm65.Number.TryParseInt(valueStr, out value, out numBase); badParseMsg = CommonUtil.Properties.Resources.ERR_INVALID_NUMERIC_CONSTANT; diff --git a/SourceGen/RuntimeData/Help/advanced.html b/SourceGen/RuntimeData/Help/advanced.html index 37a387e..6861c3a 100644 --- a/SourceGen/RuntimeData/Help/advanced.html +++ b/SourceGen/RuntimeData/Help/advanced.html @@ -72,7 +72,8 @@ written.

binary (with a leading '%'). The numeric base will be recorded and used when formatting the symbol in generated output, so use whichever form is most appropriate. Values are unsigned 24-bit numbers. The special value -"erase" may be used to erase a symbol defined in an earlier platform file.

+"erase" may be used for an address to erase a symbol defined in an earlier +platform file.

The WIDTH is optional, and ignored for constants. It must be a decimal or hexadecimal value between 1 and 65536, inclusive. If omitted, diff --git a/SourceGen/RuntimeData/Help/intro.html b/SourceGen/RuntimeData/Help/intro.html index d3e9f54..a2abe59 100644 --- a/SourceGen/RuntimeData/Help/intro.html +++ b/SourceGen/RuntimeData/Help/intro.html @@ -483,8 +483,8 @@ value, the one whose label comes first alphabetically is used.

Project symbols always have precedence over platform symbols, allowing you to redefine symbols within a project. (You can "hide" a platform -symbol by creating a project symbol with the same name and an unused -value, such as $ffffffff.)

+symbol by creating a project symbol constant with the same name. Use a +value like $ffffffff or $deadbeef so you'll know why it's there.)

Local variables are redefinable symbols that are organized into tables. They're used to specify labels for zero-page and 65816 diff --git a/SourceGen/WpfGui/EditDefSymbol.xaml b/SourceGen/WpfGui/EditDefSymbol.xaml index 22e1fe1..b67b6db 100644 --- a/SourceGen/WpfGui/EditDefSymbol.xaml +++ b/SourceGen/WpfGui/EditDefSymbol.xaml @@ -23,7 +23,7 @@ limitations under the License. xmlns:local="clr-namespace:SourceGen.WpfGui" mc:Ignorable="d" Title="Edit Symbol" - SizeToContent="Height" Width="350" ResizeMode="NoResize" + SizeToContent="Height" Width="360" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" Loaded="Window_Loaded" ContentRendered="Window_ContentRendered"> @@ -77,6 +77,8 @@ limitations under the License. IsReadOnly="{Binding ReadOnlyValueAndType}"/> + diff --git a/SourceGen/WpfGui/EditDefSymbol.xaml.cs b/SourceGen/WpfGui/EditDefSymbol.xaml.cs index dea60d3..b74a8be 100644 --- a/SourceGen/WpfGui/EditDefSymbol.xaml.cs +++ b/SourceGen/WpfGui/EditDefSymbol.xaml.cs @@ -190,7 +190,7 @@ namespace SourceGen.WpfGui { Label = Value = VarWidth = Comment = string.Empty; - int maxWidth; + int maxWidth, maxAddr; if (isVariable) { ConstantLabel = (string)FindResource("str_VariableConstant"); maxWidth = 256; @@ -302,6 +302,16 @@ namespace SourceGen.WpfGui { if (thisValue < 0 || thisValue + thisWidth > 256) { valueRangeValid = false; } + } else if (IsAddress && valueValid) { + // limit to positive 24-bit integers; use a long for value+width so we + // don't get fooled by overflow + long lvalue = thisValue; + if (thisWidth > 0) { + lvalue += thisWidth - 1; + } + if (thisValue < 0 || lvalue > 0x00ffffff) { + valueRangeValid = false; + } } Symbol.Type symbolType = IsConstant ? Symbol.Type.Constant : Symbol.Type.ExternalAddr; @@ -328,6 +338,7 @@ namespace SourceGen.WpfGui { labelUniqueLabel.Foreground = projectLabelUniqueLabel.Foreground = labelUnique ? mDefaultLabelColor : Brushes.Red; valueNotesLabel.Foreground = valueValid ? mDefaultLabelColor : Brushes.Red; + addrValueRangeLabel.Foreground = valueRangeValid ? mDefaultLabelColor : Brushes.Red; varValueRangeLabel.Foreground = valueRangeValid ? mDefaultLabelColor : Brushes.Red; varValueUniqueLabel.Foreground = valueUniqueValid ? mDefaultLabelColor : Brushes.Red; widthNotesLabel.Foreground = widthValid ? mDefaultLabelColor : Brushes.Red;