From c41dea668342d44066d712e428f50a9d93fc2299 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Mon, 29 Apr 2024 23:22:40 -0700 Subject: [PATCH] Cleanup some GPGX stuff, fix system detection for archived roms --- .../Consoles/Sega/gpgx64/GPGX.ISettable.cs | 4 +- .../Consoles/Sega/gpgx64/GPGX.cs | 37 ++++++++++--------- .../Consoles/Sega/gpgx64/LibGPGX.cs | 12 +++--- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ISettable.cs index 2b7abc139f..02f59d175a 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ISettable.cs @@ -266,7 +266,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx [DisplayName("[SMS/GG] Load BIOS")] [Description("Indicates whether to load the system BIOS rom.")] [DefaultValue(false)] - public bool loadBIOS { get; set; } + public bool LoadBIOS { get; set; } [DisplayName("[SMS] FM Sound Chip Type")] [Description("Sets the method used to emulate the FM Sound Unit of the Sega Mark III/Master System. 'MAME' is fast and runs full speed on most systems.'Nuked' is cycle accurate, very high quality, and have substantial CPU requirements.")] @@ -339,7 +339,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx InputSystemA = SystemForSystem(ControlTypeLeft), InputSystemB = SystemForSystem(ControlTypeRight), Region = Region, - loadBIOS = loadBIOS, + LoadBIOS = LoadBIOS, ForceSram = game["sram"], SMSFMSoundChip = SMSFMSoundChip, GenesisFMSoundChip = GenesisFMSoundChip, diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs index eb9684da24..eb3d2ced79 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs @@ -38,14 +38,20 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx // Determining system ID from the rom. If no rom provided, assume Genesis (Sega CD) SystemId = VSystemID.Raw.GEN; - var RomExtension = string.Empty; + var romExtension = "GEN"; if (lp.Roms.Count >= 1) { SystemId = lp.Roms[0].Game.System; - // We need to pass the exact file extension to GPGX for it to correctly interpret the console - RomExtension = Path.GetExtension(lp.Roms[0].RomPath).RemovePrefix('.'); + romExtension = SystemId switch + { + VSystemID.Raw.GEN => "GEN", + VSystemID.Raw.SMS => "SMS", + VSystemID.Raw.GG => "GG", + VSystemID.Raw.SG => "SG", + _ => throw new InvalidOperationException("Invalid system id") + }; } - + // three or six button? // http://www.sega-16.com/forum/showthread.php?4398-Forgotten-Worlds-giving-you-GAME-OVER-immediately-Fix-inside&highlight=forgotten%20worlds @@ -97,18 +103,16 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx DriveLightEnabled = true; } - LibGPGX.INPUT_SYSTEM system_a = SystemForSystem(_syncSettings.ControlTypeLeft); - LibGPGX.INPUT_SYSTEM system_b = SystemForSystem(_syncSettings.ControlTypeRight); - - var initResult = Core.gpgx_init(RomExtension, LoadCallback, _syncSettings.GetNativeSettings(lp.Game)); + var initSettings = _syncSettings.GetNativeSettings(lp.Game); + var initResult = Core.gpgx_init(romExtension, LoadCallback, ref initSettings); if (!initResult) + { throw new Exception($"{nameof(Core.gpgx_init)}() failed"); + } { - int fpsnum = 60; - int fpsden = 1; - Core.gpgx_get_fps(ref fpsnum, ref fpsden); + Core.gpgx_get_fps(out var fpsnum, out var fpsden); VsyncNumerator = fpsnum; VsyncDenominator = fpsden; Region = VsyncNumerator / VsyncDenominator > 55 ? DisplayType.NTSC : DisplayType.PAL; @@ -137,7 +141,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx KillMemCallbacks(); _tracer = new GPGXTraceBuffer(this, _memoryDomains, this); - (ServiceProvider as BasicServiceProvider).Register(_tracer); + ((BasicServiceProvider)ServiceProvider).Register(_tracer); } _romfile = null; @@ -261,12 +265,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx if (firmwareID != null) { // this path will be the most common PEBKAC error, so be a bit more vocal about the problem - srcdata = CoreComm.CoreFileProvider.GetFirmware(firmwareID.Value, "GPGX firmwares are usually required."); - if (srcdata == null) - { - Console.WriteLine($"Frontend couldn't satisfy firmware request {firmwareID}"); - return 0; - } + srcdata = CoreComm.CoreFileProvider.GetFirmwareOrThrow(firmwareID.Value, "GPGX firmwares are required."); } else { @@ -384,7 +383,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx { inputsize = Marshal.SizeOf(typeof(LibGPGX.InputData)); if (!Core.gpgx_get_control(input, inputsize)) + { throw new Exception($"{nameof(Core.gpgx_get_control)}() failed"); + } ControlConverter = new(input, systemId: SystemId, cdButtons: _cds is not null); ControllerDefinition = ControlConverter.ControllerDef; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs index 5e08cc6bc3..8aad1e6985 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs @@ -3,12 +3,12 @@ using System.Runtime.InteropServices; using BizHawk.BizInvoke; +#pragma warning disable IDE1006 + namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx { public abstract class LibGPGX { - public const string DllName = "libgenplusgx.dll"; - [BizImport(CallingConvention.Cdecl)] public abstract void gpgx_get_video(out int w, out int h, out int pitch, ref IntPtr buffer); @@ -31,7 +31,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx } [StructLayout(LayoutKind.Sequential)] - public class InitSettings + public struct InitSettings { public uint BackdropColor; public Region Region; @@ -73,17 +73,17 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public GenesisFMSoundChipType GenesisFMSoundChip; public bool SpritesAlwaysOnTop; - public bool loadBIOS; + public bool LoadBIOS; } [BizImport(CallingConvention.Cdecl)] public abstract bool gpgx_init( string feromextension, load_archive_cb feload_archive_cb, - [In]InitSettings settings); + ref InitSettings settings); [BizImport(CallingConvention.Cdecl)] - public abstract void gpgx_get_fps(ref int num, ref int den); + public abstract void gpgx_get_fps(out int num, out int den); [BizImport(CallingConvention.Cdecl, Compatibility = true)] public abstract bool gpgx_get_control([Out]InputData dest, int bytes);