Pac-Man Emulation Guide v0.1, Oct 2008

This document is a reference for the Pac-Man video game arcade hardware, mainly written to document my findings as I create a Pac-Man emulator for learning purposes.

The information was gathered from the Internet and my own investigations and was merged and edited into this document. There are various red TODOs left in the document where I hope to add or clarify material.

This was written by Chris Lomont in Oct 2008. If you have comments or fixes then email me at (my first name) at lomont.org. Also check out my website www.lomont.org.

 

To start, Figure 1 shows a Pac-Man “attract” screen and the start of a level.

 

http://upload.wikimedia.org/wikipedia/en/5/51/Pacman_title_na.pnghttp://upload.wikimedia.org/wikipedia/en/5/59/Pac-man.png

Figure 1 – Two views of Pac-Man        


 

Introduction

Throughout this document decimal numbers appear as usual, and hexadecimal numbers are suffixed with an ‘h’. For example 1K is 1024 bytes = 400h bytes.

Pac-Man hardware is at the highest level:

·         Main CPU : Z80A at 3.072 MHZ

·         ROM: 16K of ROM in four 4K chips

·         RAM: almost 2K of working RAM

·         Video:

o   2K of RAM as follows

§  1K holds tile information.

§  1K holds per tile palette indices.

o   The visible screen is 28x36 tiles.

o   Each tile is an 8x8 pixel 4-color image from 16 possible colors.

o   Video resolution is thus 224x288 pixels.

o   Eight 16x16 pixel hardware sprites, each with a 4-color palette from 16 possible colors.

o   60.61 frames per second (60.61fps).

·         Sound Chip : Custom monophonic 3-voice 4-bit Wave Sound Generator

Z80

The heart of the Pac-Man arcade machine is the 8-bit Z80 Central Processing Unit (CPU). It was released in July 1976, borrowing ideas from the Intel 8080. In fact it was designed to be binary compatible with the 8080.

The Pac-Man Z80 runs at 3.072 MHZ.

One important feature is that it addresses 16 bits of memory, so all Pac-Man addresses must lie in the range 0-65535 (0000h-FFFFh). Pac-Man actually uses less than half of this.

The Z80 also supports three interrupt modes, although the game only uses one, the so-called “mode 2” set via the Z80 instruction “IM 2.” An emulator must support port 0 in hardware, which is used to store a byte (used to form an address for an interrupt vector) which must be returned when triggering an interrupt. See the section on interrupts.

Memory Map

All hardware is memory-mapped, that is, can be accessed by reading and writing memory addresses from the CPU.

The game ROM uses the lowest 16K of memory, followed by 2K of video memory for tile selection and per tile palettes (1K each), and then a little less than 2K of general purpose RAM. This is followed at address 5000h with 256 bytes of memory-mapped hardware devices such as counters, sound hardware, and joystick switches.

 

Addresses

Bytes

Description

0000h-3FFFh

16,384

Game ROM in four 1K chips:

0000h-0FFFh pacman.6e

1000h-1FFFh pacman.6f

2000h-2FFFh pacman.6h

3000h-3FFFh pacman.6j

4000h-43FFh

1024

Video RAM (tile information)

4400h-47FFh

1024

Video RAM (tile palettes)

4800h-4FEFh

2032

RAM

4FF0h-4FFFh

16

Sprite #, x and y flip bits (write only). 8 pairs of 2 bytes:

First byte is sprite number 0-31, (bits 2-7), X flip (bit1), Y flip(bit 0)

Second byte is sprite palette

 

 

Memory Mapped Registers*

 

5000h-503Fh read

1

IN0 (joystick and coin slot) (each byte returns same value)

5000h write

1

Interrupt enable (bit 0: 0 = disabled, 1 = enabled)

5001h write

1

Sound enable (bit 0: 0 = disabled, 1 = enabled)

5002h write

1

??? Aux board enable?

5003h

1

Flip screen (bit 0: 0 = normal, 1 = flipped)

5004h

1

1 player start lamp (bit 0: 0 = on, 1 = off)

5005h

1

2 players start lamp (bit 0: 0 = on, 1 = off)

5006h

1

Coin lockout (bit 0: 0 = unlocked, 1 = locked)

5007h

1

Coin counter (trigger by changing bit 0 from 0 to 1)

5040h-507Fh read

64

IN1 (joystick and start buttons) (each byte returns same value)

5040h-5045h write

6

Sound voice 1

 

 

5040-5044 – accumulator (low nibbles, used by H/W only)

 

 

5045 – waveform (low nibble)

5046h-504Ah write

5

Sound voice 2, laid out like voice 1, missing low accumulator nibble

504Bh-504Fh write

5

Sound voice 3, laid out like voice 1, missing low accumulator nibble

5050h-5054h write

5

Voice 1 frequency (low nibbles)

5055h write

1