Remove IEmuClientApi.Get/SetInput and supporting types, and cleanup

what's a deprecation cycle
also -1k LOC whoo
This commit is contained in:
YoshiRulz 2021-02-25 15:33:49 +10:00
parent ef0b380192
commit c11d410fb7
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
8 changed files with 49 additions and 951 deletions

View File

@ -1,28 +1,18 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
using BizHawk.Emulation.Cores.PCEngine;
using BizHawk.Emulation.Cores.Sega.MasterSystem;
namespace BizHawk.Client.Common
{
public sealed class EmuClientApi : IEmuClientApi
{
private readonly List<Joypad> _allJoyPads;
private readonly Config _config;
private readonly IWindowCoordsTransformer _displayManager;
private readonly InputManager _inputManager;
private readonly IMainFormForApi _mainForm;
private readonly Action<string> _logCallback;
@ -31,43 +21,6 @@ namespace BizHawk.Client.Common
private readonly IGameInfo Game;
private readonly IReadOnlyCollection<JoypadButton> JoypadButtonsArray = Enum.GetValues(typeof(JoypadButton)).Cast<JoypadButton>().ToList(); //TODO can the return of GetValues be cast to JoypadButton[]? --yoshi
private readonly JoypadStringToEnumConverter JoypadConverter = new JoypadStringToEnumConverter();
/// <remarks>future humans: if this is broken, rewrite the caller instead if fixing it</remarks>
private SystemInfo RunningSystem
{
get
{
switch (Emulator.SystemId)
{
case "PCE" when Emulator is PCEngine pceHawk:
return pceHawk.Type switch
{
NecSystemType.TurboGrafx => SystemInfo.PCE,
NecSystemType.TurboCD => SystemInfo.PCECD,
NecSystemType.SuperGrafx => SystemInfo.SGX,
_ => throw new ArgumentOutOfRangeException()
};
case "PCE":
return SystemInfo.PCE;
case "SMS":
var sms = (SMS) Emulator;
return sms.IsSG1000
? SystemInfo.SG
: sms.IsGameGear
? SystemInfo.GG
: SystemInfo.SMS;
case "GB":
if (Emulator is Gameboy gb) return gb.IsCGBMode() ? SystemInfo.GBC : SystemInfo.GB;
return SystemInfo.DualGB;
default:
return SystemInfo.FindByCoreSystem(SystemIdConverter.Convert(Emulator.SystemId));
}
}
}
public static readonly BizHawkSystemIdToEnumConverter SystemIdConverter = new BizHawkSystemIdToEnumConverter();
private readonly IVideoProvider VideoProvider;
@ -82,27 +35,14 @@ namespace BizHawk.Client.Common
public event StateSavedEventHandler StateSaved;
public EmuClientApi(Action<string> logCallback, IMainFormForApi mainForm, IWindowCoordsTransformer displayManager, InputManager inputManager, Config config, IEmulator emulator, IGameInfo game)
public EmuClientApi(Action<string> logCallback, IMainFormForApi mainForm, IWindowCoordsTransformer displayManager, Config config, IEmulator emulator, IGameInfo game)
{
_config = config;
_displayManager = displayManager;
Emulator = emulator;
Game = game;
_inputManager = inputManager;
_logCallback = logCallback;
_mainForm = mainForm;
try
{
_allJoyPads = new List<Joypad>(RunningSystem.MaxControllers);
for (var i = 1; i <= RunningSystem.MaxControllers; i++)
_allJoyPads.Add(new Joypad(RunningSystem, i));
}
catch (Exception e)
{
Console.Error.WriteLine("Apihawk is garbage and may not work this session.");
Console.Error.WriteLine(e);
}
VideoProvider = Emulator.AsVideoProviderOrDefault();
}
@ -149,38 +89,6 @@ namespace BizHawk.Client.Common
_mainForm.FrameSkipMessage();
}
private void GetAllInputs()
{
var joypadAdapter = _inputManager.AutofireStickyXorAdapter;
var pressedButtons = joypadAdapter.Definition.BoolButtons.Where(b => joypadAdapter.IsPressed(b));
foreach (var j in _allJoyPads) j.ClearInputs();
Parallel.ForEach(pressedButtons, button =>
{
if (RunningSystem == SystemInfo.GB) _allJoyPads[0].AddInput(JoypadConverter.Convert(button));
else if (int.TryParse(button.Substring(1, 2), out var player)) _allJoyPads[player - 1].AddInput(JoypadConverter.Convert(button.Substring(3)));
});
if ((RunningSystem.AvailableButtons & JoypadButton.AnalogStick) == JoypadButton.AnalogStick)
{
for (var i = 1; i <= RunningSystem.MaxControllers; i++)
{
_allJoyPads[i - 1].AnalogX = joypadAdapter.AxisValue($"P{i} X Axis");
_allJoyPads[i - 1].AnalogY = joypadAdapter.AxisValue($"P{i} Y Axis");
}
}
}
public Joypad GetInput(int player)
{
if (!1.RangeTo(RunningSystem.MaxControllers).Contains(player))
throw new IndexOutOfRangeException($"{RunningSystem.DisplayName} does not support {player} controller(s)");
GetAllInputs();
return _allJoyPads[player - 1];
}
public bool GetSoundOn() => _config.SoundEnabled;
public int GetTargetScanlineIntensity() => _config.TargetScanlineFilterIntensity;
@ -273,39 +181,6 @@ namespace BizHawk.Client.Common
_mainForm.FrameBufferResized();
}
public void SetInput(int player, Joypad joypad)
{
if (!1.RangeTo(RunningSystem.MaxControllers).Contains(player)) throw new IndexOutOfRangeException($"{RunningSystem.DisplayName} does not support {player} controller(s)");
if (joypad.Inputs == 0)
{
_inputManager.AutofireStickyXorAdapter.ClearStickies();
}
else
{
foreach (var button in JoypadButtonsArray.Where(button => joypad.Inputs.HasFlag(button)))
{
_inputManager.AutofireStickyXorAdapter.SetSticky(
RunningSystem == SystemInfo.GB
? $"{JoypadConverter.ConvertBack(button, RunningSystem)}"
: $"P{player} {JoypadConverter.ConvertBack(button, RunningSystem)}",
isSticky: true
);
}
}
#if false // Using this breaks joypad usage (even in UI); have to figure out why
if ((RunningSystem.AvailableButtons & JoypadButton.AnalogStick) == JoypadButton.AnalogStick)
{
for (var i = 1; i <= RunningSystem.MaxControllers; i++)
{
_inputManager.AutofireStickyXorAdapter.SetAxis($"P{i} X Axis", _allJoyPads[i - 1].AnalogX);
_inputManager.AutofireStickyXorAdapter.SetAxis($"P{i} Y Axis", _allJoyPads[i - 1].AnalogY);
}
}
#endif
}
public void SetScreenshotOSD(bool value) => _config.ScreenshotCaptureOsd = value;
public void SetSoundOn(bool enable)

View File

@ -63,14 +63,6 @@ namespace BizHawk.Client.Common
void FrameSkip(int numFrames);
/// <summary>
/// Gets a <see cref="Joypad"/> for specified player
/// </summary>
/// <param name="player">Player (one based) you want current inputs</param>
/// <returns>A <see cref="Joypad"/> populated with current inputs</returns>
/// <exception cref="IndexOutOfRangeException">Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information)</exception>
Joypad GetInput(int player);
bool GetSoundOn();
int GetTargetScanlineIntensity();
@ -178,15 +170,6 @@ namespace BizHawk.Client.Common
/// <param name="bottom">Bottom padding</param>
void SetGameExtraPadding(int left, int top = 0, int right = 0, int bottom = 0);
/// <summary>
/// Set inputs in specified <see cref="Joypad"/> to specified player
/// </summary>
/// <param name="player">Player (one based) whom inputs must be set</param>
/// <param name="joypad"><see cref="Joypad"/> with inputs</param>
/// <exception cref="IndexOutOfRangeException">Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information)</exception>
/// <remarks>Still have some strange behaviour with multiple inputs; so this feature is still in beta</remarks>
void SetInput(int player, Joypad joypad);
void SetScreenshotOSD(bool value);
void SetSoundOn(bool enable);

View File

@ -1,101 +0,0 @@
using System;
using BizHawk.Common;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class holds a joypad for any type of console
/// </summary>
public sealed class Joypad
{
private JoypadButton _pressedButtons;
private float _analogX;
private float _analogY;
private int _player;
/// <summary>
/// Initialize a new instance of <see cref="Joypad"/>
/// </summary>
/// <param name="system">What <see cref="SystemInfo"/> this <see cref="Joypad"/> is used for</param>
/// <param name="player">Which player this controller is assigned to</param>
/// <exception cref="IndexOutOfRangeException"><paramref name="player"/> not in range <c>1..max</c> where <c>max</c> is <paramref name="system"/>.<see cref="SystemInfo.MaxControllers"/></exception>
public Joypad(SystemInfo system, int player)
{
if (!1.RangeTo(system.MaxControllers).Contains(player))
{
throw new InvalidOperationException($"{player} is invalid for {system.DisplayName}");
}
System = system;
_player = player;
}
/// <summary>
/// Add specified input to current ones
/// </summary>
/// <param name="input">Input to add</param>
public void AddInput(JoypadButton input)
{
input &= System.AvailableButtons;
_pressedButtons |= input;
}
/// <summary>
/// Clear inputs
/// </summary>
public void ClearInputs()
{
_pressedButtons = 0;
}
/// <summary>
/// Remove specified input to current ones
/// </summary>
/// <param name="input">Input to remove</param>
public void RemoveInput(JoypadButton input)
{
_pressedButtons ^= input;
}
/// <summary>
/// Gets or sets X value for Analog stick
/// </summary>
/// <remarks>The value you get will always be rounded to 0 decimal</remarks>
public float AnalogX
{
get => (float)Math.Round(_analogX, 0);
set => _analogX = value;
}
/// <summary>
/// Gets or sets Y value for Analog stick
/// </summary>
/// <remarks>The value you get will always be rounded to 0 decimal</remarks>
public float AnalogY
{
get => (float)Math.Round(_analogY, 0);
set => _analogY = value;
}
/// <summary>
/// Gets or sets inputs
/// If you pass inputs unavailable for current system, they'll be removed
/// </summary>
/// <remarks>It overrides all existing inputs</remarks>
public JoypadButton Inputs
{
get => _pressedButtons;
set
{
value &= System.AvailableButtons;
_pressedButtons = value;
}
}
/// <summary>
/// Gets <see cref="SystemInfo"/> for current <see cref="Joypad"/>
/// </summary>
public SystemInfo System { get; }
}
}

View File

@ -1,62 +0,0 @@
using System;
namespace BizHawk.Client.Common
{
/// <summary>
/// This enumeration list all buttons
/// for all existing controllers
/// </summary>
[Flags]
public enum JoypadButton
{
A = 1,
B = 2,
C = 4,
X = 8,
Y = 16,
Z = 32,
L = 64,
R = 128,
Start = 256,
Select = 512,
Up = 1024,
Down = 2048,
Left = 4096,
Right = 8192,
/// <summary>
/// Master system Button 1
/// </summary>
B1 = 16384,
/// <summary>
/// Master system Button 1
/// </summary>
B2 = 32768,
/// <summary>
/// N64 C up
/// </summary>
CUp = 65536,
/// <summary>
/// N64 C down
/// </summary>
CDown = 131072,
/// <summary>
/// N64 C Left
/// </summary>
CLeft = 262144,
/// <summary>
/// N64 C Right
/// </summary>
CRight = 524288,
/// <summary>
/// N64 Analog stick
/// </summary>
AnalogStick = 1048576
}
}

View File

@ -1,229 +0,0 @@
using System;
using System.Globalization;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class holds a converter for BizHawk joypad buttons (which is a simple <see cref="string"/>
/// It allows you to convert it to a <see cref="JoypadButton"/> value and vice versa
/// </summary>
/// <remarks>I made it this way just in case one day we need it for WPF (DependencyProperty binding). Just uncomment :IValueConverter implementation
/// I didn't implemented it because of mono compatibility
/// </remarks>
public sealed class JoypadStringToEnumConverter //:IValueConverter
{
/// <summary>
/// Convert BizHawk button <see cref="string"/> to <see cref="JoypadButton"/> value
/// </summary>
/// <param name="value"><see cref="string"/> you want to convert</param>
/// <param name="targetType">The type of the binding target property</param>
/// <param name="parameter">The converter parameter to use; null in our case</param>
/// <param name="cultureInfo">The culture to use in the converter</param>
/// <returns>A <see cref="JoypadButton"/> that is equivalent to BizHawk <see cref="string"/> button</returns>
/// <exception cref="IndexOutOfRangeException">Thrown when SystemId hasn't been found</exception>
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
switch (((string)value).ToUpper())
{
case "A":
return JoypadButton.A;
case "B":
return JoypadButton.B;
case "B1":
return JoypadButton.B1;
case "B2":
return JoypadButton.B2;
case "C":
return JoypadButton.C;
case "C UP":
return JoypadButton.CUp;
case "C DOWN":
return JoypadButton.CDown;
case "C LEFT":
return JoypadButton.CLeft;
case "C RIGHT":
return JoypadButton.CRight;
case "X":
return JoypadButton.X;
case "Y":
return JoypadButton.Y;
case "Z":
return JoypadButton.Z;
case "START":
return JoypadButton.Start;
case "SELECT":
return JoypadButton.Select;
case "UP":
case "DPAD U":
return JoypadButton.Up;
case "DOWN":
case "DPAD D":
return JoypadButton.Down;
case "LEFT":
case "DPAD L":
return JoypadButton.Left;
case "RIGHT":
case "DPAD R":
return JoypadButton.Right;
case "L":
return JoypadButton.L;
case "R":
return JoypadButton.R;
default:
throw new IndexOutOfRangeException($"{value} is missing in convert list");
}
}
/// <summary>
/// Convert BizHawk button <see cref="string"/> to <see cref="JoypadButton"/> value
/// </summary>
/// <param name="value"><see cref="string"/> you want to convert</param>
/// <returns>A <see cref="JoypadButton"/> that is equivalent to BizHawk <see cref="string"/> button</returns>
/// <exception cref="IndexOutOfRangeException">Thrown when SystemId hasn't been found</exception>
public JoypadButton Convert(string value)
{
return (JoypadButton)Convert(value, null, null, CultureInfo.CurrentCulture);
}
/// <summary>
/// Convert a <see cref="JoypadButton"/> value to BizHawk <see cref="string"/>
/// </summary>
/// <param name="value"><see cref="JoypadButton"/> you want to convert</param>
/// <param name="targetType">The type of the binding target property</param>
/// <param name="parameter">In our case, we pass the <see cref="SystemInfo"/></param>
/// <param name="cultureInfo">The culture to use in the converter</param>
/// <returns>A <see cref="string"/> that is used by BizHawk</returns>
/// <exception cref="IndexOutOfRangeException">Thrown when <see cref="JoypadButton"/> hasn't been found</exception>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
switch ((JoypadButton)value)
{
case JoypadButton.A:
return "A";
case JoypadButton.B:
return "B";
case JoypadButton.B1:
return "B1";
case JoypadButton.B2:
return "B2";
case JoypadButton.C:
return "C";
case JoypadButton.CUp:
return "C Up";
case JoypadButton.CDown:
return "C Down";
case JoypadButton.CLeft:
return "C Left";
case JoypadButton.CRight:
return "C Right";
case JoypadButton.X:
return "X";
case JoypadButton.Y:
return "Y";
case JoypadButton.Z:
return "Z";
case JoypadButton.Start:
return "Start";
case JoypadButton.Select:
return "Select";
case JoypadButton.Up:
if (((SystemInfo)parameter) == SystemInfo.N64)
{
return "Dpad U";
}
else
{
return "Up";
}
case JoypadButton.Down:
if (((SystemInfo)parameter) == SystemInfo.N64)
{
return "Dpad D";
}
else
{
return "Down";
}
case JoypadButton.Left:
if (((SystemInfo)parameter) == SystemInfo.N64)
{
return "Dpad L";
}
else
{
return "Left";
}
case JoypadButton.Right:
if (((SystemInfo)parameter) == SystemInfo.N64)
{
return "Dpad R";
}
else
{
return "Right";
}
case JoypadButton.L:
return "L";
case JoypadButton.R:
return "R";
default:
throw new IndexOutOfRangeException($"{value} is missing in convert list");
}
}
/// <summary>
/// Convert a <see cref="JoypadButton"/> value to BizHawk <see cref="string"/>
/// </summary>
/// <param name="button"><see cref="JoypadButton"/> you want to convert</param>
/// <param name="system">Current <see cref="SystemInfo"/></param>
/// <returns>A <see cref="string"/> that is used by BizHawk</returns>
/// <exception cref="IndexOutOfRangeException">Thrown when <see cref="JoypadButton"/> hasn't been found</exception>
public string ConvertBack(JoypadButton button, SystemInfo system)
{
return (string)ConvertBack(button, null, system, CultureInfo.CurrentCulture);
}
}
}

View File

@ -1,315 +0,0 @@
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class holds logic for System information.
/// That means specifications about a system that BizHawk emulates
/// </summary>
public sealed class SystemInfo
{
private const JoypadButton UpDownLeftRight = JoypadButton.Up | JoypadButton.Down | JoypadButton.Left | JoypadButton.Right;
private const JoypadButton StandardButtons = JoypadButton.A | JoypadButton.B | JoypadButton.Start | JoypadButton.Select | UpDownLeftRight;
private static readonly List<SystemInfo> AllSystemInfos = new List<SystemInfo>();
/// <summary>
/// Initializes a new instance of the <see cref="SystemInfo"/> class
/// </summary>
/// <param name="displayName">A <see cref="string"/> that specify how the system name is displayed</param>
/// <param name="system">A <see cref="CoreSystem"/> that specify what core is used</param>
/// <param name="maxControllers">Maximum controller allowed by this system</param>
/// <param name="availableButtons">Which buttons are available (i.e. are actually on the controller) for this system</param>
private SystemInfo(string displayName, CoreSystem system, int maxControllers, JoypadButton availableButtons = 0)
{
DisplayName = displayName;
System = system;
MaxControllers = maxControllers;
AvailableButtons = availableButtons;
AllSystemInfos.Add(this);
}
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Apple II
/// </summary>
public static SystemInfo Libretro { get; } = new SystemInfo("Libretro", CoreSystem.Libretro, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Apple II
/// </summary>
public static SystemInfo AppleII { get; } = new SystemInfo("Apple II", CoreSystem.AppleII, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Atari 2600
/// </summary>
public static SystemInfo Atari2600 { get; } = new SystemInfo("Atari 2600", CoreSystem.Atari2600, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Atari 7800
/// </summary>
public static SystemInfo Atari7800 { get; } = new SystemInfo("Atari 7800", CoreSystem.Atari7800, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Commodore 64
/// </summary>
public static SystemInfo C64 { get; } = new SystemInfo("Commodore 64", CoreSystem.Commodore64, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Coleco Vision
/// </summary>
public static SystemInfo Coleco { get; } = new SystemInfo("ColecoVision", CoreSystem.ColecoVision, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Triple Gameboy
/// </summary>
public static SystemInfo GB3x { get; } = new SystemInfo("Game Boy Link 3x", CoreSystem.GB3x, 3, StandardButtons);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Quad Gameboy
/// </summary>
public static SystemInfo GB4x { get; } = new SystemInfo("Game Boy Link 4x", CoreSystem.GB4x, 4, StandardButtons);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Dual Gameboy
/// </summary>
public static SystemInfo DualGB { get; } = new SystemInfo("Game Boy Link", CoreSystem.DualGameBoy, 2, StandardButtons);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Gameboy
/// </summary>
public static SystemInfo GB { get; } = new SystemInfo("GB", CoreSystem.GameBoy, 1, StandardButtons);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Gameboy Advance
/// </summary>
public static SystemInfo GBA { get; } = new SystemInfo("Gameboy Advance", CoreSystem.GameBoyAdvance, 1, StandardButtons | JoypadButton.L | JoypadButton.R);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Gameboy Color
/// </summary>
public static SystemInfo GBC { get; } = new SystemInfo("Gameboy Color", CoreSystem.GameBoy, 1, StandardButtons);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Nintendo DS
/// </summary>
public static SystemInfo NDS { get; } = new SystemInfo("NDS", CoreSystem.NintendoDS, 1, StandardButtons | JoypadButton.L | JoypadButton.R | JoypadButton.X | JoypadButton.Y);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Genesis
/// </summary>
public static SystemInfo Genesis { get; } = new SystemInfo("Genesis", CoreSystem.Genesis, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Game Gear
/// </summary>
public static SystemInfo GG { get; } = new SystemInfo("Game Gear", CoreSystem.MasterSystem, 1, UpDownLeftRight | JoypadButton.B1 | JoypadButton.B2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Intellivision
/// </summary>
public static SystemInfo Intellivision { get; } = new SystemInfo("Intellivision", CoreSystem.Intellivision, 2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Lynx
/// </summary>
public static SystemInfo Lynx { get; } = new SystemInfo("Lynx", CoreSystem.Lynx, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for NES
/// </summary>
public static SystemInfo Nes { get; } = new SystemInfo("NES", CoreSystem.NES, 2, StandardButtons);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Nintendo 64
/// </summary>
public static SystemInfo N64 { get; } = new SystemInfo("Nintendo 64", CoreSystem.Nintendo64, 4, StandardButtons ^ JoypadButton.Select | JoypadButton.Z | JoypadButton.CUp | JoypadButton.CDown | JoypadButton.CLeft | JoypadButton.CRight | JoypadButton.AnalogStick | JoypadButton.L | JoypadButton.R);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Null (i.e. nothing is emulated) emulator
/// </summary>
public static SystemInfo Null { get; } = new SystemInfo("", CoreSystem.Null, 0);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for PCEngine (TurboGrafx-16)
/// </summary>
public static SystemInfo PCE { get; } = new SystemInfo("TurboGrafx-16", CoreSystem.PCEngine, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for PCEngine (TurboGrafx-16) + CD
/// </summary>
public static SystemInfo PCECD { get; } = new SystemInfo("TurboGrafx - 16(CD)", CoreSystem.PCEngine, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for PlayStation
/// </summary>
public static SystemInfo PSX { get; } = new SystemInfo("PlayStation", CoreSystem.Playstation, 2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Sega Saturn
/// </summary>
public static SystemInfo Saturn { get; } = new SystemInfo("Saturn", CoreSystem.Saturn, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for SG-1000 (Sega Game 1000)
/// </summary>
public static SystemInfo SG { get; } = new SystemInfo("SG-1000", CoreSystem.MasterSystem, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for PCEngine (Supergraph FX)
/// </summary>
public static SystemInfo SGX { get; } = new SystemInfo("SuperGrafx", CoreSystem.PCEngine, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Sega Master System
/// </summary>
public static SystemInfo SMS { get; } = new SystemInfo("Sega Master System", CoreSystem.MasterSystem, 2, UpDownLeftRight | JoypadButton.B1 | JoypadButton.B2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for SNES
/// </summary>
public static SystemInfo SNES { get; } = new SystemInfo("SNES", CoreSystem.SNES, 8, StandardButtons | JoypadButton.X | JoypadButton.Y | JoypadButton.L | JoypadButton.R);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for TI-83
/// </summary>
public static SystemInfo TI83 { get; } = new SystemInfo("TI - 83", CoreSystem.TI83, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for WonderSwan
/// </summary>
public static SystemInfo WonderSwan { get; } = new SystemInfo("WonderSwan", CoreSystem.WonderSwan, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Virtual Boy
/// </summary>
public static SystemInfo VirtualBoy { get; } = new SystemInfo("Virtual Boy", CoreSystem.VirtualBoy, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Vectrex
/// </summary>
public static SystemInfo Vectrex { get; } = new SystemInfo("Vectrex", CoreSystem.Vectrex, 2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for TI-83
/// </summary>
public static SystemInfo NeoGeoPocket { get; } = new SystemInfo("Neo-Geo Pocket", CoreSystem.NeoGeoPocket, 1);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for ZXSpectrum
/// </summary>
public static SystemInfo ZxSpectrum { get; } = new SystemInfo("ZX Spectrum", CoreSystem.ZXSpectrum, 2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for AmstradCPC
/// </summary>
public static SystemInfo AmstradCpc { get; } = new SystemInfo("Amstrad CPC", CoreSystem.AmstradCPC, 2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for GGL
/// </summary>
public static SystemInfo GGL { get; } = new SystemInfo("Game Gear Linked", CoreSystem.GGL, 2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for ChannelF
/// </summary>
///
public static SystemInfo ChannelF { get; } = new SystemInfo("Channel F", CoreSystem.ChannelF, 2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for Odyssey2
/// </summary>
///
public static SystemInfo O2 { get; } = new SystemInfo("Odyssey2", CoreSystem.Odyssey2, 2);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for MAME
/// </summary>
public static SystemInfo Mame { get; } = new SystemInfo("MAME", CoreSystem.MAME, 4);
/// <summary>
/// Gets the <see cref="SystemInfo"/> instance for MSX
/// </summary>
public static SystemInfo MSX { get; } = new SystemInfo("MSX", CoreSystem.MSX, 2);
public static SystemInfo Sgb { get; } = new SystemInfo("SGB", CoreSystem.SuperGameBoy, 4);
public static SystemInfo Pcfx { get; } = new SystemInfo("PCFX", CoreSystem.PcFx, 1);
public static SystemInfo UzeBox { get; } = new SystemInfo("uzem", CoreSystem.UzeBox, 1);
/// <summary>
/// Get a <see cref="SystemInfo"/> by its <see cref="CoreSystem"/>
/// </summary>
/// <param name="system"><see cref="CoreSystem"/> you're looking for</param>
/// <returns><see cref="SystemInfo"/></returns>
public static SystemInfo FindByCoreSystem(CoreSystem system)
{
return AllSystemInfos.Find(s => s.System == system);
}
/// <summary>
/// Determine if this <see cref="SystemInfo"/> is equal to specified <see cref="object"/>
/// </summary>
/// <param name="obj"><see cref="object"/> to compare to</param>
/// <returns>True if object is equal to this instance; otherwise, false</returns>
public override bool Equals(object obj)
{
if (obj is SystemInfo info)
{
return this == info;
}
return base.Equals(obj);
}
public override int GetHashCode() => DisplayName.GetHashCode(); // should be unique considering the property's purpose
/// <summary>
/// Returns a <see cref="string"/> representation of current <see cref="SystemInfo"/>
/// In fact, return the same as DisplayName property
/// </summary>
public override string ToString() => DisplayName;
/// <summary>
/// Determine if two <see cref="SystemInfo"/> are equals.
/// As it is all static instance, it just compare their reference
/// </summary>
/// <param name="system1">First <see cref="SystemInfo"/></param>
/// <param name="system2">Second <see cref="SystemInfo"/></param>
/// <returns>True if both system are equals; otherwise, false</returns>
public static bool operator ==(SystemInfo system1, SystemInfo system2)
{
return ReferenceEquals(system1, system2);
}
/// <summary>
/// Determine if two <see cref="SystemInfo"/> are different.
/// As it is all static instance, it just compare their reference
/// </summary>
/// <param name="system1">First <see cref="SystemInfo"/></param>
/// <param name="system2">Second <see cref="SystemInfo"/></param>
/// <returns>True if both system are different; otherwise, false</returns>
public static bool operator !=(SystemInfo system1, SystemInfo system2)
{
return !(system1 == system2);
}
/// <summary>
/// Gets <see cref="JoypadButton"/> available for this system
/// </summary>
public JoypadButton AvailableButtons { get; }
/// <summary>
/// Gets the system name as <see cref="string"/>
/// </summary>
public string DisplayName { get; }
/// <summary>
/// Gets the maximum amount of controller allowed for this system
/// </summary>
public int MaxControllers { get; }
/// <summary>
/// Gets core used for this system as <see cref="CoreSystem"/> enum
/// </summary>
public CoreSystem System { get; }
}
}

View File

@ -1,7 +1,6 @@
using System.Drawing;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
using BizHawk.Emulation.Cores.Nintendo.SNES;
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
@ -49,104 +48,52 @@ namespace BizHawk.Client.EmuHawk.CoreExtensions
return str;
}
public static SystemInfo System(this IEmulator emulator)
public static string GetSystemDisplayName(this IEmulator emulator) => emulator.SystemId switch
{
switch (emulator.SystemId)
{
default:
case "NULL":
return SystemInfo.Null;
case "NES":
return SystemInfo.Nes;
case "INTV":
return SystemInfo.Intellivision;
case "SG":
return SystemInfo.SG;
case "SMS":
if (emulator is SMS gg && gg.IsGameGear)
{
return SystemInfo.GG;
}
if (emulator is SMS sg && sg.IsSG1000)
{
return SystemInfo.SG;
}
return SystemInfo.SMS;
case "PCECD":
return SystemInfo.PCECD;
case "PCE":
return SystemInfo.PCE;
case "SGX":
return SystemInfo.SGX;
case "GEN":
return SystemInfo.Genesis;
case "TI83":
return SystemInfo.TI83;
case "SNES":
return SystemInfo.SNES;
case "GB":
/*
if ((Emulator as IGameboyCommon).IsCGBMode())
{
return SystemInfo.GBC;
}
*/
return SystemInfo.GB;
case "A26":
return SystemInfo.Atari2600;
case "A78":
return SystemInfo.Atari7800;
case "C64":
return SystemInfo.C64;
case "Coleco":
return SystemInfo.Coleco;
case "GBA":
return SystemInfo.GBA;
case "NDS":
return SystemInfo.NDS;
case "N64":
return SystemInfo.N64;
case "SAT":
return SystemInfo.Saturn;
case "DGB":
return SystemInfo.DualGB;
case "GB3x":
return SystemInfo.GB3x;
case "GB4x":
return SystemInfo.GB4x;
case "WSWAN":
return SystemInfo.WonderSwan;
case "Lynx":
return SystemInfo.Lynx;
case "PSX":
return SystemInfo.PSX;
case "AppleII":
return SystemInfo.AppleII;
case "Libretro":
return SystemInfo.Libretro;
case "VB":
return SystemInfo.VirtualBoy;
case "VEC":
return SystemInfo.Vectrex;
case "NGP":
return SystemInfo.NeoGeoPocket;
case "ZXSpectrum":
return SystemInfo.ZxSpectrum;
case "AmstradCPC":
return SystemInfo.AmstradCpc;
case "ChannelF":
return SystemInfo.ChannelF;
case "O2":
return SystemInfo.O2;
case "MAME":
return SystemInfo.Mame;
case "uzem":
return SystemInfo.UzeBox;
case "PCFX":
return SystemInfo.Pcfx;
}
}
"NULL" => string.Empty,
"NES" => "NES",
"INTV" => "Intellivision",
"SG" => "SG-1000",
"SMS" when emulator is SMS { IsGameGear: true } => "Game Gear",
"SMS" when emulator is SMS { IsSG1000: true } => "SG-1000",
"SMS" => "Sega Master System",
"PCECD" => "TurboGrafx - 16(CD)",
"PCE" => "TurboGrafx-16",
"SGX" => "SuperGrafx",
"GEN" => "Genesis",
"TI83" => "TI - 83",
"SNES" => "SNES",
#if false
"GB" when emulator is IGameboyCommon gb && gb.IsCGBMode() => "Gameboy Color",
#endif
"GB" => "GB",
"A26" => "Atari 2600",
"A78" => "Atari 7800",
"C64" => "Commodore 64",
"Coleco" => "ColecoVision",
"GBA" => "Gameboy Advance",
"NDS" => "NDS",
"N64" => "Nintendo 64",
"SAT" => "Saturn",
"DGB" => "Game Boy Link",
"GB3x" => "Game Boy Link 3x",
"GB4x" => "Game Boy Link 4x",
"WSWAN" => "WonderSwan",
"Lynx" => "Lynx",
"PSX" => "PlayStation",
"AppleII" => "Apple II",
"Libretro" => "Libretro",
"VB" => "Virtual Boy",
"VEC" => "Vectrex",
"NGP" => "Neo-Geo Pocket",
"ZXSpectrum" => "ZX Spectrum",
"AmstradCPC" => "Amstrad CPC",
"ChannelF" => "Channel F",
"O2" => "Odyssey2",
"MAME" => "MAME",
"uzem" => "uzem",
"PCFX" => "PCFX",
_ => string.Empty
};
}
}

View File

@ -1634,7 +1634,7 @@ namespace BizHawk.Client.EmuHawk
sb.Append($"{VersionInfo.CustomBuildString} ");
}
sb.Append(Emulator.IsNull() ? "BizHawk" : Emulator.System().DisplayName);
sb.Append(Emulator.IsNull() ? "BizHawk" : Emulator.GetSystemDisplayName());
if (VersionInfo.DeveloperBuild)
{