ColecoVision clean up Super Action Controller

wheel mostly works now.
This commit is contained in:
alyosha-tas 2017-03-23 10:40:32 -04:00 committed by GitHub
parent 231795c2cb
commit a7f5bafb72
5 changed files with 121 additions and 138 deletions

View File

@ -1,104 +1,104 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.ColecoVision
{
public class ColecoVisionControllerDeck
{
public ColecoVisionControllerDeck(string controller1Name, string controller2Name)
{
if (!ValidControllerTypes.ContainsKey(controller1Name))
{
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
}
if (!ValidControllerTypes.ContainsKey(controller2Name))
{
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
}
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2); ;
Definition = new ControllerDefinition
{
Name = "ColecoVision Basic Controller",
BoolButtons = Port1.Definition.BoolButtons
.Concat(Port2.Definition.BoolButtons)
.ToList()
};
Definition.FloatControls.AddRange(Port1.Definition.FloatControls);
Definition.FloatControls.AddRange(Port2.Definition.FloatControls);
Definition.FloatRanges.AddRange(Port1.Definition.FloatRanges);
Definition.FloatRanges.AddRange(Port2.Definition.FloatRanges);
}
public int wheel1;
public int wheel2;
public byte ReadPort1(IController c, bool left_mode, bool update_wheel)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.ColecoVision
{
public class ColecoVisionControllerDeck
{
public ColecoVisionControllerDeck(string controller1Name, string controller2Name)
{
if (!ValidControllerTypes.ContainsKey(controller1Name))
{
throw new InvalidOperationException("Invalid controller type: " + controller1Name);
}
if (!ValidControllerTypes.ContainsKey(controller2Name))
{
throw new InvalidOperationException("Invalid controller type: " + controller2Name);
}
Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1);
Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2); ;
Definition = new ControllerDefinition
{
Name = "ColecoVision Basic Controller",
BoolButtons = Port1.Definition.BoolButtons
.Concat(Port2.Definition.BoolButtons)
.ToList()
};
Definition.FloatControls.AddRange(Port1.Definition.FloatControls);
Definition.FloatControls.AddRange(Port2.Definition.FloatControls);
Definition.FloatRanges.AddRange(Port1.Definition.FloatRanges);
Definition.FloatRanges.AddRange(Port2.Definition.FloatRanges);
}
public int wheel1;
public int wheel2;
public byte ReadPort1(IController c, bool left_mode, bool update_wheel)
{
if (update_wheel)
wheel1 = Port1.Update_Wheel(c, wheel1);
return Port1.Read(c, left_mode, wheel1);
}
public byte ReadPort2(IController c, bool left_mode, bool update_wheel)
return Port1.Read(c, left_mode, wheel1);
}
public byte ReadPort2(IController c, bool left_mode, bool update_wheel)
{
if (update_wheel)
wheel2 = Port2.Update_Wheel(c, wheel2);
return Port2.Read(c, left_mode, wheel2);
}
public ControllerDefinition Definition { get; private set; }
public void SyncState(Serializer ser)
return Port2.Read(c, left_mode, wheel2);
}
public ControllerDefinition Definition { get; private set; }
public void SyncState(Serializer ser)
{
ser.BeginSection("Port1");
ser.Sync("Wheel 1", ref wheel1);
Port1.SyncState(ser);
ser.EndSection();
ser.BeginSection("Port2");
ser.Sync("Wheel 2", ref wheel2);
Port2.SyncState(ser);
ser.EndSection();
}
private readonly IPort Port1;
private readonly IPort Port2;
private static Dictionary<string, Type> _controllerTypes = null;
public static Dictionary<string, Type> ValidControllerTypes
{
get
{
if (_controllerTypes == null)
{
_controllerTypes = typeof(ColecoVisionControllerDeck).Assembly
.GetTypes()
.Where(t => typeof(IPort).IsAssignableFrom(t))
.Where(t => !t.IsAbstract && !t.IsInterface)
.ToDictionary(tkey => tkey.DisplayName());
}
return _controllerTypes;
}
}
public static string DefaultControllerName
{
get { return typeof(StandardController).DisplayName(); }
}
}
}
ser.BeginSection("Port1");
ser.Sync("Wheel 1", ref wheel1);
Port1.SyncState(ser);
ser.EndSection();
ser.BeginSection("Port2");
ser.Sync("Wheel 2", ref wheel2);
Port2.SyncState(ser);
ser.EndSection();
}
private readonly IPort Port1;
private readonly IPort Port2;
private static Dictionary<string, Type> _controllerTypes = null;
public static Dictionary<string, Type> ValidControllerTypes
{
get
{
if (_controllerTypes == null)
{
_controllerTypes = typeof(ColecoVisionControllerDeck).Assembly
.GetTypes()
.Where(t => typeof(IPort).IsAssignableFrom(t))
.Where(t => !t.IsAbstract && !t.IsInterface)
.ToDictionary(tkey => tkey.DisplayName());
}
return _controllerTypes;
}
}
public static string DefaultControllerName
{
get { return typeof(StandardController).DisplayName(); }
}
}
}

View File

@ -195,21 +195,15 @@ namespace BizHawk.Emulation.Cores.ColecoVision
private static byte CalcDirection(int x, int y)
{
y = -y; // vflip to match the arrangement of FloatControllerButtons
/*
// deadzone: if we're less than ? units from the origin, return no direction
if (x * x + y * y < Deadzone * Deadzone)
{
return 0x0F; // nothing pressed
}
*/
if ((y >= 0 && y>=Math.Abs(x)))
return 0x3F;
if ((y < 0 && Math.Abs(y) >= Math.Abs(x)))
return 0x1F;
if ((x > 0 && Math.Abs(y) < x))
return 0x0F;
if ((x < 0 && Math.Abs(y) < Math.Abs(x)))
return 0x2F;
if (y >= 0 && x > 0)
return 0x10;
if (y >= 0 && x <= 0)
return 0x30;
if (y < 0 && x <= 0)
return 0x20;
if (y < 0 && x > 0)
return 0x00;
Console.WriteLine("Error");
return 0x1F;
@ -235,7 +229,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
.Select(b => "P" + PortNum + " " + b)
.ToList(),
FloatControls = { "P" + PortNum + " Disc X"},
FloatRanges = { new[] { -127.0f, 0, 127.0f }}
FloatRanges = { new[] { -360.0f, 0, 360.0f }}
};
}
@ -307,17 +301,14 @@ namespace BizHawk.Emulation.Cores.ColecoVision
{
byte retval = 0;
if (wheel >= 0 && wheel < 90)
retval = 0x30;
if (wheel >= 90 && wheel < 180)
retval = 0x10;
if (wheel >= 180 && wheel < 270)
if (wheel >= 0 && wheel < 180)
retval = 0x00;
if (wheel >= 270 && wheel <= 360)
if (wheel >= 180 && wheel < 360)
retval = 0x10;
if (wheel <0 && wheel > -180)
retval = 0x20;
//Console.WriteLine(retval);
if (wheel <= -180 && wheel >-360)
retval = 0x30;
return retval;
}
@ -328,14 +319,14 @@ namespace BizHawk.Emulation.Cores.ColecoVision
{
int x = (int)c.GetFloat(Definition.FloatControls[0]);
int diff = x >> 1;
int diff = -x;
wheel += diff;
if (wheel >= 360)
wheel = wheel - 360;
if (wheel < 0)
if (wheel <= -360)
wheel = wheel + 360;
return wheel;

View File

@ -91,16 +91,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision
Cpu.Logger = (s) => Tracer.Put(s);
}
byte temp_ret1 = ControllerDeck.ReadPort1(Controller, true, false);
byte temp_ret2 = ControllerDeck.ReadPort2(Controller, true, false);
/*
if (!temp_ret1.Bit(4) && prev_1)
Int_pending = true;
if (!temp_ret2.Bit(4) && prev_2)
Int_pending = true;
*/
byte temp_ret1 = ControllerDeck.ReadPort1(Controller, true, true);
byte temp_ret2 = ControllerDeck.ReadPort2(Controller, true, true);
bool Int_pending = (!temp_ret1.Bit(4)) | (!temp_ret2.Bit(4));

View File

@ -31,7 +31,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
byte retval;
if (InputPortSelection == InputPortMode.Left)
{
retval = ControllerDeck.ReadPort1(Controller, true, true);
retval = ControllerDeck.ReadPort1(Controller, true, false);
return retval;
}
@ -50,7 +50,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
byte retval;
if (InputPortSelection == InputPortMode.Left)
{
retval = ControllerDeck.ReadPort2(Controller, true, true);
retval = ControllerDeck.ReadPort2(Controller, true, false);
return retval;
}

View File

@ -60,13 +60,13 @@ namespace BizHawk.Emulation.Cores.ColecoVision
Cpu.Interrupt = false;
if (Int_pending)
if (Int_pending && scanLine==50)
{
if (EnableInterrupts)
{
Cpu.Interrupt = true;
Int_pending = false;
}
}
}
}