/// <summary> /// Resources the specified code. /// </summary> /// <param name="opcode">The opcode.</param> /// <param name="memory">The memory.</param> /// <returns>The number of ticks the operation took to complete.</returns> public static int Res(Opcode opcode, GbMemory memory) { if (opcode.Src != 6) { memory.R.SetR8(opcode.Src, memory.R.GetR8(opcode.Src).Res(opcode.Dest)); return(1); } memory.WriteCycleHl(memory.ReadCycleHl().Res(opcode.Dest)); return(3); }
/// <summary> /// Sets the dest bit of the src byte to true /// </summary> /// <param name="opcode">The opcode.</param> /// <param name="memory">The memory.</param> /// <returns>The number of ticks the operation took to complete.</returns> /// <remarks>Affected Flags: None.</remarks> public static int Set(Opcode opcode, GbMemory memory) { if (opcode.Src != 6) { memory.R.SetR8(opcode.Src, (byte)(memory.R.GetR8(opcode.Src) | (1 << opcode.Dest))); return(1); } memory.WriteCycleHl((byte)(memory.ReadCycleHl() | (1 << opcode.Dest))); return(3); }
/// <summary> /// Checks if the dest bit of the src register is true. /// </summary> /// <param name="code">The code.</param> /// <param name="memory">The memory.</param> /// <returns>The number of ticks the operation took to complete.</returns> public static int Bit(Opcode code, GbMemory memory) { if (code.Src != 6) { memory.R.F = (byte)(memory.R.F.AssignBit(RFlags.ZF, !memory.R.GetR8(code.Src).GetBit(code.Dest)) .Res(RFlags.NF) | RFlags.HB); return(1); } memory.R.F = (byte)(memory.R.F.AssignBit(RFlags.ZF, !memory.ReadCycleHl().GetBit(code.Dest)) .Res(RFlags.NF) | RFlags.HB); return(2); }
/// <summary> /// A framework for calling bitwise operation instructions. /// </summary> /// <param name="op">The op.</param> /// <param name="memory">The memory.</param> /// <param name="operation">The operation.</param> /// <exception cref="ArgumentNullException"><paramref name="operation"/> is null</exception> internal static int BitOpFunc(Opcode op, GbMemory memory, BitOp operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } if (op.Src != 6) { memory.R.SetR8(op.Src, operation(memory, memory.R.GetR8(op.Src))); return(1); } memory.WriteCycleHl(operation(memory, memory.ReadCycleHl())); return(3); }
/// <summary> /// A framework for calling arithmetic operation instructions. /// </summary> /// <param name="op">The op.</param> /// <param name="memory">The memory.</param> /// <param name="operation">The operation.</param> /// <exception cref="ArgumentNullException"><paramref name="operation"/> is null</exception> internal static int ArithOp8Func(Opcode op, GbMemory memory, ArithOp8 operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } if (op.Src != 6 && op.Src != 8) { operation(memory, memory.R.GetR8(op.Src)); return(1); } operation(memory, op.Src == 6 ? memory.ReadCycleHl() : memory.ReadCycleI8()); return(2); }
public static int Ld8(Opcode op, GbMemory memory) { if (op.Src == 6 || op.Dest == 6) { if (op.Src == op.Dest) // By math logic, these are both 6 if this is true. { throw new InvalidOperationException("Opcode with dest = 6 and src = 6 is invalid for this instruction."); } if (op.Src == 6) { memory.R.SetR8(op.Dest, memory.ReadCycleHl()); } else { memory.WriteCycle(memory.R.Hl, memory.R.GetR8(op.Src)); } return(2); } memory.R.SetR8(op.Dest, memory.R.GetR8(op.Src)); return(1); }