mirror of
https://github.com/fadden/6502bench.git
synced 2026-04-20 04:16:47 +00:00
Make hex adjustment threshold configurable
We generate operand adjustments automatically, and output small values as decimal (e.g. LDA FOO-1) and large values as hex (e.g. LDA FOO+$1000). This change adds a setting for the threshold between small and large. The default setting is 8. The previous threshold was 255, which felt a bit high. (issue #176)
This commit is contained in:
+7
-1
@@ -48,6 +48,9 @@ namespace Asm65 {
|
||||
// display and source code generation.
|
||||
private const int DEFAULT_OPERAND_WRAP_LEN = 64;
|
||||
|
||||
// Threshold at which operand adjustments are expressed as hex rather than decimal.
|
||||
public const int DEFAULT_HEX_ADJ_THRESH = 8;
|
||||
|
||||
/// <summary>
|
||||
/// Various format configuration options. Fill one of these out and pass it to
|
||||
/// the Formatter constructor.
|
||||
@@ -123,6 +126,8 @@ namespace Asm65 {
|
||||
/// <summary>Character position at which operands wrap; 0 == default.</summary>
|
||||
public int OperandWrapLen { get; set; } = DEFAULT_OPERAND_WRAP_LEN;
|
||||
|
||||
public int HexAdjustmentThreshold { get; set; } = DEFAULT_HEX_ADJ_THRESH;
|
||||
|
||||
/// <summary>Add spaces between bytes in the Bytes column?</summary>
|
||||
public bool SpacesBetweenBytes { get; set; } = false; // "20edfd" vs. "20 ed fd"
|
||||
/// <summary>Use comma-separated hex values for dense hex format?</summary>
|
||||
@@ -191,6 +196,7 @@ namespace Asm65 {
|
||||
StringDelimiters = new DelimiterSet(src.StringDelimiters);
|
||||
|
||||
OperandWrapLen = src.OperandWrapLen;
|
||||
HexAdjustmentThreshold = src.HexAdjustmentThreshold;
|
||||
|
||||
SpacesBetweenBytes = src.SpacesBetweenBytes;
|
||||
CommaSeparatedDense = src.CommaSeparatedDense;
|
||||
@@ -859,7 +865,7 @@ namespace Asm65 {
|
||||
public string FormatAdjustment(int adjValue) {
|
||||
if (adjValue == 0) {
|
||||
return string.Empty;
|
||||
} else if (Math.Abs(adjValue) >= 256) {
|
||||
} else if (Math.Abs(adjValue) > mFormatConfig.HexAdjustmentThreshold) {
|
||||
// not using mHexPrefix here, since dec vs. hex matters
|
||||
if (adjValue < 0) {
|
||||
return "-$" + (-adjValue).ToString(mHexValueFormats[0]);
|
||||
|
||||
@@ -56,6 +56,7 @@ namespace SourceGen {
|
||||
public const string FMT_UPPER_OPERAND_XY = "fmt-upper-operand-xy";
|
||||
public const string FMT_ADD_SPACE_FULL_COMMENT = "fmt-add-space-full-comment";
|
||||
public const string FMT_OPERAND_WRAP_LEN = "fmt-operand-wrap-len";
|
||||
public const string FMT_HEX_ADJUSTMENT_THRESHOLD = "fmt-hex-adjustment-threshold";
|
||||
|
||||
public const string FMT_OPCODE_SUFFIX_ABS = "fmt-opcode-suffix-abs";
|
||||
public const string FMT_OPCODE_SUFFIX_LONG = "fmt-opcode-suffix-long";
|
||||
|
||||
@@ -528,6 +528,9 @@ namespace SourceGen.AsmGen {
|
||||
settings.GetBool(AppSettings.FMT_ADD_SPACE_FULL_COMMENT, true);
|
||||
config.OperandWrapLen =
|
||||
settings.GetInt(AppSettings.FMT_OPERAND_WRAP_LEN, 0);
|
||||
config.HexAdjustmentThreshold =
|
||||
settings.GetInt(AppSettings.FMT_HEX_ADJUSTMENT_THRESHOLD,
|
||||
Formatter.DEFAULT_HEX_ADJ_THRESH);
|
||||
config.SuppressImpliedAcc =
|
||||
settings.GetBool(AppSettings.SRCGEN_OMIT_IMPLIED_ACC_OPERAND, false);
|
||||
|
||||
|
||||
@@ -441,6 +441,7 @@ namespace SourceGen.Tests {
|
||||
settings.SetBool(AppSettings.FMT_UPPER_OPERAND_XY, false);
|
||||
settings.SetBool(AppSettings.FMT_ADD_SPACE_FULL_COMMENT, false);
|
||||
settings.SetInt(AppSettings.FMT_OPERAND_WRAP_LEN, 64);
|
||||
settings.SetInt(AppSettings.FMT_HEX_ADJUSTMENT_THRESHOLD, 255);
|
||||
|
||||
// Don't show the assembler ident line. You can make a case for this being
|
||||
// mandatory, since the generated code is only guaranteed to work with the
|
||||
|
||||
@@ -557,6 +557,22 @@ limitations under the License.
|
||||
SelectionChanged="OperandWrapLenComboBox_SelectionChanged"/>
|
||||
<TextBlock Text="characters" Margin="4,3,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="4,8,0,0">
|
||||
<TextBlock Text="Use hex for adjustments larger than"/>
|
||||
<TextBox Name="hexAdjThreshTextBox" Width="50" MaxLength="8" Margin="4,1,0,0"
|
||||
FontFamily="{StaticResource GeneralMonoFont}">
|
||||
<TextBox.Text>
|
||||
<Binding Path="HexAdjustmentThreshold" UpdateSourceTrigger="PropertyChanged"
|
||||
FallbackValue="255">
|
||||
<Binding.ValidationRules>
|
||||
<local:HexAdjThreshRule ValidatesOnTargetUpdated="True"/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<TextBlock Text=" (0-65535)" Margin="2,0,0,0"/>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
@@ -1005,6 +1005,34 @@ namespace SourceGen.WpfGui {
|
||||
|
||||
#region Display Format
|
||||
|
||||
public const int MIN_HEX_ADJ_THRESH = 0;
|
||||
public const int MAX_HEX_ADJ_THRESH = 65535;
|
||||
|
||||
//
|
||||
// Hex adjustment threshold. This is managed with a validation rule; see the notes in
|
||||
// the Asm Config section.
|
||||
//
|
||||
private int mHexAdjustmentThreshold;
|
||||
public int HexAdjustmentThreshold {
|
||||
get { return mHexAdjustmentThreshold; }
|
||||
set {
|
||||
if (mHexAdjustmentThreshold != value) {
|
||||
mHexAdjustmentThreshold = value;
|
||||
OnPropertyChanged();
|
||||
// Only accept the value if it's in the valid range. If not, use the default.
|
||||
int threshold;
|
||||
if (!Validation.GetHasError(hexAdjThreshTextBox)) {
|
||||
threshold = value;
|
||||
} else {
|
||||
threshold = Formatter.DEFAULT_HEX_ADJ_THRESH;
|
||||
}
|
||||
|
||||
mSettings.SetInt(AppSettings.FMT_HEX_ADJUSTMENT_THRESHOLD, threshold);
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string mOpcodeSuffixAbs;
|
||||
public string OpcodeSuffixAbs {
|
||||
get { return mOpcodeSuffixAbs; }
|
||||
@@ -1291,6 +1319,9 @@ namespace SourceGen.WpfGui {
|
||||
int wrapLen = mSettings.GetInt(AppSettings.FMT_OPERAND_WRAP_LEN, 0);
|
||||
SelectOperandWrapLen(wrapLen);
|
||||
|
||||
HexAdjustmentThreshold = mSettings.GetInt(AppSettings.FMT_HEX_ADJUSTMENT_THRESHOLD,
|
||||
Formatter.DEFAULT_HEX_ADJ_THRESH);
|
||||
|
||||
// No need to set this to anything specific.
|
||||
UpdateDisplayFormatQuickCombo();
|
||||
}
|
||||
@@ -1611,6 +1642,28 @@ namespace SourceGen.WpfGui {
|
||||
}
|
||||
}
|
||||
|
||||
public class HexAdjThreshRule : ValidationRule {
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
string strValue = Convert.ToString(value);
|
||||
if (string.IsNullOrEmpty(strValue)) {
|
||||
return new ValidationResult(false, "Could not convert to string");
|
||||
}
|
||||
|
||||
if (int.TryParse(strValue, out int result)) {
|
||||
if (result >= EditAppSettings.MIN_HEX_ADJ_THRESH &&
|
||||
result <= EditAppSettings.MAX_HEX_ADJ_THRESH) {
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
//Debug.WriteLine("VVV out of range: '" + strValue + "' (" + result + ")");
|
||||
return new ValidationResult(false, "Hex adjust thresh out of range");
|
||||
}
|
||||
|
||||
//Debug.WriteLine("VVV not valid integer: '" + strValue + "'");
|
||||
return new ValidationResult(false, "Invalid integer value: '" + strValue + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Text entry validation rule for text string delimiter patterns.
|
||||
|
||||
@@ -167,10 +167,16 @@ of the hex data in the code list "bytes" column from dense
|
||||
affects the format of clipboard copies and exports.</p>
|
||||
|
||||
<p>Long operands, such as strings and bulk data, are wrapped to a new
|
||||
line after a certain number of characters. Use the pop-up to configure
|
||||
the value. Larger values can make the code display more compact, but smaller
|
||||
values allow you to shrink the width of the operand column in the
|
||||
on-screen listing, moving the comment field closer in.</p>
|
||||
line after a certain number of characters. Use the <samp>wrap operands</samp>
|
||||
pop-up to configure the value. Larger values can make the code display more
|
||||
compact, but smaller values allow you to shrink the width of the operand
|
||||
column in the on-screen listing, moving the comment field closer in.</p>
|
||||
|
||||
<p>The adjustments that are generated for operands, such as <code>FOO-1</code>
|
||||
or <code>FOO+$1000</code>, can be output as hex or decimal depending
|
||||
on the magnitude of the adjustment. The
|
||||
<samp>use hex for adjustments larger than</samp>
|
||||
setting determines the threshold.</p>
|
||||
|
||||
|
||||
<h3 id="appset-pseudoop">Pseudo-Op</h3>
|
||||
|
||||
Reference in New Issue
Block a user