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:
parent
5e65c7e977
commit
5b5932696d
|
@ -142,6 +142,7 @@ namespace BizHawk
|
||||||
tia.execute(1);
|
tia.execute(1);
|
||||||
tia.execute(1);
|
tia.execute(1);
|
||||||
|
|
||||||
|
m6532.tick();
|
||||||
cpu.Execute(1);
|
cpu.Execute(1);
|
||||||
if (cpu.PendingCycles <= 0)
|
if (cpu.PendingCycles <= 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Consoles.Atari
|
||||||
public byte swchb = 0x0B;
|
public byte swchb = 0x0B;
|
||||||
|
|
||||||
public bool resetOccured = false;
|
public bool resetOccured = false;
|
||||||
|
public int totalCycles = 0;
|
||||||
|
|
||||||
public M6532(MOS6507 cpu, byte[] ram, Atari2600 core)
|
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)
|
public byte ReadMemory(ushort addr)
|
||||||
{
|
{
|
||||||
ushort maskedAddr;
|
ushort maskedAddr;
|
||||||
|
@ -53,12 +58,12 @@ namespace BizHawk.Emulation.Consoles.Atari
|
||||||
Console.WriteLine("6532 timer read: " + maskedAddr.ToString("x"));
|
Console.WriteLine("6532 timer read: " + maskedAddr.ToString("x"));
|
||||||
|
|
||||||
// Calculate the current value on the timer
|
// Calculate the current value on the timer
|
||||||
int timerCurrentValue = timerFinishedCycles - Cpu.TotalExecutedCycles;
|
int timerCurrentValue = timerFinishedCycles - totalCycles;
|
||||||
|
|
||||||
interruptTriggered = false;
|
interruptTriggered = false;
|
||||||
|
|
||||||
// If the timer has not finished, shift the value down for the game
|
// 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);
|
return (byte)(((timerCurrentValue) >> timerShift) & 0xFF);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +98,7 @@ namespace BizHawk.Emulation.Consoles.Atari
|
||||||
}
|
}
|
||||||
else if (maskedAddr == 0x05) // interrupt
|
else if (maskedAddr == 0x05) // interrupt
|
||||||
{
|
{
|
||||||
if ((timerFinishedCycles - Cpu.TotalExecutedCycles >= 0)|| (interruptEnabled && interruptTriggered))
|
if ((timerFinishedCycles - totalCycles >= 0)|| (interruptEnabled && interruptTriggered))
|
||||||
{
|
{
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +135,7 @@ namespace BizHawk.Emulation.Consoles.Atari
|
||||||
timerStartValue = value << timerShift;
|
timerStartValue = value << timerShift;
|
||||||
|
|
||||||
// Calculate when the timer will be finished
|
// Calculate when the timer will be finished
|
||||||
timerFinishedCycles = timerStartValue + Cpu.TotalExecutedCycles;
|
timerFinishedCycles = timerStartValue + totalCycles;
|
||||||
|
|
||||||
Console.WriteLine("6532 timer write: " + maskedAddr.ToString("x"));
|
Console.WriteLine("6532 timer write: " + maskedAddr.ToString("x"));
|
||||||
|
|
||||||
|
|
|
@ -719,9 +719,17 @@ namespace BizHawk.Emulation.Consoles.Atari
|
||||||
}
|
}
|
||||||
else if (maskedAddr == 0x02) // WSYNC
|
else if (maskedAddr == 0x02) // WSYNC
|
||||||
{
|
{
|
||||||
|
int count = 0;
|
||||||
while (hsyncCnt > 0)
|
while (hsyncCnt > 0)
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
execute(1);
|
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
|
else if (maskedAddr == 0x04) // NUSIZ0
|
||||||
|
|
Loading…
Reference in New Issue