From b9b1b96c42f570faa575d186038a042243ed1dea Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Wed, 10 Jun 2026 20:12:24 +0100 Subject: [PATCH] Cycles count needs to be correct per clock tick --- EightBit/ClockedChip.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/EightBit/ClockedChip.cs b/EightBit/ClockedChip.cs index c4752f4..c7d0d16 100644 --- a/EightBit/ClockedChip.cs +++ b/EightBit/ClockedChip.cs @@ -19,14 +19,16 @@ namespace EightBit [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Tick(int extra = 1) { - this.Cycles += extra; var ticked = this.Ticked; - if (ticked is not null) + if (ticked is null) { - for (var i = 0; i < extra; ++i) - { - ticked.Invoke(this, EventArgs.Empty); - } + this.Cycles += extra; + return; + } + for (var i = 0; i < extra; ++i) + { + ++this.Cycles; + ticked.Invoke(this, EventArgs.Empty); } }