public static void Compare(IReadonlyRegister <byte> target, byte operand, IFlags flags) { flags.Zero = target.Value == operand; flags.Subtract = true; flags.Carry = target.Value < operand; flags.HalfCarry = (target.Value & 0xF) < (operand & 0xF); }
// Used for LDHL SP, e and ADD SP, e public static void LoadWithSignedOffset(IWriteonlyRegister <ushort> target, IReadonlyRegister <ushort> source, sbyte offset, IFlags flags) { var old = source.Value; target.Value = (ushort)(source.Value + offset); flags.Zero = false; flags.Subtract = false; flags.Carry = (old & 0xFF) + (offset & 0xFF) >= 0x100; flags.HalfCarry = (old & 0xF) + (offset & 0xF) >= 0x10; }
public static bool GetBit(this IReadonlyRegister <ushort> s, int index) => s.Value.GetBit(index);
// Aliases public static bool GetBit(this IReadonlyRegister <byte> b, int index) => b.Value.GetBit(index);
public static void TestBit(IReadonlyRegister <byte> source, int index, IFlags flags) { flags.Zero = !source.GetBit(index); flags.Subtract = false; flags.HalfCarry = true; }