diff --git a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs index ece738fc13..ee0b4567e7 100644 --- a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs @@ -183,6 +183,7 @@ namespace BizHawk public byte ReadControls1() { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); byte value = 0xFF; if (Controller["P1 Up"]) value &= 0xEF; @@ -196,6 +197,7 @@ namespace BizHawk public byte ReadControls2() { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); 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 4b75c8a1b1..fa287f7af6 100644 --- a/BizHawk.Emulation/Consoles/Calculator/TI83.cs +++ b/BizHawk.Emulation/Consoles/Calculator/TI83.cs @@ -126,6 +126,7 @@ namespace BizHawk.Emulation.Consoles.Calculator byte ReadKeyboard() { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); //ref TI-9X int ret = 0xFF; diff --git a/BizHawk.Emulation/Consoles/Coleco/ColecoVision.Core.cs b/BizHawk.Emulation/Consoles/Coleco/ColecoVision.Core.cs index 33085a31bf..a433805826 100644 --- a/BizHawk.Emulation/Consoles/Coleco/ColecoVision.Core.cs +++ b/BizHawk.Emulation/Consoles/Coleco/ColecoVision.Core.cs @@ -72,6 +72,7 @@ namespace BizHawk.Emulation.Consoles.Coleco public byte ReadControls() { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); byte value = 0xFF; if (Controller["P1 Up"]) value &= 0xFF; //TODO; diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs index b07fad894a..45b3759dfc 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -86,9 +86,9 @@ namespace BizHawk.Emulation.Consoles.GB public IController Controller { get; set; } - // can when this is called (or not called) be used to give information about lagged frames? LibGambatte.Buttons ControllerCallback() { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); IsLagFrame = false; return CurrentButtons; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index 58fa7b1620..783e185b03 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -251,6 +251,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo byte read_joyport(int addr) { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); //read joystick port //many todos here lagged = false; diff --git a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs index 3e893e4bd1..6c84fc197c 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -453,6 +453,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES ushort snes_input_state(int port, int device, int index, int id) { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); //Console.WriteLine("{0} {1} {2} {3}", port, device, index, id); string key = "P" + (1 + port) + " "; @@ -483,8 +484,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES void snes_input_poll() { - // libsnes.cpp calls this on every video refresh regardless of any underlying anything, so... - //IsLagFrame = false; + // this doesn't actually correspond to anything in the underlying bsnes; + // it gets called once per frame with video_refresh() and has nothing to do with anything } void snes_input_notify(int index) diff --git a/BizHawk.Emulation/Consoles/PC Engine/Input.cs b/BizHawk.Emulation/Consoles/PC Engine/Input.cs index 4e95c242ff..a2dca4aa77 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/Input.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/Input.cs @@ -39,6 +39,7 @@ byte ReadInput() { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); 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 df5d1980f3..c63421bfdb 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/IO.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/IO.cs @@ -106,7 +106,8 @@ void ReadController(ref byte data) { - data &= 0xC0; + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); + data &= 0xC0; if ((data & 0x40) != 0) // TH high { if (Controller["P1 Up"] == false) data |= 0x01; diff --git a/BizHawk.Emulation/Consoles/Sega/SMS/Input.cs b/BizHawk.Emulation/Consoles/Sega/SMS/Input.cs index 71044d8f49..7fc6bf56db 100644 --- a/BizHawk.Emulation/Consoles/Sega/SMS/Input.cs +++ b/BizHawk.Emulation/Consoles/Sega/SMS/Input.cs @@ -18,6 +18,7 @@ byte ReadControls1() { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); lagged = false; byte value = 0xFF; @@ -36,6 +37,7 @@ byte ReadControls2() { + if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); lagged = false; byte value = 0xFF; diff --git a/BizHawk.Emulation/Interfaces/CoreComms.cs b/BizHawk.Emulation/Interfaces/CoreComms.cs index 3973bb6cbe..8a130dfb69 100644 --- a/BizHawk.Emulation/Interfaces/CoreComms.cs +++ b/BizHawk.Emulation/Interfaces/CoreComms.cs @@ -20,6 +20,11 @@ namespace BizHawk /// if this is set, then the cpu should dump trace info to CpuTraceStream /// public TraceBuffer Tracer = new TraceBuffer(); + + /// + /// for emu.on_snoop() + /// + public System.Action InputCallback; } public class CoreOutputComm diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index b06eed399d..c05572db65 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -378,6 +378,7 @@ namespace BizHawk.MultiClient "enablerewind", "registerbefore", "registerafter", + "on_snoop", }; public static string[] MemoryFunctions = new string[] @@ -1171,6 +1172,27 @@ namespace BizHawk.MultiClient frame_registerafterfunc = luaf; } + public void emu_on_snoop(LuaFunction luaf) + { + if (luaf != null) + { + Global.Emulator.CoreInputComm.InputCallback = delegate() + { + try + { + luaf.Call(); + } + catch (SystemException e) + { + Global.MainForm.LuaConsole1.WriteToOutputWindow( + "error running function attached by lua function emu.on_snoop" + + "\nError message: " + e.Message); + } + }; + } + + } + //---------------------------------------------------- //Memory library //----------------------------------------------------