Load8BitRegisterAIntoHLAddressAndDecrementHL extends Instruction { @Override public void execute() { int address = z80.get16BitRegisterValue(Register.HL); byte value = z80.get8BitRegisterValue(Register.A); mmu.writeByte(address, value); int newHlRegisterValue = z80.get16BitRegisterValue(Register.HL) - 1; z80.set16BitRegisterValue(Register.HL, newHlRegisterValue); z80.setLastInstructionExecutionTime(2); } Load8BitRegisterAIntoHLAddressAndDecrementHL(GBZ80 z80, MMU mmu); @Override void execute();  }
@Test public void shouldUseTwoCyclesAsLastInstructionExecutionTime() { Instruction instruction = new Load8BitRegisterAIntoHLAddressAndDecrementHL(z80, mmu); instruction.execute(); assertEquals(2, z80.getLastInstructionExecutionTime()); }
@Test public void shouldDecrementHL() { z80.set16BitRegisterValue(Register.HL, ANY_16BIT_REGISTER_VALUE); Instruction instruction = new Load8BitRegisterAIntoHLAddressAndDecrementHL(z80, mmu); instruction.execute(); assertEquals(ANY_16BIT_REGISTER_VALUE - 1, z80.get16BitRegisterValue(Register.HL)); }
@Test public void shouldLoadRegisterAValueIntoTheHLAddress() { z80.set8BitRegisterValue(Register.A, ANY_8BIT_REGISTER_VALUE); z80.set16BitRegisterValue(Register.HL, ANY_16BIT_REGISTER_VALUE); Instruction instruction = new Load8BitRegisterAIntoHLAddressAndDecrementHL(z80, mmu); instruction.execute(); verify(mmu).writeByte(ANY_16BIT_REGISTER_VALUE, ANY_8BIT_REGISTER_VALUE); }