views:

1383

answers:

8

For a long time I've been curious about game emulation and how it works. I've heard that Gameboy emulation is often a first choice for a first project. I would like to assume that many others would also be interested in such a project, but haven't found any published books on the subject.

I know of Marat Fayzullin's article at http://fms.komkon.org/EMUL8/HOWTO.html, but I was looking for something with more depth. Anyone know of a published book even remotely relating to this subject? Maybe there aren't any specifically on game emulation, but emulation in general that can easily be applied to games? Any suggestions would be appreciated!

+4  A: 

Emulation, regardless of games or not, is about properly emulating the platform itself: the CPU, the memory mapped IO ports, sound, graphics and any eventual extra hardware. It's essentially a huge state machine.

When you've done that, you basically run game-by-game and break your perfect emulation by adding in the quirks from the original hardware platform.

Mikael Jansson
Any specific book suggestions on the subject?
Consty
A book on virtual machines, and of course the reference documentation for your platform of choice. If you're not up to par on how computers work, you might find yourself in the need of a book that describes memory mapped IO, interrupts, etc.
Mikael Jansson
You forgot the part where you spend 12 hours looking for a hard to spot typo in a single opcode.
Toon Van Acker
+2  A: 

I have never written a game emulator, but if I understand it correctly, it's essentially a virtual machine emulating game consoles. You might have a better luck finding books and resource using the keyword "virtual machine."

Also understanding the topic of "computer architecture" would greatly help you, especially the type of CPU the game consoles use.

Many of the modern computer languages are designed to run on virtual machines as byte code, so looking at source code of lua, jvm, parrot, python may help.

Since you want a book recommendation, I'll list Hennessy & Patterson's Computer Architecture: A Quantitative Approach and a book on Intel assembly language. For example, Assembly Language for Intel-Based Computers.

According to Wikipedia, Gameboy uses a custom 8-bit Sharp LR35902 (Z80-clone). Read the entry on Zilog Z80. If you fully understand what they are talking about, you are ready to code.

eed3si9n
+4  A: 

Writing game emulators is not a common enough task to warrant a book - there are none. If fact there are few books specific to writing emulators of any kind, nevermind game emulators.

It's a very niche topic, and about the only way you'll learn is by looking to the people who have written or maintained an emulator, and you already have those resources.

If you are set on using a book to help you learn this, though, I'd suggest you look at a more broad topic of designing computers from an architecture standpoint. By understanding how the processor works at a fundamental level you will be able to write code to simulate various aspects of it - it's essentially a large state machine, and it's not sufficient to understand the machine code - you really need to understand how instructions move through the processor and how the registers and memory are handled.

It gets much more complex when you add in data and instruction caching, context switching, parallel execution paths, etc, etc, etc. Gaming is even more difficult because the designers relied heavily on timing paths and processor quirks in order to get the most out of the resources available.

The seminal reference here is "Computer Organization and Design" by Patterson and Hennessy.

The reason why the game boy is often a good first target is because it's a very simple processor by today's standards, and yet complex enough and interesting enough that it should keep you busy for some time trying to get it past the first few games. It gets exponentially harder to emulate the later processors..

Adam Davis
A: 

Maybe not so much in-depth, but I think that reading about the emulators and the UtraHLE emulator in particular at wikipedia could be a good start.

epatel
A: 

It really depends on what you are looking for. If you are just interested in emulating a specific well-known CPU or you also are pasionate about the process of reversing the software/hardware to be able to emulate it.

For general emulation I would read the mame developer wiki.

For details of unencryption of ROMs and fun internal details read the blogs of Aaron Giles and Nicola.

antonio
A: 

A good start is http://sourceforge.net/projects/desmume/,

It's a Nintendo DS emulator and you can get the Visual Studio 2008 sources!

Click Ok
A: 

There is a thesis on this available on the net. 150 pages, book-style. See here.

Update: Before working on a complete system, you might want to take a look at the 2006 ICFP contest. The first task is to emulate a very simple CPU (13 instructions).

mdm
+3  A: 

Emulation is one of the most facinating projects you can work on. One of the best ways to understand a language is to implement it. One of the best ways to understand a processor is to emulate it.

I recommend:

  1. Get warm and fuzzy with MAME. Read Aaron Giles' MAME Memories.

  2. Learn an 8-bit micro. Z80 and 6502 are my two favorites. Motorola 68000 is a pretty 16-bit architecture. Used books on these topics are cheap and easy to find.

  3. Start with a system that is well-documented -- this is why most people choose GameBoy. The less documented the system, the more diffucult the task. The extreme of this scale is pure reverse engineering. See elSemi's notes on reversing the DSP of the Model2 or Nicola Salmoria's notes on cracking the CPS2 encryption.

  4. Write a simple, interpreted emulator for the processor and system of your choice.

As a hilarious side note, sometimes the hardest part of reverse engineering is getting your hands on the data. Don't forget that somebody had to physically dump these chips at some point.

Another advanced direction to pursue is dynamic recompilation. This is a pure performance enhancement employed in the emulation of more recent systems. The Nintendo64 emulator 1964 is open source and has a terrific recompilation engine. A more recent development is using this technique to emulate more ancient systems -- say, a Sega Genesis -- when the host environment is extremely slow -- say, a Flash Virtual Machine. Also, we have slyly left the domain of emulation and entered the domain of compilers and virtual machines! The Dragon Book is your friend.

Anyways, there are a lot of resources out there and emulator authors are known for being extremely helpful. Have fun, and learn a lot!

Z80 and 6502 were the ones we all learned back then. Can't think of any other relevant 8-bit chip except maybe the 6809e. The 65816 (actually a 8/16 hybrid) was a work of strange beauty, but wasn't learned by many people. 68000 is, I think, the easiest and best assembly ever to be mass market.
Nosredna