diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 1d91932851..d389b70458 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -914,7 +914,7 @@ LibsnesCore.cs - LibsnesCore.cs + LibsnesCore.cs LibsnesCore.cs @@ -938,6 +938,7 @@ LibsnesCore.cs + diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 1ee0217f21..9161ac8482 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -233,7 +233,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES _core = core; } - public override void OnHooksChanged() + protected override void OnHooksChanged() { _core.OnScanlineHooksChanged(); } @@ -670,48 +670,4 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES } } } - - public class ScanlineHookManager - { - public void Register(object tag, Action callback) - { - var rr = new RegistrationRecord - { - tag = tag, - callback = callback - }; - - Unregister(tag); - records.Add(rr); - OnHooksChanged(); - } - - public int HookCount => records.Count; - - public virtual void OnHooksChanged() - { - } - - public void Unregister(object tag) - { - records.RemoveAll(r => r.tag == tag); - } - - public void HandleScanline(int scanline) - { - foreach (var rr in records) - { - rr.callback(scanline); - } - } - - private readonly List records = new List(); - - private class RegistrationRecord - { - public object tag; - public int scanline = 0; - public Action callback; - } - } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/ScanlineHookManager.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/ScanlineHookManager.cs new file mode 100644 index 0000000000..cf91b7e18d --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/ScanlineHookManager.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +namespace BizHawk.Emulation.Cores.Nintendo.SNES +{ + // TODO: This class is specifically for the SNES Graphics Debugger, but written generally, perhaps it could be moved to a more generic place + public class ScanlineHookManager + { + private readonly List _records = new List(); + + public void Register(object tag, Action callback) + { + Unregister(tag); + + _records.Add(new RegistrationRecord + { + Tag = tag, + Callback = callback + }); + + OnHooksChanged(); + } + + public int HookCount => _records.Count; + + protected virtual void OnHooksChanged() + { + } + + public void Unregister(object tag) + { + _records.RemoveAll(r => r.Tag == tag); + } + + public void HandleScanline(int scanline) + { + foreach (var rr in _records) + { + rr.Callback(scanline); + } + } + + private class RegistrationRecord + { + public object Tag { get; set; } + + public int Scanline { get; set; } = 0; + + public Action Callback { get; set; } + } + } +}