pub(super) fn offset_addr(addr: u16, offset: i8) -> (u16, Flags) {
    // Perform sign-extension, then treat as u16.
    let offset = offset as i16 as u16;

    // JR ignores flags, SP+i8 is used in two instructions and sets flags for carry and half carry
    // based on the lower byte.
    let mut flags = Flags::empty();
    if (addr & 0xf) + (offset & 0xf) > 0xf {
        flags |= Flags::HALFCARRY;
    }
    // Since we're working on 16 bits, we calculate CARRY for the lower byte the same way we
    // typically do a HALFCARRY.
    if (addr & 0xff) + (offset & 0xff) > 0xff {
        flags |= Flags::CARRY;
    }

    // In two's compliment, adding a negative is the same as adding with wraparound.
    (addr.wrapping_add(offset), flags)
}
/// Get the result of applying an 8 bit offset to a 16 bit address.
/// * ZERO is never set.
/// * SUB is never set.
/// * CARRY is set based on the low order byte.
/// * HALFCARRY is set based on the lower order byte.
/// Carries are determined as if adding (using two's compliment).
Get the result of applying an 8 bit offset to a 16 bit address.
ZERO is never set.
SUB is never set.
CARRY is set based on the low order byte.
HALFCARRY is set based on the lower order byte.
Carries are determined as if adding (using two's compliment).
Get the result of applying an 8 bit offset to a 16 bit address . ZERO is never set . SUB is never set . CARRY is set based on the low order byte . HALFCARRY is set based on the lower order byte . Carries are determined as if adding ( using two ' s compliment ) .
pub(super) fn offset_addr(addr: u16, offset: i8) -> (u16, Flags) {
    // Perform sign-extension, then treat as u16.
    let offset = offset as i16 as u16;
    // JR ignores flags, SP+i8 is used in two instructions and sets flags for carry and half carry
    // based on the lower byte.
    let mut flags = Flags::empty();
    if (addr & 0xf) + (offset & 0xf) > 0xf {
        flags |= Flags::HALFCARRY;
    }
    // Since we're working on 16 bits, we calculate CARRY for the lower byte the same way we
    // typically do a HALFCARRY.
    if (addr & 0xff) + (offset & 0xff) > 0xff {
        flags |= Flags::CARRY;
    }
    // In two's compliment, adding a negative is the same as adding with wraparound.
    (addr.wrapping_add(offset), flags)
}
pub ( super ) fn offset_addr ( addr : u16 , offset : i8 ) -> ( u16 , Flags ) { // Perform sign-extension, then treat as u16. let offset = offset as i16 as u16 ; // JR ignores flags, SP+i8 is used in two instructions and sets flags for carry and half carry // based on the lower byte. let mut flags = Flags :: empty ( ) ; if ( addr & 0xf ) + ( offset & 0xf ) > 0xf { flags |= Flags :: HALFCARRY ; } // Since we're working on 16 bits, we calculate CARRY for the lower byte the same way we // typically do a HALFCARRY. if ( addr & 0xff ) + ( offset & 0xff ) > 0xff { flags |= Flags :: CARRY ; } // In two's compliment, adding a negative is the same as adding with wraparound. ( addr . wrapping_add ( offset ) , flags ) }
Get the result of applying an 8 bit offset to a 16 bit address.
Get the result of applying an 8 bit offset to a 16 bit address .
addr
u16
offset
i8
addr
u16
offset
i8