Accuracy improvement to z80
properly set interrupt enable after the NEXT instruction
This commit is contained in:
parent
b2920834b1
commit
3fa2828d5b
|
@ -14,6 +14,8 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
||||||
private int pendingCycles;
|
private int pendingCycles;
|
||||||
public int PendingCycles { get { return pendingCycles; } set { pendingCycles = value; } }
|
public int PendingCycles { get { return pendingCycles; } set { pendingCycles = value; } }
|
||||||
|
|
||||||
|
private int EI_pending;
|
||||||
|
|
||||||
public bool Debug;
|
public bool Debug;
|
||||||
public Action<TraceInfo> Logger;
|
public Action<TraceInfo> Logger;
|
||||||
|
|
||||||
|
@ -35,7 +37,8 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
||||||
while (pendingCycles > 0)
|
while (pendingCycles > 0)
|
||||||
{
|
{
|
||||||
Interruptable = true;
|
Interruptable = true;
|
||||||
|
//if (interrupt == true)
|
||||||
|
//Console.WriteLine(totalExecutedCycles);
|
||||||
if (halted)
|
if (halted)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -6629,7 +6632,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
||||||
totalExecutedCycles += 10; pendingCycles -= 10;
|
totalExecutedCycles += 10; pendingCycles -= 10;
|
||||||
break;
|
break;
|
||||||
case 0xFB: // EI
|
case 0xFB: // EI
|
||||||
IFF1 = IFF2 = true;
|
EI_pending = 2;
|
||||||
Interruptable = false;
|
Interruptable = false;
|
||||||
totalExecutedCycles += 4; pendingCycles -= 4;
|
totalExecutedCycles += 4; pendingCycles -= 4;
|
||||||
break;
|
break;
|
||||||
|
@ -8011,7 +8014,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
||||||
totalExecutedCycles += 10; pendingCycles -= 10;
|
totalExecutedCycles += 10; pendingCycles -= 10;
|
||||||
break;
|
break;
|
||||||
case 0xFB: // EI
|
case 0xFB: // EI
|
||||||
IFF1 = IFF2 = true;
|
EI_pending = 2;
|
||||||
Interruptable = false;
|
Interruptable = false;
|
||||||
totalExecutedCycles += 4; pendingCycles -= 4;
|
totalExecutedCycles += 4; pendingCycles -= 4;
|
||||||
break;
|
break;
|
||||||
|
@ -11857,7 +11860,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
||||||
totalExecutedCycles += 10; pendingCycles -= 10;
|
totalExecutedCycles += 10; pendingCycles -= 10;
|
||||||
break;
|
break;
|
||||||
case 0xFB: // EI
|
case 0xFB: // EI
|
||||||
IFF1 = IFF2 = true;
|
EI_pending = 2;
|
||||||
Interruptable = false;
|
Interruptable = false;
|
||||||
totalExecutedCycles += 4; pendingCycles -= 4;
|
totalExecutedCycles += 4; pendingCycles -= 4;
|
||||||
break;
|
break;
|
||||||
|
@ -11944,6 +11947,16 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
||||||
}
|
}
|
||||||
IRQCallback();
|
IRQCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//EI (enable interrupts) actually takes effect after the NEXT instruction
|
||||||
|
if (EI_pending > 0)
|
||||||
|
{
|
||||||
|
EI_pending--;
|
||||||
|
if (EI_pending == 0)
|
||||||
|
{
|
||||||
|
IFF1 = IFF2 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
||||||
ser.Sync("Halted", ref halted);
|
ser.Sync("Halted", ref halted);
|
||||||
ser.Sync("ExecutedCycles", ref totalExecutedCycles);
|
ser.Sync("ExecutedCycles", ref totalExecutedCycles);
|
||||||
ser.Sync("PendingCycles", ref pendingCycles);
|
ser.Sync("PendingCycles", ref pendingCycles);
|
||||||
|
ser.Sync("EI_pending", ref EI_pending);
|
||||||
ser.EndSection();
|
ser.EndSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue