@Test public void shouldSumSourceRegisterValuePlusHLRegisterValueAndStoreTheResultIntoHLRegister() { z80.set16BitRegisterValue(Register.HL, 1); z80.set16BitRegisterValue(ANY_16BIT_SOURCE_REGISTER, 3); Instruction instruction = new Add16BitRegisterToHLIntoHL(z80, ANY_16BIT_SOURCE_REGISTER); instruction.execute(); assertEquals(4, z80.get16BitRegisterValue(Register.HL)); }
@Override public void execute() { int registerValue = z80.get16BitRegisterValue(sourceRegister); int registerHLValue = z80.get16BitRegisterValue(Register.HL); int sum = registerHLValue + registerValue; z80.set16BitRegisterValue(Register.HL, sum); z80.setLastInstructionExecutionTime(2); z80.disableFlagN(); if ((registerValue & 0xFFF) + (registerHLValue & 0xFFF) > 0xFFF) { z80.enableFlagH(); } else { z80.disableFlagH(); } if (sum > 0xFFFF) { z80.enableFlagCY(); } else { z80.disableFlagCY(); } }
Add16BitRegisterToHLIntoHL extends Instruction { @Override public void execute() { int registerValue = z80.get16BitRegisterValue(sourceRegister); int registerHLValue = z80.get16BitRegisterValue(Register.HL); int sum = registerHLValue + registerValue; z80.set16BitRegisterValue(Register.HL, sum); z80.setLastInstructionExecutionTime(2); z80.disableFlagN(); if ((registerValue & 0xFFF) + (registerHLValue & 0xFFF) > 0xFFF) { z80.enableFlagH(); } else { z80.disableFlagH(); } if (sum > 0xFFFF) { z80.enableFlagCY(); } else { z80.disableFlagCY(); } } }
Add16BitRegisterToHLIntoHL extends Instruction { @Override public void execute() { int registerValue = z80.get16BitRegisterValue(sourceRegister); int registerHLValue = z80.get16BitRegisterValue(Register.HL); int sum = registerHLValue + registerValue; z80.set16BitRegisterValue(Register.HL, sum); z80.setLastInstructionExecutionTime(2); z80.disableFlagN(); if ((registerValue & 0xFFF) + (registerHLValue & 0xFFF) > 0xFFF) { z80.enableFlagH(); } else { z80.disableFlagH(); } if (sum > 0xFFFF) { z80.enableFlagCY(); } else { z80.disableFlagCY(); } } Add16BitRegisterToHLIntoHL(GBZ80 z80, Register sourceRegister); }
Add16BitRegisterToHLIntoHL extends Instruction { @Override public void execute() { int registerValue = z80.get16BitRegisterValue(sourceRegister); int registerHLValue = z80.get16BitRegisterValue(Register.HL); int sum = registerHLValue + registerValue; z80.set16BitRegisterValue(Register.HL, sum); z80.setLastInstructionExecutionTime(2); z80.disableFlagN(); if ((registerValue & 0xFFF) + (registerHLValue & 0xFFF) > 0xFFF) { z80.enableFlagH(); } else { z80.disableFlagH(); } if (sum > 0xFFFF) { z80.enableFlagCY(); } else { z80.disableFlagCY(); } } Add16BitRegisterToHLIntoHL(GBZ80 z80, Register sourceRegister); @Override void execute(); }
Add16BitRegisterToHLIntoHL extends Instruction { @Override public void execute() { int registerValue = z80.get16BitRegisterValue(sourceRegister); int registerHLValue = z80.get16BitRegisterValue(Register.HL); int sum = registerHLValue + registerValue; z80.set16BitRegisterValue(Register.HL, sum); z80.setLastInstructionExecutionTime(2); z80.disableFlagN(); if ((registerValue & 0xFFF) + (registerHLValue & 0xFFF) > 0xFFF) { z80.enableFlagH(); } else { z80.disableFlagH(); } if (sum > 0xFFFF) { z80.enableFlagCY(); } else { z80.disableFlagCY(); } } Add16BitRegisterToHLIntoHL(GBZ80 z80, Register sourceRegister); @Override void execute();  }