/// <summary> /// Reads the value of a 16bit shadow register /// </summary> /// <param name="register"></param> /// <returns></returns> public ushort Read(Reg16Shadow register) { var highOrderByte = default(byte); var lowOrderByte = default(byte); switch (register) { case Reg16Shadow.AF: highOrderByte = A2; lowOrderByte = F2; break; case Reg16Shadow.BC: highOrderByte = B2; lowOrderByte = C2; break; case Reg16Shadow.DE: highOrderByte = D2; lowOrderByte = E2; break; case Reg16Shadow.HL: highOrderByte = H2; lowOrderByte = L2; break; default: throw new Exception("Unknown register " + register); } return(MakeWord(highOrderByte, lowOrderByte)); }
/// <summary> /// Sets the value into a 16bit shadow register /// </summary> /// <param name="register"></param> /// <param name="word"></param> public void Set(Reg16Shadow register, ushort word) { var(highOrderByte, lowOrderByte) = word.Split(); switch (register) { case Reg16Shadow.AF: A2 = highOrderByte; F2 = lowOrderByte; break; case Reg16Shadow.BC: B2 = highOrderByte; C2 = lowOrderByte; break; case Reg16Shadow.DE: D2 = highOrderByte; E2 = lowOrderByte; break; case Reg16Shadow.HL: H2 = highOrderByte; L2 = lowOrderByte; break; default: throw new Exception("Unknown register " + register); } }
public void IsShouldBePossibleToWriteAndReadFromEvery16BitShadowRegister(Reg16Shadow register) { var ANY_VALUE = (ushort)0xABCD; var machine = new Machine(); machine.Registers.Set(register, ANY_VALUE); Assert.Equal(ANY_VALUE, machine.Registers.Read(register)); }
public void EXShouldErrorIfGivenAnyShadowRegisterOtherThanAF(Reg16Shadow register) { var machine = new Machine(); machine.Registers.Set(Reg16.AF, 0x1000); machine.Registers.Set(register, 0x2000); var exception = Record.Exception(() => machine.EX(Reg16.AF, register)); Assert.IsType(typeof(System.InvalidOperationException), exception); }
public void EXXShouldSwapARegisterWithItsShadow(Reg16 register, Reg16Shadow shadow) { var machine = new Machine(); machine.Registers.Set(register, 0xAAAA); machine.Registers.Set(shadow, 0xBBBB); machine.EXX(); Assert.Equal(0xAAAA, machine.Registers.Read(shadow)); Assert.Equal(0xBBBB, machine.Registers.Read(register)); }
/// <summary> /// Usage: Exchanges the register AF with its shadow register /// Flags: Yes as this is the F register /// </summary> /// <param name="operand1"></param> /// <param name="operand2"></param> public void EX(Reg16 operand1, Reg16Shadow operand2) { if (operand1 != Reg16.AF) { throw new InvalidOperationException("The only register supported is AF"); } if (operand2 != Reg16Shadow.AF) { throw new InvalidOperationException("The only shadow register supported is AF"); } var valueForOperand1 = this.Registers.Read(operand1); var valueForOperand2 = this.Registers.Read(operand2); this.Registers.Set(operand2, valueForOperand1); this.Registers.Set(operand1, valueForOperand2); }