Let's begin by explaining a couple of things a little bit before we start coding:

What's an emulator and a simulator?

An emulator is a piece of software that can run binary code written for a particular machine without that actual code being 'aware' of it. In other words, the emulated game runs exactly as it would on its original hardware. That's what we will be doing. On the other hand, a simulator is an imitation: it could look almost exactly the same and behave the same as the original game, but underneath it runs totally different code. For example, if you would be coding a Pac-man clone in Blitzmax that behaves like the original game, we could say that you essentially wrote a 'pac-man simulator'. For better reading, please refer to wikipedia and read a bit about http://en.wikipedia.org/wiki/Emulator.

Great, now what exactly is an arcade game machine?

If we take a look at one of the most popular game arcade in the 80's, we can say that the machine contains generally the following items:

  • Self-contained cabinet
  • TV monitor
  • Loud speaker(s)
  • Joystick(s) and button(s)
  • DIP switches 
  • Coin box(es)
  • Game motherboard (inside)
  • Power supply and various electronic components

You can browse this excellent Killer List Of Videogames Pac-man machine: http://www.klov.com/game_detail.php?game_id=10816

Note that the cabinet itself can take several shapes. It doesn't matter much for us. Now if we remember our definition of emulation, a perfect emulator would need to emulate all of these components in perfect syncronisation in order to recreate have a flawless reproduction of the original game experience. We will not go that far of course. In fact, for the most part, only the central processor is going to be emulated. Everything else will be simulated or ignored completely.

In that sense, we need to go in further details regarding the most important component: the motherboard. This circuit board holds the Central Processing Unit (CPU), the game byte code (ROM), some work memory (RAM), and input and output ports (I/O ports) to communicate with the outside world, i.e.: the player. Without these ports, the board itself would be of absolutely no use since it cannot by itself 'show' something or even play a sound. The game would run silently, invisibly, without any way of controlling anything. Not what we would call fun! This leads us to realise that we will have to spend some time simulating these ports and somewhat route them to our own computer in order to display the screen, play sound, and convert keyboard or gamepad input back to the game. The DIP switches allow some settings by the arcade owner to make the game harder or set various items.

Enough about general stuff, what's the game we are going to emulate?

I have selected one of the most remembered classic of all times, one that is also easier to emulate because of its relative simplistic nature, and mostly one that as a lot of Internet information available. The game is Space Invaders, developed by Taito and published by Midway in America. You can read historical facts and interesting info on wikipedia at http://en.wikipedia.org/wiki/Space_invaders.

The game looks like this:

Inside this machine, the interesting hardware is an Intel 8080 CPU (Additional info http://en.wikipedia.org/wiki/Intel_8080) with 8KB of RAM. The display is a monochromatic 1-bit 224x256 that had translucent colored strips to make a portion of the screen red and green. Sound is interestingly completely controlled by separate circuits that we are no going to emulate at all. Instead, we are going to use standard WAV samples that were taken from an actual machine, so it's going to sound very much like the original game, although we are not emulating the sound board. Player input is handled by a left/right controller and a fire button. There is also a 'coin inserted' detection trigger that allows the game to start, along with player 1 start and player 2 start buttons. A couple of dip switches allow to set the number of ships at the beginning of a game, set the game in easy or hard mode, and toggle display of a coin status line. In summary, that's all we need to care to start coding!

Take me to chapter 2: The project setup

Back to tutorial home page