use crate::ppu::oam::entry::{Attributes, TileIndexNumber};
use crate::ppu::oam::{Entry, Iter, OAM_ARRAY_ENTRIES_COUNT};
const OAM_ARRAY_ENTRY_SIZE: usize = 4;
pub struct OamArrayRaw {
data: [u8; OAM_ARRAY_ENTRY_SIZE * OAM_ARRAY_ENTRIES_COUNT],
}
impl Default for OamArrayRaw {
fn default() -> Self {
Self {
data: [u8::default(); OAM_ARRAY_ENTRY_SIZE * OAM_ARRAY_ENTRIES_COUNT],
}
}
}
#[allow(dead_code)]
impl OamArrayRaw {
pub fn new() -> Self {
Self::default()
}
pub fn data(&self, addr: u8) -> u8 {
self.data[addr as usize]
}
pub fn write_data(&mut self, addr: u8, data: u8) {
self.data[addr as usize] = data;
}
pub fn y(&self, sprite_index: u8) -> u8 {
let addr = (sprite_index << 2) as usize;
self.data[addr]
}
pub fn tile_number(&self, sprite_index: u8) -> TileIndexNumber {
let addr = (sprite_index << 2) as usize;
self.data[addr + 1].into()
}
pub fn attributes(&self, sprite_index: u8) -> Attributes {
let addr = (sprite_index << 2) as usize;
Attributes::from_bits_truncate(self.data[addr + 2])
}
pub fn x(&self, sprite_index: u8) -> u8 {
let addr = (sprite_index << 2) as usize;
self.data[addr + 3]
}
pub fn entry(&self, sprite_index: u8) -> Entry {
let addr = (sprite_index << 2) as usize;
Entry::with_data(
self.data[addr],
self.data[addr + 1],
Attributes::from_bits_truncate(self.data[addr + 2]),
self.data[addr + 3],
)
}
pub fn iter(&self) -> Iter<'_> {
Iter {
array: self,
index: 0,
}
}
}