From 3a41061f836896a2e8e7ac8587476b2c82e1aee3 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 1 Jun 2019 16:54:58 +0100 Subject: [PATCH] Check interrupt sources after every opcode when in normal speed. (#651) --- source/CPU.cpp | 13 +++++++------ source/CPU/cpu6502.h | 2 +- source/CPU/cpu65C02.h | 2 +- source/CPU/cpu65d02.h | 2 +- test/TestCPU6502/TestCPU6502.cpp | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/source/CPU.cpp b/source/CPU.cpp index c951431d..8b1e9635 100644 --- a/source/CPU.cpp +++ b/source/CPU.cpp @@ -132,10 +132,11 @@ unsigned __int64 g_nCumulativeCycles = 0; static ULONG g_nCyclesExecuted; // # of cycles executed up to last IO access //static signed long g_uInternalExecutedCycles; -// TODO: Use IRQ_CHECK_TIMEOUT=128 when running at full-speed else with IRQ_CHECK_TIMEOUT=1 +// Use IRQ_CHECK_TIMEOUT=128 when running at full-speed; else use IRQ_CHECK_TIMEOUT=1 (GH#651) // - What about when running benchmark? -static const int IRQ_CHECK_TIMEOUT = 128; -static signed int g_nIrqCheckTimeout = IRQ_CHECK_TIMEOUT; +static const int IRQ_CHECK_TIMEOUT_FULL_SPEED = 128; +static const int IRQ_CHECK_TIMEOUT_NORMAL_SPEED = 1; +static signed int g_nIrqCheckTimeout = IRQ_CHECK_TIMEOUT_NORMAL_SPEED; // @@ -417,20 +418,20 @@ static __forceinline void IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, } } -static __forceinline void CheckInterruptSources(ULONG uExecutedCycles) +static __forceinline void CheckInterruptSources(ULONG uExecutedCycles, const bool bVideoUpdate) { if (g_nIrqCheckTimeout < 0) { MB_UpdateCycles(uExecutedCycles); sg_Mouse.SetVBlank( !VideoGetVblBar(uExecutedCycles) ); - g_nIrqCheckTimeout = IRQ_CHECK_TIMEOUT; + g_nIrqCheckTimeout = bVideoUpdate ? IRQ_CHECK_TIMEOUT_NORMAL_SPEED : IRQ_CHECK_TIMEOUT_FULL_SPEED; } } // GH#608: IRQ needs to occur within 17 cycles (6 opcodes) of configuring the timer interrupt void CpuAdjustIrqCheck(UINT uCyclesUntilInterrupt) { - if (uCyclesUntilInterrupt < IRQ_CHECK_TIMEOUT) + if (g_bFullSpeed && uCyclesUntilInterrupt < IRQ_CHECK_TIMEOUT_FULL_SPEED) g_nIrqCheckTimeout = uCyclesUntilInterrupt; } diff --git a/source/CPU/cpu6502.h b/source/CPU/cpu6502.h index a9b87701..29b8452b 100644 --- a/source/CPU/cpu6502.h +++ b/source/CPU/cpu6502.h @@ -318,7 +318,7 @@ static DWORD Cpu6502(DWORD uTotalCycles, const bool bVideoUpdate) #undef $ } - CheckInterruptSources(uExecutedCycles); + CheckInterruptSources(uExecutedCycles, bVideoUpdate); NMI(uExecutedCycles, flagc, flagn, flagv, flagz); IRQ(uExecutedCycles, flagc, flagn, flagv, flagz); diff --git a/source/CPU/cpu65C02.h b/source/CPU/cpu65C02.h index 67279db3..1dc06227 100644 --- a/source/CPU/cpu65C02.h +++ b/source/CPU/cpu65C02.h @@ -321,7 +321,7 @@ static DWORD Cpu65C02(DWORD uTotalCycles, const bool bVideoUpdate) #undef $ } - CheckInterruptSources(uExecutedCycles); + CheckInterruptSources(uExecutedCycles, bVideoUpdate); NMI(uExecutedCycles, flagc, flagn, flagv, flagz); IRQ(uExecutedCycles, flagc, flagn, flagv, flagz); diff --git a/source/CPU/cpu65d02.h b/source/CPU/cpu65d02.h index e7e5b2e9..bdb78634 100644 --- a/source/CPU/cpu65d02.h +++ b/source/CPU/cpu65d02.h @@ -406,7 +406,7 @@ static DWORD Cpu65D02(DWORD uTotalCycles, const bool bVideoUpdate) } #undef $ - CheckInterruptSources(uExecutedCycles); + CheckInterruptSources(uExecutedCycles, bVideoUpdate); NMI(uExecutedCycles, flagc, flagn, flagv, flagz); IRQ(uExecutedCycles, flagc, flagn, flagv, flagz); diff --git a/test/TestCPU6502/TestCPU6502.cpp b/test/TestCPU6502/TestCPU6502.cpp index 08342e73..2e869469 100644 --- a/test/TestCPU6502/TestCPU6502.cpp +++ b/test/TestCPU6502/TestCPU6502.cpp @@ -54,7 +54,7 @@ static __forceinline void DoIrqProfiling(DWORD uCycles) { } -static __forceinline void CheckInterruptSources(ULONG uExecutedCycles) +static __forceinline void CheckInterruptSources(ULONG uExecutedCycles, const bool bVideoUpdate) { }