Writing an emulator for a CPU or entire system is a great programming project. Some of the old 8-bit CPU’s can be emulated fairly easily and running them at a decent speed isn’t a problem for modern PC’s. In addition to the CPU, code will be needed to emulate any graphics and sound hardware too.
Here are some notes on where to start.
Chip 8 is usually the first place to start – its actually an interpreted programming language rather than a CPU architecture. Programs are run within a CHIP-8 virtual machine. It was done this way to allow programs to run on different machines. It was developed in the mid-1970’s and there are plenty of simple games available. CHIP-8 only uses 35 instructions (or opcodes) which is why its the simplest system to emulate.
There are plenty of good CHIP-8 emulator tutorials – for example, this one.
The Intel 8080 has 256 opcodes so is a little more time consuming to write an emulator for.
The original Space Invaders arcade game from 1975 is a good system to develop an 8080 emulator for. Its very simple – the graphics is just a 256 x 224 x 1 bit black-and-white frame buffer in RAM. There’s a great tutorial here.
Writing a CP/M emulator for an 8080 might also be something to look at.
The 6502 is a very elegant design – there are only 148 opcodes to implement and a lot of these are very similar.
The Apple I computer was very simple and used a 6502 so is fairly straightforward to emulate. The Apple II is also a good choice but the video subsystem is more complicated.
The Commodore PET might also be a worth looking into – this computer from 1977 also used a 6502.
The Nintendo Entertainment System from 1983 was based on a 6502 and there is lots of documentation available for it. It uses a Picture Processing Unit (PPU) which can be quite challenging to emulate. There is a good overview of what is needed here.
The Z80 has much more opcodes (677) so programming this can be a bit of a grind – there are also some quirks and undocumented functionality. This means that emulating a Z80 is a larger project.
The Sega VIC Dual is an arcade system from 1977 which used the Z80 processor. There are various games available (the best known one is “Carnival”). The video is held in RAM and is a 32×28 array of 8×8 characters which can support a simple colour palette. This system looks fairly straightforward to emulate
The ZX Spectrum is also popular system to write an emulator for. Its a little more complicated due to more exact timing that is needed, but the video is held in RAM so there is no need to emulate any graphics hardware.
There is more to emulating a system than just a CPU, and this is where it can start to get complicated.
A list of systems to try and emulate in order of difficulty might be: –
- Space Invaders (8080)
- Apple I (6502)
- Apple II (6502)
- VIC Dual (Z80)
- NES (6502)
- ZX Spectrum (Z80)
Image Credits: mutednarayan