diff --git a/agb/src/memory_mapped.rs b/agb/src/memory_mapped.rs index 57b5bb51..290d865f 100644 --- a/agb/src/memory_mapped.rs +++ b/agb/src/memory_mapped.rs @@ -38,6 +38,21 @@ where } } +pub fn set_bits(current_value: T, value: T, length: usize, shift: usize) -> T +where + T: From + + Copy + + ops::Shl + + ops::BitAnd + + ops::Sub + + ops::BitOr + + ops::Not, +{ + let one: T = 1u8.into(); + let mask: T = (one << length) - one; + (current_value & !(mask << shift)) | ((value & mask) << shift) +} + pub struct MemoryMapped1DArray { array: *mut [T; N], }