From 8246de14aacdc9efd5caac07d681bff29a31a5a9 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 25 Jan 2015 22:14:58 +0000 Subject: [PATCH] IMemoryCallbackSystem - add a flag to indicate whether execute callbacks are available, in lua and the debugger, take this flag into account, also improve some availability checking in Lua memory callbacks. Flag N64 as not having execute callbacks available --- .../lua/EmuLuaLibrary.Events.cs | 21 +++++++++++++------ .../Debugger/AddBreakpointDialog.Designer.cs | 3 +++ .../tools/Debugger/AddBreakpointDialog.cs | 11 ++++++++++ .../tools/Debugger/AddBreakpointDialog.resx | 3 +++ .../tools/Debugger/BreakpointControl.cs | 5 +++++ .../MemoryCallbackSystem.cs | 7 +++++++ BizHawk.Emulation.Common/Extensions.cs | 20 +++++++++++++++++- .../Interfaces/IMemoryCallbackSystem.cs | 5 +++++ .../Consoles/Nintendo/N64/N64.cs | 5 ++++- 9 files changed, 72 insertions(+), 8 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs index 6fae338a14..a2486a0203 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs @@ -17,6 +17,9 @@ namespace BizHawk.Client.Common [OptionalService] public IDebuggable DebuggableCore { get; set; } + [RequiredService] + public IEmulator Emulator { get; set; } + private readonly LuaFunctionList _luaFunctions = new LuaFunctionList(); public EventLuaLibrary(Lua lua) @@ -132,7 +135,12 @@ namespace BizHawk.Client.Common private void LogMemoryCallbacksNotImplemented() { - Log(string.Format("{0} does not implement memory callbacks")); + Log(string.Format("{0} does not implement memory callbacks", Emulator.Attributes().CoreName)); + } + + private void LogMemoryExecuteCallbacksNotImplemented() + { + Log(string.Format("{0} does not implement memory execute callbacks", Emulator.Attributes().CoreName)); } #endregion @@ -212,7 +220,8 @@ namespace BizHawk.Client.Common { try { - if (DebuggableCore != null) + if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable() && + DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable) { var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name); _luaFunctions.Add(nlf); @@ -224,11 +233,11 @@ namespace BizHawk.Client.Common } catch(NotImplementedException) { - LogMemoryCallbacksNotImplemented(); + LogMemoryExecuteCallbacksNotImplemented(); return Guid.Empty.ToString(); } - LogMemoryCallbacksNotImplemented(); + LogMemoryExecuteCallbacksNotImplemented(); return Guid.Empty.ToString(); } @@ -240,7 +249,7 @@ namespace BizHawk.Client.Common { try { - if (DebuggableCore != null) + if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable()) { var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name); _luaFunctions.Add(nlf); @@ -268,7 +277,7 @@ namespace BizHawk.Client.Common { try { - if (DebuggableCore != null) + if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable()) { var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentThread, name); _luaFunctions.Add(nlf); diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.Designer.cs b/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.Designer.cs index dae11ab55a..c7b88092b9 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.AddButton = new System.Windows.Forms.Button(); this.BreakpointTypeGroupbox = new System.Windows.Forms.GroupBox(); this.ExecuteRadio = new System.Windows.Forms.RadioButton(); @@ -35,6 +36,7 @@ this.ReadRadio = new System.Windows.Forms.RadioButton(); this.AddressBox = new BizHawk.Client.EmuHawk.HexTextBox(); this.label1 = new System.Windows.Forms.Label(); + this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.BreakpointTypeGroupbox.SuspendLayout(); this.SuspendLayout(); // @@ -144,5 +146,6 @@ private System.Windows.Forms.RadioButton ReadRadio; private HexTextBox AddressBox; private System.Windows.Forms.Label label1; + private System.Windows.Forms.ToolTip toolTip1; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.cs b/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.cs index 695a5d1ff0..d14da0c99d 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.cs @@ -18,6 +18,17 @@ namespace BizHawk.Client.EmuHawk InitializeComponent(); } + public void DisableExecuteOption() + { + if (ExecuteRadio.Checked) + { + ReadRadio.Checked = true; + } + + ExecuteRadio.Enabled = false; + + } + public MemoryCallbackType BreakType { get diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.resx b/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.resx index 29dcb1b3a3..65a871b69c 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.resx +++ b/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs b/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs index 62e570200c..08f052fb6c 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs @@ -150,6 +150,11 @@ namespace BizHawk.Client.EmuHawk.tools.Debugger MaxAddressSize = Global.Emulator.AsMemoryDomains().SystemBus.Size - 1 }; + if (!MCS.ExecuteCallbacksAvailable) + { + b.DisableExecuteOption(); + } + if (b.ShowHawkDialog() == DialogResult.OK) { Breakpoints.Add(Core, b.Address, b.BreakType); diff --git a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs index c9d7b9ac6f..9a14debc4e 100644 --- a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs @@ -8,6 +8,11 @@ namespace BizHawk.Emulation.Common { public class MemoryCallbackSystem : IMemoryCallbackSystem { + public MemoryCallbackSystem() + { + ExecuteCallbacksAvailable = true; + } + private readonly List Reads = new List(); private readonly List Writes = new List(); private readonly List Execs = new List(); @@ -18,6 +23,8 @@ namespace BizHawk.Emulation.Common private bool _hasWrites = false; private bool _hasExecutes = false; + public bool ExecuteCallbacksAvailable { get; set; } + public void Add(IMemoryCallback callback) { switch (callback.Type) diff --git a/BizHawk.Emulation.Common/Extensions.cs b/BizHawk.Emulation.Common/Extensions.cs index ed73ed2bfc..16387bc5b7 100644 --- a/BizHawk.Emulation.Common/Extensions.cs +++ b/BizHawk.Emulation.Common/Extensions.cs @@ -136,7 +136,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions { try { - var tracer = debuggable.MemoryCallbacks; + var callbacks = debuggable.MemoryCallbacks; return true; } catch (NotImplementedException) @@ -148,6 +148,24 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions return false; } + public static bool MemoryCallbacksAvailable(this IDebuggable core) + { + if (core == null) + { + return false; + } + + try + { + var callbacks = core.MemoryCallbacks; + return true; + } + catch (NotImplementedException) + { + return false; + } + } + public static bool CanDisassemble(this IEmulator core) { if (core == null) diff --git a/BizHawk.Emulation.Common/Interfaces/IMemoryCallbackSystem.cs b/BizHawk.Emulation.Common/Interfaces/IMemoryCallbackSystem.cs index d9230ca409..b2a60cc4e7 100644 --- a/BizHawk.Emulation.Common/Interfaces/IMemoryCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Interfaces/IMemoryCallbackSystem.cs @@ -11,6 +11,11 @@ namespace BizHawk.Emulation.Common * These functions must return very quickly if the list is empty. Very very quickly. */ + /// + /// Specifies whether or not Execute callbacks are available for this this implementation + /// + bool ExecuteCallbacksAvailable { get; } + /// /// Returns whether or not there are currently any read hooks /// diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index 9c542e17b4..dad320ffe1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -54,7 +54,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 { ServiceProvider = new BasicServiceProvider(this); InputCallbacks = new InputCallbackSystem(); - MemoryCallbacks = new MemoryCallbackSystem(); + MemoryCallbacks = new MemoryCallbackSystem + { + ExecuteCallbacksAvailable = false + }; int SaveType = 0; if (game.OptionValue("SaveType") == "EEPROM_16K")