Spotlight › PaccMan

The arcade Pac-Man, in C

A second Pac-Man for os8088, sharing no code with the first: the Namco arcade machine's own maze, ghosts and timings, ported from C. On a 4.77 MHz PC it is half the speed of the assembly one, which is the answer to the question that started it.

field
28 x 36 tiles
written in
2,050 lines of C
on a 4.77 MHz XT
2.18 frames a second

This one wants a 386. On an XT the other Pac-Man is the one to play, and both ship for that reason.

PaccMan
A PaccMan window on the os8088 desktop showing the arcade attract screen: CHARACTER / NICKNAME at the top and the four ghosts drawn in red, pink, cyan and orange beside their names -- SHADOW BLINKY, SPEEDY PINKY, BASHFUL INKY, POKEY CLYDE -- with a 10 PTS and 50 PTS legend below.
The attract screen, on the arcade's own schedule. Each ghost is drawn, named and nicknamed in turn, at the tick the arcade machine did it. The 10 PTS and 50 PTS legend and the CREDIT line underneath are the board's too.

Two Pac-Men, one system

They share no source, no name, no disk -- and which one you want depends on your machine.

os8088 already had a Pac-Man. It is a hand-written 8086 assembly port of the Atari 8-bit computer version published by Roklan, on a wide field of forty tiles by twenty-two, and on a 4.77 MHz machine with a CGA card it runs at eighteen frames a second and then goes to sleep until the next one is due.

PaccMan is the arcade machine. It is a port of Andre Weissflog's pacman.c, a C program that reproduces the 1980 Namco original, and the field is the tall one: twenty-eight tiles across by thirty-six down, 224 pixels by 288.

Nothing is shared between them -- not a file, not a name, not a folder, not a disk. That is a rule in this project rather than an accident: a port stands on its own or it is not a port. What they do share is the shape of the drawing, which the arcade one borrowed as a precedent and not as code.

Both ship. On an XT the assembly one is the one to play. On a 386 this one is, and it is the one that is the arcade machine.

What arcade-accurate means

The maze, the ghosts and the timings are the board's, not a memory of them.

The maze is the arcade machine's: 240 dots, four power pills, the tunnel row that wraps around the sides, and the ghost house in the middle. The tile shapes, the sprite shapes and the colours are read out of the arcade board's own memory contents and turned into tables the project can compile.

The four ghosts have their real personalities. Blinky chases you. Pinky aims at where you are going rather than where you are. Inky uses Blinky's position as well as yours. Clyde loses his nerve when he gets close. They alternate between scattering to their corners and chasing on the arcade's own schedule, and they leave the house on its own dot counts.

The attract screen introduces them one at a time -- CHARACTER, then NICKNAME, then SHADOW and BLINKY, SPEEDY and PINKY, BASHFUL and INKY, POKEY and CLYDE -- on the exact ticks the arcade used. The fruit, the bonus values and the length of a fright come from the arcade's own twenty-one-row level table, and the game runs at its sixty steps a second.

The arcade machine had three sound voices playing waveforms. This machine has a PC speaker, which is one square wave with no volume control. So one voice is chosen each tick by priority: an effect first, then the siren or the fright tone, then the bass. The reduction is stated rather than hidden, which is the house rule for anything that cannot be carried across.

What the program this was ported from does not have is not here either. There is no chase animation between rounds, no coffee-break intermissions, and no per-round speed table.

See it running

A round in the arcade maze, and the menu an arcade cabinet never had.

PaccMan
The PaccMan window showing a round in progress: the tall blue Namco maze full of dots, Pac-Man in the lower left, three ghosts inside the ghost house and a red ghost out above it. The score reads 100.
The Namco maze, taller than it is wide. 240 dots, four power pills, the tunnel that wraps around the sides, and the ghost house in the middle with three still inside it. Blinky is already out and chasing.
Game
The Game menu open over the attract screen, listing New Game, Pause, Sound Off and Full Screen, with PRESS ANY KEY TO START visible underneath.
The four things every program here offers. A new game, pause, sound off and the whole screen, none of which an arcade cabinet had a control for. P, N and F do the same from the keyboard.

Getting a frame onto the screen

Bands of eight rows, and where the time actually goes.

The picture is divided into horizontal bands eight pixels tall. Only the bands that changed since the last frame are rebuilt, in the program's own memory, and each finished band is sent to the screen in a single operation rather than a call per shape.

On a colour screen the band is handed over already arranged in the four colour planes a VGA card wants. Going through the general-purpose picture call instead would be about six times slower at this width, because that call has to work out the arrangement one pixel at a time.

That is a real gain and it is not enough. Rearranging a band into the form the card wants costs 41.78 milliseconds where sending it costs 7.36, and each step of the game logic costs 18.6 milliseconds with three of them in a frame. Add those up on a 4.77 MHz processor and the frame rate follows.

The question, and the answer

It was meant to be the faster Pac-Man on an old machine. Measured, it is not.

The port started from a guess worth testing: that drawing this way, in bands sent straight to the card, might make a C Pac-Man faster on a 4.77 MHz XT than the hand-written assembly one.

Measured on a cycle-accurate 4.77 MHz XT with a VGA card, PaccMan draws 2.18 frames a second and the assembly Pac-Man draws 4.14. With a CGA card it is 2.94 against 18.21, and with Hercules 2.62 against 16.71. The answer is no on all three, and the project's own test prints that sentence whichever way the numbers come out.

There is one column this one holds, and only on VGA: game speed, twenty-four per cent of arcade pace against twenty-three. A slow frame here carries two ticks of game time rather than one, so what a player loses is smoothness rather than the game's own clock.

The two are not drawing the same picture. This one draws the arcade's twenty-eight by thirty-six field; the other draws a forty by twenty-two one. It is not a like-for-like race between two implementations of one thing, and the number that matters is the one the question was about: on the machine it was asked about, no.

On a 386 it runs at a speed nobody has to apologise for. On a 4.77 MHz XT it plays at about a fifth of arcade speed, and there is a machine profile in the project that exists to watch it do exactly that.

Playing it

One floppy, one double-click, and a key at the attract screen.

  1. Take paccman.img from the release, or apps-all.img, which carries every program on one floppy. The disk holds the program and its README and nothing else.

  2. Boot os8088 with it in the second drive, double-click Disk B, and double-click PACCMAN.O88. The attract screen runs; press a key to start a round.

  3. Arrow keys or W, A, S and D. P pauses, N starts a new game, F takes the whole screen and Escape gives it back. Sound can be switched off from the Game menu.

  4. A 386 is what to run it on. On a 4.77 MHz machine, play the other Pac-Man in the games folder of the software disk -- that is why it is still there.