2019-07-19 22:59:32 +00:00
|
|
|
|
namespace Fuse
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using EightBit;
|
|
|
|
|
|
|
|
|
|
public class RegisterState
|
|
|
|
|
{
|
|
|
|
|
public enum Register
|
|
|
|
|
{
|
|
|
|
|
AF, BC, DE, HL, SP, PC
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public List<Register16> Registers { get; } = new List<Register16>();
|
|
|
|
|
public bool Halted { get; private set; } = false;
|
|
|
|
|
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-19 22:59:32 +00:00
|
|
|
|
this.Halted = Convert.ToInt32(tokens[0]) == 1;
|
|
|
|
|
this.TStates = Convert.ToInt32(tokens[1]);
|
|
|
|
|
}
|
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
this.Registers.Add(new Register16(Convert.ToUInt16(token, 16)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|