Lab / Project / 2025-06-08
NES Emulator
An NTSC NES emulator in Rust. It plays NROM games like Mario Bros. with graphics, sound and controls, and the CPU passes nestest.
In progress
- Rust
- raylib
- Nix
I’m writing an NES emulator in Rust, with raylib handling the window, audio and keyboard. It runs NROM (mapper 0) games such as Mario Bros. with graphics, sound and player 1 controls.
Where it’s at
- CPU (6502 / 2A03): done. Every official opcode plus the common unofficial ones, NMI and IRQ, and it passes the nestest test ROM.
- PPU (2C02): mostly done. Background and sprite rendering with scrolling and eight sprites per scanline. Sprite 0 hit and sprite overflow aren’t set during rendering yet.
- APU: done. Both pulse channels, triangle, noise and DMC, the frame sequencer and IRQs, and the nonlinear mixer, streamed at 44.1 kHz.
- Controllers: player 1 on the keyboard. Player 2 is emulated but has no keys yet.
- Cartridges: iNES and NES 2.0 headers, NROM only for now.
The main loop steps the CPU, then clocks the PPU three dots and the APU one tick for every CPU cycle. Each part has its own unit tests.
What’s next
- More mappers, starting with MMC1, UxROM and CNROM
- Sprite 0 hit and sprite overflow
- CPU stalls for OAM DMA and DMC fetches
- Keys or a gamepad for player 2
The README doubles as my notes on how the NES hardware fits together: the two buses, the memory maps, cartridges and mappers, the PPU and APU, and timing.