2019-02-04 23:52:21 +00:00
|
|
|
|
// <copyright file="ClockedChip.cs" company="Adrian Conlon">
|
|
|
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
|
namespace EightBit
|
2019-02-02 15:12:51 +00:00
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
public class ClockedChip : Chip
|
|
|
|
|
{
|
2019-02-04 23:52:21 +00:00
|
|
|
|
protected ClockedChip()
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
|
|
|
|
public event EventHandler<EventArgs> Ticked;
|
2019-02-04 23:52:21 +00:00
|
|
|
|
|
2019-02-06 23:41:56 +00:00
|
|
|
|
public int Cycles { get; protected set; }
|
2019-02-04 23:52:21 +00:00
|
|
|
|
|
2019-02-02 15:12:51 +00:00
|
|
|
|
public void Tick(int extra)
|
|
|
|
|
{
|
2019-02-22 22:33:51 +00:00
|
|
|
|
for (var i = 0; i < extra; ++i)
|
2019-02-04 23:52:21 +00:00
|
|
|
|
{
|
|
|
|
|
this.Tick();
|
|
|
|
|
}
|
2019-02-02 15:12:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Tick()
|
|
|
|
|
{
|
2019-02-04 23:52:21 +00:00
|
|
|
|
++this.Cycles;
|
|
|
|
|
this.OnTicked();
|
2019-02-02 15:12:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 23:52:21 +00:00
|
|
|
|
protected virtual void OnTicked() => this.Ticked?.Invoke(this, EventArgs.Empty);
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
2019-02-04 23:52:21 +00:00
|
|
|
|
protected void ResetCycles() => this.Cycles = 0;
|
2019-02-02 15:12:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|