commodore64: implement proper lag frame counting

This commit is contained in:
saxxonpike 2012-11-19 16:38:39 +00:00
parent aca129d5f6
commit 8d6e55e2a9
4 changed files with 53 additions and 3 deletions

View File

@ -100,6 +100,7 @@
<Compile Include="Computers\Commodore64\SidSoundProvider.cs" />
<Compile Include="Computers\Commodore64\SidWaveformCalculator.cs" />
<Compile Include="Computers\Commodore64\SidWaveformGenerator.cs" />
<Compile Include="Computers\Commodore64\Timing.cs" />
<Compile Include="Computers\Commodore64\Via.cs" />
<Compile Include="Computers\Commodore64\VicIINew.cs" />
<Compile Include="Computers\Commodore64\VicIINewPipeline.cs" />

View File

@ -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++;

View File

@ -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:

View File

@ -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;
}
}
}