diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs index 7b898be94f..7470f4187c 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs @@ -206,7 +206,8 @@ namespace BizHawk.Client.Common var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name); _luaFunctions.Add(nlf); - Global.Emulator.AsDebuggable().MemoryCallbacks.Add(MemoryCallbackType.Execute, nlf.Callback, address); + Global.Emulator.AsDebuggable().MemoryCallbacks.Add( + new MemoryCallback(MemoryCallbackType.Execute, "Lua Hook", nlf.Callback, address)); return nlf.Guid.ToString(); } else @@ -226,7 +227,8 @@ namespace BizHawk.Client.Common { var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name); _luaFunctions.Add(nlf); - Global.Emulator.AsDebuggable().MemoryCallbacks.Add(MemoryCallbackType.Read, nlf.Callback, address); + Global.Emulator.AsDebuggable().MemoryCallbacks.Add( + new MemoryCallback(MemoryCallbackType.Read, "Lua Hook", nlf.Callback, address)); return nlf.Guid.ToString(); } else @@ -246,7 +248,8 @@ namespace BizHawk.Client.Common { var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentThread, name); _luaFunctions.Add(nlf); - Global.Emulator.AsDebuggable().MemoryCallbacks.Add(MemoryCallbackType.Write, nlf.Callback, address); + Global.Emulator.AsDebuggable().MemoryCallbacks.Add( + new MemoryCallback(MemoryCallbackType.Write, "Lua Hook", nlf.Callback, address)); return nlf.Guid.ToString(); } else diff --git a/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs b/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs index 8043723a01..c88bdf2d60 100644 --- a/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs @@ -500,7 +500,7 @@ namespace BizHawk.Client.EmuHawk private void AddCallback() { - _core.MemoryCallbacks.Add(Type, Callback, Address); + _core.MemoryCallbacks.Add(new MemoryCallback(Type, "", Callback, Address)); } private void RemoveCallback() diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs b/BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs index a73a837923..2abbb0102e 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs @@ -76,18 +76,7 @@ namespace BizHawk.Client.EmuHawk private void AddCallback() { - switch (Type) - { - case MemoryCallbackType.Read: - _core.MemoryCallbacks.Add(MemoryCallbackType.Read, Callback, Address); - break; - case MemoryCallbackType.Write: - _core.MemoryCallbacks.Add(MemoryCallbackType.Write, Callback, Address); - break; - case MemoryCallbackType.Execute: - _core.MemoryCallbacks.Add(MemoryCallbackType.Execute, Callback, Address); - break; - } + _core.MemoryCallbacks.Add(new MemoryCallback(Type, "Pause", Callback, Address)); } private void RemoveCallback() diff --git a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs index 4790368313..911a1caeb8 100644 --- a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs @@ -16,24 +16,24 @@ namespace BizHawk.Emulation.Common private readonly List _executes = new List(); private readonly List _execAddrs = new List(); - public void Add(MemoryCallbackType type, Action function, uint? addr) + public void Add(IMemoryCallback callback) { - switch (type) + switch (callback.Type) { case MemoryCallbackType.Read: - AddRead(function, addr); + AddRead(callback.Callback, callback.Address); break; case MemoryCallbackType.Write: - AddWrite(function, addr); + AddWrite(callback.Callback, callback.Address); break; case MemoryCallbackType.Execute: - if (!addr.HasValue) + if (!callback.Address.HasValue) { throw new InvalidOperationException("When assigning an execute callback, an address must be specified"); } else { - AddExecute(function, addr.Value); + AddExecute(callback.Callback, callback.Address.Value); } break; @@ -187,4 +187,20 @@ namespace BizHawk.Emulation.Common } } } + + public class MemoryCallback : IMemoryCallback + { + public MemoryCallback(MemoryCallbackType type, string name, Action callback, uint? address) + { + Type = type; + Name = name; + Callback = callback; + Address = address; + } + + public MemoryCallbackType Type { get; private set; } + public string Name { get; private set; } + public Action Callback { get; private set; } + public uint? Address { get; private set; } + } } diff --git a/BizHawk.Emulation.Common/Interfaces/IMemoryCallbackSystem.cs b/BizHawk.Emulation.Common/Interfaces/IMemoryCallbackSystem.cs index 4e898f2cc9..1c7cbc4ab3 100644 --- a/BizHawk.Emulation.Common/Interfaces/IMemoryCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Interfaces/IMemoryCallbackSystem.cs @@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Common /// If no address is specified the callback will be hooked to all addresses /// Note: an execute callback can not be added without an address, else an InvalidOperationException will occur /// - void Add(MemoryCallbackType type, Action function, uint? addr); + void Add(IMemoryCallback callback); /// /// Executes all Read callbacks for the given addr @@ -58,5 +58,13 @@ namespace BizHawk.Emulation.Common void Clear(); } + public interface IMemoryCallback + { + MemoryCallbackType Type { get; } + string Name { get; } + Action Callback { get; } + uint? Address { get; } + } + public enum MemoryCallbackType { Read, Write, Execute } }