mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-04-21 12:16:55 +00:00
Refactor non-CPU specific parts of the LR35902 fuse test code into it's own library
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{28E65032-5DFF-406F-9385-0EE1422A7F4A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Fuse</RootNamespace>
|
||||
<AssemblyName>Fuse</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Lines.cs" />
|
||||
<Compile Include="MemoryDatum.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RegisterState.cs" />
|
||||
<Compile Include="Result.cs" />
|
||||
<Compile Include="Results.cs" />
|
||||
<Compile Include="Test.cs" />
|
||||
<Compile Include="TestEvent.cs" />
|
||||
<Compile Include="TestEvents.cs" />
|
||||
<Compile Include="Tests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="stylecop.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EightBit\EightBit.csproj">
|
||||
<Project>{6ebf8857-62a3-4ef4-af21-c1844031d7e4}</Project>
|
||||
<Name>EightBit</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,56 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public class Lines
|
||||
{
|
||||
private readonly string path;
|
||||
private readonly List<string> lines = new List<string>();
|
||||
private int position = -1;
|
||||
|
||||
public Lines(string path) => this.path = path;
|
||||
|
||||
public bool EndOfFile => this.position == this.lines.Count;
|
||||
|
||||
public void Read()
|
||||
{
|
||||
using (var reader = File.OpenText(this.path))
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
var ignored = line.StartsWith(";", StringComparison.OrdinalIgnoreCase);
|
||||
if (!ignored)
|
||||
{
|
||||
this.lines.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Users should check EndOfFile before using a bad position...
|
||||
this.position = 0;
|
||||
}
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.PeekLine();
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Increment();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnreadLine() => this.Decrement();
|
||||
|
||||
public string PeekLine() => this.lines[this.position];
|
||||
|
||||
private void Increment() => ++this.position;
|
||||
|
||||
private void Decrement() => --this.position;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
public class MemoryDatum
|
||||
{
|
||||
private readonly List<byte> bytes = new List<byte>();
|
||||
|
||||
public ushort Address { get; private set; } = (ushort)EightBit.Mask.Mask16;
|
||||
|
||||
public ReadOnlyCollection<byte> Bytes => this.bytes.AsReadOnly();
|
||||
|
||||
public void Parse(string line)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(line));
|
||||
}
|
||||
|
||||
var tokens = line.Split(new char[] { ' ', '\t' });
|
||||
this.Parse(tokens);
|
||||
}
|
||||
|
||||
public void Parse(string[] tokens)
|
||||
{
|
||||
if (tokens == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tokens));
|
||||
}
|
||||
|
||||
this.Address = Convert.ToUInt16(tokens[0], 16);
|
||||
|
||||
var finished = false;
|
||||
for (var i = 1; !finished && (i < tokens.Length); ++i)
|
||||
{
|
||||
var token = tokens[i];
|
||||
finished = token == "-1";
|
||||
if (!finished)
|
||||
{
|
||||
this.bytes.Add(Convert.ToByte(token, 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Fuse")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Fuse")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("28e65032-5dff-406f-9385-0ee1422a7f4a")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,48 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using EightBit;
|
||||
|
||||
public class RegisterState
|
||||
{
|
||||
private readonly List<Register16> registers = new List<Register16>();
|
||||
|
||||
public ReadOnlyCollection<Register16> Registers => this.registers.AsReadOnly();
|
||||
|
||||
public bool Halted { get; private set; } = false;
|
||||
|
||||
public int TStates { get; private set; } = -1;
|
||||
|
||||
public void Parse(Lines lines)
|
||||
{
|
||||
this.ParseExternalState(lines);
|
||||
this.ParseInternalState(lines);
|
||||
}
|
||||
|
||||
private void ParseInternalState(Lines lines) => this.ParseInternalState(lines.ReadLine());
|
||||
|
||||
private void ParseInternalState(string line)
|
||||
{
|
||||
var tokens = line.Split(new char[] { ' ', '\t' });
|
||||
this.ParseInternalState(tokens);
|
||||
}
|
||||
|
||||
private void ParseInternalState(string[] tokens)
|
||||
{
|
||||
this.Halted = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture) == 1;
|
||||
this.TStates = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private void ParseExternalState(Lines lines)
|
||||
{
|
||||
var line = lines.ReadLine();
|
||||
foreach (var token in line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
this.registers.Add(new Register16(Convert.ToUInt16(token, 16)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
public class Result
|
||||
{
|
||||
private readonly TestEvents events = new TestEvents();
|
||||
private readonly List<MemoryDatum> memoryData = new List<MemoryDatum>();
|
||||
|
||||
public string Description { get; private set; }
|
||||
|
||||
public RegisterState RegisterState { get; } = new RegisterState();
|
||||
|
||||
public ReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
|
||||
|
||||
public bool TryParse(Lines lines)
|
||||
{
|
||||
if (lines == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(lines));
|
||||
}
|
||||
|
||||
while (!lines.EndOfFile && string.IsNullOrWhiteSpace(this.Description))
|
||||
{
|
||||
this.Description = lines.ReadLine();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(this.Description))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.events.Parse(lines);
|
||||
this.RegisterState.Parse(lines);
|
||||
|
||||
var finished = false;
|
||||
do
|
||||
{
|
||||
var line = lines.ReadLine();
|
||||
finished = string.IsNullOrWhiteSpace(line);
|
||||
if (!finished)
|
||||
{
|
||||
var datum = new MemoryDatum();
|
||||
datum.Parse(line);
|
||||
this.memoryData.Add(datum);
|
||||
}
|
||||
}
|
||||
while (!finished);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Results
|
||||
{
|
||||
private readonly Lines lines;
|
||||
|
||||
public Dictionary<string, Result> Container { get; } = new Dictionary<string, Result>();
|
||||
|
||||
public Results(string path) => this.lines = new Lines(path);
|
||||
|
||||
public void Read() => this.lines.Read();
|
||||
|
||||
public void Parse()
|
||||
{
|
||||
while (!this.lines.EndOfFile)
|
||||
{
|
||||
var result = new Result();
|
||||
if (result.TryParse(this.lines))
|
||||
{
|
||||
this.Container.Add(result.Description, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Test
|
||||
{
|
||||
private readonly List<MemoryDatum> memoryData = new List<MemoryDatum>();
|
||||
|
||||
public string Description { get; private set; }
|
||||
|
||||
public RegisterState RegisterState { get; } = new RegisterState();
|
||||
|
||||
public IReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
|
||||
|
||||
public bool TryParse(Lines lines)
|
||||
{
|
||||
if (lines == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(lines));
|
||||
}
|
||||
|
||||
while (!lines.EndOfFile && string.IsNullOrEmpty(this.Description))
|
||||
{
|
||||
this.Description = lines.ReadLine();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(this.Description))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.RegisterState.Parse(lines);
|
||||
|
||||
var finished = false;
|
||||
do
|
||||
{
|
||||
var line = lines.ReadLine();
|
||||
finished = line == "-1";
|
||||
if (!finished)
|
||||
{
|
||||
var datum = new MemoryDatum();
|
||||
datum.Parse(line);
|
||||
this.memoryData.Add(datum);
|
||||
}
|
||||
}
|
||||
while (!finished);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
public class TestEvent
|
||||
{
|
||||
private int cycles;
|
||||
|
||||
public int Cycles => this.cycles;
|
||||
|
||||
public string Specifier { get; private set; }
|
||||
|
||||
public ushort Address { get; private set; } = (ushort)EightBit.Mask.Mask16;
|
||||
|
||||
public byte Value { get; private set; } = (byte)EightBit.Mask.Mask8;
|
||||
|
||||
public bool TryParse(Lines lines)
|
||||
{
|
||||
if (lines == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(lines));
|
||||
}
|
||||
|
||||
var returned = this.TryParseLine(lines.ReadLine());
|
||||
if (!returned)
|
||||
{
|
||||
lines.UnreadLine();
|
||||
}
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
private bool TryParseLine(string line)
|
||||
{
|
||||
var split = line.Split(new char[] { ' ', '\t' });
|
||||
return this.TryParseLine(split);
|
||||
}
|
||||
|
||||
private bool TryParseLine(string[] tokens)
|
||||
{
|
||||
if (!int.TryParse(tokens[0], out this.cycles))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.Specifier = tokens[1];
|
||||
|
||||
switch (this.Specifier)
|
||||
{
|
||||
case "MR":
|
||||
case "MW":
|
||||
this.Address = Convert.ToUInt16(tokens[2], 16);
|
||||
this.Value = Convert.ToByte(tokens[3], 16);
|
||||
break;
|
||||
|
||||
case "MC":
|
||||
case "PC":
|
||||
this.Address = Convert.ToUInt16(tokens[2], 16);
|
||||
break;
|
||||
|
||||
case "PR":
|
||||
case "PW":
|
||||
this.Address = Convert.ToUInt16(tokens[2], 16);
|
||||
this.Value = Convert.ToByte(tokens[3], 16);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
public class TestEvents
|
||||
{
|
||||
private readonly List<TestEvent> container = new List<TestEvent>();
|
||||
|
||||
public ReadOnlyCollection<TestEvent> Container => this.container.AsReadOnly();
|
||||
|
||||
public void Parse(Lines lines)
|
||||
{
|
||||
var success = false;
|
||||
do
|
||||
{
|
||||
var e = new TestEvent();
|
||||
success = e.TryParse(lines);
|
||||
if (success)
|
||||
{
|
||||
this.container.Add(e);
|
||||
}
|
||||
}
|
||||
while (success);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Fuse
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Tests
|
||||
{
|
||||
private readonly Lines lines;
|
||||
|
||||
public Dictionary<string, Test> Container { get; } = new Dictionary<string, Test>();
|
||||
|
||||
public Tests(string path) => this.lines = new Lines(path);
|
||||
|
||||
public void Read() => this.lines.Read();
|
||||
|
||||
public void Parse()
|
||||
{
|
||||
while (!this.lines.EndOfFile)
|
||||
{
|
||||
var test = new Test();
|
||||
if (test.TryParse(this.lines))
|
||||
{
|
||||
this.Container.Add(test.Description, test);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
// ACTION REQUIRED: This file was automatically added to your project, but it
|
||||
// will not take effect until additional steps are taken to enable it. See the
|
||||
// following page for additional information:
|
||||
//
|
||||
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
|
||||
|
||||
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
|
||||
"settings": {
|
||||
"documentationRules": {
|
||||
"documentInterfaces": false,
|
||||
"documentExposedElements": false,
|
||||
"documentInternalElements": false,
|
||||
"documentPrivateElements": false,
|
||||
"documentPrivateFields": false,
|
||||
"companyName": "Adrian Conlon"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user