Add a payload controller for the new bsnes core

This commit is contained in:
Morilli 2021-05-25 03:49:27 +02:00
parent 817701856c
commit 359657c29a
4 changed files with 96 additions and 14 deletions

View File

@ -27,7 +27,8 @@
SuperMultitap, SuperMultitap,
SuperScope, SuperScope,
Justifier, Justifier,
Justifiers Justifiers,
Payload
} }
public enum ENTROPY public enum ENTROPY

View File

@ -25,6 +25,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
BSNES_INPUT_DEVICE.SuperScope => new BsnesSuperScopeController(), BSNES_INPUT_DEVICE.SuperScope => new BsnesSuperScopeController(),
BSNES_INPUT_DEVICE.Justifier => new BsnesJustifierController(false), BSNES_INPUT_DEVICE.Justifier => new BsnesJustifierController(false),
BSNES_INPUT_DEVICE.Justifiers => new BsnesJustifierController(true), BSNES_INPUT_DEVICE.Justifiers => new BsnesJustifierController(true),
BSNES_INPUT_DEVICE.Payload => new BsnesPayloadController(),
_ => throw new InvalidOperationException() _ => throw new InvalidOperationException()
}; };
} }
@ -306,4 +307,32 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
return _state[index * 4 + id]; 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);
}
}
} }

View File

@ -66,7 +66,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
generate_palette(); generate_palette();
// TODO: massive random hack till waterboxhost gets fixed to support 5+ args // TODO: massive random hack till waterboxhost gets fixed to support 5+ args
ushort mergedBools = (ushort) ((_syncSettings.Hotfixes ? 1 << 8 : 0) | (_syncSettings.FastPPU ? 1 : 0)); 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); Api.SetCallbacks(callbacks);
// start up audio resampler // start up audio resampler

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.BSNES;
using BizHawk.Emulation.Cores.Nintendo.SNES; using BizHawk.Emulation.Cores.Nintendo.SNES;
using BizHawk.Emulation.Cores.Nintendo.SNES9X; using BizHawk.Emulation.Cores.Nintendo.SNES9X;
using BizHawk.Emulation.Cores.Waterbox; using BizHawk.Emulation.Cores.Waterbox;
@ -15,17 +16,13 @@ namespace BizHawk.Emulation.Cores
{ {
public IEnumerable<PadSchema> GetPadSchemas(IEmulator core, Action<string> showMessageBox) public IEnumerable<PadSchema> GetPadSchemas(IEmulator core, Action<string> showMessageBox)
{ {
if (core is LibsnesCore bsnes) return core switch
{ {
return GetBsnesPadSchemas(bsnes); LibsnesCore libsnes => GetLibsnesPadSchemas(libsnes),
} BsnesCore bsnes => GetBsnesPadSchemas(bsnes),
NymaCore nyma => GetFaustSchemas(nyma, showMessageBox),
if (core is NymaCore nyma) _ => GetSnes9xPadSchemas((Snes9x) core)
{ };
return GetFaustSchemas(nyma, showMessageBox);
}
return GetSnes9xPadSchemas((Snes9x)core);
} }
private IEnumerable<PadSchema> GetSnes9xPadSchemas(Snes9x core) private IEnumerable<PadSchema> GetSnes9xPadSchemas(Snes9x core)
{ {
@ -61,7 +58,7 @@ namespace BizHawk.Emulation.Cores
yield return ConsoleButtons(); yield return ConsoleButtons();
} }
private IEnumerable<PadSchema> GetBsnesPadSchemas(LibsnesCore core) private IEnumerable<PadSchema> GetLibsnesPadSchemas(LibsnesCore core)
{ {
var syncSettings = core.GetSyncSettings(); var syncSettings = core.GetSyncSettings();
@ -115,6 +112,58 @@ namespace BizHawk.Emulation.Cores
yield return ConsoleButtons(); yield return ConsoleButtons();
} }
private IEnumerable<PadSchema> 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<PadSchema> GetFaustSchemas(NymaCore nyma, Action<string> showMessageBox) private static IEnumerable<PadSchema> GetFaustSchemas(NymaCore nyma, Action<string> showMessageBox)
{ {
foreach (NymaCore.PortResult result in nyma.ActualPortData) foreach (NymaCore.PortResult result in nyma.ActualPortData)
@ -269,4 +318,4 @@ namespace BizHawk.Emulation.Cores
}; };
} }
} }
} }