From 7a62b2af80c6f5c1511825d35c46d8ff4c7dbde0 Mon Sep 17 00:00:00 2001 From: Sour Date: Fri, 6 Jul 2018 00:10:10 -0400 Subject: [PATCH] Debugger: Added option to select which CPU to debug (VS DualSystem) (hidden from menu because issues exist) --- Core/Console.cpp | 15 +++++-- Core/Console.h | 7 ++- GUI.NET/Config/DebugInfo.cs | 2 + GUI.NET/Debugger/DebugWindowManager.cs | 8 ++++ GUI.NET/Debugger/frmDebugger.cs | 2 +- GUI.NET/Debugger/frmEventViewer.cs | 2 +- GUI.NET/Debugger/frmMemoryViewer.cs | 2 +- GUI.NET/Debugger/frmPpuViewer.cs | 2 +- GUI.NET/Debugger/frmScript.cs | 2 +- GUI.NET/Debugger/frmTextHooker.cs | 2 +- GUI.NET/Forms/frmMain.Designer.cs | 62 +++++++++++++++++--------- GUI.NET/Forms/frmMain.Tools.cs | 23 ++++++++++ GUI.NET/Forms/frmMain.cs | 14 +++++- GUI.NET/InteropEmu.cs | 13 ++++-- InteropDLL/ConsoleWrapper.cpp | 19 +++++++- InteropDLL/DebugWrapper.cpp | 13 ++++-- TestHelper/TestHelper.cpp | 5 +-- 17 files changed, 147 insertions(+), 46 deletions(-) diff --git a/Core/Console.cpp b/Core/Console.cpp index 4e1ee8ac..f969ca0e 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -49,10 +49,6 @@ Console::Console(shared_ptr master) { _master = master; _model = NesModel::NTSC; - - if(_master) { - _master->_notificationManager->SendNotification(ConsoleNotificationType::VsDualSystemStarted); - } } Console::~Console() @@ -73,6 +69,10 @@ void Console::Init() _soundMixer.reset(new SoundMixer(shared_from_this())); _soundMixer->SetNesModel(_model); + + if(_master) { + _emulationThreadId = _master->_emulationThreadId; + } } void Console::Release(bool forShutdown) @@ -385,6 +385,10 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile) MessageManager::DisplayMessage("ClockRate", std::to_string(EmulationSettings::GetOverclockRate()) + "%"); } EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); + + if(_slave) { + _notificationManager->SendNotification(ConsoleNotificationType::VsDualSystemStarted); + } } Resume(); return true; @@ -667,6 +671,9 @@ void Console::Run() _stopLock.Acquire(); _emulationThreadId = std::this_thread::get_id(); + if(_slave) { + _slave->_emulationThreadId = std::this_thread::get_id(); + } targetTime = GetFrameDelay(); diff --git a/Core/Console.h b/Core/Console.h index aebe2a8c..85237e8b 100644 --- a/Core/Console.h +++ b/Core/Console.h @@ -4,8 +4,6 @@ #include #include "../Utilities/SimpleLock.h" #include "VirtualFile.h" -#include "RomData.h" -#include "Debugger.h" class BaseMapper; class RewindManager; @@ -26,8 +24,13 @@ class VideoRenderer; class DebugHud; class SoundMixer; class NotificationManager; +class Debugger; struct HdPackData; +struct HashInfo; +struct MapperInfo; + +enum class MemoryOperationType; enum class NesModel; enum class ScaleFilterType; enum class ConsoleFeatures; diff --git a/GUI.NET/Config/DebugInfo.cs b/GUI.NET/Config/DebugInfo.cs index 7bcf4d2a..e41cfd2a 100644 --- a/GUI.NET/Config/DebugInfo.cs +++ b/GUI.NET/Config/DebugInfo.cs @@ -119,6 +119,8 @@ namespace Mesen.GUI.Config public DebugViewInfo LeftView; public DebugViewInfo RightView; + public InteropEmu.ConsoleId DebugConsoleId = InteropEmu.ConsoleId.Master; + public string FontFamily = BaseControl.MonospaceFontFamily; public FontStyle FontStyle = FontStyle.Regular; public float FontSize = BaseControl.DefaultFontSize; diff --git a/GUI.NET/Debugger/DebugWindowManager.cs b/GUI.NET/Debugger/DebugWindowManager.cs index 1d03d8aa..c7bf7957 100644 --- a/GUI.NET/Debugger/DebugWindowManager.cs +++ b/GUI.NET/Debugger/DebugWindowManager.cs @@ -77,6 +77,14 @@ namespace Mesen.GUI.Debugger return _openedWindows.ToList().Find((form) => form.GetType() == typeof(frmMemoryViewer)) as frmMemoryViewer; } + public static bool HasOpenedWindow + { + get + { + return _openedWindows.Count > 0; + } + } + public static void CloseAll() { List
openedWindows = new List(_openedWindows); diff --git a/GUI.NET/Debugger/frmDebugger.cs b/GUI.NET/Debugger/frmDebugger.cs index b000147c..f67023a9 100644 --- a/GUI.NET/Debugger/frmDebugger.cs +++ b/GUI.NET/Debugger/frmDebugger.cs @@ -158,7 +158,7 @@ namespace Mesen.GUI.Debugger "[MyLabel, 4]: Display 4 bytes starting from the address the specified label (MyLabel) refers to" ); - _notifListener = new InteropEmu.NotificationListener(); + _notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId); _notifListener.OnNotification += _notifListener_OnNotification; InteropEmu.DebugInitialize(); diff --git a/GUI.NET/Debugger/frmEventViewer.cs b/GUI.NET/Debugger/frmEventViewer.cs index 35ac4689..6b334165 100644 --- a/GUI.NET/Debugger/frmEventViewer.cs +++ b/GUI.NET/Debugger/frmEventViewer.cs @@ -50,7 +50,7 @@ namespace Mesen.GUI.Debugger this.Location = ConfigManager.Config.DebugInfo.EventViewerLocation; } - this._notifListener = new InteropEmu.NotificationListener(); + this._notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId); this._notifListener.OnNotification += this._notifListener_OnNotification; } } diff --git a/GUI.NET/Debugger/frmMemoryViewer.cs b/GUI.NET/Debugger/frmMemoryViewer.cs index e0f68404..032a6ece 100644 --- a/GUI.NET/Debugger/frmMemoryViewer.cs +++ b/GUI.NET/Debugger/frmMemoryViewer.cs @@ -81,7 +81,7 @@ namespace Mesen.GUI.Debugger UpdateImportButton(); InitMemoryTypeDropdown(true); - _notifListener = new InteropEmu.NotificationListener(); + _notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId); _notifListener.OnNotification += _notifListener_OnNotification; this.mnuShowCharacters.CheckedChanged += this.mnuShowCharacters_CheckedChanged; diff --git a/GUI.NET/Debugger/frmPpuViewer.cs b/GUI.NET/Debugger/frmPpuViewer.cs index 44055137..13d9b226 100644 --- a/GUI.NET/Debugger/frmPpuViewer.cs +++ b/GUI.NET/Debugger/frmPpuViewer.cs @@ -56,7 +56,7 @@ namespace Mesen.GUI.Debugger base.OnLoad(e); if(!this.DesignMode) { - this._notifListener = new InteropEmu.NotificationListener(); + this._notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId); this._notifListener.OnNotification += this._notifListener_OnNotification; this.ctrlScanlineCycle.Initialize(_ppuViewerId, ConfigManager.Config.DebugInfo.PpuDisplayScanline, ConfigManager.Config.DebugInfo.PpuDisplayCycle); diff --git a/GUI.NET/Debugger/frmScript.cs b/GUI.NET/Debugger/frmScript.cs index de185d4d..c034d321 100644 --- a/GUI.NET/Debugger/frmScript.cs +++ b/GUI.NET/Debugger/frmScript.cs @@ -120,7 +120,7 @@ namespace Mesen.GUI.Debugger protected override void OnLoad(EventArgs e) { base.OnLoad(e); - this._notifListener = new InteropEmu.NotificationListener(); + this._notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId); this._notifListener.OnNotification += this._notifListener_OnNotification; this.InitShortcuts(); diff --git a/GUI.NET/Debugger/frmTextHooker.cs b/GUI.NET/Debugger/frmTextHooker.cs index 7b694bab..9dca73b2 100644 --- a/GUI.NET/Debugger/frmTextHooker.cs +++ b/GUI.NET/Debugger/frmTextHooker.cs @@ -77,7 +77,7 @@ namespace Mesen.GUI.Debugger this.ctrlTextHooker.SetCharacterMappings(_charMappings); this.ctrlCharacterMappings.SetCharacterMappings(_charMappings); - this._notifListener = new InteropEmu.NotificationListener(); + this._notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId); this._notifListener.OnNotification += this._notifListener_OnNotification; this.ctrlTextHooker.GetData(); diff --git a/GUI.NET/Forms/frmMain.Designer.cs b/GUI.NET/Forms/frmMain.Designer.cs index df082d38..79e20103 100644 --- a/GUI.NET/Forms/frmMain.Designer.cs +++ b/GUI.NET/Forms/frmMain.Designer.cs @@ -33,6 +33,7 @@ namespace Mesen.GUI.Forms this.components = new System.ComponentModel.Container(); this.menuTimer = new System.Windows.Forms.Timer(this.components); this.panelRenderer = new System.Windows.Forms.Panel(); + this.ctrlRendererDualSystem = new Mesen.GUI.Controls.ctrlRenderer(); this.ctrlLoading = new Mesen.GUI.Controls.ctrlLoadingRom(); this.panelInfo = new System.Windows.Forms.Panel(); this.picIcon = new System.Windows.Forms.PictureBox(); @@ -197,6 +198,8 @@ namespace Mesen.GUI.Forms this.mnuScriptWindow = new System.Windows.Forms.ToolStripMenuItem(); this.mnuTextHooker = new System.Windows.Forms.ToolStripMenuItem(); this.mnuTraceLogger = new System.Windows.Forms.ToolStripMenuItem(); + this.sepDebugDualSystemSecondaryCpu = new System.Windows.Forms.ToolStripSeparator(); + this.mnuDebugDualSystemSecondaryCpu = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem25 = new System.Windows.Forms.ToolStripSeparator(); this.mnuEditHeader = new System.Windows.Forms.ToolStripMenuItem(); this.mnuHelp = new System.Windows.Forms.ToolStripMenuItem(); @@ -208,7 +211,6 @@ namespace Mesen.GUI.Forms this.mnuReportBug = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripSeparator(); this.mnuAbout = new System.Windows.Forms.ToolStripMenuItem(); - this.ctrlRendererDualSystem = new Mesen.GUI.Controls.ctrlRenderer(); this.panelRenderer.SuspendLayout(); this.panelInfo.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.picIcon)).BeginInit(); @@ -238,6 +240,16 @@ namespace Mesen.GUI.Forms this.panelRenderer.MouseLeave += new System.EventHandler(this.panelRenderer_MouseLeave); this.panelRenderer.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ctrlRenderer_MouseMove); // + // ctrlRendererDualSystem + // + this.ctrlRendererDualSystem.BackColor = System.Drawing.Color.Black; + this.ctrlRendererDualSystem.Location = new System.Drawing.Point(275, 0); + this.ctrlRendererDualSystem.Margin = new System.Windows.Forms.Padding(0); + this.ctrlRendererDualSystem.Name = "ctrlRendererDualSystem"; + this.ctrlRendererDualSystem.Size = new System.Drawing.Size(150, 90); + this.ctrlRendererDualSystem.TabIndex = 8; + this.ctrlRendererDualSystem.Visible = false; + // // ctrlLoading // this.ctrlLoading.BackColor = System.Drawing.Color.Black; @@ -1498,6 +1510,8 @@ namespace Mesen.GUI.Forms this.mnuScriptWindow, this.mnuTextHooker, this.mnuTraceLogger, + this.sepDebugDualSystemSecondaryCpu, + this.mnuDebugDualSystemSecondaryCpu, this.toolStripMenuItem25, this.mnuEditHeader}); this.mnuDebug.Name = "mnuDebug"; @@ -1511,7 +1525,7 @@ namespace Mesen.GUI.Forms // this.mnuApuViewer.Image = global::Mesen.GUI.Properties.Resources.Audio; this.mnuApuViewer.Name = "mnuApuViewer"; - this.mnuApuViewer.Size = new System.Drawing.Size(162, 22); + this.mnuApuViewer.Size = new System.Drawing.Size(258, 22); this.mnuApuViewer.Text = "APU Viewer"; this.mnuApuViewer.Click += new System.EventHandler(this.mnuApuViewer_Click); // @@ -1519,7 +1533,7 @@ namespace Mesen.GUI.Forms // this.mnuAssembler.Image = global::Mesen.GUI.Properties.Resources.Chip; this.mnuAssembler.Name = "mnuAssembler"; - this.mnuAssembler.Size = new System.Drawing.Size(162, 22); + this.mnuAssembler.Size = new System.Drawing.Size(258, 22); this.mnuAssembler.Text = "Assembler"; this.mnuAssembler.Click += new System.EventHandler(this.mnuAssembler_Click); // @@ -1527,7 +1541,7 @@ namespace Mesen.GUI.Forms // this.mnuDebugDebugger.Image = global::Mesen.GUI.Properties.Resources.Bug; this.mnuDebugDebugger.Name = "mnuDebugDebugger"; - this.mnuDebugDebugger.Size = new System.Drawing.Size(162, 22); + this.mnuDebugDebugger.Size = new System.Drawing.Size(258, 22); this.mnuDebugDebugger.Text = "Debugger"; this.mnuDebugDebugger.Click += new System.EventHandler(this.mnuDebugDebugger_Click); // @@ -1535,7 +1549,7 @@ namespace Mesen.GUI.Forms // this.mnuEventViewer.Image = global::Mesen.GUI.Properties.Resources.NesEventViewer; this.mnuEventViewer.Name = "mnuEventViewer"; - this.mnuEventViewer.Size = new System.Drawing.Size(162, 22); + this.mnuEventViewer.Size = new System.Drawing.Size(258, 22); this.mnuEventViewer.Text = "Event Viewer"; this.mnuEventViewer.Click += new System.EventHandler(this.mnuEventViewer_Click); // @@ -1543,7 +1557,7 @@ namespace Mesen.GUI.Forms // this.mnuMemoryViewer.Image = global::Mesen.GUI.Properties.Resources.CheatCode; this.mnuMemoryViewer.Name = "mnuMemoryViewer"; - this.mnuMemoryViewer.Size = new System.Drawing.Size(162, 22); + this.mnuMemoryViewer.Size = new System.Drawing.Size(258, 22); this.mnuMemoryViewer.Text = "Memory Tools"; this.mnuMemoryViewer.Click += new System.EventHandler(this.mnuMemoryViewer_Click); // @@ -1551,7 +1565,7 @@ namespace Mesen.GUI.Forms // this.mnuPpuViewer.Image = global::Mesen.GUI.Properties.Resources.Video; this.mnuPpuViewer.Name = "mnuPpuViewer"; - this.mnuPpuViewer.Size = new System.Drawing.Size(162, 22); + this.mnuPpuViewer.Size = new System.Drawing.Size(258, 22); this.mnuPpuViewer.Text = "PPU Viewer"; this.mnuPpuViewer.Click += new System.EventHandler(this.mnuPpuViewer_Click); // @@ -1559,7 +1573,7 @@ namespace Mesen.GUI.Forms // this.mnuScriptWindow.Image = global::Mesen.GUI.Properties.Resources.Script; this.mnuScriptWindow.Name = "mnuScriptWindow"; - this.mnuScriptWindow.Size = new System.Drawing.Size(162, 22); + this.mnuScriptWindow.Size = new System.Drawing.Size(258, 22); this.mnuScriptWindow.Text = "Script Window"; this.mnuScriptWindow.Click += new System.EventHandler(this.mnuScriptWindow_Click); // @@ -1567,7 +1581,7 @@ namespace Mesen.GUI.Forms // this.mnuTextHooker.Image = global::Mesen.GUI.Properties.Resources.Font; this.mnuTextHooker.Name = "mnuTextHooker"; - this.mnuTextHooker.Size = new System.Drawing.Size(162, 22); + this.mnuTextHooker.Size = new System.Drawing.Size(258, 22); this.mnuTextHooker.Text = "Text Hooker"; this.mnuTextHooker.Click += new System.EventHandler(this.mnuTextHooker_Click); // @@ -1575,20 +1589,32 @@ namespace Mesen.GUI.Forms // this.mnuTraceLogger.Image = global::Mesen.GUI.Properties.Resources.LogWindow; this.mnuTraceLogger.Name = "mnuTraceLogger"; - this.mnuTraceLogger.Size = new System.Drawing.Size(162, 22); + this.mnuTraceLogger.Size = new System.Drawing.Size(258, 22); this.mnuTraceLogger.Text = "Trace Logger"; this.mnuTraceLogger.Click += new System.EventHandler(this.mnuTraceLogger_Click); // + // sepDebugDualSystemSecondaryCpu + // + this.sepDebugDualSystemSecondaryCpu.Name = "sepDebugDualSystemSecondaryCpu"; + this.sepDebugDualSystemSecondaryCpu.Size = new System.Drawing.Size(255, 6); + // + // mnuDebugDualSystemSecondaryCpu + // + this.mnuDebugDualSystemSecondaryCpu.Name = "mnuDebugDualSystemSecondaryCpu"; + this.mnuDebugDualSystemSecondaryCpu.Size = new System.Drawing.Size(258, 22); + this.mnuDebugDualSystemSecondaryCpu.Text = "Debug DualSystem Secondary CPU"; + this.mnuDebugDualSystemSecondaryCpu.Click += new System.EventHandler(this.mnuDebugDualSystemSecondaryCpu_Click); + // // toolStripMenuItem25 // this.toolStripMenuItem25.Name = "toolStripMenuItem25"; - this.toolStripMenuItem25.Size = new System.Drawing.Size(159, 6); + this.toolStripMenuItem25.Size = new System.Drawing.Size(255, 6); // // mnuEditHeader // this.mnuEditHeader.Image = global::Mesen.GUI.Properties.Resources.Edit; this.mnuEditHeader.Name = "mnuEditHeader"; - this.mnuEditHeader.Size = new System.Drawing.Size(162, 22); + this.mnuEditHeader.Size = new System.Drawing.Size(258, 22); this.mnuEditHeader.Text = "Edit iNES Header"; this.mnuEditHeader.Click += new System.EventHandler(this.mnuEditHeader_Click); // @@ -1664,16 +1690,6 @@ namespace Mesen.GUI.Forms this.mnuAbout.Text = "About"; this.mnuAbout.Click += new System.EventHandler(this.mnuAbout_Click); // - // ctrlRendererDualSystem - // - this.ctrlRendererDualSystem.BackColor = System.Drawing.Color.Black; - this.ctrlRendererDualSystem.Location = new System.Drawing.Point(275, 0); - this.ctrlRendererDualSystem.Margin = new System.Windows.Forms.Padding(0); - this.ctrlRendererDualSystem.Name = "ctrlRendererDualSystem"; - this.ctrlRendererDualSystem.Size = new System.Drawing.Size(150, 90); - this.ctrlRendererDualSystem.TabIndex = 8; - this.ctrlRendererDualSystem.Visible = false; - // // frmMain // this.AllowDrop = true; @@ -1881,6 +1897,8 @@ namespace Mesen.GUI.Forms private System.Windows.Forms.ToolStripMenuItem mnuInstallHdPack; private System.Windows.Forms.ToolStripMenuItem mnuTextHooker; private Controls.ctrlRenderer ctrlRendererDualSystem; + private System.Windows.Forms.ToolStripSeparator sepDebugDualSystemSecondaryCpu; + private System.Windows.Forms.ToolStripMenuItem mnuDebugDualSystemSecondaryCpu; } } diff --git a/GUI.NET/Forms/frmMain.Tools.cs b/GUI.NET/Forms/frmMain.Tools.cs index 16269e18..a0eb0d40 100644 --- a/GUI.NET/Forms/frmMain.Tools.cs +++ b/GUI.NET/Forms/frmMain.Tools.cs @@ -346,5 +346,28 @@ namespace Mesen.GUI.Forms { DebugWindowManager.OpenDebugWindow(DebugWindow.TextHooker); } + + private void mnuDebugDualSystemSecondaryCpu_Click(object sender, EventArgs e) + { + bool switchCpu = false; + + if(!DebugWindowManager.HasOpenedWindow) { + switchCpu = true; + } else { + if(MessageBox.Show("Warning: Changing this setting will close all currently opened debug tools!", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { + DebugWindowManager.CloseAll(); + if(!DebugWindowManager.HasOpenedWindow) { + switchCpu = true; + } + } + } + + if(switchCpu) { + mnuDebugDualSystemSecondaryCpu.Checked = !mnuDebugDualSystemSecondaryCpu.Checked; + ConfigManager.Config.DebugInfo.DebugConsoleId = mnuDebugDualSystemSecondaryCpu.Checked ? InteropEmu.ConsoleId.Slave : InteropEmu.ConsoleId.Master; + ConfigManager.ApplyChanges(); + InteropEmu.DebugSetDebuggerConsole(ConfigManager.Config.DebugInfo.DebugConsoleId == InteropEmu.ConsoleId.Slave ? 1 : 0); + } + } } } diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 877a6182..13932df9 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -153,7 +153,7 @@ namespace Mesen.GUI.Forms #endif InitializeCore(); - _notifListener = new InteropEmu.NotificationListener(); + _notifListener = new InteropEmu.NotificationListener(InteropEmu.ConsoleId.Master); _notifListener.OnNotification += _notifListener_OnNotification; menuTimer.Start(); @@ -204,6 +204,9 @@ namespace Mesen.GUI.Forms if(ConfigManager.Config.PreferenceInfo.DisableMouseResize) { this.FormBorderStyle = FormBorderStyle.Fixed3D; } + + mnuDebugDualSystemSecondaryCpu.Checked = ConfigManager.Config.DebugInfo.DebugConsoleId == InteropEmu.ConsoleId.Slave; + InteropEmu.DebugSetDebuggerConsole(ConfigManager.Config.DebugInfo.DebugConsoleId == InteropEmu.ConsoleId.Slave ? 1 : 0); } private void ProcessFullscreenSwitch(List switches) @@ -1114,6 +1117,15 @@ namespace Mesen.GUI.Forms mnuTextHooker.Enabled = running; mnuTraceLogger.Enabled = running; +#if !HIDETESTMENU + //Keep this option hidden for now, until some remaining issues are fixed. + mnuDebugDualSystemSecondaryCpu.Visible = _isDualSystem; + sepDebugDualSystemSecondaryCpu.Visible = _isDualSystem; +#else + mnuDebugDualSystemSecondaryCpu.Visible = false; + sepDebugDualSystemSecondaryCpu.Visible = false; +#endif + mnuInstallHdPack.Enabled = running; mnuHdPackEditor.Enabled = !netPlay && running; diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 9d8b316c..16a05a8b 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -95,7 +95,7 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void TakeScreenshot(); - [DllImport(DLLPath)] public static extern IntPtr RegisterNotificationCallback(NotificationListener.NotificationCallback callback); + [DllImport(DLLPath)] public static extern IntPtr RegisterNotificationCallback(Int32 consoleId, NotificationListener.NotificationCallback callback); [DllImport(DLLPath)] public static extern void UnregisterNotificationCallback(IntPtr notificationListener); [DllImport(DLLPath)] public static extern void DisplayMessage([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string title, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string message, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string param1 = null); @@ -203,6 +203,7 @@ namespace Mesen.GUI [DllImport(DLLPath, EntryPoint = "GetAudioDevices")] private static extern IntPtr GetAudioDevicesWrapper(); [DllImport(DLLPath)] public static extern void SetAudioDevice(string audioDevice); + [DllImport(DLLPath)] public static extern void DebugSetDebuggerConsole(Int32 consoleId); [DllImport(DLLPath)] public static extern void DebugInitialize(); [DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool DebugIsDebuggerRunning(); [DllImport(DLLPath)] public static extern void DebugRelease(); @@ -1041,6 +1042,12 @@ namespace Mesen.GUI public IntPtr Parameter; } + public enum ConsoleId + { + Master = 0, + Slave = 1 + } + public class NotificationListener : IDisposable { public delegate void NotificationCallback(int type, IntPtr parameter); @@ -1051,12 +1058,12 @@ namespace Mesen.GUI NotificationCallback _callback; IntPtr _notificationListener; - public NotificationListener() + public NotificationListener(ConsoleId consoleId) { _callback = (int type, IntPtr parameter) => { this.ProcessNotification(type, parameter); }; - _notificationListener = InteropEmu.RegisterNotificationCallback(_callback); + _notificationListener = InteropEmu.RegisterNotificationCallback(consoleId == ConsoleId.Slave ? 1 : 0, _callback); } public void Dispose() diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index 0fac41ba..8d6a68c3 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -60,6 +60,21 @@ vector> _externalNotificationListeners; typedef void (__stdcall *NotificationListenerCallback)(int, void*); +shared_ptr GetConsoleById(int32_t consoleId) +{ + shared_ptr console; + if(consoleId == 1) { + //Get the VS Dualsystem's 2nd CPU, only if it's available (and requested) + console = _console->GetDualConsole(); + } + + if(!console) { + //Otherwise return the main CPU + console = _console; + } + return console; +} + namespace InteropEmu { class InteropNotificationListener : public INotificationListener { @@ -379,12 +394,12 @@ namespace InteropEmu { DllExport void __stdcall TakeScreenshot() { _console->GetVideoDecoder()->TakeScreenshot(); } - DllExport INotificationListener* __stdcall RegisterNotificationCallback(NotificationListenerCallback callback) + DllExport INotificationListener* __stdcall RegisterNotificationCallback(int32_t consoleId, NotificationListenerCallback callback) { auto lock = _externalNotificationListenerLock.AcquireSafe(); auto listener = shared_ptr(new InteropNotificationListener(callback)); _externalNotificationListeners.push_back(listener); - _console->GetNotificationManager()->RegisterNotificationListener(listener); + GetConsoleById(consoleId)->GetNotificationManager()->RegisterNotificationListener(listener); return listener.get(); } diff --git a/InteropDLL/DebugWrapper.cpp b/InteropDLL/DebugWrapper.cpp index 1e3ca453..f3eafae0 100644 --- a/InteropDLL/DebugWrapper.cpp +++ b/InteropDLL/DebugWrapper.cpp @@ -10,10 +10,12 @@ #include "../Core/TraceLogger.h" extern shared_ptr _console; +static int32_t _debugConsoleId = 0; +extern shared_ptr GetConsoleById(int32_t consoleId); shared_ptr GetDebugger() { - return _console->GetDebugger(); + return GetConsoleById(_debugConsoleId)->GetDebugger(); } extern "C" @@ -26,12 +28,17 @@ extern "C" DllExport void __stdcall DebugRelease() { - _console->StopDebugger(); + GetConsoleById(_debugConsoleId)->StopDebugger(); } DllExport bool __stdcall DebugIsDebuggerRunning() { - return _console->GetDebugger(false).get() != nullptr; + return GetConsoleById(_debugConsoleId)->GetDebugger(false).get() != nullptr; + } + + DllExport void __stdcall DebugSetDebuggerConsole(int32_t consoleId) + { + _debugConsoleId = consoleId; } DllExport void __stdcall DebugSetFlags(uint32_t flags) { GetDebugger()->SetFlags(flags); } diff --git a/TestHelper/TestHelper.cpp b/TestHelper/TestHelper.cpp index 20c443a5..c624d585 100644 --- a/TestHelper/TestHelper.cpp +++ b/TestHelper/TestHelper.cpp @@ -37,7 +37,7 @@ extern "C" { int __stdcall RunRecordedTest(char* filename); void __stdcall Run(); void __stdcall Stop(); - INotificationListener* __stdcall RegisterNotificationCallback(NotificationListenerCallback callback); + INotificationListener* __stdcall RegisterNotificationCallback(int32_t consoleId, NotificationListenerCallback callback); } std::thread *runThread = nullptr; @@ -189,10 +189,9 @@ int main(int argc, char* argv[]) std::getchar(); } else if(argc == 3) { char* testFilename = argv[2]; - RegisterNotificationCallback((NotificationListenerCallback)OnNotificationReceived); - SetFlags(0x8000000000000000); //EmulationFlags::ConsoleMode InitializeEmu(mesenFolder.c_str(), nullptr, nullptr, false, false, false); + RegisterNotificationCallback(0, (NotificationListenerCallback)OnNotificationReceived); SetControllerType(0, ControllerType::StandardController); SetControllerType(1, ControllerType::StandardController);