YASNES is an unfinished NES emulator written in C++.
It is the result of a personal experiment about how to write an emulator. The NES platform has been chosen because of the fond memories of my childhood I have with it and the comprehensive documentation one can found.
Overall it was a very joyful experience. Being able to play Super Mario Bros, even at a very low framerate, without sound and with visual glitches is fascinating. It is a bit as if I made a cool game, except I did not of course. Watching the game being playable little by little for each small bugfix added gives a very nice motivation.
The current state is something like:
- the CPU emulation should be close to 100% ok,
- the PPU (graphics unit) has bugs that result in strange colors and some glitches around sprites (see Super Mario Bros scren shots below),
- the APU (sound unit) is not covered at all
No optimisation has been investigated, the emulation is quite naive and slow, even on modern pieces of hardware.
You'll need SDL 2 to compile it (sudo apt install libsdl2-dev
on Debian-like systems)
mkdir build
cd build
cmake ..
make
A CPU test suite is provided. You can run it with e.g.: ./nes ../data/nestest.nes
The emulator starts paused on the first instruction and a small debugger prompt.
The following commands are available:
c
: continue the emulations
(step) : execute the next instruction and pause againb <addr>
: break when the addressaddr
is encounteredbf
: break on next video framebdf
: disable break on video framebd
: disable breakpointsv
: dump some PPU internalsvdump <file>
: dump the current video memory to a filep <sprite>
: output the content of the sprite number<sprite>
as textk
: display current controller statek a|b|select|start|up|down|right|left 0|1
: set controller button's statew <addr> r|w
: add a watch on a memory addressq
: quit
There is only one game controller hard mapped to the host keyboard with:
a
-> A buttonb
-> B button<space>
-> select<return>
-> start<left>
-> left<right>
-> right<up>
-> up<down>
-> down
The p
key allows to pause the emulation and switch to the embedded debugger.