diff --git a/Core/EmuSettings.cpp b/Core/EmuSettings.cpp index 39e74db..20bd993 100644 --- a/Core/EmuSettings.cpp +++ b/Core/EmuSettings.cpp @@ -4,6 +4,7 @@ #include "KeyManager.h" #include "MessageManager.h" #include "Console.h" +#include "SpcDisUtils.h" #include "NotificationManager.h" #include "../Utilities/FolderUtilities.h" @@ -277,6 +278,10 @@ void EmuSettings::SetDebuggerFlag(DebuggerFlags flag, bool enabled) _debuggerFlags &= ~(int)flag; } } + + if(flag == DebuggerFlags::UseAltSpcOpNames) { + SpcDisUtils::UseAltSpcOpNames = enabled; + } } bool EmuSettings::CheckDebuggerFlag(DebuggerFlags flag) diff --git a/Core/SettingTypes.h b/Core/SettingTypes.h index 576e71c..29ba8ed 100644 --- a/Core/SettingTypes.h +++ b/Core/SettingTypes.h @@ -477,6 +477,8 @@ enum class DebuggerFlags : uint32_t ShowUnidentifiedData = 0x400, DisassembleUnidentifiedData = 0x800, + + UseAltSpcOpNames = 0x1000, GsuDebuggerEnabled = 0x10000000, Sa1DebuggerEnabled = 0x20000000, diff --git a/Core/SpcDebugger.cpp b/Core/SpcDebugger.cpp index d5eac16..ffbf15f 100644 --- a/Core/SpcDebugger.cpp +++ b/Core/SpcDebugger.cpp @@ -44,6 +44,8 @@ void SpcDebugger::ProcessRead(uint16_t addr, uint8_t value, MemoryOperationType MemoryOperationInfo operation { addr, value, type }; if(type == MemoryOperationType::ExecOpCode) { + BreakSource breakSource = BreakSource::Unspecified; + SpcState spcState = _spc->GetState(); if(_traceLogger->IsCpuLogged(CpuType::Spc) || _settings->CheckDebuggerFlag(DebuggerFlags::SpcDebuggerEnabled)) { @@ -79,6 +81,17 @@ void SpcDebugger::ProcessRead(uint16_t addr, uint8_t value, MemoryOperationType if(_step->StepCount > 0) { _step->StepCount--; } + + if(_settings->CheckDebuggerFlag(DebuggerFlags::SpcDebuggerEnabled)) { + //Break on BRK/STP + if(value == 0x0F && _settings->CheckDebuggerFlag(DebuggerFlags::BreakOnBrk)) { + breakSource = BreakSource::BreakOnBrk; + _step->StepCount = 0; + } else if(value == 0xFF && _settings->CheckDebuggerFlag(DebuggerFlags::BreakOnStp)) { + breakSource = BreakSource::BreakOnStp; + _step->StepCount = 0; + } + } } _debugger->ProcessBreakConditions(_step->StepCount == 0, GetBreakpointManager(), operation, addressInfo); diff --git a/Core/SpcDisUtils.cpp b/Core/SpcDisUtils.cpp index 009afc4..2c22b66 100644 --- a/Core/SpcDisUtils.cpp +++ b/Core/SpcDisUtils.cpp @@ -7,7 +7,9 @@ #include "../Utilities/FastString.h" #include "../Utilities/HexUtilities.h" -/*constexpr const char* _opTemplate[256] = { +bool SpcDisUtils::UseAltSpcOpNames = false; + +constexpr const char* _altOpTemplate[256] = { "NOP", "TCALL 0", "SET1 d.0", "BBS d.0, q", "OR A, d", "OR A, !a", "OR A, (X)", "OR A, [d+X]", "OR A, #i", "OR t, s", "OR1 C, m.b", "ASL d", "ASL !a", "PUSH PSW", "TSET1 !a", "BRK", "BPL r", "TCALL 1", "CLR1 d.0", "BBC d.0, q", "OR A, d+X", "OR A, !a+X", "OR A, !a+Y", "OR A, [d]+Y", "OR e, #i", "OR (X), (Y)", "DECW d", "ASL d+X", "ASL A", "DEC X", "CMP X, !a", "JMP [!a+X]", "CLRP", "TCALL 2", "SET1 d.1", "BBS d.1, q", "AND A, d", "AND A, !a", "AND A, (X)", "AND A, [d+X]", "AND A, #i", "AND t, s", "OR1 C, /m.b", "ROL d", "ROL !a", "PUSH A", "CBNE d, q", "BRA r", @@ -24,7 +26,7 @@ "BNE r", "TCALL 13", "CLR1 d.6", "BBC d.6, q", "MOV d+X, A", "MOV !a+X, A", "MOV !a+Y, A", "MOV [d]+Y, A", "MOV e, X", "MOV d+Y, X", "MOVW d, YA", "MOV d+X, Y", "DEC Y", "MOV A, Y", "CBNE d+X, q", "DAA A", "CLRV", "TCALL 14", "SET1 d.7", "BBS d.7, q", "MOV A, d", "MOV A, !a", "MOV A, (X)", "MOV A, [d+X]", "MOV A, #i", "MOV X, !a", "NOT1 m.b", "MOV Y, d", "MOV Y, !a","NOTC", "POP Y", "SLEEP", "BEQ r", "TCALL 15", "CLR1 d.7", "BBC d.7, q", "MOV A, d+X", "MOV A, !a+X", "MOV A, !a+Y", "MOV A, [d]+Y", "MOV X, d", "MOV X, d+Y", "MOV t, s", "MOV Y, d+X", "INC Y", "MOV Y, A", "DBNZ Y, q", "STOP" -};*/ +}; constexpr const char* _opTemplate[256] = { "NOP", "JST0", "SET1 d.0", "BBS d.0, q", "ORA d", "ORA a", "ORA (X)", "ORA [d,X]", "ORA #i", "OR t, s", "ORC m.b", "ASL d", "ASL a", "PHP", "SET1 a", "BRK", @@ -42,7 +44,7 @@ constexpr const char* _opTemplate[256] = { "SEI", "JSTC", "SET1 d.6", "BBS d.6, q", "STA d", "STA a", "STA (X)", "STA [d,X]", "CPX #i", "STX a", "STC m.b", "STY d", "STY a", "LDX #i","PLX", "MUL YA", "BNE r", "JSTD", "CLR1 d.6", "BBC d.6, q", "STA d,X", "STA a,X", "STA a,Y", "STA [d],Y", "STX d", "STX d,Y", "STW d", "STY d,X", "DEY", "TYA", "CBNE d,X, q", "DAA A", "CLV", "JSTE", "SET1 d.7", "BBS d.7, q", "LDA d", "LDA a", "LDA (X)", "LDA [d,X]", "LDA #i", "LDX a", "NOT m.b", "LDY d", "LDY a", "NOTC", "PLY", "WAI", - "BEQ r", "JSTF", "CLR1 d.7", "BBC d.7, q", "LDA d,X", "LDA a,X", "LDA a,Y", "LDA [d],Y", "LDX d", "LDX d,Y", "MOV t,s", "LDY d,X", "INC Y", "TAY", "DBNZ Y, r", "HLT" + "BEQ r", "JSTF", "CLR1 d.7", "BBC d.7, q", "LDA d,X", "LDA a,X", "LDA a,Y", "LDA [d],Y", "LDX d", "LDX d,Y", "MOV t,s", "LDY d,X", "INC Y", "TAY", "DBNZ Y, r", "STP" }; constexpr const uint8_t _opSize[256] = { @@ -99,7 +101,7 @@ void SpcDisUtils::GetDisassembly(DisassemblyInfo &info, string &out, uint32_t me }; uint8_t* byteCode = info.GetByteCode(); - const char* op = _opTemplate[byteCode[0]]; + const char* op = SpcDisUtils::UseAltSpcOpNames ? _altOpTemplate[byteCode[0]] : _opTemplate[byteCode[0]]; int i = 0; while(op[i]) { switch(op[i]) { diff --git a/Core/SpcDisUtils.h b/Core/SpcDisUtils.h index 1076c70..34077a1 100644 --- a/Core/SpcDisUtils.h +++ b/Core/SpcDisUtils.h @@ -9,6 +9,8 @@ struct SpcState; class SpcDisUtils { public: + static bool UseAltSpcOpNames; + static void GetDisassembly(DisassemblyInfo &info, string &out, uint32_t memoryAddr, LabelManager* labelManager); static int32_t GetEffectiveAddress(DisassemblyInfo &info, Console *console, SpcState &state); static uint8_t GetOpSize(uint8_t opCode); diff --git a/UI/Debugger/Config/DebuggerInfo.cs b/UI/Debugger/Config/DebuggerInfo.cs index 872a5e9..92b4272 100644 --- a/UI/Debugger/Config/DebuggerInfo.cs +++ b/UI/Debugger/Config/DebuggerInfo.cs @@ -33,6 +33,8 @@ namespace Mesen.GUI.Config public CodeDisplayMode UnidentifiedBlockDisplay = CodeDisplayMode.Hide; public CodeDisplayMode VerifiedDataDisplay = CodeDisplayMode.Hide; + public bool UseAltSpcOpNames = false; + public int BreakOnValue = 0; public int BreakInCount = 1; public BreakInMetric BreakInMetric = BreakInMetric.CpuInstructions; @@ -75,6 +77,8 @@ namespace Mesen.GUI.Config ConfigApi.SetDebuggerFlag(DebuggerFlags.DisassembleUnidentifiedData, UnidentifiedBlockDisplay == CodeDisplayMode.Disassemble); ConfigApi.SetDebuggerFlag(DebuggerFlags.ShowVerifiedData, VerifiedDataDisplay == CodeDisplayMode.Show); ConfigApi.SetDebuggerFlag(DebuggerFlags.DisassembleVerifiedData, VerifiedDataDisplay == CodeDisplayMode.Disassemble); + + ConfigApi.SetDebuggerFlag(DebuggerFlags.UseAltSpcOpNames, UseAltSpcOpNames); } } diff --git a/UI/Debugger/Controls/ctrlTextbox.cs b/UI/Debugger/Controls/ctrlTextbox.cs index 0986c52..6824542 100644 --- a/UI/Debugger/Controls/ctrlTextbox.cs +++ b/UI/Debugger/Controls/ctrlTextbox.cs @@ -442,7 +442,7 @@ namespace Mesen.GUI.Debugger.Controls return false; } - char[] _wordDelimiters = new char[] { ' ', ',', '|', ';', '(', ')', '.', '-', ':', '<', '>', '#', '*', '/', '&', '[', ']', '~', '%' }; + char[] _wordDelimiters = new char[] { ' ', ',', '|', ';', '(', ')', '.', '-', ':', '<', '>', '#', '*', '/', '&', '[', ']', '~', '%', '!' }; public string GetWordUnderLocation(Point position) { int charIndex; diff --git a/UI/Debugger/frmDebugger.Designer.cs b/UI/Debugger/frmDebugger.Designer.cs index 5de0692..2c72602 100644 --- a/UI/Debugger/frmDebugger.Designer.cs +++ b/UI/Debugger/frmDebugger.Designer.cs @@ -90,6 +90,7 @@ this.mnuShowData = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripSeparator(); this.mnuShowByteCode = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuUseAltSpcOpNames = new System.Windows.Forms.ToolStripMenuItem(); this.mnuBreakOptions = new System.Windows.Forms.ToolStripMenuItem(); this.mnuBreakOnPowerCycleReset = new System.Windows.Forms.ToolStripMenuItem(); this.mnuBreakOnOpen = new System.Windows.Forms.ToolStripMenuItem(); @@ -98,7 +99,7 @@ this.mnuBreakOnCop = new System.Windows.Forms.ToolStripMenuItem(); this.mnuBreakOnStp = new System.Windows.Forms.ToolStripMenuItem(); this.mnuBreakOnWdm = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem11 = new System.Windows.Forms.ToolStripSeparator(); + this.sepBreakOnUnitRead = new System.Windows.Forms.ToolStripSeparator(); this.mnuBreakOnUnitRead = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem10 = new System.Windows.Forms.ToolStripSeparator(); this.mnuBringToFrontOnBreak = new System.Windows.Forms.ToolStripMenuItem(); @@ -519,7 +520,8 @@ this.mnuUnidentifiedData, this.mnuVerifiedData, this.toolStripMenuItem6, - this.mnuShowByteCode}); + this.mnuShowByteCode, + this.mnuUseAltSpcOpNames}); this.mnuDisassemblyOptions.Name = "mnuDisassemblyOptions"; this.mnuDisassemblyOptions.Size = new System.Drawing.Size(209, 22); this.mnuDisassemblyOptions.Text = "Disassembly Options"; @@ -532,7 +534,7 @@ this.mnuShowUnident}); this.mnuUnidentifiedData.Image = global::Mesen.GUI.Properties.Resources.UnidentifiedData; this.mnuUnidentifiedData.Name = "mnuUnidentifiedData"; - this.mnuUnidentifiedData.Size = new System.Drawing.Size(199, 22); + this.mnuUnidentifiedData.Size = new System.Drawing.Size(217, 22); this.mnuUnidentifiedData.Text = "Unidentified Code/Data"; this.mnuUnidentifiedData.DropDownOpening += new System.EventHandler(this.mnuUnidentifiedData_DropDownOpening); // @@ -562,7 +564,7 @@ this.mnuShowData}); this.mnuVerifiedData.Image = global::Mesen.GUI.Properties.Resources.VerifiedData; this.mnuVerifiedData.Name = "mnuVerifiedData"; - this.mnuVerifiedData.Size = new System.Drawing.Size(199, 22); + this.mnuVerifiedData.Size = new System.Drawing.Size(217, 22); this.mnuVerifiedData.Text = "Verified Data"; this.mnuVerifiedData.DropDownOpening += new System.EventHandler(this.mnuVerifiedData_DropDownOpening); // @@ -587,15 +589,22 @@ // toolStripMenuItem6 // this.toolStripMenuItem6.Name = "toolStripMenuItem6"; - this.toolStripMenuItem6.Size = new System.Drawing.Size(196, 6); + this.toolStripMenuItem6.Size = new System.Drawing.Size(214, 6); // // mnuShowByteCode // this.mnuShowByteCode.CheckOnClick = true; this.mnuShowByteCode.Name = "mnuShowByteCode"; - this.mnuShowByteCode.Size = new System.Drawing.Size(199, 22); + this.mnuShowByteCode.Size = new System.Drawing.Size(217, 22); this.mnuShowByteCode.Text = "Show byte code"; // + // mnuUseAltSpcOpNames + // + this.mnuUseAltSpcOpNames.CheckOnClick = true; + this.mnuUseAltSpcOpNames.Name = "mnuUseAltSpcOpNames"; + this.mnuUseAltSpcOpNames.Size = new System.Drawing.Size(217, 22); + this.mnuUseAltSpcOpNames.Text = "Use alternative mnemonics"; + // // mnuBreakOptions // this.mnuBreakOptions.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -606,7 +615,7 @@ this.mnuBreakOnCop, this.mnuBreakOnStp, this.mnuBreakOnWdm, - this.toolStripMenuItem11, + this.sepBreakOnUnitRead, this.mnuBreakOnUnitRead, this.toolStripMenuItem10, this.mnuBringToFrontOnBreak, @@ -657,10 +666,10 @@ this.mnuBreakOnWdm.Size = new System.Drawing.Size(261, 22); this.mnuBreakOnWdm.Text = "Break on WDM"; // - // toolStripMenuItem11 + // sepBreakOnUnitRead // - this.toolStripMenuItem11.Name = "toolStripMenuItem11"; - this.toolStripMenuItem11.Size = new System.Drawing.Size(258, 6); + this.sepBreakOnUnitRead.Name = "sepBreakOnUnitRead"; + this.sepBreakOnUnitRead.Size = new System.Drawing.Size(258, 6); // // mnuBreakOnUnitRead // @@ -1039,7 +1048,7 @@ private System.Windows.Forms.ToolStripMenuItem mnuBreakOnBrk; private System.Windows.Forms.ToolStripMenuItem mnuBreakOnCop; private System.Windows.Forms.ToolStripMenuItem mnuBreakOnWdm; - private System.Windows.Forms.ToolStripSeparator toolStripMenuItem11; + private System.Windows.Forms.ToolStripSeparator sepBreakOnUnitRead; private System.Windows.Forms.ToolStripMenuItem mnuBreakOnUnitRead; private System.Windows.Forms.ToolStripMenuItem mnuBreakOnOpen; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem10; @@ -1057,5 +1066,6 @@ private System.Windows.Forms.ToolStripSeparator toolStripMenuItem13; private System.Windows.Forms.ToolStripMenuItem mnuExit; private Controls.ctrlGsuStatus ctrlGsuStatus; - } + private System.Windows.Forms.ToolStripMenuItem mnuUseAltSpcOpNames; + } } \ No newline at end of file diff --git a/UI/Debugger/frmDebugger.cs b/UI/Debugger/frmDebugger.cs index ccccb37..1a62e8e 100644 --- a/UI/Debugger/frmDebugger.cs +++ b/UI/Debugger/frmDebugger.cs @@ -44,6 +44,8 @@ namespace Mesen.GUI.Debugger _notifListener = new NotificationListener(); _notifListener.OnNotification += OnNotificationReceived; + mnuUseAltSpcOpNames.Visible = false; + switch(_cpuType) { case CpuType.Cpu: ctrlDisassemblyView.Initialize(new CpuDisassemblyManager(), new CpuLineStyleProvider()); @@ -54,6 +56,11 @@ namespace Mesen.GUI.Debugger case CpuType.Spc: ctrlDisassemblyView.Initialize(new SpcDisassemblyManager(), new SpcLineStyleProvider()); ConfigApi.SetDebuggerFlag(DebuggerFlags.SpcDebuggerEnabled, true); + mnuBreakOnWdm.Visible = false; + mnuBreakOnCop.Visible = false; + mnuBreakOnUnitRead.Visible = false; + sepBreakOnUnitRead.Visible = false; + mnuUseAltSpcOpNames.Visible = true; this.Text = "SPC Debugger"; break; @@ -73,6 +80,13 @@ namespace Mesen.GUI.Debugger mnuStepOut.Visible = false; mnuStepInto.Text = "Step"; tlpBottomPanel.ColumnCount = 2; + + mnuBreakOnWdm.Visible = false; + mnuBreakOnCop.Visible = false; + mnuBreakOnStp.Visible = false; + mnuBreakOnBrk.Visible = false; + sepBreakOnUnitRead.Visible = false; + mnuBreakOnUnitRead.Visible = false; break; } @@ -282,8 +296,14 @@ namespace Mesen.GUI.Debugger DebuggerInfo cfg = ConfigManager.Config.Debug.Debugger; _entityBinder.Entity = cfg; _entityBinder.AddBinding(nameof(cfg.ShowByteCode), mnuShowByteCode); + _entityBinder.AddBinding(nameof(cfg.UseAltSpcOpNames), mnuUseAltSpcOpNames); mnuShowByteCode.CheckedChanged += (s, e) => { ctrlDisassemblyView.CodeViewer.ShowContentNotes = mnuShowByteCode.Checked; }; + mnuUseAltSpcOpNames.CheckedChanged += (s, e) => { + _entityBinder.UpdateObject(); + cfg.ApplyConfig(); + RefreshDisassembly(); + }; _entityBinder.UpdateUI(); diff --git a/UI/Interop/ConfigApi.cs b/UI/Interop/ConfigApi.cs index a013f8b..3f9aad0 100644 --- a/UI/Interop/ConfigApi.cs +++ b/UI/Interop/ConfigApi.cs @@ -59,6 +59,8 @@ namespace Mesen.GUI ShowUnidentifiedData = 0x400, DisassembleUnidentifiedData = 0x800, + UseAltSpcOpNames = 0x1000, + GsuDebuggerEnabled = 0x10000000, Sa1DebuggerEnabled = 0x20000000, SpcDebuggerEnabled = 0x40000000,