commodore64: joystick input now works 100% accurately (tested with ciaports.prg from the VICE test suite)

This commit is contained in:
saxxonpike 2012-12-01 00:02:24 +00:00
parent 3049098afb
commit 08c83a16fd
5 changed files with 35 additions and 22 deletions

View File

@ -70,14 +70,8 @@ namespace BizHawk.Emulation.Computers.Commodore64
byte portB = inputAdapter1.Data;
byte resultA = 0xFF;
byte resultB = 0xFF;
for (uint i = 0; i < 5; i++)
{
if (joystickPressed[1, i])
resultA &= inputBitMask[i];
if (joystickPressed[0, i])
resultB &= inputBitMask[i];
}
byte joyA = 0xFF;
byte joyB = 0xFF;
for (uint i = 0; i < 8; i++)
{
@ -94,8 +88,18 @@ namespace BizHawk.Emulation.Computers.Commodore64
}
}
inputAdapter0.ForceWrite((byte)(resultA & portB));
for (uint i = 0; i < 5; i++)
{
if (joystickPressed[1, i])
joyA &= inputBitMask[i];
if (joystickPressed[0, i])
joyB &= inputBitMask[i];
}
inputAdapter0.Data = resultA;
inputAdapter1.Data = resultB;
inputAdapter0.MaskWrite(joyB);
inputAdapter1.MaskWrite(joyA);
}
}
}

View File

@ -66,6 +66,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public void ExecutePhase2()
{
if (chips.vic.BA)
freezeCpu = false;
if (chips.vic.AEC && !freezeCpu)
{
// the 6502 core expects active high

View File

@ -406,10 +406,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
switch (addr)
{
case 0x0:
val = portData[0];
val = (byte)(portData[0] & portMask[0]);
break;
case 0x1:
val = portData[1];
val = (byte)(portData[1] & portMask[1]);
break;
case 0x2:
val = portDir[0];

View File

@ -32,14 +32,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public class PortAdapter
{
private Action<byte> actWrite;
private Action<byte> actWriteForce;
private Action<byte> actWriteMask;
private Func<byte> funcRead;
public PortAdapter(Func<byte> newRead, Action<byte> newWrite, Action<byte> newWriteForce)
public PortAdapter(Func<byte> newRead, Action<byte> newWrite, Action<byte> newWriteMask)
{
funcRead = newRead;
actWrite = newWrite;
actWriteForce = newWriteForce;
actWriteMask = newWriteMask;
}
public byte Data
@ -54,9 +54,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
}
}
public void ForceWrite(byte val)
public void MaskWrite(byte val)
{
actWriteForce(val);
actWriteMask(val);
}
}
}

View File

@ -12,6 +12,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
protected bool pinIRQ;
protected byte[] portData;
protected byte[] portDir;
protected byte[] portMask;
protected uint[] timer;
protected uint[] timerLatch;
protected bool[] timerOn;
@ -21,6 +22,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
portData = new byte[2];
portDir = new byte[2];
portMask = new byte[2];
timer = new uint[2];
timerLatch = new uint[2];
timerOn = new bool[2];
@ -31,7 +33,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
get
{
return Port.GetAdapter(ReadPort0, ExternalWritePort0, ExternalWriteForce0);
return Port.GetAdapter(ReadPort0, ExternalWritePort0, ExternalWriteMask0);
}
}
@ -39,18 +41,18 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
get
{
return Port.GetAdapter(ReadPort1, ExternalWritePort1, ExternalWriteForce1);
return Port.GetAdapter(ReadPort1, ExternalWritePort1, ExternalWriteMask1);
}
}
private void ExternalWriteForce0(byte data)
private void ExternalWriteMask0(byte data)
{
portData[0] = data;
portMask[0] = data;
}
private void ExternalWriteForce1(byte data)
private void ExternalWriteMask1(byte data)
{
portData[1] = data;
portMask[1] = data;
}
private void ExternalWritePort(uint index, byte data)
@ -77,6 +79,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
pinIRQ = true;
portDir[0] = 0xFF;
portDir[1] = 0xFF;
portMask[0] = 0xFF;
portMask[1] = 0xFF;
portData[0] = 0xFF;
portData[1] = 0xFF;
}
public bool IRQ