2019-02-04 23:52:21 +00:00
|
|
|
|
// <copyright file="TestHarness.cs" company="Adrian Conlon">
|
|
|
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
2019-02-06 22:49:26 +00:00
|
|
|
|
namespace M6502.Test
|
2019-02-02 15:12:51 +00:00
|
|
|
|
{
|
2019-02-18 00:54:02 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
internal class TestHarness : IDisposable
|
2019-02-02 15:12:51 +00:00
|
|
|
|
{
|
2019-02-18 00:54:02 +00:00
|
|
|
|
private readonly Stopwatch timer = new Stopwatch();
|
|
|
|
|
private readonly Board board;
|
|
|
|
|
private long totalCycles = 0;
|
|
|
|
|
private long instructions = 0;
|
|
|
|
|
|
|
|
|
|
private bool disposed = false;
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
|
|
|
|
public TestHarness(Configuration configuration)
|
|
|
|
|
{
|
2019-02-04 23:52:21 +00:00
|
|
|
|
this.board = new Board(configuration);
|
2019-02-02 15:12:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-18 00:54:02 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
this.Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-02 15:12:51 +00:00
|
|
|
|
public void Run()
|
|
|
|
|
{
|
2019-02-04 23:52:21 +00:00
|
|
|
|
this.board.Initialize();
|
|
|
|
|
this.board.RaisePOWER();
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
2019-02-04 23:52:21 +00:00
|
|
|
|
var cpu = this.board.CPU;
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
2019-02-18 00:54:02 +00:00
|
|
|
|
this.timer.Start();
|
2019-02-02 15:12:51 +00:00
|
|
|
|
while (cpu.Powered)
|
2019-02-04 23:52:21 +00:00
|
|
|
|
{
|
2019-02-18 00:54:02 +00:00
|
|
|
|
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;
|
2019-02-04 23:52:21 +00:00
|
|
|
|
}
|
2019-02-02 15:12:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|