diff --git a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs index 2aa061e095..131a0c556d 100644 --- a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs @@ -96,7 +96,7 @@ namespace BizHawk { byte temp = mapper.ReadMemory((ushort)(addr&0x1FFF)); - if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasRead) { CoreInputComm.MemoryCallbackSystem.TriggerRead(addr); } @@ -108,9 +108,9 @@ namespace BizHawk { mapper.WriteMemory((ushort)(addr & 0x1FFF), value); - if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasWrite) { - CoreInputComm.MemoryCallbackSystem.WriteCallback(); + CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr); } } diff --git a/BizHawk.Emulation/Consoles/Calculator/TI83.cs b/BizHawk.Emulation/Consoles/Calculator/TI83.cs index a0ddd06c82..31935d34fa 100644 --- a/BizHawk.Emulation/Consoles/Calculator/TI83.cs +++ b/BizHawk.Emulation/Consoles/Calculator/TI83.cs @@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Consoles.Calculator ret = rom[romPage * 0x4000 + addr - 0x4000]; //other rom page else ret = ram[addr - 0x8000]; - if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasRead) { CoreInputComm.MemoryCallbackSystem.TriggerRead(addr); } @@ -55,9 +55,9 @@ namespace BizHawk.Emulation.Consoles.Calculator return; //other rom page else ram[addr - 0x8000] = value; - if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasWrite) { - CoreInputComm.MemoryCallbackSystem.WriteCallback(); + CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr); } } diff --git a/BizHawk.Emulation/Consoles/Coleco/ColecoVision.Core.cs b/BizHawk.Emulation/Consoles/Coleco/ColecoVision.Core.cs index edb9b6f60c..69f94d7565 100644 --- a/BizHawk.Emulation/Consoles/Coleco/ColecoVision.Core.cs +++ b/BizHawk.Emulation/Consoles/Coleco/ColecoVision.Core.cs @@ -40,7 +40,7 @@ namespace BizHawk.Emulation.Consoles.Coleco ret = 0xFF; } - if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasRead) { CoreInputComm.MemoryCallbackSystem.TriggerRead(addr); } @@ -55,9 +55,9 @@ namespace BizHawk.Emulation.Consoles.Coleco ram[addr] = value; } - if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasWrite) { - CoreInputComm.MemoryCallbackSystem.WriteCallback(); + CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr); } } diff --git a/BizHawk.Emulation/Consoles/Intellivision/MemoryMap.cs b/BizHawk.Emulation/Consoles/Intellivision/MemoryMap.cs index ae191f4565..4686b3fc97 100644 --- a/BizHawk.Emulation/Consoles/Intellivision/MemoryMap.cs +++ b/BizHawk.Emulation/Consoles/Intellivision/MemoryMap.cs @@ -115,7 +115,7 @@ namespace BizHawk.Emulation.Consoles.Intellivision break; } - if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasRead) { CoreInputComm.MemoryCallbackSystem.TriggerRead(addr); } @@ -286,9 +286,9 @@ namespace BizHawk.Emulation.Consoles.Intellivision } } - if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasWrite) { - CoreInputComm.MemoryCallbackSystem.WriteCallback(); + CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr); } return (cart || stic || psg); diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index 999a402920..4452bd2f22 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -369,7 +369,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo ret = sysbus_watch[addr].ApplyGameGenie(ret); } - if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasRead) { CoreInputComm.MemoryCallbackSystem.TriggerRead(addr); } @@ -426,9 +426,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo board.WritePRG(addr - 0x8000, value); } - if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasWrite) { - CoreInputComm.MemoryCallbackSystem.WriteCallback(); + CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr); } } diff --git a/BizHawk.Emulation/Consoles/PC Engine/MemoryMap.cs b/BizHawk.Emulation/Consoles/PC Engine/MemoryMap.cs index c0a661674e..dd6a9a60c2 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/MemoryMap.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/MemoryMap.cs @@ -33,7 +33,7 @@ return 0xFF; } - if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasRead) { CoreInputComm.MemoryCallbackSystem.TriggerRead(addr); } @@ -74,9 +74,9 @@ else Log.Error("MEM", "UNHANDLED WRITE: {0:X6}:{1:X2}", addr, value); - if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasWrite) { - CoreInputComm.MemoryCallbackSystem.WriteCallback(); + CoreInputComm.MemoryCallbackSystem.TriggerWrite(addr); } } } diff --git a/BizHawk.Emulation/Consoles/Sega/SMS/MemoryMap.Sega.cs b/BizHawk.Emulation/Consoles/Sega/SMS/MemoryMap.Sega.cs index 971ad06250..6892b01377 100644 --- a/BizHawk.Emulation/Consoles/Sega/SMS/MemoryMap.Sega.cs +++ b/BizHawk.Emulation/Consoles/Sega/SMS/MemoryMap.Sega.cs @@ -43,7 +43,7 @@ ret = SystemRam[address & RamSizeMask]; } - if (CoreInputComm.MemoryCallbackSystem.ReadCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasRead) { CoreInputComm.MemoryCallbackSystem.TriggerRead(address); } @@ -81,9 +81,9 @@ return; } - if (CoreInputComm.MemoryCallbackSystem.WriteCallback != null) + if (CoreInputComm.MemoryCallbackSystem.HasWrite) { - CoreInputComm.MemoryCallbackSystem.WriteCallback(); + CoreInputComm.MemoryCallbackSystem.TriggerWrite(address); } } diff --git a/BizHawk.Emulation/Interfaces/CoreComms.cs b/BizHawk.Emulation/Interfaces/CoreComms.cs index fc0b6d58ac..2bbde2a4aa 100644 --- a/BizHawk.Emulation/Interfaces/CoreComms.cs +++ b/BizHawk.Emulation/Interfaces/CoreComms.cs @@ -99,7 +99,19 @@ namespace BizHawk public class MemoryCallbackSystem { public int? ReadAddr = null; - public System.Action ReadCallback = null; + private System.Action ReadCallback = null; + public void SetReadCallback(System.Action func) + { + ReadCallback = func; + } + + public bool HasRead + { + get + { + return ReadCallback != null; + } + } public void TriggerRead(int addr) { @@ -120,7 +132,19 @@ namespace BizHawk } public int? WriteAddr = null; - public System.Action WriteCallback = null; + private System.Action WriteCallback = null; + public void SetWriteCallback(System.Action func) + { + WriteCallback = func; + } + + public bool HasWrite + { + get + { + return WriteCallback != null; + } + } public void TriggerWrite(int addr) { diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index b585015464..d4d8265ffc 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -2698,7 +2698,7 @@ namespace BizHawk.MultiClient } Global.Emulator.CoreInputComm.MemoryCallbackSystem.ReadAddr = _addr; - Global.Emulator.CoreInputComm.MemoryCallbackSystem.ReadCallback = delegate() + Global.Emulator.CoreInputComm.MemoryCallbackSystem.SetReadCallback(delegate() { try { @@ -2710,12 +2710,12 @@ namespace BizHawk.MultiClient "error running function attached by lua function event.onmemoryread" + "\nError message: " + e.Message); } - }; + }); } else { - Global.Emulator.CoreInputComm.MemoryCallbackSystem.ReadCallback = null; + Global.Emulator.CoreInputComm.MemoryCallbackSystem.SetReadCallback(null); } } @@ -2736,7 +2736,7 @@ namespace BizHawk.MultiClient } Global.Emulator.CoreInputComm.MemoryCallbackSystem.WriteAddr = _addr; - Global.Emulator.CoreInputComm.MemoryCallbackSystem.WriteCallback = delegate() + Global.Emulator.CoreInputComm.MemoryCallbackSystem.SetWriteCallback(delegate() { try { @@ -2748,11 +2748,11 @@ namespace BizHawk.MultiClient "error running function attached by lua function event.onmemoryread" + "\nError message: " + e.Message); } - }; + }); } else { - Global.Emulator.CoreInputComm.MemoryCallbackSystem.WriteCallback = null; + Global.Emulator.CoreInputComm.MemoryCallbackSystem.SetWriteCallback(null); } } }