2019-07-19 22:59:32 +00:00
|
|
|
|
namespace Fuse
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-07-21 08:10:45 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Globalization;
|
2019-07-19 22:59:32 +00:00
|
|
|
|
using EightBit;
|
|
|
|
|
|
|
|
|
|
public class RegisterState
|
|
|
|
|
{
|
2019-07-21 08:10:45 +00:00
|
|
|
|
private readonly List<Register16> registers = new List<Register16>();
|
|
|
|
|
|
|
|
|
|
public ReadOnlyCollection<Register16> Registers => this.registers.AsReadOnly();
|
|
|
|
|
|
2019-07-19 22:59:32 +00:00
|
|
|
|
public bool Halted { get; private set; } = false;
|
2019-07-21 08:10:45 +00:00
|
|
|
|
|
2019-07-19 22:59:32 +00:00
|
|
|
|
public int TStates { get; private set; } = -1;
|
|
|
|
|
|
2019-07-20 18:17:08 +00:00
|
|
|
|
public void Parse(Lines lines)
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
2019-07-20 18:17:08 +00:00
|
|
|
|
this.ParseExternalState(lines);
|
|
|
|
|
this.ParseInternalState(lines);
|
2019-07-19 22:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 18:17:08 +00:00
|
|
|
|
private void ParseInternalState(Lines lines) => this.ParseInternalState(lines.ReadLine());
|
|
|
|
|
|
|
|
|
|
private void ParseInternalState(string line)
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
|
|
|
|
var tokens = line.Split(new char[] { ' ', '\t' });
|
2019-07-20 18:17:08 +00:00
|
|
|
|
this.ParseInternalState(tokens);
|
|
|
|
|
}
|
2019-07-19 22:59:32 +00:00
|
|
|
|
|
2019-07-20 18:17:08 +00:00
|
|
|
|
private void ParseInternalState(string[] tokens)
|
|
|
|
|
{
|
2019-07-21 08:10:45 +00:00
|
|
|
|
this.Halted = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture) == 1;
|
|
|
|
|
this.TStates = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture);
|
2019-07-19 22:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 18:17:08 +00:00
|
|
|
|
private void ParseExternalState(Lines lines)
|
2019-07-19 22:59:32 +00:00
|
|
|
|
{
|
2019-07-20 18:17:08 +00:00
|
|
|
|
var line = lines.ReadLine();
|
2019-07-19 22:59:32 +00:00
|
|
|
|
foreach (var token in line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
|
|
|
|
|
{
|
2019-07-21 08:10:45 +00:00
|
|
|
|
this.registers.Add(new Register16(Convert.ToUInt16(token, 16)));
|
2019-07-19 22:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|