Some fixes and code refactoring
This commit is contained in:
@@ -25,10 +25,12 @@ namespace Core.Cpu
|
||||
|
||||
public int InterruptMode { get; private set; } = 0;
|
||||
|
||||
|
||||
// Interrupt Flip-Flops
|
||||
public bool IFF1 { get; private set; } = false;
|
||||
public bool IFF2 { get; private set; } = false;
|
||||
public bool InterruptRequested { get; private set; } = false;
|
||||
private bool _eiPending = false;
|
||||
|
||||
// Main Register Set
|
||||
public RegisterPair AF;
|
||||
@@ -213,7 +215,8 @@ namespace Core.Cpu
|
||||
}
|
||||
|
||||
public int Step()
|
||||
{
|
||||
{
|
||||
bool triggerEi = _eiPending;
|
||||
|
||||
// Fetch the next opcode and increment the Program Counter
|
||||
byte opcode = ReadMemory(PC++);
|
||||
@@ -221,6 +224,13 @@ namespace Core.Cpu
|
||||
int tStates = ExecuteOpcode(opcode);
|
||||
TotalTStates += tStates;
|
||||
|
||||
if (triggerEi)
|
||||
{
|
||||
IFF1 = true;
|
||||
IFF2 = true;
|
||||
_eiPending = false;
|
||||
}
|
||||
|
||||
// Decode and execute
|
||||
return tStates;
|
||||
}
|
||||
@@ -240,9 +250,6 @@ namespace Core.Cpu
|
||||
$"C:{f & 1}";
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// MATH AND LOGIC HELPERS
|
||||
// =========================================================================
|
||||
|
||||
private void SubA(byte value, bool isCompare)
|
||||
{
|
||||
@@ -1272,6 +1279,7 @@ namespace Core.Cpu
|
||||
case 0xF3: // DI
|
||||
IFF1 = false;
|
||||
IFF2 = false;
|
||||
_eiPending = false;
|
||||
return 4;
|
||||
case 0xf5: //push af
|
||||
Push(AF.Word);
|
||||
@@ -1283,8 +1291,7 @@ namespace Core.Cpu
|
||||
SP = HL.Word;
|
||||
return 6;
|
||||
case 0xFB: // EI
|
||||
IFF1 = true;
|
||||
IFF2 = true;
|
||||
_eiPending = true;
|
||||
return 4;
|
||||
case 0xFD:
|
||||
return ExecuteFDPrefix();
|
||||
|
||||
Reference in New Issue
Block a user