2019-02-20 22:23:58 +00:00
|
|
|
|
// <copyright file="TestHarness.cs" company="Adrian Conlon">
|
|
|
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
|
|
|
// </copyright>
|
2019-02-19 00:58:17 +00:00
|
|
|
|
|
|
|
|
|
namespace Z80.Test
|
|
|
|
|
{
|
2019-02-20 22:23:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
internal class TestHarness : IDisposable
|
2019-02-19 00:58:17 +00:00
|
|
|
|
{
|
2019-02-20 22:23:58 +00:00
|
|
|
|
private readonly Stopwatch timer = new Stopwatch();
|
|
|
|
|
private readonly Board board;
|
|
|
|
|
private long totalCycles = 0;
|
|
|
|
|
|
|
|
|
|
private bool disposed = false;
|
|
|
|
|
|
2019-02-22 22:33:51 +00:00
|
|
|
|
public TestHarness(Configuration configuration) => this.board = new Board(configuration);
|
2019-02-20 22:23:58 +00:00
|
|
|
|
|
|
|
|
|
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.timer.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!this.disposed)
|
|
|
|
|
{
|
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
2019-02-21 01:11:07 +00:00
|
|
|
|
System.Console.Out.WriteLine($"\n\nGuest cycles = {this.totalCycles}");
|
2019-02-20 22:23:58 +00:00
|
|
|
|
System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.disposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-19 00:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|