NES emulator written in C
An NES emulator written in pure C
Here lies an NES emulator I wrote to learn about emulation and generally sharpen my understanding of the C language. Don't let this fool you though. It is a pretty decent emulator with full 6502 instruction set (official, unofficial and most illegal opcodes) to say the least. It is also an impressive NSF player.
What is implemented
Below shows the features that have been implemented. This is obviously subject to change as I will continue to implement features where I can over time. Any help is welcome.
- CPU (6502)
- Memory
- PPU (Picture Processing Unit)
- APU (Audio Processing Unit)
- Gaming input
- Formats
- Mappers
- Game genie (for cheat codes)
What can be played
I haven't really taken time to do a survey but based on mappers implemented we can put the estimate at 90% of NES games. This is assuming none of them are using a quirk that I haven't gotten round to implementing. Games using mid-scanline trickery may not work as expected unless I find time to iron out timing issues in the PPU. Below are a few demos:
Contra

Metal gear

Legend of Zelda

1943: Battle of Midway

NSF Player: Ninja Gaiden

NSFe Player: Castlevania 3

Android: Ninja Gaiden

Controller setup
Xbox and Playstation controllers have not been tested on the emulator and are not guaranteed to work as shown here.| Key | Keyboard | Playstation | Xbox | |---------|--------------|-------------------|-------------------| | Start | Enter | Start | Menu | | Select | Shift | Select | View | | A | J | โข | Y | | B | K | โฏ | B | | Turbo A | H | โณ | A | | Turbo B | B | X | X | | up | Up | D-pad/stick Up | D-pad/stick Up | | down | Down | D-pad/stick Down | D-pad/stick Down | | left | Left | D-pad/stick Left | D-pad/stick Left | | right | Right | D-pad/stick Right | D-pad/stick Right |
Compiling
Compiling the emulator requires:
- a C11 (or higher) compiler e.g. gcc
- cmake
- make (linux), msvc nmake (windows)
$ git clone --recurse-submodules https://github.com/obaraemmanuel/NES
$ cd NES
$ mkdir build
$ cmake . -B build
$ cd build
$ make
You can now run the built emulator
$ ./nes ~/nes/roms/Contra.nes
To run with Game Genie enabled provide path to the original game genie ROM as an extra argument
$ ./nes ~/nes/roms/Contra.nes ~/nes/roms/game_genie.nes