M6532: Added a dedicated cycle count variable to fix a timer issue.

TIA: Increment the M6532 cycle count when in wsync.
This commit is contained in:
pjgat09 2012-03-21 01:02:24 +00:00
parent 5e65c7e977
commit 5b5932696d
3 changed files with 19 additions and 5 deletions

View File

@ -142,6 +142,7 @@ namespace BizHawk
tia.execute(1);
tia.execute(1);
m6532.tick();
cpu.Execute(1);
if (cpu.PendingCycles <= 0)
{

View File

@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Consoles.Atari
public byte swchb = 0x0B;
public bool resetOccured = false;
public int totalCycles = 0;
public M6532(MOS6507 cpu, byte[] ram, Atari2600 core)
{
@ -35,6 +35,11 @@ namespace BizHawk.Emulation.Consoles.Atari
}
public void tick()
{
totalCycles++;
}
public byte ReadMemory(ushort addr)
{
ushort maskedAddr;
@ -53,12 +58,12 @@ namespace BizHawk.Emulation.Consoles.Atari
Console.WriteLine("6532 timer read: " + maskedAddr.ToString("x"));
// Calculate the current value on the timer
int timerCurrentValue = timerFinishedCycles - Cpu.TotalExecutedCycles;
int timerCurrentValue = timerFinishedCycles - totalCycles;
interruptTriggered = false;
// If the timer has not finished, shift the value down for the game
if (Cpu.TotalExecutedCycles < timerFinishedCycles)
if (totalCycles < timerFinishedCycles)
{
return (byte)(((timerCurrentValue) >> timerShift) & 0xFF);
}
@ -93,7 +98,7 @@ namespace BizHawk.Emulation.Consoles.Atari
}
else if (maskedAddr == 0x05) // interrupt
{
if ((timerFinishedCycles - Cpu.TotalExecutedCycles >= 0)|| (interruptEnabled && interruptTriggered))
if ((timerFinishedCycles - totalCycles >= 0)|| (interruptEnabled && interruptTriggered))
{
return 0x00;
}
@ -130,7 +135,7 @@ namespace BizHawk.Emulation.Consoles.Atari
timerStartValue = value << timerShift;
// Calculate when the timer will be finished
timerFinishedCycles = timerStartValue + Cpu.TotalExecutedCycles;
timerFinishedCycles = timerStartValue + totalCycles;
Console.WriteLine("6532 timer write: " + maskedAddr.ToString("x"));

View File

@ -719,9 +719,17 @@ namespace BizHawk.Emulation.Consoles.Atari
}
else if (maskedAddr == 0x02) // WSYNC
{
int count = 0;
while (hsyncCnt > 0)
{
count++;
execute(1);
// Add a cycle to the cpu every 3 TIA clocks (corrects timer error in M6532)
if (count % 3 == 0)
{
core.m6532.tick();
}
}
}
else if (maskedAddr == 0x04) // NUSIZ0