Skip to content

rib/nes-emulator

Repository files navigation

NES emulator! 🎉

A highly accurate NES emulator and NSF music player written in Rust.

Screenshot

Overview

The project is split into two crates:

  • nes-emulator; provides the core that deals with the logic of emulating a NES system without any I/O capabilities
  • nes-emulator-ui; acts as a frontend that can be used either as:
    • A headless command line tool for running tests or benchmarks
    • A graphical UI with a suite of interactive debugging tools, based on Egui.

Core Emulator

CPU

  • Cycle accurate CPU (including all dummy reads/write cycles for instructions that may have side effects)
    • Interrupt handling works in terms of the raising and lowering edge of each clock cycle
  • Unofficial opcodes
  • RST line handling, for DMAs
  • Cycle-accurate DMA handling, including combined DMC + OAM DMAs - SOME BUGS STILL

PPU

  • Cycle accurate (including all sprite evaluation)
  • 8x16 Sprites
  • Emulates all redundant reads that can have side effects for cartridges
  • Emulates Sprite 0 hit bug
  • Monochrome
  • Color Emphasis
  • Shared t,v,fine-x internal register state affecting scrolling and PPU data reads
  • I/O latch decay
  • Skipped dot for odd frames
  • Mirroring Modes
    • Single Screen A
    • Single Screen B
    • Horizontal
    • Vertical
    • Four-screen

APU

  • 2x Pulse channels
  • Triangle channel
  • Noise channel
  • DMC channel
  • $4017 register write delay

System

  • NTSC (2C02)
  • PAL (2C07) INCOMPLETE
  • Dendy (UA6538)
  • PPU and CPU emulation in lockstep with cycle accuracy. The CPU clock is the main clock and everything makes progress each read/write cycle for the CPU.
  • Game Genie Codes
  • Clocking Modes:
    • Real-time (emulation progresses according the passing of real (wall clock) time
    • Greedy (emulation progresses as fast as possible - useful for running tests)

Mappers

  • iNES 000: NROM
  • iNES 001: MMC1 / SxROM
  • iNES 002: UxROM
  • iNES 003: CNROM
  • iNES 004: MMC3, MMC6 / TxROM
  • iNES 007: AxROM
  • iNES 031: NSF Player
  • iNES 066: GxROM

Debugging

  • CPU Breakpoints (read or write, optionally ignoring dummy I/O cycles)
  • Stack Unwinding
  • CPU Tracing - comparable with Mesen trace logs
  • General Tracing - Ability to record detailed traces of different hardware events that can be visualized in real-time
  • Watch Points
  • PPU Breakpoints (based on frame, line and dot counts)
  • Hook into PPU MUX (background + sprite composition) for debugging
  • Optional transistor-level PPU simulator can be run in parallel with the emulated PPU

UI

ROM Formats

  • iNES
  • iNES 2
  • NSF

Command Line Arguments

nes-emulator-ui 0.1.0

USAGE:
    nes_emulator.exe [OPTIONS] [ROM]

ARGS:
    <ROM>

OPTIONS:
    -d, --rom-dir <ROM_DIR>         Add a directory to find macro roms that are specified with a
                                    relative path
    -g, --genie <GENIE_CODES>       Game Genie Code
    -h, --help                      Print help information
    -m, --macros <MACROS>           Load the macros in the given library
    -p, --play <PLAY_MACROS>        Play a single macro or "all" to execute all loaded macros
    -q, --headless                  Disables any IO and all synchronization (i.e. emulates frames as
                                    quickly as possible; good for benchmarking and running tests)
    -r, --relative-time             Step emulator by relative time intervals, not necessarily
                                    keeping up with real time
        --results <RESULTS_JSON>    Write the results of running macros to the given file in JSON
                                    format
    -t, --trace <TRACE>             Record a trace of CPU instructions executed
    -V, --version                   Print version information

Key Bindings

Key Action
Esc Pause/Resume
Ctrl-R Reset
Ctrl-T Power Cycle
Enter Start
Space Select
W Up
A Left
S Down
D Right
Left A
Right B

Tools

Memory View

Memory View

Macro Recorder

Macro Recorder

Nametable View

Nametable View

Sprites View

Sprites View

APU View

APU View

Links:

A random selection of other NES emulators

Some cool NES emulators written in Rust