From c839bffc3367809d94a8447635bfb4846173fc93 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 12 Mar 2018 09:12:41 -0400 Subject: [PATCH] A2600: Add Driving controller and fix coleco Super Action Controller --- .../tools/VirtualPads/schema/A26Schema.cs | 43 ++++++++ .../Atari/2600/Atari2600ControllerDeck.cs | 3 +- .../Atari/2600/Atari2600Controllers.cs | 98 ++++++++++++++++++- .../Consoles/Coleco/ColecoControllers.cs | 23 ++--- 4 files changed, 154 insertions(+), 13 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs index 6369a8a1b5..c915c4015d 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs @@ -39,6 +39,8 @@ namespace BizHawk.Client.EmuHawk return StandardController(controller); case Atari2600ControllerTypes.Paddle: return PaddleController(controller); + case Atari2600ControllerTypes.Driving: + return DrivingController(controller); } } @@ -143,6 +145,47 @@ namespace BizHawk.Client.EmuHawk }; } + private static PadSchema DrivingController(int controller) + { + return new PadSchema + { + DisplayName = "Player " + controller, + IsConsole = false, + DefaultSize = new Size(334, 94), + MaxSize = new Size(334, 94), + Buttons = new[] + { + new PadSchema.ButtonSchema + { + Name = "P" + controller + " Button", + DisplayName = "B1", + Location = new Point(5, 24), + Type = PadSchema.PadInputType.Boolean + }, + new PadSchema.ButtonSchema + { + Name = "P" + controller + " Wheel X 1", + DisplayName = "Wheel X 1", + Location = new Point(55, 17), + Type = PadSchema.PadInputType.FloatSingle, + TargetSize = new Size(128, 69), + MaxValue = 127, + MinValue = -127 + }, + new PadSchema.ButtonSchema + { + Name = "P" + controller + " Wheel X 2", + DisplayName = "Wheel X 2", + Location = new Point(193, 17), + Type = PadSchema.PadInputType.FloatSingle, + TargetSize = new Size(128, 69), + MaxValue = 127, + MinValue = -127 + }, + } + }; + } + private static PadSchema ConsoleButtons() { return new PadSchema diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs index 7f3813cc82..89604f6516 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs @@ -14,7 +14,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { typeof(UnpluggedController), // Order must match Atari2600ControllerTypes enum values typeof(StandardController), - typeof(PaddleController) + typeof(PaddleController), + typeof(DrivingController) }; public Atari2600ControllerDeck(Atari2600ControllerTypes controller1, Atari2600ControllerTypes controller2) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index 9e5f41444e..90d9b1cd16 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -12,7 +12,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { Unplugged, Joystick, - Paddle + Paddle, + Driving } /// @@ -160,4 +161,99 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 return x; } } + + public class DrivingController : IPort + { + public DrivingController(int portNum) + { + PortNum = portNum; + Definition = new ControllerDefinition + { + BoolButtons = BaseDefinition + .Select(b => $"P{PortNum} " + b) + .ToList(), + FloatControls = { "P" + PortNum + " Wheel X 1", "P" + PortNum + " Wheel X 2" }, + FloatRanges = { new[] { -127.0f, 0, 127.0f }, new[] { -127.0f, 0, 127.0f } } + }; + } + + public int PortNum { get; } + + public void SyncState(Serializer ser) + { + // Nothing todo, I think + } + + public ControllerDefinition Definition { get; } + + private static readonly string[] BaseDefinition = + { + "Button" + }; + + public byte Read(IController c) + { + byte result = 0xFF; + + if (c.IsPressed($"P{PortNum} Button")) { result &= 0xF7; } + + float x = c.GetFloat(Definition.FloatControls[0]); + float y = c.GetFloat(Definition.FloatControls[1]); + + float angle = CalcDirection(x, y); + + byte temp2 = 0; + + int temp1 = (int)Math.Floor(angle / 45); + temp1 = temp1 % 4; + + if (temp1 == 0) + { + temp2 = 0xEF; + } + + if (temp1 == 1) + { + temp2 = 0xCF; + } + if (temp1 == 2) + { + temp2 = 0xDF; + } + + if (temp1 == 3) + { + temp2 = 0xFF; + } + + + result &= temp2; + + + return result; + } + + public int Read_Pot(IController c, int pot) + { + return -1; // indicates not applicable + } + + private static float CalcDirection(float x, float y) + { + y = -y; // vflip to match the arrangement of FloatControllerButtons + + // the wheel is arranged in a grey coded configuration of sensitivity ~2.5 degrees + // for each signal + // so overall the value returned changes every 1.25 degrees + + float angle = (float)(Math.Atan2(y, x) * 180.0 / Math.PI); + + if (angle < 0) + { + angle = 360 + angle; + } + + return angle; + } + } } diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs index 28f00263bd..3bd2179713 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs @@ -159,8 +159,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision if (c.IsPressed(Definition.BoolButtons[0])) retval &= 0x3F; - int x = (int)c.GetFloat(Definition.FloatControls[0]); - int y = (int)c.GetFloat(Definition.FloatControls[1]); + float x = c.GetFloat(Definition.FloatControls[0]); + float y = c.GetFloat(Definition.FloatControls[1]); float angle; @@ -223,7 +223,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision // x and y are both assumed to be in [-127, 127] // x increases from left to right // y increases from top to bottom - private static float CalcDirection(int x, int y) + private static float CalcDirection(float x, float y) { y = -y; // vflip to match the arrangement of FloatControllerButtons @@ -243,10 +243,9 @@ namespace BizHawk.Emulation.Cores.ColecoVision public float UpdateWheel(IController c) { - int x = (int)c.GetFloat(Definition.FloatControls[0]); - int y = (int)c.GetFloat(Definition.FloatControls[1]); - return CalcDirection(x, y); - + float x = c.GetFloat(Definition.FloatControls[0]); + float y = c.GetFloat(Definition.FloatControls[1]); + return CalcDirection(x, y); } } @@ -281,8 +280,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision if (c.IsPressed(Definition.BoolButtons[3])) retval &= 0xF7; if (c.IsPressed(Definition.BoolButtons[4])) retval &= 0x3F; - int x = (int)c.GetFloat(Definition.FloatControls[0]); - int y = (int)c.GetFloat(Definition.FloatControls[1]); + float x = c.GetFloat(Definition.FloatControls[0]); + float y = c.GetFloat(Definition.FloatControls[1]); float angle; @@ -368,7 +367,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision // x and y are both assumed to be in [-127, 127] // x increases from left to right // y increases from top to bottom - private static float CalcDirection(int x, int y) + private static float CalcDirection(float x, float y) { y = -y; // vflip to match the arrangement of FloatControllerButtons @@ -388,7 +387,9 @@ namespace BizHawk.Emulation.Cores.ColecoVision public float UpdateWheel(IController c) { - return 0; + float x = c.GetFloat(Definition.FloatControls[0]); + float y = c.GetFloat(Definition.FloatControls[1]); + return CalcDirection(x, y); } } }