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

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

    return 4;
}
/*
    SUB r
    10010rrr

    The 8-bit register r is subtracted from the contents of the Accumulator, and the
    result is stored in the accumulator.

    4 Cycles

    Flags affected(znhc): z1hc
*/


The 8-bit register r is subtracted from the contents of the Accumulator, and the
result is stored in the accumulator.

4 Cycles


The 8 - bit register r is subtracted from the contents of the Accumulator and the result is stored in the accumulator . 4 Cycles
unsigned long CPU::SUBr(const byte& opCode)
{
    byte* r = GetByteRegister(opCode);
    byte A = GetHighByte(m_AF);
    byte result = A - (*r);
    SetHighByte(&m_AF, result);
    (result == 0x00) ? SetFlag(ZeroFlag) : ClearFlag(ZeroFlag);
    SetFlag(SubtractFlag);
    ((A & 0x0F) < ((*r) & 0x0F)) ? SetFlag(HalfCarryFlag) : ClearFlag(HalfCarryFlag);
    ((A & 0xFF) < ((*r) & 0xFF)) ? SetFlag(CarryFlag) : ClearFlag(CarryFlag);
    return 4;
}
unsigned long CPU :: SUBr ( const byte & opCode ) { byte * r = GetByteRegister ( opCode ) ; byte A = GetHighByte ( m_AF ) ; byte result = A - ( * r ) ; SetHighByte ( & m_AF , result ) ; ( result == 0x00 ) ? SetFlag ( ZeroFlag ) : ClearFlag ( ZeroFlag ) ; SetFlag ( SubtractFlag ) ; ( ( A & 0x0F ) < ( ( * r ) & 0x0F ) ) ? SetFlag ( HalfCarryFlag ) : ClearFlag ( HalfCarryFlag ) ; ( ( A & 0xFF ) < ( ( * r ) & 0xFF ) ) ? SetFlag ( CarryFlag ) : ClearFlag ( CarryFlag ) ; return 4 ; }
SUB r
10010rrr
SUB r 10010rrr