Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SimpleNES -- An NES emulator in SFML and C++!  (Read 8541 times)

0 Members and 3 Guests are viewing this topic.

amhndu

  • Newbie
  • *
  • Posts: 42
  • Err, err and err again, but less, less and less
    • View Profile
    • amhndu.github.io
    • Email
SimpleNES -- An NES emulator in SFML and C++!
« on: December 08, 2016, 12:57:00 pm »
SimpleNES

Github repo
An NES emulator written in C++ and SFML.
Roughly 40-50% of games should work (ie. games that use either no mapper or mappers 1, 2 or 3).
Examples of games that have been tested to run (but NOT limited to):
(USA/Japan or World versions only i.e. NTSC compatible)
  • Super Mario Bros.             
  • Contra                         
  • Adventure Island               
  • Ninja Gaiden                   
  • Wrecking Crew                 
  • Megaman and Megaman 2         
  • Mario Bros.                   
  • Donky Kong and Donkey Kong Jr.
  • Battle City                   
  • Paperboy                       
  • Legend of Zelda               
  • Pacman                         
  • Tennis                         
  • Excitebike                     
Here's a big list of games that match the supported specs from SimpleNES. (Unlike the list above, these aren't tested. Some may or may not work)

Screenshots

(click to show/hide)

Videos

Playlist on YouTube: https://www.youtube.com/playlist?list=PLiULt7qySWt2VbHTkvIt9kYPMPcWt01qN

Download

Windows 32-bit
Linux 64-bit

I don't have a Mac executable but I've tested an older version of the emulator and should work now too.

ROMs available here for testing

Compiling

You need:
* SFML 2.0+ development headers and library
* C++11 compliant compiler
* CMake build system

Compiling is straight forward with cmake, just run cmake on the project directory with CMAKE_BUILD_TYPE=Release
and you'll get Makefile or equivalent for your platform, with which you can compile the emulator

For e.g., on Linux/OS X:
$ git clone https://github.com/amhndu/SimpleNES
$ cd SimpleNES
$ mkdir build/ && cd build/
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ make -j4    #Replace 4 with however many cores you have to spare


Running

I didn't bother with a GUI, the emulator can be launched from the terminal.
Just pass the path to a .nes image like
$ ./SimpleNES ~/Games/SuperMarioBros.nes
To set size of the window,
$ ./SimpleNES -w 600 ~/Games/Contra.nes
For supported command line options, try
$ ./SimpleNES -h


Keybindings can be configured with keybindings.conf

Default keybindings:

Player 1

 Button        | Mapped to
 --------------|-------------
 Start         | Return/Enter
 Select        | Right Shift
 A             | J
 B             | K
 Up            | W
 Down          | S
 Left          | A
 Right         | D

 
Player 2

 Button        | Mapped to
 --------------|-------------
 Start         | Numpad9
 Select        | Numpad8
 A             | Numpad5
 B             | Numpad6
 Up            | Up
 Down          | Down
 Left          | Left
 Right         | Right

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: SimpleNES -- An NES emulator in SFML and C++!
« Reply #1 on: December 09, 2016, 08:06:35 am »
Very impressive, great job! Can you tell us a bit more about it? Maybe there was something interesting in implementation or some C++11 things that greatly helped you?
I've never done emulation, so this topic is pure magic for me. :D
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

amhndu

  • Newbie
  • *
  • Posts: 42
  • Err, err and err again, but less, less and less
    • View Profile
    • amhndu.github.io
    • Email
Re: SimpleNES -- An NES emulator in SFML and C++!
« Reply #2 on: December 09, 2016, 10:38:34 am »
Very impressive, great job! Can you tell us a bit more about it? Maybe there was something interesting in implementation or some C++11 things that greatly helped you?
I've never done emulation, so this topic is pure magic for me. :D

I haven't particularly used much of modern C++ or any cool new features except for lambdas,
range-based for loops, std::chrono and other minor things.

Talking about the development, NES is fairly well documented.
The cpu 6502 was used in Apple I and II, several systems by Commodore and Atari,
so it has tons of documentation online.
Emulating a CPU involves reading the instructions made up of opcodes, specifying the operation and the operand.
These operate on the few registers 6502 has and the small 8-bit address space of which large portions are unmapped and
mirrored in the NES which consists of only 32KB for the read-only instructions and 2KB of RAM! (Aren't we privileged with gigabytes of memory to waste ?)
The CPU was then the easiest part of the development.
The NES sports a PPU, a Picture Processing Unit, the predecessor of the beasts we have as GPUs these days :)
The PPU too has only 2KB of (V)RAM plus 2KB for "name-tables" plus some bytes for the palette.
The resolution of the picture produced by the NES is 256x240 which is 61KB (with a color depth of 1 byte) is way more than the space we have.
So the picture is made up with the help of repeating patterns which you've obviously observed playing a game on it.
The background is thus made with patterns defined in the "pattern table", the screen is made of these patterns as arranged in the "name-tables".
It actually has address for four name-tables but space only for two, so two of these are mirrored.
The PPU thus offers scrolling between these name-tables which helped spawn all the platformers on the NES.
Making this PPU involved LOTS of bit-manipulations. I once spent days tracking down a bug which came out to be ONE wrong BIT!
Anyway it was quite fun and I had it easy as most of reverse-engineering has already been done for the NES.

Edit: Oh and I gave up on trying to make a GUI with ImGui, remember my mail on fonts ? :D

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: SimpleNES -- An NES emulator in SFML and C++!
« Reply #3 on: December 10, 2016, 10:36:06 pm »
Thanks for the detailed info! :D
And yeah, I remember your mail. What went wrong with ImGui?
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

amhndu

  • Newbie
  • *
  • Posts: 42
  • Err, err and err again, but less, less and less
    • View Profile
    • amhndu.github.io
    • Email
Re: SimpleNES -- An NES emulator in SFML and C++!
« Reply #4 on: December 12, 2016, 08:20:26 am »
And yeah, I remember your mail. What went wrong with ImGui?

It can't be customised much, I couldn't even change the font...
I found it to be too big to include in my project and I think it's meant more for debugging and development than a user-facing GUI.
All I wanted was a simple laucher, I gave up on the GUI as I found the command line invokation good enough

Carlos Augusto Br Cpp

  • Newbie
  • *
  • Posts: 40
  • Programming is life
    • View Profile
    • Email
Re: SimpleNES -- An NES emulator in SFML and C++!
« Reply #5 on: December 13, 2016, 12:05:58 am »
Hey bro... where did you have find material for 6502??  I have searched a lot... but only have find the "Easy 6502"...  :o


Carlos Augusto Br Cpp

  • Newbie
  • *
  • Posts: 40
  • Programming is life
    • View Profile
    • Email
Re: SimpleNES -- An NES emulator in SFML and C++!
« Reply #7 on: December 13, 2016, 07:57:10 pm »
humn... thanks... for sure I will give an try... but nice work bro...

 

anything