diff --git a/BizHawk.Client.EmuHawk/config/SNES/SNESControllerConfig.cs b/BizHawk.Client.EmuHawk/config/SNES/SNESControllerConfig.cs index 04c94e9604..074af8a968 100644 --- a/BizHawk.Client.EmuHawk/config/SNES/SNESControllerConfig.cs +++ b/BizHawk.Client.EmuHawk/config/SNES/SNESControllerConfig.cs @@ -1,13 +1,10 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; using System.Windows.Forms; + using BizHawk.Emulation.Cores.Nintendo.SNES; using BizHawk.Client.Common; using BizHawk.Client.EmuHawk.WinFormExtensions; + namespace BizHawk.Client.EmuHawk { public partial class SNESControllerSettings : Form @@ -21,7 +18,7 @@ namespace BizHawk.Client.EmuHawk private void SNESControllerSettings_Load(object sender, EventArgs e) { - _syncSettings = (Global.Emulator as LibsnesCore).SyncSettings.Clone(); + _syncSettings = ((LibsnesCore)Global.Emulator).GetSyncSettings().Clone(); Port1ComboBox.PopulateFromEnum(_syncSettings.LeftPort); Port2ComboBox.PopulateFromEnum(_syncSettings.RightPort); } diff --git a/BizHawk.Emulation.Common/Interfaces/Services/ISettable.cs b/BizHawk.Emulation.Common/Interfaces/Services/ISettable.cs index ab56d42dc9..0bec101359 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/ISettable.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/ISettable.cs @@ -6,7 +6,7 @@ namespace BizHawk.Emulation.Common { /// /// This service provides mechanism for the client to set sync and non-sync related settings to the core - /// Settings are settings that can changge during the lifetime of the core and do not affect potential movie sync + /// Settings are settings that can change during the lifetime of the core and do not affect potential movie sync /// Sync Settings do not change during the lifetime of the core and affect movie sync /// If available, Sync settings are stored in movie files and automatically applied when the movie is loaded /// If this service is available the client can provide UI for the user to manage these settings @@ -59,10 +59,10 @@ namespace BizHawk.Emulation.Common { public SettingsAdapter(IEmulator e) { - emu = e; + _emu = e; Type impl = e.GetType().GetInterfaces() - .Where(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ISettable<,>)).FirstOrDefault(); + .FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ISettable<,>)); if (impl == null) { HasSettings = false; @@ -71,39 +71,37 @@ namespace BizHawk.Emulation.Common else { var tt = impl.GetGenericArguments(); - settingtype = tt[0]; - synctype = tt[1]; + var settingtype = tt[0]; + var synctype = tt[1]; HasSettings = settingtype != typeof(object); // object is used for a placeholder where an emu doesn't have both s and ss HasSyncSettings = synctype != typeof(object); if (HasSettings) { - gets = impl.GetMethod("GetSettings"); - puts = impl.GetMethod("PutSettings"); + _gets = impl.GetMethod("GetSettings"); + _puts = impl.GetMethod("PutSettings"); } + if (HasSyncSettings) { - getss = impl.GetMethod("GetSyncSettings"); - putss = impl.GetMethod("PutSyncSettings"); + _getss = impl.GetMethod("GetSyncSettings"); + _putss = impl.GetMethod("PutSyncSettings"); } } } - private IEmulator emu; + private readonly IEmulator _emu; - public bool HasSettings { get; private set; } - public bool HasSyncSettings { get; private set; } + public bool HasSettings { get; } + public bool HasSyncSettings { get; } - private object[] tmp1 = new object[1]; - private object[] tmp0 = new object[0]; + private readonly object[] _tmp1 = new object[1]; + private readonly object[] _tmp0 = new object[0]; - private Type settingtype; - private Type synctype; - - private MethodInfo gets; - private MethodInfo puts; - private MethodInfo getss; - private MethodInfo putss; + private readonly MethodInfo _gets; + private readonly MethodInfo _puts; + private readonly MethodInfo _getss; + private readonly MethodInfo _putss; public object GetSettings() { @@ -112,7 +110,7 @@ namespace BizHawk.Emulation.Common throw new InvalidOperationException(); } - return gets.Invoke(emu, tmp0); + return _gets.Invoke(_emu, _tmp0); } public object GetSyncSettings() @@ -122,7 +120,7 @@ namespace BizHawk.Emulation.Common throw new InvalidOperationException(); } - return (getss.Invoke(emu, tmp0)); + return _getss.Invoke(_emu, _tmp0); } public bool PutSettings(object o) @@ -132,8 +130,8 @@ namespace BizHawk.Emulation.Common throw new InvalidOperationException(); } - tmp1[0] = o; - return (bool)puts.Invoke(emu, tmp1); + _tmp1[0] = o; + return (bool)_puts.Invoke(_emu, _tmp1); } public bool PutSyncSettings(object o) @@ -143,10 +141,8 @@ namespace BizHawk.Emulation.Common throw new InvalidOperationException(); } - tmp1[0] = o; - return (bool)putss.Invoke(emu, tmp1); + _tmp1[0] = o; + return (bool)_putss.Invoke(_emu, _tmp1); } } - - } diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index c2e3a9f130..b236773592 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -901,6 +901,9 @@ + + LibsnesCore.cs + diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ISettable.cs new file mode 100644 index 0000000000..d1fb77f0fd --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.ISettable.cs @@ -0,0 +1,80 @@ +using BizHawk.Emulation.Common; + +namespace BizHawk.Emulation.Cores.Nintendo.SNES +{ + public partial class LibsnesCore : ISettable + { + public SnesSettings GetSettings() + { + return _settings.Clone(); + } + + public SnesSyncSettings GetSyncSettings() + { + return _syncSettings.Clone(); + } + + public bool PutSettings(SnesSettings o) + { + bool refreshneeded = o.Palette != _settings.Palette; + _settings = o; + if (refreshneeded) + { + RefreshPalette(); + } + + return false; + } + + public bool PutSyncSettings(SnesSyncSettings o) + { + bool ret = o.Profile != _syncSettings.Profile + || o.LeftPort != _syncSettings.LeftPort + || o.RightPort != _syncSettings.RightPort; + + _syncSettings = o; + return ret; + } + + private SnesSettings _settings; + private SnesSyncSettings _syncSettings; + + public class SnesSettings + { + public bool ShowBG1_0 { get; set; } = true; + public bool ShowBG2_0 { get; set; } = true; + public bool ShowBG3_0 { get; set; } = true; + public bool ShowBG4_0 { get; set; } = true; + public bool ShowBG1_1 { get; set; } = true; + public bool ShowBG2_1 { get; set; } = true; + public bool ShowBG3_1 { get; set; } = true; + public bool ShowBG4_1 { get; set; } = true; + public bool ShowOBJ_0 { get; set; } = true; + public bool ShowOBJ_1 { get; set; } = true; + public bool ShowOBJ_2 { get; set; } = true; + public bool ShowOBJ_3 { get; set; } = true; + + public bool AlwaysDoubleSize { get; set; } = false; + public bool ForceDeterminism { get; set; } = true; + public string Palette { get; set; } = "BizHawk"; + + public SnesSettings Clone() + { + return (SnesSettings)MemberwiseClone(); + } + } + + public class SnesSyncSettings + { + public string Profile { get; set; } = "Performance"; // "Accuracy", and "Compatibility" are the other choicec, todo: make this an enum + + public LibsnesControllerDeck.ControllerType LeftPort { get; set; } = LibsnesControllerDeck.ControllerType.Gamepad; + public LibsnesControllerDeck.ControllerType RightPort { get; set; } = LibsnesControllerDeck.ControllerType.Gamepad; + + public SnesSyncSettings Clone() + { + return (SnesSyncSettings)MemberwiseClone(); + } + } + } +} diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 0dca98f6ea..bcf18ae93f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES portedUrl: "http://byuu.org/" )] [ServiceNotApplicable(typeof(IDriveLight))] - public unsafe class LibsnesCore : IEmulator, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ICodeDataLogger, + public unsafe partial class LibsnesCore : IEmulator, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ICodeDataLogger, IDebuggable, ISettable { public LibsnesCore(GameInfo game, byte[] romData, bool deterministicEmulation, byte[] xmlData, CoreComm comm, object Settings, object SyncSettings) @@ -56,8 +56,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES game.FirmwareHash = sgbRomData.HashSHA1(); } - this.Settings = (SnesSettings)Settings ?? new SnesSettings(); - this.SyncSettings = (SnesSyncSettings)SyncSettings ?? new SnesSyncSettings(); + _settings = (SnesSettings)Settings ?? new SnesSettings(); + _syncSettings = (SnesSyncSettings)SyncSettings ?? new SnesSyncSettings(); api = new LibsnesApi(GetDllPath()); api.ReadHook = ReadHook; @@ -66,8 +66,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES ScanlineHookManager = new MyScanlineHookManager(this); - _controllerDeck = new LibsnesControllerDeck(this.SyncSettings.LeftPort, - this.SyncSettings.RightPort); + _controllerDeck = new LibsnesControllerDeck( + _syncSettings.LeftPort, + _syncSettings.RightPort); _controllerDeck.NativeInit(api); api.CMD_init(); @@ -221,7 +222,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES return "Compatibility"; } - return SyncSettings.Profile; + return _syncSettings.Profile; } } @@ -530,7 +531,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES void snes_video_refresh(int* data, int width, int height) { - bool doubleSize = Settings.AlwaysDoubleSize; + bool doubleSize = _settings.AlwaysDoubleSize; bool lineDouble = doubleSize, dotDouble = doubleSize; vidWidth = width; @@ -647,18 +648,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES if (powerSignal) api.CMD_power(); var enables = new LibsnesApi.LayerEnables(); - enables.BG1_Prio0 = Settings.ShowBG1_0; - enables.BG1_Prio1 = Settings.ShowBG1_1; - enables.BG2_Prio0 = Settings.ShowBG2_0; - enables.BG2_Prio1 = Settings.ShowBG2_1; - enables.BG3_Prio0 = Settings.ShowBG3_0; - enables.BG3_Prio1 = Settings.ShowBG3_1; - enables.BG4_Prio0 = Settings.ShowBG4_0; - enables.BG4_Prio1 = Settings.ShowBG4_1; - enables.Obj_Prio0 = Settings.ShowOBJ_0; - enables.Obj_Prio1 = Settings.ShowOBJ_1; - enables.Obj_Prio2 = Settings.ShowOBJ_2; - enables.Obj_Prio3 = Settings.ShowOBJ_3; + enables.BG1_Prio0 = _settings.ShowBG1_0; + enables.BG1_Prio1 = _settings.ShowBG1_1; + enables.BG2_Prio0 = _settings.ShowBG2_0; + enables.BG2_Prio1 = _settings.ShowBG2_1; + enables.BG3_Prio0 = _settings.ShowBG3_0; + enables.BG3_Prio1 = _settings.ShowBG3_1; + enables.BG4_Prio0 = _settings.ShowBG4_0; + enables.BG4_Prio1 = _settings.ShowBG4_1; + enables.Obj_Prio0 = _settings.ShowOBJ_0; + enables.Obj_Prio1 = _settings.ShowOBJ_1; + enables.Obj_Prio2 = _settings.ShowOBJ_2; + enables.Obj_Prio3 = _settings.ShowOBJ_3; api.SetLayerEnables(ref enables); RefreshMemoryCallbacks(false); @@ -727,7 +728,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES { get { - return Settings.ForceDeterminism && + return _settings.ForceDeterminism && (CurrentProfile == "Compatibility" || CurrentProfile == "Accuracy"); } private set { /* Do nothing */ } @@ -1254,70 +1255,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES void RefreshPalette() { - SetPalette((SnesColors.ColorType)Enum.Parse(typeof(SnesColors.ColorType), Settings.Palette, false)); + SetPalette((SnesColors.ColorType)Enum.Parse(typeof(SnesColors.ColorType), _settings.Palette, false)); } - - SnesSettings Settings; - public SnesSyncSettings SyncSettings; - - public SnesSettings GetSettings() { return Settings.Clone(); } - public SnesSyncSettings GetSyncSettings() { return SyncSettings.Clone(); } - public bool PutSettings(SnesSettings o) - { - bool refreshneeded = o.Palette != Settings.Palette; - Settings = o; - if (refreshneeded) - RefreshPalette(); - return false; - } - public bool PutSyncSettings(SnesSyncSettings o) - { - bool ret = o.Profile != SyncSettings.Profile - || o.LeftPort != SyncSettings.LeftPort - || o.RightPort != SyncSettings.RightPort; - - SyncSettings = o; - return ret; - } - - public class SnesSettings - { - public bool ShowBG1_0 = true; - public bool ShowBG2_0 = true; - public bool ShowBG3_0 = true; - public bool ShowBG4_0 = true; - public bool ShowBG1_1 = true; - public bool ShowBG2_1 = true; - public bool ShowBG3_1 = true; - public bool ShowBG4_1 = true; - public bool ShowOBJ_0 = true; - public bool ShowOBJ_1 = true; - public bool ShowOBJ_2 = true; - public bool ShowOBJ_3 = true; - - public bool AlwaysDoubleSize = false; - public bool ForceDeterminism = true; - public string Palette = "BizHawk"; - - public SnesSettings Clone() - { - return (SnesSettings)MemberwiseClone(); - } - } - - public class SnesSyncSettings - { - public string Profile = "Performance"; // "Accuracy", and "Compatibility" are the other choicec, todo: make this an enum - - public LibsnesControllerDeck.ControllerType LeftPort { get; set; } = LibsnesControllerDeck.ControllerType.Gamepad; - public LibsnesControllerDeck.ControllerType RightPort { get; set; } = LibsnesControllerDeck.ControllerType.Gamepad; - - public SnesSyncSettings Clone() - { - return (SnesSyncSettings)MemberwiseClone(); - } - } } public class ScanlineHookManager diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 1df6022c36..778cd2062b 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -16,9 +16,11 @@ DO_NOT_SHOW DO_NOT_SHOW DO_NOT_SHOW + HINT AF ARGB AV + BG BMP CDL CGB @@ -33,6 +35,7 @@ IRQ NES NMI + OBJ OR PC PCECD