cge_nes 0.1.1

Cycle-accurate NES (Nintendo Entertainment System) emulator library: CPU, PPU, cartridge, input, and iNES ROM loading.
Documentation
//! Object Attribute Memory (OAM) handling for sprite data.
//!
//! This module provides types and implementations for managing the NES PPU's
//! Object Attribute Memory (OAM), which stores up to 64 sprite entries.
//!
//! Two implementations are provided behind a feature flag:
//! * `OamArray`: a typed, in-memory array of Entry values.
//! * `OamArrayRaw`: a raw byte-backed representation that mirrors the
//!   hardware layout (selected with the `oam_array_raw` feature).

mod entry;

#[cfg(test)]
mod tests;

#[cfg(not(feature = "oam_array_raw"))]
mod oam_array;

#[cfg(feature = "oam_array_raw")]
mod oam_array_raw;

pub use entry::Entry;

#[cfg(not(feature = "oam_array_raw"))]
pub use oam_array::OamArray;

#[cfg(feature = "oam_array_raw")]
pub use oam_array_raw::OamArrayRaw as OamArray;

/// Number of sprite entries in OAM (hardware constant).
const OAM_ARRAY_ENTRIES_COUNT: usize = 64;

/// Iterator over all entries in an OAM array.
///
/// Produces a copy of each `Entry` in sequence from index 0..63.
pub struct Iter<'a> {
    array: &'a OamArray,
    index: u8,
}

impl<'a> Iterator for Iter<'a> {
    type Item = Entry;

    fn next(&mut self) -> Option<Self::Item> {
        if self.index < (OAM_ARRAY_ENTRIES_COUNT as u8) {
            self.index += 1;
            return Some(self.array.entry(self.index - 1));
        }

        None
    }
}