gb-emu-lib/CPU.cpp
unsigned long CPU::CPr(const byte& opCode)
{
    byte* r = GetByteRegister(opCode);
    byte A = GetHighByte(m_AF);
    byte result = A - (*r);

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

    return 4;
}
/*
    CP r
    10111rrr

    The contents of 8-bit register r 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.

    4 Cycles

    Flags affected(znhc): z1hc
*/


The contents of 8-bit register r 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.

4 Cycles


The contents of 8 - bit register r 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 . 4 Cycles
unsigned long CPU::CPr(const byte& opCode)
{
    byte* r = GetByteRegister(opCode);
    byte A = GetHighByte(m_AF);
    byte result = A - (*r);
    (result == 0x00) ? SetFlag(ZeroFlag) : ClearFlag(ZeroFlag);
    SetFlag(SubtractFlag);
    ((A & 0xFF) < ((*r) & 0xFF)) ? SetFlag(CarryFlag) : ClearFlag(CarryFlag);
    ((A & 0x0F) < ((*r) & 0x0F)) ? SetFlag(HalfCarryFlag) : ClearFlag(HalfCarryFlag);
    return 4;
}
unsigned long CPU :: CPr ( const byte & opCode ) { byte * r = GetByteRegister ( opCode ) ; byte A = GetHighByte ( m_AF ) ; byte result = A - ( * r ) ; ( result == 0x00 ) ? SetFlag ( ZeroFlag ) : ClearFlag ( ZeroFlag ) ; SetFlag ( SubtractFlag ) ; ( ( A & 0xFF ) < ( ( * r ) & 0xFF ) ) ? SetFlag ( CarryFlag ) : ClearFlag ( CarryFlag ) ; ( ( A & 0x0F ) < ( ( * r ) & 0x0F ) ) ? SetFlag ( HalfCarryFlag ) : ClearFlag ( HalfCarryFlag ) ; return 4 ; }
CP r
10111rrr
CP r 10111rrr