pub fn alu_sub_8bit(accumulator: u8, flags: Flags, d8: u8, use_carry: bool) -> (u8, Flags) {
    let cy = if use_carry && flags.contains(Flags::CARRY) {
        1
    } else {
        0
    };

    let signed_result = accumulator as i16 - d8 as i16 - cy as i16;
    let result = signed_result as u8;

    let mut new_flags = flags;
    new_flags.set(Flags::ZERO, result == 0);
    new_flags.set(Flags::SUBTRACT, true);
    new_flags.set(Flags::HALF_CARRY, (accumulator & 0x0F) < (d8 & 0x0F) + cy);
    new_flags.set(Flags::CARRY, signed_result < 0);

    (result, new_flags)
}
/// Subtract 8-bit value from register A, storing the result in A.
/// If use_carry is true this will subtract the content of the carry flag along with the value and
/// take that into account when updating flags too.
///
/// Update flags:
///
/// ## Flags::ZERO
///
/// Set if the result equals zero.
///
/// ## Flags::SUBTRACT
///
/// Always set
///
/// ## Flags::HALF_CARRY
///
/// Set if the lower nibble of the value subtracted from the lower nibble of A would have attempted
/// to borrow a bit. i.e. the lower nibble of the value is larger than the lower nibble of A.
///set
/// ## Flags::CARRY
///
/// Set if the value subtracted from A would have required a borrow, otherwise reset
///
Subtract 8-bit value from register A, storing the result in A.
If use_carry is true this will subtract the content of the carry flag along with the value and
take that into account when updating flags too.

Update flags.

:ZERO

Set if the result equals zero.

:SUBTRACT

Always set



Set if the lower nibble of the value subtracted from the lower nibble of A would have attempted
to borrow a bit.

Set if the value subtracted from A would have required a borrow, otherwise reset
Subtract 8 - bit value from register A storing the result in A . If use_carry is true this will subtract the content of the carry flag along with the value and take that into account when updating flags too . Update flags . : ZERO Set if the result equals zero . : SUBTRACT Always set Set if the lower nibble of the value subtracted from the lower nibble of A would have attempted to borrow a bit . Set if the value subtracted from A would have required a borrow otherwise reset
pub fn alu_sub_8bit(accumulator: u8, flags: Flags, d8: u8, use_carry: bool) -> (u8, Flags) {
    let cy = if use_carry && flags.contains(Flags::CARRY) {
        1
    } else {
        0
    };
    let signed_result = accumulator as i16 - d8 as i16 - cy as i16;
    let result = signed_result as u8;
    let mut new_flags = flags;
    new_flags.set(Flags::ZERO, result == 0);
    new_flags.set(Flags::SUBTRACT, true);
    new_flags.set(Flags::HALF_CARRY, (accumulator & 0x0F) < (d8 & 0x0F) + cy);
    new_flags.set(Flags::CARRY, signed_result < 0);
    (result, new_flags)
}
pub fn alu_sub_8bit ( accumulator : u8 , flags : Flags , d8 : u8 , use_carry : bool ) -> ( u8 , Flags ) { let cy = if use_carry && flags . contains ( Flags :: CARRY ) { 1 } else { 0 } ; let signed_result = accumulator as i16 - d8 as i16 - cy as i16 ; let result = signed_result as u8 ; let mut new_flags = flags ; new_flags . set ( Flags :: ZERO , result == 0 ) ; new_flags . set ( Flags :: SUBTRACT , true ) ; new_flags . set ( Flags :: HALF_CARRY , ( accumulator & 0x0F ) < ( d8 & 0x0F ) + cy ) ; new_flags . set ( Flags :: CARRY , signed_result < 0 ) ; ( result , new_flags ) }
Subtract 8-bit value from register A, storing the result in A.
Subtract 8 - bit value from register A storing the result in A .
accumulator
u8
flags
Flags
d8
u8
use_carry
bool
accumulator
u8
flags
Flags
d8
u8
use_carry
bool