C64: Simplify input handling.
This commit is contained in:
parent
68396dcb03
commit
67edd5df1e
|
@ -2,23 +2,23 @@
|
|||
{
|
||||
public sealed partial class Motherboard
|
||||
{
|
||||
private readonly int[] _joystickPressed = new int[10];
|
||||
private readonly int[] _keyboardPressed = new int[64];
|
||||
private readonly bool[] _joystickPressed = new bool[10];
|
||||
private readonly bool[] _keyboardPressed = new bool[64];
|
||||
|
||||
private static readonly string[,] JoystickMatrix = {
|
||||
{"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button"},
|
||||
{"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button"}
|
||||
private static readonly string[][] JoystickMatrix = {
|
||||
new[] {"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button"},
|
||||
new[] {"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button"}
|
||||
};
|
||||
|
||||
private static readonly string[,] KeyboardMatrix = {
|
||||
{ "Key Insert/Delete", "Key Return", "Key Cursor Left/Right", "Key F7", "Key F1", "Key F3", "Key F5", "Key Cursor Up/Down" },
|
||||
{ "Key 3", "Key W", "Key A", "Key 4", "Key Z", "Key S", "Key E", "Key Left Shift" },
|
||||
{ "Key 5", "Key R", "Key D", "Key 6", "Key C", "Key F", "Key T", "Key X" },
|
||||
{ "Key 7", "Key Y", "Key G", "Key 8", "Key B", "Key H", "Key U", "Key V" },
|
||||
{ "Key 9", "Key I", "Key J", "Key 0", "Key M", "Key K", "Key O", "Key N" },
|
||||
{ "Key Plus", "Key P", "Key L", "Key Minus", "Key Period", "Key Colon", "Key At", "Key Comma" },
|
||||
{ "Key Pound", "Key Asterisk", "Key Semicolon", "Key Clear/Home", "Key Right Shift", "Key Equal", "Key Up Arrow", "Key Slash" },
|
||||
{ "Key 1", "Key Left Arrow", "Key Control", "Key 2", "Key Space", "Key Commodore", "Key Q", "Key Run/Stop" }
|
||||
private static readonly string[][] KeyboardMatrix = {
|
||||
new[] { "Key Insert/Delete", "Key Return", "Key Cursor Left/Right", "Key F7", "Key F1", "Key F3", "Key F5", "Key Cursor Up/Down" },
|
||||
new[] { "Key 3", "Key W", "Key A", "Key 4", "Key Z", "Key S", "Key E", "Key Left Shift" },
|
||||
new[] { "Key 5", "Key R", "Key D", "Key 6", "Key C", "Key F", "Key T", "Key X" },
|
||||
new[] { "Key 7", "Key Y", "Key G", "Key 8", "Key B", "Key H", "Key U", "Key V" },
|
||||
new[] { "Key 9", "Key I", "Key J", "Key 0", "Key M", "Key K", "Key O", "Key N" },
|
||||
new[] { "Key Plus", "Key P", "Key L", "Key Minus", "Key Period", "Key Colon", "Key At", "Key Comma" },
|
||||
new[] { "Key Pound", "Key Asterisk", "Key Semicolon", "Key Clear/Home", "Key Right Shift", "Key Equal", "Key Up Arrow", "Key Slash" },
|
||||
new[] { "Key 1", "Key Left Arrow", "Key Control", "Key 2", "Key Space", "Key Commodore", "Key Q", "Key Run/Stop" }
|
||||
};
|
||||
|
||||
[SaveState.DoNotSave] int _pollIndex;
|
||||
|
@ -33,9 +33,10 @@
|
|||
{
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
_joystickPressed[_pollIndex++] = Controller[JoystickMatrix[j, i]] ? -1 : 0;
|
||||
_joystickPressed[_pollIndex] = Controller[JoystickMatrix[j][i]];
|
||||
_pollIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// scan keyboard
|
||||
_pollIndex = 0;
|
||||
|
@ -43,7 +44,7 @@
|
|||
{
|
||||
for (var j = 0; j < 8; j++)
|
||||
{
|
||||
_keyboardPressed[_pollIndex++] = Controller[KeyboardMatrix[i, j]] ? -1 : 0;
|
||||
_keyboardPressed[_pollIndex++] = Controller[KeyboardMatrix[i][j]];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
|
|||
}
|
||||
}
|
||||
|
||||
public static Cia Create(C64.CiaType type, int[] keyboard, int[] joysticks)
|
||||
public static Cia Create(C64.CiaType type, bool[] keyboard, bool[] joysticks)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -36,10 +36,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
|
|||
{
|
||||
[SaveState.DoNotSave] private int _ret;
|
||||
[SaveState.DoNotSave] private int _tst;
|
||||
[SaveState.DoNotSave] private readonly int[] _joyData;
|
||||
[SaveState.DoNotSave] private readonly int[] _keyData;
|
||||
[SaveState.DoNotSave] private readonly bool[] _joyData;
|
||||
[SaveState.DoNotSave] private readonly bool[] _keyData;
|
||||
|
||||
public JoystickKeyboardPort(int[] joyData, int[] keyData)
|
||||
public JoystickKeyboardPort(bool[] joyData, bool[] keyData)
|
||||
{
|
||||
_joyData = joyData;
|
||||
_keyData = keyData;
|
||||
|
@ -48,21 +48,21 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
|
|||
private int GetJoystick1()
|
||||
{
|
||||
return 0xE0 |
|
||||
(_joyData[0] == 0 ? 0x01 : 0x00) |
|
||||
(_joyData[1] == 0 ? 0x02 : 0x00) |
|
||||
(_joyData[2] == 0 ? 0x04 : 0x00) |
|
||||
(_joyData[3] == 0 ? 0x08 : 0x00) |
|
||||
(_joyData[4] == 0 ? 0x10 : 0x00);
|
||||
(_joyData[0] ? 0x00 : 0x01) |
|
||||
(_joyData[1] ? 0x00 : 0x02) |
|
||||
(_joyData[2] ? 0x00 : 0x04) |
|
||||
(_joyData[3] ? 0x00 : 0x08) |
|
||||
(_joyData[4] ? 0x00 : 0x10);
|
||||
}
|
||||
|
||||
private int GetJoystick2()
|
||||
{
|
||||
return 0xE0 |
|
||||
(_joyData[5] == 0 ? 0x01 : 0x00) |
|
||||
(_joyData[6] == 0 ? 0x02 : 0x00) |
|
||||
(_joyData[7] == 0 ? 0x04 : 0x00) |
|
||||
(_joyData[8] == 0 ? 0x08 : 0x00) |
|
||||
(_joyData[9] == 0 ? 0x10 : 0x00);
|
||||
(_joyData[5] ? 0x00 : 0x01) |
|
||||
(_joyData[6] ? 0x00 : 0x02) |
|
||||
(_joyData[7] ? 0x00 : 0x04) |
|
||||
(_joyData[8] ? 0x00 : 0x08) |
|
||||
(_joyData[9] ? 0x00 : 0x10);
|
||||
}
|
||||
|
||||
private int GetKeyboardRows(int activeColumns)
|
||||
|
@ -75,7 +75,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
|
|||
var i = r << 3;
|
||||
for (var c = 0; c < 8; c++)
|
||||
{
|
||||
if (_keyData[i++] != 0)
|
||||
if (_keyData[i++])
|
||||
{
|
||||
result &= ~(1 << c);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
|
|||
var i = c;
|
||||
for (var r = 0; r < 8; r++)
|
||||
{
|
||||
if (_keyData[i] != 0)
|
||||
if (_keyData[i])
|
||||
{
|
||||
result &= ~(1 << r);
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
|
|||
_todDen = todDen;
|
||||
}
|
||||
|
||||
public Cia(int todNum, int todDen, int[] keyboard, int[] joysticks) : this(todNum, todDen)
|
||||
public Cia(int todNum, int todDen, bool[] keyboard, bool[] joysticks) : this(todNum, todDen)
|
||||
{
|
||||
_port = new JoystickKeyboardPort(joysticks, keyboard);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue