EightBitNet/EightBit/ClockedChip.cs
2019-02-04 23:52:21 +00:00

40 lines
858 B
C#

// <copyright file="ClockedChip.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace EightBit
{
using System;
public class ClockedChip : Chip
{
private int cycles;
protected ClockedChip()
{
}
public event EventHandler<EventArgs> Ticked;
public int Cycles { get => this.cycles; protected set => this.cycles = value; }
public void Tick(int extra)
{
for (int i = 0; i < extra; ++i)
{
this.Tick();
}
}
public void Tick()
{
++this.Cycles;
this.OnTicked();
}
protected virtual void OnTicked() => this.Ticked?.Invoke(this, EventArgs.Empty);
protected void ResetCycles() => this.Cycles = 0;
}
}