Atari 2600: start work on keyboard controller (incomplete)

This commit is contained in:
alyosha-tas 2019-12-31 18:37:10 -05:00
parent 1fd9bd7b38
commit 8548859a67
5 changed files with 189 additions and 9 deletions

View File

@ -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;

View File

@ -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)

View File

@ -13,7 +13,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
Joystick,
Paddle,
BoostGrip,
Driving
Driving,
Keyboard
}
/// <summary>
@ -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", "#"
};
}
}

View File

@ -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;

View File

@ -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;
}