2019-05-05 23:50:28 +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.Diagnostics;
|
|
|
|
|
using System.IO;
|
2019-06-16 23:34:47 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web.Script.Serialization;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
using System.Windows;
|
2019-07-20 20:28:10 +00:00
|
|
|
|
using System.Windows.Input;
|
2020-07-22 17:53:54 +00:00
|
|
|
|
using System.Windows.Media;
|
2019-07-16 21:36:09 +00:00
|
|
|
|
using Microsoft.Win32;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
|
|
|
|
using Asm65;
|
|
|
|
|
using CommonUtil;
|
2019-06-19 23:31:56 +00:00
|
|
|
|
using CommonWPF;
|
2019-07-20 20:28:10 +00:00
|
|
|
|
using SourceGen.Sandbox;
|
|
|
|
|
using SourceGen.WpfGui;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-07-20 20:28:10 +00:00
|
|
|
|
namespace SourceGen {
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This class manages user interaction. The goal is for this to be relatively
|
|
|
|
|
/// GUI-toolkit-agnostic, with all the WPF stuff tucked into the code-behind files. An
|
|
|
|
|
/// instance of this class is created by MainWindow when the app starts.
|
|
|
|
|
///
|
|
|
|
|
/// There is some Windows-specific stuff, like MessageBox and OpenFileDialog.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MainController {
|
2019-06-19 23:31:56 +00:00
|
|
|
|
private const string SETTINGS_FILE_NAME = "SourceGen-settings";
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
#region Project state
|
|
|
|
|
|
|
|
|
|
// Currently open project, or null if none.
|
|
|
|
|
private DisasmProject mProject;
|
|
|
|
|
|
|
|
|
|
// Pathname to 65xx data file.
|
|
|
|
|
private string mDataPathName;
|
|
|
|
|
|
|
|
|
|
// Pathname of .dis65 file. This will be empty for a new project.
|
|
|
|
|
private string mProjectPathName;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-05-28 01:46:09 +00:00
|
|
|
|
/// Data backing the code list.
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// </summary>
|
2019-06-16 23:34:47 +00:00
|
|
|
|
public LineListGen CodeLineList { get; private set; }
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
|
|
|
|
#endregion Project state
|
|
|
|
|
|
|
|
|
|
|
2019-05-09 23:13:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reference back to MainWindow object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private MainWindow mMainWin;
|
|
|
|
|
|
2019-07-13 00:04:14 +00:00
|
|
|
|
/// <summary>
|
2019-07-15 01:12:03 +00:00
|
|
|
|
/// Hex dump viewer window. This is used for the currently open project.
|
2019-07-13 00:04:14 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
private Tools.WpfGui.HexDumpViewer mHexDumpDialog;
|
|
|
|
|
|
2019-07-16 00:18:28 +00:00
|
|
|
|
// Debug windows.
|
|
|
|
|
private Tools.WpfGui.ShowText mShowAnalysisTimersDialog;
|
2019-07-16 21:36:09 +00:00
|
|
|
|
public bool IsDebugAnalysisTimersOpen { get { return mShowAnalysisTimersDialog != null; } }
|
2019-07-16 00:18:28 +00:00
|
|
|
|
private Tools.WpfGui.ShowText mShowAnalyzerOutputDialog;
|
|
|
|
|
public bool IsDebugAnalyzerOutputOpen { get { return mShowAnalyzerOutputDialog != null; } }
|
|
|
|
|
private Tools.WpfGui.ShowText mShowUndoRedoHistoryDialog;
|
|
|
|
|
public bool IsDebugUndoRedoHistoryOpen { get { return mShowUndoRedoHistoryDialog != null; } }
|
|
|
|
|
|
2019-07-15 01:12:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This holds any un-owned Windows that we don't otherwise track. It's used for
|
|
|
|
|
/// hex dump windows of arbitrary files. We need to close them when the main window
|
|
|
|
|
/// is closed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<Window> mUnownedWindows = new List<Window>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ASCII chart reference window. Not tied to the project.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Tools.WpfGui.AsciiChart mAsciiChartDialog;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if the ASCII chart window is currently open.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsAsciiChartOpen { get { return mAsciiChartDialog != null; } }
|
|
|
|
|
|
2020-08-20 20:18:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Apple II screen chart window. Not tied to the project.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Tools.WpfGui.Apple2ScreenChart mApple2ScreenChartDialog;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if the ASCII chart window is currently open.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsApple2ScreenChartOpen { get { return mApple2ScreenChartDialog != null; } }
|
|
|
|
|
|
2019-10-21 22:15:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Instruction chart reference window. Not tied to the project.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Tools.WpfGui.InstructionChart mInstructionChartDialog;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if the instruction chart window is currently open.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsInstructionChartOpen { get { return mInstructionChartDialog != null; } }
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// List of recently-opened projects.
|
|
|
|
|
/// </summary>
|
2019-06-22 21:41:09 +00:00
|
|
|
|
public List<string> RecentProjectPaths = new List<string>(MAX_RECENT_PROJECTS);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
public const int MAX_RECENT_PROJECTS = 6;
|
|
|
|
|
|
2019-06-16 23:34:47 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Analyzed selection state, updated whenever the selection changes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public SelectionState SelectionAnalysis { get; set; }
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Activity log generated by the code and data analyzers. Displayed in window.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private DebugLog mGenerationLog;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Timing data generated during analysis.
|
|
|
|
|
/// </summary>
|
|
|
|
|
TaskTimer mReanalysisTimer = new TaskTimer();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stack for navigate forward/backward.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private NavStack mNavStack = new NavStack();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Output format configuration.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Formatter.FormatConfig mFormatterConfig;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Output format controller.
|
|
|
|
|
///
|
|
|
|
|
/// This is shared with the DisplayList.
|
|
|
|
|
/// </summary>
|
2019-12-30 01:59:35 +00:00
|
|
|
|
private Formatter mFormatter;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pseudo-op names.
|
|
|
|
|
///
|
|
|
|
|
/// This is shared with the DisplayList.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private PseudoOp.PseudoOpNames mPseudoOpNames;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// String we most recently searched for.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string mFindString = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initial start point of most recent search.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int mFindStartIndex = -1;
|
|
|
|
|
|
2019-10-10 00:41:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if previous search was backward, so we can tell if we changed direction
|
|
|
|
|
/// (otherwise we think we immediately wrapped around and the search stops).
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool mFindBackward = false;
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to highlight the line that is the target of the selected line.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int mTargetHighlightIndex = -1;
|
|
|
|
|
|
2021-11-17 19:18:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tracks the operands we have highlighted.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<int> mOperandHighlights = new List<int>();
|
|
|
|
|
|
2019-10-13 00:23:32 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Code list color scheme.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private MainWindow.ColorScheme mColorScheme = MainWindow.ColorScheme.Light;
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// CPU definition used when the Formatter was created. If the CPU choice or
|
|
|
|
|
/// inclusion of undocumented opcodes changes, we need to wipe the formatter.
|
|
|
|
|
/// </summary>
|
2019-12-30 01:59:35 +00:00
|
|
|
|
private CpuDef mFormatterCpuDef;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Instruction description object. Used for Info window.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private OpDescription mOpDesc = OpDescription.GetOpDescription(null);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If true, plugins will execute in the main application's AppDomain instead of
|
2020-07-18 20:47:01 +00:00
|
|
|
|
/// the sandbox (effectively disabling the security features).
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// </summary>
|
2020-07-18 20:47:01 +00:00
|
|
|
|
public bool UseMainAppDomainForPlugins { get; private set; }
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-07-07 00:24:42 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Code list column numbers.
|
|
|
|
|
/// </summary>
|
2019-06-27 00:11:58 +00:00
|
|
|
|
public enum CodeListColumn {
|
|
|
|
|
Offset = 0, Address, Bytes, Flags, Attributes, Label, Opcode, Operand, Comment,
|
|
|
|
|
COUNT // must be last; must equal number of columns
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clipboard format enumeration.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public enum ClipLineFormat {
|
|
|
|
|
Unknown = -1,
|
|
|
|
|
AssemblerSource = 0,
|
2019-09-12 20:57:52 +00:00
|
|
|
|
Disassembly = 1,
|
|
|
|
|
AllColumns = 2
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-08 00:17:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if a project is open and AnalyzeUncategorizedData is enabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsAnalyzeUncategorizedDataEnabled {
|
|
|
|
|
get {
|
|
|
|
|
if (mProject == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return mProject.ProjectProps.AnalysisParams.AnalyzeUncategorizedData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
#region Init and settings
|
|
|
|
|
|
2019-05-09 23:13:20 +00:00
|
|
|
|
public MainController(MainWindow win) {
|
|
|
|
|
mMainWin = win;
|
2019-07-08 20:40:28 +00:00
|
|
|
|
|
|
|
|
|
ScriptManager.UseKeepAliveHack = true;
|
2019-05-09 23:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Early initialization, before the window is visible. Notably, we want to get the
|
|
|
|
|
/// window placement data, so we can position and size the window before it's first
|
|
|
|
|
/// drawn (avoids a blink).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void WindowSourceInitialized() {
|
|
|
|
|
// Load the settings from the file. If this fails we have no way to tell the user,
|
|
|
|
|
// so just keep going.
|
|
|
|
|
LoadAppSettings();
|
2024-03-02 19:17:52 +00:00
|
|
|
|
SetAppWindowLocation(); // <-- this causes WindowLoaded to fire
|
2019-06-19 23:31:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 01:46:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Perform one-time initialization after the Window has finished loading. We defer
|
|
|
|
|
/// to this point so we can report fatal errors directly to the user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void WindowLoaded() {
|
2021-09-17 00:02:19 +00:00
|
|
|
|
// Run library unit tests.
|
|
|
|
|
Debug.Assert(CommonUtil.AddressMap.Test());
|
Allow explicit widths in project/platform symbols, part 3
Implement multi-byte project/platform symbols by filling out a table
of addresses. Each symbol is "painted" into the table, replacing
an existing entry if the new entry has higher priority. This allows
us to handle overlapping entries, giving boosted priority to platform
symbols that are defined in .sym65 files loaded later.
The bounds on project/platform symbols are now rigidly defined. If
the "nearby" feature is enabled, references to SYM-1 will be picked
up, but we won't go hunting for SYM+1 unless the symbol is at least
two bytes wide.
The cost of adding a symbol to the symbol table is about the same,
but we don't have a quick way to remove a symbol.
Previously, if two platform symbols had the same value, the symbol
with the alphabetically lowest label would win. Now, the symbol
defined in the most-recently-loaded file wins. (If you define two
symbols with the same value in the same file, it's still resolved
alphabetically.) This allows the user to pick the winner by
arranging the load order of the platform symbol files.
Platform symbols now keep a reference to the file ident of the
symbol file that defined them, so we can show the symbols's source
in the Info panel.
These changes altered the behavior of test 2008-address-changes,
which includes some tests on external addresses that are close to
labeled internal addresses. The previous behavior essentially
treated user labels as being 3 bytes wide and extending outside the
file bounds, which was mildly convenient on occasion but felt a
little skanky. (We could do with a way to define external symbols
relative to internal symbols, for things like the source address of
code that gets relocated.)
Also, re-enabled some unit tests.
Also, added a bit of identifying stuff to CrashLog.txt.
2019-10-02 23:26:05 +00:00
|
|
|
|
Debug.Assert(CommonUtil.RangeSet.Test());
|
|
|
|
|
Debug.Assert(CommonUtil.TypedRangeSet.Test());
|
|
|
|
|
Debug.Assert(CommonUtil.Version.Test());
|
2020-10-11 01:34:19 +00:00
|
|
|
|
Debug.Assert(Asm65.CpuDef.DebugValidate());
|
Allow explicit widths in project/platform symbols, part 3
Implement multi-byte project/platform symbols by filling out a table
of addresses. Each symbol is "painted" into the table, replacing
an existing entry if the new entry has higher priority. This allows
us to handle overlapping entries, giving boosted priority to platform
symbols that are defined in .sym65 files loaded later.
The bounds on project/platform symbols are now rigidly defined. If
the "nearby" feature is enabled, references to SYM-1 will be picked
up, but we won't go hunting for SYM+1 unless the symbol is at least
two bytes wide.
The cost of adding a symbol to the symbol table is about the same,
but we don't have a quick way to remove a symbol.
Previously, if two platform symbols had the same value, the symbol
with the alphabetically lowest label would win. Now, the symbol
defined in the most-recently-loaded file wins. (If you define two
symbols with the same value in the same file, it's still resolved
alphabetically.) This allows the user to pick the winner by
arranging the load order of the platform symbol files.
Platform symbols now keep a reference to the file ident of the
symbol file that defined them, so we can show the symbols's source
in the Info panel.
These changes altered the behavior of test 2008-address-changes,
which includes some tests on external addresses that are close to
labeled internal addresses. The previous behavior essentially
treated user labels as being 3 bytes wide and extending outside the
file bounds, which was mildly convenient on occasion but felt a
little skanky. (We could do with a way to define external symbols
relative to internal symbols, for things like the source address of
code that gets relocated.)
Also, re-enabled some unit tests.
Also, added a bit of identifying stuff to CrashLog.txt.
2019-10-02 23:26:05 +00:00
|
|
|
|
|
2019-05-28 01:46:09 +00:00
|
|
|
|
if (RuntimeDataAccess.GetDirectory() == null) {
|
|
|
|
|
MessageBox.Show(Res.Strings.RUNTIME_DIR_NOT_FOUND,
|
|
|
|
|
Res.Strings.RUNTIME_DIR_NOT_FOUND_CAPTION,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
PluginDllCache.PreparePluginDir();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
string pluginPath = PluginDllCache.GetPluginDirPath();
|
|
|
|
|
if (pluginPath == null) {
|
|
|
|
|
pluginPath = "<???>";
|
|
|
|
|
}
|
2019-06-19 23:31:56 +00:00
|
|
|
|
string msg = string.Format(Res.Strings.PLUGIN_DIR_FAIL_FMT,
|
2019-05-28 01:46:09 +00:00
|
|
|
|
pluginPath + ": " + ex.Message);
|
2019-06-19 23:31:56 +00:00
|
|
|
|
MessageBox.Show(msg, Res.Strings.PLUGIN_DIR_FAIL_CAPTION,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
Application.Current.Shutdown();
|
2019-05-28 01:46:09 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
// Place the main window and apply the various settings.
|
|
|
|
|
ApplyAppSettings();
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-07-16 21:36:09 +00:00
|
|
|
|
UpdateTitle();
|
2019-06-22 21:41:09 +00:00
|
|
|
|
mMainWin.UpdateRecentLinks();
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
ProcessCommandLine();
|
2019-07-07 23:18:46 +00:00
|
|
|
|
|
|
|
|
|
// Create an initial value.
|
|
|
|
|
SelectionAnalysis = UpdateSelectionState();
|
2019-06-19 23:31:56 +00:00
|
|
|
|
}
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
private void ProcessCommandLine() {
|
|
|
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
|
|
|
if (args.Length == 2) {
|
|
|
|
|
DoOpenFile(Path.GetFullPath(args[1]));
|
2019-05-28 01:46:09 +00:00
|
|
|
|
}
|
2019-06-19 23:31:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads settings from the settings file into AppSettings.Global. Does not apply
|
|
|
|
|
/// them to the ProjectView.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void LoadAppSettings() {
|
|
|
|
|
AppSettings settings = AppSettings.Global;
|
|
|
|
|
|
|
|
|
|
// Set some default settings for first-time use. The general rule is to set
|
|
|
|
|
// a default value of false, 0, or the empty string, so we only need to set
|
|
|
|
|
// values here when that isn't the case. The point at which the setting is
|
|
|
|
|
// actually used is expected to do something reasonable by default.
|
|
|
|
|
|
2024-08-02 20:47:39 +00:00
|
|
|
|
settings.SetInt(AppSettings.PROJ_AUTO_SAVE_INTERVAL, 60); // enabled by default
|
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SHOW_USER, true);
|
2019-11-16 04:40:14 +00:00
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SHOW_NON_UNIQUE, false);
|
2019-06-19 23:31:56 +00:00
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SHOW_PROJECT, true);
|
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SHOW_PLATFORM, false);
|
2021-10-05 03:41:19 +00:00
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SHOW_ADDR_PRE_LABELS, true);
|
2019-06-19 23:31:56 +00:00
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SHOW_AUTO, false);
|
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SHOW_ADDR, true);
|
2019-11-16 04:40:14 +00:00
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SHOW_CONST, true);
|
2019-06-19 23:31:56 +00:00
|
|
|
|
settings.SetBool(AppSettings.SYMWIN_SORT_ASCENDING, true);
|
|
|
|
|
settings.SetInt(AppSettings.SYMWIN_SORT_COL, (int)Symbol.SymbolSortField.Name);
|
|
|
|
|
|
|
|
|
|
settings.SetBool(AppSettings.FMT_UPPER_OPERAND_A, true);
|
|
|
|
|
settings.SetBool(AppSettings.FMT_UPPER_OPERAND_S, true);
|
|
|
|
|
settings.SetBool(AppSettings.FMT_ADD_SPACE_FULL_COMMENT, true);
|
2019-08-19 21:16:35 +00:00
|
|
|
|
settings.SetBool(AppSettings.FMT_SPACES_BETWEEN_BYTES, true);
|
2019-06-19 23:31:56 +00:00
|
|
|
|
settings.SetString(AppSettings.FMT_OPCODE_SUFFIX_LONG, "l");
|
|
|
|
|
settings.SetString(AppSettings.FMT_OPERAND_PREFIX_ABS, "a:");
|
|
|
|
|
settings.SetString(AppSettings.FMT_OPERAND_PREFIX_LONG, "f:");
|
|
|
|
|
|
|
|
|
|
settings.SetBool(AppSettings.SRCGEN_ADD_IDENT_COMMENT, true);
|
2024-04-21 22:30:11 +00:00
|
|
|
|
settings.SetEnum(AppSettings.SRCGEN_LABEL_NEW_LINE,
|
|
|
|
|
AsmGen.GenCommon.LabelPlacement.SplitIfTooLong);
|
2019-06-19 23:31:56 +00:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
settings.SetBool(AppSettings.DEBUG_MENU_ENABLED, true);
|
|
|
|
|
#else
|
|
|
|
|
settings.SetBool(AppSettings.DEBUG_MENU_ENABLED, false);
|
2019-05-28 01:46:09 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2019-06-27 00:11:58 +00:00
|
|
|
|
// Make sure we have entries for these.
|
|
|
|
|
settings.SetString(AppSettings.CDLV_FONT_FAMILY,
|
|
|
|
|
mMainWin.CodeListFontFamily.ToString());
|
|
|
|
|
settings.SetInt(AppSettings.CDLV_FONT_SIZE, (int)mMainWin.CodeListFontSize);
|
|
|
|
|
|
2019-08-14 22:25:09 +00:00
|
|
|
|
// Character and string delimiters.
|
|
|
|
|
Formatter.DelimiterSet chrDel = Formatter.DelimiterSet.GetDefaultCharDelimiters();
|
|
|
|
|
string chrSer = chrDel.Serialize();
|
|
|
|
|
settings.SetString(AppSettings.FMT_CHAR_DELIM, chrSer);
|
|
|
|
|
|
|
|
|
|
Formatter.DelimiterSet strDel = Formatter.DelimiterSet.GetDefaultStringDelimiters();
|
|
|
|
|
string strSer = strDel.Serialize();
|
|
|
|
|
settings.SetString(AppSettings.FMT_STRING_DELIM, strSer);
|
|
|
|
|
|
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
// Load the settings file, and merge it into the globals.
|
|
|
|
|
string runtimeDataDir = RuntimeDataAccess.GetDirectory();
|
|
|
|
|
if (runtimeDataDir == null) {
|
|
|
|
|
Debug.WriteLine("Unable to load settings file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string settingsDir = Path.GetDirectoryName(runtimeDataDir);
|
|
|
|
|
string settingsPath = Path.Combine(settingsDir, SETTINGS_FILE_NAME);
|
|
|
|
|
try {
|
|
|
|
|
string text = File.ReadAllText(settingsPath);
|
|
|
|
|
AppSettings fileSettings = AppSettings.Deserialize(text);
|
|
|
|
|
AppSettings.Global.MergeSettings(fileSettings);
|
|
|
|
|
Debug.WriteLine("Settings file loaded and merged");
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Debug.WriteLine("Unable to read settings file: " + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves AppSettings to a file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SaveAppSettings() {
|
|
|
|
|
if (!AppSettings.Global.Dirty) {
|
|
|
|
|
Debug.WriteLine("Settings not dirty, not saving");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
// Main window position and size.
|
|
|
|
|
AppSettings.Global.SetString(AppSettings.MAIN_WINDOW_PLACEMENT,
|
|
|
|
|
mMainWin.GetPlacement());
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
// Horizontal splitters.
|
|
|
|
|
AppSettings.Global.SetInt(AppSettings.MAIN_LEFT_PANEL_WIDTH,
|
|
|
|
|
(int)mMainWin.LeftPanelWidth);
|
|
|
|
|
AppSettings.Global.SetInt(AppSettings.MAIN_RIGHT_PANEL_WIDTH,
|
|
|
|
|
(int)mMainWin.RightPanelWidth);
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
// Vertical splitters.
|
2020-01-02 01:27:03 +00:00
|
|
|
|
//AppSettings.Global.SetInt(AppSettings.MAIN_REFERENCES_HEIGHT,
|
|
|
|
|
// (int)mMainWin.ReferencesPanelHeight);
|
|
|
|
|
//AppSettings.Global.SetInt(AppSettings.MAIN_SYMBOLS_HEIGHT,
|
|
|
|
|
// (int)mMainWin.SymbolsPanelHeight);
|
|
|
|
|
|
|
|
|
|
// Something peculiar happens when we switch from the launch window to the
|
|
|
|
|
// code list: the refs/notes splitter and sym/info splitter shift down a pixel.
|
|
|
|
|
// Closing the project causes everything to shift back. I'm not sure what's
|
|
|
|
|
// causing the layout to change. I'm working around the issue by not saving the
|
|
|
|
|
// splitter positions if they've only moved 1 pixel.
|
|
|
|
|
// TODO: fix this properly
|
|
|
|
|
int refSetting = AppSettings.Global.GetInt(AppSettings.MAIN_REFERENCES_HEIGHT, -1);
|
|
|
|
|
if ((int)mMainWin.ReferencesPanelHeight == refSetting ||
|
|
|
|
|
(int)mMainWin.ReferencesPanelHeight == refSetting - 1) {
|
|
|
|
|
Debug.WriteLine("NOT updating references height");
|
|
|
|
|
} else {
|
|
|
|
|
AppSettings.Global.SetInt(AppSettings.MAIN_REFERENCES_HEIGHT,
|
|
|
|
|
(int)mMainWin.ReferencesPanelHeight);
|
|
|
|
|
}
|
|
|
|
|
int symSetting = AppSettings.Global.GetInt(AppSettings.MAIN_SYMBOLS_HEIGHT, -1);
|
|
|
|
|
if ((int)mMainWin.SymbolsPanelHeight == symSetting ||
|
|
|
|
|
(int)mMainWin.SymbolsPanelHeight == symSetting - 1) {
|
|
|
|
|
Debug.WriteLine("NOT updating symbols height");
|
|
|
|
|
} else {
|
|
|
|
|
AppSettings.Global.SetInt(AppSettings.MAIN_SYMBOLS_HEIGHT,
|
|
|
|
|
(int)mMainWin.SymbolsPanelHeight);
|
|
|
|
|
}
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-06-20 22:10:35 +00:00
|
|
|
|
mMainWin.CaptureColumnWidths();
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
string runtimeDataDir = RuntimeDataAccess.GetDirectory();
|
|
|
|
|
if (runtimeDataDir == null) {
|
|
|
|
|
Debug.WriteLine("Unable to save settings file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string settingsDir = Path.GetDirectoryName(runtimeDataDir);
|
|
|
|
|
string settingsPath = Path.Combine(settingsDir, SETTINGS_FILE_NAME);
|
|
|
|
|
try {
|
|
|
|
|
string cereal = AppSettings.Global.Serialize();
|
|
|
|
|
File.WriteAllText(settingsPath, cereal);
|
|
|
|
|
AppSettings.Global.Dirty = false;
|
|
|
|
|
Debug.WriteLine("Saved settings (" + settingsPath + ")");
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Debug.WriteLine("Failed to save settings: " + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2019-06-19 23:31:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the app window's location and size. This should be called before the window has
|
|
|
|
|
/// finished initialization.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetAppWindowLocation() {
|
|
|
|
|
const int DEFAULT_SPLIT = 250;
|
|
|
|
|
|
|
|
|
|
AppSettings settings = AppSettings.Global;
|
|
|
|
|
|
|
|
|
|
string placement = settings.GetString(AppSettings.MAIN_WINDOW_PLACEMENT, null);
|
|
|
|
|
if (placement != null) {
|
|
|
|
|
mMainWin.SetPlacement(placement);
|
2019-05-28 01:46:09 +00:00
|
|
|
|
}
|
2019-06-19 23:31:56 +00:00
|
|
|
|
|
|
|
|
|
mMainWin.LeftPanelWidth =
|
|
|
|
|
settings.GetInt(AppSettings.MAIN_LEFT_PANEL_WIDTH, DEFAULT_SPLIT);
|
|
|
|
|
mMainWin.RightPanelWidth =
|
|
|
|
|
settings.GetInt(AppSettings.MAIN_RIGHT_PANEL_WIDTH, DEFAULT_SPLIT);
|
|
|
|
|
mMainWin.ReferencesPanelHeight =
|
|
|
|
|
settings.GetInt(AppSettings.MAIN_REFERENCES_HEIGHT, 350);
|
|
|
|
|
mMainWin.SymbolsPanelHeight =
|
|
|
|
|
settings.GetInt(AppSettings.MAIN_SYMBOLS_HEIGHT, 400);
|
|
|
|
|
|
2019-06-20 22:10:35 +00:00
|
|
|
|
mMainWin.RestoreColumnWidths();
|
2019-05-28 01:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies "actionable" settings to the ProjectView, pulling them out of the global
|
|
|
|
|
/// settings object. If a project is open, refreshes the display list and all sub-windows.
|
|
|
|
|
/// </summary>
|
2020-09-05 00:49:28 +00:00
|
|
|
|
public void ApplyAppSettings() {
|
2019-05-28 01:46:09 +00:00
|
|
|
|
Debug.WriteLine("ApplyAppSettings...");
|
|
|
|
|
AppSettings settings = AppSettings.Global;
|
|
|
|
|
|
2024-07-04 17:32:24 +00:00
|
|
|
|
// Set up the formatter with default values.
|
2019-05-28 01:46:09 +00:00
|
|
|
|
mFormatterConfig = new Formatter.FormatConfig();
|
|
|
|
|
AsmGen.GenCommon.ConfigureFormatterFromSettings(AppSettings.Global,
|
|
|
|
|
ref mFormatterConfig);
|
2024-06-24 23:36:27 +00:00
|
|
|
|
mFormatterConfig.EndOfLineCommentDelimiter = ";";
|
2019-08-14 22:25:09 +00:00
|
|
|
|
|
2024-06-24 23:36:27 +00:00
|
|
|
|
mFormatterConfig.NonUniqueLabelPrefix =
|
2019-11-13 01:24:41 +00:00
|
|
|
|
settings.GetString(AppSettings.FMT_NON_UNIQUE_LABEL_PREFIX, string.Empty);
|
2024-06-24 23:36:27 +00:00
|
|
|
|
mFormatterConfig.LocalVariableLabelPrefix =
|
2019-08-31 21:54:44 +00:00
|
|
|
|
settings.GetString(AppSettings.FMT_LOCAL_VARIABLE_PREFIX, string.Empty);
|
2024-06-24 23:36:27 +00:00
|
|
|
|
mFormatterConfig.CommaSeparatedDense =
|
2022-01-12 21:29:10 +00:00
|
|
|
|
settings.GetBool(AppSettings.FMT_COMMA_SEP_BULK_DATA, true);
|
2024-07-06 21:54:09 +00:00
|
|
|
|
mFormatterConfig.DebugLongComments = DebugLongComments;
|
2019-08-31 21:54:44 +00:00
|
|
|
|
|
2019-08-14 22:25:09 +00:00
|
|
|
|
string chrDelCereal = settings.GetString(AppSettings.FMT_CHAR_DELIM, null);
|
|
|
|
|
if (chrDelCereal != null) {
|
2024-06-24 23:36:27 +00:00
|
|
|
|
mFormatterConfig.CharDelimiters =
|
2019-08-14 22:25:09 +00:00
|
|
|
|
Formatter.DelimiterSet.Deserialize(chrDelCereal);
|
|
|
|
|
}
|
|
|
|
|
string strDelCereal = settings.GetString(AppSettings.FMT_STRING_DELIM, null);
|
|
|
|
|
if (strDelCereal != null) {
|
2024-06-24 23:36:27 +00:00
|
|
|
|
mFormatterConfig.StringDelimiters =
|
2019-08-14 22:25:09 +00:00
|
|
|
|
Formatter.DelimiterSet.Deserialize(strDelCereal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-12-30 01:59:35 +00:00
|
|
|
|
// Update the formatter, and null out mFormatterCpuDef to force a refresh
|
Various improvements
The PseudoOpNames class is increasingly being used in situations
where mutability is undesirable. This change makes instances
immutable, eliminating the Copy() method and adding a constructor
that takes a Dictionary. The serialization code now operates on a
Dictionary instead of the class properties, but the JSON encoding is
identical, so this doesn't invalidate app settings file data.
Added an equality test to PseudoOpNames. In LineListGen, don't
reset the line list if the names haven't actually changed.
Use a table lookup for C64 character conversions. I figure that
should be faster than multiple conditionals on a modern x64 system.
Fixed a 64tass generator issue where we tried to query project
properties in a call that might not have a project available
(specifically, getting FormatConfig values out of the generator for
use in the "quick set" buttons for Display Format).
Fixed a regression test harness issue where, if the assembler reported
success but didn't actually generate output, an exception would be
thrown that halted the tests.
Increased the width of text entry fields on the Pseudo-Op tab of app
settings. The previous 8-character limit wasn't wide enough to hold
ACME's "!pseudopc". Also, use TrimEnd() to remove trailing spaces
(leading spaces are still allowed).
In the last couple of months, Win10 started stalling for a fraction
of a second when executing assemblers. It doesn't do this every
time; mostly it happens if it has been a while since the assembler
was run. My guess is this has to do with changes to the built-in
malware scanner. Whatever the case, we now change the mouse pointer
to a wait cursor while updating the assembler version cache.
2019-08-17 18:14:05 +00:00
|
|
|
|
// of related items.
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatter = new Formatter(mFormatterConfig);
|
|
|
|
|
mFormatterCpuDef = null;
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
|
|
|
|
// Set pseudo-op names. Entries aren't allowed to be blank, so we start with the
|
|
|
|
|
// default values and merge in whatever the user has configured.
|
2019-08-14 00:22:21 +00:00
|
|
|
|
mPseudoOpNames = PseudoOp.DefaultPseudoOpNames;
|
2019-05-28 01:46:09 +00:00
|
|
|
|
string pseudoCereal = settings.GetString(AppSettings.FMT_PSEUDO_OP_NAMES, null);
|
|
|
|
|
if (!string.IsNullOrEmpty(pseudoCereal)) {
|
|
|
|
|
PseudoOp.PseudoOpNames deser = PseudoOp.PseudoOpNames.Deserialize(pseudoCereal);
|
|
|
|
|
if (deser != null) {
|
2019-08-18 00:22:14 +00:00
|
|
|
|
mPseudoOpNames = PseudoOp.PseudoOpNames.Merge(mPseudoOpNames, deser);
|
2019-05-28 01:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configure the Symbols window.
|
2019-07-16 21:52:08 +00:00
|
|
|
|
mMainWin.SymFilterUserLabels =
|
2019-05-28 01:46:09 +00:00
|
|
|
|
settings.GetBool(AppSettings.SYMWIN_SHOW_USER, false);
|
2019-11-16 04:40:14 +00:00
|
|
|
|
mMainWin.SymFilterNonUniqueLabels =
|
|
|
|
|
settings.GetBool(AppSettings.SYMWIN_SHOW_NON_UNIQUE, false);
|
2019-07-16 21:52:08 +00:00
|
|
|
|
mMainWin.SymFilterAutoLabels =
|
2019-05-28 01:46:09 +00:00
|
|
|
|
settings.GetBool(AppSettings.SYMWIN_SHOW_AUTO, false);
|
2019-07-16 21:52:08 +00:00
|
|
|
|
mMainWin.SymFilterProjectSymbols =
|
2019-05-28 01:46:09 +00:00
|
|
|
|
settings.GetBool(AppSettings.SYMWIN_SHOW_PROJECT, false);
|
2019-07-16 21:52:08 +00:00
|
|
|
|
mMainWin.SymFilterPlatformSymbols =
|
2019-05-28 01:46:09 +00:00
|
|
|
|
settings.GetBool(AppSettings.SYMWIN_SHOW_PLATFORM, false);
|
2021-10-05 03:41:19 +00:00
|
|
|
|
mMainWin.SymFilterAddrPreLabels =
|
|
|
|
|
settings.GetBool(AppSettings.SYMWIN_SHOW_ADDR_PRE_LABELS, false);
|
2019-07-16 21:52:08 +00:00
|
|
|
|
mMainWin.SymFilterConstants =
|
2019-05-28 01:46:09 +00:00
|
|
|
|
settings.GetBool(AppSettings.SYMWIN_SHOW_CONST, false);
|
2019-07-16 21:52:08 +00:00
|
|
|
|
mMainWin.SymFilterAddresses =
|
2019-05-28 01:46:09 +00:00
|
|
|
|
settings.GetBool(AppSettings.SYMWIN_SHOW_ADDR, false);
|
|
|
|
|
|
2019-06-27 00:11:58 +00:00
|
|
|
|
// Get the configured font info. If nothing is configured, use whatever the
|
|
|
|
|
// code list happens to be using now.
|
|
|
|
|
string fontFamilyName = settings.GetString(AppSettings.CDLV_FONT_FAMILY, null);
|
|
|
|
|
if (fontFamilyName == null) {
|
|
|
|
|
fontFamilyName = mMainWin.CodeListFontFamily.ToString();
|
2019-05-28 01:46:09 +00:00
|
|
|
|
}
|
2019-06-27 00:11:58 +00:00
|
|
|
|
int size = settings.GetInt(AppSettings.CDLV_FONT_SIZE, -1);
|
|
|
|
|
if (size <= 0) {
|
|
|
|
|
size = (int)mMainWin.CodeListFontSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mMainWin.SetCodeListFont(fontFamilyName, size);
|
|
|
|
|
|
|
|
|
|
// Update the column widths. This was done earlier during init, but may need to be
|
|
|
|
|
// repeated if the show/hide buttons were used in Settings.
|
|
|
|
|
mMainWin.RestoreColumnWidths();
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
|
|
|
|
// Unpack the recent-project list.
|
|
|
|
|
UnpackRecentProjectList();
|
|
|
|
|
|
2019-10-13 00:23:32 +00:00
|
|
|
|
// Set the color scheme.
|
|
|
|
|
bool useDark = settings.GetBool(AppSettings.SKIN_DARK_COLOR_SCHEME, false);
|
|
|
|
|
if (useDark) {
|
|
|
|
|
mColorScheme = MainWindow.ColorScheme.Dark;
|
|
|
|
|
} else {
|
|
|
|
|
mColorScheme = MainWindow.ColorScheme.Light;
|
|
|
|
|
}
|
|
|
|
|
mMainWin.SetColorScheme(mColorScheme);
|
|
|
|
|
if (CodeLineList != null) {
|
|
|
|
|
SetCodeLineListColorMultiplier();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 01:46:09 +00:00
|
|
|
|
// Enable the DEBUG menu if configured.
|
2019-07-15 22:32:27 +00:00
|
|
|
|
mMainWin.ShowDebugMenu =
|
|
|
|
|
AppSettings.Global.GetBool(AppSettings.DEBUG_MENU_ENABLED, false);
|
2019-05-28 01:46:09 +00:00
|
|
|
|
|
2020-09-05 00:49:28 +00:00
|
|
|
|
// Refresh the toolbar checkbox.
|
|
|
|
|
mMainWin.DoShowCycleCounts =
|
|
|
|
|
AppSettings.Global.GetBool(AppSettings.FMT_SHOW_CYCLE_COUNTS, false);
|
|
|
|
|
|
2019-05-28 01:46:09 +00:00
|
|
|
|
// Finally, update the display list generator with all the fancy settings.
|
2019-06-16 23:34:47 +00:00
|
|
|
|
if (CodeLineList != null) {
|
2019-05-28 01:46:09 +00:00
|
|
|
|
// Regenerate the display list with the latest formatter config and
|
|
|
|
|
// pseudo-op definition. (These are set as part of the refresh.)
|
|
|
|
|
UndoableChange uc =
|
|
|
|
|
UndoableChange.CreateDummyChange(UndoableChange.ReanalysisScope.DisplayOnly);
|
|
|
|
|
ApplyChanges(new ChangeSet(uc), false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-10-13 00:23:32 +00:00
|
|
|
|
private void SetCodeLineListColorMultiplier() {
|
|
|
|
|
if (mColorScheme == MainWindow.ColorScheme.Dark) {
|
|
|
|
|
CodeLineList.NoteColorMultiplier = 0.6f;
|
|
|
|
|
} else {
|
|
|
|
|
CodeLineList.NoteColorMultiplier = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-22 21:41:09 +00:00
|
|
|
|
private void UnpackRecentProjectList() {
|
|
|
|
|
RecentProjectPaths.Clear();
|
|
|
|
|
|
|
|
|
|
string cereal = AppSettings.Global.GetString(
|
|
|
|
|
AppSettings.PRVW_RECENT_PROJECT_LIST, null);
|
|
|
|
|
if (string.IsNullOrEmpty(cereal)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
JavaScriptSerializer ser = new JavaScriptSerializer();
|
|
|
|
|
RecentProjectPaths = ser.Deserialize<List<string>>(cereal);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Debug.WriteLine("Failed deserializing recent projects: " + ex.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures that the named project is at the top of the list. If it's elsewhere
|
|
|
|
|
/// in the list, move it to the top. Excess items are removed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="projectPath"></param>
|
|
|
|
|
private void UpdateRecentProjectList(string projectPath) {
|
|
|
|
|
if (string.IsNullOrEmpty(projectPath)) {
|
|
|
|
|
// This can happen if you create a new project, then close the window
|
|
|
|
|
// without having saved it.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-22 21:41:09 +00:00
|
|
|
|
int index = RecentProjectPaths.IndexOf(projectPath);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
if (index == 0) {
|
|
|
|
|
// Already in the list, nothing changes. No need to update anything else.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (index > 0) {
|
2019-06-22 21:41:09 +00:00
|
|
|
|
RecentProjectPaths.RemoveAt(index);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
2019-06-22 21:41:09 +00:00
|
|
|
|
RecentProjectPaths.Insert(0, projectPath);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
|
|
|
|
// Trim the list to the max allowed.
|
2019-06-22 21:41:09 +00:00
|
|
|
|
while (RecentProjectPaths.Count > MAX_RECENT_PROJECTS) {
|
2019-05-05 23:50:28 +00:00
|
|
|
|
Debug.WriteLine("Recent projects: dropping " +
|
2019-06-22 21:41:09 +00:00
|
|
|
|
RecentProjectPaths[MAX_RECENT_PROJECTS]);
|
|
|
|
|
RecentProjectPaths.RemoveAt(MAX_RECENT_PROJECTS);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store updated list in app settings. JSON-in-JSON is ugly and inefficient,
|
|
|
|
|
// but it'll do for now.
|
|
|
|
|
JavaScriptSerializer ser = new JavaScriptSerializer();
|
2019-06-22 21:41:09 +00:00
|
|
|
|
string cereal = ser.Serialize(RecentProjectPaths);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
AppSettings.Global.SetString(AppSettings.PRVW_RECENT_PROJECT_LIST, cereal);
|
|
|
|
|
|
2019-06-22 21:41:09 +00:00
|
|
|
|
mMainWin.UpdateRecentLinks();
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-16 21:36:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the main form title to show project name and modification status.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateTitle() {
|
|
|
|
|
// Update main window title.
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
if (mProject != null) {
|
|
|
|
|
if (string.IsNullOrEmpty(mProjectPathName)) {
|
|
|
|
|
sb.Append(Res.Strings.TITLE_NEW_PROJECT);
|
|
|
|
|
} else {
|
|
|
|
|
sb.Append(Path.GetFileName(mProjectPathName));
|
|
|
|
|
}
|
2019-10-26 20:07:31 +00:00
|
|
|
|
if (mProject.IsReadOnly) {
|
|
|
|
|
sb.Append(" ");
|
|
|
|
|
sb.Append(Res.Strings.TITLE_READ_ONLY);
|
|
|
|
|
}
|
|
|
|
|
sb.Append(" - ");
|
2019-07-16 21:36:09 +00:00
|
|
|
|
}
|
2019-10-27 00:32:22 +00:00
|
|
|
|
|
2019-10-26 20:07:31 +00:00
|
|
|
|
sb.Append(Res.Strings.TITLE_BASE);
|
2019-10-27 00:32:22 +00:00
|
|
|
|
|
|
|
|
|
if (mProject != null && mProject.IsDirty) {
|
|
|
|
|
sb.Append(" - ");
|
|
|
|
|
sb.Append(Res.Strings.TITLE_MODIFIED);
|
|
|
|
|
}
|
2019-07-16 21:36:09 +00:00
|
|
|
|
mMainWin.Title = sb.ToString();
|
2019-11-20 02:18:41 +00:00
|
|
|
|
|
|
|
|
|
UpdateByteCounts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the code/data/junk percentages in the status bar.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateByteCounts() {
|
|
|
|
|
if (mProject == null) {
|
|
|
|
|
mMainWin.ByteCountText = string.Empty;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.Assert(mProject.ByteCounts.CodeByteCount + mProject.ByteCounts.DataByteCount +
|
|
|
|
|
mProject.ByteCounts.JunkByteCount == mProject.FileData.Length);
|
|
|
|
|
|
|
|
|
|
int total = mProject.FileData.Length;
|
|
|
|
|
float codePerc = (mProject.ByteCounts.CodeByteCount * 100.0f) / total;
|
|
|
|
|
float dataPerc = (mProject.ByteCounts.DataByteCount * 100.0f) / total;
|
|
|
|
|
float junkPerc = (mProject.ByteCounts.JunkByteCount * 100.0f) / total;
|
|
|
|
|
mMainWin.ByteCountText = string.Format(Res.Strings.STATUS_BYTE_COUNT_FMT,
|
2020-03-02 02:18:31 +00:00
|
|
|
|
total / 1024.0f, codePerc, dataPerc, junkPerc);
|
2019-07-16 21:36:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
#endregion Init and settings
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
#region Project management
|
|
|
|
|
|
|
|
|
|
private bool PrepareNewProject(string dataPathName, SystemDef sysDef) {
|
|
|
|
|
DisasmProject proj = new DisasmProject();
|
|
|
|
|
mDataPathName = dataPathName;
|
|
|
|
|
mProjectPathName = string.Empty;
|
2022-03-01 23:03:12 +00:00
|
|
|
|
byte[] fileData;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
try {
|
|
|
|
|
fileData = LoadDataFile(dataPathName);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Debug.WriteLine("PrepareNewProject exception: " + ex);
|
|
|
|
|
string message = Res.Strings.OPEN_DATA_FAIL_CAPTION;
|
|
|
|
|
string caption = Res.Strings.OPEN_DATA_FAIL_MESSAGE + ": " + ex.Message;
|
|
|
|
|
MessageBox.Show(caption, message, MessageBoxButton.OK,
|
|
|
|
|
MessageBoxImage.Error);
|
|
|
|
|
return false;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
2020-07-18 20:47:01 +00:00
|
|
|
|
proj.UseMainAppDomainForPlugins = UseMainAppDomainForPlugins;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
proj.Initialize(fileData.Length);
|
|
|
|
|
proj.PrepForNew(fileData, Path.GetFileName(dataPathName));
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-07-16 21:36:09 +00:00
|
|
|
|
// Initial header comment is the program name and version.
|
|
|
|
|
string cmt = string.Format(Res.Strings.DEFAULT_HEADER_COMMENT_FMT, App.ProgramVersion);
|
2019-06-08 22:48:44 +00:00
|
|
|
|
proj.LongComments.Add(LineListGen.Line.HEADER_COMMENT_OFFSET,
|
2019-07-16 21:36:09 +00:00
|
|
|
|
new MultiLineComment(cmt));
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
// The system definition provides a set of defaults that can be overridden.
|
|
|
|
|
// We pull everything of interest out and then discard the object.
|
|
|
|
|
proj.ApplySystemDef(sysDef);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
mProject = proj;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-07-19 22:24:51 +00:00
|
|
|
|
#if false
|
|
|
|
|
private class FinishPrepProgress : WorkProgress.IWorker {
|
|
|
|
|
public string ExtMessages { get; private set; }
|
|
|
|
|
private MainController mMainCtrl;
|
|
|
|
|
|
|
|
|
|
public FinishPrepProgress(MainController mainCtrl) {
|
|
|
|
|
mMainCtrl = mainCtrl;
|
|
|
|
|
}
|
|
|
|
|
public object DoWork(BackgroundWorker worker) {
|
|
|
|
|
string messages = mMainCtrl.mProject.LoadExternalFiles();
|
|
|
|
|
mMainCtrl.DoRefreshProject(UndoableChange.ReanalysisScope.CodeAndData);
|
|
|
|
|
return messages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RunWorkerCompleted(object results) {
|
|
|
|
|
ExtMessages = (string)results;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
private void FinishPrep() {
|
2019-07-19 22:24:51 +00:00
|
|
|
|
CodeLineList = new LineListGen(mProject, mMainWin.CodeDisplayList,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatter, mPseudoOpNames);
|
2019-10-13 00:23:32 +00:00
|
|
|
|
SetCodeLineListColorMultiplier();
|
2019-07-19 22:24:51 +00:00
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
string messages = mProject.LoadExternalFiles();
|
|
|
|
|
if (messages.Length != 0) {
|
2019-07-19 22:24:51 +00:00
|
|
|
|
// ProjectLoadIssues isn't quite the right dialog, but it'll do. This is
|
|
|
|
|
// purely informative; no decision needs to be made.
|
2019-06-16 23:46:40 +00:00
|
|
|
|
ProjectLoadIssues dlg = new ProjectLoadIssues(mMainWin, messages,
|
2019-06-08 22:48:44 +00:00
|
|
|
|
ProjectLoadIssues.Buttons.Continue);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 22:24:51 +00:00
|
|
|
|
// Ideally we'd call DoRefreshProject (and LoadExternalFiles) from a progress
|
|
|
|
|
// dialog, but we're not allowed to update the DisplayList from a different thread.
|
2019-06-08 22:48:44 +00:00
|
|
|
|
RefreshProject(UndoableChange.ReanalysisScope.CodeAndData);
|
2019-06-12 21:17:24 +00:00
|
|
|
|
|
|
|
|
|
// Populate the Symbols list.
|
|
|
|
|
PopulateSymbolsList();
|
|
|
|
|
|
2019-06-12 22:54:22 +00:00
|
|
|
|
// Load initial contents of Notes panel.
|
|
|
|
|
PopulateNotesList();
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
mMainWin.ShowCodeListView = true;
|
|
|
|
|
mNavStack.Clear();
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
UpdateRecentProjectList(mProjectPathName);
|
2019-07-16 21:36:09 +00:00
|
|
|
|
|
|
|
|
|
UpdateTitle();
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-06-08 22:48:44 +00:00
|
|
|
|
/// Loads the data file, reading it entirely into memory.
|
|
|
|
|
///
|
|
|
|
|
/// All errors are reported as exceptions.
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// </summary>
|
2019-06-08 22:48:44 +00:00
|
|
|
|
/// <param name="dataFileName">Full pathname.</param>
|
|
|
|
|
/// <returns>Data file contents.</returns>
|
2020-06-24 00:21:18 +00:00
|
|
|
|
private static byte[] LoadDataFile(string dataFileName) {
|
2019-06-08 22:48:44 +00:00
|
|
|
|
byte[] fileData;
|
|
|
|
|
|
|
|
|
|
using (FileStream fs = File.Open(dataFileName, FileMode.Open, FileAccess.Read)) {
|
|
|
|
|
// Check length; should have been caught earlier.
|
|
|
|
|
if (fs.Length > DisasmProject.MAX_DATA_FILE_SIZE) {
|
|
|
|
|
throw new InvalidDataException(
|
|
|
|
|
string.Format(Res.Strings.OPEN_DATA_TOO_LARGE_FMT,
|
|
|
|
|
fs.Length / 1024, DisasmProject.MAX_DATA_FILE_SIZE / 1024));
|
|
|
|
|
} else if (fs.Length == 0) {
|
|
|
|
|
throw new InvalidDataException(Res.Strings.OPEN_DATA_EMPTY);
|
|
|
|
|
}
|
|
|
|
|
fileData = new byte[fs.Length];
|
|
|
|
|
int actual = fs.Read(fileData, 0, (int)fs.Length);
|
|
|
|
|
if (actual != fs.Length) {
|
|
|
|
|
// Not expected -- should be able to read the entire file in one shot.
|
|
|
|
|
throw new Exception(Res.Strings.OPEN_DATA_PARTIAL_READ);
|
|
|
|
|
}
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fileData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-06-08 22:48:44 +00:00
|
|
|
|
/// Applies the changes to the project, adds them to the undo stack, and updates
|
|
|
|
|
/// the display.
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// </summary>
|
2019-06-08 22:48:44 +00:00
|
|
|
|
/// <param name="cs">Set of changes to apply.</param>
|
|
|
|
|
private void ApplyUndoableChanges(ChangeSet cs) {
|
|
|
|
|
if (cs.Count == 0) {
|
|
|
|
|
Debug.WriteLine("ApplyUndoableChanges: change set is empty");
|
2020-07-28 17:56:07 +00:00
|
|
|
|
// Apply anyway to create an undoable non-event?
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
2019-06-08 22:48:44 +00:00
|
|
|
|
ApplyChanges(cs, false);
|
|
|
|
|
mProject.PushChangeSet(cs);
|
2019-07-16 21:36:09 +00:00
|
|
|
|
UpdateTitle();
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
// If the debug dialog is visible, update it.
|
|
|
|
|
if (mShowUndoRedoHistoryDialog != null) {
|
2019-07-16 00:18:28 +00:00
|
|
|
|
mShowUndoRedoHistoryDialog.DisplayText = mProject.DebugGetUndoRedoHistory();
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies the changes to the project, and updates the display.
|
|
|
|
|
///
|
|
|
|
|
/// This is called by the undo/redo commands. Don't call this directly from the
|
|
|
|
|
/// various UI-driven functions, as this does not add the change to the undo stack.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cs">Set of changes to apply.</param>
|
|
|
|
|
/// <param name="backward">If set, undo the changes instead.</param>
|
|
|
|
|
private void ApplyChanges(ChangeSet cs, bool backward) {
|
|
|
|
|
mReanalysisTimer.Clear();
|
|
|
|
|
mReanalysisTimer.StartTask("ProjectView.ApplyChanges()");
|
|
|
|
|
|
|
|
|
|
mReanalysisTimer.StartTask("Save selection");
|
2019-07-18 00:42:57 +00:00
|
|
|
|
mMainWin.CodeListView_DebugValidateSelectionCount();
|
2019-06-15 23:00:31 +00:00
|
|
|
|
int topItemIndex = mMainWin.CodeListView_GetTopIndex();
|
2019-05-28 01:46:09 +00:00
|
|
|
|
LineListGen.SavedSelection savedSel = LineListGen.SavedSelection.Generate(
|
Improve save & restore of top line
Whenever the display list gets regenerated, we need to restore the
code list view scroll position to the previous location in the file.
This gets tricky when multiple lines are appearing or disappearing.
We were saving the file offset of the line, but that works poorly
when there's a multi-line comment associated with that offset,
because we end up scrolling to the top of the comment whenever any
part of the comment is at the top of the screen.
We now track the file offset and the number of lines we were from
the top of that offset's content. This works well unless we remove
a lot of lines. If the adjusted line index would put us into a
different file offset, we punt and just scroll to the top of the item.
Also, fix a crasher in Edit Note.
Also, fix behavior when the list shrinks while a line near the end
of the file is selected.
Also, change a few instances of "Color.FromArgb(0,0,0,0)" to use a
common constant.
2019-07-17 20:47:43 +00:00
|
|
|
|
CodeLineList, mMainWin.CodeDisplayList.SelectedIndices, topItemIndex);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
//savedSel.DebugDump();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
|
2021-11-17 19:18:23 +00:00
|
|
|
|
// Clear the addr/label highlight index.
|
|
|
|
|
// (Certain changes will blow away the CodeDisplayList and affect the selection,
|
|
|
|
|
// which will cause the selection-changed handler to try to un-highlight something
|
|
|
|
|
// that doesn't exist. We want to clear the index here, but we probably also want
|
|
|
|
|
// to clear the highlighting before we do it. As it happens, changes will either
|
|
|
|
|
// be big enough to wipe out our highlight, or small enough that we immediately
|
|
|
|
|
// re-highlight the thing that's already highlighted, so it doesn't really matter.
|
|
|
|
|
// If we start to see vestigial highlighting after a change, we'll need to be
|
|
|
|
|
// more rigorous here.)
|
2019-06-16 23:34:47 +00:00
|
|
|
|
mTargetHighlightIndex = -1;
|
2021-11-17 19:18:23 +00:00
|
|
|
|
|
|
|
|
|
// Clear operand highlighting indices as well.
|
|
|
|
|
mOperandHighlights.Clear();
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
mReanalysisTimer.EndTask("Save selection");
|
|
|
|
|
|
|
|
|
|
mReanalysisTimer.StartTask("Apply changes");
|
|
|
|
|
UndoableChange.ReanalysisScope needReanalysis = mProject.ApplyChanges(cs, backward,
|
|
|
|
|
out RangeSet affectedOffsets);
|
|
|
|
|
mReanalysisTimer.EndTask("Apply changes");
|
|
|
|
|
|
|
|
|
|
string refreshTaskStr = "Refresh w/reanalysis=" + needReanalysis;
|
|
|
|
|
mReanalysisTimer.StartTask(refreshTaskStr);
|
|
|
|
|
if (needReanalysis != UndoableChange.ReanalysisScope.None) {
|
|
|
|
|
Debug.WriteLine("Refreshing project (" + needReanalysis + ")");
|
|
|
|
|
RefreshProject(needReanalysis);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("Refreshing " + affectedOffsets.Count + " offsets");
|
|
|
|
|
RefreshCodeListViewEntries(affectedOffsets);
|
|
|
|
|
mProject.Validate(); // shouldn't matter w/o reanalysis, but do it anyway
|
|
|
|
|
}
|
|
|
|
|
mReanalysisTimer.EndTask(refreshTaskStr);
|
|
|
|
|
|
2020-09-05 00:49:28 +00:00
|
|
|
|
mReanalysisTimer.StartTask("Restore selection and top position");
|
2019-06-16 23:34:47 +00:00
|
|
|
|
DisplayListSelection newSel = savedSel.Restore(CodeLineList, out topItemIndex);
|
2019-05-05 23:50:28 +00:00
|
|
|
|
//newSel.DebugDump();
|
|
|
|
|
|
2019-06-10 22:46:35 +00:00
|
|
|
|
// Restore the selection. The selection-changed event will cause updates to the
|
|
|
|
|
// references, notes, and info panels.
|
2019-06-15 23:00:31 +00:00
|
|
|
|
mMainWin.CodeListView_SetSelection(newSel);
|
|
|
|
|
mMainWin.CodeListView_SetTopIndex(topItemIndex);
|
2019-06-10 22:46:35 +00:00
|
|
|
|
mReanalysisTimer.EndTask("Restore selection and top position");
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-07-17 00:16:47 +00:00
|
|
|
|
// Update the Notes and Symbols windows. References should refresh automatically
|
|
|
|
|
// when the selection is restored.
|
2020-09-05 00:49:28 +00:00
|
|
|
|
mReanalysisTimer.StartTask("Populate Notes and Symbols");
|
2019-06-12 22:54:22 +00:00
|
|
|
|
PopulateNotesList();
|
2019-07-08 22:40:30 +00:00
|
|
|
|
PopulateSymbolsList();
|
2020-09-05 00:49:28 +00:00
|
|
|
|
mReanalysisTimer.EndTask("Populate Notes and Symbols");
|
2019-06-12 22:54:22 +00:00
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
mReanalysisTimer.EndTask("ProjectView.ApplyChanges()");
|
|
|
|
|
|
|
|
|
|
//mReanalysisTimer.DumpTimes("ProjectView timers:", mGenerationLog);
|
|
|
|
|
if (mShowAnalysisTimersDialog != null) {
|
|
|
|
|
string timerStr = mReanalysisTimer.DumpToString("ProjectView timers:");
|
2019-07-16 00:18:28 +00:00
|
|
|
|
mShowAnalysisTimersDialog.DisplayText = timerStr;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lines may have moved around. Update the selection highlight. It's important
|
|
|
|
|
// we do it here, and not down in DoRefreshProject(), because at that point the
|
|
|
|
|
// ListView's selection index could be referencing a line off the end.
|
2019-07-16 21:36:09 +00:00
|
|
|
|
// (This may not be necessary with WPF, because the way highlights work changed.)
|
2019-05-05 23:50:28 +00:00
|
|
|
|
UpdateSelectionHighlight();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 22:24:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates all of the specified ListView entries. This is called after minor changes,
|
|
|
|
|
/// such as editing a comment or renaming a label, that can be handled by regenerating
|
|
|
|
|
/// selected parts of the DisplayList.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offsetSet"></param>
|
|
|
|
|
private void RefreshCodeListViewEntries(RangeSet offsetSet) {
|
|
|
|
|
IEnumerator<RangeSet.Range> iter = offsetSet.RangeListIterator;
|
|
|
|
|
while (iter.MoveNext()) {
|
|
|
|
|
RangeSet.Range range = iter.Current;
|
|
|
|
|
CodeLineList.GenerateRange(range.Low, range.High);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the project after something of substance has changed. Some
|
|
|
|
|
/// re-analysis will be done, followed by a complete rebuild of the DisplayList.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reanalysisRequired">Indicates whether reanalysis is required, and
|
|
|
|
|
/// what level.</param>
|
|
|
|
|
private void RefreshProject(UndoableChange.ReanalysisScope reanalysisRequired) {
|
|
|
|
|
Debug.Assert(reanalysisRequired != UndoableChange.ReanalysisScope.None);
|
|
|
|
|
|
|
|
|
|
// NOTE: my goal is to arrange things so that reanalysis (data-only, and ideally
|
|
|
|
|
// code+data) takes less than 100ms. With that response time there's no need for
|
|
|
|
|
// background processing and progress bars. Since we need to do data-only
|
|
|
|
|
// reanalysis after many common operations, the program becomes unpleasant to
|
|
|
|
|
// use if we miss this goal, and progress bars won't make it less so.
|
|
|
|
|
|
2019-07-19 22:24:51 +00:00
|
|
|
|
if (mProject.FileDataLength > 65536) {
|
2019-05-05 23:50:28 +00:00
|
|
|
|
try {
|
2019-07-19 18:41:18 +00:00
|
|
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
DoRefreshProject(reanalysisRequired);
|
|
|
|
|
} finally {
|
2019-07-19 18:41:18 +00:00
|
|
|
|
Mouse.OverrideCursor = null;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
DoRefreshProject(reanalysisRequired);
|
2019-07-19 18:41:18 +00:00
|
|
|
|
}
|
2019-05-05 23:50:28 +00:00
|
|
|
|
|
2019-07-19 22:24:51 +00:00
|
|
|
|
if (mGenerationLog != null) {
|
|
|
|
|
//mReanalysisTimer.StartTask("Save _log");
|
|
|
|
|
//mGenerationLog.WriteToFile(@"C:\Src\WorkBench\SourceGen\TestData\_log.txt");
|
|
|
|
|
//mReanalysisTimer.EndTask("Save _log");
|
|
|
|
|
|
|
|
|
|
if (mShowAnalyzerOutputDialog != null) {
|
|
|
|
|
mShowAnalyzerOutputDialog.DisplayText = mGenerationLog.WriteToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-05 23:50:28 +00:00
|
|
|
|
if (FormatDescriptor.DebugCreateCount != 0) {
|
|
|
|
|
Debug.WriteLine("FormatDescriptor total=" + FormatDescriptor.DebugCreateCount +
|
|
|
|
|
" prefab=" + FormatDescriptor.DebugPrefabCount + " (" +
|
|
|
|
|
(FormatDescriptor.DebugPrefabCount * 100) / FormatDescriptor.DebugCreateCount +
|
|
|
|
|
"%)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-19 22:24:51 +00:00
|
|
|
|
/// Refreshes the project after something of substance has changed.
|
2019-05-05 23:50:28 +00:00
|
|
|
|
/// </summary>
|
2019-07-19 22:24:51 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Ideally from this point on we can run on a background thread. The tricky part
|
|
|
|
|
/// is the close relationship between LineListGen and DisplayList -- we can't update
|
|
|
|
|
/// DisplayList from a background thread. Until that's fixed, putting up a "working..."
|
|
|
|
|
/// dialog or other UI will be awkward.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="reanalysisRequired">Indicates whether reanalysis is required, and
|
|
|
|
|
/// what level.</param>
|
|
|
|
|
private void DoRefreshProject(UndoableChange.ReanalysisScope reanalysisRequired) {
|
|
|
|
|
// Changing the CPU type or whether undocumented instructions are supported
|
|
|
|
|
// invalidates the Formatter's mnemonic cache. We can change these values
|
|
|
|
|
// through undo/redo, so we need to check it here.
|
2019-12-30 01:59:35 +00:00
|
|
|
|
if (mFormatterCpuDef != mProject.CpuDef) { // reference equality is fine
|
2019-07-19 22:24:51 +00:00
|
|
|
|
Debug.WriteLine("CpuDef has changed, resetting formatter (now " +
|
|
|
|
|
mProject.CpuDef + ")");
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatter = new Formatter(mFormatterConfig);
|
|
|
|
|
CodeLineList.SetFormatter(mFormatter);
|
2019-07-19 22:24:51 +00:00
|
|
|
|
CodeLineList.SetPseudoOpNames(mPseudoOpNames);
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatterCpuDef = mProject.CpuDef;
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reanalysisRequired != UndoableChange.ReanalysisScope.DisplayOnly) {
|
|
|
|
|
mGenerationLog = new CommonUtil.DebugLog();
|
|
|
|
|
mGenerationLog.SetMinPriority(CommonUtil.DebugLog.Priority.Debug);
|
|
|
|
|
mGenerationLog.SetShowRelTime(true);
|
|
|
|
|
|
|
|
|
|
mReanalysisTimer.StartTask("Call DisasmProject.Analyze()");
|
|
|
|
|
mProject.Analyze(reanalysisRequired, mGenerationLog, mReanalysisTimer);
|
|
|
|
|
mReanalysisTimer.EndTask("Call DisasmProject.Analyze()");
|
2019-10-20 21:40:32 +00:00
|
|
|
|
|
|
|
|
|
mReanalysisTimer.StartTask("Update message list");
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mMainWin.UpdateMessageList(mProject.Messages, mFormatter);
|
2019-10-20 21:40:32 +00:00
|
|
|
|
mReanalysisTimer.EndTask("Update message list");
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mReanalysisTimer.StartTask("Generate DisplayList");
|
2019-06-16 23:34:47 +00:00
|
|
|
|
CodeLineList.GenerateAll();
|
2019-05-05 23:50:28 +00:00
|
|
|
|
mReanalysisTimer.EndTask("Generate DisplayList");
|
2019-12-03 22:34:45 +00:00
|
|
|
|
|
|
|
|
|
mReanalysisTimer.StartTask("Refresh Visualization thumbnails");
|
|
|
|
|
VisualizationSet.RefreshAllThumbnails(mProject);
|
|
|
|
|
mReanalysisTimer.EndTask("Refresh Visualization thumbnails");
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Project management
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
#region Main window UI event handlers
|
|
|
|
|
|
2019-06-23 00:38:07 +00:00
|
|
|
|
public void NewProject() {
|
|
|
|
|
if (!CloseProject()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string sysDefsPath = RuntimeDataAccess.GetPathName("SystemDefs.json");
|
|
|
|
|
if (sysDefsPath == null) {
|
|
|
|
|
MessageBox.Show(Res.Strings.ERR_LOAD_CONFIG_FILE, Res.Strings.OPERATION_FAILED,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 23:03:12 +00:00
|
|
|
|
SystemDefSet sds;
|
2019-06-23 00:38:07 +00:00
|
|
|
|
try {
|
|
|
|
|
sds = SystemDefSet.ReadFile(sysDefsPath);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Debug.WriteLine("Failed loading system def set: " + ex);
|
|
|
|
|
MessageBox.Show(Res.Strings.ERR_LOAD_CONFIG_FILE, Res.Strings.OPERATION_FAILED,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NewProject dlg = new NewProject(mMainWin, sds);
|
|
|
|
|
if (dlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bool ok = PrepareNewProject(Path.GetFullPath(dlg.DataFileName), dlg.SystemDef);
|
|
|
|
|
if (ok) {
|
|
|
|
|
FinishPrep();
|
2024-08-02 20:47:39 +00:00
|
|
|
|
SaveProjectAs();
|
2019-06-23 00:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
public void OpenRecentProject(int projIndex) {
|
|
|
|
|
if (!CloseProject()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-22 21:41:09 +00:00
|
|
|
|
DoOpenFile(RecentProjectPaths[projIndex]);
|
2019-06-08 22:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles opening an existing project by letting the user select the project file.
|
|
|
|
|
/// </summary>
|
2019-06-21 23:27:58 +00:00
|
|
|
|
public void OpenProject() {
|
2019-06-08 22:48:44 +00:00
|
|
|
|
if (!CloseProject()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenFileDialog fileDlg = new OpenFileDialog() {
|
|
|
|
|
Filter = ProjectFile.FILENAME_FILTER + "|" + Res.Strings.FILE_FILTER_ALL,
|
|
|
|
|
FilterIndex = 1
|
|
|
|
|
};
|
|
|
|
|
if (fileDlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string projPathName = Path.GetFullPath(fileDlg.FileName);
|
|
|
|
|
DoOpenFile(projPathName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-19 22:24:51 +00:00
|
|
|
|
/// Handles opening an existing project, given a full pathname to the project file.
|
2019-06-08 22:48:44 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
private void DoOpenFile(string projPathName) {
|
|
|
|
|
Debug.WriteLine("DoOpenFile: " + projPathName);
|
|
|
|
|
Debug.Assert(mProject == null);
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(projPathName)) {
|
2019-07-19 22:24:51 +00:00
|
|
|
|
// Should only happen for projects in "recents".
|
2019-06-08 22:48:44 +00:00
|
|
|
|
string msg = string.Format(Res.Strings.ERR_FILE_NOT_FOUND_FMT, projPathName);
|
|
|
|
|
MessageBox.Show(msg, Res.Strings.ERR_FILE_GENERIC_CAPTION,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DisasmProject newProject = new DisasmProject();
|
2020-07-18 20:47:01 +00:00
|
|
|
|
newProject.UseMainAppDomainForPlugins = UseMainAppDomainForPlugins;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
// Deserialize the project file. I want to do this before loading the data file
|
|
|
|
|
// in case we decide to store the data file name in the project (e.g. the data
|
|
|
|
|
// file is a disk image or zip archive, and we need to know which part(s) to
|
|
|
|
|
// extract).
|
|
|
|
|
if (!ProjectFile.DeserializeFromFile(projPathName, newProject,
|
|
|
|
|
out FileLoadReport report)) {
|
|
|
|
|
// Should probably use a less-busy dialog for something simple like
|
|
|
|
|
// "permission denied", but the open file dialog handles most simple
|
|
|
|
|
// stuff directly.
|
2019-06-16 23:46:40 +00:00
|
|
|
|
ProjectLoadIssues dlg = new ProjectLoadIssues(mMainWin, report.Format(),
|
2019-06-08 22:48:44 +00:00
|
|
|
|
ProjectLoadIssues.Buttons.Cancel);
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
// ignore dlg.DialogResult
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now open the data file, generating the pathname by stripping off the ".dis65"
|
|
|
|
|
// extension. If we can't find the file, show a message box and offer the option to
|
|
|
|
|
// locate it manually, repeating the process until successful or canceled.
|
|
|
|
|
const string UNKNOWN_FILE = "UNKNOWN";
|
|
|
|
|
string dataPathName;
|
|
|
|
|
if (projPathName.Length <= ProjectFile.FILENAME_EXT.Length) {
|
|
|
|
|
dataPathName = UNKNOWN_FILE;
|
|
|
|
|
} else {
|
|
|
|
|
dataPathName = projPathName.Substring(0,
|
|
|
|
|
projPathName.Length - ProjectFile.FILENAME_EXT.Length);
|
|
|
|
|
}
|
|
|
|
|
byte[] fileData;
|
|
|
|
|
while ((fileData = FindValidDataFile(ref dataPathName, newProject,
|
|
|
|
|
out bool cancel)) == null) {
|
|
|
|
|
if (cancel) {
|
|
|
|
|
// give up
|
|
|
|
|
Debug.WriteLine("Abandoning attempt to open project");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 21:24:19 +00:00
|
|
|
|
newProject.SetFileData(fileData, Path.GetFileName(dataPathName), ref report);
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
// If there were warnings, notify the user and give the a chance to cancel.
|
|
|
|
|
if (report.Count != 0) {
|
2019-06-16 23:46:40 +00:00
|
|
|
|
ProjectLoadIssues dlg = new ProjectLoadIssues(mMainWin, report.Format(),
|
2019-06-08 22:48:44 +00:00
|
|
|
|
ProjectLoadIssues.Buttons.ContinueOrCancel);
|
|
|
|
|
bool? ok = dlg.ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (ok != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-10-26 20:07:31 +00:00
|
|
|
|
|
|
|
|
|
newProject.IsReadOnly = dlg.WantReadOnly;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mProject = newProject;
|
|
|
|
|
mProjectPathName = mProject.ProjectPathName = projPathName;
|
2019-12-31 21:59:08 +00:00
|
|
|
|
mDataPathName = dataPathName;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
FinishPrep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds and loads the specified data file. The file's length and CRC must match
|
|
|
|
|
/// the project's expectations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dataPathName">Full path to file.</param>
|
|
|
|
|
/// <param name="proj">Project object.</param>
|
|
|
|
|
/// <param name="cancel">Returns true if we want to cancel the attempt.</param>
|
2020-07-02 00:59:12 +00:00
|
|
|
|
/// <returns>File data.</returns>
|
2019-06-08 22:48:44 +00:00
|
|
|
|
private byte[] FindValidDataFile(ref string dataPathName, DisasmProject proj,
|
|
|
|
|
out bool cancel) {
|
2021-07-20 18:28:26 +00:00
|
|
|
|
// TODO(someday):
|
|
|
|
|
// It would be nice to "fix" the length and CRC if they don't match while we're
|
|
|
|
|
// making manual edits to test files. We can pass "can fix" to the ChooseDataFile
|
|
|
|
|
// dialog, and have it return a "want fix" if they click on the "fix" button, and
|
|
|
|
|
// only enable this if the DEBUG menu is enabled. It's a little ugly but mostly
|
|
|
|
|
// works. One issue that must be handled is that "proj" has sized a bunch of data
|
|
|
|
|
// structures based on the expected file length, and will blow up if the actual
|
|
|
|
|
// length is different. So we really need to check both len/crc here, and if
|
|
|
|
|
// all broken things are fixable, return the "do fix" back to the caller so
|
|
|
|
|
// it can re-generate the DisasmProject object with the corrected length.
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
FileInfo fi = new FileInfo(dataPathName);
|
|
|
|
|
if (!fi.Exists) {
|
|
|
|
|
Debug.WriteLine("File '" + dataPathName + "' doesn't exist");
|
|
|
|
|
dataPathName = ChooseDataFile(dataPathName,
|
|
|
|
|
Res.Strings.OPEN_DATA_DOESNT_EXIST);
|
|
|
|
|
cancel = (dataPathName == null);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (fi.Length != proj.FileDataLength) {
|
|
|
|
|
Debug.WriteLine("File '" + dataPathName + "' has length=" + fi.Length +
|
|
|
|
|
", expected " + proj.FileDataLength);
|
|
|
|
|
dataPathName = ChooseDataFile(dataPathName,
|
|
|
|
|
string.Format(Res.Strings.OPEN_DATA_WRONG_LENGTH_FMT,
|
|
|
|
|
fi.Length, proj.FileDataLength));
|
|
|
|
|
cancel = (dataPathName == null);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-03-01 23:03:12 +00:00
|
|
|
|
byte[] fileData;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
try {
|
|
|
|
|
fileData = LoadDataFile(dataPathName);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Debug.WriteLine("File '" + dataPathName + "' failed to load: " + ex.Message);
|
|
|
|
|
dataPathName = ChooseDataFile(dataPathName,
|
|
|
|
|
string.Format(Res.Strings.OPEN_DATA_LOAD_FAILED_FMT, ex.Message));
|
|
|
|
|
cancel = (dataPathName == null);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
uint crc = CRC32.OnWholeBuffer(0, fileData);
|
|
|
|
|
if (crc != proj.FileDataCrc32) {
|
|
|
|
|
Debug.WriteLine("File '" + dataPathName + "' has CRC32=" + crc +
|
|
|
|
|
", expected " + proj.FileDataCrc32);
|
|
|
|
|
// Format the CRC as signed decimal, so that interested parties can
|
|
|
|
|
// easily replace the value in the .dis65 file.
|
|
|
|
|
dataPathName = ChooseDataFile(dataPathName,
|
|
|
|
|
string.Format(Res.Strings.OPEN_DATA_WRONG_CRC_FMT,
|
|
|
|
|
(int)crc, (int)proj.FileDataCrc32));
|
|
|
|
|
cancel = (dataPathName == null);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancel = false;
|
|
|
|
|
return fileData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays a "do you want to pick a different file" message, then (on OK) allows the
|
|
|
|
|
/// user to select a file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="origPath">Pathname of original file.</param>
|
|
|
|
|
/// <param name="errorMsg">Message to display in the message box.</param>
|
|
|
|
|
/// <returns>Full path of file to open.</returns>
|
|
|
|
|
private string ChooseDataFile(string origPath, string errorMsg) {
|
2019-06-16 23:46:40 +00:00
|
|
|
|
DataFileLoadIssue dlg = new DataFileLoadIssue(mMainWin, origPath, errorMsg);
|
2019-06-08 22:48:44 +00:00
|
|
|
|
bool? ok = dlg.ShowDialog();
|
|
|
|
|
if (ok != true) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenFileDialog fileDlg = new OpenFileDialog() {
|
|
|
|
|
FileName = Path.GetFileName(origPath),
|
|
|
|
|
Filter = Res.Strings.FILE_FILTER_ALL
|
|
|
|
|
};
|
|
|
|
|
if (fileDlg.ShowDialog() != true) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string newPath = Path.GetFullPath(fileDlg.FileName);
|
|
|
|
|
Debug.WriteLine("User selected data file " + newPath);
|
|
|
|
|
return newPath;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-21 23:27:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves the project, querying for the filename.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True on success, false if the save attempt failed or was canceled.</returns>
|
|
|
|
|
public bool SaveProjectAs() {
|
2019-10-26 20:07:31 +00:00
|
|
|
|
Debug.Assert(!mProject.IsReadOnly);
|
2019-06-08 22:48:44 +00:00
|
|
|
|
SaveFileDialog fileDlg = new SaveFileDialog() {
|
|
|
|
|
Filter = ProjectFile.FILENAME_FILTER + "|" + Res.Strings.FILE_FILTER_ALL,
|
|
|
|
|
FilterIndex = 1,
|
|
|
|
|
ValidateNames = true,
|
|
|
|
|
AddExtension = true,
|
|
|
|
|
FileName = Path.GetFileName(mDataPathName) + ProjectFile.FILENAME_EXT
|
|
|
|
|
};
|
2019-06-21 23:27:58 +00:00
|
|
|
|
if (fileDlg.ShowDialog() != true) {
|
|
|
|
|
Debug.WriteLine("SaveAs canceled by user");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
string pathName = Path.GetFullPath(fileDlg.FileName);
|
|
|
|
|
Debug.WriteLine("Project save path: " + pathName);
|
|
|
|
|
if (!DoSave(pathName)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Success, record the path name.
|
|
|
|
|
mProjectPathName = mProject.ProjectPathName = pathName;
|
|
|
|
|
|
|
|
|
|
// add it to the title bar
|
2019-07-16 21:36:09 +00:00
|
|
|
|
UpdateTitle();
|
2019-06-21 23:27:58 +00:00
|
|
|
|
return true;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-21 22:06:04 +00:00
|
|
|
|
/// <summary>
|
2019-06-21 23:27:58 +00:00
|
|
|
|
/// Saves the project. If it hasn't been saved before, use save-as behavior instead.
|
2019-06-21 22:06:04 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True on success, false if the save attempt failed.</returns>
|
2019-06-21 23:27:58 +00:00
|
|
|
|
public bool SaveProject() {
|
2019-10-26 20:07:31 +00:00
|
|
|
|
Debug.Assert(!mProject.IsReadOnly);
|
2019-06-08 22:48:44 +00:00
|
|
|
|
if (string.IsNullOrEmpty(mProjectPathName)) {
|
2019-06-21 23:27:58 +00:00
|
|
|
|
return SaveProjectAs();
|
2019-06-08 22:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
return DoSave(mProjectPathName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool DoSave(string pathName) {
|
|
|
|
|
Debug.WriteLine("SAVING " + pathName);
|
|
|
|
|
if (!ProjectFile.SerializeToFile(mProject, pathName, out string errorMessage)) {
|
|
|
|
|
MessageBox.Show(Res.Strings.ERR_PROJECT_SAVE_FAIL + ": " + errorMessage,
|
|
|
|
|
Res.Strings.OPERATION_FAILED,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mProject.ResetDirtyFlag();
|
|
|
|
|
// If the debug dialog is visible, update it.
|
|
|
|
|
if (mShowUndoRedoHistoryDialog != null) {
|
2019-07-16 00:18:28 +00:00
|
|
|
|
mShowUndoRedoHistoryDialog.DisplayText = mProject.DebugGetUndoRedoHistory();
|
2019-06-08 22:48:44 +00:00
|
|
|
|
}
|
2019-07-16 21:36:09 +00:00
|
|
|
|
UpdateTitle();
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
// Update this, in case this was a new project.
|
|
|
|
|
UpdateRecentProjectList(pathName);
|
|
|
|
|
|
|
|
|
|
// Seems like a good time to save this off too.
|
|
|
|
|
SaveAppSettings();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-06-19 23:31:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles main window closing.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if it's okay for the window to close, false to cancel it.</returns>
|
|
|
|
|
public bool WindowClosing() {
|
|
|
|
|
SaveAppSettings();
|
2019-07-15 01:12:03 +00:00
|
|
|
|
if (!CloseProject()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WPF won't exit until all windows are closed, so any unowned windows need
|
|
|
|
|
// to be cleaned up here.
|
2020-08-20 20:18:46 +00:00
|
|
|
|
mApple2ScreenChartDialog?.Close();
|
2019-07-16 00:18:28 +00:00
|
|
|
|
mAsciiChartDialog?.Close();
|
2019-10-21 22:15:09 +00:00
|
|
|
|
mInstructionChartDialog?.Close();
|
2019-07-16 00:18:28 +00:00
|
|
|
|
mHexDumpDialog?.Close();
|
|
|
|
|
mShowAnalysisTimersDialog?.Close();
|
|
|
|
|
mShowAnalyzerOutputDialog?.Close();
|
|
|
|
|
mShowUndoRedoHistoryDialog?.Close();
|
|
|
|
|
|
2019-07-15 01:12:03 +00:00
|
|
|
|
while (mUnownedWindows.Count > 0) {
|
|
|
|
|
int count = mUnownedWindows.Count;
|
|
|
|
|
mUnownedWindows[0].Close();
|
|
|
|
|
if (count == mUnownedWindows.Count) {
|
|
|
|
|
// Window failed to remove itself; this will cause an infinite loop.
|
|
|
|
|
// The user will have to close them manually.
|
|
|
|
|
Debug.Assert(false, "Failed to close window " + mUnownedWindows[0]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2019-06-19 23:31:56 +00:00
|
|
|
|
}
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Closes the project and associated modeless dialogs. Unsaved changes will be
|
|
|
|
|
/// lost, so if the project has outstanding changes the user will be given the
|
|
|
|
|
/// opportunity to cancel.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if the project was closed, false if the user chose to cancel.</returns>
|
|
|
|
|
public bool CloseProject() {
|
2019-06-22 21:41:09 +00:00
|
|
|
|
Debug.WriteLine("CloseProject() - dirty=" +
|
2019-06-08 22:48:44 +00:00
|
|
|
|
(mProject == null ? "N/A" : mProject.IsDirty.ToString()));
|
|
|
|
|
if (mProject != null && mProject.IsDirty) {
|
2019-06-16 23:46:40 +00:00
|
|
|
|
DiscardChanges dlg = new DiscardChanges(mMainWin);
|
2019-06-08 22:48:44 +00:00
|
|
|
|
bool? ok = dlg.ShowDialog();
|
|
|
|
|
if (ok != true) {
|
|
|
|
|
return false;
|
|
|
|
|
} else if (dlg.UserChoice == DiscardChanges.Choice.SaveAndContinue) {
|
2019-06-21 23:27:58 +00:00
|
|
|
|
if (!SaveProject()) {
|
2019-06-08 22:48:44 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close modeless dialogs that depend on project.
|
2019-07-16 00:18:28 +00:00
|
|
|
|
mHexDumpDialog?.Close();
|
|
|
|
|
mShowAnalysisTimersDialog?.Close();
|
|
|
|
|
mShowAnalyzerOutputDialog?.Close();
|
|
|
|
|
mShowUndoRedoHistoryDialog?.Close();
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
// Discard all project state.
|
|
|
|
|
if (mProject != null) {
|
|
|
|
|
mProject.Cleanup();
|
|
|
|
|
mProject = null;
|
|
|
|
|
}
|
|
|
|
|
mDataPathName = null;
|
|
|
|
|
mProjectPathName = null;
|
2021-11-17 19:18:23 +00:00
|
|
|
|
|
|
|
|
|
// We may get a "selection changed" message as things are being torn down. Clear
|
|
|
|
|
// these so we don't try to remove the highlight from something that doesn't exist.
|
2019-06-21 22:06:04 +00:00
|
|
|
|
mTargetHighlightIndex = -1;
|
2021-11-17 19:18:23 +00:00
|
|
|
|
mOperandHighlights.Clear();
|
2019-06-22 21:41:09 +00:00
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
mMainWin.ShowCodeListView = false;
|
2019-07-19 22:24:51 +00:00
|
|
|
|
mMainWin.ProjectClosing();
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
mGenerationLog = null;
|
|
|
|
|
|
2019-12-07 21:55:11 +00:00
|
|
|
|
UpdateTitle();
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
// Not necessary, but it lets us check the memory monitor to see if we got
|
|
|
|
|
// rid of everything.
|
|
|
|
|
GC.Collect();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-26 20:07:31 +00:00
|
|
|
|
public bool IsProjectOpen {
|
|
|
|
|
get { return mProject != null; }
|
|
|
|
|
}
|
|
|
|
|
public bool IsProjectReadOnly {
|
|
|
|
|
get { return mProject != null && mProject.IsReadOnly; }
|
2019-06-08 22:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-24 00:24:51 +00:00
|
|
|
|
public void AssembleProject() {
|
|
|
|
|
if (string.IsNullOrEmpty(mProjectPathName)) {
|
|
|
|
|
// We need a project pathname so we know where to write the assembler
|
|
|
|
|
// source files, and what to call the output files. We could just pop up the
|
|
|
|
|
// Save As dialog, but that seems confusing unless we do a custom dialog with
|
|
|
|
|
// an explanation, or have some annoying click-through.
|
|
|
|
|
//
|
|
|
|
|
// This only appears for never-saved projects, not projects with unsaved data.
|
|
|
|
|
MessageBox.Show(Res.Strings.SAVE_BEFORE_ASM, Res.Strings.SAVE_BEFORE_ASM_CAPTION,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AsmGen.WpfGui.GenAndAsm dlg =
|
2019-07-17 00:16:47 +00:00
|
|
|
|
new AsmGen.WpfGui.GenAndAsm(mMainWin, this, mProject, mProjectPathName);
|
2019-06-24 00:24:51 +00:00
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 18:36:07 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Copies the selection to the clipboard as formatted text.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void CopyToClipboard() {
|
2019-09-11 00:43:31 +00:00
|
|
|
|
DisplayListSelection selection = mMainWin.CodeDisplayList.SelectedIndices;
|
2019-09-12 20:57:52 +00:00
|
|
|
|
if (selection.Count == 0) {
|
|
|
|
|
Debug.WriteLine("Selection is empty!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-21 22:30:11 +00:00
|
|
|
|
ClipLineFormat format = AppSettings.Global.GetEnum(AppSettings.CLIP_LINE_FORMAT,
|
|
|
|
|
ClipLineFormat.AssemblerSource);
|
2019-07-11 18:36:07 +00:00
|
|
|
|
|
2020-07-16 17:48:03 +00:00
|
|
|
|
int[] rightWidths = new int[] { 16, 6, 16, 80 };
|
2019-09-12 20:57:52 +00:00
|
|
|
|
|
|
|
|
|
Exporter.ActiveColumnFlags colFlags = Exporter.ActiveColumnFlags.None;
|
|
|
|
|
if (format == ClipLineFormat.Disassembly) {
|
|
|
|
|
colFlags |= Exporter.ActiveColumnFlags.Address |
|
|
|
|
|
Exporter.ActiveColumnFlags.Bytes;
|
|
|
|
|
} else if (format == ClipLineFormat.AllColumns) {
|
|
|
|
|
colFlags = Exporter.ActiveColumnFlags.ALL;
|
|
|
|
|
}
|
2019-12-30 01:59:35 +00:00
|
|
|
|
Exporter eport = new Exporter(mProject, CodeLineList, mFormatter,
|
2019-09-12 20:57:52 +00:00
|
|
|
|
colFlags, rightWidths);
|
|
|
|
|
eport.Selection = selection;
|
2019-09-14 00:09:06 +00:00
|
|
|
|
|
|
|
|
|
// Might want to set Mouse.OverrideCursor if the selection exceeds a few
|
|
|
|
|
// hundred thousand lines.
|
2019-09-12 20:57:52 +00:00
|
|
|
|
eport.SelectionToString(true, out string fullText, out string csvText);
|
2019-07-11 18:36:07 +00:00
|
|
|
|
|
|
|
|
|
DataObject dataObject = new DataObject();
|
|
|
|
|
dataObject.SetText(fullText.ToString());
|
|
|
|
|
|
|
|
|
|
// We want to have both plain text and CSV data on the clipboard. To add both
|
|
|
|
|
// formats we need to stream it to a DataObject. Complicating matters is Excel's
|
|
|
|
|
// entirely reasonable desire to have data in UTF-8 rather than UTF-16.
|
|
|
|
|
//
|
|
|
|
|
// (I'm not sure pasting assembly bits into Excel is actually useful, so this
|
|
|
|
|
// should probably be optional.)
|
|
|
|
|
//
|
|
|
|
|
// https://stackoverflow.com/a/369219/294248
|
2019-09-11 00:43:31 +00:00
|
|
|
|
const bool addCsv = true;
|
2019-07-11 18:36:07 +00:00
|
|
|
|
if (addCsv) {
|
2019-09-11 00:43:31 +00:00
|
|
|
|
byte[] csvData = Encoding.UTF8.GetBytes(csvText.ToString());
|
2019-07-11 18:36:07 +00:00
|
|
|
|
MemoryStream stream = new MemoryStream(csvData);
|
|
|
|
|
dataObject.SetData(DataFormats.CommaSeparatedValue, stream);
|
|
|
|
|
}
|
|
|
|
|
Clipboard.SetDataObject(dataObject, true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-24 22:48:11 +00:00
|
|
|
|
/// <summary>
|
2024-03-02 22:48:06 +00:00
|
|
|
|
/// Handles Edit > App Settings.
|
2019-06-24 22:48:11 +00:00
|
|
|
|
/// </summary>
|
2019-07-07 00:24:42 +00:00
|
|
|
|
public void EditAppSettings() {
|
2019-07-17 00:16:47 +00:00
|
|
|
|
ShowAppSettings(mMainWin, WpfGui.EditAppSettings.Tab.Unknown,
|
|
|
|
|
AsmGen.AssemblerInfo.Id.Unknown);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 22:48:06 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the application settings dialog. All changes to settings are made directly
|
|
|
|
|
/// to the AppSettings.Global object.
|
|
|
|
|
/// </summary>
|
2019-07-17 00:16:47 +00:00
|
|
|
|
public void ShowAppSettings(Window owner, EditAppSettings.Tab initialTab,
|
|
|
|
|
AsmGen.AssemblerInfo.Id initialAsmId) {
|
2024-03-02 22:48:06 +00:00
|
|
|
|
EditAppSettings dlg = new EditAppSettings(owner, mMainWin, initialTab, initialAsmId);
|
|
|
|
|
dlg.SettingsApplied += SetAppSettings; // called when "Apply" is clicked
|
2019-06-24 22:48:11 +00:00
|
|
|
|
dlg.ShowDialog();
|
2024-03-02 22:48:06 +00:00
|
|
|
|
}
|
Various improvements
The PseudoOpNames class is increasingly being used in situations
where mutability is undesirable. This change makes instances
immutable, eliminating the Copy() method and adding a constructor
that takes a Dictionary. The serialization code now operates on a
Dictionary instead of the class properties, but the JSON encoding is
identical, so this doesn't invalidate app settings file data.
Added an equality test to PseudoOpNames. In LineListGen, don't
reset the line list if the names haven't actually changed.
Use a table lookup for C64 character conversions. I figure that
should be faster than multiple conditionals on a modern x64 system.
Fixed a 64tass generator issue where we tried to query project
properties in a call that might not have a project available
(specifically, getting FormatConfig values out of the generator for
use in the "quick set" buttons for Display Format).
Fixed a regression test harness issue where, if the assembler reported
success but didn't actually generate output, an exception would be
thrown that halted the tests.
Increased the width of text entry fields on the Pseudo-Op tab of app
settings. The previous 8-character limit wasn't wide enough to hold
ACME's "!pseudopc". Also, use TrimEnd() to remove trailing spaces
(leading spaces are still allowed).
In the last couple of months, Win10 started stalling for a fraction
of a second when executing assemblers. It doesn't do this every
time; mostly it happens if it has been a while since the assembler
was run. My guess is this has to do with changes to the built-in
malware scanner. Whatever the case, we now change the mouse pointer
to a wait cursor while updating the assembler version cache.
2019-08-17 18:14:05 +00:00
|
|
|
|
|
2024-03-02 22:48:06 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies settings to the project, and saves them to the settings files.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetAppSettings() {
|
|
|
|
|
ApplyAppSettings();
|
|
|
|
|
SaveAppSettings();
|
2019-06-24 22:48:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
public void HandleCodeListDoubleClick(int row, int col) {
|
2019-08-14 22:25:09 +00:00
|
|
|
|
//Debug.WriteLine("DCLICK: row=" + row + " col=" + col);
|
2019-07-14 22:11:27 +00:00
|
|
|
|
mMainWin.CodeListView_DebugValidateSelectionCount();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
|
|
|
|
|
// Clicking on some types of lines, such as ORG directives, results in
|
|
|
|
|
// specific behavior regardless of which column you click in. We're just
|
|
|
|
|
// checking the clicked-on line to decide what action to take. If it doesn't
|
|
|
|
|
// make sense to do for a multi-line selection, the action will have been
|
|
|
|
|
// disabled.
|
|
|
|
|
LineListGen.Line line = CodeLineList[row];
|
|
|
|
|
switch (line.LineType) {
|
|
|
|
|
case LineListGen.Line.Type.EquDirective:
|
|
|
|
|
// Currently only does something for project symbols; platform symbols
|
|
|
|
|
// do nothing.
|
2019-07-14 20:18:10 +00:00
|
|
|
|
if (CanEditProjectSymbol()) {
|
2020-04-23 17:42:54 +00:00
|
|
|
|
EditProjectSymbol((CodeListColumn)col);
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2021-09-22 21:39:39 +00:00
|
|
|
|
case LineListGen.Line.Type.ArStartDirective:
|
2021-09-27 00:06:43 +00:00
|
|
|
|
case LineListGen.Line.Type.ArEndDirective:
|
2021-10-02 20:47:05 +00:00
|
|
|
|
if ((CodeListColumn)col == CodeListColumn.Opcode) {
|
|
|
|
|
JumpToOperandTarget(line, false);
|
|
|
|
|
} else if (CanEditAddress()) {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
EditAddress();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.RegWidthDirective:
|
2019-06-21 22:06:04 +00:00
|
|
|
|
if (CanEditStatusFlags()) {
|
|
|
|
|
EditStatusFlags();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2020-07-09 22:17:47 +00:00
|
|
|
|
case LineListGen.Line.Type.DataBankDirective:
|
|
|
|
|
if (CanEditDataBank()) {
|
|
|
|
|
EditDataBank();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-06-16 23:34:47 +00:00
|
|
|
|
case LineListGen.Line.Type.LongComment:
|
2019-07-07 23:18:46 +00:00
|
|
|
|
if (CanEditLongComment()) {
|
|
|
|
|
EditLongComment();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.Note:
|
2019-07-14 00:04:47 +00:00
|
|
|
|
if (CanEditNote()) {
|
|
|
|
|
EditNote();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2019-08-27 23:45:37 +00:00
|
|
|
|
case LineListGen.Line.Type.LocalVariableTable:
|
|
|
|
|
if (CanEditLocalVariableTable()) {
|
|
|
|
|
EditLocalVariableTable();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-11-23 04:45:57 +00:00
|
|
|
|
case LineListGen.Line.Type.VisualizationSet:
|
|
|
|
|
if (CanEditVisualizationSet()) {
|
|
|
|
|
EditVisualizationSet();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-06-16 23:34:47 +00:00
|
|
|
|
|
|
|
|
|
case LineListGen.Line.Type.Code:
|
|
|
|
|
case LineListGen.Line.Type.Data:
|
|
|
|
|
// For code and data, we have to break it down by column.
|
2019-06-27 00:11:58 +00:00
|
|
|
|
switch ((CodeListColumn)col) {
|
|
|
|
|
case CodeListColumn.Offset:
|
2019-06-16 23:34:47 +00:00
|
|
|
|
// does nothing
|
|
|
|
|
break;
|
2019-06-27 00:11:58 +00:00
|
|
|
|
case CodeListColumn.Address:
|
2019-06-16 23:34:47 +00:00
|
|
|
|
// edit address
|
|
|
|
|
if (CanEditAddress()) {
|
|
|
|
|
EditAddress();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-06-27 00:11:58 +00:00
|
|
|
|
case CodeListColumn.Bytes:
|
2019-07-13 00:04:14 +00:00
|
|
|
|
ShowHexDump();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
break;
|
2019-06-27 00:11:58 +00:00
|
|
|
|
case CodeListColumn.Flags:
|
2019-06-21 22:06:04 +00:00
|
|
|
|
if (CanEditStatusFlags()) {
|
|
|
|
|
EditStatusFlags();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2019-06-27 00:11:58 +00:00
|
|
|
|
case CodeListColumn.Attributes:
|
2019-06-16 23:34:47 +00:00
|
|
|
|
// does nothing
|
|
|
|
|
break;
|
2019-06-27 00:11:58 +00:00
|
|
|
|
case CodeListColumn.Label:
|
2019-07-07 00:24:42 +00:00
|
|
|
|
if (CanEditLabel()) {
|
|
|
|
|
EditLabel();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2019-06-27 00:11:58 +00:00
|
|
|
|
case CodeListColumn.Opcode:
|
2020-07-09 22:17:47 +00:00
|
|
|
|
if (IsPlbInstruction(line) && CanEditDataBank()) {
|
2021-10-11 21:44:44 +00:00
|
|
|
|
// Special handling for PLB instruction, so you can update the bank
|
|
|
|
|
// value just by double-clicking on it. Only used for PLBs without
|
|
|
|
|
// user- or auto-assigned bank changes.
|
2020-07-09 22:17:47 +00:00
|
|
|
|
EditDataBank();
|
|
|
|
|
} else {
|
|
|
|
|
JumpToOperandTarget(line, false);
|
|
|
|
|
}
|
2019-06-16 23:34:47 +00:00
|
|
|
|
break;
|
2019-06-27 00:11:58 +00:00
|
|
|
|
case CodeListColumn.Operand:
|
2019-07-08 22:40:30 +00:00
|
|
|
|
if (CanEditOperand()) {
|
|
|
|
|
EditOperand();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2019-06-27 00:11:58 +00:00
|
|
|
|
case CodeListColumn.Comment:
|
2019-07-11 22:55:43 +00:00
|
|
|
|
if (CanEditComment()) {
|
|
|
|
|
EditComment();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Debug.WriteLine("Double-click: unhandled line type " + line.LineType);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 22:17:47 +00:00
|
|
|
|
private bool IsPlbInstruction(LineListGen.Line line) {
|
|
|
|
|
if (line.LineType != LineListGen.Line.Type.Code) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int offset = line.FileOffset;
|
|
|
|
|
Anattrib attr = mProject.GetAnattrib(offset);
|
|
|
|
|
|
|
|
|
|
// should always be an instruction start since this is a code line
|
|
|
|
|
if (!attr.IsInstructionStart) {
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpDef op = mProject.CpuDef.GetOpDef(mProject.FileData[offset]);
|
|
|
|
|
if (op != OpDef.OpPLB_StackPull) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 23:28:29 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Jumps to the line referenced by the operand of the selected line.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="line">Selected line.</param>
|
|
|
|
|
/// <param name="testOnly">If set, don't actually do the goto.</param>
|
|
|
|
|
/// <returns>True if a jump is available for this line.</returns>
|
|
|
|
|
private bool JumpToOperandTarget(LineListGen.Line line, bool testOnly) {
|
2019-10-10 20:49:21 +00:00
|
|
|
|
if (line.FileOffset < 0) {
|
|
|
|
|
// Double-click on project symbol EQUs and the file header comment are handled
|
|
|
|
|
// elsewhere.
|
2020-06-07 23:28:29 +00:00
|
|
|
|
return false;
|
2019-10-10 20:49:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
ORG rework, part 5
Updated project file format to save the new map entries.
Tweaked appearance of .arend directives to show the .arstart address
in the operand field. This makes it easier to match them up on screen.
Also, add a synthetic comment on auto-generated .arstart entries.
Added .arstart/.arend to the things that respond to Jump to Operand
(Ctrl+J). Selecting one jumps to the other end. (Well, it jumps
to the code nearest the other, which will do for now.)
Added a menu item to display a text rendering of the address map.
Helpful when things get complicated.
Modified the linear map iterator to return .arend items with the offset
of the last byte in the region, rather than the first byte of the
following region. While the "exclusive end" approach is pretty
common, it caused problems when updating the line list, because it
meant that the .arend directives were outside the range of offsets
being updated (and, for directives at the end of the file, outside
the file itself). This was painful to deal with for partial updates.
Changing this required some relatively subtle changes and annoyed some
of the debug assertions, such as the one where all Line items have
offsets that match the start of a line, but it's the cleaner approach.
2021-09-28 00:02:18 +00:00
|
|
|
|
if (line.IsAddressRangeDirective) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// TODO(someday): make this jump to the specific directive rather than the first
|
|
|
|
|
// (should be able to do it with LineDelta)
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
AddressMap.AddressRegion region = CodeLineList.GetAddrRegionFromLine(line,
|
|
|
|
|
out bool unused);
|
ORG rework, part 5
Updated project file format to save the new map entries.
Tweaked appearance of .arend directives to show the .arstart address
in the operand field. This makes it easier to match them up on screen.
Also, add a synthetic comment on auto-generated .arstart entries.
Added .arstart/.arend to the things that respond to Jump to Operand
(Ctrl+J). Selecting one jumps to the other end. (Well, it jumps
to the code nearest the other, which will do for now.)
Added a menu item to display a text rendering of the address map.
Helpful when things get complicated.
Modified the linear map iterator to return .arend items with the offset
of the last byte in the region, rather than the first byte of the
following region. While the "exclusive end" approach is pretty
common, it caused problems when updating the line list, because it
meant that the .arend directives were outside the range of offsets
being updated (and, for directives at the end of the file, outside
the file itself). This was painful to deal with for partial updates.
Changing this required some relatively subtle changes and annoyed some
of the debug assertions, such as the one where all Line items have
offsets that match the start of a line, but it's the cleaner approach.
2021-09-28 00:02:18 +00:00
|
|
|
|
if (region == null) {
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!testOnly) {
|
|
|
|
|
if (line.LineType == LineListGen.Line.Type.ArStartDirective) {
|
|
|
|
|
// jump to end
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(new NavStack.Location(region.Offset + region.ActualLength - 1,
|
|
|
|
|
0, NavStack.GoToMode.JumpToArEnd), true);
|
ORG rework, part 5
Updated project file format to save the new map entries.
Tweaked appearance of .arend directives to show the .arstart address
in the operand field. This makes it easier to match them up on screen.
Also, add a synthetic comment on auto-generated .arstart entries.
Added .arstart/.arend to the things that respond to Jump to Operand
(Ctrl+J). Selecting one jumps to the other end. (Well, it jumps
to the code nearest the other, which will do for now.)
Added a menu item to display a text rendering of the address map.
Helpful when things get complicated.
Modified the linear map iterator to return .arend items with the offset
of the last byte in the region, rather than the first byte of the
following region. While the "exclusive end" approach is pretty
common, it caused problems when updating the line list, because it
meant that the .arend directives were outside the range of offsets
being updated (and, for directives at the end of the file, outside
the file itself). This was painful to deal with for partial updates.
Changing this required some relatively subtle changes and annoyed some
of the debug assertions, such as the one where all Line items have
offsets that match the start of a line, but it's the cleaner approach.
2021-09-28 00:02:18 +00:00
|
|
|
|
} else {
|
|
|
|
|
// jump to start
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(new NavStack.Location(region.Offset,
|
|
|
|
|
0, NavStack.GoToMode.JumpToArStart), true);
|
ORG rework, part 5
Updated project file format to save the new map entries.
Tweaked appearance of .arend directives to show the .arstart address
in the operand field. This makes it easier to match them up on screen.
Also, add a synthetic comment on auto-generated .arstart entries.
Added .arstart/.arend to the things that respond to Jump to Operand
(Ctrl+J). Selecting one jumps to the other end. (Well, it jumps
to the code nearest the other, which will do for now.)
Added a menu item to display a text rendering of the address map.
Helpful when things get complicated.
Modified the linear map iterator to return .arend items with the offset
of the last byte in the region, rather than the first byte of the
following region. While the "exclusive end" approach is pretty
common, it caused problems when updating the line list, because it
meant that the .arend directives were outside the range of offsets
being updated (and, for directives at the end of the file, outside
the file itself). This was painful to deal with for partial updates.
Changing this required some relatively subtle changes and annoyed some
of the debug assertions, such as the one where all Line items have
offsets that match the start of a line, but it's the cleaner approach.
2021-09-28 00:02:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-10 20:49:21 +00:00
|
|
|
|
Anattrib attr = mProject.GetAnattrib(line.FileOffset);
|
|
|
|
|
FormatDescriptor dfd = attr.DataDescriptor;
|
|
|
|
|
|
2020-07-04 00:37:04 +00:00
|
|
|
|
if (dfd != null && dfd.HasSymbol) {
|
|
|
|
|
// Operand has a symbol, do a symbol lookup. This is slower than a simple
|
|
|
|
|
// jump based on OperandOffset, but if we've incorporated reloc data then
|
|
|
|
|
// the jump will be wrong.
|
2019-10-10 20:49:21 +00:00
|
|
|
|
if (dfd.SymbolRef.IsVariable) {
|
2020-06-07 23:28:29 +00:00
|
|
|
|
if (!testOnly) {
|
|
|
|
|
GoToVarDefinition(line.FileOffset, dfd.SymbolRef, true);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-10-10 20:49:21 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (mProject.SymbolTable.TryGetValue(dfd.SymbolRef.Label, out Symbol sym)) {
|
|
|
|
|
if (sym.SymbolSource == Symbol.Source.User ||
|
2021-10-05 03:41:19 +00:00
|
|
|
|
sym.SymbolSource == Symbol.Source.Auto ||
|
|
|
|
|
sym.SymbolSource == Symbol.Source.AddrPreLabel) {
|
2019-10-10 20:49:21 +00:00
|
|
|
|
int labelOffset = mProject.FindLabelOffsetByName(dfd.SymbolRef.Label);
|
|
|
|
|
if (labelOffset >= 0) {
|
2020-06-07 23:28:29 +00:00
|
|
|
|
if (!testOnly) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
NavStack.GoToMode mode = NavStack.GoToMode.JumpToCodeData;
|
|
|
|
|
if (sym.SymbolSource == Symbol.Source.AddrPreLabel) {
|
|
|
|
|
mode = NavStack.GoToMode.JumpToArStart;
|
|
|
|
|
}
|
|
|
|
|
GoToLocation(new NavStack.Location(labelOffset, 0, mode), true);
|
2020-06-07 23:28:29 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-10-10 20:49:21 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (sym.SymbolSource == Symbol.Source.Platform ||
|
|
|
|
|
sym.SymbolSource == Symbol.Source.Project) {
|
|
|
|
|
// find entry
|
|
|
|
|
for (int i = 0; i < mProject.ActiveDefSymbolList.Count; i++) {
|
|
|
|
|
if (mProject.ActiveDefSymbolList[i] == sym) {
|
|
|
|
|
int offset = LineListGen.DefSymOffsetFromIndex(i);
|
2020-06-07 23:28:29 +00:00
|
|
|
|
if (!testOnly) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(new NavStack.Location(offset, 0,
|
|
|
|
|
NavStack.GoToMode.JumpToCodeData), true);
|
2020-06-07 23:28:29 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-10-10 20:49:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// must be a broken weak symbol ref
|
|
|
|
|
Debug.WriteLine("Operand symbol not found: " + dfd.SymbolRef.Label);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-04 00:37:04 +00:00
|
|
|
|
} else if (attr.OperandOffset >= 0) {
|
|
|
|
|
// Operand has an in-file target offset. We can resolve it as a numeric reference.
|
|
|
|
|
// Find the line for that offset and jump to it.
|
|
|
|
|
if (!testOnly) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(new NavStack.Location(attr.OperandOffset, 0,
|
|
|
|
|
NavStack.GoToMode.JumpToCodeData), true);
|
2020-07-04 00:37:04 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-10-10 20:49:21 +00:00
|
|
|
|
} else if (attr.IsDataStart || attr.IsInlineDataStart) {
|
|
|
|
|
// If it's an Address or Symbol, we can try to resolve
|
|
|
|
|
// the value. (Symbols should have been resolved by the
|
|
|
|
|
// previous clause, but Address entries would not have been.)
|
|
|
|
|
int operandOffset = DataAnalysis.GetDataOperandOffset(mProject, line.FileOffset);
|
|
|
|
|
if (operandOffset >= 0) {
|
2020-06-07 23:28:29 +00:00
|
|
|
|
if (!testOnly) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(new NavStack.Location(operandOffset, 0,
|
|
|
|
|
NavStack.GoToMode.JumpToCodeData), true);
|
2020-06-07 23:28:29 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-10-10 20:49:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-07 23:28:29 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
2019-10-10 20:49:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 20:50:15 +00:00
|
|
|
|
public bool CanDeleteMlc() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return (SelectionAnalysis.mLineType == LineListGen.Line.Type.LongComment ||
|
|
|
|
|
SelectionAnalysis.mLineType == LineListGen.Line.Type.Note);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete multi-line comment (Note or LongComment)
|
|
|
|
|
public void DeleteMlc() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
LineListGen.Line line = CodeLineList[selIndex];
|
|
|
|
|
int offset = line.FileOffset;
|
|
|
|
|
|
|
|
|
|
UndoableChange uc;
|
|
|
|
|
if (line.LineType == LineListGen.Line.Type.Note) {
|
|
|
|
|
if (!mProject.Notes.TryGetValue(offset, out MultiLineComment oldNote)) {
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uc = UndoableChange.CreateNoteChange(offset, oldNote, null);
|
|
|
|
|
} else if (line.LineType == LineListGen.Line.Type.LongComment) {
|
|
|
|
|
if (!mProject.LongComments.TryGetValue(offset, out MultiLineComment oldComment)) {
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uc = UndoableChange.CreateLongCommentChange(offset, oldComment, null);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 23:34:47 +00:00
|
|
|
|
public bool CanEditAddress() {
|
2021-09-27 00:06:43 +00:00
|
|
|
|
// First line must be code, data, or an AR directive.
|
2019-12-26 01:15:37 +00:00
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
if (selIndex < 0) {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-12-26 01:15:37 +00:00
|
|
|
|
LineListGen.Line selLine = CodeLineList[selIndex];
|
|
|
|
|
if (selLine.LineType != LineListGen.Line.Type.Code &&
|
|
|
|
|
selLine.LineType != LineListGen.Line.Type.Data &&
|
2021-09-27 00:06:43 +00:00
|
|
|
|
selLine.LineType != LineListGen.Line.Type.ArStartDirective &&
|
|
|
|
|
selLine.LineType != LineListGen.Line.Type.ArEndDirective) {
|
2019-12-26 01:15:37 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int lastIndex = mMainWin.CodeListView_GetLastSelectedIndex();
|
2021-09-27 00:06:43 +00:00
|
|
|
|
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// Can only start with arend if it's single-selection.
|
2021-09-27 00:06:43 +00:00
|
|
|
|
if (selIndex != lastIndex && selLine.LineType == LineListGen.Line.Type.ArEndDirective) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// If multiple lines with code/data are selected, there must not be an arstart
|
2021-09-27 00:06:43 +00:00
|
|
|
|
// between them unless we're resizing a region. Determining whether or not a resize
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// is valid is left to the edit dialog. It's okay for an arend to be in the middle
|
|
|
|
|
// so long as the corresponding arstart is at the current offset.
|
2021-09-27 00:06:43 +00:00
|
|
|
|
if (selLine.LineType == LineListGen.Line.Type.ArStartDirective) {
|
|
|
|
|
// Skip overlapping region check.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-12-26 01:15:37 +00:00
|
|
|
|
int firstOffset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
int lastOffset = CodeLineList[lastIndex].FileOffset;
|
|
|
|
|
if (firstOffset == lastOffset) {
|
|
|
|
|
// Single-item selection, we're fine.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-02 20:47:05 +00:00
|
|
|
|
// Anything else is too complicated to be worth messing with here. We could do
|
|
|
|
|
// the work, but we have no good way of telling the user what went wrong.
|
|
|
|
|
// Let the dialog explain it.
|
2019-12-26 01:15:37 +00:00
|
|
|
|
|
2021-10-02 20:47:05 +00:00
|
|
|
|
//// Compute exclusive end point of selected range.
|
|
|
|
|
//int nextOffset = lastOffset + CodeLineList[lastIndex].OffsetSpan;
|
|
|
|
|
|
|
|
|
|
//if (!mProject.AddrMap.IsRangeUnbroken(firstOffset, nextOffset - firstOffset)) {
|
|
|
|
|
// Debug.WriteLine("Found mid-selection AddressMap entry (len=" +
|
|
|
|
|
// (nextOffset - firstOffset) + ")");
|
|
|
|
|
// return false;
|
|
|
|
|
//}
|
2019-12-26 01:15:37 +00:00
|
|
|
|
|
2021-09-27 00:06:43 +00:00
|
|
|
|
//Debug.WriteLine("First +" + firstOffset.ToString("x6") +
|
|
|
|
|
// ", last +" + lastOffset.ToString("x6") + ",next +" + nextOffset.ToString("x6"));
|
|
|
|
|
|
2019-12-26 01:15:37 +00:00
|
|
|
|
return true;
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditAddress() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
2019-12-26 01:15:37 +00:00
|
|
|
|
int lastIndex = mMainWin.CodeListView_GetLastSelectedIndex();
|
|
|
|
|
int firstOffset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
int lastOffset = CodeLineList[lastIndex].FileOffset;
|
2021-09-27 00:06:43 +00:00
|
|
|
|
int nextOffset = lastOffset + CodeLineList[lastIndex].OffsetSpan;
|
2021-09-17 00:02:19 +00:00
|
|
|
|
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// The offset of an arend directive is the last byte in the address region. It
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
// has a span length of zero because it's a directive, so if it's selected as
|
|
|
|
|
// the last offset then our nextOffset calculation will be off by one. (This would
|
|
|
|
|
// be avoided by using an exclusive end offset, but that causes other problems.)
|
|
|
|
|
// Work around it here.
|
|
|
|
|
if (CodeLineList[lastIndex].LineType == LineListGen.Line.Type.ArEndDirective) {
|
|
|
|
|
nextOffset++;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// Compute length of selection. May be zero if it's entirely arstart/arend.
|
2021-09-27 00:06:43 +00:00
|
|
|
|
int selectedLen = nextOffset - firstOffset;
|
|
|
|
|
|
|
|
|
|
AddressMap.AddressRegion curRegion;
|
|
|
|
|
if (CodeLineList[selIndex].LineType == LineListGen.Line.Type.ArStartDirective ||
|
|
|
|
|
CodeLineList[selIndex].LineType == LineListGen.Line.Type.ArEndDirective) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// First selected line was arstart/arend, find the address map entry.
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
curRegion = CodeLineList.GetAddrRegionFromLine(CodeLineList[selIndex],
|
|
|
|
|
out bool isSynth);
|
2021-09-27 00:06:43 +00:00
|
|
|
|
Debug.Assert(curRegion != null);
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
if (isSynth) {
|
|
|
|
|
// Synthetic regions are created for non-addressable "holes" in the map.
|
|
|
|
|
// They're not part of the map, so this is a create operation rather than
|
|
|
|
|
// a resize operation.
|
|
|
|
|
curRegion = null;
|
|
|
|
|
Debug.WriteLine("Ignoring synthetic region");
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("Using region from " + CodeLineList[selIndex].LineType +
|
|
|
|
|
": " + curRegion);
|
|
|
|
|
}
|
2021-09-27 00:06:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (selectedLen == 0) {
|
|
|
|
|
// A length of zero is only possible if nothing but directives were selected,
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// but since the first entry wasn't arstart/arend this can't happen.
|
2021-09-27 00:06:43 +00:00
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
curRegion = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddressMap.AddressMapEntry newEntry = null;
|
|
|
|
|
if (curRegion == null) {
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
// No entry, create a new one. Use the current address as the default value,
|
|
|
|
|
// unless the region is non-addressable.
|
2021-10-05 03:41:19 +00:00
|
|
|
|
Anattrib attr = mProject.GetAnattrib(firstOffset);
|
|
|
|
|
int addr;
|
|
|
|
|
if (attr.IsNonAddressable) {
|
|
|
|
|
addr = Address.NON_ADDR;
|
|
|
|
|
} else {
|
|
|
|
|
addr = attr.Address;
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
}
|
2019-12-26 01:15:37 +00:00
|
|
|
|
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
// Create a prototype entry with the various values.
|
2024-05-20 21:50:18 +00:00
|
|
|
|
newEntry = new AddressMap.AddressMapEntry(firstOffset, selectedLen, addr);
|
2021-09-27 00:06:43 +00:00
|
|
|
|
Debug.WriteLine("New entry prototype: " + newEntry);
|
2019-12-26 01:15:37 +00:00
|
|
|
|
}
|
2021-09-27 00:06:43 +00:00
|
|
|
|
|
|
|
|
|
EditAddress dlg = new EditAddress(mMainWin, curRegion, newEntry,
|
|
|
|
|
selectedLen, firstOffset == lastOffset, mProject, mFormatter);
|
2019-06-21 22:06:04 +00:00
|
|
|
|
if (dlg.ShowDialog() != true) {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-26 01:15:37 +00:00
|
|
|
|
ChangeSet cs = new ChangeSet(1);
|
2021-09-27 00:06:43 +00:00
|
|
|
|
if (curRegion != dlg.ResultEntry) {
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateAddressChange(curRegion, dlg.ResultEntry);
|
|
|
|
|
cs.Add(uc);
|
|
|
|
|
}
|
2019-12-26 01:15:37 +00:00
|
|
|
|
if (cs.Count > 0) {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
} else {
|
2019-12-26 01:15:37 +00:00
|
|
|
|
Debug.WriteLine("EditAddress: no changes");
|
2019-06-16 23:34:47 +00:00
|
|
|
|
}
|
2019-06-15 23:00:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 22:55:43 +00:00
|
|
|
|
public bool CanEditComment() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Line must be code or data.
|
|
|
|
|
return (SelectionAnalysis.mLineType == LineListGen.Line.Type.Code ||
|
|
|
|
|
SelectionAnalysis.mLineType == LineListGen.Line.Type.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditComment() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
|
|
|
|
|
string oldComment = mProject.Comments[offset];
|
|
|
|
|
EditComment dlg = new EditComment(mMainWin, oldComment);
|
|
|
|
|
if (dlg.ShowDialog() == true) {
|
|
|
|
|
if (!oldComment.Equals(dlg.CommentText)) {
|
|
|
|
|
Debug.WriteLine("Changing comment at +" + offset.ToString("x6"));
|
|
|
|
|
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateCommentChange(offset,
|
|
|
|
|
oldComment, dlg.CommentText);
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-07 23:18:46 +00:00
|
|
|
|
public void EditHeaderComment() {
|
|
|
|
|
EditLongComment(LineListGen.Line.HEADER_COMMENT_OFFSET);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 00:56:27 +00:00
|
|
|
|
public bool CanEditDataBank() {
|
|
|
|
|
if (mProject.CpuDef.HasAddr16) {
|
|
|
|
|
return false; // only available for 65816
|
|
|
|
|
}
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-07-09 22:17:47 +00:00
|
|
|
|
return (SelectionAnalysis.mLineType == LineListGen.Line.Type.Code ||
|
|
|
|
|
SelectionAnalysis.mLineType == LineListGen.Line.Type.DataBankDirective);
|
2020-07-09 00:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditDataBank() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
|
2020-07-09 18:10:39 +00:00
|
|
|
|
// Get current user-specified value, or null.
|
2020-07-09 22:17:47 +00:00
|
|
|
|
mProject.DbrOverrides.TryGetValue(offset, out CodeAnalysis.DbrValue curValue);
|
2020-07-09 00:56:27 +00:00
|
|
|
|
|
2020-07-09 18:10:39 +00:00
|
|
|
|
EditDataBank dlg = new EditDataBank(mMainWin, mProject, mFormatter, curValue);
|
2020-07-09 00:56:27 +00:00
|
|
|
|
if (dlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dlg.Result != curValue) {
|
2020-07-09 18:10:39 +00:00
|
|
|
|
Debug.WriteLine("Changing DBR at +" + offset.ToString("x6") + " to $" + dlg.Result);
|
2020-07-09 00:56:27 +00:00
|
|
|
|
UndoableChange uc =
|
|
|
|
|
UndoableChange.CreateDataBankChange(offset, curValue, dlg.Result);
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-07 00:24:42 +00:00
|
|
|
|
public bool CanEditLabel() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
EntityCounts counts = SelectionAnalysis.mEntityCounts;
|
|
|
|
|
// Single line, code or data.
|
|
|
|
|
return (counts.mDataLines > 0 || counts.mCodeLines > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditLabel() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
|
|
|
|
|
Anattrib attr = mProject.GetAnattrib(offset);
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
int addr = attr.Address;
|
|
|
|
|
if (attr.IsNonAddressable) {
|
|
|
|
|
addr = Address.NON_ADDR;
|
|
|
|
|
}
|
|
|
|
|
EditLabel dlg = new EditLabel(mMainWin, attr.Symbol, addr, offset,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mProject.SymbolTable, mFormatter);
|
2019-07-07 00:24:42 +00:00
|
|
|
|
if (dlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: if label matching is case-insensitive, we want to allow a situation
|
|
|
|
|
// where a label is being renamed from "FOO" to "Foo". (We should be able to
|
|
|
|
|
// test for object equality on the Symbol.)
|
|
|
|
|
if (attr.Symbol != dlg.LabelSym) {
|
|
|
|
|
Debug.WriteLine("Changing label at offset +" + offset.ToString("x6"));
|
|
|
|
|
|
|
|
|
|
// For undo/redo, we want to update the UserLabels value. This may
|
|
|
|
|
// be different from the Anattrib symbol, which can have an auto-generated
|
|
|
|
|
// value.
|
|
|
|
|
Symbol oldUserValue = null;
|
|
|
|
|
if (mProject.UserLabels.ContainsKey(offset)) {
|
|
|
|
|
oldUserValue = mProject.UserLabels[offset];
|
|
|
|
|
}
|
2019-09-12 21:24:09 +00:00
|
|
|
|
if (oldUserValue == dlg.LabelSym) {
|
|
|
|
|
// Only expected when attr.Symbol is Auto
|
|
|
|
|
Debug.Assert(attr.Symbol.SymbolSource == Symbol.Source.Auto);
|
|
|
|
|
Debug.Assert(oldUserValue == null);
|
|
|
|
|
Debug.WriteLine("Ignoring attempt to delete an auto label");
|
|
|
|
|
} else {
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateLabelChange(offset,
|
|
|
|
|
oldUserValue, dlg.LabelSym);
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
2019-07-07 00:24:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 22:53:23 +00:00
|
|
|
|
public bool CanCreateLocalVariableTable() {
|
2019-10-02 02:13:15 +00:00
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-09-19 22:53:23 +00:00
|
|
|
|
// Only allow on code lines. This is somewhat arbitrary; data would work fine.
|
2019-10-02 02:13:15 +00:00
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
2019-09-19 22:53:23 +00:00
|
|
|
|
if (CodeLineList[selIndex].LineType != LineListGen.Line.Type.Code) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
// Don't allow creation if a table already exists.
|
|
|
|
|
return !mProject.LvTables.ContainsKey(offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CreateLocalVariableTable() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
Debug.Assert(!mProject.LvTables.ContainsKey(offset));
|
|
|
|
|
CreateOrEditLocalVariableTable(offset);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-25 21:14:44 +00:00
|
|
|
|
public bool CanEditLocalVariableTable() {
|
2019-08-26 23:58:53 +00:00
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-09-19 22:53:23 +00:00
|
|
|
|
// Check to see if the offset of the first-defined table is less than or equal to
|
|
|
|
|
// the offset of the selected line. If so, we know there's a table, though we
|
|
|
|
|
// don't know which one.
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
return mProject.LvTables.Count > 0 && mProject.LvTables.Keys[0] <= offset;
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditLocalVariableTable() {
|
2019-08-26 23:58:53 +00:00
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
2019-10-28 23:54:01 +00:00
|
|
|
|
|
Label rework, part 6
Correct handling of local variables. We now correctly uniquify them
with regard to non-unique labels. Because local vars can effectively
have global scope we mostly want to treat them as global, but they're
uniquified relative to other globals very late in the process, so we
can't just throw them in the symbol table and be done. Fortunately
local variables exist in a separate namespace, so we just need to
uniquify the variables relative to the post-localization symbol table.
In other words, we take the symbol table, apply the label map, and
rename any variable that clashes.
This also fixes an older problem where we weren't masking the
leading '_' on variable labels when generating 64tass output.
The code list now makes non-unique labels obvious, but you can't tell
the difference between unique global and unique local. What's more,
the default type value in Edit Label is now adjusted to Global for
unique locals that were auto-generated. To make it a bit easier to
figure out what's what, the Info panel now has a "label type" line
that reports the type.
The 2023-non-unique-labels test had some additional tests added to
exercise conflicts with local variables. The 2019-local-variables
test output changed slightly because the de-duplicated variable
naming convention was simplified.
2019-11-18 21:26:03 +00:00
|
|
|
|
LocalVariableLookup lvLookup = new LocalVariableLookup(mProject.LvTables, mProject,
|
|
|
|
|
null, false, false);
|
2019-10-28 23:54:01 +00:00
|
|
|
|
int bestOffset = lvLookup.GetNearestTableOffset(offset);
|
2019-09-19 22:53:23 +00:00
|
|
|
|
Debug.Assert(bestOffset >= 0);
|
|
|
|
|
CreateOrEditLocalVariableTable(bestOffset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateOrEditLocalVariableTable(int offset) {
|
2019-09-01 23:40:54 +00:00
|
|
|
|
// Get existing table, if any.
|
2019-08-26 23:58:53 +00:00
|
|
|
|
mProject.LvTables.TryGetValue(offset, out LocalVariableTable oldLvt);
|
|
|
|
|
|
2019-09-01 23:40:54 +00:00
|
|
|
|
EditLocalVariableTable dlg = new EditLocalVariableTable(mMainWin, mProject,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatter, oldLvt, offset);
|
2019-08-25 21:14:44 +00:00
|
|
|
|
if (dlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-09-01 23:40:54 +00:00
|
|
|
|
if (offset != dlg.NewOffset) {
|
|
|
|
|
// Table moved. We create two changes, one to delete the current table, one
|
|
|
|
|
// to create a new table.
|
|
|
|
|
Debug.Assert(!mProject.LvTables.TryGetValue(dlg.NewOffset,
|
|
|
|
|
out LocalVariableTable unused));
|
|
|
|
|
|
|
|
|
|
UndoableChange rem = UndoableChange.CreateLocalVariableTableChange(offset,
|
|
|
|
|
oldLvt, null);
|
|
|
|
|
UndoableChange add = UndoableChange.CreateLocalVariableTableChange(dlg.NewOffset,
|
|
|
|
|
null, dlg.NewTable);
|
|
|
|
|
ChangeSet cs = new ChangeSet(2);
|
|
|
|
|
cs.Add(rem);
|
|
|
|
|
cs.Add(add);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
} else if (oldLvt != dlg.NewTable) {
|
|
|
|
|
// New table, edited in place, or deleted.
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateLocalVariableTableChange(offset,
|
|
|
|
|
oldLvt, dlg.NewTable);
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
} else {
|
2019-08-26 23:58:53 +00:00
|
|
|
|
Debug.WriteLine("LvTable unchanged");
|
|
|
|
|
}
|
2019-08-25 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-07 23:18:46 +00:00
|
|
|
|
public bool CanEditLongComment() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
EntityCounts counts = SelectionAnalysis.mEntityCounts;
|
|
|
|
|
// Single line, code or data, or a long comment.
|
|
|
|
|
return (counts.mDataLines > 0 || counts.mCodeLines > 0 ||
|
|
|
|
|
SelectionAnalysis.mLineType == LineListGen.Line.Type.LongComment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditLongComment() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
EditLongComment(offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EditLongComment(int offset) {
|
2019-12-30 01:59:35 +00:00
|
|
|
|
EditLongComment dlg = new EditLongComment(mMainWin, mFormatter);
|
2019-07-07 23:18:46 +00:00
|
|
|
|
if (mProject.LongComments.TryGetValue(offset, out MultiLineComment oldComment)) {
|
|
|
|
|
dlg.LongComment = oldComment;
|
|
|
|
|
}
|
2019-08-26 23:58:53 +00:00
|
|
|
|
if (dlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-07-07 23:18:46 +00:00
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
MultiLineComment newComment = dlg.LongComment;
|
|
|
|
|
if (oldComment != newComment) {
|
|
|
|
|
Debug.WriteLine("Changing long comment at +" + offset.ToString("x6"));
|
2019-07-07 23:18:46 +00:00
|
|
|
|
|
2019-08-26 23:58:53 +00:00
|
|
|
|
UndoableChange uc = UndoableChange.CreateLongCommentChange(offset,
|
|
|
|
|
oldComment, newComment);
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
2019-07-07 23:18:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 00:04:47 +00:00
|
|
|
|
public bool CanEditNote() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
EntityCounts counts = SelectionAnalysis.mEntityCounts;
|
|
|
|
|
// Single line, code or data, or a note.
|
|
|
|
|
return (counts.mDataLines > 0 || counts.mCodeLines > 0 ||
|
|
|
|
|
SelectionAnalysis.mLineType == LineListGen.Line.Type.Note);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditNote() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
|
|
|
|
|
MultiLineComment oldNote;
|
|
|
|
|
if (!mProject.Notes.TryGetValue(offset, out oldNote)) {
|
Improve save & restore of top line
Whenever the display list gets regenerated, we need to restore the
code list view scroll position to the previous location in the file.
This gets tricky when multiple lines are appearing or disappearing.
We were saving the file offset of the line, but that works poorly
when there's a multi-line comment associated with that offset,
because we end up scrolling to the top of the comment whenever any
part of the comment is at the top of the screen.
We now track the file offset and the number of lines we were from
the top of that offset's content. This works well unless we remove
a lot of lines. If the adjusted line index would put us into a
different file offset, we punt and just scroll to the top of the item.
Also, fix a crasher in Edit Note.
Also, fix behavior when the list shrinks while a line near the end
of the file is selected.
Also, change a few instances of "Color.FromArgb(0,0,0,0)" to use a
common constant.
2019-07-17 20:47:43 +00:00
|
|
|
|
oldNote = null;
|
2019-07-14 00:04:47 +00:00
|
|
|
|
}
|
|
|
|
|
EditNote dlg = new EditNote(mMainWin, oldNote);
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (dlg.DialogResult != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MultiLineComment newNote = dlg.Note;
|
|
|
|
|
if (oldNote != newNote) {
|
|
|
|
|
Debug.WriteLine("Changing note at +" + offset.ToString("x6"));
|
|
|
|
|
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateNoteChange(offset,
|
|
|
|
|
oldNote, newNote);
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-08 22:40:30 +00:00
|
|
|
|
public bool CanEditOperand() {
|
2019-07-09 00:02:25 +00:00
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected == 0) {
|
2019-07-08 22:40:30 +00:00
|
|
|
|
return false;
|
2019-07-09 00:02:25 +00:00
|
|
|
|
} else if (SelectionAnalysis.mNumItemsSelected == 1) {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int selOffset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
|
|
|
|
|
bool editInstr = (CodeLineList[selIndex].LineType == LineListGen.Line.Type.Code &&
|
|
|
|
|
mProject.GetAnattrib(selOffset).IsInstructionWithOperand);
|
|
|
|
|
bool editData = (CodeLineList[selIndex].LineType == LineListGen.Line.Type.Data);
|
|
|
|
|
return editInstr || editData;
|
|
|
|
|
} else {
|
|
|
|
|
// Data operands are one of the few things we can edit in bulk. It's okay
|
|
|
|
|
// if meta-data like ORGs and Notes are selected, but we don't allow it if
|
|
|
|
|
// any code is selected.
|
|
|
|
|
EntityCounts counts = SelectionAnalysis.mEntityCounts;
|
|
|
|
|
return (counts.mDataLines > 0 && counts.mCodeLines == 0);
|
2019-07-08 22:40:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditOperand() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int selOffset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
if (CodeLineList[selIndex].LineType == LineListGen.Line.Type.Code) {
|
|
|
|
|
EditInstructionOperand(selOffset);
|
|
|
|
|
} else {
|
2019-08-29 00:34:29 +00:00
|
|
|
|
// We allow the selection to include meta-data like .org and Notes.
|
|
|
|
|
//Debug.Assert(CodeLineList[selIndex].LineType == LineListGen.Line.Type.Data);
|
2022-03-01 23:03:12 +00:00
|
|
|
|
EditDataOperand();
|
2019-07-08 22:40:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EditInstructionOperand(int offset) {
|
2019-09-07 20:39:22 +00:00
|
|
|
|
EditInstructionOperand dlg = new EditInstructionOperand(mMainWin, mProject,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
offset, mFormatter);
|
2019-09-07 20:39:22 +00:00
|
|
|
|
if (dlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-07-08 22:40:30 +00:00
|
|
|
|
|
2019-09-07 20:39:22 +00:00
|
|
|
|
ChangeSet cs = new ChangeSet(1);
|
|
|
|
|
mProject.OperandFormats.TryGetValue(offset, out FormatDescriptor dfd);
|
|
|
|
|
if (dlg.FormatDescriptorResult != dfd) {
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateOperandFormatChange(offset,
|
|
|
|
|
dfd, dlg.FormatDescriptorResult);
|
|
|
|
|
cs.Add(uc);
|
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
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("No change to operand format");
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 23:41:54 +00:00
|
|
|
|
// Check for changes to a local variable table. The edit dialog can't delete an
|
|
|
|
|
// entire table, so a null value here means no changes were made.
|
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
|
|
|
|
if (dlg.LocalVariableResult != null) {
|
|
|
|
|
int tableOffset = dlg.LocalVariableTableOffsetResult;
|
|
|
|
|
LocalVariableTable lvt = mProject.LvTables[tableOffset];
|
2019-09-08 23:41:54 +00:00
|
|
|
|
Debug.Assert(lvt != null); // cannot create a table either
|
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
|
|
|
|
UndoableChange uc = UndoableChange.CreateLocalVariableTableChange(tableOffset,
|
|
|
|
|
lvt, dlg.LocalVariableResult);
|
|
|
|
|
cs.Add(uc);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("No change to LvTable");
|
2019-09-07 20:39:22 +00:00
|
|
|
|
}
|
2019-09-08 23:41:54 +00:00
|
|
|
|
|
|
|
|
|
// Check for changes to label at operand target address. Labels can be created,
|
|
|
|
|
// modified, or deleted.
|
|
|
|
|
if (dlg.SymbolEditOffsetResult >= 0) {
|
|
|
|
|
mProject.UserLabels.TryGetValue(dlg.SymbolEditOffsetResult, out Symbol oldLabel);
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateLabelChange(dlg.SymbolEditOffsetResult,
|
|
|
|
|
oldLabel, dlg.SymbolEditResult);
|
|
|
|
|
cs.Add(uc);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("No change to label");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 23:03:12 +00:00
|
|
|
|
// Check for changes to a project symbol. The dialog can create a new entry or
|
|
|
|
|
// modify an existing entry, but can't delete an entry.
|
|
|
|
|
if (dlg.ProjectSymbolResult != null) {
|
|
|
|
|
DefSymbol oldSym = dlg.OrigProjectSymbolResult;
|
|
|
|
|
DefSymbol newSym = dlg.ProjectSymbolResult;
|
|
|
|
|
if (oldSym == newSym) {
|
|
|
|
|
Debug.WriteLine("No actual change to project symbol");
|
|
|
|
|
} else {
|
|
|
|
|
// Generate a completely new set of project properties.
|
|
|
|
|
ProjectProperties newProps = new ProjectProperties(mProject.ProjectProps);
|
|
|
|
|
// Add new symbol entry, or replace existing entry.
|
|
|
|
|
if (oldSym != null) {
|
|
|
|
|
newProps.ProjectSyms.Remove(oldSym.Label);
|
|
|
|
|
}
|
|
|
|
|
newProps.ProjectSyms.Add(newSym.Label, newSym);
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateProjectPropertiesChange(
|
|
|
|
|
mProject.ProjectProps, newProps);
|
|
|
|
|
cs.Add(uc);
|
2019-09-09 04:56:47 +00:00
|
|
|
|
}
|
2019-09-08 23:41:54 +00:00
|
|
|
|
} else {
|
2022-03-01 23:03:12 +00:00
|
|
|
|
Debug.WriteLine("No change to project symbol");
|
2019-09-08 23:41:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
Debug.WriteLine("EditInstructionOperand: " + cs.Count + " changes");
|
2019-07-08 22:40:30 +00:00
|
|
|
|
if (cs.Count != 0) {
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 23:03:12 +00:00
|
|
|
|
private void EditDataOperand() {
|
2019-07-09 00:02:25 +00:00
|
|
|
|
Debug.Assert(mMainWin.CodeListView_GetSelectionCount() > 0);
|
|
|
|
|
|
|
|
|
|
TypedRangeSet trs = GroupedOffsetSetFromSelected();
|
|
|
|
|
if (trs.Count == 0) {
|
|
|
|
|
Debug.Assert(false, "EditDataOperand found nothing to edit"); // shouldn't happen
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the first offset has a FormatDescriptor, pass that in as a recommendation
|
|
|
|
|
// for the default value in the dialog. This allows single-item editing to work
|
|
|
|
|
// as expected. If the format can't be applied to the full selection (which
|
|
|
|
|
// would disable that radio button), the dialog will have to pick something
|
|
|
|
|
// that does work.
|
|
|
|
|
//
|
|
|
|
|
// We could pull this out of Anattribs, which would let the dialog reflect the
|
|
|
|
|
// auto-format that the user was just looking at. However, I think it's better
|
|
|
|
|
// if the dialog shows what's actually there, i.e. no formatting at all.
|
|
|
|
|
IEnumerator<TypedRangeSet.Tuple> iter =
|
|
|
|
|
(IEnumerator<TypedRangeSet.Tuple>)trs.GetEnumerator();
|
|
|
|
|
iter.MoveNext();
|
|
|
|
|
TypedRangeSet.Tuple firstOffset = iter.Current;
|
|
|
|
|
mProject.OperandFormats.TryGetValue(firstOffset.Value, out FormatDescriptor dfd);
|
|
|
|
|
|
2019-10-19 03:28:02 +00:00
|
|
|
|
EditDataOperand dlg =
|
2019-12-30 01:59:35 +00:00
|
|
|
|
new EditDataOperand(mMainWin, mProject, mFormatter, trs, dfd);
|
2019-10-19 03:28:02 +00:00
|
|
|
|
if (dlg.ShowDialog() == true) {
|
2019-07-09 00:02:25 +00:00
|
|
|
|
// Merge the changes into the OperandFormats list. We need to remove all
|
|
|
|
|
// FormatDescriptors that overlap the selected region. We don't need to
|
|
|
|
|
// pass the selection set in, because the dlg.Results list spans the exact
|
|
|
|
|
// set of ranges.
|
|
|
|
|
//
|
|
|
|
|
// If nothing actually changed, don't generate an undo record.
|
|
|
|
|
ChangeSet cs = mProject.GenerateFormatMergeSet(dlg.Results);
|
|
|
|
|
if (cs.Count != 0) {
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("No change to data formats");
|
|
|
|
|
}
|
|
|
|
|
}
|
Binary includes
This adds a new data format option, "binary include", that takes a
filename operand. When assembly sources are generated, the section
of file is replaced with an appropriate pseudo-op, and binary files
are generated that hold the file contents. This is a convenient way
to remove large binary blobs, such as music or sound samples, that
aren't useful to have in text form in the sources.
Partial pathnames are allowed, so you can output a sound blob to
"sounds/blather.bin". For safety reasons, we don't allow the files
to be created above the project directory, and existing files will
only be overwritten if they have a matching length (so you don't
accidentally stomp on your project file).
The files are not currently shown in the GenAsm dialog, which lets
you see a preview of the generated sources. The hex dump tool
can do this for the (presumably rare) situations where it's useful.
A new regression test, 20300-binary-include, has been added. The
pseudo-op name can be overridden on-screen in the settings.
We don't currently do anything new for text/HTML exports. It might
be useful to generate an optional appendix with a hex dump of the
excised sections.
(issue #144)
2024-05-31 21:09:39 +00:00
|
|
|
|
|
2019-07-08 22:40:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-13 19:29:37 +00:00
|
|
|
|
public void EditProjectProperties(WpfGui.EditProjectProperties.Tab initialTab) {
|
2019-11-23 04:45:57 +00:00
|
|
|
|
string projectDir = string.Empty;
|
|
|
|
|
if (!string.IsNullOrEmpty(mProjectPathName)) {
|
|
|
|
|
projectDir = Path.GetDirectoryName(mProjectPathName);
|
|
|
|
|
}
|
2020-07-04 00:37:04 +00:00
|
|
|
|
EditProjectProperties dlg = new EditProjectProperties(mMainWin, mProject,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
projectDir, mFormatter, initialTab);
|
2019-11-23 04:45:57 +00:00
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
ProjectProperties newProps = dlg.NewProps;
|
|
|
|
|
|
|
|
|
|
// The dialog result doesn't matter, because the user might have hit "apply"
|
|
|
|
|
// before hitting "cancel".
|
|
|
|
|
if (newProps != null) {
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateProjectPropertiesChange(
|
|
|
|
|
mProject.ProjectProps, newProps);
|
|
|
|
|
ApplyUndoableChanges(new ChangeSet(uc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 20:18:10 +00:00
|
|
|
|
public bool CanEditProjectSymbol() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (SelectionAnalysis.mLineType != LineListGen.Line.Type.EquDirective) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int symIndex = LineListGen.DefSymIndexFromOffset(CodeLineList[selIndex].FileOffset);
|
|
|
|
|
DefSymbol defSym = mProject.ActiveDefSymbolList[symIndex];
|
|
|
|
|
return (defSym.SymbolSource == Symbol.Source.Project);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:42:54 +00:00
|
|
|
|
public void EditProjectSymbol(CodeListColumn col) {
|
2019-07-14 20:18:10 +00:00
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int symIndex = LineListGen.DefSymIndexFromOffset(CodeLineList[selIndex].FileOffset);
|
|
|
|
|
DefSymbol origDefSym = mProject.ActiveDefSymbolList[symIndex];
|
|
|
|
|
Debug.Assert(origDefSym.SymbolSource == Symbol.Source.Project);
|
|
|
|
|
|
2019-12-30 01:59:35 +00:00
|
|
|
|
EditDefSymbol dlg = new EditDefSymbol(mMainWin, mFormatter,
|
2022-03-01 23:03:12 +00:00
|
|
|
|
mProject.ProjectProps.ProjectSyms, origDefSym, origDefSym, null);
|
2020-04-23 17:42:54 +00:00
|
|
|
|
|
|
|
|
|
switch (col) {
|
|
|
|
|
case CodeListColumn.Operand:
|
|
|
|
|
dlg.InitialFocusField = EditDefSymbol.InputField.Value;
|
|
|
|
|
break;
|
|
|
|
|
case CodeListColumn.Comment:
|
|
|
|
|
dlg.InitialFocusField = EditDefSymbol.InputField.Comment;
|
|
|
|
|
break;
|
|
|
|
|
case CodeListColumn.Label:
|
|
|
|
|
default:
|
|
|
|
|
dlg.InitialFocusField = EditDefSymbol.InputField.Label;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 20:18:10 +00:00
|
|
|
|
if (dlg.ShowDialog() == true) {
|
|
|
|
|
ProjectProperties newProps = new ProjectProperties(mProject.ProjectProps);
|
|
|
|
|
newProps.ProjectSyms.Remove(origDefSym.Label);
|
2019-08-26 00:25:15 +00:00
|
|
|
|
newProps.ProjectSyms[dlg.NewSym.Label] = dlg.NewSym;
|
2019-07-14 20:18:10 +00:00
|
|
|
|
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateProjectPropertiesChange(
|
|
|
|
|
mProject.ProjectProps, newProps);
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-21 22:06:04 +00:00
|
|
|
|
public bool CanEditStatusFlags() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-07-07 23:18:46 +00:00
|
|
|
|
// Single line, must be code or a RegWidth directive.
|
2019-06-21 22:06:04 +00:00
|
|
|
|
return (SelectionAnalysis.mLineType == LineListGen.Line.Type.Code ||
|
|
|
|
|
SelectionAnalysis.mLineType == LineListGen.Line.Type.RegWidthDirective);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditStatusFlags() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
|
|
|
|
|
EditStatusFlags dlg = new EditStatusFlags(mMainWin,
|
|
|
|
|
mProject.StatusFlagOverrides[offset], mProject.CpuDef.HasEmuFlag);
|
|
|
|
|
if (dlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dlg.FlagValue != mProject.StatusFlagOverrides[offset]) {
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateStatusFlagChange(offset,
|
|
|
|
|
mProject.StatusFlagOverrides[offset], dlg.FlagValue);
|
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
2019-07-01 21:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 04:45:57 +00:00
|
|
|
|
public bool CanEditVisualizationSet() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
2019-07-01 21:07:30 +00:00
|
|
|
|
}
|
2021-11-13 23:45:49 +00:00
|
|
|
|
// Single line, must be a visualization set or a place where one can be created.
|
2019-11-23 04:45:57 +00:00
|
|
|
|
LineListGen.Line.Type lineType = SelectionAnalysis.mLineType;
|
|
|
|
|
return (lineType == LineListGen.Line.Type.VisualizationSet ||
|
|
|
|
|
lineType == LineListGen.Line.Type.Code ||
|
|
|
|
|
lineType == LineListGen.Line.Type.Data);
|
|
|
|
|
}
|
2019-07-01 21:07:30 +00:00
|
|
|
|
|
2019-11-23 04:45:57 +00:00
|
|
|
|
public void EditVisualizationSet() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int offset = CodeLineList[selIndex].FileOffset;
|
|
|
|
|
mProject.VisualizationSets.TryGetValue(offset, out VisualizationSet curVisSet);
|
|
|
|
|
|
2019-11-25 22:27:38 +00:00
|
|
|
|
EditVisualizationSet dlg = new EditVisualizationSet(mMainWin, mProject,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatter, curVisSet, offset);
|
2019-11-23 04:45:57 +00:00
|
|
|
|
if (dlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-18 00:40:27 +00:00
|
|
|
|
VisualizationSet newSet = dlg.NewVisSet;
|
|
|
|
|
if (newSet.Count == 0) {
|
|
|
|
|
// empty sets are deleted
|
|
|
|
|
newSet = null;
|
|
|
|
|
}
|
|
|
|
|
if (curVisSet != newSet) {
|
2019-12-22 02:04:44 +00:00
|
|
|
|
ChangeSet cs = new ChangeSet(1);
|
|
|
|
|
|
2019-11-23 04:45:57 +00:00
|
|
|
|
// New table, edited in place, or deleted.
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateVisualizationSetChange(offset,
|
2019-12-18 00:40:27 +00:00
|
|
|
|
curVisSet, newSet);
|
|
|
|
|
//Debug.WriteLine("Change " + curVisSet + " to " + newSet);
|
2019-12-22 02:04:44 +00:00
|
|
|
|
cs.Add(uc);
|
|
|
|
|
|
|
|
|
|
// And now the messy bit. If Visualizations were removed, we need to purge
|
|
|
|
|
// them from any animations that reference them. The edit dialog took care
|
|
|
|
|
// of this for animations in the same set, but we need to check other sets.
|
|
|
|
|
foreach (KeyValuePair<int, VisualizationSet> kvp in mProject.VisualizationSets) {
|
|
|
|
|
if (kvp.Value == curVisSet) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VisualizationSet stripSet;
|
|
|
|
|
if (VisualizationSet.StripEntriesFromAnimations(kvp.Value, dlg.RemovedSerials,
|
|
|
|
|
out stripSet)) {
|
|
|
|
|
if (stripSet.Count == 0) {
|
|
|
|
|
stripSet = null;
|
|
|
|
|
}
|
|
|
|
|
uc = UndoableChange.CreateVisualizationSetChange(kvp.Key,
|
|
|
|
|
kvp.Value, stripSet);
|
|
|
|
|
cs.Add(uc);
|
|
|
|
|
Debug.WriteLine("Also updating visSet at +" + kvp.Key.ToString("x6"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 04:45:57 +00:00
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("No change to VisualizationSet");
|
2019-07-01 21:07:30 +00:00
|
|
|
|
}
|
2019-06-21 22:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-11 00:43:31 +00:00
|
|
|
|
public void Export() {
|
2019-09-12 20:57:52 +00:00
|
|
|
|
string outName;
|
|
|
|
|
if (string.IsNullOrEmpty(mProjectPathName)) {
|
|
|
|
|
outName = Path.GetFileName(mDataPathName);
|
|
|
|
|
} else {
|
|
|
|
|
outName = Path.GetFileName(mProjectPathName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Export dlg = new Export(mMainWin, outName);
|
2019-09-11 00:43:31 +00:00
|
|
|
|
if (dlg.ShowDialog() == false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 20:57:52 +00:00
|
|
|
|
int[] rightWidths = new int[] {
|
|
|
|
|
dlg.AsmLabelColWidth, dlg.AsmOpcodeColWidth,
|
|
|
|
|
dlg.AsmOperandColWidth, dlg.AsmCommentColWidth
|
|
|
|
|
};
|
2019-12-30 01:59:35 +00:00
|
|
|
|
Exporter eport = new Exporter(mProject, CodeLineList, mFormatter,
|
2019-09-12 20:57:52 +00:00
|
|
|
|
dlg.ColFlags, rightWidths);
|
|
|
|
|
eport.IncludeNotes = dlg.IncludeNotes;
|
2019-12-14 00:52:50 +00:00
|
|
|
|
eport.GenerateImageFiles = dlg.GenerateImageFiles;
|
2019-09-18 18:05:52 +00:00
|
|
|
|
eport.LongLabelNewLine = dlg.LongLabelNewLine;
|
2019-09-12 20:57:52 +00:00
|
|
|
|
if (dlg.SelectionOnly) {
|
|
|
|
|
DisplayListSelection selection = mMainWin.CodeDisplayList.SelectedIndices;
|
|
|
|
|
if (selection.Count == 0) {
|
|
|
|
|
// no selection == select all
|
|
|
|
|
selection = null;
|
|
|
|
|
}
|
|
|
|
|
eport.Selection = selection;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-15 18:49:11 +00:00
|
|
|
|
if (dlg.GenType == WpfGui.Export.GenerateFileType.Html) {
|
|
|
|
|
// Generating wireframe animations can be slow, so we need to use a
|
|
|
|
|
// progress dialog.
|
|
|
|
|
eport.OutputToHtml(mMainWin, dlg.PathName, dlg.OverwriteCss);
|
|
|
|
|
} else {
|
|
|
|
|
// Text output is generally very fast. Put up a wait cursor just in case.
|
|
|
|
|
try {
|
|
|
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
2019-09-12 20:57:52 +00:00
|
|
|
|
eport.OutputToText(dlg.PathName, dlg.TextModeCsv);
|
2020-03-15 18:49:11 +00:00
|
|
|
|
} finally {
|
|
|
|
|
Mouse.OverrideCursor = null;
|
2019-09-12 20:57:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-11 00:43:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-20 22:36:15 +00:00
|
|
|
|
public void GenerateLabels() {
|
|
|
|
|
GenerateLabels dlg = new GenerateLabels(mMainWin);
|
|
|
|
|
if (dlg.ShowDialog() == false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string ext;
|
|
|
|
|
string filter;
|
|
|
|
|
switch (dlg.Format) {
|
|
|
|
|
case LabelFileGenerator.LabelFmt.VICE:
|
2024-04-22 22:07:54 +00:00
|
|
|
|
ext = ".lbl";
|
|
|
|
|
filter = "VICE labels (*.lbl)|*.lbl";
|
2024-04-20 22:36:15 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Debug.Assert(false, "bad format");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SaveFileDialog fileDlg = new SaveFileDialog() {
|
|
|
|
|
Filter = filter,
|
|
|
|
|
FilterIndex = 1,
|
|
|
|
|
ValidateNames = true,
|
|
|
|
|
AddExtension = true, // doesn't add extension if non-ext file exists
|
|
|
|
|
FileName = "labels" + ext
|
|
|
|
|
};
|
|
|
|
|
if (fileDlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string pathName = Path.GetFullPath(fileDlg.FileName);
|
|
|
|
|
try {
|
|
|
|
|
using (StreamWriter writer = new StreamWriter(pathName, false)) {
|
|
|
|
|
LabelFileGenerator gen = new LabelFileGenerator(mProject,
|
|
|
|
|
dlg.Format, dlg.IncludeAutoLabels);
|
|
|
|
|
gen.Generate(writer);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
MessageBox.Show("Error: " + ex.Message, "Failed", MessageBoxButton.OK,
|
|
|
|
|
MessageBoxImage.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-07 20:28:45 +00:00
|
|
|
|
public void Find() {
|
|
|
|
|
FindBox dlg = new FindBox(mMainWin, mFindString);
|
|
|
|
|
if (dlg.ShowDialog() == true) {
|
|
|
|
|
mFindString = dlg.TextToFind;
|
|
|
|
|
mFindStartIndex = -1;
|
2020-07-30 21:32:15 +00:00
|
|
|
|
FindText(dlg.IsBackward, true);
|
2019-07-07 20:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FindNext() {
|
2020-07-30 21:32:15 +00:00
|
|
|
|
FindText(false, false);
|
2019-10-10 00:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FindPrevious() {
|
2020-07-30 21:32:15 +00:00
|
|
|
|
FindText(true, false);
|
2019-07-07 20:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 21:32:15 +00:00
|
|
|
|
private void FindText(bool goBackward, bool pushLocation) {
|
2019-07-07 20:28:45 +00:00
|
|
|
|
if (string.IsNullOrEmpty(mFindString)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-10-10 00:41:44 +00:00
|
|
|
|
int incr = goBackward ? -1 : 1;
|
|
|
|
|
|
|
|
|
|
// If we reversed direction, reset the "start index" so we don't tell the user
|
|
|
|
|
// we've wrapped around.
|
|
|
|
|
if (mFindBackward != goBackward) {
|
|
|
|
|
mFindStartIndex = -1;
|
|
|
|
|
mFindBackward = goBackward;
|
|
|
|
|
}
|
2019-07-07 20:28:45 +00:00
|
|
|
|
|
|
|
|
|
// Start from the topmost selected line, or the start of the file if nothing
|
|
|
|
|
// is selected.
|
2019-10-10 00:41:44 +00:00
|
|
|
|
// TODO(maybe): if multiple lines are selected, search only within the selected set.
|
2019-07-07 20:28:45 +00:00
|
|
|
|
int index = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
if (index < 0) {
|
|
|
|
|
index = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start one past the selected item.
|
2019-10-10 00:41:44 +00:00
|
|
|
|
index += incr;
|
2019-07-07 20:28:45 +00:00
|
|
|
|
if (index == CodeLineList.Count) {
|
|
|
|
|
index = 0;
|
2019-10-10 00:41:44 +00:00
|
|
|
|
} else if (index == -1) {
|
|
|
|
|
index = CodeLineList.Count - 1;
|
2019-07-07 20:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
//Debug.WriteLine("FindText index=" + index + " start=" + mFindStartIndex +
|
|
|
|
|
// " str=" + mFindString);
|
|
|
|
|
while (index != mFindStartIndex) {
|
|
|
|
|
if (mFindStartIndex < 0) {
|
|
|
|
|
// need to latch this inside the loop so the initial test doesn't fail
|
|
|
|
|
mFindStartIndex = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string searchStr = CodeLineList.GetSearchString(index);
|
|
|
|
|
int matchPos = searchStr.IndexOf(mFindString,
|
|
|
|
|
StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
if (matchPos >= 0) {
|
|
|
|
|
//Debug.WriteLine("Match " + index + ": " + searchStr);
|
2020-07-30 21:32:15 +00:00
|
|
|
|
if (pushLocation) {
|
|
|
|
|
mNavStack.Push(GetCurrentlySelectedLocation());
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-07 20:28:45 +00:00
|
|
|
|
mMainWin.CodeListView_EnsureVisible(index);
|
|
|
|
|
mMainWin.CodeListView_SelectRange(index, 1);
|
2021-08-09 00:39:21 +00:00
|
|
|
|
mMainWin.CodeListView_SetSelectionFocus();
|
2019-07-07 20:28:45 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-10 00:41:44 +00:00
|
|
|
|
index += incr;
|
2019-07-07 20:28:45 +00:00
|
|
|
|
if (index == CodeLineList.Count) {
|
|
|
|
|
index = 0;
|
2019-10-10 00:41:44 +00:00
|
|
|
|
} else if (index == -1) {
|
|
|
|
|
index = CodeLineList.Count - 1;
|
2019-07-07 20:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Announce that we've wrapped around, then clear the start index.
|
|
|
|
|
MessageBox.Show(Res.Strings.FIND_REACHED_START,
|
|
|
|
|
Res.Strings.FIND_REACHED_START_CAPTION, MessageBoxButton.OK,
|
|
|
|
|
MessageBoxImage.Information);
|
|
|
|
|
mFindStartIndex = -1;
|
|
|
|
|
|
2021-08-09 00:39:21 +00:00
|
|
|
|
//mMainWin.CodeListView_Focus();
|
2019-07-07 20:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 20:50:15 +00:00
|
|
|
|
public bool CanFormatAsWord() {
|
|
|
|
|
EntityCounts counts = SelectionAnalysis.mEntityCounts;
|
|
|
|
|
// This is insufficient -- we need to know how many bytes are selected, and
|
|
|
|
|
// whether they're already formatted as multi-byte items. Too expensive to
|
|
|
|
|
// deal with here, so we'll need to show failure dialogs instead (ugh).
|
|
|
|
|
return (counts.mDataLines > 0 && counts.mCodeLines == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FormatAsWord() {
|
|
|
|
|
TypedRangeSet trs = GroupedOffsetSetFromSelected();
|
|
|
|
|
if (trs.Count == 0) {
|
|
|
|
|
Debug.Assert(false, "nothing to edit"); // shouldn't happen
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the user has only selected a single byte, we want to add the following byte
|
|
|
|
|
// to the selection, then proceed as usual. We can't simply modify the ListView
|
|
|
|
|
// selection because the following item might be an auto-detected string or fill,
|
|
|
|
|
// and we'd be adding multiple bytes. We have to be careful when grabbing the byte
|
|
|
|
|
// in case there's a region-split at that point (e.g. user label or .ORG).
|
|
|
|
|
//
|
|
|
|
|
// We could expand this to allow multiple regions, each of which is a single byte,
|
|
|
|
|
// but we'd need to deal with the case where the user selects two adjacent bytes that
|
|
|
|
|
// cross a region boundary.
|
|
|
|
|
if (trs.RangeCount == 1) {
|
|
|
|
|
// Exactly one range entry. Check its size.
|
|
|
|
|
IEnumerator<TypedRangeSet.TypedRange> checkIter = trs.RangeListIterator;
|
|
|
|
|
checkIter.MoveNext();
|
|
|
|
|
TypedRangeSet.TypedRange rng = checkIter.Current;
|
|
|
|
|
if (rng.Low == rng.High && rng.Low < mProject.FileDataLength - 1) {
|
|
|
|
|
// Single byte selected. Check to see if it's okay to grab the next byte.
|
|
|
|
|
Anattrib thisAttr = mProject.GetAnattrib(rng.Low);
|
|
|
|
|
Debug.Assert(thisAttr.DataDescriptor.Length == 1);
|
|
|
|
|
|
|
|
|
|
int nextOffset = rng.Low + 1;
|
|
|
|
|
// This must match what GroupedOffsetSetFromSelected() does.
|
|
|
|
|
if (!mProject.UserLabels.ContainsKey(nextOffset) &&
|
2019-12-06 22:49:35 +00:00
|
|
|
|
!mProject.HasCommentNoteOrVis(nextOffset) &&
|
2021-09-17 00:02:19 +00:00
|
|
|
|
mProject.AddrMap.IsRangeUnbroken(nextOffset - 1, 2)) {
|
2019-07-14 20:50:15 +00:00
|
|
|
|
// Good to go.
|
|
|
|
|
Debug.WriteLine("Grabbing second byte from +" + nextOffset.ToString("x6"));
|
|
|
|
|
trs.Add(nextOffset, rng.Type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Confirm that every selected byte is a single-byte data item (either set by
|
|
|
|
|
// the user or as part of the uncategorized data scan).
|
|
|
|
|
foreach (TypedRangeSet.Tuple tup in trs) {
|
|
|
|
|
FormatDescriptor dfd = mProject.GetAnattrib(tup.Value).DataDescriptor;
|
|
|
|
|
if (dfd != null && dfd.Length != 1) {
|
|
|
|
|
Debug.WriteLine("Can't format as word: offset +" + tup.Value.ToString("x6") +
|
|
|
|
|
" has len=" + dfd.Length + " (must be 1)");
|
|
|
|
|
MessageBox.Show(Res.Strings.INVALID_FORMAT_WORD_SEL_NON1,
|
|
|
|
|
Res.Strings.INVALID_FORMAT_WORD_SEL_CAPTION,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Confirm that, in each region, an even number of bytes are selected.
|
|
|
|
|
IEnumerator<TypedRangeSet.TypedRange> rngIter = trs.RangeListIterator;
|
|
|
|
|
while (rngIter.MoveNext()) {
|
|
|
|
|
TypedRangeSet.TypedRange rng = rngIter.Current;
|
|
|
|
|
int rangeLen = rng.High - rng.Low + 1;
|
|
|
|
|
if ((rangeLen & 0x01) != 0) {
|
|
|
|
|
string msg = string.Format(Res.Strings.INVALID_FORMAT_WORD_SEL_UNEVEN_FMT,
|
|
|
|
|
trs.RangeCount);
|
|
|
|
|
MessageBox.Show(msg,
|
|
|
|
|
Res.Strings.INVALID_FORMAT_WORD_SEL_CAPTION,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Selection is good, generate changes.
|
|
|
|
|
SortedList<int, FormatDescriptor> newFmts = new SortedList<int, FormatDescriptor>();
|
|
|
|
|
rngIter.Reset();
|
|
|
|
|
FormatDescriptor newDfd = FormatDescriptor.Create(2, FormatDescriptor.Type.NumericLE,
|
|
|
|
|
FormatDescriptor.SubType.None);
|
|
|
|
|
while (rngIter.MoveNext()) {
|
|
|
|
|
TypedRangeSet.TypedRange rng = rngIter.Current;
|
|
|
|
|
for (int i = rng.Low; i <= rng.High; i += 2) {
|
|
|
|
|
newFmts.Add(i, newDfd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChangeSet cs = mProject.GenerateFormatMergeSet(newFmts);
|
|
|
|
|
if (cs.Count != 0) {
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-15 20:37:38 +00:00
|
|
|
|
public bool CanFormatAddressTable() {
|
2019-07-13 20:31:51 +00:00
|
|
|
|
EntityCounts counts = SelectionAnalysis.mEntityCounts;
|
2019-07-13 22:50:11 +00:00
|
|
|
|
// Must be at least one line of data, and no code. Note this is lines, not bytes,
|
|
|
|
|
// so we can't screen out single-byte lines without additional work.
|
2019-07-13 20:31:51 +00:00
|
|
|
|
return (counts.mDataLines > 0 && counts.mCodeLines == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-15 20:37:38 +00:00
|
|
|
|
public void FormatAddressTable() {
|
2019-07-13 20:31:51 +00:00
|
|
|
|
TypedRangeSet trs = GroupedOffsetSetFromSelected();
|
|
|
|
|
if (trs.Count == 0) {
|
|
|
|
|
// shouldn't happen
|
|
|
|
|
Debug.Assert(false, "FormatSplitAddressTable found nothing to edit");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-15 20:37:38 +00:00
|
|
|
|
FormatAddressTable dlg = new FormatAddressTable(mMainWin, mProject, trs,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatter);
|
2019-07-13 20:31:51 +00:00
|
|
|
|
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
if (dlg.DialogResult != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start with the format descriptors.
|
|
|
|
|
ChangeSet cs = mProject.GenerateFormatMergeSet(dlg.NewFormatDescriptors);
|
|
|
|
|
|
|
|
|
|
// Add in the user labels.
|
|
|
|
|
foreach (KeyValuePair<int, Symbol> kvp in dlg.NewUserLabels) {
|
|
|
|
|
Symbol oldUserValue = null;
|
|
|
|
|
if (mProject.UserLabels.ContainsKey(kvp.Key)) {
|
|
|
|
|
Debug.Assert(false, "should not be replacing label");
|
|
|
|
|
oldUserValue = mProject.UserLabels[kvp.Key];
|
|
|
|
|
}
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateLabelChange(kvp.Key,
|
|
|
|
|
oldUserValue, kvp.Value);
|
|
|
|
|
cs.Add(uc);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-15 21:03:32 +00:00
|
|
|
|
// Apply analyzer tags.
|
|
|
|
|
if (dlg.WantCodeStartPoints) {
|
2019-07-13 20:31:51 +00:00
|
|
|
|
TypedRangeSet newSet = new TypedRangeSet();
|
|
|
|
|
TypedRangeSet undoSet = new TypedRangeSet();
|
|
|
|
|
|
|
|
|
|
foreach (int offset in dlg.AllTargetOffsets) {
|
2021-08-02 01:15:44 +00:00
|
|
|
|
// We don't need to add a "code start" tag if this is already the
|
|
|
|
|
// start of an instruction. We do need to add one if it's the *middle*
|
|
|
|
|
// of an instruction, e.g. the table points inside a "BIT abs". So we
|
|
|
|
|
// test against IsInstructionStart, not IsInstruction.
|
|
|
|
|
if (!mProject.GetAnattrib(offset).IsInstructionStart) {
|
2020-10-15 21:03:32 +00:00
|
|
|
|
CodeAnalysis.AnalyzerTag oldType = mProject.AnalyzerTags[offset];
|
|
|
|
|
if (oldType == CodeAnalysis.AnalyzerTag.Code) {
|
2019-07-13 20:31:51 +00:00
|
|
|
|
continue; // already set
|
|
|
|
|
}
|
|
|
|
|
undoSet.Add(offset, (int)oldType);
|
2020-10-15 21:03:32 +00:00
|
|
|
|
newSet.Add(offset, (int)CodeAnalysis.AnalyzerTag.Code);
|
2019-07-13 20:31:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (newSet.Count != 0) {
|
2020-10-15 21:03:32 +00:00
|
|
|
|
cs.Add(UndoableChange.CreateAnalyzerTagChange(undoSet, newSet));
|
2019-07-13 20:31:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally, apply the change.
|
|
|
|
|
if (cs.Count != 0) {
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("No changes found");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 18:16:50 +00:00
|
|
|
|
public bool CanRemoveFormatting() {
|
|
|
|
|
// Want at least one line of code or data. No need to check for existing formatting.
|
|
|
|
|
EntityCounts counts = SelectionAnalysis.mEntityCounts;
|
|
|
|
|
return (counts.mDataLines > 0 || counts.mCodeLines > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveFormatting() {
|
|
|
|
|
RangeSet sel = OffsetSetFromSelected();
|
|
|
|
|
ChangeSet cs = new ChangeSet(16);
|
|
|
|
|
foreach (int offset in sel) {
|
|
|
|
|
if (offset < 0) {
|
|
|
|
|
// header comment
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Formatted?
|
|
|
|
|
if (mProject.OperandFormats.TryGetValue(offset, out FormatDescriptor oldFd)) {
|
|
|
|
|
Debug.WriteLine("Remove format from +" + offset.ToString("x6"));
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateOperandFormatChange(offset,
|
|
|
|
|
oldFd, null);
|
|
|
|
|
cs.Add(uc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// As an added bonus, check for mid-line labels. The tricky part with this is
|
|
|
|
|
// that the determination of visibility is made before the effects of removing
|
|
|
|
|
// the formatting are known. In general we try very hard to avoid embedding
|
|
|
|
|
// labels, so this is unlikely to be a problem.
|
|
|
|
|
Anattrib attr = mProject.GetAnattrib(offset);
|
|
|
|
|
if (attr.Symbol != null && !attr.IsStart) {
|
|
|
|
|
Debug.WriteLine("Remove label from +" + offset.ToString("x6"));
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateLabelChange(offset, attr.Symbol, null);
|
|
|
|
|
cs.Add(uc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cs.Count != 0) {
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("No formatting or embedded labels found");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-19 23:55:36 +00:00
|
|
|
|
public void ReloadExternalFiles() {
|
|
|
|
|
string messages = mProject.LoadExternalFiles();
|
|
|
|
|
if (messages.Length != 0) {
|
|
|
|
|
// ProjectLoadIssues isn't quite the right dialog, but it'll do. This is
|
|
|
|
|
// purely informative; no decision needs to be made.
|
|
|
|
|
ProjectLoadIssues dlg = new ProjectLoadIssues(mMainWin, messages,
|
|
|
|
|
ProjectLoadIssues.Buttons.Continue);
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We only really need to do this if the set of extension scripts has changed.
|
|
|
|
|
// For an explicit reload we might as well just do it all the time.
|
|
|
|
|
mProject.ClearVisualizationCache();
|
|
|
|
|
|
|
|
|
|
// Update the project.
|
|
|
|
|
UndoableChange uc =
|
|
|
|
|
UndoableChange.CreateDummyChange(UndoableChange.ReanalysisScope.CodeAndData);
|
|
|
|
|
ApplyChanges(new ChangeSet(uc), false);
|
2020-07-22 17:53:54 +00:00
|
|
|
|
|
|
|
|
|
// TODO(someday): this would really be better as a special-case dummy change
|
|
|
|
|
// that caused the "external files have changed" behavior in ApplyChanges() to fire.
|
|
|
|
|
// Before we can do that, though, we need a way to propagate the load errors and
|
|
|
|
|
// compiler warnings out for display.
|
2020-07-19 23:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-07 21:28:35 +00:00
|
|
|
|
public void Goto() {
|
2019-11-17 00:34:42 +00:00
|
|
|
|
int index = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
if (index < 0) {
|
|
|
|
|
index = mMainWin.CodeListView_GetTopIndex(); // nothing selected
|
|
|
|
|
}
|
|
|
|
|
int offset = CodeLineList[index].FileOffset;
|
|
|
|
|
|
2019-12-30 01:59:35 +00:00
|
|
|
|
GotoBox dlg = new GotoBox(mMainWin, mProject, offset, mFormatter);
|
2019-07-07 21:28:35 +00:00
|
|
|
|
if (dlg.ShowDialog() == true) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(new NavStack.Location(dlg.TargetOffset, 0,
|
|
|
|
|
NavStack.GoToMode.JumpToCodeData), true);
|
2021-08-09 00:39:21 +00:00
|
|
|
|
//mMainWin.CodeListView_Focus();
|
2019-07-07 21:28:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moves the view and selection to the specified offset. We want to select stuff
|
|
|
|
|
/// differently if we're jumping to a note vs. jumping to an instruction.
|
|
|
|
|
/// </summary>
|
2021-10-07 19:39:08 +00:00
|
|
|
|
/// <param name="newLoc">Location to jump to.</param>
|
|
|
|
|
/// <param name="mode">Interesting set of lines within that offset.</param>
|
2019-06-15 23:00:31 +00:00
|
|
|
|
/// <param name="doPush">If set, push new offset onto navigation stack.</param>
|
2021-10-07 19:39:08 +00:00
|
|
|
|
public void GoToLocation(NavStack.Location newLoc, bool doPush) {
|
2019-06-22 18:27:21 +00:00
|
|
|
|
NavStack.Location prevLoc = GetCurrentlySelectedLocation();
|
2019-10-10 20:49:21 +00:00
|
|
|
|
//Debug.WriteLine("GoToLocation: " + loc + " mode=" + mode + " doPush=" + doPush +
|
|
|
|
|
// " (curLoc=" + prevLoc + ")");
|
2019-10-10 18:57:36 +00:00
|
|
|
|
|
|
|
|
|
// Avoid pushing multiple copies of the same address on. This doesn't quite work
|
|
|
|
|
// because we can't compare the LineDelta without figuring out JumpToCodeData first.
|
|
|
|
|
// If we're sitting in a long comment or LvTable and the user double-clicks on the
|
|
|
|
|
// entry in the symbol table for the current offset, we want to move the selection,
|
|
|
|
|
// so we don't want to bail out if the offset matches. Easiest thing to do is to
|
|
|
|
|
// do the move but not push it.
|
2021-10-07 19:39:08 +00:00
|
|
|
|
if (newLoc.Offset == prevLoc.Offset && newLoc.Mode == prevLoc.Mode) {
|
2019-06-22 18:27:21 +00:00
|
|
|
|
// we're jumping to ourselves?
|
2019-10-10 18:57:36 +00:00
|
|
|
|
if (doPush) {
|
|
|
|
|
Debug.WriteLine("Ignoring push for goto to current offset");
|
|
|
|
|
doPush = false;
|
|
|
|
|
}
|
2019-06-22 18:27:21 +00:00
|
|
|
|
}
|
2019-06-15 23:00:31 +00:00
|
|
|
|
|
2021-10-07 19:39:08 +00:00
|
|
|
|
int topLineIndex = CodeLineList.FindLineIndexByOffset(newLoc.Offset);
|
2019-06-15 23:00:31 +00:00
|
|
|
|
if (topLineIndex < 0) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
Debug.Assert(false, "failed goto offset +" + newLoc.Offset.ToString("x6"));
|
2019-06-15 23:00:31 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int lastLineIndex;
|
2021-10-07 19:39:08 +00:00
|
|
|
|
if (newLoc.Mode == NavStack.GoToMode.JumpToNote) {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
// Select all note lines, disregard the rest.
|
2019-06-16 23:34:47 +00:00
|
|
|
|
while (CodeLineList[topLineIndex].LineType != LineListGen.Line.Type.Note) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
if (CodeLineList[topLineIndex].FileOffset != newLoc.Offset) {
|
|
|
|
|
// This can happen if the note got deleted.
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-15 23:00:31 +00:00
|
|
|
|
topLineIndex++;
|
|
|
|
|
}
|
|
|
|
|
lastLineIndex = topLineIndex + 1;
|
2019-06-16 23:34:47 +00:00
|
|
|
|
while (lastLineIndex < CodeLineList.Count &&
|
|
|
|
|
CodeLineList[lastLineIndex].LineType == LineListGen.Line.Type.Note) {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
lastLineIndex++;
|
|
|
|
|
}
|
2021-10-07 19:39:08 +00:00
|
|
|
|
} else if (newLoc.Offset < 0) {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
// This is the offset of the header comment or a .EQ directive. Don't mess with it.
|
|
|
|
|
lastLineIndex = topLineIndex + 1;
|
2021-10-07 19:39:08 +00:00
|
|
|
|
} else if (newLoc.Mode == NavStack.GoToMode.JumpToCodeData) {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
// Advance to the code or data line.
|
2019-06-16 23:34:47 +00:00
|
|
|
|
while (CodeLineList[topLineIndex].LineType != LineListGen.Line.Type.Code &&
|
|
|
|
|
CodeLineList[topLineIndex].LineType != LineListGen.Line.Type.Data) {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
topLineIndex++;
|
|
|
|
|
}
|
2019-10-10 18:57:36 +00:00
|
|
|
|
|
|
|
|
|
lastLineIndex = topLineIndex + 1;
|
2021-10-07 19:39:08 +00:00
|
|
|
|
} else if (newLoc.Mode == NavStack.GoToMode.JumpToAdjIndex) {
|
2019-10-10 18:57:36 +00:00
|
|
|
|
// Adjust the line position by the line delta. If the adjustment moves us to
|
|
|
|
|
// a different element, ignore the adjustment.
|
|
|
|
|
if (CodeLineList[topLineIndex].FileOffset ==
|
2021-10-07 19:39:08 +00:00
|
|
|
|
CodeLineList[topLineIndex + newLoc.LineDelta].FileOffset) {
|
|
|
|
|
topLineIndex += newLoc.LineDelta;
|
|
|
|
|
}
|
|
|
|
|
lastLineIndex = topLineIndex + 1;
|
|
|
|
|
} else if (newLoc.Mode == NavStack.GoToMode.JumpToArStart ||
|
|
|
|
|
newLoc.Mode == NavStack.GoToMode.JumpToArEnd) {
|
|
|
|
|
LineListGen.Line.Type matchType = LineListGen.Line.Type.ArStartDirective;
|
|
|
|
|
if (newLoc.Mode != NavStack.GoToMode.JumpToArStart) {
|
|
|
|
|
matchType = LineListGen.Line.Type.ArEndDirective;
|
|
|
|
|
}
|
|
|
|
|
// Find first instance of specified type.
|
|
|
|
|
while (CodeLineList[topLineIndex].LineType != matchType) {
|
|
|
|
|
if (CodeLineList[topLineIndex].FileOffset > newLoc.Offset) {
|
|
|
|
|
// This can happen if the region got deleted.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
topLineIndex++;
|
2019-10-10 18:57:36 +00:00
|
|
|
|
}
|
|
|
|
|
lastLineIndex = topLineIndex + 1;
|
2021-10-07 19:39:08 +00:00
|
|
|
|
// If there's multiple lines, make sure they're all on screen.
|
|
|
|
|
while (lastLineIndex < CodeLineList.Count &&
|
|
|
|
|
CodeLineList[lastLineIndex].LineType == matchType) {
|
|
|
|
|
lastLineIndex++;
|
|
|
|
|
}
|
2019-10-10 18:57:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
Debug.Assert(false);
|
2019-06-15 23:00:31 +00:00
|
|
|
|
lastLineIndex = topLineIndex + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the item is visible. For notes, this can span multiple lines.
|
|
|
|
|
mMainWin.CodeListView_EnsureVisible(lastLineIndex - 1);
|
|
|
|
|
mMainWin.CodeListView_EnsureVisible(topLineIndex);
|
|
|
|
|
|
|
|
|
|
// Update the selection.
|
|
|
|
|
mMainWin.CodeListView_SelectRange(topLineIndex, lastLineIndex - topLineIndex);
|
|
|
|
|
|
2020-06-07 23:28:29 +00:00
|
|
|
|
// Set the focus to the first selected item. The focus is used by the keyboard
|
|
|
|
|
// handler to decide what the up/down arrows select next.
|
|
|
|
|
mMainWin.CodeListView_SetSelectionFocus();
|
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
if (doPush) {
|
2019-06-22 18:27:21 +00:00
|
|
|
|
// Update the back stack and associated controls.
|
|
|
|
|
mNavStack.Push(prevLoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moves the view and selection to the definition of a local variable.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">Offset at which the variable was referenced.</param>
|
|
|
|
|
/// <param name="symRef">Reference to variable.</param>
|
|
|
|
|
public void GoToVarDefinition(int offset, WeakSymbolRef symRef, bool doPush) {
|
|
|
|
|
Debug.Assert(offset >= 0);
|
|
|
|
|
Debug.Assert(symRef.IsVariable);
|
|
|
|
|
|
|
|
|
|
LocalVariableLookup lvLookup = new LocalVariableLookup(mProject.LvTables, mProject,
|
Label rework, part 6
Correct handling of local variables. We now correctly uniquify them
with regard to non-unique labels. Because local vars can effectively
have global scope we mostly want to treat them as global, but they're
uniquified relative to other globals very late in the process, so we
can't just throw them in the symbol table and be done. Fortunately
local variables exist in a separate namespace, so we just need to
uniquify the variables relative to the post-localization symbol table.
In other words, we take the symbol table, apply the label map, and
rename any variable that clashes.
This also fixes an older problem where we weren't masking the
leading '_' on variable labels when generating 64tass output.
The code list now makes non-unique labels obvious, but you can't tell
the difference between unique global and unique local. What's more,
the default type value in Edit Label is now adjusted to Global for
unique locals that were auto-generated. To make it a bit easier to
figure out what's what, the Info panel now has a "label type" line
that reports the type.
The 2023-non-unique-labels test had some additional tests added to
exercise conflicts with local variables. The 2019-local-variables
test output changed slightly because the de-duplicated variable
naming convention was simplified.
2019-11-18 21:26:03 +00:00
|
|
|
|
null, false, false);
|
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
|
|
|
|
int varOffset = lvLookup.GetDefiningTableOffset(offset, symRef);
|
2020-04-16 02:23:28 +00:00
|
|
|
|
if (varOffset < 0) {
|
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
|
|
|
|
Debug.WriteLine("Local variable not found; offset=" + offset + " ref=" + symRef);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-23 19:13:37 +00:00
|
|
|
|
// Find the actual symbol definition.
|
|
|
|
|
LocalVariableTable lvTable = mProject.LvTables[varOffset];
|
|
|
|
|
DefSymbol foundSym = lvTable.GetByLabel(symRef.Label);
|
|
|
|
|
if (foundSym == null) {
|
|
|
|
|
// shouldn't be possible
|
|
|
|
|
Debug.WriteLine("Did not find " + symRef.Label + " in expected table");
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
// We have the offset to which the local variable table is bound. We need to
|
|
|
|
|
// walk down until we find the variable definitions, and find the line with the
|
|
|
|
|
// matching symbol.
|
|
|
|
|
//
|
|
|
|
|
// We're comparing to the formatted strings -- safer than trying to find the symbol
|
|
|
|
|
// in the table and then guess at how the table arranges itself for display -- so we
|
|
|
|
|
// need to compare the formatted form of the label.
|
2020-01-23 19:13:37 +00:00
|
|
|
|
//
|
|
|
|
|
// We need to use GenerateDisplayLabel() because the symbol might have an annotation.
|
|
|
|
|
string cmpStr = mFormatter.FormatVariableLabel(
|
|
|
|
|
foundSym.GenerateDisplayLabel(mFormatter));
|
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
|
|
|
|
int lineIndex = CodeLineList.FindLineIndexByOffset(varOffset);
|
|
|
|
|
while (lineIndex < mProject.FileDataLength) {
|
|
|
|
|
LineListGen.Line line = CodeLineList[lineIndex];
|
|
|
|
|
if (line.FileOffset != varOffset) {
|
|
|
|
|
// we've gone too far
|
|
|
|
|
Debug.WriteLine("ran out of LV table");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (line.LineType == LineListGen.Line.Type.LocalVariableTable) {
|
|
|
|
|
DisplayList.FormattedParts parts = CodeLineList.GetFormattedParts(lineIndex);
|
|
|
|
|
if (cmpStr.Equals(parts.Label)) {
|
|
|
|
|
// Eureka
|
|
|
|
|
NavStack.Location prevLoc = GetCurrentlySelectedLocation();
|
|
|
|
|
|
|
|
|
|
mMainWin.CodeListView_EnsureVisible(lineIndex);
|
|
|
|
|
|
|
|
|
|
// Update the selection.
|
|
|
|
|
mMainWin.CodeListView_SelectRange(lineIndex, 1);
|
2021-08-09 00:39:21 +00:00
|
|
|
|
mMainWin.CodeListView_SetSelectionFocus();
|
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
|
|
|
|
|
|
|
|
|
if (doPush) {
|
|
|
|
|
// Update the back stack and associated controls.
|
|
|
|
|
mNavStack.Push(prevLoc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
//Debug.WriteLine("Var: '" + cmpStr + "' != '" + parts.Label + "'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lineIndex++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 23:28:29 +00:00
|
|
|
|
public bool CanJumpToOperand() {
|
|
|
|
|
if (SelectionAnalysis.mNumItemsSelected != 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
LineListGen.Line.Type lineType = SelectionAnalysis.mLineType;
|
|
|
|
|
if (lineType != LineListGen.Line.Type.Code &&
|
ORG rework, part 5
Updated project file format to save the new map entries.
Tweaked appearance of .arend directives to show the .arstart address
in the operand field. This makes it easier to match them up on screen.
Also, add a synthetic comment on auto-generated .arstart entries.
Added .arstart/.arend to the things that respond to Jump to Operand
(Ctrl+J). Selecting one jumps to the other end. (Well, it jumps
to the code nearest the other, which will do for now.)
Added a menu item to display a text rendering of the address map.
Helpful when things get complicated.
Modified the linear map iterator to return .arend items with the offset
of the last byte in the region, rather than the first byte of the
following region. While the "exclusive end" approach is pretty
common, it caused problems when updating the line list, because it
meant that the .arend directives were outside the range of offsets
being updated (and, for directives at the end of the file, outside
the file itself). This was painful to deal with for partial updates.
Changing this required some relatively subtle changes and annoyed some
of the debug assertions, such as the one where all Line items have
offsets that match the start of a line, but it's the cleaner approach.
2021-09-28 00:02:18 +00:00
|
|
|
|
lineType != LineListGen.Line.Type.Data &&
|
|
|
|
|
lineType != LineListGen.Line.Type.ArStartDirective &&
|
|
|
|
|
lineType != LineListGen.Line.Type.ArEndDirective) {
|
2020-06-07 23:28:29 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
Debug.Assert(selIndex >= 0);
|
|
|
|
|
return JumpToOperandTarget(CodeLineList[selIndex], true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void JumpToOperand() {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
Debug.Assert(selIndex >= 0);
|
|
|
|
|
JumpToOperandTarget(CodeLineList[selIndex], false);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-10 18:57:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calculates the currently-selected location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This is done whenever we jump somewhere else. For the most part we'll be in a
|
|
|
|
|
/// line of code, jumping when an operand or reference is double-clicked, but we might
|
|
|
|
|
/// be in the middle of a long comment when a symbol is double-clicked or the
|
|
|
|
|
/// nav-forward arrow is clicked. The most interesting case is when a reference for
|
|
|
|
|
/// a local variable table entry is double-clicked, since we want to be sure that we
|
|
|
|
|
/// return to the correct entry in the LvTable (assuming it still exists).
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <returns>Returns the location.</returns>
|
2019-06-22 18:27:21 +00:00
|
|
|
|
private NavStack.Location GetCurrentlySelectedLocation() {
|
|
|
|
|
int index = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
if (index < 0) {
|
|
|
|
|
// nothing selected, use top instead
|
|
|
|
|
index = mMainWin.CodeListView_GetTopIndex();
|
2019-06-15 23:00:31 +00:00
|
|
|
|
}
|
2019-06-22 18:27:21 +00:00
|
|
|
|
int offset = CodeLineList[index].FileOffset;
|
2019-10-10 18:57:36 +00:00
|
|
|
|
int lineDelta = index - CodeLineList.FindLineIndexByOffset(offset);
|
2019-06-22 18:27:21 +00:00
|
|
|
|
bool isNote = (CodeLineList[index].LineType == LineListGen.Line.Type.Note);
|
2021-10-07 19:39:08 +00:00
|
|
|
|
return new NavStack.Location(offset, lineDelta,
|
|
|
|
|
isNote ? NavStack.GoToMode.JumpToNote : NavStack.GoToMode.JumpToAdjIndex);
|
2019-06-15 23:00:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-02 01:44:22 +00:00
|
|
|
|
public void GotoLastChange() {
|
|
|
|
|
ChangeSet cs = mProject.GetTopChange();
|
|
|
|
|
Debug.Assert(cs.Count > 0);
|
|
|
|
|
|
|
|
|
|
// Get the offset from the first change in the set. Ignore the rest.
|
|
|
|
|
UndoableChange uc = cs[0];
|
|
|
|
|
int offset;
|
|
|
|
|
bool isNote = false;
|
|
|
|
|
if (uc.HasOffset) {
|
|
|
|
|
offset = uc.Offset;
|
|
|
|
|
|
|
|
|
|
// If we altered a Note, and didn't remove it, jump to the note instead of
|
|
|
|
|
// the nearby code/data.
|
|
|
|
|
//
|
|
|
|
|
// TODO(someday): we can do similar things for comment edits, e.g. if it's
|
|
|
|
|
// SetLongComment we can find the line on which the comment starts and
|
|
|
|
|
// pass that as a line delta.
|
|
|
|
|
if (uc.Type == UndoableChange.ChangeType.SetNote &&
|
|
|
|
|
uc.NewValue != null) {
|
|
|
|
|
isNote = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (uc.Type == UndoableChange.ChangeType.SetProjectProperties) {
|
|
|
|
|
// some chance it modified the EQU statements... jump there
|
|
|
|
|
offset = 0;
|
2020-10-15 21:03:32 +00:00
|
|
|
|
} else if (uc.Type == UndoableChange.ChangeType.SetAnalyzerTag) {
|
2019-11-02 01:44:22 +00:00
|
|
|
|
TypedRangeSet newSet = (TypedRangeSet)uc.NewValue;
|
|
|
|
|
if (newSet.Count == 0) {
|
|
|
|
|
// unexpected
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the offset of the first entry.
|
|
|
|
|
IEnumerator<TypedRangeSet.Tuple> iter =
|
|
|
|
|
(IEnumerator<TypedRangeSet.Tuple>)newSet.GetEnumerator();
|
|
|
|
|
iter.MoveNext();
|
|
|
|
|
TypedRangeSet.Tuple firstOffset = iter.Current;
|
|
|
|
|
offset = firstOffset.Value;
|
|
|
|
|
} else {
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isNote) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(new NavStack.Location(offset, 0, NavStack.GoToMode.JumpToNote),
|
|
|
|
|
true);
|
2019-11-02 01:44:22 +00:00
|
|
|
|
} else {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(new NavStack.Location(offset, 0, NavStack.GoToMode.JumpToCodeData),
|
|
|
|
|
true);
|
2019-11-02 01:44:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
public bool CanNavigateBackward() {
|
|
|
|
|
return mNavStack.HasBackward;
|
|
|
|
|
}
|
|
|
|
|
public void NavigateBackward() {
|
|
|
|
|
Debug.Assert(mNavStack.HasBackward);
|
2019-06-22 18:27:21 +00:00
|
|
|
|
NavStack.Location backLoc = mNavStack.MoveBackward(GetCurrentlySelectedLocation());
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(backLoc, false);
|
2019-06-15 23:00:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanNavigateForward() {
|
|
|
|
|
return mNavStack.HasForward;
|
|
|
|
|
}
|
|
|
|
|
public void NavigateForward() {
|
|
|
|
|
Debug.Assert(mNavStack.HasForward);
|
2019-06-22 18:27:21 +00:00
|
|
|
|
NavStack.Location fwdLoc = mNavStack.MoveForward(GetCurrentlySelectedLocation());
|
2021-10-07 19:39:08 +00:00
|
|
|
|
GoToLocation(fwdLoc, false);
|
2019-06-15 23:00:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-21 22:06:04 +00:00
|
|
|
|
/// <summary>
|
2022-01-12 23:28:59 +00:00
|
|
|
|
/// Scrolls the code list so that the specified label is shown. If the label can't
|
|
|
|
|
/// be found, nothing happens.
|
2019-06-21 22:06:04 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sym">Label symbol.</param>
|
2022-01-12 23:28:59 +00:00
|
|
|
|
public bool GoToSymbol(Symbol sym) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
|
|
if (sym.SymbolSource == Symbol.Source.Platform ||
|
|
|
|
|
sym.SymbolSource == Symbol.Source.Project) {
|
|
|
|
|
// Look for an EQU line for the project or platform symbol.
|
|
|
|
|
for (int i = 0; i < mProject.ActiveDefSymbolList.Count; i++) {
|
|
|
|
|
if (mProject.ActiveDefSymbolList[i] == sym) {
|
|
|
|
|
int offset = LineListGen.DefSymOffsetFromIndex(i);
|
|
|
|
|
Debug.Assert(offset < 0);
|
|
|
|
|
GoToLocation(new NavStack.Location(offset, 0,
|
|
|
|
|
NavStack.GoToMode.JumpToCodeData), true);
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-21 22:06:04 +00:00
|
|
|
|
} else {
|
2022-01-12 23:28:59 +00:00
|
|
|
|
// Just look for a matching label.
|
|
|
|
|
int offset = mProject.FindLabelOffsetByName(sym.Label);
|
|
|
|
|
if (offset >= 0) {
|
|
|
|
|
// TODO(someday):jump to symbol line, not arstart, for address region pre-labels
|
|
|
|
|
GoToLocation(new NavStack.Location(offset, 0, NavStack.GoToMode.JumpToCodeData),
|
|
|
|
|
true);
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
2019-06-21 22:06:04 +00:00
|
|
|
|
}
|
2022-01-12 23:28:59 +00:00
|
|
|
|
|
|
|
|
|
return found;
|
2019-06-21 22:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 23:34:47 +00:00
|
|
|
|
public void SelectionChanged() {
|
|
|
|
|
SelectionAnalysis = UpdateSelectionState();
|
2019-06-09 21:24:46 +00:00
|
|
|
|
|
2019-06-10 01:09:00 +00:00
|
|
|
|
UpdateReferencesPanel();
|
2019-06-09 21:24:46 +00:00
|
|
|
|
UpdateInfoPanel();
|
2019-06-16 16:29:54 +00:00
|
|
|
|
UpdateSelectionHighlight();
|
2019-06-09 21:24:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 22:48:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gathered facts about the current selection. Recalculated whenever the selection
|
|
|
|
|
/// changes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SelectionState {
|
|
|
|
|
// Number of selected items or lines, reduced. This will be:
|
|
|
|
|
// 0 if no lines are selected
|
|
|
|
|
// 1 if a single *item* is selected (regardless of number of lines)
|
|
|
|
|
// >1 if more than one item is selected (exact value not specified)
|
2019-06-16 23:34:47 +00:00
|
|
|
|
public int mNumItemsSelected;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
2019-06-16 23:34:47 +00:00
|
|
|
|
// Single selection: the type of line selected. (Multi-sel: Unclassified)
|
2019-06-08 22:48:44 +00:00
|
|
|
|
public LineListGen.Line.Type mLineType;
|
|
|
|
|
|
2019-06-16 23:34:47 +00:00
|
|
|
|
// Single selection: is line an instruction with an operand. (Multi-sel: False)
|
2019-06-08 22:48:44 +00:00
|
|
|
|
public bool mIsInstructionWithOperand;
|
|
|
|
|
|
2019-06-16 23:34:47 +00:00
|
|
|
|
// Single selection: is line an EQU directive for a project symbol. (Multi-sel: False)
|
2019-06-08 22:48:44 +00:00
|
|
|
|
public bool mIsProjectSymbolEqu;
|
|
|
|
|
|
|
|
|
|
// Some totals.
|
|
|
|
|
public EntityCounts mEntityCounts;
|
2019-06-11 23:27:15 +00:00
|
|
|
|
|
|
|
|
|
public SelectionState() {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
mLineType = LineListGen.Line.Type.Unclassified;
|
2019-06-11 23:27:15 +00:00
|
|
|
|
mEntityCounts = new EntityCounts();
|
|
|
|
|
}
|
2021-10-11 21:44:44 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return "SelState: numSel=" + mNumItemsSelected + " type=" + mLineType;
|
|
|
|
|
}
|
2019-06-08 22:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates Actions menu enable states when the selection changes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// is selected.</param>
|
|
|
|
|
public SelectionState UpdateSelectionState() {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
int selCount = mMainWin.CodeListView_GetSelectionCount();
|
2019-08-16 00:53:12 +00:00
|
|
|
|
//Debug.WriteLine("UpdateSelectionState: selCount=" + selCount);
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
SelectionState state = new SelectionState();
|
|
|
|
|
|
|
|
|
|
// Use IsSingleItemSelected(), rather than just checking sel.Count, because we
|
|
|
|
|
// want the user to be able to e.g. EditData on a multi-line string even if all
|
|
|
|
|
// lines in the string are selected.
|
2019-06-09 00:13:11 +00:00
|
|
|
|
if (selCount < 0) {
|
2019-06-08 22:48:44 +00:00
|
|
|
|
// nothing selected, leave everything set to false / 0
|
|
|
|
|
state.mEntityCounts = new EntityCounts();
|
|
|
|
|
} else if (IsSingleItemSelected()) {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
int firstIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
state.mNumItemsSelected = 1;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
state.mEntityCounts = GatherEntityCounts(firstIndex);
|
2019-06-16 23:34:47 +00:00
|
|
|
|
LineListGen.Line line = CodeLineList[firstIndex];
|
2019-06-08 22:48:44 +00:00
|
|
|
|
state.mLineType = line.LineType;
|
|
|
|
|
|
|
|
|
|
state.mIsInstructionWithOperand = (line.LineType == LineListGen.Line.Type.Code &&
|
|
|
|
|
mProject.GetAnattrib(line.FileOffset).IsInstructionWithOperand);
|
|
|
|
|
if (line.LineType == LineListGen.Line.Type.EquDirective) {
|
|
|
|
|
// See if this EQU directive is for a project symbol.
|
|
|
|
|
int symIndex = LineListGen.DefSymIndexFromOffset(line.FileOffset);
|
|
|
|
|
DefSymbol defSym = mProject.ActiveDefSymbolList[symIndex];
|
|
|
|
|
state.mIsProjectSymbolEqu = (defSym.SymbolSource == Symbol.Source.Project);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
state.mNumItemsSelected = 2;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
state.mEntityCounts = GatherEntityCounts(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entity count collection, for GatherEntityCounts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class EntityCounts {
|
|
|
|
|
public int mCodeLines;
|
|
|
|
|
public int mDataLines;
|
|
|
|
|
public int mBlankLines;
|
|
|
|
|
public int mControlLines;
|
|
|
|
|
|
2020-10-15 21:03:32 +00:00
|
|
|
|
public int mCodeStartTags;
|
|
|
|
|
public int mCodeStopTags;
|
|
|
|
|
public int mInlineDataTags;
|
|
|
|
|
public int mNoTags;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-10-15 21:03:32 +00:00
|
|
|
|
/// Gathers a count of different line types and atags that are currently selected.
|
2019-06-08 22:48:44 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="singleLineIndex">If a single line is selected, pass the index in.
|
|
|
|
|
/// Otherwise, pass -1 to traverse the entire line list.</param>
|
|
|
|
|
/// <returns>Object with computed totals.</returns>
|
|
|
|
|
private EntityCounts GatherEntityCounts(int singleLineIndex) {
|
|
|
|
|
//DateTime startWhen = DateTime.Now;
|
|
|
|
|
int codeLines, dataLines, blankLines, controlLines;
|
2020-10-15 21:03:32 +00:00
|
|
|
|
int codeStartTags, codeStopTags, inlineDataTags, noTags;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
codeLines = dataLines = blankLines = controlLines = 0;
|
2020-10-15 21:03:32 +00:00
|
|
|
|
codeStartTags = codeStopTags = inlineDataTags = noTags = 0;
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
int startIndex, endIndex;
|
|
|
|
|
if (singleLineIndex < 0) {
|
|
|
|
|
startIndex = 0;
|
|
|
|
|
endIndex = mMainWin.CodeDisplayList.Count - 1;
|
|
|
|
|
} else {
|
|
|
|
|
startIndex = endIndex = singleLineIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = startIndex; i <= endIndex; i++) {
|
|
|
|
|
if (!mMainWin.CodeDisplayList.SelectedIndices[i]) {
|
|
|
|
|
// not selected, ignore
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-06-16 23:34:47 +00:00
|
|
|
|
LineListGen.Line line = CodeLineList[i];
|
2019-06-08 22:48:44 +00:00
|
|
|
|
switch (line.LineType) {
|
|
|
|
|
case LineListGen.Line.Type.Code:
|
|
|
|
|
codeLines++;
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.Data:
|
|
|
|
|
dataLines++;
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.Blank:
|
|
|
|
|
// Don't generally care how many blank lines there are, but we do want
|
|
|
|
|
// to exclude them from the other categories: if we have nothing but
|
|
|
|
|
// blank lines, there's nothing to do.
|
|
|
|
|
blankLines++;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// These are only editable as single-line items. We do allow mass
|
2020-10-15 21:03:32 +00:00
|
|
|
|
// atag selection to include them (they will be ignored).
|
2019-06-08 22:48:44 +00:00
|
|
|
|
// org, equ, rwid, long comment...
|
|
|
|
|
controlLines++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A single line can span multiple offsets, each of which could have a
|
2020-10-15 21:03:32 +00:00
|
|
|
|
// different analyzer tag. Note the code start/stop tags are only applied to the
|
|
|
|
|
// first byte of each selected line, so we're not quite in sync with that.
|
2019-08-17 23:59:08 +00:00
|
|
|
|
//
|
|
|
|
|
// For multi-line items, the OffsetSpan of the first item covers the entire
|
|
|
|
|
// item (it's the same for all Line instances), so we only want to do this for
|
|
|
|
|
// the first entry.
|
|
|
|
|
if (line.SubLineIndex == 0) {
|
|
|
|
|
for (int offset = line.FileOffset; offset < line.FileOffset + line.OffsetSpan;
|
|
|
|
|
offset++) {
|
2020-10-15 21:03:32 +00:00
|
|
|
|
switch (mProject.AnalyzerTags[offset]) {
|
|
|
|
|
case CodeAnalysis.AnalyzerTag.Code:
|
|
|
|
|
codeStartTags++;
|
2019-08-17 23:59:08 +00:00
|
|
|
|
break;
|
2020-10-15 21:03:32 +00:00
|
|
|
|
case CodeAnalysis.AnalyzerTag.Data:
|
|
|
|
|
codeStopTags++;
|
2019-08-17 23:59:08 +00:00
|
|
|
|
break;
|
2020-10-15 21:03:32 +00:00
|
|
|
|
case CodeAnalysis.AnalyzerTag.InlineData:
|
|
|
|
|
inlineDataTags++;
|
2019-08-17 23:59:08 +00:00
|
|
|
|
break;
|
2020-10-15 21:03:32 +00:00
|
|
|
|
case CodeAnalysis.AnalyzerTag.None:
|
|
|
|
|
noTags++;
|
2019-08-17 23:59:08 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-08 22:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 23:59:08 +00:00
|
|
|
|
//Debug.WriteLine("GatherEntityCounts (start=" + startIndex + " end=" + endIndex +
|
|
|
|
|
// " len=" + mMainWin.CodeDisplayList.Count +
|
|
|
|
|
// ") took " + (DateTime.Now - startWhen).TotalMilliseconds + " ms");
|
2019-06-08 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
return new EntityCounts() {
|
|
|
|
|
mCodeLines = codeLines,
|
|
|
|
|
mDataLines = dataLines,
|
|
|
|
|
mBlankLines = blankLines,
|
|
|
|
|
mControlLines = controlLines,
|
2020-10-15 21:03:32 +00:00
|
|
|
|
mCodeStartTags = codeStartTags,
|
|
|
|
|
mCodeStopTags = codeStopTags,
|
|
|
|
|
mInlineDataTags = inlineDataTags,
|
|
|
|
|
mNoTags = noTags
|
2019-06-08 22:48:44 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether the current selection spans a single item. This could be a
|
|
|
|
|
/// single-line item or a multi-line item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool IsSingleItemSelected() {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
int firstIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
2019-06-08 22:48:44 +00:00
|
|
|
|
if (firstIndex < 0) {
|
|
|
|
|
// empty selection
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
int lastIndex = mMainWin.CodeListView_GetLastSelectedIndex();
|
2019-06-08 22:48:44 +00:00
|
|
|
|
if (lastIndex == firstIndex) {
|
|
|
|
|
// only one line is selected
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Just check the first and last entries to see if they're the same.
|
2019-06-16 23:34:47 +00:00
|
|
|
|
LineListGen.Line firstItem = CodeLineList[firstIndex];
|
|
|
|
|
LineListGen.Line lastItem = CodeLineList[lastIndex];
|
2019-06-08 22:48:44 +00:00
|
|
|
|
if (firstItem.FileOffset == lastItem.FileOffset &&
|
|
|
|
|
firstItem.LineType == lastItem.LineType) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-13 23:45:49 +00:00
|
|
|
|
private bool mUpdatingSelectionHighlight; // recursion guard for next method
|
|
|
|
|
|
2019-06-16 16:29:54 +00:00
|
|
|
|
/// <summary>
|
2021-11-17 19:18:23 +00:00
|
|
|
|
/// Updates the selection highlights. When a code or data item with an operand offset is
|
2019-06-16 16:29:54 +00:00
|
|
|
|
/// selected, such as a branch, we want to highlight the address and label of the
|
2021-11-17 19:18:23 +00:00
|
|
|
|
/// target. When a code or data item is referenced by another instruction, such as a
|
|
|
|
|
/// branch, we want to highlight the operands of all such instructions.
|
2019-06-16 16:29:54 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateSelectionHighlight() {
|
2021-11-13 23:45:49 +00:00
|
|
|
|
if (mUpdatingSelectionHighlight) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-17 19:18:23 +00:00
|
|
|
|
mUpdatingSelectionHighlight = true;
|
2019-06-16 16:29:54 +00:00
|
|
|
|
|
2021-11-25 18:31:50 +00:00
|
|
|
|
//
|
|
|
|
|
// Start with the target address highlight, for branches and in-file memory accesses.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int targetIndex = -1;
|
|
|
|
|
LineListGen.Line selectedLine = null;
|
|
|
|
|
if (mMainWin.CodeListView_GetSelectionCount() == 1) {
|
|
|
|
|
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
selectedLine = CodeLineList[selIndex];
|
|
|
|
|
if (selectedLine.IsCodeOrData) {
|
|
|
|
|
Debug.Assert(selectedLine.FileOffset >= 0);
|
|
|
|
|
targetIndex = FindSelectionAddrHighlight(selectedLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-13 23:45:49 +00:00
|
|
|
|
if (mTargetHighlightIndex != targetIndex) {
|
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
|
|
|
|
Debug.WriteLine("Target highlight moving from " + mTargetHighlightIndex +
|
|
|
|
|
" to " + targetIndex);
|
|
|
|
|
|
|
|
|
|
// The highlight is currently implemented by modifying the item in the
|
|
|
|
|
// display list. Because those items are immutable, we have to remove the
|
|
|
|
|
// old and add a new. The WPF ListView maintains its selection by object
|
|
|
|
|
// reference, so replacing an item requires removing the old item from the
|
|
|
|
|
// selection set and adding it to the new.
|
|
|
|
|
//
|
|
|
|
|
// So if a line references itself (like the ZipGS cache conditioner loop does),
|
|
|
|
|
// it will be the selected line while we're doing this little dance. When the
|
|
|
|
|
// calls below update the selection, this method will be called again. This
|
|
|
|
|
// turns into infinite recursion.
|
2021-11-17 19:18:23 +00:00
|
|
|
|
mMainWin.CodeListView_RemoveSelectionAddrHighlight(mTargetHighlightIndex);
|
|
|
|
|
mMainWin.CodeListView_AddSelectionAddrHighlight(targetIndex);
|
2019-06-16 16:29:54 +00:00
|
|
|
|
|
|
|
|
|
mTargetHighlightIndex = targetIndex;
|
|
|
|
|
}
|
2021-11-17 19:18:23 +00:00
|
|
|
|
|
2021-11-25 18:31:50 +00:00
|
|
|
|
//
|
|
|
|
|
// Now do the source operand highlight, to see what refers to the current address.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Un-highlight anything we had highlighted previously.
|
2021-11-17 19:18:23 +00:00
|
|
|
|
if (mOperandHighlights.Count > 0) {
|
|
|
|
|
foreach (int index in mOperandHighlights) {
|
|
|
|
|
mMainWin.CodeListView_RemoveSelectionOperHighlight(index);
|
|
|
|
|
}
|
|
|
|
|
mOperandHighlights.Clear();
|
|
|
|
|
}
|
2021-11-25 18:31:50 +00:00
|
|
|
|
if (selectedLine != null) {
|
|
|
|
|
XrefSet xrefs = null;
|
|
|
|
|
if (selectedLine.IsCodeOrData) {
|
|
|
|
|
xrefs = mProject.GetXrefSet(selectedLine.FileOffset);
|
|
|
|
|
} else if (selectedLine.LineType == LineListGen.Line.Type.LocalVariableTable) {
|
|
|
|
|
DefSymbol defSym = CodeLineList.GetLocalVariableFromLine(selectedLine);
|
|
|
|
|
xrefs = (defSym == null) ? null : defSym.Xrefs;
|
|
|
|
|
}
|
2021-11-17 19:18:23 +00:00
|
|
|
|
if (xrefs != null) {
|
|
|
|
|
foreach (XrefSet.Xref xr in xrefs) {
|
|
|
|
|
int refIndex = CodeLineList.FindCodeDataIndexByOffset(xr.Offset);
|
|
|
|
|
mMainWin.CodeListView_AddSelectionOperHighlight(refIndex);
|
|
|
|
|
mOperandHighlights.Add(refIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mUpdatingSelectionHighlight = false;
|
2019-06-16 16:29:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-25 18:31:50 +00:00
|
|
|
|
private int FindSelectionAddrHighlight(LineListGen.Line line) {
|
2019-06-16 16:29:54 +00:00
|
|
|
|
// Does this have an operand with an in-file target offset?
|
2020-07-04 00:37:04 +00:00
|
|
|
|
// TODO: may not work correctly with reloc data?
|
2019-06-16 16:29:54 +00:00
|
|
|
|
Anattrib attr = mProject.GetAnattrib(line.FileOffset);
|
|
|
|
|
if (attr.OperandOffset >= 0) {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
return CodeLineList.FindCodeDataIndexByOffset(attr.OperandOffset);
|
2019-06-16 16:29:54 +00:00
|
|
|
|
} else if (attr.IsDataStart || attr.IsInlineDataStart) {
|
|
|
|
|
// If it's an Address or Symbol, we can try to resolve
|
|
|
|
|
// the value.
|
|
|
|
|
int operandOffset = DataAnalysis.GetDataOperandOffset(mProject, line.FileOffset);
|
|
|
|
|
if (operandOffset >= 0) {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
return CodeLineList.FindCodeDataIndexByOffset(operandOffset);
|
2019-06-16 16:29:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-13 00:04:14 +00:00
|
|
|
|
public void ShowHexDump() {
|
|
|
|
|
if (mHexDumpDialog == null) {
|
|
|
|
|
// Create and show modeless dialog. This one is "always on top" by default,
|
2019-07-15 01:12:03 +00:00
|
|
|
|
// to allow the user to click around to various points. Note that "on top"
|
|
|
|
|
// means on top of *everything*. We create this without an owner so that,
|
|
|
|
|
// when it's not on top, it can sit behind the main app window until you
|
|
|
|
|
// double-click something else.
|
|
|
|
|
mHexDumpDialog = new Tools.WpfGui.HexDumpViewer(null,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mProject.FileData, mFormatter);
|
2019-07-13 00:04:14 +00:00
|
|
|
|
mHexDumpDialog.Closing += (sender, e) => {
|
|
|
|
|
Debug.WriteLine("Hex dump dialog closed");
|
|
|
|
|
//showHexDumpToolStripMenuItem.Checked = false;
|
|
|
|
|
mHexDumpDialog = null;
|
|
|
|
|
};
|
|
|
|
|
mHexDumpDialog.Topmost = true;
|
|
|
|
|
mHexDumpDialog.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bring it to the front of the window stack. This also transfers focus to the
|
|
|
|
|
// window.
|
|
|
|
|
mHexDumpDialog.Activate();
|
|
|
|
|
|
|
|
|
|
// Set the dialog's position.
|
|
|
|
|
if (mMainWin.CodeListView_GetSelectionCount() > 0) {
|
|
|
|
|
int firstIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int lastIndex = mMainWin.CodeListView_GetLastSelectedIndex();
|
|
|
|
|
// offsets can be < 0 if they've selected EQU statements
|
|
|
|
|
int firstOffset = Math.Max(0, CodeLineList[firstIndex].FileOffset);
|
|
|
|
|
int lastOffset = Math.Max(firstOffset, CodeLineList[lastIndex].FileOffset +
|
|
|
|
|
CodeLineList[lastIndex].OffsetSpan - 1);
|
|
|
|
|
mHexDumpDialog.ShowOffsetRange(firstOffset, lastOffset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 23:27:15 +00:00
|
|
|
|
/// <summary>
|
2020-10-15 21:03:32 +00:00
|
|
|
|
/// Handles the four analyzer tag commands.
|
2019-06-11 23:27:15 +00:00
|
|
|
|
/// </summary>
|
2020-10-15 21:03:32 +00:00
|
|
|
|
/// <param name="atag">Type of tag to apply.</param>
|
|
|
|
|
/// <param name="firstByteOnly">If set, only the first byte on each line is tagged.</param>
|
|
|
|
|
public void MarkAsType(CodeAnalysis.AnalyzerTag atag, bool firstByteOnly) {
|
2019-06-09 00:13:11 +00:00
|
|
|
|
RangeSet sel;
|
|
|
|
|
|
|
|
|
|
if (firstByteOnly) {
|
|
|
|
|
sel = new RangeSet();
|
|
|
|
|
foreach (int index in mMainWin.CodeDisplayList.SelectedIndices) {
|
2019-06-16 23:34:47 +00:00
|
|
|
|
int offset = CodeLineList[index].FileOffset;
|
2019-06-09 00:13:11 +00:00
|
|
|
|
if (offset >= 0) {
|
2020-10-15 21:03:32 +00:00
|
|
|
|
// Ignore the header lines.
|
2019-06-09 00:13:11 +00:00
|
|
|
|
sel.Add(offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-16 00:18:49 +00:00
|
|
|
|
|
|
|
|
|
// "first byte only" is used for code start/stop tags, which should only be
|
|
|
|
|
// placed at the start of a region.
|
|
|
|
|
if (sel.Count > 1) {
|
|
|
|
|
MessageBoxResult result = MessageBox.Show(Res.Strings.ANALYZER_TAG_MULTI_CHK,
|
|
|
|
|
Res.Strings.CONFIRMATION_NEEDED,
|
|
|
|
|
MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
|
|
|
|
if (result == MessageBoxResult.Cancel) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-09 00:13:11 +00:00
|
|
|
|
} else {
|
2020-10-16 00:18:49 +00:00
|
|
|
|
// Inline data or none. Select all bytes.
|
2019-06-09 00:13:11 +00:00
|
|
|
|
sel = OffsetSetFromSelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TypedRangeSet newSet = new TypedRangeSet();
|
|
|
|
|
TypedRangeSet undoSet = new TypedRangeSet();
|
|
|
|
|
|
|
|
|
|
foreach (int offset in sel) {
|
|
|
|
|
if (offset < 0) {
|
|
|
|
|
// header comment
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-10-15 21:03:32 +00:00
|
|
|
|
CodeAnalysis.AnalyzerTag oldType = mProject.AnalyzerTags[offset];
|
|
|
|
|
if (oldType == atag) {
|
2019-06-09 00:13:11 +00:00
|
|
|
|
// no change, don't add to set
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
undoSet.Add(offset, (int)oldType);
|
2020-10-15 21:03:32 +00:00
|
|
|
|
newSet.Add(offset, (int)atag);
|
2019-06-09 00:13:11 +00:00
|
|
|
|
}
|
|
|
|
|
if (newSet.Count == 0) {
|
2020-10-15 21:03:32 +00:00
|
|
|
|
Debug.WriteLine("No changes found (" + atag + ", " + sel.Count + " offsets)");
|
2019-06-09 00:13:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-15 21:03:32 +00:00
|
|
|
|
UndoableChange uc = UndoableChange.CreateAnalyzerTagChange(undoSet, newSet);
|
2019-06-09 00:13:11 +00:00
|
|
|
|
ChangeSet cs = new ChangeSet(uc);
|
|
|
|
|
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts the set of selected items into a set of offsets. If a line
|
|
|
|
|
/// spans multiple offsets (e.g. a 3-byte instruction), offsets for every
|
|
|
|
|
/// byte are included.
|
|
|
|
|
///
|
|
|
|
|
/// Boundaries such as labels and address changes are ignored.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>RangeSet with all offsets.</returns>
|
|
|
|
|
private RangeSet OffsetSetFromSelected() {
|
|
|
|
|
RangeSet rs = new RangeSet();
|
|
|
|
|
|
|
|
|
|
foreach (int index in mMainWin.CodeDisplayList.SelectedIndices) {
|
2021-10-12 18:16:50 +00:00
|
|
|
|
if (CodeLineList[index].LineType == LineListGen.Line.Type.ArEndDirective) {
|
|
|
|
|
// We don't care about these, and they have the offset of the *last* byte
|
|
|
|
|
// of multi-byte instructions, which is a little confusing.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-06-16 23:34:47 +00:00
|
|
|
|
int offset = CodeLineList[index].FileOffset;
|
2021-11-13 23:45:49 +00:00
|
|
|
|
if (offset < 0) {
|
|
|
|
|
// Ignore file header comment and EQU lines.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-06-09 00:13:11 +00:00
|
|
|
|
|
|
|
|
|
// Mark every byte of an instruction or multi-byte data item --
|
|
|
|
|
// everything that is represented by the line the user selected.
|
|
|
|
|
int len;
|
|
|
|
|
if (offset >= 0) {
|
|
|
|
|
len = mProject.GetAnattrib(offset).Length;
|
|
|
|
|
} else {
|
|
|
|
|
// header area
|
|
|
|
|
len = 1;
|
|
|
|
|
}
|
|
|
|
|
Debug.Assert(len > 0);
|
|
|
|
|
for (int i = offset; i < offset + len; i++) {
|
|
|
|
|
rs.Add(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rs;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 23:27:15 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles Help - Help
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ShowHelp() {
|
|
|
|
|
HelpAccess.ShowHelp(HelpAccess.Topic.Contents);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-06 22:51:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles Help - About
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ShowAboutBox() {
|
|
|
|
|
AboutBox dlg = new AboutBox(mMainWin);
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-08 00:17:48 +00:00
|
|
|
|
public void ToggleDataScan() {
|
|
|
|
|
ProjectProperties oldProps = mProject.ProjectProps;
|
|
|
|
|
ProjectProperties newProps = new ProjectProperties(oldProps);
|
|
|
|
|
newProps.AnalysisParams.AnalyzeUncategorizedData =
|
|
|
|
|
!newProps.AnalysisParams.AnalyzeUncategorizedData;
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateProjectPropertiesChange(oldProps, newProps);
|
|
|
|
|
ApplyUndoableChanges(new ChangeSet(uc));
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 20:50:15 +00:00
|
|
|
|
public bool CanToggleSingleByteFormat() {
|
|
|
|
|
EntityCounts counts = SelectionAnalysis.mEntityCounts;
|
|
|
|
|
return (counts.mDataLines > 0 && counts.mCodeLines == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleSingleByteFormat() {
|
|
|
|
|
TypedRangeSet trs = GroupedOffsetSetFromSelected();
|
|
|
|
|
if (trs.Count == 0) {
|
|
|
|
|
Debug.Assert(false, "nothing to edit"); // shouldn't happen
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check the format descriptor of the first selected offset.
|
|
|
|
|
int firstOffset = -1;
|
|
|
|
|
foreach (TypedRangeSet.Tuple tup in trs) {
|
|
|
|
|
firstOffset = tup.Value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-10-06 02:51:34 +00:00
|
|
|
|
Debug.Assert(mProject.GetAnattrib(firstOffset).IsDataStart ||
|
|
|
|
|
mProject.GetAnattrib(firstOffset).IsInlineDataStart);
|
2019-07-14 20:50:15 +00:00
|
|
|
|
bool toDefault = false;
|
|
|
|
|
if (mProject.OperandFormats.TryGetValue(firstOffset, out FormatDescriptor curDfd)) {
|
|
|
|
|
if (curDfd.FormatType == FormatDescriptor.Type.NumericLE &&
|
|
|
|
|
curDfd.FormatSubType == FormatDescriptor.SubType.None &&
|
|
|
|
|
curDfd.Length == 1) {
|
|
|
|
|
// Currently single-byte, toggle to default.
|
|
|
|
|
toDefault = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Iterate through the selected regions.
|
|
|
|
|
SortedList<int, FormatDescriptor> newFmts = new SortedList<int, FormatDescriptor>();
|
|
|
|
|
IEnumerator<TypedRangeSet.TypedRange> rngIter = trs.RangeListIterator;
|
|
|
|
|
while (rngIter.MoveNext()) {
|
|
|
|
|
TypedRangeSet.TypedRange rng = rngIter.Current;
|
|
|
|
|
if (toDefault) {
|
|
|
|
|
// Create a single REMOVE descriptor that covers the full span.
|
|
|
|
|
FormatDescriptor newDfd = FormatDescriptor.Create(rng.High - rng.Low + 1,
|
|
|
|
|
FormatDescriptor.Type.REMOVE, FormatDescriptor.SubType.None);
|
|
|
|
|
newFmts.Add(rng.Low, newDfd);
|
|
|
|
|
} else {
|
|
|
|
|
// Add individual single-byte format descriptors for everything.
|
|
|
|
|
FormatDescriptor newDfd = FormatDescriptor.Create(1,
|
|
|
|
|
FormatDescriptor.Type.NumericLE, FormatDescriptor.SubType.None);
|
|
|
|
|
for (int i = rng.Low; i <= rng.High; i++) {
|
|
|
|
|
newFmts.Add(i, newDfd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChangeSet cs = mProject.GenerateFormatMergeSet(newFmts);
|
|
|
|
|
if (cs.Count != 0) {
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 00:02:25 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts the ListView's selected items into a set of offsets. If a line
|
|
|
|
|
/// spans multiple offsets (e.g. a 3-byte instruction), offsets for every
|
|
|
|
|
/// byte are included.
|
2019-12-28 19:44:26 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
2019-07-09 00:02:25 +00:00
|
|
|
|
/// Contiguous regions with user labels or address changes are split into
|
|
|
|
|
/// independent regions by using a serial number for the range type. Same for
|
|
|
|
|
/// long comments and notes.
|
|
|
|
|
///
|
|
|
|
|
/// We don't split based on existing data format items. That would make it impossible
|
|
|
|
|
/// to convert from (say) a collection of single bytes to a collection of double bytes
|
|
|
|
|
/// or a string. It should not be possible to select part of a formatted section,
|
2020-10-15 21:03:32 +00:00
|
|
|
|
/// unless the user has been playing weird games with analyzer tags to get overlapping
|
2019-07-09 00:02:25 +00:00
|
|
|
|
/// format descriptors.
|
2020-02-28 22:43:03 +00:00
|
|
|
|
///
|
|
|
|
|
/// The type values used in the TypedRangeSet may not be contiguous. They're only
|
|
|
|
|
/// there to create group separation from otherwise contiguous address ranges.
|
2019-12-28 19:44:26 +00:00
|
|
|
|
/// </remarks>
|
2019-07-09 00:02:25 +00:00
|
|
|
|
/// <returns>TypedRangeSet with all offsets.</returns>
|
|
|
|
|
private TypedRangeSet GroupedOffsetSetFromSelected() {
|
|
|
|
|
TypedRangeSet rs = new TypedRangeSet();
|
|
|
|
|
int groupNum = 0;
|
|
|
|
|
int expectedAddr = -1;
|
|
|
|
|
|
|
|
|
|
DateTime startWhen = DateTime.Now;
|
|
|
|
|
int prevOffset = -1;
|
|
|
|
|
foreach (int index in mMainWin.CodeDisplayList.SelectedIndices) {
|
|
|
|
|
// Don't add an offset to the set if the only part of it that is selected
|
|
|
|
|
// is a directive or blank line. We only care about file offsets, so skip
|
|
|
|
|
// anything that isn't code or data.
|
|
|
|
|
if (!CodeLineList[index].IsCodeOrData) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int offset = CodeLineList[index].FileOffset;
|
|
|
|
|
if (offset == prevOffset) {
|
|
|
|
|
// This is a continuation of a multi-line item like a string. We've
|
|
|
|
|
// already accounted for all bytes associated with this offset.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Anattrib attr = mProject.GetAnattrib(offset);
|
|
|
|
|
|
|
|
|
|
if (expectedAddr == -1) {
|
|
|
|
|
expectedAddr = attr.Address;
|
|
|
|
|
}
|
2019-11-09 04:44:45 +00:00
|
|
|
|
// Check for things that start a new group.
|
|
|
|
|
if (attr.Address != expectedAddr) {
|
|
|
|
|
// For a contiguous selection, this should only happen if there's a .ORG
|
|
|
|
|
// address change. For non-contiguous selection this is expected. In the
|
2020-02-28 22:43:03 +00:00
|
|
|
|
// latter case, incrementing the group number is unnecessary but harmless
|
|
|
|
|
// (the TypedRangeSet splits at the gap).
|
|
|
|
|
//Debug.WriteLine("Address break: $" + attr.Address.ToString("x4") + " vs. $"
|
|
|
|
|
// + expectedAddr.ToString("x4"));
|
2019-11-09 04:44:45 +00:00
|
|
|
|
expectedAddr = attr.Address;
|
|
|
|
|
groupNum++;
|
2021-09-17 00:02:19 +00:00
|
|
|
|
} else if (offset > 0 && !mProject.AddrMap.IsRangeUnbroken(offset - 1, 2)) {
|
2020-02-28 22:43:03 +00:00
|
|
|
|
// Was the previous byte in a different address range? This is only
|
|
|
|
|
// strictly necessary if the previous byte was in the selection set (which
|
|
|
|
|
// it won't be if the selection starts at the beginning of an address
|
|
|
|
|
// range), but bumping the group number is harmless if it wasn't.
|
|
|
|
|
groupNum++;
|
2019-12-05 21:48:18 +00:00
|
|
|
|
} else if (mProject.UserLabels.ContainsKey(offset)) {
|
2019-07-09 00:02:25 +00:00
|
|
|
|
//if (mProject.GetAnattrib(offset).Symbol != null) {
|
|
|
|
|
// We consider auto labels when splitting regions for the data analysis,
|
|
|
|
|
// but I don't think we want to take them into account here. The specific
|
|
|
|
|
// example that threw me was loading a 16-bit value from an address table.
|
|
|
|
|
// The code does "LDA table,X / STA / LDA table+1,X / STA", which puts auto
|
|
|
|
|
// labels at the first two addresses -- splitting the region. That's good
|
|
|
|
|
// for the uncategorized data analyzer, but very annoying if you want to
|
|
|
|
|
// slap a 16-bit numeric format on all entries in a table.
|
|
|
|
|
groupNum++;
|
2019-12-06 22:49:35 +00:00
|
|
|
|
} else if (mProject.HasCommentNoteOrVis(offset)) {
|
|
|
|
|
// Don't carry across a long comment, note, or visualization.
|
2019-12-05 21:48:18 +00:00
|
|
|
|
groupNum++;
|
2019-07-09 00:02:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mark every byte of an instruction or multi-byte data item --
|
|
|
|
|
// everything that is represented by the line the user selected. Control
|
|
|
|
|
// statements and blank lines aren't relevant here, as we only care about
|
|
|
|
|
// file offsets.
|
|
|
|
|
int len = CodeLineList[index].OffsetSpan; // attr.Length;
|
|
|
|
|
Debug.Assert(len > 0);
|
|
|
|
|
for (int i = offset; i < offset + len; i++) {
|
|
|
|
|
rs.Add(i, groupNum);
|
|
|
|
|
}
|
|
|
|
|
// Advance the address.
|
|
|
|
|
expectedAddr += len;
|
|
|
|
|
|
|
|
|
|
prevOffset = offset;
|
|
|
|
|
}
|
|
|
|
|
Debug.WriteLine("Offset selection conv took " +
|
|
|
|
|
(DateTime.Now - startWhen).TotalMilliseconds + " ms");
|
|
|
|
|
return rs;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-19 23:55:36 +00:00
|
|
|
|
public bool CanUndo() {
|
|
|
|
|
return (mProject != null && mProject.CanUndo);
|
|
|
|
|
}
|
2019-06-09 21:24:46 +00:00
|
|
|
|
|
2020-07-19 23:55:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles Edit - Undo.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void UndoChanges() {
|
|
|
|
|
if (!mProject.CanUndo) {
|
|
|
|
|
Debug.Assert(false, "Nothing to undo");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ChangeSet cs = mProject.PopUndoSet();
|
|
|
|
|
ApplyChanges(cs, true);
|
|
|
|
|
UpdateTitle();
|
|
|
|
|
|
|
|
|
|
// If the debug dialog is visible, update it.
|
|
|
|
|
if (mShowUndoRedoHistoryDialog != null) {
|
|
|
|
|
mShowUndoRedoHistoryDialog.DisplayText = mProject.DebugGetUndoRedoHistory();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanRedo() {
|
|
|
|
|
return (mProject != null && mProject.CanRedo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles Edit - Redo.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RedoChanges() {
|
|
|
|
|
if (!mProject.CanRedo) {
|
|
|
|
|
Debug.Assert(false, "Nothing to redo");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ChangeSet cs = mProject.PopRedoSet();
|
|
|
|
|
ApplyChanges(cs, false);
|
|
|
|
|
UpdateTitle();
|
|
|
|
|
|
|
|
|
|
// If the debug dialog is visible, update it.
|
|
|
|
|
if (mShowUndoRedoHistoryDialog != null) {
|
|
|
|
|
mShowUndoRedoHistoryDialog.DisplayText = mProject.DebugGetUndoRedoHistory();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Main window UI event handlers
|
2019-06-16 23:34:47 +00:00
|
|
|
|
|
2019-06-10 01:09:00 +00:00
|
|
|
|
#region References panel
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the "references" panel to reflect the current selection.
|
|
|
|
|
///
|
|
|
|
|
/// The number of references to any given address should be relatively small, and
|
|
|
|
|
/// won't change without a data refresh, so recreating the list every time shouldn't
|
|
|
|
|
/// be a problem.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateReferencesPanel() {
|
|
|
|
|
mMainWin.ReferencesList.Clear();
|
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
if (mMainWin.CodeListView_GetSelectionCount() != 1) {
|
2019-06-10 01:09:00 +00:00
|
|
|
|
// Nothing selected, or multiple lines selected.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-15 23:00:31 +00:00
|
|
|
|
int lineIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
2024-05-22 21:01:02 +00:00
|
|
|
|
LineListGen.Line line = CodeLineList[lineIndex];
|
|
|
|
|
LineListGen.Line.Type type = line.LineType;
|
2019-06-10 01:09:00 +00:00
|
|
|
|
if (type != LineListGen.Line.Type.Code &&
|
|
|
|
|
type != LineListGen.Line.Type.Data &&
|
2019-08-29 20:32:45 +00:00
|
|
|
|
type != LineListGen.Line.Type.EquDirective &&
|
|
|
|
|
type != LineListGen.Line.Type.LocalVariableTable) {
|
2019-06-10 01:09:00 +00:00
|
|
|
|
// Code, data, and platform symbol EQUs have xrefs.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XrefSet xrefs;
|
2019-08-29 20:32:45 +00:00
|
|
|
|
|
|
|
|
|
// Find the appropriate xref set.
|
|
|
|
|
if (type == LineListGen.Line.Type.LocalVariableTable) {
|
2024-05-22 21:01:02 +00:00
|
|
|
|
DefSymbol defSym = CodeLineList.GetLocalVariableFromLine(line);
|
2019-08-29 20:32:45 +00:00
|
|
|
|
xrefs = (defSym == null) ? null : defSym.Xrefs;
|
2019-06-10 01:09:00 +00:00
|
|
|
|
} else {
|
2024-05-22 21:01:02 +00:00
|
|
|
|
int offset = line.FileOffset;
|
2019-08-29 20:32:45 +00:00
|
|
|
|
if (offset < 0) {
|
|
|
|
|
// EQU in header
|
|
|
|
|
int index = LineListGen.DefSymIndexFromOffset(offset);
|
|
|
|
|
DefSymbol defSym = mProject.ActiveDefSymbolList[index];
|
|
|
|
|
xrefs = defSym.Xrefs;
|
|
|
|
|
} else {
|
|
|
|
|
xrefs = mProject.GetXrefSet(offset);
|
|
|
|
|
}
|
2019-06-10 01:09:00 +00:00
|
|
|
|
}
|
|
|
|
|
if (xrefs == null || xrefs.Count == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(someday): localization
|
2019-12-30 01:59:35 +00:00
|
|
|
|
Asm65.Formatter formatter = mFormatter;
|
2019-06-10 01:09:00 +00:00
|
|
|
|
bool showBank = !mProject.CpuDef.HasAddr16;
|
|
|
|
|
for (int i = 0; i < xrefs.Count; i++) {
|
|
|
|
|
XrefSet.Xref xr = xrefs[i];
|
|
|
|
|
|
2020-05-02 21:09:53 +00:00
|
|
|
|
string idxStr = string.Empty;
|
2019-06-10 01:09:00 +00:00
|
|
|
|
string typeStr;
|
|
|
|
|
switch (xr.Type) {
|
|
|
|
|
case XrefSet.XrefType.SubCallOp:
|
|
|
|
|
typeStr = "call ";
|
|
|
|
|
break;
|
|
|
|
|
case XrefSet.XrefType.BranchOp:
|
|
|
|
|
typeStr = "branch ";
|
|
|
|
|
break;
|
|
|
|
|
case XrefSet.XrefType.RefFromData:
|
|
|
|
|
typeStr = "data ";
|
|
|
|
|
break;
|
|
|
|
|
case XrefSet.XrefType.MemAccessOp:
|
|
|
|
|
switch (xr.AccType) {
|
|
|
|
|
case OpDef.MemoryEffect.Read:
|
|
|
|
|
typeStr = "read ";
|
|
|
|
|
break;
|
|
|
|
|
case OpDef.MemoryEffect.Write:
|
|
|
|
|
typeStr = "write ";
|
|
|
|
|
break;
|
|
|
|
|
case OpDef.MemoryEffect.ReadModifyWrite:
|
|
|
|
|
typeStr = "rmw ";
|
|
|
|
|
break;
|
|
|
|
|
case OpDef.MemoryEffect.None: // e.g. LDA #<symbol, PEA addr
|
|
|
|
|
typeStr = "ref ";
|
|
|
|
|
break;
|
|
|
|
|
case OpDef.MemoryEffect.Unknown:
|
|
|
|
|
default:
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
typeStr = "??! ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
typeStr = "??? ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:26:41 +00:00
|
|
|
|
// "LDA (dp,X)" gets both of these
|
|
|
|
|
if (xr.IsIndexedAccess) {
|
|
|
|
|
idxStr += "idx ";
|
|
|
|
|
}
|
|
|
|
|
if (xr.IsPointerAccess) {
|
|
|
|
|
idxStr += "ptr ";
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
MainWindow.ReferencesListItem rli = new MainWindow.ReferencesListItem(xr.Offset,
|
2019-06-10 01:09:00 +00:00
|
|
|
|
formatter.FormatOffset24(xr.Offset),
|
|
|
|
|
formatter.FormatAddress(mProject.GetAnattrib(xr.Offset).Address, showBank),
|
2020-05-02 21:09:53 +00:00
|
|
|
|
(xr.IsByName ? "Sym " : "Oth ") + typeStr + idxStr +
|
2019-06-10 01:09:00 +00:00
|
|
|
|
formatter.FormatAdjustment(-xr.Adjustment));
|
|
|
|
|
|
|
|
|
|
mMainWin.ReferencesList.Add(rli);
|
|
|
|
|
}
|
2020-09-04 20:26:41 +00:00
|
|
|
|
|
|
|
|
|
// TODO(maybe): set the selection to something, instead of just inheriting it?
|
2019-06-10 01:09:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion References panel
|
|
|
|
|
|
2019-06-12 22:54:22 +00:00
|
|
|
|
#region Notes panel
|
|
|
|
|
|
|
|
|
|
private void PopulateNotesList() {
|
|
|
|
|
mMainWin.NotesList.Clear();
|
|
|
|
|
foreach (KeyValuePair<int, MultiLineComment> kvp in mProject.Notes) {
|
|
|
|
|
int offset = kvp.Key;
|
|
|
|
|
MultiLineComment mlc = kvp.Value;
|
|
|
|
|
|
|
|
|
|
// Replace line break with bullet. If there's a single CRLF at the end, strip it.
|
|
|
|
|
string nocrlfStr;
|
|
|
|
|
if (mlc.Text.EndsWith("\r\n")) {
|
2019-06-15 23:00:31 +00:00
|
|
|
|
nocrlfStr =
|
|
|
|
|
mlc.Text.Substring(0, mlc.Text.Length - 2).Replace("\r\n", " \u2022 ");
|
2019-06-12 22:54:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
nocrlfStr = mlc.Text.Replace("\r\n", " \u2022 ");
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
MainWindow.NotesListItem nli = new MainWindow.NotesListItem(offset,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatter.FormatOffset24(offset),
|
2019-06-12 22:54:22 +00:00
|
|
|
|
nocrlfStr,
|
|
|
|
|
mlc.BackgroundColor);
|
|
|
|
|
mMainWin.NotesList.Add(nli);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Notes panel
|
|
|
|
|
|
2019-06-12 21:17:24 +00:00
|
|
|
|
#region Symbols panel
|
|
|
|
|
|
2019-11-13 01:24:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Populates the ItemsSource for the Symbols window. Each entry in the project
|
|
|
|
|
/// symbol table is added.
|
|
|
|
|
/// </summary>
|
2019-06-12 21:17:24 +00:00
|
|
|
|
private void PopulateSymbolsList() {
|
|
|
|
|
mMainWin.SymbolsList.Clear();
|
|
|
|
|
foreach (Symbol sym in mProject.SymbolTable) {
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
string valueStr;
|
|
|
|
|
if (sym.SymbolSource == Symbol.Source.User && sym.Value == Address.NON_ADDR) {
|
|
|
|
|
valueStr = Address.NON_ADDR_STR;
|
|
|
|
|
} else {
|
|
|
|
|
valueStr = mFormatter.FormatHexValue(sym.Value, 0);
|
|
|
|
|
}
|
2019-10-15 23:37:14 +00:00
|
|
|
|
string sourceTypeStr = sym.SourceTypeString;
|
|
|
|
|
if (sym is DefSymbol) {
|
|
|
|
|
DefSymbol defSym = (DefSymbol)sym;
|
|
|
|
|
if (defSym.MultiMask != null) {
|
|
|
|
|
valueStr += " & " +
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mFormatter.FormatHexValue(defSym.MultiMask.AddressMask, 4);
|
2019-10-15 23:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
if (defSym.Direction == DefSymbol.DirectionFlags.Read) {
|
|
|
|
|
sourceTypeStr += '<';
|
|
|
|
|
} else if (defSym.Direction == DefSymbol.DirectionFlags.Write) {
|
|
|
|
|
sourceTypeStr += '>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 21:17:24 +00:00
|
|
|
|
MainWindow.SymbolsListItem sli = new MainWindow.SymbolsListItem(sym,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
sourceTypeStr, valueStr, sym.GenerateDisplayLabel(mFormatter));
|
2019-06-12 21:17:24 +00:00
|
|
|
|
mMainWin.SymbolsList.Add(sli);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Symbols panel
|
|
|
|
|
|
2019-06-09 21:24:46 +00:00
|
|
|
|
#region Info panel
|
|
|
|
|
|
|
|
|
|
private void UpdateInfoPanel() {
|
2021-09-27 00:06:43 +00:00
|
|
|
|
const string CRLF = "\r\n";
|
|
|
|
|
|
2019-10-23 04:27:49 +00:00
|
|
|
|
mMainWin.ClearInfoPanel();
|
2021-10-11 21:44:44 +00:00
|
|
|
|
int selCount = mMainWin.CodeListView_GetSelectionCount();
|
|
|
|
|
if (selCount < 1) {
|
|
|
|
|
// Nothing selected.
|
|
|
|
|
return;
|
|
|
|
|
} else if (selCount > 1) {
|
|
|
|
|
// Multiple lines selected.
|
|
|
|
|
mMainWin.InfoLineDescrText = string.Format(Res.Strings.INFO_MULTI_LINE_SUM_FMT,
|
|
|
|
|
selCount);
|
|
|
|
|
|
|
|
|
|
int firstIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
|
|
|
|
int lastIndex = mMainWin.CodeListView_GetLastSelectedIndex();
|
|
|
|
|
int firstOffset = CodeLineList[firstIndex].FileOffset;
|
|
|
|
|
int nextOffset = CodeLineList[lastIndex].FileOffset +
|
|
|
|
|
CodeLineList[lastIndex].OffsetSpan;
|
|
|
|
|
if (firstOffset == nextOffset) {
|
|
|
|
|
return; // probably selected a bunch of lines from a long comment or note
|
|
|
|
|
}
|
|
|
|
|
if (firstOffset < 0 || nextOffset < 0) {
|
|
|
|
|
// We're in the header comment or .equ area.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (CodeLineList[lastIndex].LineType == LineListGen.Line.Type.ArEndDirective) {
|
|
|
|
|
nextOffset++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder msb = new StringBuilder();
|
|
|
|
|
msb.AppendFormat(Res.Strings.INFO_MULTI_LINE_START_FMT, firstIndex,
|
|
|
|
|
mFormatter.FormatOffset24(firstOffset));
|
|
|
|
|
msb.Append(CRLF);
|
|
|
|
|
msb.AppendFormat(Res.Strings.INFO_MULTI_LINE_END_FMT, lastIndex,
|
|
|
|
|
mFormatter.FormatOffset24(nextOffset - 1));
|
|
|
|
|
msb.Append(CRLF);
|
|
|
|
|
int len = nextOffset - firstOffset;
|
|
|
|
|
string lenStr = len.ToString() + " (" + mFormatter.FormatHexValue(len, 2) + ")";
|
|
|
|
|
msb.AppendFormat(Res.Strings.INFO_MULTI_LINE_LEN_FMT, lenStr);
|
|
|
|
|
mMainWin.InfoPanelDetail1 = msb.ToString();
|
2019-06-09 21:24:46 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-10-11 21:44:44 +00:00
|
|
|
|
|
2019-06-15 23:00:31 +00:00
|
|
|
|
int lineIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
|
2019-06-16 23:34:47 +00:00
|
|
|
|
LineListGen.Line line = CodeLineList[lineIndex];
|
2019-06-09 21:24:46 +00:00
|
|
|
|
|
|
|
|
|
// TODO(someday): this should be made easier to localize
|
2019-10-23 04:27:49 +00:00
|
|
|
|
string lineTypeStr = null;
|
|
|
|
|
bool isSimple = true;
|
|
|
|
|
DefSymbol defSym = null;
|
2019-06-09 21:24:46 +00:00
|
|
|
|
switch (line.LineType) {
|
|
|
|
|
case LineListGen.Line.Type.LongComment:
|
|
|
|
|
lineTypeStr = "comment";
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.Note:
|
|
|
|
|
lineTypeStr = "note";
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.Blank:
|
|
|
|
|
lineTypeStr = "blank line";
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.RegWidthDirective:
|
|
|
|
|
lineTypeStr = "register width directive";
|
|
|
|
|
break;
|
2020-07-09 22:17:47 +00:00
|
|
|
|
case LineListGen.Line.Type.DataBankDirective:
|
|
|
|
|
lineTypeStr = "data bank directive";
|
|
|
|
|
break;
|
2019-10-23 04:27:49 +00:00
|
|
|
|
|
2021-09-27 00:06:43 +00:00
|
|
|
|
case LineListGen.Line.Type.ArStartDirective:
|
|
|
|
|
isSimple = false;
|
ORG rework, part 5
Updated project file format to save the new map entries.
Tweaked appearance of .arend directives to show the .arstart address
in the operand field. This makes it easier to match them up on screen.
Also, add a synthetic comment on auto-generated .arstart entries.
Added .arstart/.arend to the things that respond to Jump to Operand
(Ctrl+J). Selecting one jumps to the other end. (Well, it jumps
to the code nearest the other, which will do for now.)
Added a menu item to display a text rendering of the address map.
Helpful when things get complicated.
Modified the linear map iterator to return .arend items with the offset
of the last byte in the region, rather than the first byte of the
following region. While the "exclusive end" approach is pretty
common, it caused problems when updating the line list, because it
meant that the .arend directives were outside the range of offsets
being updated (and, for directives at the end of the file, outside
the file itself). This was painful to deal with for partial updates.
Changing this required some relatively subtle changes and annoyed some
of the debug assertions, such as the one where all Line items have
offsets that match the start of a line, but it's the cleaner approach.
2021-09-28 00:02:18 +00:00
|
|
|
|
lineTypeStr = "address region start directive";
|
2021-09-27 00:06:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.ArEndDirective:
|
|
|
|
|
isSimple = false;
|
ORG rework, part 5
Updated project file format to save the new map entries.
Tweaked appearance of .arend directives to show the .arstart address
in the operand field. This makes it easier to match them up on screen.
Also, add a synthetic comment on auto-generated .arstart entries.
Added .arstart/.arend to the things that respond to Jump to Operand
(Ctrl+J). Selecting one jumps to the other end. (Well, it jumps
to the code nearest the other, which will do for now.)
Added a menu item to display a text rendering of the address map.
Helpful when things get complicated.
Modified the linear map iterator to return .arend items with the offset
of the last byte in the region, rather than the first byte of the
following region. While the "exclusive end" approach is pretty
common, it caused problems when updating the line list, because it
meant that the .arend directives were outside the range of offsets
being updated (and, for directives at the end of the file, outside
the file itself). This was painful to deal with for partial updates.
Changing this required some relatively subtle changes and annoyed some
of the debug assertions, such as the one where all Line items have
offsets that match the start of a line, but it's the cleaner approach.
2021-09-28 00:02:18 +00:00
|
|
|
|
lineTypeStr = "address region end directive";
|
2021-09-27 00:06:43 +00:00
|
|
|
|
break;
|
2019-08-27 23:45:37 +00:00
|
|
|
|
case LineListGen.Line.Type.LocalVariableTable:
|
2019-10-23 04:27:49 +00:00
|
|
|
|
isSimple = false;
|
2019-08-27 23:45:37 +00:00
|
|
|
|
lineTypeStr = "variable table";
|
2019-10-23 04:27:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.Code:
|
|
|
|
|
isSimple = false;
|
|
|
|
|
lineTypeStr = "code";
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.Data:
|
|
|
|
|
isSimple = false;
|
|
|
|
|
if (mProject.GetAnattrib(line.FileOffset).IsInlineData) {
|
|
|
|
|
lineTypeStr = "inline data";
|
|
|
|
|
} else {
|
|
|
|
|
lineTypeStr = "data";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LineListGen.Line.Type.EquDirective:
|
|
|
|
|
isSimple = false;
|
|
|
|
|
int defSymIndex = LineListGen.DefSymIndexFromOffset(line.FileOffset);
|
|
|
|
|
defSym = mProject.ActiveDefSymbolList[defSymIndex];
|
|
|
|
|
if (defSym.SymbolSource == Symbol.Source.Project) {
|
|
|
|
|
lineTypeStr = "project symbol equate";
|
|
|
|
|
} else if (defSym.SymbolSource == Symbol.Source.Platform) {
|
|
|
|
|
lineTypeStr = "platform symbol equate";
|
|
|
|
|
} else {
|
|
|
|
|
lineTypeStr = "???";
|
2019-08-27 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2019-11-23 04:45:57 +00:00
|
|
|
|
case LineListGen.Line.Type.VisualizationSet:
|
|
|
|
|
lineTypeStr = "visualization set";
|
|
|
|
|
break;
|
2019-06-09 21:24:46 +00:00
|
|
|
|
default:
|
|
|
|
|
lineTypeStr = "???";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-23 04:27:49 +00:00
|
|
|
|
if (line.IsCodeOrData) {
|
|
|
|
|
// Show number of bytes of code/data.
|
|
|
|
|
if (line.OffsetSpan == 1) {
|
Label rework, part 6
Correct handling of local variables. We now correctly uniquify them
with regard to non-unique labels. Because local vars can effectively
have global scope we mostly want to treat them as global, but they're
uniquified relative to other globals very late in the process, so we
can't just throw them in the symbol table and be done. Fortunately
local variables exist in a separate namespace, so we just need to
uniquify the variables relative to the post-localization symbol table.
In other words, we take the symbol table, apply the label map, and
rename any variable that clashes.
This also fixes an older problem where we weren't masking the
leading '_' on variable labels when generating 64tass output.
The code list now makes non-unique labels obvious, but you can't tell
the difference between unique global and unique local. What's more,
the default type value in Edit Label is now adjusted to Global for
unique locals that were auto-generated. To make it a bit easier to
figure out what's what, the Info panel now has a "label type" line
that reports the type.
The 2023-non-unique-labels test had some additional tests added to
exercise conflicts with local variables. The 2019-local-variables
test output changed slightly because the de-duplicated variable
naming convention was simplified.
2019-11-18 21:26:03 +00:00
|
|
|
|
mMainWin.InfoLineDescrText =
|
|
|
|
|
string.Format(Res.Strings.INFO_LINE_SUM_SINGULAR_FMT,
|
|
|
|
|
lineIndex, line.OffsetSpan, lineTypeStr);
|
2019-10-23 04:27:49 +00:00
|
|
|
|
} else {
|
Label rework, part 6
Correct handling of local variables. We now correctly uniquify them
with regard to non-unique labels. Because local vars can effectively
have global scope we mostly want to treat them as global, but they're
uniquified relative to other globals very late in the process, so we
can't just throw them in the symbol table and be done. Fortunately
local variables exist in a separate namespace, so we just need to
uniquify the variables relative to the post-localization symbol table.
In other words, we take the symbol table, apply the label map, and
rename any variable that clashes.
This also fixes an older problem where we weren't masking the
leading '_' on variable labels when generating 64tass output.
The code list now makes non-unique labels obvious, but you can't tell
the difference between unique global and unique local. What's more,
the default type value in Edit Label is now adjusted to Global for
unique locals that were auto-generated. To make it a bit easier to
figure out what's what, the Info panel now has a "label type" line
that reports the type.
The 2023-non-unique-labels test had some additional tests added to
exercise conflicts with local variables. The 2019-local-variables
test output changed slightly because the de-duplicated variable
naming convention was simplified.
2019-11-18 21:26:03 +00:00
|
|
|
|
mMainWin.InfoLineDescrText =
|
|
|
|
|
string.Format(Res.Strings.INFO_LINE_SUM_PLURAL_FMT,
|
|
|
|
|
lineIndex, line.OffsetSpan, lineTypeStr);
|
2019-10-23 04:27:49 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mMainWin.InfoLineDescrText = string.Format(Res.Strings.INFO_LINE_SUM_NON_FMT,
|
2019-06-09 21:24:46 +00:00
|
|
|
|
lineIndex, lineTypeStr);
|
2019-10-23 04:27:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-09 21:24:46 +00:00
|
|
|
|
#if DEBUG
|
2021-09-27 00:06:43 +00:00
|
|
|
|
mMainWin.InfoOffsetText = "[offset=+" + line.FileOffset.ToString("x6") +
|
|
|
|
|
" sub=" + line.SubLineIndex + "]";
|
2019-06-09 21:24:46 +00:00
|
|
|
|
#endif
|
2019-10-23 04:27:49 +00:00
|
|
|
|
if (isSimple) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 00:06:43 +00:00
|
|
|
|
if (line.LineType == LineListGen.Line.Type.ArStartDirective ||
|
|
|
|
|
line.LineType == LineListGen.Line.Type.ArEndDirective) {
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
AddressMap.AddressRegion region = CodeLineList.GetAddrRegionFromLine(line,
|
|
|
|
|
out bool isSynth);
|
|
|
|
|
if (region == null) {
|
|
|
|
|
Debug.Assert(false, "Unable to find region at: " + line);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-27 00:06:43 +00:00
|
|
|
|
StringBuilder esb = new StringBuilder();
|
|
|
|
|
esb.Append("Address: ");
|
ORG rework, part 6
Added support for non-addressable regions, which are useful for things
like file headers stripped out by the system loader, or chunks that
get loaded into non-addressable graphics RAM. Regions are specified
with the "NA" address value. The code list displays the address field
greyed out, starting from zero (which is kind of handy if you want to
know the relative offset within the region).
Putting labels in non-addressable regions doesn't make sense, but
symbol resolution is complicated enough that we really only have two
options: ignore the labels entirely, or allow them but warn of their
presence. The problem isn't so much the label, which you could
legitimately want to access from an extension script, but rather the
references to them from code or data. So we keep the label and add a
warning to the Messages list when we see a reference.
Moved NON_ADDR constants to Address class. AddressMap now has a copy.
This is awkward because Asm65 and CommonUtil don't share.
Updated the asm code generators to understand NON_ADDR, and reworked
the API so that Merlin and cc65 output is correct for nested regions.
Address region changes are now noted in the anattribs array, which
makes certain operations faster than checking the address map. It
also fixes a failure to recognize mid-instruction region changes in
the code analyzer.
Tweaked handling of synthetic regions, which are non-addressable areas
generated by the linear address map traversal to fill in any "holes".
The address region editor now treats attempts to edit them as
creation of a new region.
2021-10-01 01:07:21 +00:00
|
|
|
|
if (region.Address == Address.NON_ADDR) {
|
2021-09-27 00:06:43 +00:00
|
|
|
|
esb.Append("non-addressable");
|
|
|
|
|
} else {
|
|
|
|
|
esb.Append("$" +
|
|
|
|
|
mFormatter.FormatAddress(region.Address, !mProject.CpuDef.HasAddr16));
|
|
|
|
|
}
|
|
|
|
|
esb.Append(CRLF);
|
|
|
|
|
esb.Append("Start: " + mFormatter.FormatOffset24(region.Offset));
|
|
|
|
|
esb.Append(CRLF);
|
|
|
|
|
esb.Append("End: ");
|
|
|
|
|
esb.Append(mFormatter.FormatOffset24(region.Offset + region.ActualLength - 1));
|
|
|
|
|
esb.Append(CRLF);
|
2021-10-20 16:06:53 +00:00
|
|
|
|
esb.Append("Length: " + region.ActualLength + " (" +
|
|
|
|
|
mFormatter.FormatHexValue(region.ActualLength, 2) + ")");
|
2021-09-27 00:06:43 +00:00
|
|
|
|
if (region.Length == AddressMap.FLOATING_LEN) {
|
2021-10-20 16:06:53 +00:00
|
|
|
|
esb.Append(" [floating]");
|
2021-09-27 00:06:43 +00:00
|
|
|
|
}
|
|
|
|
|
esb.Append(CRLF);
|
2021-10-07 19:39:08 +00:00
|
|
|
|
esb.Append("Pre-label: ");
|
2021-09-27 00:06:43 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(region.PreLabel)) {
|
2021-10-07 19:39:08 +00:00
|
|
|
|
esb.Append("'");
|
|
|
|
|
esb.Append(region.PreLabel);
|
|
|
|
|
if (region.PreLabelAddress == Address.NON_ADDR) {
|
|
|
|
|
esb.Append("' (non-addressable)");
|
|
|
|
|
} else {
|
|
|
|
|
esb.Append("' addr=$");
|
|
|
|
|
esb.Append(mFormatter.FormatAddress(region.PreLabelAddress,
|
|
|
|
|
!mProject.CpuDef.HasAddr16));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2021-10-20 16:06:53 +00:00
|
|
|
|
esb.Append("(not set)");
|
2021-09-27 00:06:43 +00:00
|
|
|
|
}
|
2021-10-07 19:39:08 +00:00
|
|
|
|
esb.Append(CRLF);
|
|
|
|
|
esb.Append("Synthetic: " + isSynth);
|
|
|
|
|
esb.Append(CRLF);
|
2021-09-27 00:06:43 +00:00
|
|
|
|
esb.Append("Relative: " + region.IsRelative);
|
|
|
|
|
esb.Append(CRLF);
|
|
|
|
|
mMainWin.InfoPanelDetail1 = esb.ToString();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-23 04:27:49 +00:00
|
|
|
|
if (line.LineType == LineListGen.Line.Type.LocalVariableTable) {
|
|
|
|
|
string str = string.Empty;
|
|
|
|
|
if (mProject.LvTables.TryGetValue(line.FileOffset,
|
|
|
|
|
out LocalVariableTable lvt)) {
|
Label rework, part 6
Correct handling of local variables. We now correctly uniquify them
with regard to non-unique labels. Because local vars can effectively
have global scope we mostly want to treat them as global, but they're
uniquified relative to other globals very late in the process, so we
can't just throw them in the symbol table and be done. Fortunately
local variables exist in a separate namespace, so we just need to
uniquify the variables relative to the post-localization symbol table.
In other words, we take the symbol table, apply the label map, and
rename any variable that clashes.
This also fixes an older problem where we weren't masking the
leading '_' on variable labels when generating 64tass output.
The code list now makes non-unique labels obvious, but you can't tell
the difference between unique global and unique local. What's more,
the default type value in Edit Label is now adjusted to Global for
unique locals that were auto-generated. To make it a bit easier to
figure out what's what, the Info panel now has a "label type" line
that reports the type.
The 2023-non-unique-labels test had some additional tests added to
exercise conflicts with local variables. The 2019-local-variables
test output changed slightly because the de-duplicated variable
naming convention was simplified.
2019-11-18 21:26:03 +00:00
|
|
|
|
if (lvt.Count == 1) {
|
|
|
|
|
str = "1 entry";
|
|
|
|
|
} else {
|
|
|
|
|
str = lvt.Count + " entries";
|
|
|
|
|
}
|
2019-10-23 04:27:49 +00:00
|
|
|
|
if (lvt.ClearPrevious) {
|
|
|
|
|
str += "; clear previous";
|
|
|
|
|
}
|
2019-06-09 21:24:46 +00:00
|
|
|
|
}
|
2019-10-23 04:27:49 +00:00
|
|
|
|
mMainWin.InfoPanelDetail1 = str;
|
2019-06-09 21:24:46 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-23 04:27:49 +00:00
|
|
|
|
if (line.LineType == LineListGen.Line.Type.EquDirective) {
|
|
|
|
|
StringBuilder esb = new StringBuilder();
|
|
|
|
|
//esb.Append("\u25b6 ");
|
|
|
|
|
esb.Append("\u2022 ");
|
|
|
|
|
if (defSym.IsConstant) {
|
|
|
|
|
esb.Append("Constant");
|
|
|
|
|
} else {
|
|
|
|
|
esb.Append("External address");
|
|
|
|
|
if (defSym.HasWidth) {
|
|
|
|
|
esb.Append(", width=");
|
|
|
|
|
esb.Append(defSym.DataDescriptor.Length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (defSym.Direction != DefSymbol.DirectionFlags.ReadWrite) {
|
|
|
|
|
esb.Append("\r\nI/O direction: ");
|
|
|
|
|
esb.Append(defSym.Direction);
|
|
|
|
|
}
|
|
|
|
|
if (defSym.MultiMask != null) {
|
|
|
|
|
esb.Append("\r\nMulti-mask:");
|
|
|
|
|
int i = 23;
|
|
|
|
|
if ((defSym.MultiMask.AddressMask | defSym.MultiMask.CompareMask |
|
|
|
|
|
defSym.MultiMask.CompareValue) < 0x10000) {
|
|
|
|
|
i = 15;
|
|
|
|
|
}
|
|
|
|
|
for ( ; i >= 0; i--) {
|
|
|
|
|
if ((i & 3) == 3) {
|
|
|
|
|
esb.Append(' ');
|
|
|
|
|
}
|
|
|
|
|
int bit = 1 << i;
|
|
|
|
|
if ((defSym.MultiMask.AddressMask & bit) != 0) {
|
|
|
|
|
esb.Append('x');
|
|
|
|
|
} else if ((defSym.MultiMask.CompareMask & bit) != 0) {
|
|
|
|
|
if ((defSym.MultiMask.CompareValue & bit) != 0) {
|
|
|
|
|
esb.Append('1');
|
|
|
|
|
} else {
|
|
|
|
|
esb.Append('0');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
esb.Append('?');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (defSym.SymbolSource == Symbol.Source.Platform) {
|
|
|
|
|
esb.Append("\r\n\r\nSource file # ");
|
|
|
|
|
esb.Append(defSym.LoadOrdinal);
|
|
|
|
|
esb.Append(": ");
|
|
|
|
|
esb.Append(defSym.FileIdentifier);
|
2019-06-09 21:24:46 +00:00
|
|
|
|
|
2019-10-23 04:27:49 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(defSym.Tag)) {
|
|
|
|
|
esb.Append(", tag=");
|
|
|
|
|
esb.Append(defSym.Tag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mMainWin.InfoPanelDetail1 = esb.ToString();
|
|
|
|
|
return;
|
2019-06-09 21:24:46 +00:00
|
|
|
|
}
|
2019-10-23 04:27:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Handle code/data items. In particular, the format descriptor.
|
|
|
|
|
//
|
|
|
|
|
Debug.Assert(line.IsCodeOrData);
|
|
|
|
|
bool isCode = (line.LineType == LineListGen.Line.Type.Code);
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(250);
|
|
|
|
|
Anattrib attr = mProject.GetAnattrib(line.FileOffset);
|
2019-06-09 21:24:46 +00:00
|
|
|
|
|
Label rework, part 6
Correct handling of local variables. We now correctly uniquify them
with regard to non-unique labels. Because local vars can effectively
have global scope we mostly want to treat them as global, but they're
uniquified relative to other globals very late in the process, so we
can't just throw them in the symbol table and be done. Fortunately
local variables exist in a separate namespace, so we just need to
uniquify the variables relative to the post-localization symbol table.
In other words, we take the symbol table, apply the label map, and
rename any variable that clashes.
This also fixes an older problem where we weren't masking the
leading '_' on variable labels when generating 64tass output.
The code list now makes non-unique labels obvious, but you can't tell
the difference between unique global and unique local. What's more,
the default type value in Edit Label is now adjusted to Global for
unique locals that were auto-generated. To make it a bit easier to
figure out what's what, the Info panel now has a "label type" line
that reports the type.
The 2023-non-unique-labels test had some additional tests added to
exercise conflicts with local variables. The 2019-local-variables
test output changed slightly because the de-duplicated variable
naming convention was simplified.
2019-11-18 21:26:03 +00:00
|
|
|
|
if (attr.Symbol != null) {
|
|
|
|
|
string descr;
|
|
|
|
|
switch (attr.Symbol.SymbolType) {
|
|
|
|
|
case Symbol.Type.NonUniqueLocalAddr:
|
|
|
|
|
descr = "non-unique local";
|
|
|
|
|
break;
|
|
|
|
|
case Symbol.Type.LocalOrGlobalAddr:
|
|
|
|
|
descr = "unique local";
|
|
|
|
|
break;
|
|
|
|
|
case Symbol.Type.GlobalAddr:
|
|
|
|
|
descr = "unique global";
|
|
|
|
|
break;
|
|
|
|
|
case Symbol.Type.GlobalAddrExport:
|
|
|
|
|
descr = "global + marked for export";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
descr = "???";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (attr.Symbol.SymbolSource == Symbol.Source.Auto) {
|
|
|
|
|
descr += ", auto-generated";
|
|
|
|
|
} else if (attr.Symbol.LabelAnno == Symbol.LabelAnnotation.Generated) {
|
|
|
|
|
descr += " [gen]";
|
|
|
|
|
}
|
|
|
|
|
mMainWin.InfoLabelDescrText =
|
|
|
|
|
string.Format(Res.Strings.INFO_LABEL_DESCR_FMT, descr);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-09 21:24:46 +00:00
|
|
|
|
if (!mProject.OperandFormats.TryGetValue(line.FileOffset, out FormatDescriptor dfd)) {
|
|
|
|
|
// No user-specified format, but there may be a generated format.
|
2019-10-23 04:27:49 +00:00
|
|
|
|
mMainWin.InfoFormatBoxBrush = Brushes.Blue;
|
2019-06-09 21:24:46 +00:00
|
|
|
|
if (attr.DataDescriptor != null) {
|
2019-10-23 04:27:49 +00:00
|
|
|
|
mMainWin.InfoFormatShowSolid = true;
|
|
|
|
|
sb.Append(Res.Strings.INFO_AUTO_FORMAT);
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
sb.Append(attr.DataDescriptor.ToUiString(!isCode));
|
|
|
|
|
} else {
|
|
|
|
|
mMainWin.InfoFormatShowDashes = true;
|
|
|
|
|
sb.AppendFormat(Res.Strings.INFO_DEFAULT_FORMAT);
|
2019-06-09 21:24:46 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// User-specified operand format.
|
2019-10-23 04:27:49 +00:00
|
|
|
|
mMainWin.InfoFormatBoxBrush = Brushes.Green;
|
|
|
|
|
mMainWin.InfoFormatShowSolid = true;
|
|
|
|
|
sb.Append(Res.Strings.INFO_CUSTOM_FORMAT);
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
sb.Append(dfd.ToUiString(!isCode));
|
2019-06-09 21:24:46 +00:00
|
|
|
|
}
|
2019-10-23 04:27:49 +00:00
|
|
|
|
mMainWin.InfoFormatText = sb.ToString();
|
|
|
|
|
|
|
|
|
|
sb.Clear();
|
2019-06-09 21:24:46 +00:00
|
|
|
|
|
|
|
|
|
// Debug only
|
|
|
|
|
//sb.Append("DEBUG: opAddr=" + attr.OperandAddress.ToString("x4") +
|
|
|
|
|
// " opOff=" + attr.OperandOffset.ToString("x4") + "\r\n");
|
|
|
|
|
|
2021-10-27 21:18:52 +00:00
|
|
|
|
if (attr.NoContinueScript) {
|
|
|
|
|
sb.AppendLine("\"No-continue\" flag set by script");
|
|
|
|
|
}
|
2020-10-15 21:03:32 +00:00
|
|
|
|
if (attr.HasAnalyzerTag) {
|
2020-10-14 22:02:53 +00:00
|
|
|
|
sb.Append("\u2022 Analyzer Tags: ");
|
2019-06-09 21:24:46 +00:00
|
|
|
|
for (int i = 0; i < line.OffsetSpan; i++) {
|
2020-10-15 21:03:32 +00:00
|
|
|
|
switch (mProject.AnalyzerTags[line.FileOffset + i]) {
|
|
|
|
|
case CodeAnalysis.AnalyzerTag.Code:
|
2020-10-14 22:02:53 +00:00
|
|
|
|
sb.Append("S"); // S)tart
|
2019-06-09 21:24:46 +00:00
|
|
|
|
break;
|
2020-10-15 21:03:32 +00:00
|
|
|
|
case CodeAnalysis.AnalyzerTag.Data:
|
2020-10-14 22:02:53 +00:00
|
|
|
|
sb.Append("E"); // E)nd
|
2019-06-09 21:24:46 +00:00
|
|
|
|
break;
|
2020-10-15 21:03:32 +00:00
|
|
|
|
case CodeAnalysis.AnalyzerTag.InlineData:
|
2020-10-14 22:02:53 +00:00
|
|
|
|
sb.Append("I"); // I)nline
|
2019-06-09 21:24:46 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i > 8) {
|
|
|
|
|
sb.Append("...");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-23 04:27:49 +00:00
|
|
|
|
sb.Append("\r\n");
|
2019-06-09 21:24:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attr.IsInstruction) {
|
2019-10-23 04:27:49 +00:00
|
|
|
|
sb.Append("\r\n");
|
|
|
|
|
|
2019-06-09 21:24:46 +00:00
|
|
|
|
Asm65.OpDef op = mProject.CpuDef.GetOpDef(mProject.FileData[line.FileOffset]);
|
|
|
|
|
|
|
|
|
|
string shortDesc = mOpDesc.GetShortDescription(op.Mnemonic);
|
|
|
|
|
if (!string.IsNullOrEmpty(shortDesc)) {
|
|
|
|
|
if (op.IsUndocumented) {
|
|
|
|
|
sb.Append("\u25b6[*] ");
|
|
|
|
|
} else {
|
|
|
|
|
sb.Append("\u25b6 ");
|
|
|
|
|
}
|
|
|
|
|
sb.Append(shortDesc);
|
|
|
|
|
string addrStr = mOpDesc.GetAddressModeDescription(op.AddrMode);
|
|
|
|
|
if (!string.IsNullOrEmpty(addrStr)) {
|
|
|
|
|
sb.Append(", ");
|
|
|
|
|
sb.Append(addrStr);
|
|
|
|
|
}
|
|
|
|
|
sb.Append("\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sb.Append("\u2022Cycles: ");
|
|
|
|
|
int cycles = op.Cycles;
|
|
|
|
|
sb.Append(cycles.ToString());
|
2019-10-23 04:27:49 +00:00
|
|
|
|
|
|
|
|
|
OpDef.CycleMod allMods = op.CycleMods;
|
|
|
|
|
OpDef.CycleMod nowMods =
|
|
|
|
|
mProject.CpuDef.GetOpCycleMod(mProject.FileData[line.FileOffset]);
|
|
|
|
|
if (allMods != 0) {
|
|
|
|
|
StringBuilder nowSb = new StringBuilder();
|
|
|
|
|
StringBuilder otherSb = new StringBuilder();
|
|
|
|
|
int workBits = (int)allMods;
|
2019-06-09 21:24:46 +00:00
|
|
|
|
while (workBits != 0) {
|
|
|
|
|
// Isolate rightmost bit.
|
|
|
|
|
int firstBit = (~workBits + 1) & workBits;
|
2019-10-23 04:27:49 +00:00
|
|
|
|
|
|
|
|
|
string desc = mOpDesc.GetCycleModDescription((OpDef.CycleMod)firstBit);
|
|
|
|
|
if (((int)nowMods & firstBit) != 0) {
|
|
|
|
|
if (nowSb.Length != 0) {
|
|
|
|
|
nowSb.Append(", ");
|
|
|
|
|
}
|
|
|
|
|
nowSb.Append(desc);
|
|
|
|
|
} else {
|
|
|
|
|
if (otherSb.Length != 0) {
|
|
|
|
|
otherSb.Append(", ");
|
|
|
|
|
}
|
|
|
|
|
otherSb.Append(desc);
|
|
|
|
|
}
|
2019-06-09 21:24:46 +00:00
|
|
|
|
// Remove from set.
|
|
|
|
|
workBits &= ~firstBit;
|
|
|
|
|
}
|
2019-10-23 04:27:49 +00:00
|
|
|
|
if (nowSb.Length != 0) {
|
|
|
|
|
sb.Append(" (");
|
|
|
|
|
sb.Append(nowSb);
|
|
|
|
|
sb.Append(")");
|
|
|
|
|
}
|
|
|
|
|
if (otherSb.Length != 0) {
|
|
|
|
|
sb.Append(" [");
|
|
|
|
|
sb.Append(otherSb);
|
|
|
|
|
sb.Append("]");
|
|
|
|
|
}
|
2019-06-09 21:24:46 +00:00
|
|
|
|
}
|
|
|
|
|
sb.Append("\r\n");
|
|
|
|
|
|
|
|
|
|
const string FLAGS = "NVMXDIZC";
|
|
|
|
|
sb.Append("\u2022Flags affected: ");
|
|
|
|
|
Asm65.StatusFlags affectedFlags = op.FlagsAffected;
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
|
if (affectedFlags.GetBit((StatusFlags.FlagBits)(7 - i)) >= 0) {
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
sb.Append(FLAGS[i]);
|
|
|
|
|
} else {
|
|
|
|
|
sb.Append(" -");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.Append("\r\n");
|
|
|
|
|
|
|
|
|
|
string longDesc = mOpDesc.GetLongDescription(op.Mnemonic);
|
|
|
|
|
if (!string.IsNullOrEmpty(longDesc)) {
|
|
|
|
|
sb.Append("\r\n");
|
|
|
|
|
sb.Append(longDesc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Publish
|
2019-10-23 04:27:49 +00:00
|
|
|
|
mMainWin.InfoPanelDetail1 = sb.ToString();
|
2019-06-09 21:24:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Info panel
|
2019-07-06 21:20:51 +00:00
|
|
|
|
|
2019-12-29 01:14:29 +00:00
|
|
|
|
#region Tools
|
|
|
|
|
|
2020-08-20 20:18:46 +00:00
|
|
|
|
public void ToggleApple2ScreenChart() {
|
|
|
|
|
if (mApple2ScreenChartDialog == null) {
|
|
|
|
|
// Create without owner so it doesn't have to be in front of main window.
|
|
|
|
|
mApple2ScreenChartDialog = new Tools.WpfGui.Apple2ScreenChart(null, mFormatter);
|
|
|
|
|
mApple2ScreenChartDialog.Closing += (sender, e) => {
|
|
|
|
|
Debug.WriteLine("Apple II screen chart closed");
|
|
|
|
|
mApple2ScreenChartDialog = null;
|
|
|
|
|
};
|
|
|
|
|
mApple2ScreenChartDialog.Show();
|
|
|
|
|
} else {
|
|
|
|
|
mApple2ScreenChartDialog.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 01:14:29 +00:00
|
|
|
|
public void ToggleAsciiChart() {
|
|
|
|
|
if (mAsciiChartDialog == null) {
|
|
|
|
|
// Create without owner so it doesn't have to be in front of main window.
|
|
|
|
|
mAsciiChartDialog = new Tools.WpfGui.AsciiChart(null);
|
|
|
|
|
mAsciiChartDialog.Closing += (sender, e) => {
|
|
|
|
|
Debug.WriteLine("ASCII chart closed");
|
|
|
|
|
mAsciiChartDialog = null;
|
|
|
|
|
};
|
|
|
|
|
mAsciiChartDialog.Show();
|
|
|
|
|
} else {
|
|
|
|
|
mAsciiChartDialog.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleInstructionChart() {
|
|
|
|
|
if (mInstructionChartDialog == null) {
|
|
|
|
|
// Create without owner so it doesn't have to be in front of main window.
|
2019-12-30 01:59:35 +00:00
|
|
|
|
mInstructionChartDialog = new Tools.WpfGui.InstructionChart(null, mFormatter);
|
2019-12-29 01:14:29 +00:00
|
|
|
|
mInstructionChartDialog.Closing += (sender, e) => {
|
|
|
|
|
Debug.WriteLine("Instruction chart closed");
|
|
|
|
|
mInstructionChartDialog = null;
|
|
|
|
|
};
|
|
|
|
|
mInstructionChartDialog.Show();
|
|
|
|
|
} else {
|
|
|
|
|
mInstructionChartDialog.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowFileHexDump() {
|
2020-07-09 00:56:27 +00:00
|
|
|
|
if (!OpenAnyFile(null, out string pathName)) {
|
2019-12-29 01:14:29 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-24 00:21:18 +00:00
|
|
|
|
FileInfo fi = new FileInfo(pathName);
|
2019-12-29 01:14:29 +00:00
|
|
|
|
if (fi.Length > Tools.WpfGui.HexDumpViewer.MAX_LENGTH) {
|
|
|
|
|
string msg = string.Format(Res.Strings.OPEN_DATA_TOO_LARGE_FMT,
|
|
|
|
|
fi.Length / 1024, Tools.WpfGui.HexDumpViewer.MAX_LENGTH / 1024);
|
|
|
|
|
MessageBox.Show(msg, Res.Strings.OPEN_DATA_FAIL_CAPTION,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
byte[] data;
|
|
|
|
|
try {
|
2020-06-24 00:21:18 +00:00
|
|
|
|
data = File.ReadAllBytes(pathName);
|
2019-12-29 01:14:29 +00:00
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
// not expecting this to happen
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the dialog without an owner, and add it to the "unowned" list.
|
|
|
|
|
Tools.WpfGui.HexDumpViewer dlg = new Tools.WpfGui.HexDumpViewer(null,
|
2019-12-30 01:59:35 +00:00
|
|
|
|
data, mFormatter);
|
2020-06-24 00:21:18 +00:00
|
|
|
|
dlg.SetFileName(Path.GetFileName(pathName));
|
2019-12-29 01:14:29 +00:00
|
|
|
|
dlg.Closing += (sender, e) => {
|
|
|
|
|
Debug.WriteLine("Window " + dlg + " closed, removing from unowned list");
|
|
|
|
|
mUnownedWindows.Remove(dlg);
|
|
|
|
|
};
|
|
|
|
|
mUnownedWindows.Add(dlg);
|
|
|
|
|
dlg.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ConcatenateFiles() {
|
|
|
|
|
Tools.WpfGui.FileConcatenator concat =
|
|
|
|
|
new Tools.WpfGui.FileConcatenator(this.mMainWin);
|
|
|
|
|
concat.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 01:59:35 +00:00
|
|
|
|
public void SliceFiles() {
|
2020-07-09 00:56:27 +00:00
|
|
|
|
if (!OpenAnyFile(null, out string pathName)) {
|
2019-12-30 01:59:35 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tools.WpfGui.FileSlicer slicer = new Tools.WpfGui.FileSlicer(this.mMainWin, pathName,
|
|
|
|
|
mFormatter);
|
|
|
|
|
slicer.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:21:18 +00:00
|
|
|
|
public void ConvertOmf() {
|
2020-07-09 00:56:27 +00:00
|
|
|
|
if (!OpenAnyFile(Res.Strings.OMF_SELECT_FILE, out string pathName)) {
|
2020-06-24 00:21:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load the file here, so basic problems like empty / oversized files can be
|
|
|
|
|
// reported immediately.
|
|
|
|
|
|
|
|
|
|
byte[] fileData = null;
|
|
|
|
|
using (FileStream fs = File.Open(pathName, FileMode.Open, FileAccess.Read)) {
|
|
|
|
|
string errMsg = null;
|
|
|
|
|
|
|
|
|
|
if (fs.Length == 0) {
|
|
|
|
|
errMsg = Res.Strings.OPEN_DATA_EMPTY;
|
|
|
|
|
} else if (fs.Length < Tools.Omf.OmfFile.MIN_FILE_SIZE) {
|
|
|
|
|
errMsg = string.Format(Res.Strings.OPEN_DATA_TOO_SMALL_FMT, fs.Length);
|
|
|
|
|
} else if (fs.Length > Tools.Omf.OmfFile.MAX_FILE_SIZE) {
|
|
|
|
|
errMsg = string.Format(Res.Strings.OPEN_DATA_TOO_LARGE_FMT,
|
|
|
|
|
fs.Length / 1024, Tools.Omf.OmfFile.MAX_FILE_SIZE / 1024);
|
|
|
|
|
}
|
|
|
|
|
if (errMsg == null) {
|
|
|
|
|
fileData = new byte[fs.Length];
|
|
|
|
|
int actual = fs.Read(fileData, 0, (int)fs.Length);
|
|
|
|
|
if (actual != fs.Length) {
|
|
|
|
|
errMsg = Res.Strings.OPEN_DATA_PARTIAL_READ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errMsg != null) {
|
|
|
|
|
MessageBox.Show(errMsg, Res.Strings.ERR_FILE_GENERIC_CAPTION,
|
|
|
|
|
MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tools.Omf.WpfGui.OmfViewer ov =
|
2020-06-26 23:58:42 +00:00
|
|
|
|
new Tools.Omf.WpfGui.OmfViewer(this.mMainWin, pathName, fileData, mFormatter);
|
2020-06-24 00:21:18 +00:00
|
|
|
|
ov.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 00:56:27 +00:00
|
|
|
|
private bool OpenAnyFile(string title, out string pathName) {
|
2020-06-24 00:21:18 +00:00
|
|
|
|
OpenFileDialog fileDlg = new OpenFileDialog() {
|
|
|
|
|
Filter = Res.Strings.FILE_FILTER_ALL,
|
|
|
|
|
FilterIndex = 1
|
|
|
|
|
};
|
2020-07-09 00:56:27 +00:00
|
|
|
|
if (title != null) {
|
|
|
|
|
fileDlg.Title = title;
|
|
|
|
|
}
|
2020-06-24 00:21:18 +00:00
|
|
|
|
if (fileDlg.ShowDialog() != true) {
|
|
|
|
|
pathName = null;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
pathName = Path.GetFullPath(fileDlg.FileName);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
ORG rework, part 5
Updated project file format to save the new map entries.
Tweaked appearance of .arend directives to show the .arstart address
in the operand field. This makes it easier to match them up on screen.
Also, add a synthetic comment on auto-generated .arstart entries.
Added .arstart/.arend to the things that respond to Jump to Operand
(Ctrl+J). Selecting one jumps to the other end. (Well, it jumps
to the code nearest the other, which will do for now.)
Added a menu item to display a text rendering of the address map.
Helpful when things get complicated.
Modified the linear map iterator to return .arend items with the offset
of the last byte in the region, rather than the first byte of the
following region. While the "exclusive end" approach is pretty
common, it caused problems when updating the line list, because it
meant that the .arend directives were outside the range of offsets
being updated (and, for directives at the end of the file, outside
the file itself). This was painful to deal with for partial updates.
Changing this required some relatively subtle changes and annoyed some
of the debug assertions, such as the one where all Line items have
offsets that match the start of a line, but it's the cleaner approach.
2021-09-28 00:02:18 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays a representation of the address map.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This is in the "tools" section, but it's not a tool. It's in the "navigation" menu
|
|
|
|
|
/// but has nothing to do with navigation. Bit of an oddball.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void ViewAddressMap() {
|
|
|
|
|
string mapStr = RenderAddressMap.GenerateString(mProject, mFormatter);
|
|
|
|
|
|
|
|
|
|
Tools.WpfGui.ShowText dlg = new Tools.WpfGui.ShowText(mMainWin, mapStr);
|
|
|
|
|
dlg.Title = "Address Map";
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 01:14:29 +00:00
|
|
|
|
#endregion Tools
|
|
|
|
|
|
2019-07-06 21:20:51 +00:00
|
|
|
|
#region Debug features
|
|
|
|
|
|
2024-07-06 21:54:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// If set, show rulers and visible spaces in long comments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal bool DebugLongComments { get; private set; } = false;
|
|
|
|
|
|
2019-07-15 23:50:54 +00:00
|
|
|
|
public void Debug_ExtensionScriptInfo() {
|
|
|
|
|
string info = mProject.DebugGetLoadedScriptInfo();
|
|
|
|
|
|
|
|
|
|
Tools.WpfGui.ShowText dlg = new Tools.WpfGui.ShowText(mMainWin, info);
|
|
|
|
|
dlg.Title = "Loaded Extension Script Info";
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-16 00:18:28 +00:00
|
|
|
|
public void Debug_ShowAnalysisTimers() {
|
|
|
|
|
if (mShowAnalysisTimersDialog == null) {
|
|
|
|
|
Tools.WpfGui.ShowText dlg = new Tools.WpfGui.ShowText(null, "(no data yet)");
|
|
|
|
|
dlg.Title = "Analysis Timers";
|
|
|
|
|
dlg.Closing += (sender, e) => {
|
|
|
|
|
Debug.WriteLine("Analysis timers dialog closed");
|
|
|
|
|
mShowAnalysisTimersDialog = null;
|
|
|
|
|
};
|
|
|
|
|
dlg.Show();
|
|
|
|
|
mShowAnalysisTimersDialog = dlg;
|
|
|
|
|
} else {
|
|
|
|
|
// Ask the dialog to close. Do the cleanup in the event.
|
|
|
|
|
mShowAnalysisTimersDialog.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Debug_ShowAnalyzerOutput() {
|
|
|
|
|
if (mShowAnalyzerOutputDialog == null) {
|
|
|
|
|
Tools.WpfGui.ShowText dlg = new Tools.WpfGui.ShowText(null, "(no data yet)");
|
|
|
|
|
dlg.Title = "Analyzer Output";
|
|
|
|
|
dlg.Closing += (sender, e) => {
|
|
|
|
|
Debug.WriteLine("Analyzer output dialog closed");
|
|
|
|
|
mShowAnalyzerOutputDialog = null;
|
|
|
|
|
};
|
|
|
|
|
dlg.Show();
|
|
|
|
|
mShowAnalyzerOutputDialog = dlg;
|
|
|
|
|
} else {
|
|
|
|
|
// Ask the dialog to close. Do the cleanup in the event.
|
|
|
|
|
mShowAnalyzerOutputDialog.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Debug_ShowUndoRedoHistory() {
|
|
|
|
|
if (mShowUndoRedoHistoryDialog == null) {
|
|
|
|
|
Tools.WpfGui.ShowText dlg = new Tools.WpfGui.ShowText(null,
|
|
|
|
|
mProject.DebugGetUndoRedoHistory());
|
|
|
|
|
dlg.Title = "Undo/Redo History";
|
|
|
|
|
dlg.Closing += (sender, e) => {
|
|
|
|
|
Debug.WriteLine("Undo/redo history dialog closed");
|
|
|
|
|
mShowUndoRedoHistoryDialog = null;
|
|
|
|
|
};
|
|
|
|
|
dlg.Show();
|
|
|
|
|
mShowUndoRedoHistoryDialog = dlg;
|
|
|
|
|
} else {
|
|
|
|
|
// Ask the dialog to close. Do the cleanup in the event.
|
|
|
|
|
mShowUndoRedoHistoryDialog.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-15 23:50:54 +00:00
|
|
|
|
public void Debug_RunSourceGenerationTests() {
|
2019-07-06 21:20:51 +00:00
|
|
|
|
Tests.WpfGui.GenTestRunner dlg = new Tests.WpfGui.GenTestRunner(mMainWin);
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-15 23:50:54 +00:00
|
|
|
|
public void Debug_Refresh() {
|
|
|
|
|
Debug.WriteLine("Reanalyzing...");
|
|
|
|
|
// Call through ApplyChanges so we update the timer task output.
|
|
|
|
|
UndoableChange uc =
|
|
|
|
|
UndoableChange.CreateDummyChange(UndoableChange.ReanalysisScope.CodeAndData);
|
|
|
|
|
ApplyChanges(new ChangeSet(uc), false);
|
2019-07-16 21:36:09 +00:00
|
|
|
|
UpdateTitle(); // in case something changed
|
2019-07-15 23:50:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Debug_ToggleCommentRulers() {
|
2024-07-06 21:54:09 +00:00
|
|
|
|
DebugLongComments = !DebugLongComments;
|
|
|
|
|
mFormatterConfig.DebugLongComments = DebugLongComments;
|
|
|
|
|
mFormatterConfig.AddSpaceLongComment = !DebugLongComments;
|
|
|
|
|
mFormatterCpuDef = null; // force mFormatter refresh on next analysis
|
|
|
|
|
if (CodeLineList != null) {
|
|
|
|
|
UndoableChange uc =
|
|
|
|
|
UndoableChange.CreateDummyChange(UndoableChange.ReanalysisScope.DisplayOnly);
|
|
|
|
|
ApplyChanges(new ChangeSet(uc), false);
|
|
|
|
|
}
|
2019-07-15 23:50:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Debug_ToggleKeepAliveHack() {
|
|
|
|
|
ScriptManager.UseKeepAliveHack = !ScriptManager.UseKeepAliveHack;
|
2020-07-18 20:47:01 +00:00
|
|
|
|
if (mProject != null) {
|
|
|
|
|
MessageBox.Show("Project must be closed and re-opened for change to take effect");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Debug_ToggleSecuritySandbox() {
|
|
|
|
|
UseMainAppDomainForPlugins = !UseMainAppDomainForPlugins;
|
|
|
|
|
if (mProject != null) {
|
|
|
|
|
MessageBox.Show("Project must be closed and re-opened for change to take effect");
|
|
|
|
|
}
|
2019-07-15 23:50:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 00:49:59 +00:00
|
|
|
|
public void Debug_ApplesoftToHtml() {
|
2020-07-09 00:56:27 +00:00
|
|
|
|
if (!OpenAnyFile(null, out string basPathName)) {
|
2019-10-24 00:49:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] data;
|
|
|
|
|
try {
|
|
|
|
|
data = File.ReadAllBytes(basPathName);
|
2020-04-14 00:33:34 +00:00
|
|
|
|
} catch (IOException ex) {
|
2019-10-24 00:49:59 +00:00
|
|
|
|
// not expecting this to happen
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tools.ApplesoftToHtml conv = new Tools.ApplesoftToHtml();
|
|
|
|
|
string html = conv.Convert(data);
|
|
|
|
|
|
|
|
|
|
Tools.WpfGui.ShowText showTextDlg = new Tools.WpfGui.ShowText(mMainWin, html);
|
|
|
|
|
showTextDlg.Title = "Applesoft to HTML";
|
|
|
|
|
showTextDlg.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 23:18:02 +00:00
|
|
|
|
public void Debug_ExportEditCommands() {
|
|
|
|
|
SaveFileDialog fileDlg = new SaveFileDialog() {
|
|
|
|
|
Filter = Res.Strings.FILE_FILTER_SGEC + "|" + Res.Strings.FILE_FILTER_ALL,
|
|
|
|
|
FilterIndex = 1,
|
|
|
|
|
ValidateNames = true,
|
|
|
|
|
AddExtension = true,
|
|
|
|
|
FileName = Path.GetFileName(mDataPathName) + Sgec.SGEC_EXT
|
|
|
|
|
};
|
|
|
|
|
if (fileDlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string sgecPathName = Path.GetFullPath(fileDlg.FileName);
|
2020-07-16 00:43:08 +00:00
|
|
|
|
|
|
|
|
|
MessageBoxResult res = MessageBox.Show("Use relative offsets?", "Question",
|
|
|
|
|
MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
|
|
|
bool resMode;
|
|
|
|
|
if (res == MessageBoxResult.Cancel) {
|
|
|
|
|
return;
|
|
|
|
|
} else if (res == MessageBoxResult.Yes) {
|
|
|
|
|
resMode = true;
|
|
|
|
|
} else {
|
|
|
|
|
resMode = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Sgec.ExportToFile(sgecPathName, mProject, resMode, out string detailMsg)) {
|
2020-07-15 23:18:02 +00:00
|
|
|
|
MessageBox.Show("Failed: " + detailMsg);
|
|
|
|
|
} else {
|
|
|
|
|
MessageBox.Show("Success: " + detailMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-14 00:33:34 +00:00
|
|
|
|
public void Debug_ApplyEditCommands() {
|
Reboot sandbox when required
Another chapter in the never-ending AppDomain security saga.
If a computer goes to sleep while SourceGen is running with a project
open, life gets confusing when the system wakes up. The keep-alive
timer fires and a ping is sent to the remote AppDomain, successfully.
At the same time, the lease expires on the remote side, and the objects
are discarded (apparently without bothering to query the ILease object).
This failure mode is 100% repeatable.
Since we can't prevent sandbox objects from disappearing, we have to
detect and recover from the problem. Fortunately we don't keep any
necessary state on the plugin side, so we can just tear the whole
thing down and recreate it.
The various methods in ScriptManager now do a "health check" before
making calls into the plugin AppDomain. If the ping attempt fails,
the AppDomain is "rebooted" by destroying it and creating a new one,
reloading all plugins that were in there before. The plugin binaries
*should* still be in the PluginDllCache directory since the ping failure
was due to objects being discarded, not AppDomain shutdown, and Windows
doesn't let you mess with files that hold executable code.
A new "reboot security sandbox" option has been added to the DEBUG
menu to facilitate testing.
The PluginManager's Ping() method gets called more often, but not to
the extent that performance will be affected.
This change also adds a finalizer to DisasmProject, since we're relying
on it to shut down the ScriptManager, and it's relying on callers to
invoke its cleanup function. The finalizer throws an assertion if the
cleanup function doesn't get called.
(Issue #82)
2020-07-19 20:20:18 +00:00
|
|
|
|
// Might want to suggest disabling Edit > Toggle Data Scan for some merges.
|
2020-04-14 00:33:34 +00:00
|
|
|
|
OpenFileDialog fileDlg = new OpenFileDialog() {
|
|
|
|
|
Filter = Res.Strings.FILE_FILTER_SGEC + "|" + Res.Strings.FILE_FILTER_ALL,
|
|
|
|
|
FilterIndex = 1
|
|
|
|
|
};
|
|
|
|
|
if (fileDlg.ShowDialog() != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string sgecPathName = Path.GetFullPath(fileDlg.FileName);
|
|
|
|
|
|
|
|
|
|
ChangeSet cs = new ChangeSet(1);
|
2020-07-15 23:18:02 +00:00
|
|
|
|
if (!Sgec.ImportFromFile(sgecPathName, mProject, cs, out string detailMsg)) {
|
|
|
|
|
MessageBox.Show("Failed: " + detailMsg);
|
|
|
|
|
} else {
|
2020-07-16 17:14:28 +00:00
|
|
|
|
if (cs.Count != 0) {
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
MessageBox.Show("Success: " + detailMsg);
|
|
|
|
|
} else {
|
|
|
|
|
MessageBox.Show("Success; no changes were made.");
|
|
|
|
|
}
|
2020-04-14 00:33:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:21:18 +00:00
|
|
|
|
// Disable "analyze uncategorized data" for best results.
|
2020-07-28 17:56:07 +00:00
|
|
|
|
public void Debug_ApplyExternalSymbols() {
|
2019-11-19 21:31:04 +00:00
|
|
|
|
ChangeSet cs = new ChangeSet(1);
|
|
|
|
|
|
2020-08-10 21:09:26 +00:00
|
|
|
|
MessageBoxResult result =
|
|
|
|
|
MessageBox.Show("Apply project symbols (in addition to platform symbols)?",
|
|
|
|
|
"Apply project symbols?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
|
|
|
bool doProject;
|
|
|
|
|
if (result == MessageBoxResult.Cancel) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
doProject = (result == MessageBoxResult.Yes);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-19 21:31:04 +00:00
|
|
|
|
foreach (Symbol sym in mProject.SymbolTable) {
|
2020-07-28 17:56:07 +00:00
|
|
|
|
if (sym.SymbolSource != Symbol.Source.Platform &&
|
2020-08-10 21:09:26 +00:00
|
|
|
|
(!doProject || sym.SymbolSource != Symbol.Source.Project)) {
|
2019-11-19 21:31:04 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
DefSymbol defSym = (DefSymbol)sym;
|
|
|
|
|
if (defSym.MultiMask != null) {
|
|
|
|
|
// These would require additional work... probably.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int offset = mProject.AddrMap.AddressToOffset(0, sym.Value);
|
|
|
|
|
if (offset < 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure this is the start of an instruction or data item. (If you
|
2020-10-15 21:03:32 +00:00
|
|
|
|
// haven't finished tagging code start points, it's best to disable the
|
|
|
|
|
// string/fill finder.)
|
2019-11-19 21:31:04 +00:00
|
|
|
|
Anattrib attr = mProject.GetAnattrib(offset);
|
|
|
|
|
if (!attr.IsStart) {
|
|
|
|
|
Debug.WriteLine("Found match at non-start +" + offset.ToString("x6") +
|
|
|
|
|
": " + defSym);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for user label. Okay to overwrite auto label.
|
|
|
|
|
if (mProject.UserLabels.ContainsKey(offset)) {
|
|
|
|
|
Debug.WriteLine("User label already exists at +" + offset.ToString("x6"));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 04:45:57 +00:00
|
|
|
|
// Create a new user label symbol. We should not be creating a duplicate name,
|
|
|
|
|
// because user labels have priority over platform symbols when populating
|
|
|
|
|
// the symbol table.
|
2019-11-19 21:31:04 +00:00
|
|
|
|
Symbol newSym = new Symbol(sym.Label, sym.Value, Symbol.Source.User,
|
|
|
|
|
Symbol.Type.GlobalAddr, Symbol.LabelAnnotation.None);
|
|
|
|
|
UndoableChange uc = UndoableChange.CreateLabelChange(offset, null, newSym);
|
|
|
|
|
cs.Add(uc);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 17:56:07 +00:00
|
|
|
|
if (cs.Count == 0) {
|
|
|
|
|
MessageBox.Show("No changes made.");
|
|
|
|
|
} else {
|
|
|
|
|
ApplyUndoableChanges(cs);
|
|
|
|
|
MessageBox.Show("Set " + cs.Count + " labels.");
|
|
|
|
|
}
|
2019-11-19 21:31:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
Reboot sandbox when required
Another chapter in the never-ending AppDomain security saga.
If a computer goes to sleep while SourceGen is running with a project
open, life gets confusing when the system wakes up. The keep-alive
timer fires and a ping is sent to the remote AppDomain, successfully.
At the same time, the lease expires on the remote side, and the objects
are discarded (apparently without bothering to query the ILease object).
This failure mode is 100% repeatable.
Since we can't prevent sandbox objects from disappearing, we have to
detect and recover from the problem. Fortunately we don't keep any
necessary state on the plugin side, so we can just tear the whole
thing down and recreate it.
The various methods in ScriptManager now do a "health check" before
making calls into the plugin AppDomain. If the ping attempt fails,
the AppDomain is "rebooted" by destroying it and creating a new one,
reloading all plugins that were in there before. The plugin binaries
*should* still be in the PluginDllCache directory since the ping failure
was due to objects being discarded, not AppDomain shutdown, and Windows
doesn't let you mess with files that hold executable code.
A new "reboot security sandbox" option has been added to the DEBUG
menu to facilitate testing.
The PluginManager's Ping() method gets called more often, but not to
the extent that performance will be affected.
This change also adds a finalizer to DisasmProject, since we're relying
on it to shut down the ScriptManager, and it's relying on callers to
invoke its cleanup function. The finalizer throws an assertion if the
cleanup function doesn't get called.
(Issue #82)
2020-07-19 20:20:18 +00:00
|
|
|
|
public void Debug_RebootSecuritySandbox() {
|
|
|
|
|
Debug.Assert(mProject != null);
|
|
|
|
|
mProject.DebugRebootSandbox();
|
|
|
|
|
}
|
|
|
|
|
|
Allow explicit widths in project/platform symbols, part 3
Implement multi-byte project/platform symbols by filling out a table
of addresses. Each symbol is "painted" into the table, replacing
an existing entry if the new entry has higher priority. This allows
us to handle overlapping entries, giving boosted priority to platform
symbols that are defined in .sym65 files loaded later.
The bounds on project/platform symbols are now rigidly defined. If
the "nearby" feature is enabled, references to SYM-1 will be picked
up, but we won't go hunting for SYM+1 unless the symbol is at least
two bytes wide.
The cost of adding a symbol to the symbol table is about the same,
but we don't have a quick way to remove a symbol.
Previously, if two platform symbols had the same value, the symbol
with the alphabetically lowest label would win. Now, the symbol
defined in the most-recently-loaded file wins. (If you define two
symbols with the same value in the same file, it's still resolved
alphabetically.) This allows the user to pick the winner by
arranging the load order of the platform symbol files.
Platform symbols now keep a reference to the file ident of the
symbol file that defined them, so we can show the symbols's source
in the Info panel.
These changes altered the behavior of test 2008-address-changes,
which includes some tests on external addresses that are close to
labeled internal addresses. The previous behavior essentially
treated user labels as being 3 bytes wide and extending outside the
file bounds, which was mildly convenient on occasion but felt a
little skanky. (We could do with a way to define external symbols
relative to internal symbols, for things like the source address of
code that gets relocated.)
Also, re-enabled some unit tests.
Also, added a bit of identifying stuff to CrashLog.txt.
2019-10-02 23:26:05 +00:00
|
|
|
|
#endregion Debug features
|
2019-05-05 23:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|