diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs index fe11e45150..56468fcd35 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs @@ -149,7 +149,7 @@ namespace BizHawk.Client.Common { if (luaf != null) { - Global.Emulator.CoreComm.InputCallback = delegate + Global.Emulator.CoreComm.InputCallback.Add(delegate { try { @@ -162,7 +162,7 @@ namespace BizHawk.Client.Common "\nError message: " + e.Message); } - }; + }); } else { diff --git a/BizHawk.Emulation.Common/Interfaces/CoreComms.cs b/BizHawk.Emulation.Common/Interfaces/CoreComms.cs index 6c8f241de4..eb85a3cddb 100644 --- a/BizHawk.Emulation.Common/Interfaces/CoreComms.cs +++ b/BizHawk.Emulation.Common/Interfaces/CoreComms.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Text; namespace BizHawk.Emulation.Common @@ -38,7 +39,7 @@ namespace BizHawk.Emulation.Common /// /// for emu.on_snoop() /// - public Action InputCallback; + public InputCallbackSystem InputCallback = new InputCallbackSystem(); public MemoryCallbackSystem MemoryCallbackSystem = new MemoryCallbackSystem(); @@ -118,6 +119,34 @@ namespace BizHawk.Emulation.Common private bool logging; } + public class InputCallbackSystem + { + private List _list = new List(); + + 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 int? ReadAddr = null; diff --git a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs index 72f8aeb78a..88441740a1 100644 --- a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs @@ -237,7 +237,7 @@ namespace BizHawk public byte ReadControls1(bool peek) { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); byte value = 0xFF; if (Controller["P1 Up"]) value &= 0xEF; @@ -251,7 +251,7 @@ namespace BizHawk public byte ReadControls2(bool peek) { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); byte value = 0xFF; if (Controller["P2 Up"]) value &= 0xEF; diff --git a/BizHawk.Emulation/Consoles/Calculator/TI83.cs b/BizHawk.Emulation/Consoles/Calculator/TI83.cs index 10dd4946b3..694284f8db 100644 --- a/BizHawk.Emulation/Consoles/Calculator/TI83.cs +++ b/BizHawk.Emulation/Consoles/Calculator/TI83.cs @@ -155,7 +155,7 @@ namespace BizHawk.Emulation.Consoles.Calculator byte ReadKeyboard() { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); //ref TI-9X int ret = 0xFF; diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs index b92455c064..c3c92a7d79 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -119,7 +119,7 @@ namespace BizHawk.Emulation.Consoles.GB LibGambatte.Buttons ControllerCallback() { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); IsLagFrame = false; return CurrentButtons; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/GambatteLink.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/GambatteLink.cs index 7ed6eafded..a71a184e51 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -54,8 +54,8 @@ namespace BizHawk.Emulation.Consoles.GB SetMemoryDomains(); - L.CoreComm.InputCallback = CallbackLinker; - R.CoreComm.InputCallback = CallbackLinker; + L.CoreComm.InputCallback = CoreComm.InputCallback; + R.CoreComm.InputCallback = CoreComm.InputCallback; } public IVideoProvider VideoProvider { get { return this; } } @@ -77,15 +77,6 @@ namespace BizHawk.Emulation.Consoles.GB public ControllerDefinition ControllerDefinition { get { return DualGbController; } } public IController Controller { get; set; } - /// - /// each sub-core calls this - /// - void CallbackLinker() - { - if (CoreComm.InputCallback != null) - CoreComm.InputCallback(); - } - public void FrameAdvance(bool render, bool rendersound = true) { LCont.Clear(); diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs index f63c897d61..4d06fc0e55 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs @@ -96,7 +96,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 public void setControllers() { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); IsLagFrame = false; // Analog stick right = +X diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index 95c9442687..692b12b21f 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -392,7 +392,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo byte read_joyport(int addr) { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); return handle_read_joyport(addr, false); } diff --git a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs index 3c80923719..bf26836caa 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -290,7 +290,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES { // 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); string key = "P" + (1 + port) + " "; diff --git a/BizHawk.Emulation/Consoles/PC Engine/Input.cs b/BizHawk.Emulation/Consoles/PC Engine/Input.cs index bf3f8c2f86..442dc8e820 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/Input.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/Input.cs @@ -41,7 +41,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx byte ReadInput() { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); byte value = 0x3F; int player = SelectedController + 1; diff --git a/BizHawk.Emulation/Consoles/Sega/Genesis/IO.cs b/BizHawk.Emulation/Consoles/Sega/Genesis/IO.cs index e96ed497b1..f1c01f61e1 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/IO.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/IO.cs @@ -108,7 +108,7 @@ namespace BizHawk.Emulation.Consoles.Sega void ReadController(ref byte data) { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); data &= 0xC0; if ((data & 0x40) != 0) // TH high { diff --git a/BizHawk.Emulation/Consoles/Sega/SMS/Input.cs b/BizHawk.Emulation/Consoles/Sega/SMS/Input.cs index 1aba9e5774..b2c86d07b7 100644 --- a/BizHawk.Emulation/Consoles/Sega/SMS/Input.cs +++ b/BizHawk.Emulation/Consoles/Sega/SMS/Input.cs @@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Consoles.Sega byte ReadControls1() { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); lagged = false; byte value = 0xFF; @@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Consoles.Sega byte ReadControls2() { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + CoreComm.InputCallback.Call(); lagged = false; byte value = 0xFF;