I always found emulators amazing pieces of software. The first I used was a SNES one, that I use to play some classic games I never was able to get when I was a kid. I thought those beasts were black magic, something I will never be able to grasp.
I basically wanted to improve my OpenGL (and C++) skills through a fun project. I always wanted to make an emulator, and the Chip8 is a fairly easy one to start with. So why not making the rendering 3D to be able to move “inside” the game.
Here is a small video of what it looks like: youtube
The Chip 8 is actually a virtual machine developed in the 70s by Joseph Weisbecker. So it was never a real console to begin with but we still can emulate it. There have been plenty of games written for it so we can run them later in our emulator.
This is probably the easiest emulator you can start with, since it has a very small number of opcodes and they are pretty simple to implement. You can find easily on the internet the specifications needed to be implemented. For instance on this website.
C++ data modeling
So as we can see that machine is very simple. We've got 4Kb memory to work with, 16 registers and then some variables where we are storing the current opcode, the current index and the value of the program counter (pc). There is two timers that are clocked at 60Hz. Each one of them should be decremented 60 times per second. If the
timerSound is above 0, we should play a sound.
If you are interested in knowing more about it, you should check this guide which explains a lot more things than me.
Usually the games are rendered in a
64 * 32 framebuffer. To make mine a bit different from the others I decided to treat each pixels as a cube. Each single pixel is treated as an entity to be drawn, this is definitively not the most efficient way of doing it, but for such a small number of pixels it went well with an average of 200 fps on a machine without a dedicated graphic card.
The 3D engine is a simple basic OpenGL renderer with a few shaders for the shadows and lights and a very basic free fly camera. The most important part is to render those array of pixels into cubes and translating it into 3D using matrices.
You can find the source for everything here.
A NES emulator should be a fun next exercice.