diff --git a/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs b/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs index 679860469b..36c8715e6a 100644 --- a/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs @@ -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 _allJoyPads; - private readonly Config _config; private readonly IWindowCoordsTransformer _displayManager; - private readonly InputManager _inputManager; - private readonly IMainFormForApi _mainForm; private readonly Action _logCallback; @@ -31,43 +21,6 @@ namespace BizHawk.Client.Common private readonly IGameInfo Game; - private readonly IReadOnlyCollection JoypadButtonsArray = Enum.GetValues(typeof(JoypadButton)).Cast().ToList(); //TODO can the return of GetValues be cast to JoypadButton[]? --yoshi - - private readonly JoypadStringToEnumConverter JoypadConverter = new JoypadStringToEnumConverter(); - - /// future humans: if this is broken, rewrite the caller instead if fixing it - 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 logCallback, IMainFormForApi mainForm, IWindowCoordsTransformer displayManager, InputManager inputManager, Config config, IEmulator emulator, IGameInfo game) + public EmuClientApi(Action 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(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) diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs index cb9bbdbcf2..e6eed73a14 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs @@ -63,14 +63,6 @@ namespace BizHawk.Client.Common void FrameSkip(int numFrames); - /// - /// Gets a for specified player - /// - /// Player (one based) you want current inputs - /// A populated with current inputs - /// Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information) - Joypad GetInput(int player); - bool GetSoundOn(); int GetTargetScanlineIntensity(); @@ -178,15 +170,6 @@ namespace BizHawk.Client.Common /// Bottom padding void SetGameExtraPadding(int left, int top = 0, int right = 0, int bottom = 0); - /// - /// Set inputs in specified to specified player - /// - /// Player (one based) whom inputs must be set - /// with inputs - /// Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information) - /// Still have some strange behaviour with multiple inputs; so this feature is still in beta - void SetInput(int player, Joypad joypad); - void SetScreenshotOSD(bool value); void SetSoundOn(bool enable); diff --git a/src/BizHawk.Client.Common/Api/Joypad.cs b/src/BizHawk.Client.Common/Api/Joypad.cs deleted file mode 100644 index 79d1eaa680..0000000000 --- a/src/BizHawk.Client.Common/Api/Joypad.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; - -using BizHawk.Common; - -namespace BizHawk.Client.Common -{ - /// - /// This class holds a joypad for any type of console - /// - public sealed class Joypad - { - private JoypadButton _pressedButtons; - private float _analogX; - private float _analogY; - private int _player; - - /// - /// Initialize a new instance of - /// - /// What this is used for - /// Which player this controller is assigned to - /// not in range 1..max where max is . - 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; - } - - /// - /// Add specified input to current ones - /// - /// Input to add - public void AddInput(JoypadButton input) - { - input &= System.AvailableButtons; - _pressedButtons |= input; - } - - /// - /// Clear inputs - /// - public void ClearInputs() - { - _pressedButtons = 0; - } - - /// - /// Remove specified input to current ones - /// - /// Input to remove - public void RemoveInput(JoypadButton input) - { - _pressedButtons ^= input; - } - - /// - /// Gets or sets X value for Analog stick - /// - /// The value you get will always be rounded to 0 decimal - public float AnalogX - { - get => (float)Math.Round(_analogX, 0); - set => _analogX = value; - } - - /// - /// Gets or sets Y value for Analog stick - /// - /// The value you get will always be rounded to 0 decimal - public float AnalogY - { - get => (float)Math.Round(_analogY, 0); - set => _analogY = value; - } - - /// - /// Gets or sets inputs - /// If you pass inputs unavailable for current system, they'll be removed - /// - /// It overrides all existing inputs - public JoypadButton Inputs - { - get => _pressedButtons; - set - { - value &= System.AvailableButtons; - _pressedButtons = value; - } - } - - /// - /// Gets for current - /// - public SystemInfo System { get; } - } -} diff --git a/src/BizHawk.Client.Common/Api/JoypadButton.cs b/src/BizHawk.Client.Common/Api/JoypadButton.cs deleted file mode 100644 index 11e80e0903..0000000000 --- a/src/BizHawk.Client.Common/Api/JoypadButton.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; - -namespace BizHawk.Client.Common -{ - /// - /// This enumeration list all buttons - /// for all existing controllers - /// - [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, - - /// - /// Master system Button 1 - /// - B1 = 16384, - - /// - /// Master system Button 1 - /// - B2 = 32768, - - /// - /// N64 C up - /// - CUp = 65536, - - /// - /// N64 C down - /// - CDown = 131072, - - /// - /// N64 C Left - /// - CLeft = 262144, - - /// - /// N64 C Right - /// - CRight = 524288, - - /// - /// N64 Analog stick - /// - AnalogStick = 1048576 - } -} diff --git a/src/BizHawk.Client.Common/Api/JoypadStringToEnumConverter.cs b/src/BizHawk.Client.Common/Api/JoypadStringToEnumConverter.cs deleted file mode 100644 index 5a59dea72a..0000000000 --- a/src/BizHawk.Client.Common/Api/JoypadStringToEnumConverter.cs +++ /dev/null @@ -1,229 +0,0 @@ -using System; -using System.Globalization; - -namespace BizHawk.Client.Common -{ - /// - /// This class holds a converter for BizHawk joypad buttons (which is a simple - /// It allows you to convert it to a value and vice versa - /// - /// 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 - /// - public sealed class JoypadStringToEnumConverter //:IValueConverter - { - /// - /// Convert BizHawk button to value - /// - /// you want to convert - /// The type of the binding target property - /// The converter parameter to use; null in our case - /// The culture to use in the converter - /// A that is equivalent to BizHawk button - /// Thrown when SystemId hasn't been found - 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"); - } - } - - - /// - /// Convert BizHawk button to value - /// - /// you want to convert - /// A that is equivalent to BizHawk button - /// Thrown when SystemId hasn't been found - public JoypadButton Convert(string value) - { - return (JoypadButton)Convert(value, null, null, CultureInfo.CurrentCulture); - } - - - /// - /// Convert a value to BizHawk - /// - /// you want to convert - /// The type of the binding target property - /// In our case, we pass the - /// The culture to use in the converter - /// A that is used by BizHawk - /// Thrown when hasn't been found - 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"); - } - } - - - /// - /// Convert a value to BizHawk - /// - /// you want to convert - /// Current - /// A that is used by BizHawk - /// Thrown when hasn't been found - public string ConvertBack(JoypadButton button, SystemInfo system) - { - return (string)ConvertBack(button, null, system, CultureInfo.CurrentCulture); - } - } -} diff --git a/src/BizHawk.Client.Common/SystemInfo.cs b/src/BizHawk.Client.Common/SystemInfo.cs deleted file mode 100644 index b74e8af724..0000000000 --- a/src/BizHawk.Client.Common/SystemInfo.cs +++ /dev/null @@ -1,315 +0,0 @@ -using System.Collections.Generic; - -namespace BizHawk.Client.Common -{ - /// - /// This class holds logic for System information. - /// That means specifications about a system that BizHawk emulates - /// - 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 AllSystemInfos = new List(); - - /// - /// Initializes a new instance of the class - /// - /// A that specify how the system name is displayed - /// A that specify what core is used - /// Maximum controller allowed by this system - /// Which buttons are available (i.e. are actually on the controller) for this system - private SystemInfo(string displayName, CoreSystem system, int maxControllers, JoypadButton availableButtons = 0) - { - DisplayName = displayName; - System = system; - MaxControllers = maxControllers; - AvailableButtons = availableButtons; - - AllSystemInfos.Add(this); - } - - /// - /// Gets the instance for Apple II - /// - public static SystemInfo Libretro { get; } = new SystemInfo("Libretro", CoreSystem.Libretro, 1); - - /// - /// Gets the instance for Apple II - /// - public static SystemInfo AppleII { get; } = new SystemInfo("Apple II", CoreSystem.AppleII, 1); - - /// - /// Gets the instance for Atari 2600 - /// - public static SystemInfo Atari2600 { get; } = new SystemInfo("Atari 2600", CoreSystem.Atari2600, 1); - - /// - /// Gets the instance for Atari 7800 - /// - public static SystemInfo Atari7800 { get; } = new SystemInfo("Atari 7800", CoreSystem.Atari7800, 1); - - /// - /// Gets the instance for Commodore 64 - /// - public static SystemInfo C64 { get; } = new SystemInfo("Commodore 64", CoreSystem.Commodore64, 1); - - /// - /// Gets the instance for Coleco Vision - /// - public static SystemInfo Coleco { get; } = new SystemInfo("ColecoVision", CoreSystem.ColecoVision, 1); - - /// - /// Gets the instance for Triple Gameboy - /// - public static SystemInfo GB3x { get; } = new SystemInfo("Game Boy Link 3x", CoreSystem.GB3x, 3, StandardButtons); - - /// - /// Gets the instance for Quad Gameboy - /// - public static SystemInfo GB4x { get; } = new SystemInfo("Game Boy Link 4x", CoreSystem.GB4x, 4, StandardButtons); - - /// - /// Gets the instance for Dual Gameboy - /// - public static SystemInfo DualGB { get; } = new SystemInfo("Game Boy Link", CoreSystem.DualGameBoy, 2, StandardButtons); - - /// - /// Gets the instance for Gameboy - /// - public static SystemInfo GB { get; } = new SystemInfo("GB", CoreSystem.GameBoy, 1, StandardButtons); - - /// - /// Gets the instance for Gameboy Advance - /// - public static SystemInfo GBA { get; } = new SystemInfo("Gameboy Advance", CoreSystem.GameBoyAdvance, 1, StandardButtons | JoypadButton.L | JoypadButton.R); - - /// - /// Gets the instance for Gameboy Color - /// - public static SystemInfo GBC { get; } = new SystemInfo("Gameboy Color", CoreSystem.GameBoy, 1, StandardButtons); - - /// - /// Gets the instance for Nintendo DS - /// - public static SystemInfo NDS { get; } = new SystemInfo("NDS", CoreSystem.NintendoDS, 1, StandardButtons | JoypadButton.L | JoypadButton.R | JoypadButton.X | JoypadButton.Y); - - /// - /// Gets the instance for Genesis - /// - public static SystemInfo Genesis { get; } = new SystemInfo("Genesis", CoreSystem.Genesis, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z); - - /// - /// Gets the instance for Game Gear - /// - public static SystemInfo GG { get; } = new SystemInfo("Game Gear", CoreSystem.MasterSystem, 1, UpDownLeftRight | JoypadButton.B1 | JoypadButton.B2); - - /// - /// Gets the instance for Intellivision - /// - public static SystemInfo Intellivision { get; } = new SystemInfo("Intellivision", CoreSystem.Intellivision, 2); - - /// - /// Gets the instance for Lynx - /// - public static SystemInfo Lynx { get; } = new SystemInfo("Lynx", CoreSystem.Lynx, 1); - - /// - /// Gets the instance for NES - /// - public static SystemInfo Nes { get; } = new SystemInfo("NES", CoreSystem.NES, 2, StandardButtons); - - /// - /// Gets the instance for Nintendo 64 - /// - 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); - - /// - /// Gets the instance for Null (i.e. nothing is emulated) emulator - /// - public static SystemInfo Null { get; } = new SystemInfo("", CoreSystem.Null, 0); - - /// - /// Gets the instance for PCEngine (TurboGrafx-16) - /// - public static SystemInfo PCE { get; } = new SystemInfo("TurboGrafx-16", CoreSystem.PCEngine, 1); - - /// - /// Gets the instance for PCEngine (TurboGrafx-16) + CD - /// - public static SystemInfo PCECD { get; } = new SystemInfo("TurboGrafx - 16(CD)", CoreSystem.PCEngine, 1); - - /// - /// Gets the instance for PlayStation - /// - public static SystemInfo PSX { get; } = new SystemInfo("PlayStation", CoreSystem.Playstation, 2); - - /// - /// Gets the instance for Sega Saturn - /// - public static SystemInfo Saturn { get; } = new SystemInfo("Saturn", CoreSystem.Saturn, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z); - - /// - /// Gets the instance for SG-1000 (Sega Game 1000) - /// - public static SystemInfo SG { get; } = new SystemInfo("SG-1000", CoreSystem.MasterSystem, 1); - - /// - /// Gets the instance for PCEngine (Supergraph FX) - /// - public static SystemInfo SGX { get; } = new SystemInfo("SuperGrafx", CoreSystem.PCEngine, 1); - - /// - /// Gets the instance for Sega Master System - /// - public static SystemInfo SMS { get; } = new SystemInfo("Sega Master System", CoreSystem.MasterSystem, 2, UpDownLeftRight | JoypadButton.B1 | JoypadButton.B2); - - /// - /// Gets the instance for SNES - /// - public static SystemInfo SNES { get; } = new SystemInfo("SNES", CoreSystem.SNES, 8, StandardButtons | JoypadButton.X | JoypadButton.Y | JoypadButton.L | JoypadButton.R); - - /// - /// Gets the instance for TI-83 - /// - public static SystemInfo TI83 { get; } = new SystemInfo("TI - 83", CoreSystem.TI83, 1); - - /// - /// Gets the instance for WonderSwan - /// - public static SystemInfo WonderSwan { get; } = new SystemInfo("WonderSwan", CoreSystem.WonderSwan, 1); - - /// - /// Gets the instance for Virtual Boy - /// - public static SystemInfo VirtualBoy { get; } = new SystemInfo("Virtual Boy", CoreSystem.VirtualBoy, 1); - - /// - /// Gets the instance for Vectrex - /// - public static SystemInfo Vectrex { get; } = new SystemInfo("Vectrex", CoreSystem.Vectrex, 2); - - /// - /// Gets the instance for TI-83 - /// - public static SystemInfo NeoGeoPocket { get; } = new SystemInfo("Neo-Geo Pocket", CoreSystem.NeoGeoPocket, 1); - - /// - /// Gets the instance for ZXSpectrum - /// - public static SystemInfo ZxSpectrum { get; } = new SystemInfo("ZX Spectrum", CoreSystem.ZXSpectrum, 2); - - /// - /// Gets the instance for AmstradCPC - /// - public static SystemInfo AmstradCpc { get; } = new SystemInfo("Amstrad CPC", CoreSystem.AmstradCPC, 2); - - /// - /// Gets the instance for GGL - /// - public static SystemInfo GGL { get; } = new SystemInfo("Game Gear Linked", CoreSystem.GGL, 2); - - /// - /// Gets the instance for ChannelF - /// - /// - public static SystemInfo ChannelF { get; } = new SystemInfo("Channel F", CoreSystem.ChannelF, 2); - /// - /// Gets the instance for Odyssey2 - /// - /// - public static SystemInfo O2 { get; } = new SystemInfo("Odyssey2", CoreSystem.Odyssey2, 2); - /// - /// Gets the instance for MAME - /// - public static SystemInfo Mame { get; } = new SystemInfo("MAME", CoreSystem.MAME, 4); - /// - /// Gets the instance for MSX - /// - 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); - - /// - /// Get a by its - /// - /// you're looking for - /// - public static SystemInfo FindByCoreSystem(CoreSystem system) - { - return AllSystemInfos.Find(s => s.System == system); - } - - /// - /// Determine if this is equal to specified - /// - /// to compare to - /// True if object is equal to this instance; otherwise, false - 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 - - /// - /// Returns a representation of current - /// In fact, return the same as DisplayName property - /// - public override string ToString() => DisplayName; - - /// - /// Determine if two are equals. - /// As it is all static instance, it just compare their reference - /// - /// First - /// Second - /// True if both system are equals; otherwise, false - public static bool operator ==(SystemInfo system1, SystemInfo system2) - { - return ReferenceEquals(system1, system2); - } - - /// - /// Determine if two are different. - /// As it is all static instance, it just compare their reference - /// - /// First - /// Second - /// True if both system are different; otherwise, false - public static bool operator !=(SystemInfo system1, SystemInfo system2) - { - return !(system1 == system2); - } - - /// - /// Gets available for this system - /// - public JoypadButton AvailableButtons { get; } - - /// - /// Gets the system name as - /// - public string DisplayName { get; } - - /// - /// Gets the maximum amount of controller allowed for this system - /// - public int MaxControllers { get; } - - /// - /// Gets core used for this system as enum - /// - public CoreSystem System { get; } - } -} diff --git a/src/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs index 7c9e134cb7..0eb3b8cfce 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs @@ -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 + }; } } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index d98a0aecc3..0eed07ecbb 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -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) {