Push16BitRegister extends Instruction { @Override public void execute() { int registerValue = z80.get16BitRegisterValue(sourceRegister); pushTwice(registerValue); z80.setLastInstructionExecutionTime(4); } Push16BitRegister(GBZ80 z80, MMU mmu, Register sourceRegister); @Override void execute();  }
@Test public void shouldPushTheContentOfThe16BitRegisterValueIntoTheAddressPointedByTheMemoryStack() { z80.set16BitRegisterValue(ANY_16BIT_SOURCE_REGISTER, ANY_16BIT_REGISTER_VALUE); Instruction instruction = new Push16BitRegister(z80, mmu, ANY_16BIT_SOURCE_REGISTER); instruction.execute(); }
@Test public void shouldUseFourCyclesAsLastInstructionExecutionTime() { Instruction instruction = new Push16BitRegister(z80, mmu, ANY_16BIT_SOURCE_REGISTER); instruction.execute(); assertEquals(4, z80.getLastInstructionExecutionTime()); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAccept8BitRegistersAsSourceRegister() { Instruction instruction = new Push16BitRegister(z80, mmu, ANY_8BIT_SOURCE_REGISTER); instruction.execute(); }
@Test public void shouldDecrementStackPointerByTwo() { z80.setStackPointer(ANY_16BIT_REGISTER_VALUE); Instruction instruction = new Push16BitRegister(z80, mmu, ANY_16BIT_SOURCE_REGISTER); instruction.execute(); assertEquals(ANY_16BIT_REGISTER_VALUE - 2, z80.getStackPointer()); }
@Test public void shouldPushTheValueOfTheSourceRegisterIntoTheMemoryPointedByTheStackPointer() { z80.set16BitRegisterValue(ANY_16BIT_SOURCE_REGISTER, ANY_16BIT_REGISTER_VALUE); z80.setStackPointer(ANY_STACK_POINTER_VALUE); Instruction instruction = new Push16BitRegister(z80, mmu, ANY_16BIT_SOURCE_REGISTER); instruction.execute(); byte firstPart = (ANY_16BIT_REGISTER_VALUE >> 8) & 0xFF; verify(mmu).writeByte(ANY_STACK_POINTER_VALUE - 1, firstPart); byte secondPart = ANY_16BIT_REGISTER_VALUE & 0xFF; verify(mmu).writeByte(ANY_STACK_POINTER_VALUE - 2, secondPart); }