From e2fb36240d7bebd8f76e2f0af2295f4a2305d392 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 11 Mar 2017 15:37:57 -0500 Subject: [PATCH] Debugger: Assembler can now be used to write new code without selecting code to edit --- GUI.NET/Debugger/frmAssembler.cs | 28 ++++++++++++++-------------- GUI.NET/Debugger/frmDebugger.cs | 29 +++++++++++++++++------------ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/GUI.NET/Debugger/frmAssembler.cs b/GUI.NET/Debugger/frmAssembler.cs index 72585dfb..8283d87b 100644 --- a/GUI.NET/Debugger/frmAssembler.cs +++ b/GUI.NET/Debugger/frmAssembler.cs @@ -27,11 +27,7 @@ namespace Mesen.GUI.Debugger { InitializeComponent(); - if(string.IsNullOrWhiteSpace(code)) { - btnCancel.Text = "Close"; - btnOk.Enabled = false; - btnOk.Visible = false; - } else { + if(!string.IsNullOrWhiteSpace(code)) { _isEditMode = true; _containedRtiRts = ContainsRtiOrRts(code); } @@ -135,13 +131,16 @@ namespace Mesen.GUI.Debugger lblByteUsage.Text = ctrlHexBox.ByteProvider.Length.ToString() + " / " + _blockLength.ToString(); lblByteUsage.ForeColor = SizeExceeded ? Color.Red : Color.Black; picSizeWarning.Visible = SizeExceeded; - btnOk.Image = _hasParsingErrors || NeedRtiRtsWarning || SizeExceeded ? Properties.Resources.Warning : null; bool isIdentical = IsIdentical; lblNoChanges.Visible = isIdentical; + btnOk.Image = _hasParsingErrors || NeedRtiRtsWarning || SizeExceeded ? Properties.Resources.Warning : null; btnOk.Enabled = !isIdentical && _startAddressValid && ctrlHexBox.ByteProvider.Length > 0; } else { lblNoChanges.Visible = false; + btnOk.Image = _hasParsingErrors ? Properties.Resources.Warning : null; + btnOk.Enabled = _startAddressValid && ctrlHexBox.ByteProvider.Length > 0; + lblByteUsage.Text = ctrlHexBox.ByteProvider.Length.ToString(); } @@ -183,14 +182,15 @@ namespace Mesen.GUI.Debugger if(_hasParsingErrors) { warningMessages.Add("Warning: The code contains parsing errors - lines with errors will be ignored."); } - if(SizeExceeded) { - warningMessages.Add("Warning: The new code exceeds the original code's length." + Environment.NewLine + "Applying this modification will overwrite other portions of the code and potentially cause problems."); - } - if(NeedRtiRtsWarning) { - warningMessages.Add("Warning: The code originally contained an RTI/RTS instruction and it no longer does - this will probably cause problems."); - } - if(!_startAddressValid) { - warningMessages.Add("Warning: Start address is invalid. Must be a valid hexadecimal string."); + if(_isEditMode) { + if(SizeExceeded) { + warningMessages.Add("Warning: The new code exceeds the original code's length." + Environment.NewLine + "Applying this modification will overwrite other portions of the code and potentially cause problems."); + } + if(NeedRtiRtsWarning) { + warningMessages.Add("Warning: The code originally contained an RTI/RTS instruction and it no longer does - this will probably cause problems."); + } + } else { + warningMessages.Add($"Warning: The contents currently mapped to CPU memory addresses ${_startAddress.ToString("X4")} to ${(_startAddress+ctrlHexBox.ByteProvider.Length).ToString("X4")} will be overridden."); } if(warningMessages.Count == 0 || MessageBox.Show(string.Join(Environment.NewLine+Environment.NewLine, warningMessages.ToArray()) + Environment.NewLine + Environment.NewLine + "OK?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { diff --git a/GUI.NET/Debugger/frmDebugger.cs b/GUI.NET/Debugger/frmDebugger.cs index e196f552..db11b22d 100644 --- a/GUI.NET/Debugger/frmDebugger.cs +++ b/GUI.NET/Debugger/frmDebugger.cs @@ -441,17 +441,6 @@ namespace Mesen.GUI.Debugger this.UpdateDebugger(); } - private void ctrlDebuggerCode_OnEditCode(AssemblerEventArgs args) - { - frmAssembler assembler = new frmAssembler(args.Code, args.StartAddress, args.BlockLength); - assembler.FormClosed += (s, e) => { - if(assembler.DialogResult == DialogResult.OK) { - this.UpdateDebugger(false); - } - }; - OpenChildForm(assembler); - } - private void mnuFind_Click(object sender, EventArgs e) { _lastCodeWindow.OpenSearchBox(); @@ -869,9 +858,25 @@ namespace Mesen.GUI.Debugger } } + private void OpenAssembler(string code, UInt16 startAddress, UInt16 blockLength = 0) + { + frmAssembler assembler = new frmAssembler(code, startAddress, blockLength); + assembler.FormClosed += (s, e) => { + if(assembler.DialogResult == DialogResult.OK) { + this.UpdateDebugger(false); + } + }; + OpenChildForm(assembler); + } + private void mnuAssembler_Click(object sender, EventArgs e) { - OpenChildForm(new frmAssembler()); + this.OpenAssembler(string.Empty, 0x8000); + } + + private void ctrlDebuggerCode_OnEditCode(AssemblerEventArgs args) + { + this.OpenAssembler(args.Code, args.StartAddress, args.BlockLength); } private void mnuCode_DropDownOpening(object sender, EventArgs e)