Lua - event.OnInputPoll() - allow multiple functions to be registered
This commit is contained in:
parent
28a73c8174
commit
ea24f236fb
|
@ -149,7 +149,7 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
if (luaf != null)
|
if (luaf != null)
|
||||||
{
|
{
|
||||||
Global.Emulator.CoreComm.InputCallback = delegate
|
Global.Emulator.CoreComm.InputCallback.Add(delegate
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -162,7 +162,7 @@ namespace BizHawk.Client.Common
|
||||||
"\nError message: "
|
"\nError message: "
|
||||||
+ e.Message);
|
+ e.Message);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Common
|
namespace BizHawk.Emulation.Common
|
||||||
|
@ -38,7 +39,7 @@ namespace BizHawk.Emulation.Common
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// for emu.on_snoop()
|
/// for emu.on_snoop()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action InputCallback;
|
public InputCallbackSystem InputCallback = new InputCallbackSystem();
|
||||||
|
|
||||||
public MemoryCallbackSystem MemoryCallbackSystem = new MemoryCallbackSystem();
|
public MemoryCallbackSystem MemoryCallbackSystem = new MemoryCallbackSystem();
|
||||||
|
|
||||||
|
@ -118,6 +119,34 @@ namespace BizHawk.Emulation.Common
|
||||||
private bool logging;
|
private bool logging;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class InputCallbackSystem
|
||||||
|
{
|
||||||
|
private List<Action> _list = new List<Action>();
|
||||||
|
|
||||||
|
public void Add(Action action)
|
||||||
|
{
|
||||||
|
_list.Add(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Call()
|
||||||
|
{
|
||||||
|
foreach (var action in _list)
|
||||||
|
{
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(Action action)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
_list.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class MemoryCallbackSystem
|
public class MemoryCallbackSystem
|
||||||
{
|
{
|
||||||
public int? ReadAddr = null;
|
public int? ReadAddr = null;
|
||||||
|
|
|
@ -237,7 +237,7 @@ namespace BizHawk
|
||||||
|
|
||||||
public byte ReadControls1(bool peek)
|
public byte ReadControls1(bool peek)
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
byte value = 0xFF;
|
byte value = 0xFF;
|
||||||
|
|
||||||
if (Controller["P1 Up"]) value &= 0xEF;
|
if (Controller["P1 Up"]) value &= 0xEF;
|
||||||
|
@ -251,7 +251,7 @@ namespace BizHawk
|
||||||
|
|
||||||
public byte ReadControls2(bool peek)
|
public byte ReadControls2(bool peek)
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
byte value = 0xFF;
|
byte value = 0xFF;
|
||||||
|
|
||||||
if (Controller["P2 Up"]) value &= 0xEF;
|
if (Controller["P2 Up"]) value &= 0xEF;
|
||||||
|
|
|
@ -155,7 +155,7 @@ namespace BizHawk.Emulation.Consoles.Calculator
|
||||||
|
|
||||||
byte ReadKeyboard()
|
byte ReadKeyboard()
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
//ref TI-9X
|
//ref TI-9X
|
||||||
|
|
||||||
int ret = 0xFF;
|
int ret = 0xFF;
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace BizHawk.Emulation.Consoles.GB
|
||||||
|
|
||||||
LibGambatte.Buttons ControllerCallback()
|
LibGambatte.Buttons ControllerCallback()
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
IsLagFrame = false;
|
IsLagFrame = false;
|
||||||
return CurrentButtons;
|
return CurrentButtons;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,8 @@ namespace BizHawk.Emulation.Consoles.GB
|
||||||
|
|
||||||
SetMemoryDomains();
|
SetMemoryDomains();
|
||||||
|
|
||||||
L.CoreComm.InputCallback = CallbackLinker;
|
L.CoreComm.InputCallback = CoreComm.InputCallback;
|
||||||
R.CoreComm.InputCallback = CallbackLinker;
|
R.CoreComm.InputCallback = CoreComm.InputCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IVideoProvider VideoProvider { get { return this; } }
|
public IVideoProvider VideoProvider { get { return this; } }
|
||||||
|
@ -77,15 +77,6 @@ namespace BizHawk.Emulation.Consoles.GB
|
||||||
public ControllerDefinition ControllerDefinition { get { return DualGbController; } }
|
public ControllerDefinition ControllerDefinition { get { return DualGbController; } }
|
||||||
public IController Controller { get; set; }
|
public IController Controller { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// each sub-core calls this
|
|
||||||
/// </summary>
|
|
||||||
void CallbackLinker()
|
|
||||||
{
|
|
||||||
if (CoreComm.InputCallback != null)
|
|
||||||
CoreComm.InputCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void FrameAdvance(bool render, bool rendersound = true)
|
public void FrameAdvance(bool render, bool rendersound = true)
|
||||||
{
|
{
|
||||||
LCont.Clear();
|
LCont.Clear();
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64
|
||||||
|
|
||||||
public void setControllers()
|
public void setControllers()
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
IsLagFrame = false;
|
IsLagFrame = false;
|
||||||
|
|
||||||
// Analog stick right = +X
|
// Analog stick right = +X
|
||||||
|
|
|
@ -392,7 +392,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
||||||
|
|
||||||
byte read_joyport(int addr)
|
byte read_joyport(int addr)
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
return handle_read_joyport(addr, false);
|
return handle_read_joyport(addr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -290,7 +290,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES
|
||||||
{
|
{
|
||||||
// as this is implemented right now, only P1 and P2 normal controllers work
|
// as this is implemented right now, only P1 and P2 normal controllers work
|
||||||
|
|
||||||
if (!nocallbacks && CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
//Console.WriteLine("{0} {1} {2} {3}", port, device, index, id);
|
//Console.WriteLine("{0} {1} {2} {3}", port, device, index, id);
|
||||||
|
|
||||||
string key = "P" + (1 + port) + " ";
|
string key = "P" + (1 + port) + " ";
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx
|
||||||
|
|
||||||
byte ReadInput()
|
byte ReadInput()
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
byte value = 0x3F;
|
byte value = 0x3F;
|
||||||
|
|
||||||
int player = SelectedController + 1;
|
int player = SelectedController + 1;
|
||||||
|
|
|
@ -108,7 +108,7 @@ namespace BizHawk.Emulation.Consoles.Sega
|
||||||
|
|
||||||
void ReadController(ref byte data)
|
void ReadController(ref byte data)
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
data &= 0xC0;
|
data &= 0xC0;
|
||||||
if ((data & 0x40) != 0) // TH high
|
if ((data & 0x40) != 0) // TH high
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Consoles.Sega
|
||||||
|
|
||||||
byte ReadControls1()
|
byte ReadControls1()
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
lagged = false;
|
lagged = false;
|
||||||
byte value = 0xFF;
|
byte value = 0xFF;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Consoles.Sega
|
||||||
|
|
||||||
byte ReadControls2()
|
byte ReadControls2()
|
||||||
{
|
{
|
||||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
CoreComm.InputCallback.Call();
|
||||||
lagged = false;
|
lagged = false;
|
||||||
byte value = 0xFF;
|
byte value = 0xFF;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue