gb-emu-lib/CPU.cpp
unsigned long CPU::SUB_HL_(const byte& opCode)
{
    byte A = GetHighByte(m_AF);
    byte HL = m_MMU->Read(m_HL);
    byte result = A - HL;
    SetHighByte(&m_AF, result);

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

    return 8;
}
/*
    SUB (HL) - 0x96

    The byte at the memory address specified by the contents of the HL register pair
    is subtracted to the contents of the accumulator, and the result is stored in the
    accumulator.

    8 Cycles

    Flags affected(znhc): z1hc
*/
SUB (HL) - 0x96
The byte at the memory address specified by the contents of the HL register pair
is subtracted to the contents of the accumulator, and the result is stored in the
accumulator.

8 Cycles


SUB ( HL ) - 0x96 The byte at the memory address specified by the contents of the HL register pair is subtracted to the contents of the accumulator and the result is stored in the accumulator . 8 Cycles
unsigned long CPU::SUB_HL_(const byte& opCode)
{
    byte A = GetHighByte(m_AF);
    byte HL = m_MMU->Read(m_HL);
    byte result = A - HL;
    SetHighByte(&m_AF, result);
    (result == 0x00) ? SetFlag(ZeroFlag) : ClearFlag(ZeroFlag);
    SetFlag(SubtractFlag);
    ((A & 0x0F) < (result & 0x0F)) ? SetFlag(HalfCarryFlag) : ClearFlag(HalfCarryFlag);
    ((A & 0xFF) < (result & 0xFF)) ? SetFlag(CarryFlag) : ClearFlag(CarryFlag);
    return 8;
}
unsigned long CPU :: SUB_HL_ ( const byte & opCode ) { byte A = GetHighByte ( m_AF ) ; byte HL = m_MMU -> Read ( m_HL ) ; byte result = A - HL ; SetHighByte ( & m_AF , result ) ; ( result == 0x00 ) ? SetFlag ( ZeroFlag ) : ClearFlag ( ZeroFlag ) ; SetFlag ( SubtractFlag ) ; ( ( A & 0x0F ) < ( result & 0x0F ) ) ? SetFlag ( HalfCarryFlag ) : ClearFlag ( HalfCarryFlag ) ; ( ( A & 0xFF ) < ( result & 0xFF ) ) ? SetFlag ( CarryFlag ) : ClearFlag ( CarryFlag ) ; return 8 ; }
SUB (HL) - 0x96
The byte at the memory address specified by the contents of the HL register pair
is subtracted to the contents of the accumulator, and the result is stored in the
accumulator.
SUB ( HL ) - 0x96 The byte at the memory address specified by the contents of the HL register pair is subtracted to the contents of the accumulator and the result is stored in the accumulator .