EightBitNet/Fuse/AbstractRegisterState.cs
Adrian Conlon 9550ed57be Add a .net Fuse test suite for the Z80 core (one "unexpected" result).
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
2019-08-13 22:24:04 +01:00

49 lines
1.6 KiB
C#

// <copyright file="AbstractRegisterState.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using EightBit;
public abstract class AbstractRegisterState
{
private readonly List<Register16> registers = new List<Register16>();
public ReadOnlyCollection<Register16> Registers => this.MutableRegisters.AsReadOnly();
public bool Halted { get; protected set; } = false;
public int TStates { get; protected set; } = -1;
protected List<Register16> MutableRegisters => this.registers;
public void Parse(Lines lines)
{
this.ParseExternalState(lines);
this.ParseInternalState(lines);
}
protected void ParseInternalState(Lines lines) => this.ParseInternalState(lines.ReadLine());
protected virtual void ParseInternalState(string line)
{
var tokens = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
this.ParseInternalState(tokens);
}
protected abstract void ParseInternalState(string[] tokens);
protected virtual 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)));
}
}
}
}