mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-10-24 14:05:42 +00:00
36 lines
859 B
C#
36 lines
859 B
C#
// <copyright file="ClockedChip.cs" company="Adrian Conlon">
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
// </copyright>
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace EightBit
|
|
{
|
|
public class ClockedChip : Chip
|
|
{
|
|
protected ClockedChip()
|
|
{
|
|
}
|
|
|
|
public event EventHandler<EventArgs>? Ticked;
|
|
|
|
public int Cycles { get; protected set; }
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void Tick(int extra = 1)
|
|
{
|
|
this.Cycles += extra;
|
|
var ticked = this.Ticked;
|
|
if (ticked is not null)
|
|
{
|
|
for (var i = 0; i < extra; ++i)
|
|
{
|
|
ticked.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void ResetCycles() => this.Cycles = 0;
|
|
}
|
|
}
|