diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj
index b02eb1a1b9..0365d14c0b 100644
--- a/BizHawk.Emulation/BizHawk.Emulation.csproj
+++ b/BizHawk.Emulation/BizHawk.Emulation.csproj
@@ -100,6 +100,7 @@
+
diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs
index 5b2770a25d..435c5c1ad4 100644
--- a/BizHawk.Emulation/Computers/Commodore64/C64.cs
+++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs
@@ -91,11 +91,13 @@ namespace BizHawk.Emulation.Computers.Commodore64
// process frame
public void FrameAdvance(bool render, bool rendersound)
{
- _frame++;
- _islag = true;
-
int cyclesPerFrame = vic.CyclesPerFrame;
+
+ // bizhawk interface setup
+ _frame++;
+ mem.inputWasRead = false;
+ // apply any media if needed
foreach (IMedia media in mediaAttached)
{
if (!media.Loaded() && media.Ready())
@@ -104,8 +106,10 @@ namespace BizHawk.Emulation.Computers.Commodore64
}
}
+ // refresh the input values
PollInput();
+ // perform the cycle
for (int i = 0; i < cyclesPerFrame; i++)
{
vic.PerformCycle();
@@ -124,6 +128,8 @@ namespace BizHawk.Emulation.Computers.Commodore64
}
}
+ _islag = !mem.inputWasRead;
+
if (_islag)
{
LagCount++;
diff --git a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs
index cb13681fe1..bc1c7f7a86 100644
--- a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs
+++ b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs
@@ -62,6 +62,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
// registers
public byte busData;
+ public bool inputWasRead;
public bool readTrigger = true;
public bool writeTrigger = true;
@@ -364,6 +365,8 @@ namespace BizHawk.Emulation.Computers.Commodore64
result = ReadColorRam(addr);
break;
case MemoryDesignation.Cia0:
+ if ((addr & 0xF) < 0x02)
+ inputWasRead = true;
result = cia0.Read(addr);
break;
case MemoryDesignation.Cia1:
diff --git a/BizHawk.Emulation/Computers/Commodore64/Timing.cs b/BizHawk.Emulation/Computers/Commodore64/Timing.cs
new file mode 100644
index 0000000000..9d56e06b0e
--- /dev/null
+++ b/BizHawk.Emulation/Computers/Commodore64/Timing.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BizHawk.Emulation.Computers.Commodore64
+{
+ public class Timing
+ {
+ public int crystalFreq;
+ public uint timer;
+
+ public Timing(Region timingRegion)
+ {
+ switch (timingRegion)
+ {
+ case Region.NTSC:
+ crystalFreq = 14318181;
+ break;
+ case Region.PAL:
+ crystalFreq = 17734472;
+ break;
+ }
+ }
+
+ public void Advance()
+ {
+ // need an unchecked block here since the timer will wrap
+ unchecked
+ {
+ timer++;
+ }
+ }
+
+ public bool IsCycle(int divisor)
+ {
+ return (timer % divisor) == 0;
+ }
+ }
+}