1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! 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 *;
use ;
/// MMC3 (Mapper 4) implementation.
///
/// See [`mapper004`] for details.
/// Type alias for horizontal name table mirroring setup
type HorizontalNameTablesRam = ;
/// Type alias for vertical name table mirroring setup
type VerticalNameTablesRam = ;
/// Type alias for four-screen name table setup
type FourScreensNameTablesRam = ;
/// 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