gb-emu-lib/CPU.cpp
unsigned long CPU::CPn(const byte& opCode)
{
    byte n = ReadBytePC();
    byte A = GetHighByte(m_AF);
    byte result = A - n;

    (result == 0x00) ? SetFlag(ZeroFlag) : ClearFlag(ZeroFlag);
    ((A & 0xFF) < (n & 0xFF)) ? SetFlag(CarryFlag) : ClearFlag(CarryFlag);
    ((A & 0x0F) < (n & 0x0F)) ? SetFlag(HalfCarryFlag) : ClearFlag(HalfCarryFlag);
    SetFlag(SubtractFlag);

    return 8;
}
/*
    CP n - 0xFE

    The contents of 8-bit operand n are compared with the contents of the accumulator.
    If there is a true compare, the Z flag is set. The execution of this instruction
    does not affect the contents of the accumulator.

    8 Cycles

    Flags affected(znhc): z1hc
*/
CP n - 0xFE
The contents of 8-bit operand n are compared with the contents of the accumulator.
If there is a true compare, the Z flag is set. The execution of this instruction
does not affect the contents of the accumulator.

8 Cycles


CP n - 0xFE The contents of 8 - bit operand n are compared with the contents of the accumulator . If there is a true compare the Z flag is set . The execution of this instruction does not affect the contents of the accumulator . 8 Cycles
unsigned long CPU::CPn(const byte& opCode)
{
    byte n = ReadBytePC();
    byte A = GetHighByte(m_AF);
    byte result = A - n;
    (result == 0x00) ? SetFlag(ZeroFlag) : ClearFlag(ZeroFlag);
    ((A & 0xFF) < (n & 0xFF)) ? SetFlag(CarryFlag) : ClearFlag(CarryFlag);
    ((A & 0x0F) < (n & 0x0F)) ? SetFlag(HalfCarryFlag) : ClearFlag(HalfCarryFlag);
    SetFlag(SubtractFlag);
    return 8;
}
unsigned long CPU :: CPn ( const byte & opCode ) { byte n = ReadBytePC ( ) ; byte A = GetHighByte ( m_AF ) ; byte result = A - n ; ( result == 0x00 ) ? SetFlag ( ZeroFlag ) : ClearFlag ( ZeroFlag ) ; ( ( A & 0xFF ) < ( n & 0xFF ) ) ? SetFlag ( CarryFlag ) : ClearFlag ( CarryFlag ) ; ( ( A & 0x0F ) < ( n & 0x0F ) ) ? SetFlag ( HalfCarryFlag ) : ClearFlag ( HalfCarryFlag ) ; SetFlag ( SubtractFlag ) ; return 8 ; }
CP n - 0xFE
The contents of 8-bit operand n are compared with the contents of the accumulator.
CP n - 0xFE The contents of 8 - bit operand n are compared with the contents of the accumulator .