diff --git a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.Designer.cs b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.Designer.cs index 30b38633..3df0c795 100644 --- a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.Designer.cs +++ b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.Designer.cs @@ -48,6 +48,7 @@ this.mnuHidePrgAddresses = new System.Windows.Forms.ToolStripMenuItem(); this.sepEditLabel = new System.Windows.Forms.ToolStripSeparator(); this.mnuEditLabel = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuEditInMemoryViewer = new System.Windows.Forms.ToolStripMenuItem(); this.mnuToggleBreakpoint = new System.Windows.Forms.ToolStripMenuItem(); this.sepAddToWatch = new System.Windows.Forms.ToolStripSeparator(); this.mnuAddToWatch = new System.Windows.Forms.ToolStripMenuItem(); @@ -95,6 +96,7 @@ this.mnuShowLineNotes, this.sepEditLabel, this.mnuEditLabel, + this.mnuEditInMemoryViewer, this.mnuToggleBreakpoint, this.sepAddToWatch, this.mnuAddToWatch, @@ -250,6 +252,15 @@ this.mnuEditLabel.Text = "Edit Label"; this.mnuEditLabel.Click += new System.EventHandler(this.mnuEditLabel_Click); // + // mnuEditInMemoryViewer + // + this.mnuEditInMemoryViewer.Image = global::Mesen.GUI.Properties.Resources.CheatCode; + this.mnuEditInMemoryViewer.Name = "mnuEditInMemoryViewer"; + this.mnuEditInMemoryViewer.ShortcutKeys = System.Windows.Forms.Keys.F1; + this.mnuEditInMemoryViewer.Size = new System.Drawing.Size(258, 22); + this.mnuEditInMemoryViewer.Text = "Edit in Memory Viewer"; + this.mnuEditInMemoryViewer.Click += new System.EventHandler(this.mnuEditInMemoryViewer_Click); + // // mnuToggleBreakpoint // this.mnuToggleBreakpoint.Image = global::Mesen.GUI.Properties.Resources.Breakpoint; @@ -536,5 +547,6 @@ private System.Windows.Forms.ToolStripMenuItem mnuEditSubroutine; private System.Windows.Forms.ToolStripMenuItem mnuEditSelectedCode; private System.Windows.Forms.ToolStripMenuItem copySelectionToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem mnuEditInMemoryViewer; } } diff --git a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs index dba15570..b1a1c5d0 100644 --- a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs +++ b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs @@ -480,6 +480,9 @@ namespace Mesen.GUI.Debugger mnuEditLabel.Enabled = true; mnuEditLabel.Text = $"Edit Label ({word})"; + mnuEditInMemoryViewer.Enabled = true; + mnuEditInMemoryViewer.Text = $"Edit in Memory Viewer ({word})"; + return true; } else { mnuGoToLocation.Enabled = false; @@ -490,9 +493,17 @@ namespace Mesen.GUI.Debugger mnuFindOccurrences.Text = "Find Occurrences"; mnuEditLabel.Enabled = false; mnuEditLabel.Text = "Edit Label"; + mnuEditInMemoryViewer.Enabled = false; + mnuEditInMemoryViewer.Text = $"Edit in Memory Viewer"; - _lastClickedAddress = ctrlCodeViewer.GetLineNumberAtPosition(mouseLocation.Y); - if(mouseLocation.X < this.ctrlCodeViewer.CodeMargin && _lastClickedAddress >= 0) { + + if(mouseLocation.X < this.ctrlCodeViewer.CodeMargin) { + _lastClickedAddress = ctrlCodeViewer.GetLineNumberAtPosition(mouseLocation.Y); + } else { + _lastClickedAddress = ctrlCodeViewer.LastSelectedLine; + } + + if(_lastClickedAddress >= 0) { //Cursor is in the margin, over an address label string address = $"${_lastClickedAddress.ToString("X4")}"; _newWatchValue = $"[{address}]"; @@ -504,7 +515,8 @@ namespace Mesen.GUI.Debugger mnuFindOccurrences.Text = $"Find Occurrences ({address})"; mnuEditLabel.Enabled = true; mnuEditLabel.Text = $"Edit Label ({address})"; - + mnuEditInMemoryViewer.Enabled = true; + mnuEditInMemoryViewer.Text = $"Edit in Memory Viewer ({address})"; return true; } @@ -867,6 +879,13 @@ namespace Mesen.GUI.Debugger { this.ctrlCodeViewer.CopySelection(); } + + private void mnuEditInMemoryViewer_Click(object sender, EventArgs e) + { + if(UpdateContextMenu(_previousLocation)) { + DebugWindowManager.OpenMemoryViewer(_lastClickedAddress); + } + } } public class WatchEventArgs : EventArgs diff --git a/GUI.NET/Debugger/Controls/ctrlHexViewer.cs b/GUI.NET/Debugger/Controls/ctrlHexViewer.cs index c655a50e..138efd0d 100644 --- a/GUI.NET/Debugger/Controls/ctrlHexViewer.cs +++ b/GUI.NET/Debugger/Controls/ctrlHexViewer.cs @@ -116,6 +116,14 @@ namespace Mesen.GUI.Debugger.Controls this.SetFontSize(BaseControl.DefaultFontSize); } + public void GoToAddress(int address) + { + this.ctrlHexBox.ScrollByteIntoView(GetData().Length - 1); + this.ctrlHexBox.ScrollByteIntoView(address); + this.ctrlHexBox.Select(address, 0); + this.ctrlHexBox.Focus(); + } + public void GoToAddress() { GoToAddress address = new GoToAddress(); @@ -128,8 +136,7 @@ namespace Mesen.GUI.Debugger.Controls Point topLeft = this.PointToScreen(new Point(0, 0)); frm.Location = new Point(topLeft.X + (this.Width - frm.Width) / 2, topLeft.Y + (this.Height - frm.Height) / 2); if(frm.ShowDialog() == DialogResult.OK) { - this.ctrlHexBox.ScrollByteIntoView((int)address.Address); - this.ctrlHexBox.Focus(); + GoToAddress((int)address.Address); } } diff --git a/GUI.NET/Debugger/DebugWindowManager.cs b/GUI.NET/Debugger/DebugWindowManager.cs index b05614d0..9620e941 100644 --- a/GUI.NET/Debugger/DebugWindowManager.cs +++ b/GUI.NET/Debugger/DebugWindowManager.cs @@ -9,7 +9,7 @@ namespace Mesen.GUI.Debugger { public class DebugWindowManager { - private static List