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;
|
|
|
|
|
|
|
|
|
|
public class TestEvent
|
|
|
|
|
{
|
2019-07-20 19:20:25 +00:00
|
|
|
|
private int cycles;
|
|
|
|
|
|
|
|
|
|
public int Cycles => this.cycles;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
|
|
|
|
|
public string Specifier { get; private set; }
|
|
|
|
|
|
|
|
|
|
public ushort Address { get; private set; } = (ushort)EightBit.Mask.Mask16;
|
|
|
|
|
|
2019-07-20 18:17:08 +00:00
|
|
|
|
public byte Value { get; private set; } = (byte)EightBit.Mask.Mask8;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 08:28:49 +00:00
|
|
|
|
private bool TryParseLine(string line)
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
|
|
|
|
var split = line.Split(new char[] { ' ', '\t' });
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|