Simplify half carry checking logic
parent
dcf13061c6
commit
418a659e07
|
@ -28,15 +28,16 @@ impl CarryingAdd<u8, u16> for u16 {
|
||||||
// NOTE: These generics are not as generic as they could be. The Into<u16> is just a shortcut because we
|
// NOTE: These generics are not as generic as they could be. The Into<u16> is just a shortcut because we
|
||||||
// only use up to u16s
|
// only use up to u16s
|
||||||
fn did_8bit_half_carry<L: Into<u16>, R: Into<u16>>(lhs: L, rhs: R) -> bool {
|
fn did_8bit_half_carry<L: Into<u16>, R: Into<u16>>(lhs: L, rhs: R) -> bool {
|
||||||
// https://robdor.com/2016/08/10/gameboy-emulator-half-carry-flag/
|
// https://stackoverflow.com/a/7261149/1103734
|
||||||
((lhs.into() & 0xf) + (rhs.into() & 0xf)) & 0x10 == 0x10
|
(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.
|
/// `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<u16> is just a shortcut because we
|
// NOTE: These generics are not as generic as they could be. The Into<u16> is just a shortcut because we
|
||||||
// only use up to u16s
|
// only use up to u16s
|
||||||
fn did_8bit_full_carry<L: Into<u16>, R: Into<u16>>(lhs: L, rhs: R) -> bool {
|
fn did_8bit_full_carry<L: Into<u16>, R: Into<u16>>(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)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in New Issue