From 359657c29a7a42f2d3f049d4056f53dbac732826 Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Tue, 25 May 2021 03:49:27 +0200 Subject: [PATCH] Add a payload controller for the new bsnes core --- .../Consoles/Nintendo/BSNES/BsnesApi_Enums.cs | 3 +- .../Nintendo/BSNES/BsnesControllers.cs | 29 ++++++++ .../Consoles/Nintendo/BSNES/BsnesCore.cs | 5 +- .../vpads_schemata/SnesSchema.cs | 73 ++++++++++++++++--- 4 files changed, 96 insertions(+), 14 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi_Enums.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi_Enums.cs index 5b3411b5b3..e02d025153 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi_Enums.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi_Enums.cs @@ -27,7 +27,8 @@ SuperMultitap, SuperScope, Justifier, - Justifiers + Justifiers, + Payload } public enum ENTROPY diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesControllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesControllers.cs index a2784bcd6b..c46817deec 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesControllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesControllers.cs @@ -25,6 +25,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES BSNES_INPUT_DEVICE.SuperScope => new BsnesSuperScopeController(), BSNES_INPUT_DEVICE.Justifier => new BsnesJustifierController(false), BSNES_INPUT_DEVICE.Justifiers => new BsnesJustifierController(true), + BSNES_INPUT_DEVICE.Payload => new BsnesPayloadController(), _ => throw new InvalidOperationException() }; } @@ -306,4 +307,32 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES return _state[index * 4 + id]; } } + + internal class BsnesPayloadController : IBsnesController + { + private readonly bool[] _state = new bool[32]; + + private static readonly ControllerDefinition _definition = new() + { + BoolButtons = Enumerable.Range(0, 32).Select(i => $"0B{i}").ToList() + }; + + public ControllerDefinition Definition => _definition; + + public void UpdateState(IController controller) + { + for (int i = 0; i < 32; i++) + { + _state[i] = controller.IsPressed(Definition.BoolButtons[i]); + } + } + + public short GetState(int index, int id) + { + if (index >= 2 || id >= 16) + return 0; + + return (short) (_state[index * 2 + id] ? 1 : 0); + } + } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs index 79ba002c48..6de9810386 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs @@ -66,7 +66,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES generate_palette(); // TODO: massive random hack till waterboxhost gets fixed to support 5+ args ushort mergedBools = (ushort) ((_syncSettings.Hotfixes ? 1 << 8 : 0) | (_syncSettings.FastPPU ? 1 : 0)); - Api.core.snes_init(_syncSettings.Entropy, _syncSettings.LeftPort, _syncSettings.RightPort, mergedBools); + BsnesApi.BSNES_INPUT_DEVICE rightPort = _syncSettings.RightPort == BsnesApi.BSNES_INPUT_DEVICE.Payload + ? BsnesApi.BSNES_INPUT_DEVICE.SuperMultitap + : _syncSettings.RightPort; + Api.core.snes_init(_syncSettings.Entropy, _syncSettings.LeftPort, rightPort, mergedBools); Api.SetCallbacks(callbacks); // start up audio resampler diff --git a/src/BizHawk.Emulation.Cores/vpads_schemata/SnesSchema.cs b/src/BizHawk.Emulation.Cores/vpads_schemata/SnesSchema.cs index afde157d12..9f6a5321f1 100644 --- a/src/BizHawk.Emulation.Cores/vpads_schemata/SnesSchema.cs +++ b/src/BizHawk.Emulation.Cores/vpads_schemata/SnesSchema.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Cores.Nintendo.BSNES; using BizHawk.Emulation.Cores.Nintendo.SNES; using BizHawk.Emulation.Cores.Nintendo.SNES9X; using BizHawk.Emulation.Cores.Waterbox; @@ -15,17 +16,13 @@ namespace BizHawk.Emulation.Cores { public IEnumerable GetPadSchemas(IEmulator core, Action showMessageBox) { - if (core is LibsnesCore bsnes) + return core switch { - return GetBsnesPadSchemas(bsnes); - } - - if (core is NymaCore nyma) - { - return GetFaustSchemas(nyma, showMessageBox); - } - - return GetSnes9xPadSchemas((Snes9x)core); + LibsnesCore libsnes => GetLibsnesPadSchemas(libsnes), + BsnesCore bsnes => GetBsnesPadSchemas(bsnes), + NymaCore nyma => GetFaustSchemas(nyma, showMessageBox), + _ => GetSnes9xPadSchemas((Snes9x) core) + }; } private IEnumerable GetSnes9xPadSchemas(Snes9x core) { @@ -61,7 +58,7 @@ namespace BizHawk.Emulation.Cores yield return ConsoleButtons(); } - private IEnumerable GetBsnesPadSchemas(LibsnesCore core) + private IEnumerable GetLibsnesPadSchemas(LibsnesCore core) { var syncSettings = core.GetSyncSettings(); @@ -115,6 +112,58 @@ namespace BizHawk.Emulation.Cores yield return ConsoleButtons(); } + private IEnumerable GetBsnesPadSchemas(BsnesCore core) + { + var syncSettings = core.GetSyncSettings(); + + var ports = new[] + { + syncSettings.LeftPort, + syncSettings.RightPort + }; + + int playerNum = 0; + for (int i = 0; i < 2; i++, playerNum++) + { + switch (ports[i]) + { + default: + case BsnesApi.BSNES_INPUT_DEVICE.None: + playerNum--; + break; + case BsnesApi.BSNES_INPUT_DEVICE.Gamepad: + yield return StandardController(playerNum); + break; + case BsnesApi.BSNES_INPUT_DEVICE.Mouse: + yield return Mouse(playerNum); + break; + case BsnesApi.BSNES_INPUT_DEVICE.SuperMultitap: + for (int j = 0; j < 4; j++) + { + yield return StandardController(playerNum++); + } + break; + case BsnesApi.BSNES_INPUT_DEVICE.SuperScope: + yield return SuperScope(playerNum); + break; + case BsnesApi.BSNES_INPUT_DEVICE.Justifier: + yield return Justifier(playerNum); + break; + case BsnesApi.BSNES_INPUT_DEVICE.Justifiers: + for (int j = 0; j < 2; j++) + { + yield return Justifier(playerNum++); + } + break; + case BsnesApi.BSNES_INPUT_DEVICE.Payload: + yield return Payload(playerNum); + break; + } + } + + yield return ConsoleButtons(); + } + private static IEnumerable GetFaustSchemas(NymaCore nyma, Action showMessageBox) { foreach (NymaCore.PortResult result in nyma.ActualPortData) @@ -269,4 +318,4 @@ namespace BizHawk.Emulation.Cores }; } } -} \ No newline at end of file +}