2019-02-16 21:32:34 +00:00
|
|
|
|
namespace EightBit
|
|
|
|
|
{
|
|
|
|
|
public struct RefreshRegister
|
|
|
|
|
{
|
|
|
|
|
private readonly byte high;
|
|
|
|
|
private byte variable;
|
|
|
|
|
|
|
|
|
|
public RefreshRegister(byte value)
|
|
|
|
|
{
|
|
|
|
|
this.high = (byte)(value & (byte)Bits.Bit7);
|
|
|
|
|
this.variable = (byte)(value & (byte)Mask.Mask7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator byte(RefreshRegister input)
|
|
|
|
|
{
|
|
|
|
|
return ToByte(input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator RefreshRegister(byte input)
|
|
|
|
|
{
|
|
|
|
|
return FromByte(input);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 00:56:16 +00:00
|
|
|
|
public static RefreshRegister operator ++(RefreshRegister value) => Increment(value);
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(RefreshRegister left, RefreshRegister right) => left.Equals(right);
|
|
|
|
|
|
|
|
|
|
public static bool operator !=(RefreshRegister left, RefreshRegister right) => !(left == right);
|
|
|
|
|
|
2019-02-16 21:32:34 +00:00
|
|
|
|
public static byte ToByte(RefreshRegister input)
|
|
|
|
|
{
|
2019-02-20 23:51:50 +00:00
|
|
|
|
return (byte)((input.high << 7) | (input.variable & (byte)Mask.Mask7));
|
2019-02-16 21:32:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static RefreshRegister FromByte(byte input)
|
|
|
|
|
{
|
|
|
|
|
return new RefreshRegister(input);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-20 22:23:29 +00:00
|
|
|
|
public byte ToByte()
|
|
|
|
|
{
|
|
|
|
|
return ToByte(this);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-16 21:32:34 +00:00
|
|
|
|
public static RefreshRegister Increment(RefreshRegister value)
|
|
|
|
|
{
|
|
|
|
|
++value.variable;
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (!(obj is RefreshRegister))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rhs = (RefreshRegister)obj;
|
|
|
|
|
return rhs.high == this.high && rhs.variable == this.variable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode() => this.high + this.variable;
|
|
|
|
|
}
|
|
|
|
|
}
|