diff --git a/src/cpu/run/arithutil.rs b/src/cpu/run/arithutil.rs index fc3a63d..f7943a7 100644 --- a/src/cpu/run/arithutil.rs +++ b/src/cpu/run/arithutil.rs @@ -28,15 +28,16 @@ impl CarryingAdd for u16 { // NOTE: These generics are not as generic as they could be. The Into is just a shortcut because we // only use up to u16s fn did_8bit_half_carry, R: Into>(lhs: L, rhs: R) -> bool { - // https://robdor.com/2016/08/10/gameboy-emulator-half-carry-flag/ - ((lhs.into() & 0xf) + (rhs.into() & 0xf)) & 0x10 == 0x10 + // https://stackoverflow.com/a/7261149/1103734 + (lhs.into() & 0xf) + (rhs.into() & 0xf) > 0xf } /// `did_8_bit_full_carry` checks whether or not the given addition would have done an 8 bit carry. // NOTE: These generics are not as generic as they could be. The Into is just a shortcut because we // only use up to u16s fn did_8bit_full_carry, R: Into>(lhs: L, rhs: R) -> bool { - (((lhs.into() & 0xff) + (rhs.into() & 0xff)) & 0x100) == 0x100 + // https://stackoverflow.com/a/7261149/1103734 + ((lhs.into() & 0xff) + (rhs.into() & 0xff)) > 0xff } #[cfg(test)]