public static int LdA16Sp(Opcode op, GbMemory mem) { byte low = mem.ReadCycleI8(); byte high = mem.ReadCycleI8(); mem.WriteCycle(new GbUInt16(high, low), mem.R.Sp.LowByte); mem.WriteCycle((GbUInt16)(new GbUInt16(high, low) + 1), mem.R.Sp.HighByte); return(5); }
public static int LdR16(Opcode op, GbMemory mem) { if (op.Src == 8) { mem.WriteCycle((op.Dest == 2 || op.Dest == 3) ? mem.R.Hl : mem.R.GetR16Sp(op.Dest), mem.R.A); } else { mem.R.A = mem.ReadCycle((op.Src == 2 || op.Src == 3) ? mem.R.Hl : mem.R.GetR16Sp(op.Src)); } if (op.Src == 2 || op.Dest == 2) { mem.R.Hl++; } else if (op.Src == 3 || op.Dest == 3) { mem.R.Hl--; } else { // Do nothing. } return(2); }
public static int LdH(Opcode op, GbMemory mem) { if (op.Dest == 7) { mem.R.A = mem.ReadCycle(new GbUInt16(0xFF, mem.ReadCycleI8())); } else { mem.WriteCycle(new GbUInt16(0xFF, mem.ReadCycleI8()), mem.R.A); } return(3); }
public static int LdD8(Opcode op, GbMemory mem) { byte val = mem.ReadCycleI8(); if (op.Dest == 6) { mem.WriteCycle(mem.R.Hl, val); return(3); } mem.R.SetR8(op.Dest, val); return(2); }
public static int LdA16(Opcode op, GbMemory mem) { byte low = mem.ReadCycleI8(); byte high = mem.ReadCycleI8(); if (op.Dest == 7) { mem.R.A = mem.ReadCycle(new GbUInt16(high, low)); } else { mem.WriteCycle(new GbUInt16(high, low), mem.R.A); } return(4); }
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); }