2019-08-25 21:14:44 +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.ObjectModel;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
using Asm65;
|
|
|
|
|
using CommonWPF;
|
|
|
|
|
|
2019-08-25 21:14:44 +00:00
|
|
|
|
namespace SourceGen.WpfGui {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Edit a LocalVariableTable.
|
|
|
|
|
/// </summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
public partial class EditLocalVariableTable : Window, INotifyPropertyChanged {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// <summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
/// Output. Will be null if the table was deleted, or if cancel was hit while
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// creating a new table.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public LocalVariableTable NewTable { get; private set; }
|
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Output. If the table was moved, the new offset will be different from the old.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int NewOffset { get; private set; }
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// Item for the symbol list view ItemsSource.
|
2019-08-25 21:14:44 +00:00
|
|
|
|
public class FormattedSymbol {
|
|
|
|
|
public string Label { get; private set; }
|
|
|
|
|
public string Value { get; private set; }
|
|
|
|
|
public string Type { get; private set; }
|
|
|
|
|
public string Width { get; private set; }
|
|
|
|
|
public string Comment { get; private set; }
|
|
|
|
|
|
|
|
|
|
public FormattedSymbol(string label, string value, string type, string width,
|
|
|
|
|
string comment) {
|
|
|
|
|
Label = label;
|
|
|
|
|
Value = value;
|
|
|
|
|
Type = type;
|
|
|
|
|
Width = width;
|
|
|
|
|
Comment = comment;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public ObservableCollection<FormattedSymbol> Variables { get; private set; } =
|
|
|
|
|
new ObservableCollection<FormattedSymbol>();
|
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clear-previous flag.
|
|
|
|
|
/// </summary>
|
2019-08-26 00:25:15 +00:00
|
|
|
|
public bool ClearPrevious {
|
|
|
|
|
get { return mWorkTable.ClearPrevious; }
|
|
|
|
|
set { mWorkTable.ClearPrevious = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if this is not a new table. (Using "not" because that's the sense we
|
|
|
|
|
/// need in XAML.)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsNotNewTable {
|
|
|
|
|
get { return mIsNotNewTable; }
|
|
|
|
|
set { mIsNotNewTable = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
private bool mIsNotNewTable;
|
|
|
|
|
|
2019-09-19 22:53:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Table header text string, formatted at load time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string TableHeaderText {
|
|
|
|
|
get { return mTableHeaderText; }
|
|
|
|
|
set { mTableHeaderText = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
private string mTableHeaderText;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Working set. Used internally to hold state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private LocalVariableTable mWorkTable;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
/// Project reference.
|
2019-08-26 00:25:15 +00:00
|
|
|
|
/// </summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
private DisasmProject mProject;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Format object to use when formatting addresses and constants.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Formatter mFormatter;
|
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Symbol table for uniqueness check.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private SymbolTable mSymbolTable;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Table offset, for move ops.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int mOffset;
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// INotifyPropertyChanged implementation
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor. lvt will be null when creating a new entry.
|
|
|
|
|
/// </summary>
|
2019-09-01 23:40:54 +00:00
|
|
|
|
public EditLocalVariableTable(Window owner, DisasmProject project, Formatter formatter,
|
|
|
|
|
LocalVariableTable lvt, int offset) {
|
2019-08-25 21:14:44 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
Owner = owner;
|
|
|
|
|
DataContext = this;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
mProject = project;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
mFormatter = formatter;
|
2019-09-01 23:40:54 +00:00
|
|
|
|
mSymbolTable = project.SymbolTable;
|
|
|
|
|
mOffset = NewOffset = offset;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
|
|
|
|
if (lvt != null) {
|
|
|
|
|
mWorkTable = new LocalVariableTable(lvt);
|
2019-08-26 23:58:53 +00:00
|
|
|
|
mIsNotNewTable = true;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
mWorkTable = new LocalVariableTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LoadVariables();
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Window_Loaded(object sender, RoutedEventArgs e) {
|
2019-09-19 22:53:23 +00:00
|
|
|
|
string fmt = (string)FindResource("str_TableHeaderFmt");
|
|
|
|
|
TableHeaderText = string.Format(fmt, mFormatter.FormatOffset24(mOffset));
|
|
|
|
|
|
2019-08-26 00:25:15 +00:00
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads entries from the work table into the items source.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void LoadVariables() {
|
|
|
|
|
Variables.Clear();
|
|
|
|
|
|
2019-08-29 00:34:29 +00:00
|
|
|
|
for (int i = 0; i < mWorkTable.Count; i++) {
|
|
|
|
|
DefSymbol defSym = mWorkTable[i];
|
2019-08-26 00:25:15 +00:00
|
|
|
|
string typeStr;
|
|
|
|
|
if (defSym.SymbolType == Symbol.Type.Constant) {
|
Allow explicit widths in project/platform symbols, part 1
The ability to give explicit widths to local variables worked out
pretty well, so we're going to try adding the same thing to project
and platform symbols.
The first step is to allow widths to be specified in platform files,
and set with the project symbol editor. The DefSymbol editor is
also used for local variables, so a bit of dancing is required.
For platform/project symbols the width is optional, and is totally
ignored for constants. (For variables, constants are used for the
StackRel args, so the width is meaningful and required.)
We also now show the symbol's type (address or constant) and width
in the listing. This gets really distracting when overused, so we
only show it when the width is explicitly set. The default width
is 1, which most things will be, so users can make an aesthetic
choice there. (The place where widths make very little sense is when
the symbol represents a code entry point, rather than a data item.)
The maximum width of a local variable is now 256, but it's not
allowed to overlap with other variables or run of the end of the
direct page. The maximum width of a platform/project symbol is
65536, with bank-wrap behavior TBD.
The local variable table editor now refers to stack-relative
constants as such, rather than simply "constant", to make it clear
that it's not just defining an 8-bit constant.
Widths have been added to a handful of Apple II platform defs.
2019-10-01 21:58:24 +00:00
|
|
|
|
typeStr = Res.Strings.ABBREV_STACK_RELATIVE;
|
2019-08-26 00:25:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
typeStr = Res.Strings.ABBREV_ADDRESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormattedSymbol fsym = new FormattedSymbol(
|
|
|
|
|
defSym.Label,
|
|
|
|
|
mFormatter.FormatValueInBase(defSym.Value, defSym.DataDescriptor.NumBase),
|
|
|
|
|
typeStr,
|
2019-08-26 23:58:53 +00:00
|
|
|
|
defSym.DataDescriptor.Length.ToString(),
|
2019-08-26 00:25:15 +00:00
|
|
|
|
defSym.Comment);
|
|
|
|
|
|
|
|
|
|
Variables.Add(fsym);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateControls() {
|
|
|
|
|
// Enable or disable the edit/remove buttons based on how many items are selected.
|
|
|
|
|
// (We're currently configured for single-select, so this is really just a != 0 test.)
|
|
|
|
|
int symSelCount = symbolsListView.SelectedItems.Count;
|
|
|
|
|
removeSymbolButton.IsEnabled = (symSelCount == 1);
|
|
|
|
|
editSymbolButton.IsEnabled = (symSelCount == 1);
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OkButton_Click(object sender, RoutedEventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
NewTable = mWorkTable;
|
2019-08-25 21:14:44 +00:00
|
|
|
|
DialogResult = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteTableButton_Click(object sender, RoutedEventArgs e) {
|
2019-08-26 23:58:53 +00:00
|
|
|
|
MessageBoxResult result = MessageBox.Show((string)FindResource("str_ConfirmDelete"),
|
|
|
|
|
(string)FindResource("str_ConfirmDeleteCaption"),
|
|
|
|
|
MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
|
|
if (result == MessageBoxResult.Yes) {
|
|
|
|
|
NewTable = null;
|
|
|
|
|
DialogResult = true;
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
private void MoveTableButton_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
EditLvTableLocation dlg = new EditLvTableLocation(this, mProject, mOffset, NewOffset);
|
|
|
|
|
if (dlg.ShowDialog() == true) {
|
|
|
|
|
NewOffset = dlg.NewOffset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-25 21:14:44 +00:00
|
|
|
|
private void SymbolsListView_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
UpdateControls();
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SymbolsListView_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
ListViewItem lvi = symbolsListView.GetClickedItem(e);
|
|
|
|
|
if (lvi == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormattedSymbol item = (FormattedSymbol)lvi.Content;
|
2019-08-29 00:34:29 +00:00
|
|
|
|
DefSymbol defSym = mWorkTable.GetByLabel(item.Label);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
DoEditSymbol(defSym);
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NewSymbolButton_Click(object sender, RoutedEventArgs e) {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
EditDefSymbol dlg = new EditDefSymbol(this, mFormatter, mWorkTable.GetSortedByLabel(),
|
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
|
|
|
|
null, mSymbolTable, true, false);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
if (dlg.DialogResult == true) {
|
|
|
|
|
Debug.WriteLine("ADD: " + dlg.NewSym);
|
2019-08-29 00:34:29 +00:00
|
|
|
|
mWorkTable.AddOrReplace(dlg.NewSym);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
|
|
|
|
|
// Reload the contents. This loses the selection, but that shouldn't be an
|
|
|
|
|
// issue when adding new symbols. To do this incrementally we'd need to add
|
|
|
|
|
// the symbol at the correct sorted position.
|
|
|
|
|
LoadVariables();
|
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EditSymbolButton_Click(object sender, EventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// Single-select list view, button dimmed when no selection.
|
|
|
|
|
Debug.Assert(symbolsListView.SelectedItems.Count == 1);
|
|
|
|
|
FormattedSymbol item = (FormattedSymbol)symbolsListView.SelectedItems[0];
|
2019-08-29 00:34:29 +00:00
|
|
|
|
DefSymbol defSym = mWorkTable.GetByLabel(item.Label);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
DoEditSymbol(defSym);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DoEditSymbol(DefSymbol defSym) {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
EditDefSymbol dlg = new EditDefSymbol(this, mFormatter, mWorkTable.GetSortedByLabel(),
|
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
|
|
|
|
defSym, mSymbolTable, true, false);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
if (dlg.DialogResult == true) {
|
|
|
|
|
// Label might have changed, so remove old before adding new.
|
2019-08-29 00:34:29 +00:00
|
|
|
|
mWorkTable.RemoveByLabel(defSym.Label);
|
|
|
|
|
mWorkTable.AddOrReplace(dlg.NewSym);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
LoadVariables();
|
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveSymbolButton_Click(object sender, RoutedEventArgs e) {
|
2019-08-26 00:25:15 +00:00
|
|
|
|
// Single-select list view, button dimmed when no selection.
|
|
|
|
|
Debug.Assert(symbolsListView.SelectedItems.Count == 1);
|
|
|
|
|
|
|
|
|
|
int selectionIndex = symbolsListView.SelectedIndex;
|
|
|
|
|
FormattedSymbol item = (FormattedSymbol)symbolsListView.SelectedItems[0];
|
2019-08-29 00:34:29 +00:00
|
|
|
|
mWorkTable.RemoveByLabel(item.Label);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
LoadVariables();
|
|
|
|
|
UpdateControls();
|
|
|
|
|
|
|
|
|
|
// Restore selection to the item that used to come after the one we just deleted,
|
|
|
|
|
// so you can hit "Remove" repeatedly to delete multiple items.
|
|
|
|
|
int newCount = symbolsListView.Items.Count;
|
|
|
|
|
if (selectionIndex >= newCount) {
|
|
|
|
|
selectionIndex = newCount - 1;
|
|
|
|
|
}
|
|
|
|
|
if (selectionIndex >= 0) {
|
|
|
|
|
symbolsListView.SelectedIndex = selectionIndex;
|
|
|
|
|
removeSymbolButton.Focus();
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|