diff --git a/EightBit/TestHarness.cs b/EightBit/TestHarness.cs new file mode 100644 index 0000000..e07032e --- /dev/null +++ b/EightBit/TestHarness.cs @@ -0,0 +1,52 @@ +// +// Copyright (c) Adrian Conlon. All rights reserved. +// + +namespace EightBit +{ + using System.Diagnostics; + + public class TestHarness(TBus board, TProcessor cpu) where TBus : Bus where TProcessor : Processor + { + private readonly Stopwatch _timer = new(); + private readonly TBus _board = board; + private readonly TProcessor _cpu = cpu; + private long _totalCycles; + private TimeSpan _totalUserProcessorTime; + + public long ElapsedMilliseconds => this._timer.ElapsedMilliseconds; + + public float ElapsedSeconds => this.ElapsedMilliseconds / 1000.0f; + + public float CyclesPerSecond => this._totalCycles / this.ElapsedSeconds; + + public void Run() + { + using var process = Process.GetCurrentProcess(); + { + this._timer.Start(); + var startingUsage = process.UserProcessorTime; + + this._board.Initialize(); + this._board.RaisePOWER(); + + while (this._cpu.Powered) + { + this._totalCycles += this._cpu.Step(); + } + + var finishingUsage = process.UserProcessorTime; + this._timer.Stop(); + this._totalUserProcessorTime = finishingUsage - startingUsage; + } + + Console.Out.WriteLine(); + + Console.Out.WriteLine($"Guest cycles = {this._totalCycles:N0}"); + Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}"); + + Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz"); + Console.Out.WriteLine($"Processor time = {this._totalUserProcessorTime.TotalSeconds:g}"); + } + } +} diff --git a/Intel8080/Intel8080.Test/Program.cs b/Intel8080/Intel8080.Test/Program.cs index e5e4b10..fbaa125 100644 --- a/Intel8080/Intel8080.Test/Program.cs +++ b/Intel8080/Intel8080.Test/Program.cs @@ -14,7 +14,8 @@ namespace Intel8080.Test configuration.DebugMode = true; #endif - var harness = new TestHarness(configuration); + var board = new Board(configuration); + var harness = new EightBit.TestHarness(board, board.CPU); harness.Run(); } } diff --git a/Intel8080/Intel8080.Test/TestHarness.cs b/Intel8080/Intel8080.Test/TestHarness.cs deleted file mode 100644 index 46e8cc2..0000000 --- a/Intel8080/Intel8080.Test/TestHarness.cs +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (c) Adrian Conlon. All rights reserved. -// - -namespace Intel8080.Test -{ - using System.Diagnostics; - - internal class TestHarness(Configuration configuration) - { - private readonly Stopwatch timer = new(); - private readonly Board board = new(configuration); - private long totalCycles; - - 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(); - - System.Console.Out.WriteLine($"\n\nGuest cycles = {this.totalCycles}"); - System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}"); - } - } -} diff --git a/M6502/M6502.Test/Configuration.cs b/M6502/M6502.Test/Configuration.cs index 4606a9f..2a22c7a 100644 --- a/M6502/M6502.Test/Configuration.cs +++ b/M6502/M6502.Test/Configuration.cs @@ -10,7 +10,7 @@ namespace M6502.Test { public bool DebugMode { get; set; } - public bool Profile { get; set; }; + public bool Profile { get; set; } // Sudoku public string Program { get; } = "sudoku.65b"; diff --git a/M6502/M6502.Test/Program.cs b/M6502/M6502.Test/Program.cs index 898525c..70e8a67 100644 --- a/M6502/M6502.Test/Program.cs +++ b/M6502/M6502.Test/Program.cs @@ -13,7 +13,8 @@ namespace M6502.Test #if DEBUG configuration.DebugMode = false; #endif - var harness = new TestHarness(configuration); + var board = new Board(configuration); + var harness = new EightBit.TestHarness(board, board.CPU); harness.Run(); } } diff --git a/M6502/M6502.Test/TestHarness.cs b/M6502/M6502.Test/TestHarness.cs deleted file mode 100644 index cbda837..0000000 --- a/M6502/M6502.Test/TestHarness.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) Adrian Conlon. All rights reserved. -// - -namespace M6502.Test -{ - using System; - using System.Diagnostics; - - internal sealed class TestHarness(Configuration configuration) - { - private readonly Stopwatch timer = new(); - private readonly Board board = new(configuration); - private long totalCycles; - private TimeSpan totalUserProcessorTime; - - public long ElapsedMilliseconds => this.timer.ElapsedMilliseconds; - - public float ElapsedSeconds => this.ElapsedMilliseconds / 1000.0f; - - public float CyclesPerSecond => this.totalCycles / this.ElapsedSeconds; - - public void Run() - { - using var process = Process.GetCurrentProcess(); - { - this.timer.Start(); - var startingUsage = process.UserProcessorTime; - - this.board.Initialize(); - this.board.RaisePOWER(); - - var cpu = this.board.CPU; - while (cpu.Powered) - { - this.totalCycles += cpu.Step(); - } - - var finishingUsage = process.UserProcessorTime; - this.timer.Stop(); - this.totalUserProcessorTime = finishingUsage - startingUsage; - } - - System.Console.Out.WriteLine(); - - System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles:N0}"); - System.Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}"); - - System.Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz"); - System.Console.Out.WriteLine($"Processor time = {this.totalUserProcessorTime.TotalSeconds:g}"); - } - } -} diff --git a/Z80/Z80.FuseTest/Z80.FuseTest.csproj b/Z80/Z80.FuseTest/Z80.FuseTest.csproj index 23e44b6..de3102f 100644 --- a/Z80/Z80.FuseTest/Z80.FuseTest.csproj +++ b/Z80/Z80.FuseTest/Z80.FuseTest.csproj @@ -7,7 +7,7 @@ False False True - latest + latest-all Exe diff --git a/Z80/Z80.Test/Program.cs b/Z80/Z80.Test/Program.cs index 9670a44..20b55af 100644 --- a/Z80/Z80.Test/Program.cs +++ b/Z80/Z80.Test/Program.cs @@ -4,6 +4,8 @@ namespace Z80.Test { + using EightBit; + public static class Program { public static void Main(string[] args) @@ -14,10 +16,9 @@ namespace Z80.Test configuration.DebugMode = true; #endif - using (var harness = new TestHarness(configuration)) - { - harness.Run(); - } + var board = new Board(configuration); + var harness = new TestHarness(board, board.CPU); + harness.Run(); } } } diff --git a/Z80/Z80.Test/TestHarness.cs b/Z80/Z80.Test/TestHarness.cs deleted file mode 100644 index 13b3d3f..0000000 --- a/Z80/Z80.Test/TestHarness.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) Adrian Conlon. All rights reserved. -// - -namespace Z80.Test -{ - using System; - using System.Diagnostics; - - internal class TestHarness(Configuration configuration) - { - private readonly Stopwatch timer = new(); - private readonly Board board = new(configuration); - private long totalCycles; - private TimeSpan totalUserProcessorTime; - - public long ElapsedMilliseconds => timer.ElapsedMilliseconds; - - public float ElapsedSeconds => ElapsedMilliseconds / 1000.0f; - - public float CyclesPerSecond => totalCycles / ElapsedSeconds; - - public void Run() - { - using var process = Process.GetCurrentProcess(); - { - timer.Start(); - var startingUsage = process.UserProcessorTime; - - board.Initialize(); - board.RaisePOWER(); - - var cpu = board.CPU; - while (cpu.Powered) - { - totalCycles += cpu.Step(); - } - - var finishingUsage = process.UserProcessorTime; - timer.Stop(); - totalUserProcessorTime = finishingUsage - startingUsage; - } - - System.Console.Out.WriteLine(); - - System.Console.Out.WriteLine($"Guest cycles = {totalCycles:N0}"); - System.Console.Out.WriteLine($"Seconds = {ElapsedSeconds}"); - - System.Console.Out.WriteLine($"{CyclesPerSecond / 1000000} MHz"); - System.Console.Out.WriteLine($"Processor time = {totalUserProcessorTime.TotalSeconds:g}"); - } - } -}