Atari 2600 - stub out the paddle controller

This commit is contained in:
adelikat 2017-06-27 17:22:45 -05:00
parent 74dd25e831
commit c3b890c60c
2 changed files with 122 additions and 79 deletions

View File

@ -1,90 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.ReflectionExtensions;
using System;
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Atari.Atari2600
{
public class Atari2600ControllerDeck
public class Atari2600ControllerDeck
{
private static readonly Type[] Implementors =
{
typeof(UnpluggedController), // Order must match Atari2600ControllerTypes enum values
typeof(StandardController),
private static readonly Type[] Implementors =
{
typeof(UnpluggedController), // Order must match Atari2600ControllerTypes enum values
typeof(StandardController),
typeof(PaddleController)
};
public Atari2600ControllerDeck(Atari2600ControllerTypes controller1, Atari2600ControllerTypes controller2)
public Atari2600ControllerDeck(Atari2600ControllerTypes controller1, Atari2600ControllerTypes controller2)
{
Port1 = (IPort)Activator.CreateInstance(Implementors[(int)controller1], 1);
Port2 = (IPort)Activator.CreateInstance(Implementors[(int)controller2], 2);
Definition = new ControllerDefinition
{
Name = "Atari 2600 Controller",
BoolButtons = Port1.Definition.BoolButtons
.Concat(Port2.Definition.BoolButtons)
.Concat(new[]
{
"Reset", "Select", "Power", "Toggle Left Difficulty", "Toggle Right Difficulty"
})
.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 byte ReadPort1(IController c)
{
return Port1.Read(c);
}
public byte ReadPort2(IController c)
{
return Port2.Read(c);
}
public ControllerDefinition Definition { get; }
public void SyncState(Serializer ser)
{
ser.BeginSection("Port1");
Port1.SyncState(ser);
ser.EndSection();
ser.BeginSection("Port2");
Port2.SyncState(ser);
ser.EndSection();
}
private readonly IPort Port1;
private readonly IPort Port2;
private static Dictionary<string, Type> _controllerTypes;
public static Dictionary<string, Type> ValidControllerTypes
{
get
{
if (_controllerTypes == null)
{
_controllerTypes = typeof(Atari2600ControllerDeck).Assembly
.GetTypes()
.Where(t => typeof(IPort).IsAssignableFrom(t))
.Where(t => !t.IsAbstract && !t.IsInterface)
.ToDictionary(tkey => tkey.DisplayName());
}
return _controllerTypes;
}
}
public static string DefaultControllerName => typeof(StandardController).DisplayName();
Definition = new ControllerDefinition
{
Name = "Atari 2600 Controller",
BoolButtons = Port1.Definition.BoolButtons
.Concat(Port2.Definition.BoolButtons)
.Concat(new[]
{
"Reset", "Select", "Power", "Toggle Left Difficulty", "Toggle Right Difficulty"
})
.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 byte ReadPort1(IController c)
{
return Port1.Read(c);
}
public byte ReadPort2(IController c)
{
return Port2.Read(c);
}
public ControllerDefinition Definition { get; }
public void SyncState(Serializer ser)
{
ser.BeginSection("Port1");
Port1.SyncState(ser);
ser.EndSection();
ser.BeginSection("Port2");
Port2.SyncState(ser);
ser.EndSection();
}
private readonly IPort Port1;
private readonly IPort Port2;
private static Dictionary<string, Type> _controllerTypes;
public static Dictionary<string, Type> ValidControllerTypes
{
get
{
if (_controllerTypes == null)
{
_controllerTypes = typeof(Atari2600ControllerDeck).Assembly
.GetTypes()
.Where(t => typeof(IPort).IsAssignableFrom(t))
.Where(t => !t.IsAbstract && !t.IsInterface)
.ToDictionary(tkey => tkey.DisplayName());
}
return _controllerTypes;
}
}
public static string DefaultControllerName => typeof(StandardController).DisplayName();
}
}

View File

@ -11,7 +11,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
public enum Atari2600ControllerTypes
{
Unplugged,
Joystick
Joystick,
Paddle
}
/// <summary>
@ -94,4 +95,45 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
"Up", "Down", "Left", "Right", "Button"
};
}
public class PaddleController : IPort
{
public PaddleController(int portNum)
{
PortNum = portNum;
Definition = new ControllerDefinition
{
BoolButtons = BaseDefinition
.Select(b => $"P{PortNum} " + b)
.ToList(),
FloatControls = { "P" + PortNum + " Paddle X" },
FloatRanges = { new[] { -127.0f, 0, 127.0f }, } // No idea what values should be here
};
}
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; } // TODO
//int x = (int)c.GetFloat(Definition.FloatControls[0]);
return result;
}
}
}