Add8BitAddressHLPlusAIntoA extends Instruction { @Override public void execute() { int address = z80.get16BitRegisterValue(Register.HL); byte memoryValue = mmu.readByte(address); byte registerAValue = z80.get8BitRegisterValue(Register.A); byte sum = (byte) (memoryValue + registerAValue); z80.set8BitRegisterValue(Register.A, sum); z80.setLastInstructionExecutionTime(2); z80.resetFlagF(); if (sum == 0) { z80.enableFlagZ(); } if ((sum & 0x100) == 0x100) { z80.enableFlagCY(); } if ((sum & 0x10) == 0x10) { z80.enableFlagH(); } } Add8BitAddressHLPlusAIntoA(GBZ80 z80, MMU mmu); @Override void execute();  }
@Test public void shouldUseTwoCyclesAsLastInstructionExecutionTime() { Instruction instruction = new Add8BitAddressHLPlusAIntoA(z80, mmu); instruction.execute(); assertEquals(2, z80.getLastInstructionExecutionTime()); }
@Test public void shouldSumTheContentOfTheMemoryPointedByTheRegisterHLToAAndLoadsTheResultIntoA() { z80.set8BitRegisterValue(Register.A, ANY_8BIT_REGISTER_VALUE); z80.set16BitRegisterValue(Register.HL, ANY_16BIT_REGISTER_VALUE); when(mmu.readByte(ANY_16BIT_REGISTER_VALUE)).thenReturn(ANY_MEMORY_BYTE_VALUE); Instruction instruction = new Add8BitAddressHLPlusAIntoA(z80, mmu); instruction.execute(); byte expectedSum = ANY_8BIT_REGISTER_VALUE + ANY_MEMORY_BYTE_VALUE; assertEquals(expectedSum, z80.get8BitRegisterValue(Register.A)); }