2019-07-21 12:11:00 +00:00
|
|
|
|
// <copyright file="TestEvent.cs" company="Adrian Conlon">
|
|
|
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
namespace Fuse
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
|
|
|
|
using System;
|
2020-07-04 23:09:51 +00:00
|
|
|
|
using EightBit;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
|
|
|
|
|
public class TestEvent
|
|
|
|
|
{
|
2019-07-20 19:20:25 +00:00
|
|
|
|
private int cycles;
|
|
|
|
|
|
2019-08-14 21:38:47 +00:00
|
|
|
|
public TestEvent()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TestEvent(int cycles, string specifier, ushort address, byte value)
|
|
|
|
|
{
|
|
|
|
|
this.cycles = cycles;
|
|
|
|
|
this.Specifier = specifier;
|
|
|
|
|
this.Address = address;
|
|
|
|
|
this.Value = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-04 23:09:51 +00:00
|
|
|
|
public TestEvent(int cycles, string specifier, ushort address)
|
|
|
|
|
: this(cycles, specifier, address, (byte)Mask.Eight) => this.ContentionEvent = true;
|
|
|
|
|
|
2019-07-20 19:20:25 +00:00
|
|
|
|
public int Cycles => this.cycles;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
|
|
|
|
|
public string Specifier { get; private set; }
|
|
|
|
|
|
2020-06-21 23:00:15 +00:00
|
|
|
|
public ushort Address { get; private set; } = (ushort)EightBit.Mask.Sixteen;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
|
2020-06-21 23:00:15 +00:00
|
|
|
|
public byte Value { get; private set; } = (byte)EightBit.Mask.Eight;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
|
2020-07-04 23:09:51 +00:00
|
|
|
|
private bool ContentionEvent { get; set; } = false;
|
|
|
|
|
|
2019-07-21 08:28:49 +00:00
|
|
|
|
public bool TryParse(Lines lines)
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
2019-07-21 08:10:45 +00:00
|
|
|
|
if (lines == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(lines));
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 08:28:49 +00:00
|
|
|
|
var returned = this.TryParseLine(lines.ReadLine());
|
|
|
|
|
if (!returned)
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
2019-07-20 18:17:08 +00:00
|
|
|
|
lines.UnreadLine();
|
2019-07-19 22:59:32 +00:00
|
|
|
|
}
|
2019-07-21 08:28:49 +00:00
|
|
|
|
|
|
|
|
|
return returned;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-04 23:09:51 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
var possible = $"Cycles = {this.Cycles}, Specifier = {this.Specifier}, Address = {this.Address:X4}";
|
|
|
|
|
if (!this.ContentionEvent)
|
|
|
|
|
{
|
|
|
|
|
possible += $", Value = {this.Value:X2}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return possible;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 08:28:49 +00:00
|
|
|
|
private bool TryParseLine(string line)
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
2019-08-13 21:24:04 +00:00
|
|
|
|
var split = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
2019-07-21 08:28:49 +00:00
|
|
|
|
return this.TryParseLine(split);
|
2019-07-19 22:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 08:28:49 +00:00
|
|
|
|
private bool TryParseLine(string[] tokens)
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
2019-07-21 08:28:49 +00:00
|
|
|
|
if (!int.TryParse(tokens[0], out this.cycles))
|
2019-07-20 19:20:25 +00:00
|
|
|
|
{
|
2019-07-21 08:28:49 +00:00
|
|
|
|
return false;
|
2019-07-20 19:20:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 22:59:32 +00:00
|
|
|
|
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:
|
2019-07-21 08:28:49 +00:00
|
|
|
|
return false;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
}
|
2019-07-21 08:28:49 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|