2019-02-02 15:12:51 +00:00
|
|
|
|
namespace EightBit
|
|
|
|
|
{
|
|
|
|
|
public class Chip : Device
|
|
|
|
|
{
|
|
|
|
|
protected Chip() { }
|
|
|
|
|
|
2019-02-03 10:23:41 +00:00
|
|
|
|
public static byte SetFlag(byte input, byte flag) => (byte)(input | flag);
|
|
|
|
|
public static byte SetFlag(byte input, byte flag, int condition) => SetFlag(input, flag, condition != 0);
|
|
|
|
|
public static byte SetFlag(byte input, byte flag, bool condition) => condition ? SetFlag(input, flag) : ClearFlag(input, flag);
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
2019-02-03 10:23:41 +00:00
|
|
|
|
public static byte ClearFlag(byte input, byte flag) => (byte)(input & (byte)~flag);
|
|
|
|
|
public static byte ClearFlag(byte input, byte flag, int condition) => ClearFlag(input, flag, condition != 0);
|
|
|
|
|
public static byte ClearFlag(byte input, byte flag, bool condition) => SetFlag(input, flag, !condition);
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
2019-02-03 00:42:55 +00:00
|
|
|
|
public static byte HighByte(int value) => (byte)(value >> 8);
|
|
|
|
|
public static byte HighByte(ushort value) => HighByte((int)value);
|
|
|
|
|
public static byte LowByte(int value) => (byte)(value & (int)Mask.Mask8);
|
|
|
|
|
public static byte LowByte(ushort value) => LowByte((int)value);
|
|
|
|
|
public static ushort PromoteByte(byte value) => (ushort)(value << 8);
|
|
|
|
|
public static byte DemoteByte(ushort value) => HighByte(value);
|
|
|
|
|
public static ushort HigherPart(ushort value) => (ushort)(value & 0xff00);
|
|
|
|
|
public static byte LowerPart(ushort value) => LowByte(value);
|
|
|
|
|
|
|
|
|
|
static public ushort MakeWord(byte low, byte high) => (ushort)(PromoteByte(high) | low);
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
|
|
|
|
public static int HighNibble(byte value) => value >> 4;
|
|
|
|
|
public static int LowNibble(byte value) => value & 0xf;
|
|
|
|
|
|
|
|
|
|
public static int HigherNibble(byte value) => value & 0xf0;
|
|
|
|
|
public static int LowerNibble(byte value) => LowNibble(value);
|
|
|
|
|
|
2019-02-03 00:42:55 +00:00
|
|
|
|
public static int PromoteNibble(byte value) => LowByte(value << 4);
|
2019-02-02 15:12:51 +00:00
|
|
|
|
public static int DemoteNibble(byte value) => HighNibble(value);
|
|
|
|
|
}
|
|
|
|
|
}
|