mirror of
https://github.com/fadden/6502bench.git
synced 2024-11-29 10:50:28 +00:00
Add "Copy to Operand" button to instruction operand editor
It's possible to define multiple project symbols with the same address. The way to resolve the ambiguity is to explicitly reference the desired symbol from the operand. This was the default behavior of the "create project symbol" shortcut in the previous version. It's rarely necessary, and it can get ugly if you rename a project symbol, because we don't refactor operands in that case.
This commit is contained in:
parent
62b7655a1c
commit
44c140a8d0
@ -95,7 +95,8 @@ set, or editing a local variable table.</p>
|
||||
<h3><a name="shortcut-nar">Numeric Address References</a></h3>
|
||||
|
||||
<p>For operands that are 8-bit, 16-bit, or 24-bit addresses, you can
|
||||
define a symbol for the address as a label or project symbol.</p>
|
||||
define a symbol for the address as a label or
|
||||
<a href="intro.html#symbol-types">project symbol</a>.</p>
|
||||
<p>If the operand is an address inside the project, you can set a
|
||||
label at that address. If the address falls in the middle of an
|
||||
instruction or multi-byte data item, its position will be adjusted to
|
||||
@ -103,16 +104,30 @@ the start. Labels may be created, modified, or (by erasing the label)
|
||||
deleted.</p>
|
||||
<p>The label finder does not do the optional search for "nearby" labels
|
||||
that the main analyzer does, so there will be times when an instruction
|
||||
that is shown with a symbol in the code list won't have a label
|
||||
that is shown with a symbol in the code list won't have a symbol
|
||||
in the editor.</p>
|
||||
|
||||
<p>If the operand is an address outside the project, e.g. a ROM
|
||||
address or frame buffer, you can define a project symbol. If a
|
||||
address or I/O location, you can define a project symbol. If a
|
||||
match was found in the configured platform definition files, it will be
|
||||
shown; it can't be edited, but it can be overridden by a project symbol.
|
||||
You can create or modify a project symbol, but you can't delete one
|
||||
from this editor (use Project Properties instead). If more than one
|
||||
project symbol has the same address, the first one found will be used.</p>
|
||||
You can create or modify a project symbol by clicking on "Create Project
|
||||
Symbol" or "Edit Project Symbol". You can't delete project symbols
|
||||
from this editor (use Project Properties instead).</p>
|
||||
|
||||
<p>It's possible to have more than one project symbol for the same
|
||||
address. For example, on the Apple II, reading from the memory-mapped
|
||||
I/O address $C000 returns the last key pressed, but writing to it
|
||||
changes the state of the 80-column display hardware, so it's useful to
|
||||
have two different names for it. If more than one project symbol has the
|
||||
same address, the first one found will be used, which may not be
|
||||
what is desired. In such situations, you should create the project
|
||||
symbol and then copy the symbol name into the operand. You can do this
|
||||
in one step by clicking the "Copy to Operand" button.
|
||||
(In most cases you don't want to do this, because if the project
|
||||
symbol is deleted or renamed, you'll have operands that refer to a
|
||||
nonexistent symbol. Unlike labels, project symbol renames do not
|
||||
refactor the rest of the project.)
|
||||
|
||||
<h3><a name="shortcut-local-var">Local Variable References</a></h3>
|
||||
|
||||
|
@ -426,7 +426,7 @@ MYSTRING .STR "hello"
|
||||
</pre>
|
||||
<p>See <a href="#symbol-parts">Parts and Adjustments</a> for more details.</p>
|
||||
|
||||
<h4>Symbol Types</h4>
|
||||
<h4><a name="symbol-types">Symbol Types</a></h4>
|
||||
|
||||
<p><b>Platform symbols</b> are defined in platform symbol files. These
|
||||
are named with a ".sym65" extension, and have a fairly straightforward
|
||||
|
@ -24,7 +24,8 @@ limitations under the License.
|
||||
Title="Edit Symbol"
|
||||
SizeToContent="WidthAndHeight" ResizeMode="NoResize"
|
||||
ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
||||
Loaded="Window_Loaded">
|
||||
Loaded="Window_Loaded"
|
||||
ContentRendered="Window_ContentRendered">
|
||||
<Grid Margin="8">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
|
@ -185,6 +185,11 @@ namespace SourceGen.WpfGui {
|
||||
UpdateControls();
|
||||
}
|
||||
|
||||
private void Window_ContentRendered(object sender, EventArgs e) {
|
||||
labelTextBox.SelectAll();
|
||||
labelTextBox.Focus();
|
||||
}
|
||||
|
||||
private void UpdateControls() {
|
||||
if (!IsLoaded) {
|
||||
return;
|
||||
|
@ -190,6 +190,9 @@ limitations under the License.
|
||||
<Button Width="150" Margin="0,8,0,0" HorizontalAlignment="Left"
|
||||
Content="{Binding CreateEditProjectSymbolText, FallbackValue=Diddle Project Symbol}"
|
||||
Click="EditProjectSymbol_Click"/>
|
||||
<Button Width="150" Margin="0,8,0,0" HorizontalAlignment="Left"
|
||||
Content="Copy to Operand" IsEnabled="{Binding IsCopyToOperandEnabled}"
|
||||
Click="CopyToOperandButton_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
|
@ -19,7 +19,6 @@ using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
using Asm65;
|
||||
|
||||
@ -222,6 +221,21 @@ namespace SourceGen.WpfGui {
|
||||
DialogResult = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up the symbol in the symbol table. If not found there, it checks for a
|
||||
/// match against the existing or edited project symbol.
|
||||
/// </summary>
|
||||
private bool LookupSymbol(string label, out Symbol sym) {
|
||||
if (mProject.SymbolTable.TryGetValue(label, out sym)) {
|
||||
return true;
|
||||
}
|
||||
if (mEditedProjectSymbol != null && label.Equals(mEditedProjectSymbol.Label)) {
|
||||
sym = mEditedProjectSymbol;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the state of the UI controls as the user interacts with the dialog.
|
||||
/// </summary>
|
||||
@ -242,7 +256,7 @@ namespace SourceGen.WpfGui {
|
||||
if (!Asm65.Label.ValidateLabel(SymbolLabel)) {
|
||||
SymbolValueHex = SYMBOL_INVALID;
|
||||
IsValid = false;
|
||||
} else if (mProject.SymbolTable.TryGetValue(SymbolLabel, out Symbol sym)) {
|
||||
} else if (LookupSymbol(SymbolLabel, out Symbol sym)) {
|
||||
if (sym.SymbolSource == Symbol.Source.Auto) {
|
||||
// We try to block references to auto labels, but it's possible to get
|
||||
// around it because FormatDescriptors are weak references (replace auto
|
||||
@ -272,6 +286,7 @@ namespace SourceGen.WpfGui {
|
||||
}
|
||||
|
||||
UpdatePreview();
|
||||
UpdateCopyToOperand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -350,7 +365,7 @@ namespace SourceGen.WpfGui {
|
||||
sb.Append(mFormatter.FormatCharacterValue(operandValue, enc));
|
||||
break;
|
||||
case FormatDescriptor.SubType.Symbol:
|
||||
if (mProject.SymbolTable.TryGetValue(dfd.SymbolRef.Label, out Symbol sym)) {
|
||||
if (LookupSymbol(dfd.SymbolRef.Label, out Symbol sym)) {
|
||||
// Block move is a little weird. "MVN label1,label2" is supposed to use
|
||||
// the bank byte, while "MVN #const1,#const2" uses the entire symbol.
|
||||
// The easiest thing to do is require the user to specify the "bank"
|
||||
@ -784,11 +799,21 @@ namespace SourceGen.WpfGui {
|
||||
}
|
||||
private string mCreateEditProjectSymbolText;
|
||||
|
||||
public bool IsCopyToOperandEnabled {
|
||||
get { return mIsCopyToOperandEnabled; }
|
||||
set { mIsCopyToOperandEnabled = value; OnPropertyChanged(); }
|
||||
}
|
||||
private bool mIsCopyToOperandEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Edited label value. Will be null if the label hasn't been created, or has been
|
||||
/// deleted (by entering a blank string in the label edit box).
|
||||
/// </summary>
|
||||
private Symbol mEditedLabel;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if the label has been edited.
|
||||
/// </summary>
|
||||
private bool mLabelHasBeenEdited;
|
||||
|
||||
/// <summary>
|
||||
@ -802,9 +827,13 @@ namespace SourceGen.WpfGui {
|
||||
private int mEditedLabelOffset = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Edited project symbol. Will be null if the symbol doesn't exist. Symbols can't
|
||||
/// be deleted.
|
||||
/// Edited project symbol. If a symbol already exists, this will be initialized to the
|
||||
/// existing value. Otherwise this will be null.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Project symbols can't be deleted from here, so a null reference always means that
|
||||
/// there's no symbol and we haven't made an edit.
|
||||
/// </remarks>
|
||||
private DefSymbol mEditedProjectSymbol;
|
||||
|
||||
/// <summary>
|
||||
@ -886,6 +915,17 @@ namespace SourceGen.WpfGui {
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCopyToOperand() {
|
||||
IsCopyToOperandEnabled = false;
|
||||
if (mEditedProjectSymbol != null) {
|
||||
// We have a pre-existing or recently-edited symbol. See if the current
|
||||
// operand configuration already matches.
|
||||
if (!FormatSymbol || !mEditedProjectSymbol.Label.Equals(SymbolLabel)) {
|
||||
IsCopyToOperandEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EditLabel_Click(object sender, RoutedEventArgs e) {
|
||||
EditLabel dlg = new EditLabel(this, mEditedLabel, mLabelTargetAddress,
|
||||
mProject.SymbolTable);
|
||||
@ -937,6 +977,17 @@ namespace SourceGen.WpfGui {
|
||||
ShowNarNoProjectMatch = false;
|
||||
NarProjectSymbol = mEditedProjectSymbol.Label;
|
||||
CreateEditProjectSymbolText = EDIT_PROJECT_SYMBOL;
|
||||
|
||||
// The preview and symbol value display will use mEditedProjectSymbol if it's the
|
||||
// only place the symbol exists, so we want to keep the other controls updated.
|
||||
UpdateControls();
|
||||
}
|
||||
|
||||
private void CopyToOperandButton_Click(object sender, RoutedEventArgs e) {
|
||||
FormatSymbol = true;
|
||||
SymbolLabel = mEditedProjectSymbol.Label;
|
||||
IsCopyToOperandEnabled = false;
|
||||
// changes to controls will call UpdateControls() for us
|
||||
}
|
||||
|
||||
#endregion Numeric References
|
||||
|
Loading…
Reference in New Issue
Block a user