PIE - Pacman Instructional Emulator

It's been three years since when I wrote the Pacman emulator to continue the project started with SIDE, but unfortunately at the time I had to stop working on it with only a few details missing and could not release the code. Many things happened in the meanwhile but eventually I was able to complete this emulator for one of the greatest games ever.

As for the Space Invaders emulator, the main goal of PIE is to provide a good architecture and code that is easy to read and understand. There is plenty of documentation not only for the emulator itself, but also for the Pacman hardware that is being emulated. I think this will provide the interested reader all of the information needed to understand how such an emulator works, and also a good starting point to do some experiments of his or her own.

But, of course, the emulator can be used to play as well! Here are some screenshots:

There would be more, unusual screenshots to see too, but that's enough for an introduction so let's see how the emulator works...

Emulator architecture and documentation

The emulator is written in C++. Its architecture is fairly simple and very similar to that of the Space Invaders emulator. The CPU is implemented by a Z80 class which uses an abstract Z80Environment interface to perform all I/O and memory operations. This is a generic implementation that has no specific code for Pacman. The emulator itself is implemented by a PacmanMachine class that honors the Z80Environment interface. This class is designed to be completely portable and as such it doesn't make use of OS or platform-dependent functions such as for example those needed to read the keyboard or draw to the screen. Rather it provides a sort of "virtual" interface to the emulator so that a front-end application only has to worry about getting input and displaying output, without worrying about the internals of the emulator itself.

Unfortunately there is a drawback to an emulator that is explicitly designed to be simple and understandable: performances have to suffer a little. In several places you'll find code that, considered from the point of view of speed, could make you scream in horror. Again, I remind you that I have made conscious decisions to make the code simpler and cleaner, and the expense of making it slower (*). For an old game like Pacman this is just fine though, and I can run the emulator at full speed (60 fps at double size with 44100 Hz 16-bit audio) on my 700 MHz Athlon, which is definitely not a high end machine for 2004 standards.

To complement the source code I have written extensive documentation for both the emulator classes and the Pacman hardware. If you're interested in old games you should read at least the latter to see what hardware was available for arcades in 1979!

Downloads

Latest version is 1.12 published on January 15, 2004. Get the emulator C++ source code (78K ZIP archive) or the compiled executable for Windows (46K ZIP archive). Note that the bundle does not include the game ROM because it is copyrighted material. To make the emulator work you must copy the needed ROM files in the same directory where the emulator is placed (a detailed ROM list is in the readme.txt, of course you must have a valid license to use the ROMs too!). PIE supports Pacman (Namco or Midway) and Ms. Pacman.

Update (Jan 26, 2004): Wow... Caz has ported PIE to BeOS! Download it from the BeEmulated page, which is also full of many great BeOS stuff... thanks Caz!

The version 1.0 sources, released in December 2003, are still available.

Do not forget to go to the Art of Programming section for more software, articles and downloads!

Acknowledgements

PIE owes a lot to all the emulator programmers out there that decided to share their knowledge by publishing documentation and source code, and particularly to:

- MAME, the multiple arcade emulator;

- the Z80 emulator by Marat Fayzullin, who is also author of many great emulators;

- Thomas Scherrer for maintaining the single most important resource for Z80 programmers;

- the Mowerman keeps a great page with a lot of information on Pacman and related games, including hardware and component pictures;

- Sean Young and Stefano Donati of Ramsoft for the great info on the undocumented Z80.

I would also like to thank Joe Linoff for the wonderful free tool ccdoc that I used to generate the code documentation.


* As a programmer that in the last twenty years or so has written tons of tight, fast and sometimes very dirty assembly code for several CPUs and microcontrollers, let me tell you that once you put the first divide in a inner loop then the rest is fairly easy... :-) [On a second thought, in version 1.1 I have eventually removed a lot of the slower code but at the same time I have been careful to replace it with alternatives that are still simple and easy to understand.]

Copyright (c) 1997-2004 Alessandro Scotti. All rights reserved.

 Home :: Computer Programming

Site Map