Start Atari 2600 peripheral support - currently ability to pick joystick or unplugged for port 1 and port 2. Virtualpads are not addressed with this commit

This commit is contained in:
adelikat 2017-06-27 15:14:41 -05:00
parent 872bc39583
commit 74dd25e831
7 changed files with 209 additions and 26 deletions

View File

@ -284,6 +284,8 @@
<Compile Include="Consoles\Atari\2600\Atari2600.RomHeuristics.cs">
<DependentUpon>Atari2600.cs</DependentUpon>
</Compile>
<Compile Include="Consoles\Atari\2600\Atari2600ControllerDeck.cs" />
<Compile Include="Consoles\Atari\2600\Atari2600Controllers.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m0840.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m3E.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m3F.cs" />

View File

@ -10,17 +10,6 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
{
public partial class Atari2600
{
private static readonly ControllerDefinition Atari2600ControllerDefinition = new ControllerDefinition
{
Name = "Atari 2600 Basic Controller",
BoolButtons =
{
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button",
"Reset", "Select", "Power", "Toggle Left Difficulty", "Toggle Right Difficulty"
}
};
private readonly GameInfo _game;
private TIA _tia;
@ -455,13 +444,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
internal byte ReadControls1(bool peek)
{
InputCallbacks.Call();
byte value = 0xFF;
if (_controller.IsPressed("P1 Up")) { value &= 0xEF; }
if (_controller.IsPressed("P1 Down")) { value &= 0xDF; }
if (_controller.IsPressed("P1 Left")) { value &= 0xBF; }
if (_controller.IsPressed("P1 Right")) { value &= 0x7F; }
if (_controller.IsPressed("P1 Button")) { value &= 0xF7; }
byte value = _controllerDeck.ReadPort1(_controller);
if (!peek)
{
@ -474,13 +458,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
internal byte ReadControls2(bool peek)
{
InputCallbacks.Call();
byte value = 0xFF;
if (_controller.IsPressed("P2 Up")) { value &= 0xEF; }
if (_controller.IsPressed("P2 Down")) { value &= 0xDF; }
if (_controller.IsPressed("P2 Left")) { value &= 0xBF; }
if (_controller.IsPressed("P2 Right")) { value &= 0x7F; }
if (_controller.IsPressed("P2 Button")) { value &= 0xF7; }
byte value = _controllerDeck.ReadPort2(_controller);
if (!peek)
{

View File

@ -6,7 +6,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
{
public IEmulatorServiceProvider ServiceProvider { get; }
public ControllerDefinition ControllerDefinition => Atari2600ControllerDefinition;
public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;
public void FrameAdvance(IController controller, bool render, bool rendersound)
{

View File

@ -149,6 +149,18 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
public class A2600SyncSettings
{
[DefaultValue(Atari2600ControllerTypes.Joystick)]
[DisplayName("Port 1 Device")]
[Description("The type of controller plugged into the first controller port")]
[TypeConverter(typeof(DescribableEnumConverter))]
public Atari2600ControllerTypes Port1 { get; set; } = Atari2600ControllerTypes.Joystick;
[DefaultValue(Atari2600ControllerTypes.Joystick)]
[DisplayName("Port 2 Device")]
[Description("The type of controller plugged into the second controller port")]
[TypeConverter(typeof(DescribableEnumConverter))]
public Atari2600ControllerTypes Port2 { get; set; } = Atari2600ControllerTypes.Joystick;
[DisplayName("Black and White Mode")]
[Description("Set the TV Type switch on the console to B&W or Color. This only affects the displayed image if the game supports it.")]
[DefaultValue(false)]

View File

@ -27,6 +27,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
Settings = (A2600Settings)settings ?? new A2600Settings();
SyncSettings = (A2600SyncSettings)syncSettings ?? new A2600SyncSettings();
_controllerDeck = new Atari2600ControllerDeck(SyncSettings.Port1, SyncSettings.Port2);
_leftDifficultySwitchPressed = SyncSettings.LeftDifficulty;
_rightDifficultySwitchPressed = SyncSettings.RightDifficulty;
@ -58,6 +60,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
ser.Register<ISoundProvider>(_dcfilter);
}
private readonly Atari2600ControllerDeck _controllerDeck;
// IRegionable
public DisplayType Region => _pal ? DisplayType.PAL : DisplayType.NTSC;

View File

@ -0,0 +1,90 @@
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
{
private static readonly Type[] Implementors =
{
typeof(UnpluggedController), // Order must match Atari2600ControllerTypes enum values
typeof(StandardController),
};
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();
}
}

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Atari.Atari2600
{
public enum Atari2600ControllerTypes
{
Unplugged,
Joystick
}
/// <summary>
/// Represents a controller plugged into a controller port on the Colecovision
/// </summary>
public interface IPort
{
byte Read(IController c);
ControllerDefinition Definition { get; }
void SyncState(Serializer ser);
int PortNum { get; }
}
public class UnpluggedController : IPort
{
public UnpluggedController(int portNum)
{
PortNum = portNum;
Definition = new ControllerDefinition
{
BoolButtons = new List<string>()
};
}
public byte Read(IController c)
{
return 0xFF;
}
public ControllerDefinition Definition { get; }
public void SyncState(Serializer ser)
{
// Do nothing
}
public int PortNum { get; }
}
public class StandardController : IPort
{
public StandardController(int portNum)
{
PortNum = portNum;
Definition = new ControllerDefinition
{
BoolButtons = BaseDefinition
.Select(b => $"P{PortNum} " + b)
.ToList()
};
}
public ControllerDefinition Definition { get; }
public void SyncState(Serializer ser)
{
// Nothing todo, I think
}
public int PortNum { get; }
public byte Read(IController c)
{
byte result = 0xFF;
if (c.IsPressed($"P{PortNum} Up")) { result &= 0xEF; }
if (c.IsPressed($"P{PortNum} Down")) { result &= 0xDF; }
if (c.IsPressed($"P{PortNum} Left")) { result &= 0xBF; }
if (c.IsPressed($"P{PortNum} Right")) { result &= 0x7F; }
if (c.IsPressed($"P{PortNum} Button")) { result &= 0xF7; }
return result;
}
private static readonly string[] BaseDefinition =
{
"Up", "Down", "Left", "Right", "Button"
};
}
}