cge_nes 0.1.2

Cycle-accurate NES (Nintendo Entertainment System) emulator library: CPU, PPU, cartridge, input, and iNES ROM loading.
Documentation
//! Memory mapper implementations for different NES cartridge types.
//!
//! Memory mappers (also known as Memory Management Controllers or MMCs) are circuits
//! inside NES cartridges that expand the capabilities of the basic hardware by
//! allowing bank switching of PRG ROM and CHR ROM/RAM.
//!
//! # Supported Mappers
//!
//! Currently implements the following mappers:
//!
//! ## Mapper 0 (NROM)
//! - The simplest mapper with no bank switching
//! - Up to 32KB PRG ROM and 8KB CHR ROM
//! - Used by games like Super Mario Bros. and Donkey Kong
//!
//! ## Mapper 1 (MMC1)
//! - Supports PRG ROM banking (16KB or 32KB)
//! - Supports CHR ROM/RAM banking (4KB or 8KB)
//! - PRG RAM battery backup
//! - Used by games like Legend of Zelda and Mega Man 2
//!
//! ## Mapper 2 (UxROM)
//! - PRG ROM banking only (16KB fixed + 16KB switchable)
//! - No CHR ROM banking (CHR RAM only)
//! - Used by games like Mega Man and Castlevania
//!
//! ## Mapper 3 (CNROM)
//! - No PRG ROM banking (32KB fixed)
//! - CHR ROM banking only (8KB banks)
//! - Used by games like Arkanoid and Cybernoid
//!
//! ## Mapper 4 (MMC3)
//! - PRG ROM banking in 8KB units with one fixed bank
//! - CHR ROM/RAM banking in 1KB or 2KB units
//! - Scanline-based IRQ counter
//! - Configurable name table mirroring
//! - Used by games like Super Mario Bros. 2/3 and Kirby's Adventure
//!
//! Each mapper implementation provides a `load` function that creates a cartridge
//! instance from the ROM data and header information.

use devices6502::size_const::*;
use devices6502::{Adjacent, Mirror, Ram};

pub mod basic_mapper;
pub mod mapper001;
/// MMC3 (Mapper 4) implementation.
///
/// See [`mapper004`] for details.
pub mod mapper004;

/// Type alias for horizontal name table mirroring setup
type HorizontalNameTablesRam = Adjacent<Mirror<Ram<SIZE_1K>, 2>, Mirror<Ram<SIZE_1K>, 2>>;
/// Type alias for vertical name table mirroring setup  
type VerticalNameTablesRam = Mirror<Ram<SIZE_2K>, 2>;
/// Type alias for four-screen name table setup
type FourScreensNameTablesRam = Ram<SIZE_4K>;
/// Starting address for CPU-mapped cartridge memory
const CART_CPU_MAP_BEGIN_ADDR: u16 = 0x4020;
/// Last address before cartridge memory starts
const LAST_UNREACHABLE_ADDRESS: u16 = CART_CPU_MAP_BEGIN_ADDR - 1;

/// Represents the different name table mirroring configurations
enum NameTableRam {
    /// Horizontal mirroring: each name table mirrors its horizontal neighbor
    Horizontal(HorizontalNameTablesRam),
    /// Vertical mirroring: each name table mirrors its vertical neighbor
    Vertical(VerticalNameTablesRam),
    /// Four-screen: no mirroring, all name tables are independent
    FourScreens(FourScreensNameTablesRam),
}