CPU

This is based on the Java Z80 microprocessor emulator that can be found here: https://code.google.com/p/z80-cpu/ with additions to support the mode 2 external interrupt (INT) required by the machine's sound and display hardware. Pressing 'r' while the emulator is running will force a CPU reset.

Memory

This emulates the CPU address bus (Z80Memory.java) and provides the address mappings to the program ROM (0x0000 to 0x3fff), RAM (0x4000 to 0x4fff) and memory mapped IO space (0x5000 to 0x50ff) which is used to control the sound, sprites and player controls.

IO

Not to be confused with the memory mapped IO described above, this emulates the Z80 peripheral hardware IO bus (Z80IO.java). In this emulation this performs only one function: to store the INT vector for use during the 60Hz VBLANK interrupt.

Video

This emulates the video hardware and produces a representation of the screen based on the state of the video RAM and sprite registers. It runs 60 times a second. The Pac Man screen consists of an array of static tiles overlaid with sprites. The tiles are stored in a character based array in RAM alongside the corresponding palette entries for each tile. The sprite hardware is completely separate from the CPU and is controlled by the sprite registers in the memory mapped IO space. The hardware can draw up to eight 16x16 pixel sprites anywhere on the screen. The tile layout, tile/sprite image format and colour lookup is completely bonkers. See Chris's PDF for a full explanation. Maybe it makes more sense when you look at the actual hardware. See Video.java for the implementation.

Sound

The Pac Man sound hardware supports 3 voices on a single mono channel. Each of these voices can select the volume and frequency of one of 8 output waveforms. The sound registers are written to by the CPU over the memory mapped IO space during the 60Hz VBLANK interrupt. The Pac Man sound hardware runs at a 96kHz sample rate so the output from the sound emulator is low pass filtered and downsampled to 22050Hz for output. See Sound.java for implementation.

Inputs

This emulation currently supports the following keyboard controls:

Machine controls

Player 1 controls (cursor keys)

Player 2 controls (cursor keys)

1 player start button (1)

2 player start button (2)

Coin input (5).

The DIP switches are hardcoded. See Io.java for implementation.

Emulator controls

'r' to reset the Z80 emulation

'c' to apply an invincibility cheat patch to the ROM image (do this after the machine boots else it'll fail the ROM test)

'p' to pause the emulation

ROMs

You'll need to get a set of ROMs from somewhere else to make this work. Put the following ROM images in a .zip file in the project root directory and define ROMPACK_FILENAME in Main.java to be the name of the file and it'll get picked up when the machine starts. You may have to rename the ROM filenames in the .zip to match these depending where you get them from: