public static void ConditionalReturn(IWriteonlyRegister <ushort> pc, IStack stack, JumpCondition condition, IFlags flags) { if (ShouldJump(condition, flags)) { Return(pc, stack); } }
public static void Return(IWriteonlyRegister <ushort> pc, IStack stack) { var low = stack.Pop(); var high = stack.Pop(); Load(pc, BitUtils.Combine(low, high)); }
public static void ConditionalJump(IWriteonlyRegister <ushort> target, ushort address, JumpCondition condition, IFlags flags) { if (ShouldJump(condition, flags)) { Load(target, address); } }
public static void Pop(IWriteonlyRegister <ushort> target, IStack stack) { var low = stack.Pop(); var high = stack.Pop(); target.Value = BitUtils.Combine(low, high); }
// 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 void Load <T>(IWriteonlyRegister <T> target, T value) { target.Value = value; }