RustyNES is a Nintendo Entertainment System (NES) emulator written in Rust.
Written from scratch in Rust without using any external libraries.
Cross-platform and can run on Linux, Windows, and in a web browser (using WebAssembly).
Runs using very low cpu and memory resources at stable 60fps.
Supports all 5 channels of NES audio.
Supports save state and load state, so that we can resume the game from where we left.
Can run classic NES games like Super Mario Bros, Super Mario Bros 2, Super Mario Bros 3, Contra and many more.
Try on your local machine by downloading the executable from the releases
Try online in your browser: RustyNES (Under development).
| Language | Files | Lines | Code | Comments | Blanks |
|---|---|---|---|---|---|
| Rust | 36 | 4403 | 3505 | 329 | 569 |
| TypeScript | 2 | 436 | 351 | 25 | 60 |
| CSS | 1 | 351 | 289 | 11 | 51 |
| HTML | 1 | 149 | 137 | 0 | 12 |
| Total | 40 | 5339 | 4282 | 365 | 692 |
Generated using the tokei CLI tool.
Command used to generate the statistics:
tokei -C -t=Rust,TYPESCRIPT,HTML,CSS -s=lines-
RustyNES_core: This is the heart of the emulator, containing the core emulation logic. -
RustyNES_cli: This is a command-line interface that usesRustyNES_coreandSDL2for rendering output, outputting audio, and handling input. -
RustyNES_wasm: This crate compilesRustyNES_coreto WebAssembly which is used by theRustyNES_web_ui. -
RustyNES_web_ui: This is a web interface that usesRustyNES_wasmto run the emulator in a web browser.
| Emulator Button | Keyboard Key |
|---|---|
| Up | W |
| Left | A |
| Down | S |
| Right | D |
| A | L |
| B | K |
| Start | Enter |
| Select | Right Shift |
-
A: Used for jumping. -
B: Used for shooting. -
Start: Starts the game or pauses it when running. -
Select: Selects the next option in the menu.
| Action | Key |
|---|---|
| Save emulator state | N |
| Load emulator state | M |
Emulator state is saved in a .rustynes_sav file.
.rustynes_sav file can be loaded by passing the path to the file as an argument to the emulator.
./rusty_nes_cli <path_to_save_file>The RustyNES_core library crate has zero dependencies, but RustyNES_cli uses SDL2 for rendering and input handling. Ensure that SDL2 is installed on your system for building RustyNES_cli.
Building for Linux
-
Build the project in release mode:
cargo build --release
The
rusty_nes_cliexecutable will be in thetarget/releasedirectory. -
Run the executable with the path to the ROM file as an argument:
./rusty_nes_cli <path_to_rom_file>
-
To load a save file (
.rustynes_sav), pass the path to the save file as an argument:./rusty_nes_cli <path_to_save_file>
Cross-compiling to Windows
-
Add the Rust target for Windows:
rustup target add x86_64-pc-windows-gnu
-
Install
mingw-w64:sudo apt install mingw-w64
-
Build the project for Windows:
cargo build --release --target=x86_64-pc-windows-gnu
The
rusty_nes_cli.exeexecutable will be in thetarget/x86_64-pc-windows-gnu/releasedirectory, and theSDL2.dllfile will be in the project root directory.For running the emulator on Windows, ensure the
SDL2.dllfile is in the same directory as the executable. -
Run the executable with the path to the ROM file as an argument:
rusty_nes_cli.exe <path_to_rom_file>
-
To load a save file (
.rustynes_sav), pass the path to the save file as an argument:./rusty_nes_cli <path_to_save_file>
Building for Web
-
Install
wasm-pack:cargo install wasm-pack
-
In the
RustyNES_web_uidirectory, run:npm install npm run dev
This command will build the
RustyNES_wasmlibrary and output the WebAssembly file and JavaScript bindings to theRustyNES_web_ui/public/pkgdirectory.
- Mapper 0 (NROM)
- Mapper 2 (UNROM)
- Mapper 4 (MMC3)
- NES Documentation (PDF)
- Nesdev Wiki
- 6502 CPU Reference 1
- 6502 CPU Reference 2
- NES Rendering Overview
- The NES Explained YouTube playlist by NesHacker
- NES Emulator from Scratch YouTube playlist by OneLoneCoder


