Fix TIC80 mouse inputs

resolves #3938
This commit is contained in:
CasualPokePlayer 2024-06-06 15:18:45 -07:00
parent a7c8156710
commit 8fb2ba6afa
2 changed files with 44 additions and 30 deletions

View File

@ -128,8 +128,8 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
public TIC80Gamepad P3Gamepad; public TIC80Gamepad P3Gamepad;
public TIC80Gamepad P4Gamepad; public TIC80Gamepad P4Gamepad;
public sbyte MouseX; public byte MouseX;
public sbyte MouseY; public byte MouseY;
public ushort MouseButtons; public ushort MouseButtons;
public TIC80Keys Key1; public TIC80Keys Key1;

View File

@ -11,7 +11,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
{ {
[PortedCore(CoreNames.TIC80, "nesbox", "v1.0.2164", "https://tic80.com/")] [PortedCore(CoreNames.TIC80, "nesbox", "v1.0.2164", "https://tic80.com/")]
[ServiceNotApplicable(new[] { typeof(IDriveLight), })] [ServiceNotApplicable(new[] { typeof(IDriveLight), })]
public partial class TIC80 : WaterboxCore public sealed partial class TIC80 : WaterboxCore
{ {
private readonly LibTIC80 _core; private readonly LibTIC80 _core;
@ -51,7 +51,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
}); });
var rom = lp.Roms[0].FileData; var rom = lp.Roms[0].FileData;
var inputsActive = new bool[6] var inputsActive = new[]
{ {
_syncSettings.Gamepad1, _syncSettings.Gamepad1,
_syncSettings.Gamepad2, _syncSettings.Gamepad2,
@ -72,7 +72,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
InputsActive = Array.AsReadOnly(inputsActive); InputsActive = Array.AsReadOnly(inputsActive);
PostInit(); PostInit();
DeterministicEmulation = lp.DeterministicEmulationRequested || (!_syncSettings.UseRealTime); DeterministicEmulation = lp.DeterministicEmulationRequested || !_syncSettings.UseRealTime;
InitializeRtc(_syncSettings.InitialTime); InitializeRtc(_syncSettings.InitialTime);
} }
@ -84,10 +84,10 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
{ {
var enumValues = Enum.GetValues(typeof(LibTIC80.TIC80Keys)); var enumValues = Enum.GetValues(typeof(LibTIC80.TIC80Keys));
var ret = new KeyValuePair<string, LibTIC80.TIC80Keys>[enumValues.Length - 1]; var ret = new KeyValuePair<string, LibTIC80.TIC80Keys>[enumValues.Length - 1];
for (int i = 0; i < ret.Length; i++) for (var i = 0; i < ret.Length; i++)
{ {
var val = enumValues.GetValue(i + 1); var val = enumValues.GetValue(i + 1);
var name = Enum.GetName(typeof(LibTIC80.TIC80Keys), val).TrimStart('_').Replace('_', ' '); var name = Enum.GetName(typeof(LibTIC80.TIC80Keys), val)!.TrimStart('_').Replace('_', ' ');
ret[i] = new(name, (LibTIC80.TIC80Keys)val); ret[i] = new(name, (LibTIC80.TIC80Keys)val);
} }
@ -98,7 +98,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
{ {
var ret = new ControllerDefinition("TIC-80 Controller"); var ret = new ControllerDefinition("TIC-80 Controller");
for (int i = 0; i < 4; i++) for (var i = 0; i < 4; i++)
{ {
if (inputsActive[i]) if (inputsActive[i])
{ {
@ -111,7 +111,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
if (inputsActive[4]) if (inputsActive[4])
{ {
ret.AddXYPair("Mouse Position {0}", AxisPairOrientation.RightAndUp, (-128).RangeTo(127), 0); ret.AddXYPair("Mouse Position {0}", AxisPairOrientation.RightAndUp, 0.RangeTo(255), 128);
ret.BoolButtons.Add("Mouse Left Click"); ret.BoolButtons.Add("Mouse Left Click");
ret.BoolButtons.Add("Mouse Middle Click"); ret.BoolButtons.Add("Mouse Middle Click");
ret.BoolButtons.Add("Mouse Right Click"); ret.BoolButtons.Add("Mouse Right Click");
@ -139,7 +139,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
{ {
foreach (var k in Enum.GetValues(typeof(LibTIC80.TIC80Keys))) foreach (var k in Enum.GetValues(typeof(LibTIC80.TIC80Keys)))
{ {
var name = Enum.GetName(typeof(LibTIC80.TIC80Keys), k).TrimStart('_').Replace('_', ' '); var name = Enum.GetName(typeof(LibTIC80.TIC80Keys), k)!.TrimStart('_').Replace('_', ' ');
if (name is "Unknown") continue; if (name is "Unknown") continue;
ret.BoolButtons.Add(name); ret.BoolButtons.Add(name);
ret.CategoryLabels[name] = "Keyboard"; ret.CategoryLabels[name] = "Keyboard";
@ -154,7 +154,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
private static void GetGamepads(IController controller, ref LibTIC80.TIC80Inputs inputs) private static void GetGamepads(IController controller, ref LibTIC80.TIC80Inputs inputs)
{ {
var gamepads = new LibTIC80.TIC80Gamepad[4]; var gamepads = new LibTIC80.TIC80Gamepad[4];
for (int i = 0; i < 4; i++) for (var i = 0; i < 4; i++)
{ {
gamepads[i] = 0; gamepads[i] = 0;
foreach (var b in Enum.GetValues(typeof(LibTIC80.TIC80Gamepad))) foreach (var b in Enum.GetValues(typeof(LibTIC80.TIC80Gamepad)))
@ -175,33 +175,40 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
private static ushort GetMouseButtons(IController controller) private static ushort GetMouseButtons(IController controller)
{ {
ushort ret = 0; ushort ret = 0;
if (controller.IsPressed("Mouse Left Click")) if (controller.IsPressed("Mouse Left Click"))
{
ret |= 0x8000;
}
if (controller.IsPressed("Mouse Middle Click"))
{
ret |= 0x4000;
}
if (controller.IsPressed("Mouse Right Click"))
{
ret |= 0x2000;
}
var x = (ushort)((sbyte)controller.AxisValue("Mouse Scroll X") + 32);
ret |= (ushort)(x << 7);
var y = (ushort)((sbyte)controller.AxisValue("Mouse Scroll Y") + 32);
ret |= (ushort)(y << 1);
if (controller.IsPressed("Mouse Relative Toggle"))
{ {
ret |= 0x0001; ret |= 0x0001;
} }
if (controller.IsPressed("Mouse Middle Click"))
{
ret |= 0x0002;
}
if (controller.IsPressed("Mouse Right Click"))
{
ret |= 0x0004;
}
var x = (ushort)((sbyte)controller.AxisValue("Mouse Scroll X") + 32);
ret |= (ushort)(x << 3);
var y = (ushort)((sbyte)controller.AxisValue("Mouse Scroll Y") + 32);
ret |= (ushort)(y << (3 + 6));
if (controller.IsPressed("Mouse Relative Toggle"))
{
ret |= 0x8000;
}
return ret; return ret;
} }
private static void GetKeys(IController controller, ref LibTIC80.TIC80Inputs inputs) private static void GetKeys(IController controller, ref LibTIC80.TIC80Inputs inputs)
{ {
var keys = new LibTIC80.TIC80Keys[4]; var keys = new LibTIC80.TIC80Keys[4];
int i = 0; var i = 0;
foreach (var kvp in KeyMap) foreach (var kvp in KeyMap)
{ {
if (controller.IsPressed(kvp.Key)) if (controller.IsPressed(kvp.Key))
@ -224,11 +231,18 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
{ {
var inputs = new LibTIC80.TIC80Inputs var inputs = new LibTIC80.TIC80Inputs
{ {
MouseX = (sbyte)controller.AxisValue("Mouse Position X"), MouseX = (byte)controller.AxisValue("Mouse Position X"),
MouseY = (sbyte)controller.AxisValue("Mouse Position Y"), MouseY = (byte)controller.AxisValue("Mouse Position Y"),
MouseButtons = GetMouseButtons(controller), MouseButtons = GetMouseButtons(controller),
}; };
if (controller.IsPressed("Mouse Relative Toggle"))
{
// turn (0, 255) to (-128, 127)
inputs.MouseX -= 128;
inputs.MouseY -= 128;
}
GetGamepads(controller, ref inputs); GetGamepads(controller, ref inputs);
GetKeys(controller, ref inputs); GetKeys(controller, ref inputs);
_core.SetInputs(ref inputs); _core.SetInputs(ref inputs);