mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-04-26 01:18:04 +00:00
Modernise some more c# code
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
namespace M6502.HarteTest
|
||||
{
|
||||
internal class Checker
|
||||
using System.Diagnostics;
|
||||
|
||||
internal sealed class Checker
|
||||
{
|
||||
private TestRunner Runner { get; }
|
||||
|
||||
@@ -27,15 +29,14 @@
|
||||
public Checker(TestRunner runner)
|
||||
{
|
||||
this.Runner = runner;
|
||||
this.Disassembler = new EightBit.Disassembler(this.Runner, this.Runner.CPU, this.Symbols);
|
||||
this.Disassembler = new(this.Runner, this.Runner.CPU, this.Symbols);
|
||||
}
|
||||
|
||||
public void Check(Test test)
|
||||
{
|
||||
var cpu = this.Runner.CPU;
|
||||
|
||||
this.Messages.Clear();
|
||||
this.ActualCycles.Clear();
|
||||
this.Reset();
|
||||
|
||||
this.Runner.RaisePOWER();
|
||||
this.InitialiseState(test);
|
||||
@@ -52,7 +53,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.Invalid && this.Implemented)
|
||||
Debug.Assert(this.Implemented);
|
||||
if (this.Invalid)
|
||||
{
|
||||
this.AddDisassembly(pc);
|
||||
|
||||
@@ -79,6 +81,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
this.Messages.Clear();
|
||||
this.ActualCycles.Clear();
|
||||
|
||||
this.CycleCountMismatch = false;
|
||||
this.Cycles = 0;
|
||||
this.Valid = false;
|
||||
}
|
||||
|
||||
private bool Check(string what, ushort expected, ushort actual)
|
||||
{
|
||||
var success = actual == expected;
|
||||
@@ -143,34 +155,34 @@
|
||||
var cpu = this.Runner.CPU;
|
||||
var ram = this.Runner.RAM;
|
||||
|
||||
var expected_cycles = test.AvailableCycles() ?? throw new InvalidOperationException("Expected cycles cannot be null");
|
||||
var actual_cycles = this.ActualCycles;
|
||||
var expectedCycles = test.AvailableCycles();
|
||||
var actualCycles = this.ActualCycles;
|
||||
|
||||
var actual_idx = 0;
|
||||
foreach (var expected_cycle in expected_cycles) {
|
||||
var actualIDX = 0;
|
||||
foreach (var expectedCycle in expectedCycles) {
|
||||
|
||||
if (actual_idx >= actual_cycles.Count)
|
||||
if (actualIDX >= actualCycles.Count)
|
||||
{
|
||||
this.CycleCountMismatch = true;
|
||||
return false; // more expected cycles than actual
|
||||
}
|
||||
|
||||
var actual_cycle = actual_cycles[actual_idx++];
|
||||
var actualCycle = actualCycles[actualIDX++];
|
||||
|
||||
var expected_address = expected_cycle.Address;
|
||||
var actual_address = actual_cycle.Address;
|
||||
_ = this.Check("Cycle address", expected_address, actual_address);
|
||||
var expectedAddress = expectedCycle.Address;
|
||||
var actualAddress = actualCycle.Address;
|
||||
_ = this.Check("Cycle address", expectedAddress, actualAddress);
|
||||
|
||||
var expected_value = expected_cycle.Value;
|
||||
var actual_value = actual_cycle.Value;
|
||||
_ = this.Check("Cycle value", expected_value, actual_value);
|
||||
var expectedValue = expectedCycle.Value;
|
||||
var actualValue = actualCycle.Value;
|
||||
_ = this.Check("Cycle value", expectedValue, actualValue);
|
||||
|
||||
var expected_action = expected_cycle.Type;
|
||||
var actual_action = actual_cycle.Type;
|
||||
_ = this.Check("Cycle action", expected_action, actual_action);
|
||||
var expectedAction = expectedCycle.Type;
|
||||
var actualAction = actualCycle.Type;
|
||||
_ = this.Check("Cycle action", expectedAction, actualAction);
|
||||
}
|
||||
|
||||
if (actual_idx < actual_cycles.Count)
|
||||
if (actualIDX < actualCycles.Count)
|
||||
{
|
||||
this.CycleCountMismatch = true;
|
||||
return false; // less expected cycles than actual
|
||||
@@ -194,7 +206,7 @@
|
||||
throw new InvalidOperationException("Expected RAM cannot be null");
|
||||
}
|
||||
|
||||
var ram_problem = false;
|
||||
var ramProblem = false;
|
||||
foreach (var entry in final.RAM)
|
||||
{
|
||||
if (entry.Length != 2)
|
||||
@@ -205,17 +217,17 @@
|
||||
var address = (ushort)entry[0];
|
||||
var value = (byte)entry[1];
|
||||
|
||||
var ram_good = this.Check("RAM", address, value, ram.Peek(address));
|
||||
if (!ram_good && !ram_problem)
|
||||
var ramGood = this.Check("RAM", address, value, ram.Peek(address));
|
||||
if (!ramGood && !ramProblem)
|
||||
{
|
||||
ram_problem = true;
|
||||
ramProblem = true;
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
pc_good && s_good
|
||||
&& a_good && x_good && y_good && p_good
|
||||
&& !ram_problem;
|
||||
&& !ramProblem;
|
||||
}
|
||||
|
||||
private void Raise(string what, ushort expected, ushort actual) => this.Messages.Add($"{what}: expected: {expected:X4}, actual: {actual:X4}");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace M6502.HarteTest
|
||||
{
|
||||
public class Cycle
|
||||
public sealed class Cycle
|
||||
{
|
||||
public ushort Address { get; set; }
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
throw new ArgumentOutOfRangeException(nameof(input), input, "Cycles can only have three elements");
|
||||
}
|
||||
|
||||
this.Address = ((System.Text.Json.JsonElement)input[0]).GetUInt16();
|
||||
this.Value = ((System.Text.Json.JsonElement)input[1]).GetByte();
|
||||
this.Type = ((System.Text.Json.JsonElement)input[2]).GetString();
|
||||
this.Address = AsElement(input[0]).GetUInt16();
|
||||
this.Value = AsElement(input[1]).GetByte();
|
||||
this.Type = AsElement(input[2]).GetString();
|
||||
}
|
||||
|
||||
private static System.Text.Json.JsonElement AsElement(object part) => (System.Text.Json.JsonElement)part;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
internal class OpcodeTestSuite(string path) : IDisposable
|
||||
internal sealed class OpcodeTestSuite(string path) : IDisposable
|
||||
{
|
||||
private static readonly JsonSerializerOptions SerializerOptions = new()
|
||||
{
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
public IAsyncEnumerable<Test?> TestsAsync => JsonSerializer.DeserializeAsyncEnumerable<Test>(this.stream, SerializerOptions);
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.disposed)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace M6502.HarteTest
|
||||
{
|
||||
internal class ProcessorTestSuite(string location)
|
||||
internal sealed class ProcessorTestSuite(string location)
|
||||
{
|
||||
public string Location { get; set; } = location;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace M6502.HarteTest
|
||||
{
|
||||
public class State
|
||||
public sealed class State
|
||||
{
|
||||
public ushort PC { get; set; }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace M6502.HarteTest
|
||||
{
|
||||
public class Test
|
||||
public sealed class Test
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
@@ -22,15 +22,5 @@
|
||||
yield return new Cycle(cycle);
|
||||
}
|
||||
}
|
||||
|
||||
public Cycle CycleAt(int index)
|
||||
{
|
||||
if (this.Cycles == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cycles have not been initialised");
|
||||
}
|
||||
|
||||
return new Cycle(this.Cycles[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using EightBit;
|
||||
|
||||
internal class TestRunner : Bus
|
||||
internal sealed class TestRunner : Bus
|
||||
{
|
||||
public Ram RAM { get; } = new(0x10000);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
base.LowerPOWER();
|
||||
}
|
||||
|
||||
public override MemoryMapping Mapping(ushort absolute) => this.mapping;
|
||||
public override MemoryMapping Mapping(ushort _) => this.mapping;
|
||||
|
||||
public override void RaisePOWER()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user