diff --git a/Core/BaseMapper.cpp b/Core/BaseMapper.cpp index 4832e50c..b7f0c71b 100644 --- a/Core/BaseMapper.cpp +++ b/Core/BaseMapper.cpp @@ -1076,32 +1076,31 @@ NESHeader BaseMapper::GetNesHeader() return _nesHeader; } -void BaseMapper::SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header) +void BaseMapper::GetRomFileData(vector &out, bool asIpsFile, uint8_t* header) { - ofstream file(filename, ios::out | ios::binary); - if(file.good()) { + if(header) { + //Get original rom with edited header vector originalFile; Console::GetRomPath().ReadFile(originalFile); - - if(header) { - //Save original rom with edited header - file.write((char*)header, sizeof(NESHeader)); - file.write((char*)originalFile.data()+sizeof(NESHeader), originalFile.size() - sizeof(NESHeader)); - } else { - vector newFile; - newFile.insert(newFile.end(), (uint8_t*)&_nesHeader, ((uint8_t*)&_nesHeader) + sizeof(NESHeader)); - newFile.insert(newFile.end(), _prgRom, _prgRom + _prgSize); - newFile.insert(newFile.end(), _chrRom, _chrRom + _chrRomSize); - //Save edited rom - if(saveAsIps) { - vector patchData = IpsPatcher::CreatePatch(originalFile, newFile); - file.write((char*)patchData.data(), patchData.size()); - } else { - file.write((char*)newFile.data(), newFile.size()); - } + out.insert(out.end(), header, header+sizeof(NESHeader)); + out.insert(out.end(), originalFile.begin()+sizeof(NESHeader), originalFile.end()); + } else { + vector newFile; + newFile.insert(newFile.end(), (uint8_t*)&_nesHeader, ((uint8_t*)&_nesHeader) + sizeof(NESHeader)); + newFile.insert(newFile.end(), _prgRom, _prgRom + _prgSize); + newFile.insert(newFile.end(), _chrRom, _chrRom + _chrRomSize); + + //Get edited rom + if(asIpsFile) { + vector originalFile; + Console::GetRomPath().ReadFile(originalFile); + + vector patchData = IpsPatcher::CreatePatch(originalFile, newFile); + out.insert(out.end(), patchData.begin(), patchData.end()); + } else { + out.insert(out.end(), newFile.begin(), newFile.end()); } - file.close(); } } diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index 0925efc9..bcadb9a5 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -228,7 +228,7 @@ public: int32_t FromAbsoluteAddress(uint32_t addr, AddressType type = AddressType::PrgRom); NESHeader GetNesHeader(); - void SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header); + void GetRomFileData(vector &out, bool asIpsFile, uint8_t* header); void RevertPrgChrChanges(); bool HasPrgChrChanges(); }; \ No newline at end of file diff --git a/Core/CodeDataLogger.cpp b/Core/CodeDataLogger.cpp index 46fec057..c80faf69 100644 --- a/Core/CodeDataLogger.cpp +++ b/Core/CodeDataLogger.cpp @@ -187,3 +187,20 @@ void CodeDataLogger::GetCdlData(uint32_t offset, uint32_t length, DebugMemoryTyp } } } + +void CodeDataLogger::StripData(uint8_t *romBuffer, CdlStripFlag flag) +{ + if(flag == CdlStripFlag::StripUnused) { + for(uint32_t i = 0; i < _prgSize + _chrSize; i++) { + if(_cdlData[i] == 0) { + romBuffer[i] = 0; + } + } + } else if(flag == CdlStripFlag::StripUsed) { + for(uint32_t i = 0; i < _prgSize + _chrSize; i++) { + if(_cdlData[i] != 0) { + romBuffer[i] = 0; + } + } + } +} diff --git a/Core/CodeDataLogger.h b/Core/CodeDataLogger.h index 12aa4edf..a8f71baf 100644 --- a/Core/CodeDataLogger.h +++ b/Core/CodeDataLogger.h @@ -22,6 +22,13 @@ enum class CdlChrFlags Read = 0x02, }; +enum class CdlStripFlag +{ + StripNone = 0, + StripUnused, + StripUsed, +}; + struct CdlRatios { float CodeRatio; @@ -70,4 +77,6 @@ public: bool IsDrawn(uint32_t absoluteAddr); void GetCdlData(uint32_t offset, uint32_t length, DebugMemoryType memoryType, uint8_t* cdlData); + + void StripData(uint8_t* romBuffer, CdlStripFlag flag); }; \ No newline at end of file diff --git a/Core/Debugger.cpp b/Core/Debugger.cpp index 4731af3e..1e093a67 100644 --- a/Core/Debugger.cpp +++ b/Core/Debugger.cpp @@ -1013,9 +1013,18 @@ void Debugger::GetNesHeader(uint8_t* header) memcpy(header, &nesHeader, sizeof(NESHeader)); } -void Debugger::SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header) +void Debugger::SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header, CdlStripFlag cdlStripflag) { - _mapper->SaveRomToDisk(filename, saveAsIps, header); + vector fileData; + _mapper->GetRomFileData(fileData, saveAsIps, header); + + _codeDataLogger->StripData(fileData.data() + sizeof(NESHeader), cdlStripflag); + + ofstream file(filename, ios::out | ios::binary); + if(file.good()) { + file.write((char*)fileData.data(), fileData.size()); + file.close(); + } } void Debugger::RevertPrgChrChanges() diff --git a/Core/Debugger.h b/Core/Debugger.h index 3f55bc0f..d393602b 100644 --- a/Core/Debugger.h +++ b/Core/Debugger.h @@ -219,7 +219,7 @@ public: void StopCodeRunner(); void GetNesHeader(uint8_t* header); - void SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header); + void SaveRomToDisk(string filename, bool saveAsIps, uint8_t* header, CdlStripFlag cdlStripflag); void RevertPrgChrChanges(); bool HasPrgChrChanges(); diff --git a/GUI.NET/Debugger/frmDebugger.Designer.cs b/GUI.NET/Debugger/frmDebugger.Designer.cs index e3021339..a415a62a 100644 --- a/GUI.NET/Debugger/frmDebugger.Designer.cs +++ b/GUI.NET/Debugger/frmDebugger.Designer.cs @@ -143,9 +143,9 @@ namespace Mesen.GUI.Debugger this.mnuLoadCdlFile = new System.Windows.Forms.ToolStripMenuItem(); this.mnuSaveAsCdlFile = new System.Windows.Forms.ToolStripMenuItem(); this.mnuResetCdlLog = new System.Windows.Forms.ToolStripMenuItem(); - this.generateROMToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveStrippedDataToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveUnusedDataToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuCdlGenerateRom = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuCdlStripUsedData = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuCdlStripUnusedData = new System.Windows.Forms.ToolStripMenuItem(); this.statusStrip = new System.Windows.Forms.StatusStrip(); this.lblPrgAnalysis = new System.Windows.Forms.ToolStripStatusLabel(); this.lblPrgAnalysisResult = new System.Windows.Forms.ToolStripStatusLabel(); @@ -156,6 +156,7 @@ 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.toolStripMenuItem5 = new System.Windows.Forms.ToolStripSeparator(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); this.splitContainer.Panel1.SuspendLayout(); this.splitContainer.Panel2.SuspendLayout(); @@ -225,7 +226,7 @@ namespace Mesen.GUI.Debugger this.ctrlSplitContainerTop.Panel2.Controls.Add(this.tlpFunctionLabelLists); this.ctrlSplitContainerTop.Panel2MinSize = 150; this.ctrlSplitContainerTop.Size = new System.Drawing.Size(1172, 400); - this.ctrlSplitContainerTop.SplitterDistance = 866; + this.ctrlSplitContainerTop.SplitterDistance = 860; this.ctrlSplitContainerTop.SplitterWidth = 7; this.ctrlSplitContainerTop.TabIndex = 3; this.ctrlSplitContainerTop.PanelCollapsed += new System.EventHandler(this.ctrlSplitContainerTop_PanelCollapsed); @@ -246,7 +247,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(866, 400); + this.tlpTop.Size = new System.Drawing.Size(860, 400); this.tlpTop.TabIndex = 2; // // ctrlDebuggerCode @@ -255,7 +256,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(402, 394); + this.ctrlDebuggerCode.Size = new System.Drawing.Size(396, 394); 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); @@ -264,7 +265,7 @@ namespace Mesen.GUI.Debugger // ctrlConsoleStatus // this.ctrlConsoleStatus.Dock = System.Windows.Forms.DockStyle.Fill; - this.ctrlConsoleStatus.Location = new System.Drawing.Point(408, 0); + this.ctrlConsoleStatus.Location = new System.Drawing.Point(402, 0); this.ctrlConsoleStatus.Margin = new System.Windows.Forms.Padding(0); this.ctrlConsoleStatus.Name = "ctrlConsoleStatus"; this.ctrlConsoleStatus.Size = new System.Drawing.Size(458, 400); @@ -275,7 +276,7 @@ namespace Mesen.GUI.Debugger // this.ctrlDebuggerCodeSplit.Code = null; this.ctrlDebuggerCodeSplit.Dock = System.Windows.Forms.DockStyle.Fill; - this.ctrlDebuggerCodeSplit.Location = new System.Drawing.Point(411, 3); + this.ctrlDebuggerCodeSplit.Location = new System.Drawing.Point(405, 3); this.ctrlDebuggerCodeSplit.Name = "ctrlDebuggerCodeSplit"; this.ctrlDebuggerCodeSplit.Size = new System.Drawing.Size(1, 394); this.ctrlDebuggerCodeSplit.TabIndex = 4; @@ -297,7 +298,7 @@ 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(299, 400); + this.tlpFunctionLabelLists.Size = new System.Drawing.Size(305, 400); this.tlpFunctionLabelLists.TabIndex = 5; // // grpLabels @@ -306,7 +307,7 @@ namespace Mesen.GUI.Debugger this.grpLabels.Dock = System.Windows.Forms.DockStyle.Fill; this.grpLabels.Location = new System.Drawing.Point(3, 203); this.grpLabels.Name = "grpLabels"; - this.grpLabels.Size = new System.Drawing.Size(293, 194); + this.grpLabels.Size = new System.Drawing.Size(299, 194); this.grpLabels.TabIndex = 6; this.grpLabels.TabStop = false; this.grpLabels.Text = "Labels"; @@ -316,7 +317,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(287, 175); + this.ctrlLabelList.Size = new System.Drawing.Size(293, 175); this.ctrlLabelList.TabIndex = 0; this.ctrlLabelList.OnFindOccurrence += new System.EventHandler(this.ctrlLabelList_OnFindOccurrence); this.ctrlLabelList.OnLabelSelected += new System.EventHandler(this.ctrlLabelList_OnLabelSelected); @@ -327,7 +328,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(293, 194); + this.grpFunctions.Size = new System.Drawing.Size(299, 194); this.grpFunctions.TabIndex = 5; this.grpFunctions.TabStop = false; this.grpFunctions.Text = "Functions"; @@ -337,7 +338,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(287, 175); + this.ctrlFunctionList.Size = new System.Drawing.Size(293, 175); this.ctrlFunctionList.TabIndex = 0; this.ctrlFunctionList.OnFindOccurrence += new System.EventHandler(this.ctrlFunctionList_OnFindOccurrence); this.ctrlFunctionList.OnFunctionSelected += new System.EventHandler(this.ctrlFunctionList_OnFunctionSelected); @@ -1184,7 +1185,8 @@ namespace Mesen.GUI.Debugger this.mnuLoadCdlFile, this.mnuSaveAsCdlFile, this.mnuResetCdlLog, - this.generateROMToolStripMenuItem}); + this.toolStripMenuItem5, + this.mnuCdlGenerateRom}); this.mnuCodeDataLogger.Name = "mnuCodeDataLogger"; this.mnuCodeDataLogger.Size = new System.Drawing.Size(195, 22); this.mnuCodeDataLogger.Text = "Code/Data Logger"; @@ -1205,6 +1207,7 @@ namespace Mesen.GUI.Debugger // // mnuLoadCdlFile // + this.mnuLoadCdlFile.Image = global::Mesen.GUI.Properties.Resources.FolderOpen; this.mnuLoadCdlFile.Name = "mnuLoadCdlFile"; this.mnuLoadCdlFile.Size = new System.Drawing.Size(193, 22); this.mnuLoadCdlFile.Text = "Load CDL file..."; @@ -1212,6 +1215,7 @@ namespace Mesen.GUI.Debugger // // mnuSaveAsCdlFile // + this.mnuSaveAsCdlFile.Image = global::Mesen.GUI.Properties.Resources.Floppy; this.mnuSaveAsCdlFile.Name = "mnuSaveAsCdlFile"; this.mnuSaveAsCdlFile.Size = new System.Drawing.Size(193, 22); this.mnuSaveAsCdlFile.Text = "Save as CDL file..."; @@ -1219,32 +1223,35 @@ namespace Mesen.GUI.Debugger // // mnuResetCdlLog // + this.mnuResetCdlLog.Image = global::Mesen.GUI.Properties.Resources.Reset; this.mnuResetCdlLog.Name = "mnuResetCdlLog"; this.mnuResetCdlLog.Size = new System.Drawing.Size(193, 22); this.mnuResetCdlLog.Text = "Reset log"; this.mnuResetCdlLog.Click += new System.EventHandler(this.mnuResetCdlLog_Click); // - // generateROMToolStripMenuItem + // mnuCdlGenerateRom // - this.generateROMToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.saveStrippedDataToolStripMenuItem, - this.saveUnusedDataToolStripMenuItem}); - this.generateROMToolStripMenuItem.Enabled = false; - this.generateROMToolStripMenuItem.Name = "generateROMToolStripMenuItem"; - this.generateROMToolStripMenuItem.Size = new System.Drawing.Size(193, 22); - this.generateROMToolStripMenuItem.Text = "Generate ROM"; + this.mnuCdlGenerateRom.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.mnuCdlStripUnusedData, + this.mnuCdlStripUsedData}); + this.mnuCdlGenerateRom.Image = global::Mesen.GUI.Properties.Resources.Copy; + this.mnuCdlGenerateRom.Name = "mnuCdlGenerateRom"; + this.mnuCdlGenerateRom.Size = new System.Drawing.Size(193, 22); + this.mnuCdlGenerateRom.Text = "Generate ROM"; // - // saveStrippedDataToolStripMenuItem + // mnuCdlStripUsedData // - this.saveStrippedDataToolStripMenuItem.Name = "saveStrippedDataToolStripMenuItem"; - this.saveStrippedDataToolStripMenuItem.Size = new System.Drawing.Size(170, 22); - this.saveStrippedDataToolStripMenuItem.Text = "Save stripped data"; + this.mnuCdlStripUsedData.Name = "mnuCdlStripUsedData"; + this.mnuCdlStripUsedData.Size = new System.Drawing.Size(166, 22); + this.mnuCdlStripUsedData.Text = "Strip used data"; + this.mnuCdlStripUsedData.Click += new System.EventHandler(this.mnuCdlStripUsedData_Click); // - // saveUnusedDataToolStripMenuItem + // mnuCdlStripUnusedData // - this.saveUnusedDataToolStripMenuItem.Name = "saveUnusedDataToolStripMenuItem"; - this.saveUnusedDataToolStripMenuItem.Size = new System.Drawing.Size(170, 22); - this.saveUnusedDataToolStripMenuItem.Text = "Save unused data"; + this.mnuCdlStripUnusedData.Name = "mnuCdlStripUnusedData"; + this.mnuCdlStripUnusedData.Size = new System.Drawing.Size(166, 22); + this.mnuCdlStripUnusedData.Text = "Strip unused data"; + this.mnuCdlStripUnusedData.Click += new System.EventHandler(this.mnuCdlStripUnusedData_Click); // // statusStrip // @@ -1328,6 +1335,11 @@ namespace Mesen.GUI.Debugger this.ctrlCpuMemoryMapping.Text = "ctrlMemoryMapping1"; this.ctrlCpuMemoryMapping.Visible = false; // + // toolStripMenuItem5 + // + this.toolStripMenuItem5.Name = "toolStripMenuItem5"; + this.toolStripMenuItem5.Size = new System.Drawing.Size(190, 6); + // // frmDebugger // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1421,9 +1433,9 @@ namespace Mesen.GUI.Debugger private System.Windows.Forms.ToolStripMenuItem mnuLoadCdlFile; private System.Windows.Forms.ToolStripMenuItem mnuSaveAsCdlFile; private System.Windows.Forms.ToolStripMenuItem mnuResetCdlLog; - private System.Windows.Forms.ToolStripMenuItem generateROMToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveStrippedDataToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveUnusedDataToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem mnuCdlGenerateRom; + private System.Windows.Forms.ToolStripMenuItem mnuCdlStripUsedData; + private System.Windows.Forms.ToolStripMenuItem mnuCdlStripUnusedData; private System.Windows.Forms.ToolStripMenuItem mnuDisableEnableBreakpoint; private System.Windows.Forms.ToolStripMenuItem mnuGoToAddress; private System.Windows.Forms.ToolStripMenuItem mnuGoToIrqHandler; @@ -1496,5 +1508,6 @@ namespace Mesen.GUI.Debugger private System.Windows.Forms.ToolStripSeparator toolStripMenuItem17; private System.Windows.Forms.ToolStripMenuItem mnuRevertChanges; private System.Windows.Forms.ToolStripMenuItem mnuScriptWindow; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem5; } } \ No newline at end of file diff --git a/GUI.NET/Debugger/frmDebugger.cs b/GUI.NET/Debugger/frmDebugger.cs index 8b30553f..9dd0c4ff 100644 --- a/GUI.NET/Debugger/frmDebugger.cs +++ b/GUI.NET/Debugger/frmDebugger.cs @@ -165,6 +165,9 @@ namespace Mesen.GUI.Debugger mnuRevertChanges.Enabled = hasChanges; mnuSaveRomAs.Enabled = romInfo.Format == RomFormat.iNes; mnuEditHeader.Enabled = romInfo.Format == RomFormat.iNes; + + mnuCdlStripUnusedData.Enabled = romInfo.Format == RomFormat.iNes; + mnuCdlStripUsedData.Enabled = romInfo.Format == RomFormat.iNes; } private void AutoLoadCdlFiles() @@ -936,6 +939,18 @@ namespace Mesen.GUI.Debugger } } } + + private void SaveRomWithCdlStripping(CdlStripFlag cdlStripFlag) + { + using(SaveFileDialog sfd = new SaveFileDialog()) { + sfd.SetFilter("NES roms (*.nes)|*.nes"); + sfd.FileName = InteropEmu.GetRomInfo().GetRomName() + (cdlStripFlag == CdlStripFlag.StripUnused ? "_StripUnusedData.nes" : "_StripUsedData.nes"); + sfd.InitialDirectory = ConfigManager.DebuggerFolder; + if(sfd.ShowDialog() == DialogResult.OK) { + InteropEmu.DebugSaveRomToDisk(sfd.FileName, false, null, cdlStripFlag); + } + } + } private void mnuRevertChanges_Click(object sender, EventArgs e) { @@ -979,5 +994,15 @@ namespace Mesen.GUI.Debugger } this._lastCodeWindow.ContextMenuItems = items; } + + private void mnuCdlStripUsedData_Click(object sender, EventArgs e) + { + SaveRomWithCdlStripping(CdlStripFlag.StripUsed); + } + + private void mnuCdlStripUnusedData_Click(object sender, EventArgs e) + { + SaveRomWithCdlStripping(CdlStripFlag.StripUnused); + } } } diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 9a863322..55ccca60 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -287,18 +287,18 @@ namespace Mesen.GUI return header; } - [DllImport(DLLPath, EntryPoint = "DebugSaveRomToDisk")] public static extern void DebugSaveRomToDiskWrapper([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string filename, [MarshalAs(UnmanagedType.I1)]bool saveAsIps, IntPtr headerBuffer); - public static void DebugSaveRomToDisk(string filename, bool saveAsIps = false, byte[] header = null) + [DllImport(DLLPath, EntryPoint = "DebugSaveRomToDisk")] public static extern void DebugSaveRomToDiskWrapper([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string filename, [MarshalAs(UnmanagedType.I1)]bool saveAsIps, IntPtr headerBuffer, CdlStripFlag cdlStripFlag); + public static void DebugSaveRomToDisk(string filename, bool saveAsIps = false, byte[] header = null, CdlStripFlag cdlStripFlag = CdlStripFlag.StripNone) { if(header != null) { GCHandle handle = GCHandle.Alloc(header, GCHandleType.Pinned); try { - InteropEmu.DebugSaveRomToDiskWrapper(filename, saveAsIps, handle.AddrOfPinnedObject()); + InteropEmu.DebugSaveRomToDiskWrapper(filename, saveAsIps, handle.AddrOfPinnedObject(), cdlStripFlag); } finally { handle.Free(); } } else { - InteropEmu.DebugSaveRomToDiskWrapper(filename, saveAsIps, IntPtr.Zero); + InteropEmu.DebugSaveRomToDiskWrapper(filename, saveAsIps, IntPtr.Zero, cdlStripFlag); } } @@ -1040,6 +1040,13 @@ namespace Mesen.GUI HighlightUnused = 2 } + public enum CdlStripFlag + { + StripNone = 0, + StripUnused = 1, + StripUsed = 2 + } + public struct DebugState { public CPUState CPU; diff --git a/InteropDLL/DebugWrapper.cpp b/InteropDLL/DebugWrapper.cpp index 6847f670..182a268e 100644 --- a/InteropDLL/DebugWrapper.cpp +++ b/InteropDLL/DebugWrapper.cpp @@ -105,7 +105,7 @@ extern "C" DllExport void __stdcall DebugStartCodeRunner(uint8_t* byteCode, uint32_t codeLength) { return GetDebugger()->StartCodeRunner(byteCode, codeLength); } 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 void __stdcall DebugSaveRomToDisk(char* filename, bool saveIpsFile, uint8_t* header, CdlStripFlag cdlStripFlag) { GetDebugger()->SaveRomToDisk(filename, saveIpsFile, header, cdlStripFlag); } DllExport bool __stdcall DebugHasPrgChrChanges() { return GetDebugger()->HasPrgChrChanges(); } DllExport void __stdcall DebugRevertPrgChrChanges() { GetDebugger()->RevertPrgChrChanges(); }