MemoryCallback System - another refinement, make an IMemoryCallback and make that the argument for add methods
This commit is contained in:
parent
2d1a43dc65
commit
1c179da80c
|
@ -206,7 +206,8 @@ namespace BizHawk.Client.Common
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
_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();
|
return nlf.Guid.ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -226,7 +227,8 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
_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();
|
return nlf.Guid.ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -246,7 +248,8 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
_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();
|
return nlf.Guid.ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -500,7 +500,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void AddCallback()
|
private void AddCallback()
|
||||||
{
|
{
|
||||||
_core.MemoryCallbacks.Add(Type, Callback, Address);
|
_core.MemoryCallbacks.Add(new MemoryCallback(Type, "", Callback, Address));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveCallback()
|
private void RemoveCallback()
|
||||||
|
|
|
@ -76,18 +76,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void AddCallback()
|
private void AddCallback()
|
||||||
{
|
{
|
||||||
switch (Type)
|
_core.MemoryCallbacks.Add(new MemoryCallback(Type, "Pause", Callback, Address));
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveCallback()
|
private void RemoveCallback()
|
||||||
|
|
|
@ -16,24 +16,24 @@ namespace BizHawk.Emulation.Common
|
||||||
private readonly List<Action> _executes = new List<Action>();
|
private readonly List<Action> _executes = new List<Action>();
|
||||||
private readonly List<uint> _execAddrs = new List<uint>();
|
private readonly List<uint> _execAddrs = new List<uint>();
|
||||||
|
|
||||||
public void Add(MemoryCallbackType type, Action function, uint? addr)
|
public void Add(IMemoryCallback callback)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (callback.Type)
|
||||||
{
|
{
|
||||||
case MemoryCallbackType.Read:
|
case MemoryCallbackType.Read:
|
||||||
AddRead(function, addr);
|
AddRead(callback.Callback, callback.Address);
|
||||||
break;
|
break;
|
||||||
case MemoryCallbackType.Write:
|
case MemoryCallbackType.Write:
|
||||||
AddWrite(function, addr);
|
AddWrite(callback.Callback, callback.Address);
|
||||||
break;
|
break;
|
||||||
case MemoryCallbackType.Execute:
|
case MemoryCallbackType.Execute:
|
||||||
if (!addr.HasValue)
|
if (!callback.Address.HasValue)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("When assigning an execute callback, an address must be specified");
|
throw new InvalidOperationException("When assigning an execute callback, an address must be specified");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddExecute(function, addr.Value);
|
AddExecute(callback.Callback, callback.Address.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Common
|
||||||
/// If no address is specified the callback will be hooked to all addresses
|
/// 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
|
/// Note: an execute callback can not be added without an address, else an InvalidOperationException will occur
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Add(MemoryCallbackType type, Action function, uint? addr);
|
void Add(IMemoryCallback callback);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes all Read callbacks for the given addr
|
/// Executes all Read callbacks for the given addr
|
||||||
|
@ -58,5 +58,13 @@ namespace BizHawk.Emulation.Common
|
||||||
void Clear();
|
void Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface IMemoryCallback
|
||||||
|
{
|
||||||
|
MemoryCallbackType Type { get; }
|
||||||
|
string Name { get; }
|
||||||
|
Action Callback { get; }
|
||||||
|
uint? Address { get; }
|
||||||
|
}
|
||||||
|
|
||||||
public enum MemoryCallbackType { Read, Write, Execute }
|
public enum MemoryCallbackType { Read, Write, Execute }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue