From: kub Date: Mon, 14 Dec 2020 20:06:24 +0000 (+0100) Subject: cz80, improve cycle accounting X-Git-Tag: v2.00~636 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85894ad4066396453825348105f851c6c05b6d27;p=picodrive.git cz80, improve cycle accounting --- diff --git a/cpu/cz80/cz80.c b/cpu/cz80/cz80.c index 1a3a676e..7f432bda 100644 --- a/cpu/cz80/cz80.c +++ b/cpu/cz80/cz80.c @@ -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; + } } diff --git a/cpu/cz80/cz80_op.c b/cpu/cz80/cz80_op.c index b1520088..60810f13 100644 --- a/cpu/cz80/cz80_op.c +++ b/cpu/cz80/cz80_op.c @@ -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; diff --git a/cpu/cz80/cz80macro.h b/cpu/cz80/cz80macro.h index 2e21d409..36fdacb7 100644 --- a/cpu/cz80/cz80macro.h +++ b/cpu/cz80/cz80macro.h @@ -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) \ } diff --git a/pico/pico_int.h b/pico/pico_int.h index f6ea29cb..411d9f93 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -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)