mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2024-12-25 00:31:13 +00:00
999bdf71ff
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
// <copyright file="TestHarness.cs" company="Adrian Conlon">
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
// </copyright>
|
|
|
|
namespace M6502.Test
|
|
{
|
|
using System;
|
|
using System.Diagnostics;
|
|
|
|
internal class TestHarness : IDisposable
|
|
{
|
|
private readonly Stopwatch timer = new Stopwatch();
|
|
private readonly Board board;
|
|
private long totalCycles = 0;
|
|
private long instructions = 0;
|
|
|
|
private bool disposed = false;
|
|
|
|
public TestHarness(Configuration configuration)
|
|
{
|
|
this.board = new Board(configuration);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
this.Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
public void Run()
|
|
{
|
|
this.board.Initialize();
|
|
this.board.RaisePOWER();
|
|
|
|
var cpu = this.board.CPU;
|
|
|
|
this.timer.Start();
|
|
while (cpu.Powered)
|
|
{
|
|
this.totalCycles += cpu.Step();
|
|
++this.instructions;
|
|
}
|
|
|
|
this.timer.Stop();
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!this.disposed)
|
|
{
|
|
if (disposing)
|
|
{
|
|
System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles}");
|
|
System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}");
|
|
}
|
|
|
|
this.disposed = true;
|
|
}
|
|
}
|
|
}
|
|
}
|