cz80, improve cycle accounting

This commit is contained in:
kub 2020-12-14 21:06:24 +01:00
parent e0d5c83fd3
commit 85894ad406
4 changed files with 46 additions and 45 deletions

View file

@ -275,23 +275,22 @@ Cz80_Check_Interrupt:
if (CPU->IRQState != CLEAR_LINE)
{
CHECK_INT
CPU->ICount -= CPU->ExtraCycles;
CPU->ExtraCycles = 0;
}
CPU->ICount -= CPU->ExtraCycles;
CPU->ExtraCycles = 0;
if (!CPU->HaltState)
goto Cz80_Exec;
}
}
else CPU->ICount = 0;
Cz80_Exec_End:
CPU->PC = PC;
#if CZ80_ENCRYPTED_ROM
CPU->OPBase = OPBase;
#endif
if (CPU->HaltState)
CPU->ICount = 0;
cycles -= CPU->ICount;
if (!(CPU->HaltState && CPU->ICount > 0))
cycles -= CPU->ICount;
CPU->ICount = 0;
#if !CZ80_EMULATE_R_EXACTLY
zR = (zR + (cycles >> 2)) & 0x7f;
#endif
@ -333,6 +332,11 @@ void Cz80_Set_IRQ(cz80_struc *CPU, INT32 line, INT32 state)
#endif
}
}
if (CPU->ICount > 0)
{
CPU->ICount -= CPU->ExtraCycles;
CPU->ExtraCycles = 0;
}
}

View file

@ -709,12 +709,9 @@ OP_EI:
zR++;
#endif
}
if (CPU->IRQState)
{
afterEI = 1;
CPU->ExtraCycles += 1 - CPU->ICount;
CPU->ICount = 1;
}
afterEI = 1;
CPU->ExtraCycles += 1 - CPU->ICount;
CPU->ICount = 1;
}
else zIFF2 = (1 << 2);
goto Cz80_Exec_nocheck;

View file

@ -94,36 +94,36 @@
#define IN(A) CPU->IN_Port(A)
#define OUT(A, D) CPU->OUT_Port(A, D)
#define CHECK_INT \
if (zIFF1) \
{ \
UINT32 IntVect; \
\
if (CPU->IRQState == HOLD_LINE) \
CPU->IRQState = CLEAR_LINE; \
\
CPU->HaltState = 0; \
zIFF1 = zIFF2 = 0; \
IntVect = CPU->Interrupt_Callback(CPU->IRQLine); \
\
PUSH_16(zRealPC) \
\
if (zIM == 2) \
{ \
IntVect = (IntVect & 0xff) | (zI << 8); \
PC = READ_MEM16(IntVect); \
CPU->ExtraCycles += 17; \
} \
else if (zIM == 1) \
{ \
PC = 0x38; \
CPU->ExtraCycles += 13; \
} \
else \
{ \
PC = IntVect & 0x38; \
CPU->ExtraCycles += 13; \
} \
\
SET_PC(PC) \
#define CHECK_INT \
if (zIFF1) \
{ \
UINT32 IntVect; \
\
if (CPU->IRQState == HOLD_LINE) \
CPU->IRQState = CLEAR_LINE; \
\
CPU->HaltState = 0; \
zIFF1 = zIFF2 = 0; \
IntVect = CPU->Interrupt_Callback(CPU->IRQLine); \
\
PUSH_16(zRealPC) \
\
if (zIM == 2) \
{ \
IntVect = (IntVect & 0xff) | (zI << 8); \
PC = READ_MEM16(IntVect); \
CPU->ExtraCycles += 17; \
} \
else if (zIM == 1) \
{ \
PC = 0x38; \
CPU->ExtraCycles += 13; \
} \
else \
{ \
PC = IntVect & 0x38; \
CPU->ExtraCycles += 13; \
} \
\
SET_PC(PC) \
}

View file

@ -183,7 +183,7 @@ extern struct DrZ80 drZ80;
#define z80_int_assert(a) Cz80_Set_IRQ(&CZ80, 0, (a) ? ASSERT_LINE : CLEAR_LINE)
#define z80_nmi() Cz80_Set_IRQ(&CZ80, IRQ_LINE_NMI, 0)
#define z80_cyclesLeft CZ80.ICount
#define z80_cyclesLeft (CZ80.ICount - CZ80.ExtraCycles)
#define z80_subCLeft(c) CZ80.ICount -= c
#define z80_pc() Cz80_Get_Reg(&CZ80, CZ80_PC)