implement Lua - event.onmemoryexecute(), currently only works with the NES core
This commit is contained in:
parent
9fed70a49c
commit
5d65b0ef77
|
@ -24,6 +24,7 @@ namespace BizHawk.Client.Common
|
||||||
"onframestart",
|
"onframestart",
|
||||||
"oninputpoll",
|
"oninputpoll",
|
||||||
"onloadstate",
|
"onloadstate",
|
||||||
|
"onmemoryexecute",
|
||||||
"onmemoryread",
|
"onmemoryread",
|
||||||
"onmemorywrite",
|
"onmemorywrite",
|
||||||
"onsavestate",
|
"onsavestate",
|
||||||
|
@ -159,13 +160,20 @@ namespace BizHawk.Client.Common
|
||||||
return nlf.GUID.ToString();
|
return nlf.GUID.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string event_onmemoryexecute(LuaFunction luaf, object address, string name = null)
|
||||||
|
{
|
||||||
|
NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, name);
|
||||||
|
_luaFunctions.Add(nlf);
|
||||||
|
Global.CoreComm.MemoryCallbackSystem.AddExecute(nlf.Callback, LuaUInt(address));
|
||||||
|
return nlf.GUID.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public string event_onmemoryread(LuaFunction luaf, object address = null, string name = null)
|
public string event_onmemoryread(LuaFunction luaf, object address = null, string name = null)
|
||||||
{
|
{
|
||||||
NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, name);
|
NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, name);
|
||||||
_luaFunctions.Add(nlf);
|
_luaFunctions.Add(nlf);
|
||||||
Global.CoreComm.MemoryCallbackSystem.AddRead(nlf.Callback, (address != null ? LuaUInt(address) : (uint?)null));
|
Global.CoreComm.MemoryCallbackSystem.AddRead(nlf.Callback, (address != null ? LuaUInt(address) : (uint?)null));
|
||||||
return nlf.GUID.ToString();
|
return nlf.GUID.ToString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string event_onmemorywrite(LuaFunction luaf, object address = null, string name = null)
|
public string event_onmemorywrite(LuaFunction luaf, object address = null, string name = null)
|
||||||
|
|
|
@ -165,6 +165,9 @@ namespace BizHawk.Emulation.Common
|
||||||
private List<Action> _writes = new List<Action>();
|
private List<Action> _writes = new List<Action>();
|
||||||
private List<uint?> _writeAddrs = new List<uint?>();
|
private List<uint?> _writeAddrs = new List<uint?>();
|
||||||
|
|
||||||
|
private List<Action> _executes = new List<Action>();
|
||||||
|
private List<uint> _execAddrs = new List<uint>();
|
||||||
|
|
||||||
public void AddRead(Action function, uint? addr)
|
public void AddRead(Action function, uint? addr)
|
||||||
{
|
{
|
||||||
_reads.Add(function);
|
_reads.Add(function);
|
||||||
|
@ -177,6 +180,12 @@ namespace BizHawk.Emulation.Common
|
||||||
_writeAddrs.Add(addr);
|
_writeAddrs.Add(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddExecute(Action function, uint addr)
|
||||||
|
{
|
||||||
|
_executes.Add(function);
|
||||||
|
_execAddrs.Add(addr);
|
||||||
|
}
|
||||||
|
|
||||||
public void CallRead(uint addr)
|
public void CallRead(uint addr)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _reads.Count; i++)
|
for (int i = 0; i < _reads.Count; i++)
|
||||||
|
@ -201,17 +210,18 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
public void CallExecute(uint addr)
|
public void CallExecute(uint addr)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _writes.Count; i++)
|
for (int i = 0; i < _executes.Count; i++)
|
||||||
{
|
{
|
||||||
if (_writeAddrs[i] == addr)
|
if (_execAddrs[i] == addr)
|
||||||
{
|
{
|
||||||
_writes[i]();
|
_executes[i]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasReads { get { return _reads.Any(); } }
|
public bool HasReads { get { return _reads.Any(); } }
|
||||||
public bool HasWrites { get { return _writes.Any(); } }
|
public bool HasWrites { get { return _writes.Any(); } }
|
||||||
|
public bool HasExecutes { get { return _executes.Any(); } }
|
||||||
|
|
||||||
public void Remove(Action action)
|
public void Remove(Action action)
|
||||||
{
|
{
|
||||||
|
@ -232,6 +242,15 @@ namespace BizHawk.Emulation.Common
|
||||||
_writeAddrs.Remove(_writeAddrs[i]);
|
_writeAddrs.Remove(_writeAddrs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < _executes.Count; i++)
|
||||||
|
{
|
||||||
|
if (_executes[i] == action)
|
||||||
|
{
|
||||||
|
_executes.Remove(_executes[i]);
|
||||||
|
_execAddrs.Remove(_execAddrs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAll(IEnumerable<Action> actions)
|
public void RemoveAll(IEnumerable<Action> actions)
|
||||||
|
@ -248,6 +267,8 @@ namespace BizHawk.Emulation.Common
|
||||||
_readAddrs.Clear();
|
_readAddrs.Clear();
|
||||||
_writes.Clear();
|
_writes.Clear();
|
||||||
_writes.Clear();
|
_writes.Clear();
|
||||||
|
_executes.Clear();
|
||||||
|
_execAddrs.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue