- Modern C++20
- Cycle-Accurate 6502 CPU
- 256 × 240 PPU (60 FPS)
- 4 Cartridge Mappers
- 5-Channel APU (44.1 kHz)
- Dear ImGui & OpenGL 3.3
SYSTEMS ARCHITECTURE / C++20 EMULATION
Cycle-Aware Console Emulation & Real-Time Debugging in Modern C++20
The Nintendo Entertainment System (NES) is a masterclass in synchronous hardware design. Operating with a 1.789 MHz Ricoh 2A03 CPU, a 5.37 MHz Ricoh 2C02 Picture Processing Unit, and an integrated Audio Processing Unit, the system requires cycle-exact timing coordination. This desktop emulator implements the entire hardware path in modern C++20, coupling cycle-accurate execution with a dockable Dear ImGui debugging suite that exposes internal registers, disassembly, memory maps, and raster beam timing in real time.
Ricoh 2A03 (MOS 6502) CPU Core
Executes all 56 official 6502 opcodes plus documented unofficial/illegal instructions. Models addressing modes (Zero Page, Indexed, Indirect, Absolute), cycle penalty delays for page-boundary crossings, and full interrupt logic (RESET at $FFFC, NMI at $FFFA, IRQ/BRK at $FFFE). BCD decimal mode is explicitly disabled in hardware matching Ricoh silicon.
Ricoh 2C02 Picture Processing Unit (PPU)
Renders at 256 × 240 resolution @ 60 FPS over 262 scanlines. Implements the complete 'Loopy' scrolling engine (registers v, t, x, w), 2 Pattern Tables ($0000/$1000), 4 Nametables with dynamic mirroring (Horizontal, Vertical, Single-Screen, Four-Screen), 64-sprite OAM evaluation with 8-sprites-per-scanline limits, and precise cycle-level Sprite 0 hit detection.
Ricoh 2A03 Audio Processing Unit (APU)
Synthesizes 5 independent audio channels: Pulse 1 & Pulse 2 (variable duty cycles, sweep units, envelope decay), Triangle (32-step pseudo-sine with linear counter), Noise (15-bit LFSR pseudo-random generator), and DMC (Delta Modulation for 1-bit samples). Features 4-step and 5-step frame sequencers mixed via non-linear formulas into SDL2 audio streams at 44.1 kHz.
Cartridge Mappers & Bus Multiplexing
Parses iNES header formats (.nes) and multiplexes cartridge memory spaces. Supports Mapper 0 (NROM: 16KB/32KB PRG, 8KB CHR), Mapper 1 (MMC1: 5-bit serial shift register with bank switching and dynamic mirroring), Mapper 2 (UxROM: PRG bank switching with fixed upper bank), and Mapper 3 (CNROM: 8KB CHR banking).
Modern C++20 Architectural Highlights
Utilizes constexpr lookup tables for O(1) branchless instruction decoding and cycle costing.
Employs std::span to view and slice memory buffers without allocations or pointer decay.
Leverages standard library bit operations (std::rotl, std::rotr, std::popcount) for fast shift and flag evaluations.
Encapsulates Cartridge, Bus, PPU, and APU peripherals within std::unique_ptr with zero raw pointer leaks.
Stores 2KB internal RAM and 2KB VRAM in contiguous std::array buffers for optimal L1 data cache locality.
NES CPU Memory Bus Architecture ($0000 - $FFFF)
- $0000 - $07FF
- 2KB Internal Work RAM (Zero Page at $0000-$00FF, Stack at $0100-$01FF)
- $0800 - $1FFF
- Mirrors of $0000 - $07FF (mirrored 3 times)
- $2000 - $2007
- PPU I/O Registers (PPUCTRL, PPUMASK, PPUSTATUS, OAMADDR, OAMDATA, PPUSCROLL, PPUADDR, PPUDATA)
- $2008 - $3FFF
- Mirrors of $2000 - $2007 (mirrored every 8 bytes)
- $4000 - $4017
- APU Sound Registers, OAM DMA Register ($4014), Joypad 1 & 2 ($4016, $4017)
- $4020 - $5FFF
- Cartridge Expansion ROM
- $6000 - $7FFF
- Cartridge Battery-Backed PRG-RAM (Save RAM)
- $8000 - $BFFF
- Cartridge PRG-ROM (Low Bank / Switchable via Mapper)
- $C000 - $FFFF
- Cartridge PRG-ROM (High Bank / Fixed / Vectors: NMI @ $FFFA, RESET @ $FFFC, IRQ @ $FFFE)
Gamepad Controls & Emulator Shortcuts
- Arrow Keys
- NES D-Pad (Up, Down, Left, Right)
- Z / X
- NES A Button / B Button
- Enter / Right Shift
- NES Start / Select
- F1
- Toggle Dear ImGui Debugger Docking Windows
- F2
- Single-Step 6502 CPU Instruction
- F3
- Step PPU Frame (Advance 262 Scanlines)
- F5 / Space
- Toggle Run / Pause Execution
- Esc
- Exit Emulator
Build & Toolchain Environment
Modern C++20 compiler (MSVC 2022 / Clang / GCC 11+) · CMake 3.20+ · Ninja / MSBuild · Modern OpenGL 3.3+ · SDL2 · Dear ImGui (Docking Branch)
Explore Desktop NES Emulator on GitHub