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