monsoon-core
Core NES emulation library — cycle-accurate MOS 6502 CPU, 2C02 PPU, memory subsystem, ROM parsing, and save states.
This is the primary crate for anyone wanting to embed NES emulation in their own project. It is part of the Monsoon Emulator project.
Public API Modules
emulation::nes— The top-levelNesstruct that orchestrates all emulation. Provides methods to load ROMs, step individual cycles or full frames, save/load state, read the pixel buffer, and access CPU/PPU debug information.emulation::rom— ROM file parsing for iNES, NES 2.0, and archaic iNES formats. IncludesRomFilefor loading ROMs from bytes andRomBuilderfor programmatic construction.emulation::savestate— Serializable emulator state snapshots. Save states can be encoded in binary (postcard) or JSON format.emulation::screen_renderer— TheScreenRenderertrait for implementing custom pixel renderers, plusNoneRenderer(a no-op fallback) and thedeclare_renderers!macro for registering renderers.emulation::palette_util— NES color palette types (RgbColor,RgbPalette) and.palfile parsing.emulation::ppu_util— PPU constants (output dimensions, tile counts) and debug data types (EmulatorFetchable,TileData,PaletteData,NametableData).util— Serialization helpers (ToBytes) and hashing utilities (Hashable).
Internal implementation modules (cpu, ppu, mem, opcode) are pub(crate) and not accessible to downstream consumers.
Quick Start
use Nes;
use RomFile;
Pixel Buffer Format
Nes::get_pixel_buffer() returns a Vec<u16> of palette indices, not RGB values. Each 16-bit entry encodes:
- Bits 0–5: NES color index (0–63)
- Bits 6–8: Emphasis bits from the PPU mask register
Use a ScreenRenderer implementation (e.g., LookupPaletteRenderer from the monsoon-default-renderers crate) to convert these indices to RGB colors.
Save States
use Nes;
use try_load_state_from_bytes;
use ToBytes;
let mut nes = default;
// Save state
if let Some = nes.save_state
// Load state
let data = read.unwrap;
if let Some = try_load_state_from_bytes
License
This project is licensed under the Apache-2.0 License.