Load8BitPortAddressImmPCIntoA extends Instruction { @Override public void execute() { int address = (mmu.readByte(z80.getProgramCounter()) & 0xFF) + 0xFF00; byte memoryValue = mmu.readByte(address); z80.set8BitRegisterValue(Register.A, memoryValue); z80.incrementProgramCounter(); z80.setLastInstructionExecutionTime(3); } Load8BitPortAddressImmPCIntoA(GBZ80 z80, MMU mmu); @Override void execute();  }
@Test public void shouldIncrementProgramCounterInOneUnit() { z80.setProgramCounter(ANY_16BIT_REGISTER_VALUE); Instruction instruction = new Load8BitPortAddressImmPCIntoA(z80, mmu); instruction.execute(); int expectedPCValue = ANY_16BIT_REGISTER_VALUE + 1; assertEquals(expectedPCValue, z80.getProgramCounter()); }
@Test public void shouldUseThreeCyclesAsLastExecutionTime() { Instruction instruction = new Load8BitPortAddressImmPCIntoA(z80, mmu); instruction.execute(); assertEquals(3, z80.getLastInstructionExecutionTime()); }
@Test public void shouldLoad8BitMemoryValuePointedByThePortAddressOfPCIntoA() { z80.setProgramCounter(ANY_16BIT_REGISTER_VALUE); int pcPortAddress = (mmu.readByte(z80.getProgramCounter()) & 0xFF) + 0xFF00; when(mmu.readByte(pcPortAddress)).thenReturn(ANY_MEMORY_BYTE_VALUE); Instruction instruction = new Load8BitPortAddressImmPCIntoA(z80, mmu); instruction.execute(); assertEquals(ANY_MEMORY_BYTE_VALUE, z80.get8BitRegisterValue(Register.A)); }