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

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

    return 8;
}
/*
    SUB n - 0xD6

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

    8 Cycles

    Flags affected(znhc): z1hc
*/
SUB n - 0xD6
The 8-bit value n is subtracted from the contents of the Accumulator, and the
result is stored in the accumulator.

8 Cycles


SUB n - 0xD6 The 8 - bit value n is subtracted from the contents of the Accumulator and the result is stored in the accumulator . 8 Cycles
unsigned long CPU::SUBn(const byte& opCode)
{
    byte n = ReadBytePC();
    byte A = GetHighByte(m_AF);
    byte result = A - n;
    SetHighByte(&m_AF, result);
    (result == 0x00) ? SetFlag(ZeroFlag) : ClearFlag(ZeroFlag);
    SetFlag(SubtractFlag);
    ((A & 0x0F) < (n & 0x0F)) ? SetFlag(HalfCarryFlag) : ClearFlag(HalfCarryFlag);
    ((A & 0xFF) < (n & 0xFF)) ? SetFlag(CarryFlag) : ClearFlag(CarryFlag);
    return 8;
}
unsigned long CPU :: SUBn ( const byte & opCode ) { byte n = ReadBytePC ( ) ; byte A = GetHighByte ( m_AF ) ; byte result = A - n ; SetHighByte ( & m_AF , result ) ; ( result == 0x00 ) ? SetFlag ( ZeroFlag ) : ClearFlag ( ZeroFlag ) ; SetFlag ( SubtractFlag ) ; ( ( A & 0x0F ) < ( n & 0x0F ) ) ? SetFlag ( HalfCarryFlag ) : ClearFlag ( HalfCarryFlag ) ; ( ( A & 0xFF ) < ( n & 0xFF ) ) ? SetFlag ( CarryFlag ) : ClearFlag ( CarryFlag ) ; return 8 ; }
SUB n - 0xD6
The 8-bit value n is subtracted from the contents of the Accumulator, and the
result is stored in the accumulator.
SUB n - 0xD6 The 8 - bit value n is subtracted from the contents of the Accumulator and the result is stored in the accumulator .