commodore64: updated directional dataport, keyboard input now works fully- commands can be executed in BASIC

This commit is contained in:
saxxonpike 2012-11-15 08:36:06 +00:00
parent 2ff12a9e3a
commit 020dedb1a0
4 changed files with 62 additions and 50 deletions

View File

@ -75,6 +75,8 @@ namespace BizHawk.Emulation.Computers.Commodore64
// initailize input
input = new Input( new DataPortConnector[] { cia0.ConnectPort(0), cia0.ConnectPort(1) } );
cia0.AttachWriteHook(0, input.WritePortA);
cia0.AttachWriteHook(1, input.WritePortB);
// initialize media
switch (extension.ToUpper())

View File

@ -11,13 +11,14 @@ namespace BizHawk.Emulation.Computers.Commodore64
private bool[] connected = new bool[2];
private byte[] direction = new byte[2];
private byte[] latch = new byte[2];
private List<int> servingHooks = new List<int>();
private List<Action> writeHooks = new List<Action>();
public DataPortBus()
{
connectors = new DataPortConnector[2];
connectors[0] = new DataPortConnector(ReadData0, ReadDirection0, WriteData0, WriteDirection0);
connectors[1] = new DataPortConnector(ReadData1, ReadDirection1, WriteData1, WriteDirection1);
connectors[0] = new DataPortConnector(ReadData0, ReadDirection0, ReadRemoteData0, WriteData0, WriteDirection0);
connectors[1] = new DataPortConnector(ReadData1, ReadDirection1, ReadRemoteData1, WriteData1, WriteDirection1);
connected[0] = false;
connected[1] = false;
direction[0] = 0x00;
@ -29,6 +30,14 @@ namespace BizHawk.Emulation.Computers.Commodore64
public void AttachWriteHook(Action act)
{
writeHooks.Add(act);
servingHooks.Add(0);
}
private void ClearHooks()
{
int count = servingHooks.Count;
for (int i = 0; i < count; i++)
servingHooks[i]--;
}
public DataPortConnector Connect()
@ -64,6 +73,24 @@ namespace BizHawk.Emulation.Computers.Commodore64
}
}
private void ExecuteWriteHooks()
{
int count = servingHooks.Count;
for (int i = 0; i < count; i++)
{
if (servingHooks[i] == 0)
{
servingHooks[i]++;
writeHooks[i]();
}
else
{
servingHooks[i]++;
}
}
ClearHooks();
}
private byte ReadData0()
{
if (connected[1])
@ -90,34 +117,40 @@ namespace BizHawk.Emulation.Computers.Commodore64
return direction[1];
}
private byte ReadRemoteData0()
{
return latch[1];
}
private byte ReadRemoteData1()
{
return latch[0];
}
private void WriteData0(byte val)
{
latch[0] &= (byte)~direction[0];
latch[0] |= (byte)(val & direction[0]);
foreach (Action hook in writeHooks)
hook();
ExecuteWriteHooks();
}
private void WriteData1(byte val)
{
latch[1] &= (byte)~direction[1];
latch[1] |= (byte)(val & direction[1]);
foreach (Action hook in writeHooks)
hook();
ExecuteWriteHooks();
}
private void WriteDirection0(byte val)
{
direction[0] = val;
foreach (Action hook in writeHooks)
hook();
ExecuteWriteHooks();
}
private void WriteDirection1(byte val)
{
direction[1] = val;
foreach (Action hook in writeHooks)
hook();
ExecuteWriteHooks();
}
}
@ -125,13 +158,15 @@ namespace BizHawk.Emulation.Computers.Commodore64
{
private Func<byte> ReadData;
private Func<byte> ReadDirection;
private Func<byte> ReadRemoteData;
private Action<byte> WriteData;
private Action<byte> WriteDirection;
public DataPortConnector(Func<byte> newReadData, Func<byte> newReadDirection, Action<byte> newWriteData, Action<byte> newWriteDirection)
public DataPortConnector(Func<byte> newReadData, Func<byte> newReadDirection, Func<byte> newReadRemoteData, Action<byte> newWriteData, Action<byte> newWriteDirection)
{
ReadData = newReadData;
ReadDirection = newReadDirection;
ReadRemoteData = newReadRemoteData;
WriteData = newWriteData;
WriteDirection = newWriteDirection;
}
@ -160,6 +195,14 @@ namespace BizHawk.Emulation.Computers.Commodore64
}
}
public byte RemoteData
{
get
{
return ReadRemoteData();
}
}
public DataPortListener Listener()
{
return new DataPortListener(ReadData, ReadDirection);

View File

@ -65,6 +65,8 @@ namespace BizHawk.Emulation.Computers.Commodore64
result |= controller[keyboardMatrix[row, 5]] ? (byte)0x00 : (byte)0x20;
result |= controller[keyboardMatrix[row, 6]] ? (byte)0x00 : (byte)0x40;
result |= controller[keyboardMatrix[row, 7]] ? (byte)0x00 : (byte)0x80;
if (result != 0xFF)
row = row;
return result;
}
@ -101,17 +103,17 @@ namespace BizHawk.Emulation.Computers.Commodore64
ports[1].Data = port1result;
}
public void WritePortA(byte data)
public void WritePortA()
{
// keyboard matrix column select
keyboardColumnData = data;
keyboardColumnData = ports[0].RemoteData;
UpdatePortData();
}
public void WritePortB(byte data)
public void WritePortB()
{
// keyboard matrix row select
keyboardRowData = data;
keyboardRowData = ports[1].RemoteData;
UpdatePortData();
}
}

View File

@ -33,41 +33,6 @@ namespace BizHawk.Emulation.Computers.Commodore64
mem.Write((ushort)(address & 0xFFFF), data[i]);
address++;
}
if (data[0x06] == 0x9E)
{
// sys command
bool isNumber = false;
int sysAddress = 0;
int sysIndex = 0x07;
while (data[sysIndex] != 0)
{
if (!isNumber)
{
if (data[sysIndex] >= 0x30 && data[sysIndex] <= 0x39)
{
isNumber = true;
}
else
{
sysIndex++;
}
}
if (isNumber)
{
sysAddress *= 10;
sysAddress += (data[sysIndex] & 0xF);
sysIndex++;
if (data[sysIndex] < 0x30 || data[sysIndex] > 0x39)
break;
}
}
if (sysAddress > 0 && sysAddress < 0x10000)
{
cpu.PC = (ushort)sysAddress;
}
}
loaded = true;
}