Z80 { public int getRegister(final int reg) { return this.getRegister(reg, false); } Z80(final Z80CPUBus bus);  Z80(final Z80 cpu); static int parseAndPackRegAlignValue(final String regs); Z80 fillByState(final Z80 src); int getIM(); void setIM(final int im); boolean isIFF1(); boolean isIFF2(); int getPrefixInProcessing(); int getPrevINSignals(); int getPC(); void setIFF(final boolean iff1, final boolean iff2); void setRegisterPair(final int regPair, final int value); void setRegisterPair(final int regPair, final int value, final boolean alt); int getRegisterPair(final int regPair); int getRegisterPair(final int regPair, final boolean alt); void setRegister(final int reg, final int value); void setRegister(final int reg, final int value, final boolean alt); int getRegister(final int reg); int getRegister(final int reg, final boolean alt); int getState(); Z80CPUBus getBus(); int getStepTstates(); boolean isInsideBlockLoop(); int getSP(); Z80 alignRegisterValuesWith(final Z80 src, int packedRegisterFlags); int getLastM1InstructionByte(); int getLastInstructionByte(); int nextInstruction(final int ctx, final boolean signalRESET, final boolean signalNMI,
                             final boolean signalNT); int nextInstruction_SkipBlockInstructions(final int ctx, final boolean signalRESET,
                                                   final boolean signalNMI,
                                                   final boolean signalNT); boolean step(final int ctx, final int incomingSignals); String getStateAsString(); void doReset(); boolean compareState(final Z80 other, final boolean compareExe); static final int REG_A; static final int REG_F; static final int REG_B; static final int REG_C; static final int REG_D; static final int REG_E; static final int REG_H; static final int REG_L; static final int REG_IX; static final int REG_IY; static final int REG_SP; static final int REG_PC; static final int REG_I; static final int REG_R; static final int REGPAIR_AF; static final int REGPAIR_BC; static final int REGPAIR_DE; static final int REGPAIR_HL; static final int SIGNAL_IN_nINT; static final int SIGNAL_IN_nNMI; static final int SIGNAL_IN_nRESET; static final int SIGNAL_IN_nWAIT; static final int SIGNAL_IN_ALL_INACTIVE; static final int SIGNAL_OUT_nM1; static final int SIGNAL_OUT_nHALT; static final int SIGNAL_OUT_ALL_INACTIVE; static final int FLAG_S; static final int FLAG_Z; static final int FLAG_Y; static final int FLAG_H; static final int FLAG_X; static final int FLAG_PV; static final int FLAG_N; static final int FLAG_C; }
@Test public void testCommand_CP_n_A_less_Value() { final Z80State state = new Z80State(); state.A = 69; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFE, 254); assertEquals(69, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C | FLAG_N | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_CP_n_A_greater_Value() { final Z80State state = new Z80State(); state.A = 0xFE; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFE, 69); assertEquals(0xFE, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_S | FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_CP_n_A_equ_Value() { final Z80State state = new Z80State(); state.A = 0xFE; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFE, 0xFE); assertEquals(0xFE, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_Z | FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_CP_mHL() { final Z80State state = new Z80State(); state.A = 0x29; state.L = 0x34; state.H = 0x12; memory[0x1234] = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xBE); assertEquals(0x29, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_CP_mIXd() { final Z80State state = new Z80State(); state.A = 0x29; state.IX = 0x1234; memory[0x1239] = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xBE, 0x05); assertEquals(0x29, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_CP_mIYd() { final Z80State state = new Z80State(); state.A = 0x29; state.IY = 0x1234; memory[0x1239] = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xBE, 0x05); assertEquals(0x29, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_IX_DE() { final Z80State state = new Z80State(); state.A = 0x29; state.IX = 0x3333; state.E = 0x55; state.D = 0x55; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x19); assertEquals(0x8888, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsExcludeReserved(Z80.FLAG_X | Z80.FLAG_Y | Z80.FLAG_Z | Z80.FLAG_S | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_IY_DE() { final Z80State state = new Z80State(); state.A = 0x29; state.IY = 0x3333; state.E = 0x55; state.D = 0x55; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x19); assertEquals(0x8888, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsExcludeReserved(Z80.FLAG_X | Z80.FLAG_Y | Z80.FLAG_Z | Z80.FLAG_S | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_CPL() { final Z80State state = new Z80State(); state.A = 0xB4; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x2F); assertEquals(0x4B, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0xFF, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_DAA() { final Z80State state = new Z80State(); state.A = 0x3C; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0x27); assertEquals(0x42, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(Z80.FLAG_H | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_n() { final Z80State state = new Z80State(); state.A = 12; final Pair<Z80, Integer> cpu = executeCommand(state, 0x3E, 0x67); assertEquals(0x67, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_NEG() { final Z80State state = new Z80State(); state.A = 0x98; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x44); assertEquals(0x68, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C | FLAG_N | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_CCF_Set() { final Z80State state = new Z80State(); state.A = 0x98; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x3F); assertEquals(0x98, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved( Z80.FLAG_X | Z80.FLAG_Y | Z80.FLAG_H | Z80.FLAG_PV | Z80.FLAG_Z | Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_CCF_Reset() { final Z80State state = new Z80State(); state.A = 0x98; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0x3F); assertEquals(0x98, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_SCF() { final Z80State state = new Z80State(); state.A = 0x98; state.F = FLAG_N | FLAG_H; final Pair<Z80, Integer> cpu = executeCommand(state, 0x37); assertEquals(0x98, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_INC_A() { final Z80State state = new Z80State(); state.A = 0x28; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x3C); assertEquals(0x29, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_INC_mIXd() { final Z80State state = new Z80State(); state.IX = 0x2020; state.F = 0xFF; this.memory[0x2030] = 0x34; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x34, 0x10); assertEquals(0x2020, cpu.getLeft().getRegister(Z80.REG_IX)); assertMemory(0x2030, 0x35); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_INC_mIYd() { final Z80State state = new Z80State(); state.IY = 0x2020; state.F = 0xFF; this.memory[0x2030] = 0x34; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x34, 0x10); assertEquals(0x2020, cpu.getLeft().getRegister(Z80.REG_IY)); assertMemory(0x2030, 0x35); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_INC_SP() { final Z80State state = new Z80State(); state.SP = 0x1000; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x33); assertEquals(0x1001, cpu.getLeft().getRegister(Z80.REG_SP)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(6, cpu.getRight().intValue()); }
@Test public void testCommand_LD_C_D() { final Z80State state = new Z80State(); state.A = 12; state.C = 15; final Pair<Z80, Integer> cpu = executeCommand(state, 0x4f); assertEquals(12, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(12, cpu.getLeft().getRegister(Z80.REG_C)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_INC_IX() { final Z80State state = new Z80State(); state.IX = 0x1000; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x23); assertEquals(0x1001, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_INC_IXh() { final Z80State state = new Z80State(); state.IX = 0x1000; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x24); assertEquals(0x1100, cpu.getLeft().getRegister(Z80.REG_IX)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_INC_IXl() { final Z80State state = new Z80State(); state.IX = 0xFFFF; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x2C); assertEquals(0xFF00, cpu.getLeft().getRegister(Z80.REG_IX)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_INC_IYh() { final Z80State state = new Z80State(); state.IY = 0x1000; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x24); assertEquals(0x1100, cpu.getLeft().getRegister(Z80.REG_IY)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_INC_IYl() { final Z80State state = new Z80State(); state.IY = 0xFFFF; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x2C); assertEquals(0xFF00, cpu.getLeft().getRegister(Z80.REG_IY)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_INC_IY() { final Z80State state = new Z80State(); state.IY = 0x1000; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x23); assertEquals(0x1001, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_DEC_D() { final Z80State state = new Z80State(); state.D = 0x2A; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x15); assertEquals(0x29, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsExcludeReserved(Z80.FLAG_C | FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_DEC_mHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0xFF; memory[0x1234] = 0x2A; final Pair<Z80, Integer> cpu = executeCommand(state, 0x35); assertMemory(0x1234, 0x29); assertFlagsExcludeReserved(Z80.FLAG_C | FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_DEC_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0xFF; memory[0x1239] = 0x2A; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x35, 0x05); assertMemory(0x1239, 0x29); assertFlagsExcludeReserved(Z80.FLAG_C | FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_DEC_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0xFF; memory[0x1239] = 0x2A; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x35, 0x05); assertMemory(0x1239, 0x29); assertFlagsExcludeReserved(Z80.FLAG_C | FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_mHL() { final Z80State state = new Z80State(); state.A = 12; state.H = 0x12; state.L = 0x34; this.memory[0x1234] = 0x73; final Pair<Z80, Integer> cpu = executeCommand(state, 0x7E); assertEquals(0x73, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_DEC_SP() { final Z80State state = new Z80State(); state.SP = 0x1000; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x3B); assertEquals(0x0FFF, cpu.getLeft().getRegister(Z80.REG_SP)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(6, cpu.getRight().intValue()); }
@Test public void testCommand_DEC_IX() { final Z80State state = new Z80State(); state.IX = 0x1000; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x2B); assertEquals(0x0FFF, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_DEC_IY() { final Z80State state = new Z80State(); state.IY = 0x1000; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x2B); assertEquals(0x0FFF, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_RLCA() { final Z80State state = new Z80State(); state.A = 0x88; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0x07); assertEquals(0x11, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_RLA() { final Z80State state = new Z80State(); state.A = 0x76; state.F = Z80.FLAG_C; final Pair<Z80, Integer> cpu = executeCommand(state, 0x17); assertEquals(0xED, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_RRCA() { final Z80State state = new Z80State(); state.A = 0x11; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0x0F); assertEquals(0x88, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_RRA() { final Z80State state = new Z80State(); state.A = 0xE1; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0x1F); assertEquals(0x70, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_RLC_r() { final int[] codes = new int[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07}; final int[] regs = new int[] {Z80.REG_B, Z80.REG_C, Z80.REG_D, Z80.REG_E, Z80.REG_H, Z80.REG_L, Z80.REG_A}; for (int i = 0; i < codes.length; i++) { final Z80State state = new Z80State(); state.A = 0x88; state.B = 0x88; state.C = 0x88; state.D = 0x88; state.E = 0x88; state.H = 0x88; state.L = 0x88; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, codes[i]); assertEquals(0x11, cpu.getLeft().getRegister(regs[i])); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); } }
@Test public void testCommand_LD_mHL_A() { final Z80State state = new Z80State(); state.A = 0x48; state.H = 0x12; state.L = 0x34; this.memory[0x1234] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0x77); assertEquals(0x48, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x48, this.memory[0x1234]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_RLC_mHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0x00; memory[0x1234] = (byte) 0x88; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x06); assertMemory(0x1234, 0x11); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_RLC_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0x88; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, 0x06); assertMemory(0x1239, 0x11); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_RLC_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0x88; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, 0x06); assertMemory(0x1239, 0x11); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_RL_D() { final Z80State state = new Z80State(); state.D = 0x8F; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x12); assertEquals(0x1E, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_RL_mHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0x00; memory[0x1234] = (byte) 0x8F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x16); assertMemory(0x1234, 0x1E); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_RL_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0x8F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, 0x16); assertMemory(0x1239, 0x1E); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_RL_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0x8F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, 0x16); assertMemory(0x1239, 0x1E); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_RRC_D() { final Z80State state = new Z80State(); state.D = 0x31; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x0A); assertEquals(0x98, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_RRC_mHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0x00; memory[0x1234] = (byte) 0x31; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x0E); assertMemory(0x1234, 0x98); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_RRC_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0x31; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, 0x0E); assertMemory(0x1239, 0x98); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_mIXd() { final Z80State state = new Z80State(); state.A = 12; state.IX = 0x1234; this.memory[0x1232] = 0x73; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x7E, 0xFE); assertEquals(0x73, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_RRC_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0x31; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, 0x0E); assertMemory(0x1239, 0x98); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_RR_D() { final Z80State state = new Z80State(); state.D = 0xDD; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x1A); assertEquals(0x6E, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_RR_mHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0x00; memory[0x1234] = (byte) 0xDD; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x1E); assertMemory(0x1234, 0x6E); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_RR_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0xDD; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, 0x1E); assertMemory(0x1239, 0x6E); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_RR_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0xDD; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, 0x1E); assertMemory(0x1239, 0x6E); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_SLA_D() { final Z80State state = new Z80State(); state.D = 0xB1; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x22); assertEquals(0x62, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_SLA_A() { final Z80State state = new Z80State(); state.A = 0xB1; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x27); assertEquals(0x62, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_SLA_mHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0x00; memory[0x1234] = (byte) 0xB1; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x26); assertMemory(0x1234, 0x62); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_SLA_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0xB1; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, 0x26); assertMemory(0x1239, 0x62); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_SLA_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0xB1; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, 0x26); assertMemory(0x1239, 0x62); assertFlagsExcludeReserved(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_LD_mIXd_A() { final Z80State state = new Z80State(); state.A = 0x48; state.IX = 0x1234; this.memory[0x1239] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x77, 5); assertEquals(0x48, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x48, this.memory[0x1239]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_SLL_D() { final Z80State state = new Z80State(); state.D = 0xB1; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x32); assertEquals(0x63, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_SLL_mHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0x00; memory[0x1234] = (byte) 0xB1; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x36); assertMemory(0x1234, 0x63); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_SLL_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0xB1; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, 0x36); assertMemory(0x1239, 0x63); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_SLL_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0x00; memory[0x1239] = (byte) 0xB1; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, 0x36); assertMemory(0x1239, 0x63); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_SRA_D() { final Z80State state = new Z80State(); state.D = 0xB8; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x2A); assertEquals(0xDC, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsExcludeReserved(Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_SRA_mHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0x00; memory[0x1234] = (byte) 0xB8; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x2E); assertMemory(0x1234, 0xDC); assertFlagsExcludeReserved(Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_SRA_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0x00; memory[0x1232] = (byte) 0xB8; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, -2, 0x2E); assertMemory(0x1232, 0xDC); assertFlagsExcludeReserved(Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_SRA_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0x00; memory[0x1232] = (byte) 0xB8; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, -2, 0x2E); assertMemory(0x1232, 0xDC); assertFlagsExcludeReserved(Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_SRL_D() { final Z80State state = new Z80State(); state.D = 0x8F; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x3A); assertEquals(0x47, cpu.getLeft().getRegister(Z80.REG_D)); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_SRL_HL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; state.F = 0x00; memory[0x1234] = (byte) 0x8F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x3E); assertMemory(0x1234, 0x47); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_mIYd() { final Z80State state = new Z80State(); state.A = 12; state.IY = 0x1234; this.memory[0x1239] = 0x73; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x7E, 5); assertEquals(0x73, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_SRL_mIXd() { final Z80State state = new Z80State(); state.IX = 0x1234; state.F = 0x00; memory[0x1230] = (byte) 0x8F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, -4, 0x3E); assertMemory(0x1230, 0x47); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_SRL_mIYd() { final Z80State state = new Z80State(); state.IY = 0x1234; state.F = 0x00; memory[0x1230] = (byte) 0x8F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, -4, 0x3E); assertMemory(0x1230, 0x47); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_RLD() { final Z80State state = new Z80State(); state.A = 0x7A; state.H = 0x50; state.L = 0x00; state.F = 0x00; memory[0x5000] = 0x31; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x6F); assertEquals(0x73, cpu.getLeft().getRegister(Z80.REG_A)); assertMemory(0x5000, 0x1A); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(18, cpu.getRight().intValue()); }
@Test public void testCommand_RRD() { final Z80State state = new Z80State(); state.A = 0x84; state.H = 0x50; state.L = 0x00; state.F = 0x00; memory[0x5000] = 0x20; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x67); assertEquals(0x80, cpu.getLeft().getRegister(Z80.REG_A)); assertMemory(0x5000, 0x42); assertEquals(Z80.FLAG_S, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(18, cpu.getRight().intValue()); }
@Test public void testCommand_BIT_2_reg() { final int[] codes = new int[] {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x57}; final int[] regs = new int[] {Z80.REG_B, Z80.REG_C, Z80.REG_D, Z80.REG_E, Z80.REG_H, Z80.REG_L, Z80.REG_A}; for (int i = 0; i < codes.length; i++) { final Z80State state = new Z80State(); state.B = (~4) & 0xFF; state.C = (~4) & 0xFF; state.D = (~4) & 0xFF; state.E = (~4) & 0xFF; state.H = (~4) & 0xFF; state.L = (~4) & 0xFF; state.A = (~4) & 0xFF; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, codes[i]); assertEquals((~4) & 0xFF, cpu.getLeft().getRegister(regs[i])); assertFlagsExcludeReserved(Z80.FLAG_Z | Z80.FLAG_PV | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(8, cpu.getRight().intValue()); } }
@Test public void testCommand_BIT_7_regIX() { for (int i = 0; i < 0xFF; i++) { final Z80State state = new Z80State(); state.IX = 0x1010; this.memory[0x1011] = (byte) i; final int origf = i ^ 0xFF; state.F = origf; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x01, 0x7E); assertEquals(0x1010, cpu.getLeft().getRegister(Z80.REG_IX)); assertMemory(0x1011, i); final int flag = (origf & Z80.FLAG_C) | ((i & 0x80) == 0 ? (Z80.FLAG_PV | Z80.FLAG_Z) : 0) | ((i & 0x80) == 0 ? 0 : Z80.FLAG_S) | (state.IX & (Z80.FLAG_X | Z80.FLAG_Y)) | Z80.FLAG_H; assertEquals("Value " + i, flag, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(20, cpu.getRight().intValue()); } }
@Test public void testCommand_BIT_2_mHL() { final Z80State state = new Z80State(); state.H = 0x50; state.L = 0x00; this.memory[0x5000] = (byte) 4; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0x56); assertEquals(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(12, cpu.getRight().intValue()); }
@Test public void testCommand_BIT_2_mIXd() { final Z80State state = new Z80State(); state.IX = 0x5000; this.memory[0x5010] = (byte) 4; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x10, 0x56); assertEquals(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(20, cpu.getRight().intValue()); }
@Test public void testCommand_BIT_2_mIYd() { final Z80State state = new Z80State(); state.IY = 0x5000; this.memory[0x5010] = (byte) 4; state.F = 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x10, 0x56); assertEquals(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(20, cpu.getRight().intValue()); }
@Test public void testCommand_SET_4_B() { final Z80State state = new Z80State(); state.B = 0; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0xE0); assertEquals(0x10, cpu.getLeft().getRegister(Z80.REG_B)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_mIYd_A() { final Z80State state = new Z80State(); state.A = 0x48; state.IY = 0x1234; this.memory[0x1232] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x77, -2); assertEquals(0x48, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x48, this.memory[0x1232]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_RES_4_B() { final Z80State state = new Z80State(); state.B = 0xFF; state.F = 0x18; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCB, 0xA0); assertEquals(0xEF, cpu.getLeft().getRegister(Z80.REG_B)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_JP_nn() { final Z80State state = new Z80State(); final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xC3, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_NC_nn_false() { final Z80State state = new Z80State(); state.F = Z80.FLAG_C; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xD2, 0x34, 0x12); assertEquals(0x0003, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_NC_nn_true() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_C) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xD2, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_C_nn_false() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_C) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xDA, 0x34, 0x12); assertEquals(0x0003, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_C_nn_true() { final Z80State state = new Z80State(); state.F = Z80.FLAG_C; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xDA, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_NZ_nn_false() { final Z80State state = new Z80State(); state.F = Z80.FLAG_Z; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xC2, 0x34, 0x12); assertEquals(0x0003, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_mBC() { final Z80State state = new Z80State(); state.A = 0x48; state.B = 0x12; state.C = 0x34; this.memory[0x1234] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0x0A); assertEquals(0x33, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x33, this.memory[0x1234]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_JP_NZ_nn_true() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_Z) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xC2, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_Z_nn_false() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_Z) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xCA, 0x34, 0x12); assertEquals(0x0003, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_Z_nn_true() { final Z80State state = new Z80State(); state.F = Z80.FLAG_Z; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xCA, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_PO_nn_false() { final Z80State state = new Z80State(); state.F = Z80.FLAG_PV; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xE2, 0x34, 0x12); assertEquals(0x0003, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_PO_nn_true() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_PV) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xE2, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_PE_nn_false() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_PV) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xEA, 0x34, 0x12); assertEquals(0x0003, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_PE_nn_true() { final Z80State state = new Z80State(); state.F = Z80.FLAG_PV; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xEA, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_P_nn_false() { final Z80State state = new Z80State(); state.F = Z80.FLAG_S; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xF2, 0x34, 0x12); assertEquals(0x0003, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_P_nn_true() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_S) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xF2, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JP_M_nn_false() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_S) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xFA, 0x34, 0x12); assertEquals(0x0003, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_mDE() { final Z80State state = new Z80State(); state.A = 0x48; state.D = 0x12; state.E = 0x34; this.memory[0x1234] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0x1A); assertEquals(0x33, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x33, this.memory[0x1234]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_JP_M_nn_true() { final Z80State state = new Z80State(); state.F = Z80.FLAG_S; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xFA, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(10, cpu.getRight().intValue()); }
@Test public void testCommand_JR_nn() { final Z80State state = new Z80State(); final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x18, 0x03); assertEquals(0x0005, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(12, cpu.getRight().intValue()); }
@Test public void testCommand_JR_NZ_nn_false() { final Z80State state = new Z80State(); state.F = Z80.FLAG_Z; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x20, 0x03); assertEquals(0x0002, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_JR_NZ_nn_true() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_Z) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x20, 0x03); assertEquals(0x0005, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(12, cpu.getRight().intValue()); }
@Test public void testCommand_JR_Z_nn_false() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_Z) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x28, 0x03); assertEquals(0x0002, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_JR_Z_nn_true() { final Z80State state = new Z80State(); state.F = Z80.FLAG_Z; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x28, 0x03); assertEquals(0x0005, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(12, cpu.getRight().intValue()); }
@Test public void testCommand_JR_NC_nn_false() { final Z80State state = new Z80State(); state.F = Z80.FLAG_C; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x30, 0x03); assertEquals(0x0002, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_JR_NC_nn_true() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_C) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x30, 0x03); assertEquals(0x0005, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(12, cpu.getRight().intValue()); }
@Test public void testCommand_JR_C_nn_false() { final Z80State state = new Z80State(); state.F = (~Z80.FLAG_C) & 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x38, 0x03); assertEquals(0x0002, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_JR_C_nn_true() { final Z80State state = new Z80State(); state.F = Z80.FLAG_C; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x38, 0x03); assertEquals(0x0005, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(12, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_mNN() { final Z80State state = new Z80State(); state.A = 0x48; this.memory[0x1234] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0x3A, 0x34, 0x12); assertEquals(0x33, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x33, this.memory[0x1234]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(13, cpu.getRight().intValue()); }
@Test public void testCommand_JP_rHL() { final Z80State state = new Z80State(); state.H = 0x12; state.L = 0x34; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xE9); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_JP_rIX() { final Z80State state = new Z80State(); state.IX = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xDD, 0xE9); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_JP_rIY() { final Z80State state = new Z80State(); state.IY = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0xFD, 0xE9); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_PC)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_DJNZ_false() { final Z80State state = new Z80State(); state.B = 5; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x10, 0x03); assertEquals(0x0005, cpu.getLeft().getRegister(Z80.REG_PC)); assertEquals(4, cpu.getLeft().getRegister(Z80.REG_B)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(13, cpu.getRight().intValue()); }
@Test public void testCommand_DJNZ_true() { final Z80State state = new Z80State(); state.B = 1; final Pair<Z80, Integer> cpu = executeCommand(state, false, 0x10, 0x03); assertEquals(0x0002, cpu.getLeft().getRegister(Z80.REG_PC)); assertEquals(0, cpu.getLeft().getRegister(Z80.REG_B)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_RLC_mIXd_r() { final int[] codes = new int[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07}; final int[] regs = new int[] {Z80.REG_B, Z80.REG_C, Z80.REG_D, Z80.REG_E, Z80.REG_H, Z80.REG_L, Z80.REG_A}; for (int i = 0; i < codes.length; i++) { final Z80State state = new Z80State(); state.A = 0x00; state.B = 0x00; state.C = 0x00; state.D = 0x00; state.E = 0x00; state.H = 0x00; state.L = 0x00; state.F = 0x00; state.IX = 0x1000; this.memory[0x1005] = (byte) 0x88; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, codes[i]); assertEquals(0x11, cpu.getLeft().getRegister(regs[i])); assertMemory(0x1005, 0x11); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); } }
@Test public void testCommand_RLC_mIYd_r() { final int[] codes = new int[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07}; final int[] regs = new int[] {Z80.REG_B, Z80.REG_C, Z80.REG_D, Z80.REG_E, Z80.REG_H, Z80.REG_L, Z80.REG_A}; for (int i = 0; i < codes.length; i++) { final Z80State state = new Z80State(); state.A = 0x00; state.B = 0x00; state.C = 0x00; state.D = 0x00; state.E = 0x00; state.H = 0x00; state.L = 0x00; state.F = 0x00; state.IY = 0x1000; this.memory[0x1005] = (byte) 0x88; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, codes[i]); assertEquals(0x11, cpu.getLeft().getRegister(regs[i])); assertMemory(0x1005, 0x11); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(23, cpu.getRight().intValue()); } }
@Test public void testCommand_RES_4_mIXd_r() { final int[] codes = new int[] {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA7}; final int[] regs = new int[] {Z80.REG_B, Z80.REG_C, Z80.REG_D, Z80.REG_E, Z80.REG_H, Z80.REG_L, Z80.REG_A}; for (int i = 0; i < codes.length; i++) { final Z80State state = new Z80State(); state.A = 0x00; state.B = 0x00; state.C = 0x00; state.D = 0x00; state.E = 0x00; state.H = 0x00; state.L = 0x00; state.F = 0x00; state.IX = 0x1000; this.memory[0x1005] = (byte) 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, codes[i]); assertEquals(0xEF, cpu.getLeft().getRegister(regs[i])); assertMemory(0x1005, 0xEF); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(23, cpu.getRight().intValue()); } }
@Test public void testCommand_RES_4_mIYd_r() { final int[] codes = new int[] {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA7}; final int[] regs = new int[] {Z80.REG_B, Z80.REG_C, Z80.REG_D, Z80.REG_E, Z80.REG_H, Z80.REG_L, Z80.REG_A}; for (int i = 0; i < codes.length; i++) { final Z80State state = new Z80State(); state.A = 0x00; state.B = 0x00; state.C = 0x00; state.D = 0x00; state.E = 0x00; state.H = 0x00; state.L = 0x00; state.F = 0x00; state.IY = 0x1000; this.memory[0x1005] = (byte) 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, codes[i]); assertEquals(0xEF, cpu.getLeft().getRegister(regs[i])); assertMemory(0x1005, 0xEF); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(23, cpu.getRight().intValue()); } }
@Test public void testCommand_LD_mBC_A() { final Z80State state = new Z80State(); state.A = 0x48; state.B = 0x12; state.C = 0x34; this.memory[0x1234] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0x02); assertEquals(0x48, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x48, this.memory[0x1234]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_SET_4_mIXd_r() { final int[] codes = new int[] {0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE7}; final int[] regs = new int[] {Z80.REG_B, Z80.REG_C, Z80.REG_D, Z80.REG_E, Z80.REG_H, Z80.REG_L, Z80.REG_A}; for (int i = 0; i < codes.length; i++) { final Z80State state = new Z80State(); state.A = 0x00; state.B = 0x00; state.C = 0x00; state.D = 0x00; state.E = 0x00; state.H = 0x00; state.L = 0x00; state.F = 0x00; state.IX = 0x1000; this.memory[0x1005] = (byte) 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xCB, 0x05, codes[i]); assertEquals(0x10, cpu.getLeft().getRegister(regs[i])); assertMemory(0x1005, 0x10); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(23, cpu.getRight().intValue()); } }
@Test public void testCommand_SET_4_mIYd_r() { final int[] codes = new int[] {0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE7}; final int[] regs = new int[] {Z80.REG_B, Z80.REG_C, Z80.REG_D, Z80.REG_E, Z80.REG_H, Z80.REG_L, Z80.REG_A}; for (int i = 0; i < codes.length; i++) { final Z80State state = new Z80State(); state.A = 0x00; state.B = 0x00; state.C = 0x00; state.D = 0x00; state.E = 0x00; state.H = 0x00; state.L = 0x00; state.F = 0x00; state.IY = 0x1000; this.memory[0x1005] = (byte) 0x00; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xCB, 0x05, codes[i]); assertEquals(0x10, cpu.getLeft().getRegister(regs[i])); assertMemory(0x1005, 0x10); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(23, cpu.getRight().intValue()); } }
@Test public void testCommand_LD_IYh_D() { final Z80State state = new Z80State(); state.D = 0xDD; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x62); assertEquals(0xDD00, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IYl_D() { final Z80State state = new Z80State(); state.D = 0xDD; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x6A); assertEquals(0x00DD, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_D_IYh() { final Z80State state = new Z80State(); state.D = 0xEE; state.IY = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x54); assertEquals(0x12, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_D_IYl() { final Z80State state = new Z80State(); state.D = 0xEE; state.IY = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x55); assertEquals(0x34, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IXh_D() { final Z80State state = new Z80State(); state.D = 0xDD; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x62); assertEquals(0xDD00, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IXh_nn() { final Z80State state = new Z80State(); state.IX = 0xFFFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x26, 0x12); assertEquals(0x12FF, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IXl_nn() { final Z80State state = new Z80State(); state.IX = 0xFFFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x2E, 0x12); assertEquals(0xFF12, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IYh_nn() { final Z80State state = new Z80State(); state.IY = 0xFFFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x26, 0x12); assertEquals(0x12FF, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_LD_mDE_A() { final Z80State state = new Z80State(); state.A = 0x48; state.D = 0x12; state.E = 0x34; this.memory[0x1234] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0x12); assertEquals(0x48, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x48, this.memory[0x1234]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IYl_nn() { final Z80State state = new Z80State(); state.IY = 0xFFFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x2E, 0x12); assertEquals(0xFF12, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IXl_D() { final Z80State state = new Z80State(); state.D = 0xDD; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x6A); assertEquals(0x00DD, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_D_IXh() { final Z80State state = new Z80State(); state.D = 0xEE; state.IX = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x54); assertEquals(0x12, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_D_IXl() { final Z80State state = new Z80State(); state.D = 0xEE; state.IX = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x55); assertEquals(0x34, cpu.getLeft().getRegister(Z80.REG_D)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_LD_L_mIYd() { final Z80State state = new Z80State(); state.IY = 0x25AF; this.memory[0x25C8] = (byte) 0xFE; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x6E, 0x19); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(0x00, cpu.getLeft().getRegister(Z80.REG_H)); assertEquals(0xFE, cpu.getLeft().getRegister(Z80.REG_L)); assertEquals(0x25AF, cpu.getLeft().getRegister(Z80.REG_IY)); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_LD_H_mIYd() { final Z80State state = new Z80State(); state.IY = 0x25AF; this.memory[0x25C8] = (byte) 0xFE; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x66, 0x19); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(0xFE, cpu.getLeft().getRegister(Z80.REG_H)); assertEquals(0x00, cpu.getLeft().getRegister(Z80.REG_L)); assertEquals(0x25AF, cpu.getLeft().getRegister(Z80.REG_IY)); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_LD_L_mIXd() { final Z80State state = new Z80State(); state.IX = 0x25AF; this.memory[0x25C8] = (byte) 0xFE; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x6E, 0x19); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(0x00, cpu.getLeft().getRegister(Z80.REG_H)); assertEquals(0xFE, cpu.getLeft().getRegister(Z80.REG_L)); assertEquals(0x25AF, cpu.getLeft().getRegister(Z80.REG_IX)); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_LD_H_mIXd() { final Z80State state = new Z80State(); state.IX = 0x25AF; this.memory[0x25C8] = (byte) 0xFE; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x66, 0x19); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(0xFE, cpu.getLeft().getRegister(Z80.REG_H)); assertEquals(0x00, cpu.getLeft().getRegister(Z80.REG_L)); assertEquals(0x25AF, cpu.getLeft().getRegister(Z80.REG_IX)); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_LD_SP_IX() { final Z80State state = new Z80State(); state.IX = 0x25AF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xF9); assertEquals(10, cpu.getRight().intValue()); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(0x25AF, cpu.getLeft().getRegister(Z80.REG_IX)); assertEquals(0x25AF, cpu.getLeft().getRegister(Z80.REG_SP)); }
@Test public void testCommand_LD_SP_IY() { final Z80State state = new Z80State(); state.IY = 0x25AF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xF9); assertEquals(10, cpu.getRight().intValue()); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(0x25AF, cpu.getLeft().getRegister(Z80.REG_IY)); assertEquals(0x25AF, cpu.getLeft().getRegister(Z80.REG_SP)); }
@Test public void testCommand_LD_mNN_A() { final Z80State state = new Z80State(); state.A = 0x48; state.D = 0x12; state.E = 0x34; this.memory[0x1234] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0x32, 0x34, 0x12); assertEquals(0x48, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x48, this.memory[0x1234]); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(13, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_I_noZeroAndIFF2False() { final Z80State state = new Z80State(); state.A = 0x48; state.I = 0x12; state.F = 0xFF; state.iff1 = true; state.iff2 = false; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x57); assertEquals(0x12, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(9, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_I_ZeroAndIFF2True() { final Z80State state = new Z80State(); state.A = 0x48; state.I = 0; state.F = 0xFF; state.iff1 = false; state.iff2 = true; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x57); assertEquals(0, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(Z80.FLAG_C | Z80.FLAG_Z | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(9, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_I_NonZeroAndNegativeIFF2True() { final Z80State state = new Z80State(); state.A = 0x48; state.I = -4; state.F = 0xFF; state.iff1 = false; state.iff2 = true; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x57); assertEquals(-4 & 0xFF, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_S | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(9, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_R_noZeroAndIFF2False() { final Z80State state = new Z80State(); state.A = 0x48; state.R = 0x12; state.F = 0xFF; state.iff1 = true; state.iff2 = false; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x5F); assertEquals(0x14, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(Z80.FLAG_C, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(9, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_R_ZeroAndIFF2True() { final Z80State state = new Z80State(); state.A = 0x48; state.R = 0x7F; state.F = 0xFF; state.iff1 = false; state.iff2 = true; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x5F); assertEquals(1, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(Z80.FLAG_C | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(9, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_R_NonZeroAndNegativeIFF2True() { final Z80State state = new Z80State(); state.A = 0x48; state.R = -4; state.F = 0xFF; state.iff1 = false; state.iff2 = true; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x5F); assertEquals(-2 & 0xFF, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_S | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(9, cpu.getRight().intValue()); }
@Test public void testCommand_LD_I_A() { final Z80State state = new Z80State(); state.A = 0x48; state.I = 0; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x47); assertEquals(0x48, cpu.getLeft().getRegister(Z80.REG_I)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(9, cpu.getRight().intValue()); }
@Test public void testCommand_LD_R_A() { final Z80State state = new Z80State(); state.A = 0x48; state.R = 0; final Pair<Z80, Integer> cpu = executeCommand(state, 0xED, 0x4F); assertEquals(0x48, cpu.getLeft().getRegister(Z80.REG_R)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(9, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IX_nn() { final Z80State state = new Z80State(); final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x21, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(14, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IY_nn() { final Z80State state = new Z80State(); final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x21, 0x34, 0x12); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(14, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_C() { final Z80State state = new Z80State(); state.A = 12; state.C = 15; final Pair<Z80, Integer> cpu = executeCommand(state, 0x79); assertEquals(15, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(15, cpu.getLeft().getRegister(Z80.REG_C)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IX_mNN() { final Z80State state = new Z80State(); this.memory[0x1234] = (byte) 0xAA; this.memory[0x1235] = (byte) 0xBB; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x2A, 0x34, 0x12); assertEquals(0xBBAA, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(20, cpu.getRight().intValue()); }
@Test public void testCommand_LD_IY_mNN() { final Z80State state = new Z80State(); this.memory[0x1234] = (byte) 0xAA; this.memory[0x1235] = (byte) 0xBB; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x2A, 0x34, 0x12); assertEquals(0xBBAA, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(20, cpu.getRight().intValue()); }
@Test public void testCommand_PUSH_BC() { final Z80State state = new Z80State(); state.B = 0x22; state.C = 0x33; state.SP = 0x1007; final Pair<Z80, Integer> cpu = executeCommand(state, 0xC5); assertEquals(0x1005, cpu.getLeft().getRegister(Z80.REG_SP)); assertMemory(0x1006, 0x22); assertMemory(0x1005, 0x33); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_PUSH_DE() { final Z80State state = new Z80State(); state.D = 0x22; state.E = 0x33; state.SP = 0x1007; final Pair<Z80, Integer> cpu = executeCommand(state, 0xD5); assertEquals(0x1005, cpu.getLeft().getRegister(Z80.REG_SP)); assertMemory(0x1006, 0x22); assertMemory(0x1005, 0x33); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_PUSH_HL() { final Z80State state = new Z80State(); state.H = 0x22; state.L = 0x33; state.SP = 0x1007; final Pair<Z80, Integer> cpu = executeCommand(state, 0xE5); assertEquals(0x1005, cpu.getLeft().getRegister(Z80.REG_SP)); assertMemory(0x1006, 0x22); assertMemory(0x1005, 0x33); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_PUSH_AF() { final Z80State state = new Z80State(); state.A = 0x22; state.F = 0x33; state.SP = 0x1007; final Pair<Z80, Integer> cpu = executeCommand(state, 0xF5); assertEquals(0x1005, cpu.getLeft().getRegister(Z80.REG_SP)); assertMemory(0x1006, 0x22); assertMemory(0x1005, 0x33); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(11, cpu.getRight().intValue()); }
@Test public void testCommand_PUSH_IX() { final Z80State state = new Z80State(); state.IX = 0x2233; state.SP = 0x1007; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xE5); assertEquals(0x1005, cpu.getLeft().getRegister(Z80.REG_SP)); assertMemory(0x1006, 0x22); assertMemory(0x1005, 0x33); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_PUSH_IY() { final Z80State state = new Z80State(); state.IY = 0x2233; state.SP = 0x1007; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xE5); assertEquals(0x1005, cpu.getLeft().getRegister(Z80.REG_SP)); assertMemory(0x1006, 0x22); assertMemory(0x1005, 0x33); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(15, cpu.getRight().intValue()); }
@Test public void testCommand_POP_IX() { final Z80State state = new Z80State(); state.SP = 0x1000; memory[0x1000] = 0x55; memory[0x1001] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xE1); assertEquals(0x3355, cpu.getLeft().getRegister(Z80.REG_IX)); assertEquals(0x1002, cpu.getLeft().getRegister(Z80.REG_SP)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(14, cpu.getRight().intValue()); }
@Test public void testCommand_POP_IY() { final Z80State state = new Z80State(); state.SP = 0x1000; memory[0x1000] = 0x55; memory[0x1001] = 0x33; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xE1); assertEquals(0x3355, cpu.getLeft().getRegister(Z80.REG_IY)); assertEquals(0x1002, cpu.getLeft().getRegister(Z80.REG_SP)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(14, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_H() { final Z80State state = new Z80State(); state.A = 12; state.H = 15; final Pair<Z80, Integer> cpu = executeCommand(state, 0x7C); assertEquals(15, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(15, cpu.getLeft().getRegister(Z80.REG_H)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_EX_mSP_IX() { final Z80State state = new Z80State(); state.SP = 0x8856; state.IX = 0x7012; memory[0x8856] = 0x11; memory[0x8857] = 0x22; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xE3); assertEquals(0x2211, cpu.getLeft().getRegister(Z80.REG_IX)); assertMemory(0x8856, 0x12); assertMemory(0x8857, 0x70); assertEquals(0x8856, cpu.getLeft().getRegister(Z80.REG_SP)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_EX_mSP_IY() { final Z80State state = new Z80State(); state.SP = 0x8856; state.IY = 0x7012; memory[0x8856] = 0x11; memory[0x8857] = 0x22; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xE3); assertEquals(0x2211, cpu.getLeft().getRegister(Z80.REG_IY)); assertMemory(0x8856, 0x12); assertMemory(0x8857, 0x70); assertEquals(0x8856, cpu.getLeft().getRegister(Z80.REG_SP)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(23, cpu.getRight().intValue()); }
@Test public void testCommand_EX_AF_AF() { final Z80State state = new Z80State(); state.A = 0x10; state.F = 0x20; state.altA = 0x30; state.altF = 0x40; final Pair<Z80, Integer> cpu = executeCommand(state, 0x08); assertEquals(0x30, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x40, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(0x10, cpu.getLeft().getRegister(Z80.REG_A, true)); assertEquals(0x20, cpu.getLeft().getRegister(Z80.REG_F, true)); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_EXX() { final Z80State state = new Z80State(); state.A = 1; state.F = 3; state.B = 0x10; state.C = 0x20; state.D = 0x30; state.E = 0x40; state.H = 0x50; state.L = 0x60; state.IX = 0x61; state.IY = 0x62; state.WZ = 0x1234; state.altA = 2; state.altF = 5; state.altB = 0x70; state.altC = 0x80; state.altD = 0x90; state.altE = 0xA0; state.altH = 0xB0; state.altL = 0xC0; state.altWZ = 0x4321; final Pair<Z80, Integer> cpu = executeCommand(state, 0xD9); assertEquals(0x70, cpu.getLeft().getRegister(Z80.REG_B)); assertEquals(0x80, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x90, cpu.getLeft().getRegister(Z80.REG_D)); assertEquals(0xA0, cpu.getLeft().getRegister(Z80.REG_E)); assertEquals(0xB0, cpu.getLeft().getRegister(Z80.REG_H)); assertEquals(0xC0, cpu.getLeft().getRegister(Z80.REG_L)); assertEquals(0x61, cpu.getLeft().getRegister(Z80.REG_IX)); assertEquals(0x62, cpu.getLeft().getRegister(Z80.REG_IY)); assertEquals(1, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(3, cpu.getLeft().getRegister(Z80.REG_F)); assertEquals(0x10, cpu.getLeft().getRegister(Z80.REG_B, true)); assertEquals(0x20, cpu.getLeft().getRegister(Z80.REG_C, true)); assertEquals(0x30, cpu.getLeft().getRegister(Z80.REG_D, true)); assertEquals(0x40, cpu.getLeft().getRegister(Z80.REG_E, true)); assertEquals(0x50, cpu.getLeft().getRegister(Z80.REG_H, true)); assertEquals(0x60, cpu.getLeft().getRegister(Z80.REG_L, true)); assertEquals(2, cpu.getLeft().getRegister(Z80.REG_A, true)); assertEquals(5, cpu.getLeft().getRegister(Z80.REG_F, true)); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_C_notFlagSet() { final Z80State state = new Z80State(); state.A = 0x44; state.C = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x81); assertEquals(0x11, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x55, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_C_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.C = 0x7F; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x81); assertEquals(0x7F, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0xC3, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_N_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xC6, 0x7F); assertEquals(0xC3, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_mHL_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.F = 0xFF; state.H = 0x12; state.L = 0x34; memory[0x1234] = (byte) 0x7F; final Pair<Z80, Integer> cpu = executeCommand(state, 0x86); assertEquals(0xC3, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_mIXd_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.F = 0xFF; state.IX = 0x1234; memory[0x1237] = (byte) 0x7F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x86, 3); assertEquals(0xC3, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_L() { final Z80State state = new Z80State(); state.A = 12; state.L = 15; final Pair<Z80, Integer> cpu = executeCommand(state, 0x7D); assertEquals(15, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(15, cpu.getLeft().getRegister(Z80.REG_L)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_mIYd_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.F = 0xFF; state.IY = 0x1234; memory[0x1237] = (byte) 0x7F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x86, 3); assertEquals(0xC3, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_ADD_C_flagsZCH() { final Z80State state = new Z80State(); state.A = 0xFF; state.C = 0x01; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x81); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x00, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_Z | Z80.FLAG_C | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_ADC_C_notFlagSet() { final Z80State state = new Z80State(); state.A = 0x44; state.C = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x89); assertEquals(0x11, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x56, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_ADC_C_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.C = 0x7F; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x89); assertEquals(0x7F, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0xC4, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_ADC_N_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xCE, 0x7F); assertEquals(0xC4, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_ADC_mHL_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.L = 0x34; state.H = 0x12; state.F = 0xFF; memory[0x1234] = (byte) 0x7F; final Pair<Z80, Integer> cpu = executeCommand(state, 0x8E); assertEquals(0xC4, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_ADC_mIXd_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.IX = 0x1234; state.F = 0xFF; memory[0x1238] = (byte) 0x7F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x8E, 0x04); assertEquals(0xC4, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_ADC_mIYd_flagV() { final Z80State state = new Z80State(); state.A = 0x44; state.IY = 0x1234; state.F = 0xFF; memory[0x1238] = (byte) 0x7F; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x8E, 0x04); assertEquals(0xC4, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_ADC_C_flagsCH() { final Z80State state = new Z80State(); state.A = 0xFF; state.C = 0x01; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x89); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_C | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_SUB_C() { final Z80State state = new Z80State(); state.A = 0x29; state.C = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x91); assertEquals(0x11, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x18, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_IXh() { final Z80State state = new Z80State(); state.A = 0xFF; state.IX = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x7C); assertEquals(0x12, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_SUB_n() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xD6, 0x11); assertEquals(0x18, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_SUB_mHL() { final Z80State state = new Z80State(); state.A = 0x29; state.L = 0x34; state.H = 0x12; memory[0x1234] = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x96); assertEquals(0x18, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_SUB_mIX() { final Z80State state = new Z80State(); state.A = 0x29; state.IX = 0x1234; memory[0x1239] = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x96, 0x05); assertEquals(0x18, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_SUB_mIY() { final Z80State state = new Z80State(); state.A = 0x29; state.IY = 0x1234; memory[0x1239] = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x96, 0x05); assertEquals(0x18, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_SBC_C() { final Z80State state = new Z80State(); state.A = 0x29; state.C = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0x99); assertEquals(0x11, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x17, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_SBC_N() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDE, 0x11); assertEquals(0x17, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_SBC_mHL() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; state.L = 0x34; state.H = 0x12; memory[0x1234] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0x9E); assertEquals(0x17, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_SBC_mIXd() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; state.IX = 0x1234; memory[0x1237] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x9E, 0x03); assertEquals(0x17, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_SBC_mIYd() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; state.IY = 0x1234; memory[0x1237] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x9E, 0x03); assertEquals(0x17, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_AND_C() { final Z80State state = new Z80State(); state.A = 0x29; state.C = 0x11; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xA1); assertEquals(0x11, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_IXl() { final Z80State state = new Z80State(); state.A = 0xFF; state.IX = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0x7D); assertEquals(0x34, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_IX)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_AND_C_ZeroResult() { final Z80State state = new Z80State(); state.A = 0xF0; state.C = 0x0F; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xA1); assertEquals(0x0F, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x00, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_Z | Z80.FLAG_H | Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_AND_C_ParityFalse() { final Z80State state = new Z80State(); state.A = 0x07; state.C = 0x09; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xA1); assertEquals(0x09, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_AND_N() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xE6, 0x11); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_AND_mHL() { final Z80State state = new Z80State(); state.A = 0x29; state.L = 0x34; state.H = 0x12; state.F = 0xFF; memory[0x1234] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xA6); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_AND_mIXd() { final Z80State state = new Z80State(); state.A = 0x29; state.IX = 0x1234; state.F = 0xFF; memory[0x1239] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xA6, 0x05); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_AND_mIYd() { final Z80State state = new Z80State(); state.A = 0x29; state.IY = 0x1234; state.F = 0xFF; memory[0x1239] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xA6, 0x05); assertEquals(0x01, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_OR_C() { final Z80State state = new Z80State(); state.A = 0x07; state.C = 0x09; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xB1); assertEquals(0x09, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x0F, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_OR_n() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xF6, 0x11); assertEquals(0x39, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_OR_mHL() { final Z80State state = new Z80State(); state.A = 0x29; state.L = 0x34; state.H = 0x12; state.F = 0xFF; memory[0x1234] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xB6); assertEquals(0x39, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_OR_mIXd() { final Z80State state = new Z80State(); state.A = 0x29; state.IX = 0x1234; state.F = 0xFF; memory[0x1239] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xB6, 0x05); assertEquals(0x39, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_IYh() { final Z80State state = new Z80State(); state.A = 0xFF; state.IY = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x7C); assertEquals(0x12, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }
@Test public void testCommand_OR_mIYd() { final Z80State state = new Z80State(); state.A = 0x29; state.IY = 0x1234; state.F = 0xFF; memory[0x1239] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xB6, 0x05); assertEquals(0x39, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_PV, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_XOR_C() { final Z80State state = new Z80State(); state.A = 0x07; state.C = 0x09; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xA9); assertEquals(0x09, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0x0E, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_XOR_n() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xEE, 0x11); assertEquals(0x38, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_XOR_mHL() { final Z80State state = new Z80State(); state.A = 0x29; state.L = 0x34; state.H = 0x12; state.F = 0xFF; memory[0x1234] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xAE); assertEquals(0x38, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_XOR_mIXd() { final Z80State state = new Z80State(); state.A = 0x29; state.IX = 0x1234; state.F = 0xFF; memory[0x1239] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xDD, 0xAE, 0x05); assertEquals(0x38, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_XOR_mIYd() { final Z80State state = new Z80State(); state.A = 0x29; state.IY = 0x1234; state.F = 0xFF; memory[0x1239] = 0x11; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0xAE, 0x05); assertEquals(0x38, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(0, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(19, cpu.getRight().intValue()); }
@Test public void testCommand_CP_C_Equals() { final Z80State state = new Z80State(); state.A = 0xF7; state.C = 0xF7; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xB9); assertEquals(0xF7, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0xF7, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(Z80.FLAG_Z | FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_CP_C_More() { final Z80State state = new Z80State(); state.A = 0xF7; state.C = 0xF8; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xB9); assertEquals(0xF8, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0xF7, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N | Z80.FLAG_C | Z80.FLAG_S | Z80.FLAG_H, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_CP_C_Less() { final Z80State state = new Z80State(); state.A = 0xF7; state.C = 0xF6; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xB9); assertEquals(0xF6, cpu.getLeft().getRegister(Z80.REG_C)); assertEquals(0xF7, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(4, cpu.getRight().intValue()); }
@Test public void testCommand_CP_n() { final Z80State state = new Z80State(); state.A = 0x29; state.F = 0xFF; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFE, 0x11); assertEquals(0x29, cpu.getLeft().getRegister(Z80.REG_A)); assertFlagsExcludeReserved(FLAG_N, cpu.getLeft().getRegister(Z80.REG_F) & 0xFF); assertEquals(7, cpu.getRight().intValue()); }
@Test public void testCommand_LD_A_IYl() { final Z80State state = new Z80State(); state.A = 0xFF; state.IY = 0x1234; final Pair<Z80, Integer> cpu = executeCommand(state, 0xFD, 0x7D); assertEquals(0x34, cpu.getLeft().getRegister(Z80.REG_A)); assertEquals(0x1234, cpu.getLeft().getRegister(Z80.REG_IY)); assertFlagsNotChanged(state, cpu.getLeft()); assertEquals(8, cpu.getRight().intValue()); }