From 74dd25e831941525fa9ba298270a3c266ab06bef Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 27 Jun 2017 15:14:41 -0500 Subject: [PATCH 1/8] 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 --- .../BizHawk.Emulation.Cores.csproj | 2 + .../Consoles/Atari/2600/Atari2600.Core.cs | 28 +----- .../Atari/2600/Atari2600.IEmulator.cs | 2 +- .../Atari/2600/Atari2600.ISettable.cs | 12 +++ .../Consoles/Atari/2600/Atari2600.cs | 4 + .../Atari/2600/Atari2600ControllerDeck.cs | 90 +++++++++++++++++ .../Atari/2600/Atari2600Controllers.cs | 97 +++++++++++++++++++ 7 files changed, 209 insertions(+), 26 deletions(-) create mode 100644 BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs create mode 100644 BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 43a0b1e78c..dffc9c90ac 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -284,6 +284,8 @@ Atari2600.cs + + diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index a6b6c2266f..5b1c1e6cd4 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -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) { diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IEmulator.cs index dc68137771..65d910b1c1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IEmulator.cs @@ -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) { diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.ISettable.cs index c6d8dad7fa..353b35d865 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.ISettable.cs @@ -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)] diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs index 240cb926a1..c64e16786d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs @@ -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(_dcfilter); } + private readonly Atari2600ControllerDeck _controllerDeck; + // IRegionable public DisplayType Region => _pal ? DisplayType.PAL : DisplayType.NTSC; diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs new file mode 100644 index 0000000000..27277d0b48 --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs @@ -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 _controllerTypes; + + public static Dictionary 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(); + } +} diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs new file mode 100644 index 0000000000..1bf6f23d44 --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -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 + } + + /// + /// Represents a controller plugged into a controller port on the Colecovision + /// + 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() + }; + } + + 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" + }; + } +} From c3b890c60cb716b8f7d741920647ace98b4cd815 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 27 Jun 2017 17:22:45 -0500 Subject: [PATCH 2/8] Atari 2600 - stub out the paddle controller --- .../Atari/2600/Atari2600ControllerDeck.cs | 157 +++++++++--------- .../Atari/2600/Atari2600Controllers.cs | 44 ++++- 2 files changed, 122 insertions(+), 79 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs index 27277d0b48..7a972c2f30 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs @@ -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 _controllerTypes; - - public static Dictionary 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 _controllerTypes; + + public static Dictionary 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(); } } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index 1bf6f23d44..9bd411a3a6 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -11,7 +11,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 public enum Atari2600ControllerTypes { Unplugged, - Joystick + Joystick, + Paddle } /// @@ -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; + } + } } From d862ad823268fd61db0289c730e928f1905aafec Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 28 Jun 2017 07:23:36 -0500 Subject: [PATCH 3/8] Atari 2600 - Virtual support for new controller configurations (Paddles just stubbed out), add Left and Rigth Difficulty toggle buttons to the console buttons section --- .../tools/VirtualPads/schema/A26Schema.cs | 70 +++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs index ce3f419918..bbc59be09f 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs @@ -2,6 +2,7 @@ using System.Drawing; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Cores.Atari.Atari2600; namespace BizHawk.Client.EmuHawk { @@ -10,11 +11,37 @@ namespace BizHawk.Client.EmuHawk { public IEnumerable GetPadSchemas(IEmulator core) { - yield return StandardController(1); - yield return StandardController(2); + var ss = ((Atari2600)core).GetSyncSettings().Clone(); + + var port1 = PadSchemaFromSetting(ss.Port1, 1); + if (port1 != null) + { + yield return port1; + } + + var port2 = PadSchemaFromSetting(ss.Port2, 2); + if (port2 != null) + { + yield return port2; + } + yield return ConsoleButtons(); } + private static PadSchema PadSchemaFromSetting(Atari2600ControllerTypes type, int controller) + { + switch (type) + { + default: + case Atari2600ControllerTypes.Unplugged: + return null; + case Atari2600ControllerTypes.Joystick: + return StandardController(controller); + case Atari2600ControllerTypes.Paddle: + return PaddleController(controller); + } + } + private static PadSchema StandardController(int controller) { return new PadSchema @@ -68,13 +95,34 @@ namespace BizHawk.Client.EmuHawk }; } + private static PadSchema PaddleController(int controller) + { + return new PadSchema + { + DisplayName = "Player " + controller, + IsConsole = false, + DefaultSize = new Size(174, 74), + MaxSize = new Size(174, 74), + Buttons = new[] + { + new PadSchema.ButtonSchema + { + Name = "P" + controller + " Button", + DisplayName = "B", + Location = new Point(124, 24), + Type = PadSchema.PadInputType.Boolean + } + } + }; + } + private static PadSchema ConsoleButtons() { return new PadSchema { DisplayName = "Console", IsConsole = true, - DefaultSize = new Size(160, 50), + DefaultSize = new Size(185, 75), Buttons = new[] { new PadSchema.ButtonSchema @@ -97,7 +145,21 @@ namespace BizHawk.Client.EmuHawk DisplayName = "Power", Location = new Point(108, 15), Type = PadSchema.PadInputType.Boolean - } + }, + new PadSchema.ButtonSchema + { + Name = "Toggle Left Difficulty", + DisplayName = "Left Difficulty", + Location = new Point(10, 40), + Type = PadSchema.PadInputType.Boolean + }, + new PadSchema.ButtonSchema + { + Name = "Toggle Right Difficulty", + DisplayName = "Right Difficulty", + Location = new Point(92, 40), + Type = PadSchema.PadInputType.Boolean + }, } }; } From 2f6d05512fcea59ff0888717ea6e8d98795484da Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 28 Jun 2017 10:57:07 -0400 Subject: [PATCH 4/8] A2600 TIA: Hook up Paddle logic --- BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs index 9022443ab0..4306c96eef 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs @@ -871,7 +871,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 // 6105 roughly centers the paddle in Breakout if (maskedAddr == 0x08) // INPT0 { - if (_capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= 6105) + if (_core.ReadPot1(0)>0 && _capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= _core.ReadPot1(0)) { coll = 0x80; } @@ -885,7 +885,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if (maskedAddr == 0x09) // INPT1 { - if (_capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= 6105) + if (_core.ReadPot1(1) > 0 && _capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= _core.ReadPot1(1)) { coll = 0x80; } @@ -899,7 +899,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if (maskedAddr == 0x0A) // INPT2 { - if (_capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= 6105) + if (_core.ReadPot2(0) > 0 && _capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= _core.ReadPot2(0)) { coll = 0x80; } @@ -913,7 +913,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if (maskedAddr == 0x0B) // INPT3 { - if (_capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= 6105) + if (_core.ReadPot2(1) > 0 && _capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= _core.ReadPot2(1)) { coll = 0x80; } From 82d03dc3e997561b60d0da374c971abde82007a3 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 28 Jun 2017 10:58:40 -0400 Subject: [PATCH 5/8] A2600: implement paddle support Warning: Deadzone in float controls should be set to zero. I don't know where to look to do this by default though --- .../Consoles/Atari/2600/Atari2600.Core.cs | 14 ++++++++ .../Atari/2600/Atari2600ControllerDeck.cs | 10 ++++++ .../Atari/2600/Atari2600Controllers.cs | 33 +++++++++++++++---- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index 5b1c1e6cd4..bbfdb5e569 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -468,6 +468,20 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 return value; } + internal int ReadPot1(int pot) + { + int value = _controllerDeck.ReadPot1(_controller, pot); + + return value; + } + + internal int ReadPot2(int pot) + { + int value = _controllerDeck.ReadPot2(_controller, pot); + + return value; + } + internal byte ReadConsoleSwitches(bool peek) { byte value = 0xFF; diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs index 7a972c2f30..775592841c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs @@ -51,6 +51,16 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 return Port2.Read(c); } + public int ReadPot1(IController c, int pot) + { + return Port1.Read_Pot(c, pot); + } + + public int ReadPot2(IController c, int pot) + { + return Port2.Read_Pot(c, pot); + } + public ControllerDefinition Definition { get; } public void SyncState(Serializer ser) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index 9bd411a3a6..d1e40c10fd 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -22,6 +22,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { byte Read(IController c); + int Read_Pot(IController c, int pot); + ControllerDefinition Definition { get; } void SyncState(Serializer ser); @@ -45,6 +47,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 return 0xFF; } + public int Read_Pot(IController c, int pot) + { + return -1; // indicates not applicable + } + public ControllerDefinition Definition { get; } public void SyncState(Serializer ser) @@ -90,6 +97,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 return result; } + public int Read_Pot(IController c, int pot) + { + return -1; // indicates not applicable + } + private static readonly string[] BaseDefinition = { "Up", "Down", "Left", "Right", "Button" @@ -106,8 +118,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 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 + FloatControls = { "P" + PortNum + " Paddle X 1" , "P" + PortNum + " Paddle X 2" }, + FloatRanges = { new[] { 16266.0f, 8138f, 10.0f }, new[] { 16266.0f, 8138f, 10.0f } } // No idea what values should be here }; } @@ -122,18 +134,25 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private static readonly string[] BaseDefinition = { - "Button" + "Button 0", + "Button 1" }; public byte Read(IController c) { - byte result = 0xFF; + byte result = 0xF0; - if (c.IsPressed($"P{PortNum} Button")) { result &= 0xF7; } // TODO - - //int x = (int)c.GetFloat(Definition.FloatControls[0]); + if (c.IsPressed($"P{PortNum} Button 0")) { result &= 0x70; } + if (c.IsPressed($"P{PortNum} Button 1")) { result &= 0xB0; } return result; } + + public int Read_Pot(IController c, int pot) + { + int x = (int)c.GetFloat(Definition.FloatControls[pot]); + + return x; + } } } From f5cb35a8628ba9cd0e8121509627212de58508c4 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 28 Jun 2017 14:27:15 -0500 Subject: [PATCH 6/8] Atari 2600 - vritual pad and mnemonics for paddles --- .../movie/bk2/Bk2MnemonicConstants.cs | 2 + .../tools/VirtualPads/schema/A26Schema.cs | 39 ++++++++++++++++--- .../Atari/2600/Atari2600Controllers.cs | 8 ++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/BizHawk.Client.Common/movie/bk2/Bk2MnemonicConstants.cs b/BizHawk.Client.Common/movie/bk2/Bk2MnemonicConstants.cs index 45f1d8a888..6d6dca3fe1 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2MnemonicConstants.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2MnemonicConstants.cs @@ -79,6 +79,8 @@ namespace BizHawk.Client.Common ["R3"] = '>', ["Button"] = 'B', + ["Button 1"] = '1', + ["Button 2"] = '2', ["B1"] = '1', ["B2"] = '2', diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs index bbc59be09f..8c235af5a1 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs @@ -101,17 +101,44 @@ namespace BizHawk.Client.EmuHawk { DisplayName = "Player " + controller, IsConsole = false, - DefaultSize = new Size(174, 74), - MaxSize = new Size(174, 74), + DefaultSize = new Size(334, 94), + MaxSize = new Size(334, 94), Buttons = new[] { new PadSchema.ButtonSchema { - Name = "P" + controller + " Button", - DisplayName = "B", - Location = new Point(124, 24), + Name = "P" + controller + " Button 1", + DisplayName = "B1", + Location = new Point(5, 24), Type = PadSchema.PadInputType.Boolean - } + }, + new PadSchema.ButtonSchema + { + Name = "P" + controller + " Button 2", + DisplayName = "B2", + Location = new Point(5, 48), + Type = PadSchema.PadInputType.Boolean + }, + new PadSchema.ButtonSchema + { + Name = "P" + controller + " Paddle X 1", + DisplayName = "Paddle X 1", + Location = new Point(55, 17), + Type = PadSchema.PadInputType.FloatSingle, + TargetSize = new Size(128, 69), + MaxValue = 16266, + MinValue = 0 + }, + new PadSchema.ButtonSchema + { + Name = "P" + controller + " Paddle X 2", + DisplayName = "Paddle X 2", + Location = new Point(193, 17), + Type = PadSchema.PadInputType.FloatSingle, + TargetSize = new Size(128, 69), + MaxValue = 16266, + MinValue = 0 + }, } }; } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index d1e40c10fd..381f57e5e9 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -134,16 +134,16 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private static readonly string[] BaseDefinition = { - "Button 0", - "Button 1" + "Button 1", + "Button 2" }; public byte Read(IController c) { byte result = 0xF0; - if (c.IsPressed($"P{PortNum} Button 0")) { result &= 0x70; } - if (c.IsPressed($"P{PortNum} Button 1")) { result &= 0xB0; } + if (c.IsPressed($"P{PortNum} Button 1")) { result &= 0x70; } + if (c.IsPressed($"P{PortNum} Button 2")) { result &= 0xB0; } return result; } From a4360b9c36e839de162e80961d2f4a550dd8afb0 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 29 Jun 2017 11:02:55 -0400 Subject: [PATCH 7/8] A2600: Adjust range on float controls Scale them in read function instead . NOTE: still needs some play testing from someone familiar with how the paddle controls to see if it feels right. --- .../Consoles/Atari/2600/Atari2600Controllers.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index 381f57e5e9..9e5f41444e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -119,7 +119,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 .Select(b => $"P{PortNum} " + b) .ToList(), FloatControls = { "P" + PortNum + " Paddle X 1" , "P" + PortNum + " Paddle X 2" }, - FloatRanges = { new[] { 16266.0f, 8138f, 10.0f }, new[] { 16266.0f, 8138f, 10.0f } } // No idea what values should be here + FloatRanges = { new[] { -127.0f, 0, 127.0f }, new[] { -127.0f, 0, 127.0f } } }; } @@ -150,7 +150,12 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 public int Read_Pot(IController c, int pot) { - int x = (int)c.GetFloat(Definition.FloatControls[pot]); + int x = (int)c.GetFloat(Definition.FloatControls[pot]); + + x = -x; + x += 127; + + x = x * 64 + 10; return x; } From aaaeb95a05ae125bc03fbd1c208e36627a7cfd07 Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 29 Jun 2017 13:46:17 -0500 Subject: [PATCH 8/8] Atari 2600 - update paddle virtualpads with the new float ranges --- .../tools/VirtualPads/schema/A26Schema.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs index 8c235af5a1..59890aa8a3 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/A26Schema.cs @@ -126,8 +126,8 @@ namespace BizHawk.Client.EmuHawk Location = new Point(55, 17), Type = PadSchema.PadInputType.FloatSingle, TargetSize = new Size(128, 69), - MaxValue = 16266, - MinValue = 0 + MaxValue = 127, + MinValue = -127 }, new PadSchema.ButtonSchema { @@ -136,8 +136,8 @@ namespace BizHawk.Client.EmuHawk Location = new Point(193, 17), Type = PadSchema.PadInputType.FloatSingle, TargetSize = new Size(128, 69), - MaxValue = 16266, - MinValue = 0 + MaxValue = 127, + MinValue = -127 }, } };