Skip to content

ObaraEmmanuel/NES

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
    • Official opcodes
    • Unofficial opcodes
    • Cycle accuracy (official & unofficial)
    • Dummy reads/writes
    • BCD arithmetic (Not needed by NES anyway)
  • Memory
    • Battery backed (persistent) save RAM
    • Open-bus
  • PPU (Picture Processing Unit)
    • Open-bus
    • NTSC
    • PAL
    • Dendy
  • APU (Audio Processing Unit)
    • Pulse channel
    • Triangle channel
    • Noise channel
    • Delta Modulation Channel
  • Gaming input
    • Keyboard input
    • Keyboard (multiplayer)
    • Original NES controller
    • Gamepad controller (Multiplayer)
    • Turbo keys
    • Custom Touch controller (Android)
  • Formats
    • iNES
    • NES2.0
    • NSF
    • NSFe
    • NSF2
    • UNIF
    • FDS
    • IPS
  • Mappers
    • #0 NROM
    • #1 MMC1
    • #2 UxROM
    • #3 CNROM
    • #4 MMC3
    • #5 MMC5
    • #7 AxROM
    • #11 Color Dreams
    • #66 GNROM
  • 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

contra

Metal gear

metal gear

Legend of Zelda

zelda

1943: Battle of Midway

1943

NSF Player: Ninja Gaiden

Ninja Gaiden NSF

NSFe Player: Castlevania 3

Castlevania 3 NSF

Android: Ninja Gaiden

Ninja Gaiden Android

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 X
B K B
Turbo A H Y
Turbo B B X A
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)

Assuming have the above requirements installed on your system, Acquire and build the source as follows:

$ 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