How Emulators Work (and why there will never be PS2 on Xbox)

Emulators. The best use of computing power I think I've ever seen! In this tutorial I'll explore the fundamentals of what happens inside an emulator. Hopefully this will help some of the people out who want to run PS2 games on their Xbox to understand why this will never (ever) happen.

In my time on the scene I have fielded many questions about emulators on the Xbox. I personally use MAME and Stella ports on my console and am very happy with them. I especially enjoy playing my old Atari 2600 favorites with my old GEM (yellow button) joystick (hack conversion here).


The most common question to cause flames and debate, along with the occasional enlightening insight (good or bad), is:
Can I play PS2 (or Gamecube) games on my Xbox?

The simplest answer to this is:
No.

I've seen people suggest anything from "it will happen, you just wait and see" to "just rename the PS2 files with an XBE extension and run them". In the case of the latter, when the guy was laughed into oblivion, he responded back that it was worth a try.

In this page I will try to illustrate why "just waiting for it" and "renaming the files" are not viable options. I will also attempt to demonstrate how an emulator works, and thus its limitations, to an audience not familiar with the mechanics involved. In other words I'm writing this for all the people new to the scene who ask for a PS2 emulator, and for all those who know why and are tired of answering the question.

Without further ado, lets dive in!

An emulator, whether it be to play games written for an older console on a different machine (MAME for example), or to run an entire [non open source, thus non portable] operating system on a non-target (non ported) platform (VMware and Soft Windows), performs the same basic function. Using multiple instructions available in the instruction set of the host platform to execute instructions from the target platform that the host does not provide.

In a nutshell that means the following: If I am running an old game on an old Motorola 68K CPU and the game was coded with the memory mapped architecture of that CPU in mind, then I will access the sound card as a memory read and write. The soundcard exists as a byte (or word if needed) of ram in a large memory map. In this CPU architecture there is no separate I/O and Memory space. Everything acts as memory.

Now imagine that I want to run that same game on a newer hardware platform based on x86 architecture. In this case I have a memory space and an I/O space. If I want to access the sound card and were to issue the memory read/write commands I would not only not access the sound card as intended, but I would also likely corrupt a memory address and cause a kernel panic (Blue Screen Of Death for Windows users). What I need is something to trap the instruction to read or write to the sound card and convert the memory read to an I/O read.

Enter the emulator. The emulator runs as an application on the host system. In turn the emulator acts as a "virtual system" which runs the code for the target platform. In the case of MAME there is no operating system per-se on the target system because the games were compiled to run exclusively on the processor. In the case of VMware you actually can boot the Windows OS and then run windows dependant applications.

At this point I want to make an important distinction about emulators. The emulators used for games are hardware emulators, while VMware emulation is predominately software emulation. A hardware emulator is (usually) used to run code on a platform for where a port is not available, a software emulator will let you run an application on a host OS for where a port is unavailable (i.e. running M$ Word on Linux using WINE).

Why all this means a PS2 emulator will not exist on the Xbox.

When emulating a system you are using multiple host machine instructions to execute one target machine instruction. How large this ratio is depends on how divergent the two machine architectures are. For example, if you are trying to emulate a 80486DX CPU on a Pentium4 based computer so that you can play an oldie but goodie game that is unplayable on the new hardware (due to a lack of maximum clock locking on the old game it now runs at 1000+FPS and the sound is more like rebar on a grinder than multi-tone beeps), then your emulation task is very easy. In this case the instructions themselves are pretty much identical and you may only need to "present" 33 clock cycles to the target game for every millisecond of real time, divided evenly over that millisecond. Things get more complicated as your processor becomes more divergent. In the case of our Motorola 68000 MAME example you may need four to six host instructions (on average) per target instruction. Lets say the target runs at 8MHz. Some math yields:

8,000,000 * 6 = 48,000,000

so we need to have a processor that is at least 48 MHz in order to get in the average number of instructions done in time to properly emulate the target. In reality you often need to support the peak number of instructions, not the average, but hey this is just an example right?

Fast forward to the PS2. Here is a quote from a Wired article that a quick google for "sony PS2 +processor" turned up:

The PS2 is fueled by a 128-bit central processor that Sony has dubbed The Emotion Engine. Developed in partnership with Toshiba, the CPU has a clock speed of 294 MHz, and sports 32 megabytes of RAM. The graphics processor holds an additional 4 megabytes of memory, and can display 75 million polygons per second at resolutions up to 1280 x 1024.
http://www.wired.com/news/culture/0,1284,39478,00.html?tw=wn_story_related

So as we can see this architecture is significantly different from our host system (an x86 32 bit platform). Some quick math assuming we keep with our average based computation and 6 host instructions per target instruction, while not accounting for the fact that each PS2 instruction register is 4x the width of an x86 register:

294,000,000 * 6 = 1,764,000,000

So that means we need a 1.7GHz processor, or one that is over 2x the power of the PIII in the Xbox. I am not a game or emulation developer, so I can not tell you how far off or close this is, but I have a feeling that more horsepower than that even is needed to emulate the PS2 successfully (remember we have not accounted for the 128 bit Vs. 32 bit difference in platforms yet!)

No amount of waiting will change the significant architectural differences between the Sony "Emotion Engine" CPU and the "normal" x86 architecture, so the poor chap who said "wait for it" is out of luck.

As for the guy who suggested that we simply rename the files to have an XBE extension, I'll leave that as an exercise for the reader to figure out.

How to configure an emulator:

Ok, so now that we (hopefully) understand how emulators work, I'll walk you through setting up my two favorites: Stella and MAME.

Stella:
As you likely know from the "Building an Atari Joystick adaptor out of a broken controller" page I really like my old video games. I really get a kick out of running games targeted at a 4Mhz (?) CPU on something so overbuilt for the job as an Xbox. I will cover how to install the game to your Xbox's hard disk here:

Please remember that you should actually own the cartridges for the games you play on this emulator as ownership of the cartridge is your legal right to play the game. (I think IANAL)

1) Download the Stella binary, compiled for your Xbox from the internet (do not ask for this on forums as it is considered a rude question. Do not ask me for it, I will not hand it out).
2) Create a directory on your computer named "Stella" (referred to from now on as Stella
3) Unpack the zip or rar you got off the internet into the directory Stella (see note1 for directory tree you should have)
4) Place any ROMs you have (.bin extension) in the stellaa26roms directory. To keep the list short I have both a stellaa26roms and a stellaa26roms_ directory. All my ROMs are in the directory with an underscore and I use boXplorer to copy any rom images from that directory to the stellaa26roms directory that I want to play. This is an un-necessary step if you don't mind sifting through a long list of games.
5)a To play Stella off your hard drive: Place the Stella (and all it's contents) onto your xbox hard drive in either an "emulators", "games", or "apps" directory and use the dashboard of your choice to access the emulator and load your games
5)b To play Stella off a cd or dvd rom as a game disk: Place the contents of the Stella directory, but not the root dir its self onto a disk (using your favorite GDF iso maker and CD-burning utility).
6) Build my joystick hack and pretend your back in elementary school again. (I'm afraid that dates me, but oh well) ;)
Note1 (this is what your directory tree should look like before stuffing all your rom images into the Stella/a26roms directory):
stella/
stella/default.xbe
stella/stella.ini
stella/a26roms/
stella/media/
stella/media/font.xpr
stella/media/font12.xpr
stella/media/fontsarial_12.abc
stella/media/fontsarial_12.tga
stella/media/fontsarial_16.abc
stella/media/fontsarial_16.tga

MAME:

If you don't know what MAME is, then I would really like to know what rock you've been living under! But, just in case here is a synopsis:

MAME stands for: Multiple Arcade Machine Emulator. In a nutshell, MAME can emulate many of the popular hardware platforms used on Arcade games from day Zero to the mid-nineties. Similar to Stella, where you should own the cartridges prior to downloading and running a MAME rom image, you should own a set of roms or a working (or dead) mainboard as a license to play the game (Standard disclaimer IANAL). In my case I am an addict of the game Gauntlet. I do in fact own the boards, and truly have it as a priority to beg, borrow, buy, build, or steal a 4 player cabinet (with all the decals) once I finally own my own home. In my apartment a cabinet would be grossly out of place (not to mention that it would take way too much space). The instructions for building a MAME install are practically the same as for a Stella install, except the names are different (duh), and where Stella expects a bunch of .bin files in one dir, MAME expects a bunch of .zip files (each zip containing all the .bin's for a game). The reason for this difference is that Atari games were on a single PROM chip in the cartridge (hence a single .bin file), whereas arcade games have many PROMS, each having its own corresponding .bin file (you should see the Gauntlet board, I'll post a pic here when I dig the sucker out). Easily the bulk of the area on a game board could be taken up with PROM chips. With all these .bin files it is far easier to collect them into zips (or sub-dirs on older MAME revs) rather than the chaos of tens of thousands of files overwhelming your file system ;)

1) Download the MAME binary, compiled for your Xbox from the internet (do not ask for this on forums as it is considered a rude question. Do not ask me for it, I will not hand it out).
2) Create a directory on your computer named "mame" (referred to from now on as mame
3) Unpack the zip or rar you got off the internet into the directory mame (see note2 for directory tree you should have)
4) Place any rom collections you have (.zip extension) in the mame roms directory.
5)a To play MAME off your hard drive: Place the mame (and all it's contents) onto your xbox hard drive in either an "emulators", "games", or "apps" directory and use the dashboard of your choice to access the emulator and load your games
5)b To play Stella off a cd or dvd rom as a game disk: Place the contents of the mame directory, but not the root dir its self onto a disk (using your favorite GDF iso maker and CD-burning utility).
Note2 (this is what your directory tree should look like before stuffing all your rom images into the mame oms directory):
mame
mamedefault.xbe
mamefaq.txt
mamemame.ini
mamemame.txt
mame cmamex.xbe
mamexbox.txt
mamemedia
mamemediafont.xpr
mame oms
mamesamples