diff --git a/Core/BaseMapper.cpp b/Core/BaseMapper.cpp index ff48a4a5..7b689f3c 100644 --- a/Core/BaseMapper.cpp +++ b/Core/BaseMapper.cpp @@ -1024,4 +1024,25 @@ void BaseMapper::SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header) } file.close(); } +} + +void BaseMapper::RevertPrgChrChanges() +{ + memcpy(_prgRom, _originalPrgRom.data(), _originalPrgRom.size()); + if(_chrRom) { + memcpy(_chrRom, _originalChrRom.data(), _originalChrRom.size()); + } +} + +bool BaseMapper::HasPrgChrChanges() +{ + if(memcmp(_prgRom, _originalPrgRom.data(), _originalPrgRom.size()) != 0) { + return true; + } + if(_chrRom) { + if(memcmp(_chrRom, _originalChrRom.data(), _originalChrRom.size()) != 0) { + return true; + } + } + return false; } \ No newline at end of file diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index c917714e..9c8250bc 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -215,4 +215,6 @@ public: NESHeader GetNesHeader(); void SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header); + void RevertPrgChrChanges(); + bool HasPrgChrChanges(); }; \ No newline at end of file diff --git a/Core/Console.cpp b/Core/Console.cpp index 29d4fbb2..67bca2a2 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -306,7 +306,7 @@ void Console::Stop() shared_ptr debugger = _debugger; if(debugger) { - debugger->Run(); + debugger->Suspend(); } _stopLock.Acquire(); _stopLock.Release(); diff --git a/Core/Debugger.cpp b/Core/Debugger.cpp index 2b7b028d..c9e1cbdf 100644 --- a/Core/Debugger.cpp +++ b/Core/Debugger.cpp @@ -21,6 +21,7 @@ #include "PPU.h" #include "MemoryManager.h" #include "RewindManager.h" +#include "DebugBreakHelper.h" Debugger* Debugger::Instance = nullptr; const int Debugger::BreakpointTypeCount; @@ -147,7 +148,10 @@ void Debugger::BreakIfDebugging() bool Debugger::LoadCdlFile(string cdlFilepath) { if(_codeDataLogger->LoadCdlFile(cdlFilepath)) { + //Can't use DebugBreakHelper due to the fact this is called in the constructor + Console::Pause(); UpdateCdlCache(); + Console::Resume(); return true; } return false; @@ -155,13 +159,13 @@ bool Debugger::LoadCdlFile(string cdlFilepath) void Debugger::ResetCdl() { + DebugBreakHelper helper(this); _codeDataLogger->Reset(); UpdateCdlCache(); } void Debugger::UpdateCdlCache() { - Console::Pause(); _disassembler->Reset(); for(int i = 0, len = _mapper->GetMemorySize(DebugMemoryType::PrgRom); i < len; i++) { if(_codeDataLogger->IsCode(i)) { @@ -176,7 +180,6 @@ void Debugger::UpdateCdlCache() _functionEntryPoints.emplace(i); } } - Console::Resume(); } bool Debugger::IsMarkedAsCode(uint16_t relativeAddress) @@ -858,7 +861,7 @@ shared_ptr Debugger::GetMemoryAccessCounter() bool Debugger::IsExecutionStopped() { - return _executionStopped; + return _executionStopped || !_console->IsRunning(); } void Debugger::GetAbsoluteAddressAndType(uint32_t relativeAddr, AddressTypeInfo* info) @@ -959,6 +962,19 @@ void Debugger::SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header) _mapper->SaveRomToDisk(filename, saveAsIps, header); } +void Debugger::RevertPrgChrChanges() +{ + DebugBreakHelper helper(this); + _mapper->RevertPrgChrChanges(); + _disassembler->Reset(); + UpdateCdlCache(); +} + +bool Debugger::HasPrgChrChanges() +{ + return _mapper->HasPrgChrChanges(); +} + int32_t Debugger::FindSubEntryPoint(uint16_t relativeAddress) { AddressTypeInfo info; diff --git a/Core/Debugger.h b/Core/Debugger.h index 3bfc3466..2598f2c6 100644 --- a/Core/Debugger.h +++ b/Core/Debugger.h @@ -202,6 +202,8 @@ public: void GetNesHeader(uint8_t* header); void SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header); + void RevertPrgChrChanges(); + bool HasPrgChrChanges(); int32_t FindSubEntryPoint(uint16_t relativeAddress); diff --git a/GUI.NET/Debugger/frmDebugger.Designer.cs b/GUI.NET/Debugger/frmDebugger.Designer.cs index 069b96f4..cafee1e3 100644 --- a/GUI.NET/Debugger/frmDebugger.Designer.cs +++ b/GUI.NET/Debugger/frmDebugger.Designer.cs @@ -51,10 +51,11 @@ namespace Mesen.GUI.Debugger this.grpCallstack = new System.Windows.Forms.GroupBox(); this.ctrlCallstack = new Mesen.GUI.Debugger.Controls.ctrlCallstack(); this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuFile = new System.Windows.Forms.ToolStripMenuItem(); this.mnuSaveRom = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuSaveRomAs = new System.Windows.Forms.ToolStripMenuItem(); this.mnuSaveAsIps = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuEditHeader = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuRevertChanges = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem14 = new System.Windows.Forms.ToolStripSeparator(); this.mnuWorkspace = new System.Windows.Forms.ToolStripMenuItem(); this.mnuImportLabels = new System.Windows.Forms.ToolStripMenuItem(); @@ -63,6 +64,7 @@ namespace Mesen.GUI.Debugger this.mnuResetWorkspace = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem10 = new System.Windows.Forms.ToolStripSeparator(); this.mnuAutoLoadDbgFiles = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuAutoLoadCdlFiles = new System.Windows.Forms.ToolStripMenuItem(); this.mnuDisableDefaultLabels = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator(); this.mnuClose = new System.Windows.Forms.ToolStripMenuItem(); @@ -133,6 +135,8 @@ namespace Mesen.GUI.Debugger this.mnuPpuViewer = new System.Windows.Forms.ToolStripMenuItem(); this.mnuTraceLogger = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem13 = new System.Windows.Forms.ToolStripSeparator(); + this.mnuEditHeader = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem17 = new System.Windows.Forms.ToolStripSeparator(); this.mnuCodeDataLogger = new System.Windows.Forms.ToolStripMenuItem(); this.autoLoadsaveCDLFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripSeparator(); @@ -152,7 +156,6 @@ namespace Mesen.GUI.Debugger this.lblCyclesElapsed = new System.Windows.Forms.ToolStripStatusLabel(); this.ctrlPpuMemoryMapping = new Mesen.GUI.Debugger.Controls.ctrlMemoryMapping(); this.ctrlCpuMemoryMapping = new Mesen.GUI.Debugger.Controls.ctrlMemoryMapping(); - this.mnuAutoLoadCdlFiles = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); this.splitContainer.Panel1.SuspendLayout(); this.splitContainer.Panel2.SuspendLayout(); @@ -197,7 +200,7 @@ namespace Mesen.GUI.Debugger this.splitContainer.Panel2.Controls.Add(this.tableLayoutPanel10); this.splitContainer.Panel2MinSize = 100; this.splitContainer.Size = new System.Drawing.Size(1172, 573); - this.splitContainer.SplitterDistance = 432; + this.splitContainer.SplitterDistance = 411; this.splitContainer.SplitterWidth = 7; this.splitContainer.TabIndex = 1; this.splitContainer.TabStop = false; @@ -220,8 +223,8 @@ namespace Mesen.GUI.Debugger // this.ctrlSplitContainerTop.Panel2.Controls.Add(this.tlpFunctionLabelLists); this.ctrlSplitContainerTop.Panel2MinSize = 150; - this.ctrlSplitContainerTop.Size = new System.Drawing.Size(1172, 432); - this.ctrlSplitContainerTop.SplitterDistance = 911; + this.ctrlSplitContainerTop.Size = new System.Drawing.Size(1172, 411); + this.ctrlSplitContainerTop.SplitterDistance = 890; this.ctrlSplitContainerTop.SplitterWidth = 7; this.ctrlSplitContainerTop.TabIndex = 3; this.ctrlSplitContainerTop.PanelCollapsed += new System.EventHandler(this.ctrlSplitContainerTop_PanelCollapsed); @@ -242,7 +245,7 @@ namespace Mesen.GUI.Debugger this.tlpTop.Name = "tlpTop"; this.tlpTop.RowCount = 1; this.tlpTop.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tlpTop.Size = new System.Drawing.Size(911, 432); + this.tlpTop.Size = new System.Drawing.Size(890, 411); this.tlpTop.TabIndex = 2; // // ctrlDebuggerCode @@ -251,7 +254,7 @@ namespace Mesen.GUI.Debugger this.ctrlDebuggerCode.Dock = System.Windows.Forms.DockStyle.Fill; this.ctrlDebuggerCode.Location = new System.Drawing.Point(3, 3); this.ctrlDebuggerCode.Name = "ctrlDebuggerCode"; - this.ctrlDebuggerCode.Size = new System.Drawing.Size(447, 426); + this.ctrlDebuggerCode.Size = new System.Drawing.Size(426, 405); this.ctrlDebuggerCode.TabIndex = 2; this.ctrlDebuggerCode.OnEditCode += new Mesen.GUI.Debugger.ctrlDebuggerCode.AssemblerEventHandler(this.ctrlDebuggerCode_OnEditCode); this.ctrlDebuggerCode.OnSetNextStatement += new Mesen.GUI.Debugger.ctrlDebuggerCode.AddressEventHandler(this.ctrlDebuggerCode_OnSetNextStatement); @@ -260,10 +263,10 @@ namespace Mesen.GUI.Debugger // ctrlConsoleStatus // this.ctrlConsoleStatus.Dock = System.Windows.Forms.DockStyle.Fill; - this.ctrlConsoleStatus.Location = new System.Drawing.Point(453, 0); + this.ctrlConsoleStatus.Location = new System.Drawing.Point(432, 0); this.ctrlConsoleStatus.Margin = new System.Windows.Forms.Padding(0); this.ctrlConsoleStatus.Name = "ctrlConsoleStatus"; - this.ctrlConsoleStatus.Size = new System.Drawing.Size(458, 432); + this.ctrlConsoleStatus.Size = new System.Drawing.Size(458, 411); this.ctrlConsoleStatus.TabIndex = 3; this.ctrlConsoleStatus.OnGotoLocation += new System.EventHandler(this.ctrlConsoleStatus_OnGotoLocation); // @@ -271,9 +274,9 @@ namespace Mesen.GUI.Debugger // this.ctrlDebuggerCodeSplit.Code = null; this.ctrlDebuggerCodeSplit.Dock = System.Windows.Forms.DockStyle.Fill; - this.ctrlDebuggerCodeSplit.Location = new System.Drawing.Point(456, 3); + this.ctrlDebuggerCodeSplit.Location = new System.Drawing.Point(435, 3); this.ctrlDebuggerCodeSplit.Name = "ctrlDebuggerCodeSplit"; - this.ctrlDebuggerCodeSplit.Size = new System.Drawing.Size(1, 426); + this.ctrlDebuggerCodeSplit.Size = new System.Drawing.Size(1, 405); this.ctrlDebuggerCodeSplit.TabIndex = 4; this.ctrlDebuggerCodeSplit.Visible = false; this.ctrlDebuggerCodeSplit.OnEditCode += new Mesen.GUI.Debugger.ctrlDebuggerCode.AssemblerEventHandler(this.ctrlDebuggerCode_OnEditCode); @@ -293,16 +296,16 @@ namespace Mesen.GUI.Debugger this.tlpFunctionLabelLists.RowCount = 2; this.tlpFunctionLabelLists.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tlpFunctionLabelLists.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tlpFunctionLabelLists.Size = new System.Drawing.Size(254, 432); + this.tlpFunctionLabelLists.Size = new System.Drawing.Size(275, 411); this.tlpFunctionLabelLists.TabIndex = 5; // // grpLabels // this.grpLabels.Controls.Add(this.ctrlLabelList); this.grpLabels.Dock = System.Windows.Forms.DockStyle.Fill; - this.grpLabels.Location = new System.Drawing.Point(3, 219); + this.grpLabels.Location = new System.Drawing.Point(3, 208); this.grpLabels.Name = "grpLabels"; - this.grpLabels.Size = new System.Drawing.Size(248, 210); + this.grpLabels.Size = new System.Drawing.Size(269, 200); this.grpLabels.TabIndex = 6; this.grpLabels.TabStop = false; this.grpLabels.Text = "Labels"; @@ -312,7 +315,7 @@ namespace Mesen.GUI.Debugger this.ctrlLabelList.Dock = System.Windows.Forms.DockStyle.Fill; this.ctrlLabelList.Location = new System.Drawing.Point(3, 16); this.ctrlLabelList.Name = "ctrlLabelList"; - this.ctrlLabelList.Size = new System.Drawing.Size(242, 191); + this.ctrlLabelList.Size = new System.Drawing.Size(263, 181); this.ctrlLabelList.TabIndex = 0; this.ctrlLabelList.OnFindOccurrence += new System.EventHandler(this.ctrlLabelList_OnFindOccurrence); this.ctrlLabelList.OnLabelSelected += new System.EventHandler(this.ctrlLabelList_OnLabelSelected); @@ -323,7 +326,7 @@ namespace Mesen.GUI.Debugger this.grpFunctions.Dock = System.Windows.Forms.DockStyle.Fill; this.grpFunctions.Location = new System.Drawing.Point(3, 3); this.grpFunctions.Name = "grpFunctions"; - this.grpFunctions.Size = new System.Drawing.Size(248, 210); + this.grpFunctions.Size = new System.Drawing.Size(269, 199); this.grpFunctions.TabIndex = 5; this.grpFunctions.TabStop = false; this.grpFunctions.Text = "Functions"; @@ -333,7 +336,7 @@ namespace Mesen.GUI.Debugger this.ctrlFunctionList.Dock = System.Windows.Forms.DockStyle.Fill; this.ctrlFunctionList.Location = new System.Drawing.Point(3, 16); this.ctrlFunctionList.Name = "ctrlFunctionList"; - this.ctrlFunctionList.Size = new System.Drawing.Size(242, 191); + this.ctrlFunctionList.Size = new System.Drawing.Size(263, 180); this.ctrlFunctionList.TabIndex = 0; this.ctrlFunctionList.OnFindOccurrence += new System.EventHandler(this.ctrlFunctionList_OnFindOccurrence); this.ctrlFunctionList.OnFunctionSelected += new System.EventHandler(this.ctrlFunctionList_OnFunctionSelected); @@ -354,7 +357,7 @@ namespace Mesen.GUI.Debugger this.tableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel10.Size = new System.Drawing.Size(1172, 134); + this.tableLayoutPanel10.Size = new System.Drawing.Size(1172, 155); this.tableLayoutPanel10.TabIndex = 0; // // grpWatch @@ -364,7 +367,7 @@ namespace Mesen.GUI.Debugger this.grpWatch.Dock = System.Windows.Forms.DockStyle.Fill; this.grpWatch.Location = new System.Drawing.Point(3, 3); this.grpWatch.Name = "grpWatch"; - this.grpWatch.Size = new System.Drawing.Size(384, 128); + this.grpWatch.Size = new System.Drawing.Size(384, 149); this.grpWatch.TabIndex = 2; this.grpWatch.TabStop = false; this.grpWatch.Text = "Watch"; @@ -384,7 +387,7 @@ namespace Mesen.GUI.Debugger this.ctrlWatch.Dock = System.Windows.Forms.DockStyle.Fill; this.ctrlWatch.Location = new System.Drawing.Point(3, 16); this.ctrlWatch.Name = "ctrlWatch"; - this.ctrlWatch.Size = new System.Drawing.Size(378, 109); + this.ctrlWatch.Size = new System.Drawing.Size(378, 130); this.ctrlWatch.TabIndex = 0; // // grpBreakpoints @@ -393,7 +396,7 @@ namespace Mesen.GUI.Debugger this.grpBreakpoints.Dock = System.Windows.Forms.DockStyle.Fill; this.grpBreakpoints.Location = new System.Drawing.Point(393, 3); this.grpBreakpoints.Name = "grpBreakpoints"; - this.grpBreakpoints.Size = new System.Drawing.Size(384, 128); + this.grpBreakpoints.Size = new System.Drawing.Size(384, 149); this.grpBreakpoints.TabIndex = 3; this.grpBreakpoints.TabStop = false; this.grpBreakpoints.Text = "Breakpoints"; @@ -403,7 +406,7 @@ namespace Mesen.GUI.Debugger this.ctrlBreakpoints.Dock = System.Windows.Forms.DockStyle.Fill; this.ctrlBreakpoints.Location = new System.Drawing.Point(3, 16); this.ctrlBreakpoints.Name = "ctrlBreakpoints"; - this.ctrlBreakpoints.Size = new System.Drawing.Size(378, 109); + this.ctrlBreakpoints.Size = new System.Drawing.Size(378, 130); this.ctrlBreakpoints.TabIndex = 0; this.ctrlBreakpoints.BreakpointNavigation += new System.EventHandler(this.ctrlBreakpoints_BreakpointNavigation); // @@ -413,7 +416,7 @@ namespace Mesen.GUI.Debugger this.grpCallstack.Dock = System.Windows.Forms.DockStyle.Fill; this.grpCallstack.Location = new System.Drawing.Point(783, 3); this.grpCallstack.Name = "grpCallstack"; - this.grpCallstack.Size = new System.Drawing.Size(386, 128); + this.grpCallstack.Size = new System.Drawing.Size(386, 149); this.grpCallstack.TabIndex = 4; this.grpCallstack.TabStop = false; this.grpCallstack.Text = "Call Stack"; @@ -423,14 +426,14 @@ namespace Mesen.GUI.Debugger this.ctrlCallstack.Dock = System.Windows.Forms.DockStyle.Fill; this.ctrlCallstack.Location = new System.Drawing.Point(3, 16); this.ctrlCallstack.Name = "ctrlCallstack"; - this.ctrlCallstack.Size = new System.Drawing.Size(380, 109); + this.ctrlCallstack.Size = new System.Drawing.Size(380, 130); this.ctrlCallstack.TabIndex = 0; this.ctrlCallstack.FunctionSelected += new System.EventHandler(this.ctrlCallstack_FunctionSelected); // // menuStrip // this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.fileToolStripMenuItem, + this.mnuFile, this.mnuCode, this.debugToolStripMenuItem, this.searchToolStripMenuItem, @@ -442,47 +445,57 @@ namespace Mesen.GUI.Debugger this.menuStrip.TabIndex = 2; this.menuStrip.Text = "menuStrip1"; // - // fileToolStripMenuItem + // mnuFile // - this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.mnuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mnuSaveRom, + this.mnuSaveRomAs, this.mnuSaveAsIps, - this.mnuEditHeader, + this.mnuRevertChanges, this.toolStripMenuItem14, this.mnuWorkspace, this.toolStripMenuItem3, this.mnuClose}); - this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); - this.fileToolStripMenuItem.Text = "File"; + this.mnuFile.Name = "mnuFile"; + this.mnuFile.Size = new System.Drawing.Size(37, 20); + this.mnuFile.Text = "File"; + this.mnuFile.DropDownOpening += new System.EventHandler(this.mnuFile_DropDownOpening); // // mnuSaveRom // this.mnuSaveRom.Image = global::Mesen.GUI.Properties.Resources.Floppy; this.mnuSaveRom.Name = "mnuSaveRom"; - this.mnuSaveRom.Size = new System.Drawing.Size(162, 22); - this.mnuSaveRom.Text = "Save ROM as..."; + this.mnuSaveRom.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.mnuSaveRom.Size = new System.Drawing.Size(208, 22); + this.mnuSaveRom.Text = "Save ROM"; this.mnuSaveRom.Click += new System.EventHandler(this.mnuSaveRom_Click); // + // mnuSaveRomAs + // + this.mnuSaveRomAs.Name = "mnuSaveRomAs"; + this.mnuSaveRomAs.Size = new System.Drawing.Size(208, 22); + this.mnuSaveRomAs.Text = "Save ROM as..."; + this.mnuSaveRomAs.Click += new System.EventHandler(this.mnuSaveRomAs_Click); + // // mnuSaveAsIps // this.mnuSaveAsIps.Name = "mnuSaveAsIps"; - this.mnuSaveAsIps.Size = new System.Drawing.Size(162, 22); + this.mnuSaveAsIps.Size = new System.Drawing.Size(208, 22); this.mnuSaveAsIps.Text = "Save edits as IPS"; this.mnuSaveAsIps.Click += new System.EventHandler(this.mnuSaveAsIps_Click); // - // mnuEditHeader + // mnuRevertChanges // - this.mnuEditHeader.Image = global::Mesen.GUI.Properties.Resources.Edit; - this.mnuEditHeader.Name = "mnuEditHeader"; - this.mnuEditHeader.Size = new System.Drawing.Size(162, 22); - this.mnuEditHeader.Text = "Edit iNES Header"; - this.mnuEditHeader.Click += new System.EventHandler(this.mnuEditHeader_Click); + this.mnuRevertChanges.Image = global::Mesen.GUI.Properties.Resources.Undo; + this.mnuRevertChanges.Name = "mnuRevertChanges"; + this.mnuRevertChanges.Size = new System.Drawing.Size(208, 22); + this.mnuRevertChanges.Text = "Revert PRG/CHR changes"; + this.mnuRevertChanges.Click += new System.EventHandler(this.mnuRevertChanges_Click); // // toolStripMenuItem14 // this.toolStripMenuItem14.Name = "toolStripMenuItem14"; - this.toolStripMenuItem14.Size = new System.Drawing.Size(159, 6); + this.toolStripMenuItem14.Size = new System.Drawing.Size(205, 6); // // mnuWorkspace // @@ -496,7 +509,7 @@ namespace Mesen.GUI.Debugger this.mnuAutoLoadCdlFiles, this.mnuDisableDefaultLabels}); this.mnuWorkspace.Name = "mnuWorkspace"; - this.mnuWorkspace.Size = new System.Drawing.Size(162, 22); + this.mnuWorkspace.Size = new System.Drawing.Size(208, 22); this.mnuWorkspace.Text = "Workspace"; // // mnuImportLabels @@ -541,6 +554,14 @@ namespace Mesen.GUI.Debugger this.mnuAutoLoadDbgFiles.Text = "Auto-load DBG/MLB files"; this.mnuAutoLoadDbgFiles.Click += new System.EventHandler(this.mnuAutoLoadDbgFiles_Click); // + // mnuAutoLoadCdlFiles + // + this.mnuAutoLoadCdlFiles.CheckOnClick = true; + this.mnuAutoLoadCdlFiles.Name = "mnuAutoLoadCdlFiles"; + this.mnuAutoLoadCdlFiles.Size = new System.Drawing.Size(207, 22); + this.mnuAutoLoadCdlFiles.Text = "Auto-load CDL files"; + this.mnuAutoLoadCdlFiles.Click += new System.EventHandler(this.mnuAutoLoadCdlFiles_Click); + // // mnuDisableDefaultLabels // this.mnuDisableDefaultLabels.CheckOnClick = true; @@ -552,13 +573,13 @@ namespace Mesen.GUI.Debugger // toolStripMenuItem3 // this.toolStripMenuItem3.Name = "toolStripMenuItem3"; - this.toolStripMenuItem3.Size = new System.Drawing.Size(159, 6); + this.toolStripMenuItem3.Size = new System.Drawing.Size(205, 6); // // mnuClose // this.mnuClose.Image = global::Mesen.GUI.Properties.Resources.Exit; this.mnuClose.Name = "mnuClose"; - this.mnuClose.Size = new System.Drawing.Size(162, 22); + this.mnuClose.Size = new System.Drawing.Size(208, 22); this.mnuClose.Text = "Close"; this.mnuClose.Click += new System.EventHandler(this.mnuClose_Click); // @@ -1090,6 +1111,8 @@ namespace Mesen.GUI.Debugger this.mnuPpuViewer, this.mnuTraceLogger, this.toolStripMenuItem13, + this.mnuEditHeader, + this.toolStripMenuItem17, this.mnuCodeDataLogger}); this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; this.toolsToolStripMenuItem.Size = new System.Drawing.Size(48, 20); @@ -1136,6 +1159,19 @@ namespace Mesen.GUI.Debugger this.toolStripMenuItem13.Name = "toolStripMenuItem13"; this.toolStripMenuItem13.Size = new System.Drawing.Size(193, 6); // + // mnuEditHeader + // + this.mnuEditHeader.Image = global::Mesen.GUI.Properties.Resources.Edit; + this.mnuEditHeader.Name = "mnuEditHeader"; + this.mnuEditHeader.Size = new System.Drawing.Size(196, 22); + this.mnuEditHeader.Text = "Edit iNES Header"; + this.mnuEditHeader.Click += new System.EventHandler(this.mnuEditHeader_Click); + // + // toolStripMenuItem17 + // + this.toolStripMenuItem17.Name = "toolStripMenuItem17"; + this.toolStripMenuItem17.Size = new System.Drawing.Size(193, 6); + // // mnuCodeDataLogger // this.mnuCodeDataLogger.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -1288,14 +1324,6 @@ namespace Mesen.GUI.Debugger this.ctrlCpuMemoryMapping.Text = "ctrlMemoryMapping1"; this.ctrlCpuMemoryMapping.Visible = false; // - // mnuAutoLoadCdlFiles - // - this.mnuAutoLoadCdlFiles.CheckOnClick = true; - this.mnuAutoLoadCdlFiles.Name = "mnuAutoLoadCdlFiles"; - this.mnuAutoLoadCdlFiles.Size = new System.Drawing.Size(207, 22); - this.mnuAutoLoadCdlFiles.Text = "Auto-load CDL files"; - this.mnuAutoLoadCdlFiles.Click += new System.EventHandler(this.mnuAutoLoadCdlFiles_Click); - // // frmDebugger // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1344,7 +1372,7 @@ namespace Mesen.GUI.Debugger private System.Windows.Forms.GroupBox grpBreakpoints; private System.Windows.Forms.GroupBox grpWatch; private System.Windows.Forms.MenuStrip menuStrip; - private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem mnuFile; private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem mnuContinue; private System.Windows.Forms.ToolStripMenuItem mnuBreak; @@ -1444,7 +1472,7 @@ namespace Mesen.GUI.Debugger private System.Windows.Forms.ToolStripSeparator toolStripMenuItem13; private System.Windows.Forms.ToolStripMenuItem mnuBreakOnUnofficialOpcodes; private System.Windows.Forms.ToolStripMenuItem mnuBreakOnBrk; - private System.Windows.Forms.ToolStripMenuItem mnuSaveRom; + private System.Windows.Forms.ToolStripMenuItem mnuSaveRomAs; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem14; private System.Windows.Forms.ToolStripMenuItem mnuAssembler; private System.Windows.Forms.ToolStripMenuItem mnuCode; @@ -1456,10 +1484,13 @@ namespace Mesen.GUI.Debugger private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; private System.Windows.Forms.ToolStripStatusLabel lblCyclesElapsedCount; private System.Windows.Forms.ToolStripStatusLabel lblCyclesElapsed; - private System.Windows.Forms.ToolStripMenuItem mnuEditHeader; private System.Windows.Forms.ToolStripMenuItem mnuExportLabels; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem16; private System.Windows.Forms.ToolStripMenuItem mnuSaveAsIps; private System.Windows.Forms.ToolStripMenuItem mnuAutoLoadCdlFiles; + private System.Windows.Forms.ToolStripMenuItem mnuSaveRom; + private System.Windows.Forms.ToolStripMenuItem mnuEditHeader; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem17; + private System.Windows.Forms.ToolStripMenuItem mnuRevertChanges; } } \ No newline at end of file diff --git a/GUI.NET/Debugger/frmDebugger.cs b/GUI.NET/Debugger/frmDebugger.cs index fde7a15e..9c2ac62d 100644 --- a/GUI.NET/Debugger/frmDebugger.cs +++ b/GUI.NET/Debugger/frmDebugger.cs @@ -127,8 +127,6 @@ namespace Mesen.GUI.Debugger UpdateDebuggerFlags(); UpdateCdlRatios(); tmrCdlRatios.Start(); - - mnuEditHeader.Enabled = mnuSaveRom.Enabled = InteropEmu.GetRomInfo().Format == RomFormat.iNes; } protected override void OnActivated(EventArgs e) @@ -148,6 +146,22 @@ namespace Mesen.GUI.Debugger } } + private void mnuFile_DropDownOpening(object sender, EventArgs e) + { + UpdateFileOptions(); + } + + private void UpdateFileOptions() + { + bool hasChanges = InteropEmu.DebugHasPrgChrChanges(); + RomInfo romInfo = InteropEmu.GetRomInfo(); + mnuSaveRom.Enabled = romInfo.Format == RomFormat.iNes && hasChanges && !romInfo.RomFile.Compressed; + mnuSaveAsIps.Enabled = romInfo.Format == RomFormat.iNes && hasChanges; + mnuRevertChanges.Enabled = hasChanges; + mnuSaveRomAs.Enabled = romInfo.Format == RomFormat.iNes; + mnuEditHeader.Enabled = romInfo.Format == RomFormat.iNes; + } + private void AutoLoadCdlFiles() { if(ConfigManager.Config.DebugInfo.AutoLoadCdlFiles) { @@ -156,7 +170,7 @@ namespace Mesen.GUI.Debugger string cdlPath = Path.Combine(info.RomFile.Folder, info.GetRomName() + ".cdl"); if(File.Exists(cdlPath)) { if(InteropEmu.DebugLoadCdlFile(cdlPath)) { - UpdateDebugger(); + UpdateDebugger(false); } } } @@ -245,8 +259,6 @@ namespace Mesen.GUI.Debugger case InteropEmu.ConsoleNotificationType.GameReset: case InteropEmu.ConsoleNotificationType.GameLoaded: this.BeginInvoke((MethodInvoker)(() => { - mnuEditHeader.Enabled = mnuSaveRom.Enabled = InteropEmu.GetRomInfo().Format == RomFormat.iNes; - this.UpdateWorkspace(); this.AutoLoadCdlFiles(); this.AutoLoadDbgFiles(true); @@ -605,7 +617,7 @@ namespace Mesen.GUI.Debugger private void mnuResetCdlLog_Click(object sender, EventArgs e) { InteropEmu.DebugResetCdlLog(); - UpdateDebugger(); + UpdateDebugger(false); } private void ctrlBreakpoints_BreakpointNavigation(object sender, EventArgs e) @@ -823,7 +835,7 @@ namespace Mesen.GUI.Debugger ConfigManager.ApplyChanges(); UpdateDebuggerFlags(); - UpdateDebugger(); + UpdateDebugger(false); } private void mnuDisassembleVerifiedCodeOnly_Click(object sender, EventArgs e) @@ -886,8 +898,13 @@ namespace Mesen.GUI.Debugger splitContainer.CollapsePanel(); } } - + private void mnuSaveRom_Click(object sender, EventArgs e) + { + InteropEmu.DebugSaveRomToDisk(InteropEmu.GetRomInfo().RomFile.Path); + } + + private void mnuSaveRomAs_Click(object sender, EventArgs e) { using(SaveFileDialog sfd = new SaveFileDialog()) { sfd.SetFilter("NES roms (*.nes)|*.nes"); @@ -911,6 +928,12 @@ namespace Mesen.GUI.Debugger } } + private void mnuRevertChanges_Click(object sender, EventArgs e) + { + InteropEmu.DebugRevertPrgChrChanges(); + UpdateDebugger(false); + } + private void mnuEditHeader_Click(object sender, EventArgs e) { using(frmEditHeader frm = new frmEditHeader()) { diff --git a/GUI.NET/GUI.NET.csproj b/GUI.NET/GUI.NET.csproj index 410991f0..534f8247 100644 --- a/GUI.NET/GUI.NET.csproj +++ b/GUI.NET/GUI.NET.csproj @@ -759,6 +759,7 @@ + diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index e1dfac3c..632ef408 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -246,6 +246,9 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void DebugResetMemoryAccessCounts(); [DllImport(DLLPath)] public static extern void DebugResetProfiler(); + [DllImport(DLLPath)] public static extern void DebugRevertPrgChrChanges(); + [DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool DebugHasPrgChrChanges(); + [DllImport(DLLPath, EntryPoint = "DebugGetNesHeader")] public static extern void DebugGetNesHeaderWrapper(IntPtr headerBuffer); public static byte[] DebugGetNesHeader() { diff --git a/GUI.NET/Properties/Resources.Designer.cs b/GUI.NET/Properties/Resources.Designer.cs index a4a93616..33b144f7 100644 --- a/GUI.NET/Properties/Resources.Designer.cs +++ b/GUI.NET/Properties/Resources.Designer.cs @@ -720,6 +720,16 @@ namespace Mesen.GUI.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Undo { + get { + object obj = ResourceManager.GetObject("Undo", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/GUI.NET/Properties/Resources.resx b/GUI.NET/Properties/Resources.resx index 24c039b0..1adb3085 100644 --- a/GUI.NET/Properties/Resources.resx +++ b/GUI.NET/Properties/Resources.resx @@ -334,4 +334,7 @@ ..\Resources\ShuffleEnabled.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Undo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/GUI.NET/Resources/Undo.png b/GUI.NET/Resources/Undo.png new file mode 100644 index 00000000..8b0fef9a Binary files /dev/null and b/GUI.NET/Resources/Undo.png differ diff --git a/InteropDLL/DebugWrapper.cpp b/InteropDLL/DebugWrapper.cpp index d118d93c..19fb2c7e 100644 --- a/InteropDLL/DebugWrapper.cpp +++ b/InteropDLL/DebugWrapper.cpp @@ -104,6 +104,8 @@ extern "C" DllExport void __stdcall DebugGetNesHeader(uint8_t* header) { GetDebugger()->GetNesHeader(header); } DllExport void __stdcall DebugSaveRomToDisk(char* filename, bool saveIpsFile, uint8_t* header) { GetDebugger()->SaveRomToDisk(filename, saveIpsFile, header); } + DllExport bool __stdcall DebugHasPrgChrChanges() { return GetDebugger()->HasPrgChrChanges(); } + DllExport void __stdcall DebugRevertPrgChrChanges() { GetDebugger()->RevertPrgChrChanges(); } DllExport int32_t __stdcall DebugFindSubEntryPoint(uint16_t relativeAddress) { return GetDebugger()->FindSubEntryPoint(relativeAddress); }