From 8548859a67f35aa9ebd85b7b3b283d524738f6db Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Tue, 31 Dec 2019 18:37:10 -0500 Subject: [PATCH] Atari 2600: start work on keyboard controller (incomplete) --- .../Consoles/Atari/2600/Atari2600.Core.cs | 4 +- .../Atari/2600/Atari2600ControllerDeck.cs | 3 +- .../Atari/2600/Atari2600Controllers.cs | 59 +++++++- .../Consoles/Atari/2600/M6532.cs | 6 +- .../Consoles/Atari/2600/Tia/TIA.cs | 126 +++++++++++++++++- 5 files changed, 189 insertions(+), 9 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index bef82b1590..3c479b2647 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -12,8 +12,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { private readonly GameInfo _game; - private TIA _tia; - private M6532 _m6532; + public TIA _tia; + public M6532 _m6532; private DCFilter _dcfilter; private MapperBase _mapper; private byte[] _ram; diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs index baa68e39ec..18d3306ca3 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs @@ -16,7 +16,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 typeof(StandardController), typeof(PaddleController), typeof(BoostGripController), - typeof(DrivingController) + typeof(DrivingController), + typeof(KeyboardController) }; public Atari2600ControllerDeck(Atari2600ControllerTypes controller1, Atari2600ControllerTypes controller2) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index 1b44676c6d..a66018fb87 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -13,7 +13,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 Joystick, Paddle, BoostGrip, - Driving + Driving, + Keyboard } /// @@ -320,4 +321,60 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 return angle; } } + + public class KeyboardController : IPort + { + public KeyboardController(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} 0")) { result = 0x00; } + if (c.IsPressed($"P{PortNum} 1")) { result = 0x01; } + if (c.IsPressed($"P{PortNum} 2")) { result = 0x02; } + if (c.IsPressed($"P{PortNum} 3")) { result = 0x03; } + if (c.IsPressed($"P{PortNum} 4")) { result = 0x04; } + if (c.IsPressed($"P{PortNum} 5")) { result = 0x05; } + if (c.IsPressed($"P{PortNum} 6")) { result = 0x06; } + if (c.IsPressed($"P{PortNum} 7")) { result = 0x07; } + if (c.IsPressed($"P{PortNum} 8")) { result = 0x08; } + if (c.IsPressed($"P{PortNum} 9")) { result = 0x09; } + if (c.IsPressed($"P{PortNum} *")) { result = 0x0A; } + if (c.IsPressed($"P{PortNum} #")) { result = 0x0B; } + + return result; + } + + public int Read_Pot(IController c, int pot) + { + return -2; // indicates keyboard + } + + private static readonly string[] BaseDefinition = + { + "1", "2", "3", + "4", "5", "6", + "7", "8", "9", + "*", "0", "#" + }; + } } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/M6532.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/M6532.cs index 5c4486818f..e13945a1b2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/M6532.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/M6532.cs @@ -8,9 +8,9 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { private readonly Atari2600 _core; - private byte _ddRa = 0x00; - private byte _ddRb = 0x00; - private byte _outputA = 0x00; + public byte _ddRa = 0x00; + public byte _ddRb = 0x00; + public byte _outputA = 0x00; public TimerData Timer; diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs index ee22dc7599..d95eba6713 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs @@ -982,6 +982,25 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { coll = 0x80; } + else if (_core.ReadPot1(0) == -2) + { + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x80) + { + if (_core.ReadControls1(peek) == 0x1) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x40) + { + if (_core.ReadControls1(peek) == 0x4) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x20) + { + if (_core.ReadControls1(peek) == 0x7) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x10) + { + if (_core.ReadControls1(peek) == 0xA) { coll |= 0x80; } + } + } else { coll = 0x00; @@ -996,6 +1015,25 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { coll = 0x80; } + else if (_core.ReadPot1(1) == -2) + { + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x80) + { + if (_core.ReadControls1(peek) == 0x2) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x40) + { + if (_core.ReadControls1(peek) == 0x5) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x20) + { + if (_core.ReadControls1(peek) == 0x8) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x10) + { + if (_core.ReadControls1(peek) == 0x0) { coll |= 0x80; } + } + } else { coll = 0x00; @@ -1010,6 +1048,25 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { coll = 0x80; } + else if (_core.ReadPot2(0) == -2) + { + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x08) == 0x08) + { + if (_core.ReadControls2(peek) == 0x1) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x04) == 0x04) + { + if (_core.ReadControls2(peek) == 0x4) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x02) == 0x02) + { + if (_core.ReadControls2(peek) == 0x7) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x01) == 0x01) + { + if (_core.ReadControls2(peek) == 0xA) { coll |= 0x80; } + } + } else { coll = 0x00; @@ -1024,6 +1081,25 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { coll = 0x80; } + else if (_core.ReadPot2(1) == -2) + { + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x08) == 0x08) + { + if (_core.ReadControls2(peek) == 0x2) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x04) == 0x04) + { + if (_core.ReadControls2(peek) == 0x5) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x02) == 0x02) + { + if (_core.ReadControls2(peek) == 0x8) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x01) == 0x01) + { + if (_core.ReadControls2(peek) == 0x0) { coll |= 0x80; } + } + } else { coll = 0x00; @@ -1034,13 +1110,59 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if (maskedAddr == 0x0C) // INPT4 { - coll = (byte)((_core.ReadControls1(peek) & 0x08) != 0 ? 0x80 : 0x00); + if (_core.ReadPot1(0) != -2) + { + coll = (byte)((_core.ReadControls1(peek) & 0x08) != 0 ? 0x80 : 0x00); + } + else + { + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x80) + { + if (_core.ReadControls1(peek) == 0x3) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x40) + { + if (_core.ReadControls1(peek) == 0x6) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x20) + { + if (_core.ReadControls1(peek) == 0x9) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x80) == 0x10) + { + if (_core.ReadControls1(peek) == 0xB) { coll |= 0x80; } + } + } + mask = 0x7f; } if (maskedAddr == 0x0D) // INPT5 { - coll = (byte)((_core.ReadControls2(peek) & 0x08) != 0 ? 0x80 : 0x00); + if (_core.ReadPot2(0) != -2) + { + coll = (byte)((_core.ReadControls2(peek) & 0x08) != 0 ? 0x80 : 0x00); + } + else + { + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x08) == 0x08) + { + if (_core.ReadControls2(peek) == 0x3) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x04) == 0x04) + { + if (_core.ReadControls2(peek) == 0x6) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x02) == 0x02) + { + if (_core.ReadControls2(peek) == 0x9) { coll |= 0x80; } + } + if (((_core._m6532._ddRa & _core._m6532._outputA) & 0x01) == 0x01) + { + if (_core.ReadControls2(peek) == 0xB) { coll |= 0x80; } + } + } + mask = 0x7f; }