2019-07-05 21:53:45 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2019 faddenSoft
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
|
|
|
using Asm65;
|
|
|
|
|
|
2019-07-20 20:28:10 +00:00
|
|
|
|
namespace SourceGen.WpfGui {
|
2019-07-05 21:53:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Symbol edit dialog.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class EditDefSymbol : Window, INotifyPropertyChanged {
|
|
|
|
|
/// <summary>
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// Result; will be set non-null on OK.
|
2019-07-05 21:53:45 +00:00
|
|
|
|
/// </summary>
|
2019-08-26 00:25:15 +00:00
|
|
|
|
public DefSymbol NewSym { get; private set; }
|
2019-07-05 21:53:45 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set to true when all fields are valid. Controls whether the OK button is enabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsValid {
|
|
|
|
|
get { return mIsValid; }
|
2019-08-26 00:25:15 +00:00
|
|
|
|
set { mIsValid = value; OnPropertyChanged(); }
|
2019-07-05 21:53:45 +00:00
|
|
|
|
}
|
|
|
|
|
private bool mIsValid;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
public string Label {
|
|
|
|
|
get { return mLabel; }
|
|
|
|
|
set { mLabel = value; OnPropertyChanged(); UpdateControls(); }
|
|
|
|
|
}
|
|
|
|
|
private string mLabel;
|
|
|
|
|
|
|
|
|
|
public string Value {
|
|
|
|
|
get { return mValue; }
|
|
|
|
|
set { mValue = value; OnPropertyChanged(); UpdateControls(); }
|
|
|
|
|
}
|
|
|
|
|
private string mValue;
|
|
|
|
|
|
|
|
|
|
public string VarWidth {
|
|
|
|
|
get { return mWidth; }
|
|
|
|
|
set { mWidth = value; OnPropertyChanged(); UpdateControls(); }
|
|
|
|
|
}
|
|
|
|
|
private string mWidth;
|
|
|
|
|
|
|
|
|
|
public string Comment {
|
|
|
|
|
get { return mComment; }
|
|
|
|
|
set { mComment = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
private string mComment;
|
|
|
|
|
|
2019-08-29 00:34:29 +00:00
|
|
|
|
public bool IsAddress {
|
|
|
|
|
get { return mIsAddress; }
|
|
|
|
|
set { mIsAddress = value; OnPropertyChanged(); UpdateControls(); }
|
|
|
|
|
}
|
|
|
|
|
private bool mIsAddress;
|
|
|
|
|
|
|
|
|
|
public bool IsConstant {
|
|
|
|
|
get { return mIsConstant; }
|
|
|
|
|
set { mIsConstant = value; OnPropertyChanged(); UpdateControls(); }
|
|
|
|
|
}
|
|
|
|
|
private bool mIsConstant;
|
|
|
|
|
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
public bool ReadOnlyValueAndType {
|
|
|
|
|
get { return mReadOnlyValueAndType; }
|
|
|
|
|
set { mReadOnlyValueAndType = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
public bool NotReadOnlyValueAndType {
|
|
|
|
|
get { return !mReadOnlyValueAndType; }
|
|
|
|
|
}
|
|
|
|
|
private bool mReadOnlyValueAndType;
|
|
|
|
|
|
2019-07-05 21:53:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Format object to use when formatting addresses and constants.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Formatter mNumFormatter;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Old symbol value. May be null.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private DefSymbol mOldSym;
|
|
|
|
|
|
2019-07-05 21:53:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// List of existing symbols, for uniqueness check. The list will not be modified.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private SortedList<string, DefSymbol> mDefSymbolList;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Full symbol table, for extended uniqueness check.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private SymbolTable mSymbolTable;
|
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set to true if we should create a Variable rather than a project symbol.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool mIsVariable;
|
|
|
|
|
|
2019-07-05 21:53:45 +00:00
|
|
|
|
// Saved off at dialog load time.
|
|
|
|
|
private Brush mDefaultLabelColor;
|
|
|
|
|
|
|
|
|
|
// INotifyPropertyChanged implementation
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// <summary>
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
/// Constructor, for editing a project or platform symbol.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public EditDefSymbol(Window owner, Formatter formatter,
|
|
|
|
|
SortedList<string, DefSymbol> defList, DefSymbol defSym,
|
|
|
|
|
SymbolTable symbolTable)
|
|
|
|
|
: this(owner, formatter, defList, defSym, symbolTable, false, false) { }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-08 23:41:54 +00:00
|
|
|
|
/// Constructor, for editing a local variable, or editing a project symbol with
|
|
|
|
|
/// the value field locked.
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// </summary>
|
2019-07-05 21:53:45 +00:00
|
|
|
|
public EditDefSymbol(Window owner, Formatter formatter,
|
2019-08-26 23:58:53 +00:00
|
|
|
|
SortedList<string, DefSymbol> defList, DefSymbol defSym,
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
SymbolTable symbolTable, bool isVariable, bool lockValueAndType) {
|
2019-07-05 21:53:45 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
Owner = owner;
|
|
|
|
|
DataContext = this;
|
|
|
|
|
|
|
|
|
|
mNumFormatter = formatter;
|
|
|
|
|
mDefSymbolList = defList;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
mOldSym = defSym;
|
|
|
|
|
mSymbolTable = symbolTable;
|
2019-08-26 23:58:53 +00:00
|
|
|
|
mIsVariable = isVariable;
|
Instruction operand editor rework, part 2
Implemented local variable editing. Operands that have a local
variable reference, or are eligible to have one, can now be edited
directly from the instruction operand edit dialog.
Also, updated the code list double-click handler so that, if you
double-click on the opcode of an instruction that uses a local
variable reference, the selection and view will jump to the place
where that variable was defined.
Also, tweaked the way the References window refers to references
to an address that didn't use a symbol at that address. Updated
the explanation in the manual, which was a bit confusing.
Also, fixed some odds and ends in the manual.
Also, fixed a nasty infinite recursion bug (issue #47).
2019-09-08 01:57:22 +00:00
|
|
|
|
mReadOnlyValueAndType = lockValueAndType;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
Label = Value = VarWidth = Comment = string.Empty;
|
|
|
|
|
if (isVariable) {
|
|
|
|
|
widthEntry1.Visibility = widthEntry2.Visibility = labelUniqueLabel.Visibility =
|
|
|
|
|
Visibility.Visible;
|
|
|
|
|
projectLabelUniqueLabel.Visibility = Visibility.Collapsed;
|
|
|
|
|
} else {
|
|
|
|
|
widthEntry1.Visibility = widthEntry2.Visibility = labelUniqueLabel.Visibility =
|
|
|
|
|
Visibility.Collapsed;
|
|
|
|
|
labelUniqueLabel.Visibility = Visibility.Collapsed;
|
2019-08-29 00:34:29 +00:00
|
|
|
|
valueRangeLabel.Visibility = valueUniqueLabel.Visibility = Visibility.Collapsed;
|
2019-08-26 23:58:53 +00:00
|
|
|
|
}
|
2019-07-05 21:53:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
|
|
|
|
mDefaultLabelColor = labelNotesLabel.Foreground;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
if (mOldSym != null) {
|
|
|
|
|
Label = mOldSym.Label;
|
|
|
|
|
Value = mNumFormatter.FormatValueInBase(mOldSym.Value,
|
|
|
|
|
mOldSym.DataDescriptor.NumBase);
|
2019-08-26 23:58:53 +00:00
|
|
|
|
VarWidth = mOldSym.DataDescriptor.Length.ToString();
|
2019-08-26 00:25:15 +00:00
|
|
|
|
Comment = mOldSym.Comment;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
if (mOldSym.SymbolType == Symbol.Type.Constant) {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
IsConstant = true;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
} else {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
IsAddress = true;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
IsAddress = true;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labelTextBox.Focus();
|
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-15 00:48:54 +00:00
|
|
|
|
private void Window_ContentRendered(object sender, EventArgs e) {
|
|
|
|
|
labelTextBox.SelectAll();
|
|
|
|
|
labelTextBox.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 21:53:45 +00:00
|
|
|
|
private void UpdateControls() {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
if (!IsLoaded) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-07-05 21:53:45 +00:00
|
|
|
|
|
2019-08-31 01:33:05 +00:00
|
|
|
|
// Label must be valid and not already exist in the table we're editing. (For project
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// symbols, it's okay if an identical label exists elsewhere.)
|
|
|
|
|
bool labelValid = Asm65.Label.ValidateLabel(Label);
|
|
|
|
|
bool labelUnique;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
|
2019-08-29 00:34:29 +00:00
|
|
|
|
// NOTE: should be using Asm65.Label.LABEL_COMPARER?
|
2019-08-26 00:25:15 +00:00
|
|
|
|
if (mDefSymbolList.TryGetValue(Label, out DefSymbol existing)) {
|
2019-07-05 21:53:45 +00:00
|
|
|
|
// It's okay if it's the same object.
|
2019-08-26 00:25:15 +00:00
|
|
|
|
labelUnique = (existing == mOldSym);
|
2019-07-05 21:53:45 +00:00
|
|
|
|
} else {
|
|
|
|
|
labelUnique = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 00:34:29 +00:00
|
|
|
|
// For local variables, do a secondary uniqueness check across the full symbol table.
|
2019-08-26 00:25:15 +00:00
|
|
|
|
if (labelUnique && mSymbolTable != null) {
|
|
|
|
|
labelUnique = !mSymbolTable.TryGetValue(Label, out Symbol sym);
|
2019-08-31 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
// It's okay if this and the other are both variables.
|
|
|
|
|
if (!labelUnique && mIsVariable && sym.IsVariable) {
|
|
|
|
|
labelUnique = true;
|
|
|
|
|
}
|
2019-08-26 00:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 21:53:45 +00:00
|
|
|
|
// Value must be blank, meaning "erase any earlier definition", or valid value.
|
|
|
|
|
// (Hmm... don't currently have a way to specify "no symbol" in DefSymbol.)
|
|
|
|
|
//if (!string.IsNullOrEmpty(valueTextBox.Text)) {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
bool valueValid = ParseValue(out int thisValue, out int unused2);
|
2019-07-05 21:53:45 +00:00
|
|
|
|
//} else {
|
|
|
|
|
// valueValid = true;
|
|
|
|
|
//}
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
bool widthValid = true;
|
2019-08-29 00:34:29 +00:00
|
|
|
|
int thisWidth = 0;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
if (widthEntry1.Visibility == Visibility.Visible) {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
if (!int.TryParse(VarWidth, out thisWidth) ||
|
|
|
|
|
thisWidth < DefSymbol.MIN_WIDTH || thisWidth > DefSymbol.MAX_WIDTH) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
widthValid = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:32:45 +00:00
|
|
|
|
bool valueRangeValid = true;
|
|
|
|
|
if (mIsVariable && valueValid && widthValid) {
|
|
|
|
|
// $ff with width 1 is okay, $ff with width 2 is not
|
|
|
|
|
if (thisValue < 0 || thisValue + thisWidth > 256) {
|
|
|
|
|
valueRangeValid = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 00:34:29 +00:00
|
|
|
|
Symbol.Type symbolType = IsConstant ? Symbol.Type.Constant : Symbol.Type.ExternalAddr;
|
|
|
|
|
|
|
|
|
|
// For a variable, the value must also be unique within the table. Values have
|
|
|
|
|
// width, so we need to check for overlap.
|
|
|
|
|
bool valueUniqueValid = true;
|
|
|
|
|
if (mIsVariable && valueValid && widthValid) {
|
|
|
|
|
foreach (KeyValuePair<string, DefSymbol> kvp in mDefSymbolList) {
|
2019-09-01 03:32:43 +00:00
|
|
|
|
if (kvp.Value != mOldSym &&
|
|
|
|
|
DefSymbol.CheckOverlap(kvp.Value, thisValue, thisWidth, symbolType)) {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
valueUniqueValid = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 21:53:45 +00:00
|
|
|
|
labelNotesLabel.Foreground = labelValid ? mDefaultLabelColor : Brushes.Red;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
labelUniqueLabel.Foreground = projectLabelUniqueLabel.Foreground =
|
|
|
|
|
labelUnique ? mDefaultLabelColor : Brushes.Red;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
valueNotesLabel.Foreground = valueValid ? mDefaultLabelColor : Brushes.Red;
|
2019-08-27 23:45:37 +00:00
|
|
|
|
valueRangeLabel.Foreground = valueRangeValid ? mDefaultLabelColor : Brushes.Red;
|
2019-08-29 00:34:29 +00:00
|
|
|
|
valueUniqueLabel.Foreground = valueUniqueValid ? mDefaultLabelColor : Brushes.Red;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
widthNotesLabel.Foreground = widthValid ? mDefaultLabelColor : Brushes.Red;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
|
2019-08-29 00:34:29 +00:00
|
|
|
|
IsValid = labelValid && labelUnique && valueValid && valueRangeValid &&
|
|
|
|
|
valueUniqueValid && widthValid;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ParseValue(out int value, out int numBase) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
string str = Value;
|
2019-07-05 21:53:45 +00:00
|
|
|
|
if (str.IndexOf('/') >= 0) {
|
|
|
|
|
// treat as address
|
|
|
|
|
numBase = 16;
|
|
|
|
|
return Asm65.Address.ParseAddress(str, (1 << 24) - 1, out value);
|
|
|
|
|
} else {
|
|
|
|
|
return Asm65.Number.TryParseInt(str, out value, out numBase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OkButton_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
ParseValue(out int value, out int numBase);
|
|
|
|
|
FormatDescriptor.SubType subType = FormatDescriptor.GetSubTypeForBase(numBase);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
int width = DefSymbol.NO_WIDTH;
|
|
|
|
|
if (!string.IsNullOrEmpty(VarWidth)) {
|
|
|
|
|
width = int.Parse(VarWidth);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
NewSym = new DefSymbol(Label, value,
|
2019-08-29 00:34:29 +00:00
|
|
|
|
mIsVariable ? Symbol.Source.Variable : Symbol.Source.Project,
|
|
|
|
|
IsConstant ? Symbol.Type.Constant : Symbol.Type.ExternalAddr,
|
2019-08-26 00:25:15 +00:00
|
|
|
|
subType, Comment, string.Empty, width);
|
2019-07-05 21:53:45 +00:00
|
|
|
|
|
|
|
|
|
DialogResult = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|