A2600: Add Driving controller and fix coleco Super Action Controller

This commit is contained in:
alyosha-tas 2018-03-12 09:12:41 -04:00
parent b5321b8d1e
commit c839bffc33
4 changed files with 154 additions and 13 deletions

View File

@ -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

View File

@ -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)

View File

@ -12,7 +12,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
{
Unplugged,
Joystick,
Paddle
Paddle,
Driving
}
/// <summary>
@ -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;
}
}
}

View File

@ -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);
}
}
}