From c9666a56478a6c6d4fd1435c27f7315a25551831 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Sat, 23 Nov 2024 22:21:26 -0800 Subject: [PATCH] [GPGX] Add offscreen shot control, make lightgun inputs always use the correct screen width/height Fixes #4120 --- .../Base Implementations/Bk2MnemonicLookup.cs | 1 + .../Consoles/Sega/gpgx64/GPGX.IEmulator.cs | 5 +++-- .../Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs | 3 +-- .../Consoles/Sega/gpgx64/GPGXControlConverter.cs | 14 ++++++++++++-- .../Consoles/Sega/gpgx64/LibGPGX.cs | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/BizHawk.Emulation.Common/Base Implementations/Bk2MnemonicLookup.cs b/src/BizHawk.Emulation.Common/Base Implementations/Bk2MnemonicLookup.cs index 1af66ded8e..436f31cc90 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/Bk2MnemonicLookup.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/Bk2MnemonicLookup.cs @@ -133,6 +133,7 @@ namespace BizHawk.Emulation.Common ["Lightgun Start"] = 'S', ["Lightgun B"] = 'B', ["Lightgun C"] = 'C', + ["Lightgun Offscreen Shot"] = 'O', ["Microphone"] = 'M', ["Star"] = '*', diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IEmulator.cs index d63373ba89..716c9e941d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IEmulator.cs @@ -59,8 +59,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx // if (!Core.gpgx_get_control(input, inputsize)) // throw new Exception("gpgx_get_control() failed!"); - ControlConverter.ScreenWidth = _vwidth; - ControlConverter.ScreenHeight = _vheight; + Core.gpgx_get_video(out var screenWidth, out var screenHeight, out _, out _); + ControlConverter.ScreenWidth = screenWidth; + ControlConverter.ScreenHeight = screenHeight; ControlConverter.Convert(controller, _input); if (controller.IsPressed("Pause")) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs index 257623b19e..bfec4f2031 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs @@ -96,8 +96,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx using (_elf.EnterExit()) { - var src = IntPtr.Zero; - Core.gpgx_get_video(out var gpwidth, out var gpheight, out var gppitch, ref src); + Core.gpgx_get_video(out var gpwidth, out var gpheight, out var gppitch, out var src); _vwidth = gpwidth; _vheight = gpheight; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs index 449dec1357..4f0c86dfd5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs @@ -78,6 +78,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx new("Lightgun Start", LibGPGX.INPUT_KEYS.INPUT_MENACER_START), new("Lightgun B", LibGPGX.INPUT_KEYS.INPUT_MENACER_B), new("Lightgun C", LibGPGX.INPUT_KEYS.INPUT_MENACER_C), + new("Lightgun Offscreen Shot", LibGPGX.INPUT_KEYS.INPUT_MENACER_TRIGGER), ]; private static readonly CName[] Activator = @@ -164,12 +165,21 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx { // lightgun needs to be transformed to match the current screen resolution ControllerDef.AddXYPair($"P{player} Lightgun {{0}}", AxisPairOrientation.RightAndUp, 0.RangeTo(10000), 5000); //TODO verify direction against hardware + var no = $"P{player} Lightgun Offscreen Shot"; var nx = $"P{player} Lightgun X"; var ny = $"P{player} Lightgun Y"; _converts.Add(() => { - _target.analog[(2 * idx) + 0] = (short)(_source.AxisValue(nx) / 10000.0f * (ScreenWidth - 1)); - _target.analog[(2 * idx) + 1] = (short)(_source.AxisValue(ny) / 10000.0f * (ScreenHeight - 1)); + if (_source.IsPressed(no)) + { + _target.analog[(2 * idx) + 0] = 512; + _target.analog[(2 * idx) + 1] = 512; + } + else + { + _target.analog[(2 * idx) + 0] = (short)(_source.AxisValue(nx) / 10000.0f * (ScreenWidth - 1)); + _target.analog[(2 * idx) + 1] = (short)(_source.AxisValue(ny) / 10000.0f * (ScreenHeight - 1)); + } }); } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs index 59c21040c3..473a542535 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public abstract class LibGPGX { [BizImport(CallingConvention.Cdecl)] - public abstract void gpgx_get_video(out int w, out int h, out int pitch, ref IntPtr buffer); + public abstract void gpgx_get_video(out int w, out int h, out int pitch, out IntPtr buffer); [BizImport(CallingConvention.Cdecl)] public abstract void gpgx_get_audio(ref int n, ref IntPtr buffer);