mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-22 23:26:33 +11:00
Add implementation of set bits to save bit twiddling
This commit is contained in:
parent
5543f1a7b0
commit
404be633c1
1 changed files with 20 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use core::ops;
|
||||||
|
|
||||||
pub struct MemoryMapped<T> {
|
pub struct MemoryMapped<T> {
|
||||||
address: *mut T,
|
address: *mut T,
|
||||||
}
|
}
|
||||||
|
@ -18,6 +20,24 @@ impl<T> MemoryMapped<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> MemoryMapped<T>
|
||||||
|
where
|
||||||
|
T: From<u8>
|
||||||
|
+ Copy
|
||||||
|
+ ops::Shl<Output = T>
|
||||||
|
+ ops::BitAnd<Output = T>
|
||||||
|
+ ops::Sub<Output = T>
|
||||||
|
+ ops::BitOr<Output = T>
|
||||||
|
+ ops::Not<Output = T>,
|
||||||
|
{
|
||||||
|
pub fn set_bits(&self, value: T, length: T, shift: T) {
|
||||||
|
let one: T = 1u8.into();
|
||||||
|
let mask: T = (one << length) - one;
|
||||||
|
let current_val = self.get();
|
||||||
|
self.set((current_val & !(mask << shift)) | ((value & mask) << shift));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct MemoryMapped1DArray<T, const N: usize> {
|
pub struct MemoryMapped1DArray<T, const N: usize> {
|
||||||
array: *mut [T; N],
|
array: *mut [T; N],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue