break SNES settings code into its own file
This commit is contained in:
parent
8f3d1613a0
commit
d1d6c20749
|
@ -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<LibsnesControllerDeck.ControllerType>(_syncSettings.LeftPort);
|
||||
Port2ComboBox.PopulateFromEnum<LibsnesControllerDeck.ControllerType>(_syncSettings.RightPort);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
/// <summary>
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -901,6 +901,9 @@
|
|||
<Compile Include="Consoles\Nintendo\SNES9X\LibSnes9x.cs" />
|
||||
<Compile Include="Consoles\Nintendo\SNES9X\Snes9x.cs" />
|
||||
<Compile Include="Consoles\Nintendo\SNES\LibsnesApi.cs" />
|
||||
<Compile Include="Consoles\Nintendo\SNES\LibsnesCore.ISettable.cs">
|
||||
<DependentUpon>LibsnesCore.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\SNES\LibsnesApi_BRK.cs" />
|
||||
<Compile Include="Consoles\Nintendo\SNES\LibsnesApi_CMD.cs" />
|
||||
<Compile Include="Consoles\Nintendo\SNES\LibsnesApi_Enums.cs" />
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.SNES
|
||||
{
|
||||
public partial class LibsnesCore : ISettable<LibsnesCore.SnesSettings, LibsnesCore.SnesSyncSettings>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<LibsnesCore.SnesSettings, LibsnesCore.SnesSyncSettings>
|
||||
{
|
||||
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
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1201/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1202/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1210/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedMemberInSuper_002ELocal/@EntryIndexedValue">HINT</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AF/@EntryIndexedValue">AF</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ARGB/@EntryIndexedValue">ARGB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AV/@EntryIndexedValue">AV</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BG/@EntryIndexedValue">BG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BMP/@EntryIndexedValue">BMP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CDL/@EntryIndexedValue">CDL</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CGB/@EntryIndexedValue">CGB</s:String>
|
||||
|
@ -33,6 +35,7 @@
|
|||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IRQ/@EntryIndexedValue">IRQ</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NES/@EntryIndexedValue">NES</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NMI/@EntryIndexedValue">NMI</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OBJ/@EntryIndexedValue">OBJ</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OR/@EntryIndexedValue">OR</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PC/@EntryIndexedValue">PC</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PCECD/@EntryIndexedValue">PCECD</s:String>
|
||||
|
|
Loading…
Reference in New Issue