mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 01:21:34 +11:00
add bitarray implementation
This commit is contained in:
parent
9286378a36
commit
8bf59e0f20
24
agb/src/bitarray.rs
Normal file
24
agb/src/bitarray.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
pub struct Bitarray<const N: usize> {
|
||||
a: [u32; N],
|
||||
}
|
||||
|
||||
impl<const N: usize> Bitarray<N> {
|
||||
pub fn new() -> Self {
|
||||
Bitarray { a: [0; N] }
|
||||
}
|
||||
|
||||
pub fn get(&self, index: usize) -> Option<bool> {
|
||||
if index < N * 32 {
|
||||
Some((self.a[index / N] >> (N % 32) & 1) != 0)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(&mut self, index: usize, value: bool) {
|
||||
let value = value as u32;
|
||||
let mask = 1 << (N % 32);
|
||||
let value_mask = value << (N % 32);
|
||||
self.a[index / N] = self.a[index / N] & !mask | value_mask
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ pub mod input;
|
|||
/// Implements sound output.
|
||||
pub mod sound;
|
||||
|
||||
mod bitarray;
|
||||
mod interrupt;
|
||||
mod memory_mapped;
|
||||
/// Implements logging to the mgba emulator.
|
||||
|
|
Loading…
Reference in a new issue