2019-02-21 19:58:49 +00:00
|
|
|
|
// <copyright file="RefreshRegister.cs" company="Adrian Conlon">
|
|
|
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
|
namespace EightBit
|
2019-02-16 21:32:34 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-22 22:33:51 +00:00
|
|
|
|
public static implicit operator byte(RefreshRegister input) => ToByte(input);
|
2019-02-16 21:32:34 +00:00
|
|
|
|
|
2019-02-22 22:33:51 +00:00
|
|
|
|
public static implicit operator RefreshRegister(byte input) => FromByte(input);
|
2019-02-16 21:32:34 +00:00
|
|
|
|
|
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-08-14 07:31:19 +00:00
|
|
|
|
public static byte ToByte(RefreshRegister input) => (byte)(input.high | (input.variable & (byte)Mask.Mask7));
|
2019-02-16 21:32:34 +00:00
|
|
|
|
|
2019-02-21 00:01:36 +00:00
|
|
|
|
public static RefreshRegister Increment(RefreshRegister value)
|
|
|
|
|
{
|
|
|
|
|
++value.variable;
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-22 22:33:51 +00:00
|
|
|
|
public static RefreshRegister FromByte(byte input) => new RefreshRegister(input);
|
2019-02-16 21:32:34 +00:00
|
|
|
|
|
2019-02-22 22:33:51 +00:00
|
|
|
|
public byte ToByte() => ToByte(this);
|
2019-02-20 22:23:29 +00:00
|
|
|
|
|
2019-02-16 21:32:34 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|