diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs index 40c31c5c6d..274fe1529f 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs @@ -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); } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs index 5337040508..c37ca46753 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs @@ -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 diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs index b848b07817..7062014ddd 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs @@ -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]; diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs index 7016108962..434806e4c9 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs @@ -32,14 +32,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public class PortAdapter { private Action actWrite; - private Action actWriteForce; + private Action actWriteMask; private Func funcRead; - public PortAdapter(Func newRead, Action newWrite, Action newWriteForce) + public PortAdapter(Func newRead, Action newWrite, Action 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); } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs index 96dbc22c6b..553a5e96f2 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs @@ -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