2019-02-14 23:01:31 +00:00
|
|
|
|
// <copyright file="Register16.cs" company="Adrian Conlon">
|
|
|
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
|
namespace EightBit
|
|
|
|
|
{
|
2019-02-20 22:17:54 +00:00
|
|
|
|
using System.Diagnostics;
|
2019-02-14 23:01:31 +00:00
|
|
|
|
|
2019-02-20 22:17:54 +00:00
|
|
|
|
[DebuggerDisplay("Word = {Word}")]
|
2019-02-21 19:58:49 +00:00
|
|
|
|
public class Register16
|
2019-02-14 23:01:31 +00:00
|
|
|
|
{
|
2019-04-10 18:51:39 +00:00
|
|
|
|
private byte low;
|
|
|
|
|
private byte high;
|
|
|
|
|
|
2019-02-14 23:01:31 +00:00
|
|
|
|
public Register16(byte low, byte high)
|
|
|
|
|
{
|
|
|
|
|
this.Low = low;
|
|
|
|
|
this.High = high;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Register16(ushort value)
|
|
|
|
|
{
|
2019-02-18 22:28:20 +00:00
|
|
|
|
this.Low = Chip.LowByte(value);
|
|
|
|
|
this.High = Chip.HighByte(value);
|
2019-02-14 23:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 19:58:49 +00:00
|
|
|
|
public Register16()
|
|
|
|
|
: this((ushort)0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 23:01:31 +00:00
|
|
|
|
public Register16(int value)
|
|
|
|
|
: this((ushort)value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-10 18:51:39 +00:00
|
|
|
|
public Register16(uint value)
|
|
|
|
|
: this((ushort)value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 23:01:31 +00:00
|
|
|
|
public Register16(byte low)
|
|
|
|
|
: this(low, 0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Register16(Register16 rhs)
|
|
|
|
|
{
|
2019-02-18 22:28:20 +00:00
|
|
|
|
this.Low = rhs.Low;
|
|
|
|
|
this.High = rhs.High;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ushort Word
|
|
|
|
|
{
|
2019-06-30 23:15:25 +00:00
|
|
|
|
get => Chip.MakeWord(this.Low, this.High);
|
2019-02-18 22:28:20 +00:00
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.Low = Chip.LowByte(value);
|
|
|
|
|
this.High = Chip.HighByte(value);
|
|
|
|
|
}
|
2019-02-14 23:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-10 18:51:39 +00:00
|
|
|
|
public ref byte Low => ref this.low;
|
2019-02-21 19:58:49 +00:00
|
|
|
|
|
2019-04-10 18:51:39 +00:00
|
|
|
|
public ref byte High => ref this.high;
|
2019-02-21 19:58:49 +00:00
|
|
|
|
|
2019-02-14 23:51:32 +00:00
|
|
|
|
public static bool operator ==(Register16 left, Register16 right) => left.Equals(right);
|
2019-02-14 23:01:31 +00:00
|
|
|
|
|
2019-02-14 23:51:32 +00:00
|
|
|
|
public static bool operator !=(Register16 left, Register16 right) => !(left == right);
|
2019-02-14 23:01:31 +00:00
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2019-02-21 19:58:49 +00:00
|
|
|
|
var rhs = obj as Register16;
|
2019-02-22 22:33:51 +00:00
|
|
|
|
return rhs == null ? false : rhs.Low == this.Low && rhs.High == this.High;
|
2019-02-14 23:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 23:51:32 +00:00
|
|
|
|
public override int GetHashCode() => this.Word;
|
2019-02-14 23:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|