commodore64: full keyboard controller implemented
This commit is contained in:
parent
d1576a5efc
commit
e0f9abd1ee
|
@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
public partial class C64 : IEmulator
|
||||
{
|
||||
// input
|
||||
private IController controller;
|
||||
public Input input;
|
||||
|
||||
// source
|
||||
public Cartridge cart;
|
||||
|
@ -21,8 +21,6 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
// chipset
|
||||
public Cia cia0;
|
||||
public Cia cia1;
|
||||
public byte cia0portAData;
|
||||
public byte cia0portBData;
|
||||
public MOS6502X cpu;
|
||||
public Memory mem;
|
||||
public Sid sid;
|
||||
|
@ -31,6 +29,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
|
||||
public void HardReset()
|
||||
{
|
||||
// initalize cpu
|
||||
cpu = new MOS6502X();
|
||||
cpu.ReadMemory = ReadMemory;
|
||||
cpu.WriteMemory = WriteMemory;
|
||||
|
@ -56,9 +55,12 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
mem = new Memory(romPath, vic, sid, cia0, cia1);
|
||||
vic.mem = mem;
|
||||
|
||||
// initialize cpu (hard reset vector)
|
||||
// initialize cpu hard reset vector
|
||||
cpu.PC = (ushort)(ReadMemory(0xFFFC) + (ReadMemory(0xFFFD) << 8));
|
||||
|
||||
// initailize input
|
||||
input = new Input(cia0.ports);
|
||||
|
||||
// initialize media
|
||||
switch (extension.ToUpper())
|
||||
{
|
||||
|
@ -100,6 +102,9 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
|
||||
public void PollInput()
|
||||
{
|
||||
input.Poll();
|
||||
|
||||
/*
|
||||
cia0portAData = 0xFF;
|
||||
cia0portBData = 0xFF;
|
||||
|
||||
|
@ -113,6 +118,9 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
if (Controller["P2 Left"]) cia0portAData &= 0xFB;
|
||||
if (Controller["P2 Right"]) cia0portAData &= 0xF7;
|
||||
if (Controller["P2 Button"]) cia0portAData &= 0xEF;
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
public byte ReadMemory(ushort addr)
|
||||
|
|
|
@ -54,14 +54,22 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
public void SaveStateBinary(BinaryWriter bw) { } //TODO
|
||||
public void LoadStateBinary(BinaryReader br) { } //TODO
|
||||
public ControllerDefinition ControllerDefinition { get { return C64ControllerDefinition; } }
|
||||
public IController Controller { get { return controller; } set { controller = value; } }
|
||||
public IController Controller { get { return input.controller; } set { input.controller = value; } }
|
||||
public static readonly ControllerDefinition C64ControllerDefinition = new ControllerDefinition
|
||||
{
|
||||
Name = "Commodore 64 Controller", //TODO
|
||||
BoolButtons =
|
||||
{
|
||||
"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",
|
||||
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button",
|
||||
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button"
|
||||
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -33,6 +33,11 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
}
|
||||
}
|
||||
|
||||
public void SetRemoteData(byte val)
|
||||
{
|
||||
_data = val;
|
||||
}
|
||||
|
||||
private void WritePortDummy(byte val)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -9,9 +9,14 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
{
|
||||
static string[,] keyboardMatrix = new string[,]
|
||||
{
|
||||
{"Key Insert/Delete", "Key Return", "Key Cursor Left/Right", "Key F7", "Key F1", "Key F3", "Key F5", "Cursor Up/Down"},
|
||||
{"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"}
|
||||
};
|
||||
|
||||
static string[,] joystickMatrix = new string[,]
|
||||
|
@ -20,19 +25,21 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
{"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button"}
|
||||
};
|
||||
|
||||
private IController controller;
|
||||
private byte[] joystickLatch = new byte[2];
|
||||
private byte keyboardColumnData;
|
||||
private byte[] keyboardLatch = new byte[8];
|
||||
private byte keyboardRowData;
|
||||
public IController controller;
|
||||
|
||||
public Input(IController newController, Cia newCia)
|
||||
private byte[] joystickLatch = new byte[2];
|
||||
private byte keyboardColumnData = 0xFF;
|
||||
private byte[] keyboardLatch = new byte[8];
|
||||
private byte keyboardRowData = 0xFF;
|
||||
private DirectionalDataPort[] ports;
|
||||
|
||||
public Input(DirectionalDataPort[] newPorts)
|
||||
{
|
||||
controller = newController;
|
||||
ports = newPorts;
|
||||
|
||||
// attach input to a CIA I/O port
|
||||
newCia.ports[0].WritePort = WritePortA;
|
||||
newCia.ports[1].WritePort = WritePortB;
|
||||
ports[0].WritePort = WritePortA;
|
||||
ports[1].WritePort = WritePortB;
|
||||
}
|
||||
|
||||
private byte GetJoystickBits(int index)
|
||||
|
@ -66,18 +73,41 @@ namespace BizHawk.Emulation.Computers.Commodore64
|
|||
joystickLatch[i] = GetJoystickBits(i);
|
||||
for (int i = 0; i < 8; i++)
|
||||
keyboardLatch[i] = GetKeyboardBits(i);
|
||||
UpdatePortData();
|
||||
}
|
||||
|
||||
private void UpdatePortData()
|
||||
{
|
||||
int keyboardShift = keyboardRowData;
|
||||
byte port0result = 0xFF;
|
||||
byte port1result = 0xFF;
|
||||
|
||||
port0result = (byte)(keyboardColumnData & joystickLatch[1]);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if ((keyboardShift & 0x01) == 0x00)
|
||||
port1result &= keyboardLatch[i];
|
||||
keyboardShift >>= 1;
|
||||
}
|
||||
port1result &= joystickLatch[0];
|
||||
|
||||
ports[0].SetRemoteData(port0result);
|
||||
ports[1].SetRemoteData(port1result);
|
||||
}
|
||||
|
||||
public void WritePortA(byte data)
|
||||
{
|
||||
// keyboard matrix column select
|
||||
keyboardColumnData = data;
|
||||
UpdatePortData();
|
||||
}
|
||||
|
||||
public void WritePortB(byte data)
|
||||
{
|
||||
// keyboard matrix row select
|
||||
keyboardRowData = data;
|
||||
UpdatePortData();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue