LoadSPIntoImmPC extends Instruction { @Override public void execute() { int stackPointer = z80.getStackPointer(); int programCounter = z80.getProgramCounter(); mmu.writeWord(programCounter, stackPointer); z80.incrementProgramCounterTwice(); z80.setLastInstructionExecutionTime(5); } LoadSPIntoImmPC(GBZ80 z80, MMU mmu); @Override void execute();  }
@Test public void shouldUseFiveCyclesAsLastInstructionExecutionTime() { Instruction instruction = new LoadSPIntoImmPC(z80, mmu); instruction.execute(); assertEquals(5, z80.getLastInstructionExecutionTime()); }
@Test public void shouldLoadStackPointerIntoTheProgramCounterAddress() { z80.setStackPointer(ANY_STACK_POINTER_VALUE); z80.setProgramCounter(ANY_16BIT_REGISTER_VALUE); Instruction instruction = new LoadSPIntoImmPC(z80, mmu); instruction.execute(); verify(mmu).writeWord(ANY_16BIT_REGISTER_VALUE, ANY_STACK_POINTER_VALUE); }
@Test public void shouldIncrementProgramCounterTwice() { z80.setProgramCounter(ANY_16BIT_REGISTER_VALUE); Instruction instruction = new LoadSPIntoImmPC(z80, mmu); instruction.execute(); assertEquals(ANY_16BIT_REGISTER_VALUE + 2, z80.getProgramCounter()); }