INTRODUCTION

To demonstrate the versatility of the flicker-free mechanism I've produced this version of the arcade classic Pacman. It uses concepts based on those found in Macronics' 3K Space Invaders game. However, all program code has been written from scratch, which has allowed the opportunity to incorporate improvements to the techniques. The game requires 16K of RAM, and will automatically detect and configure itself to run on either a UK (50 Hz) or USA (60 Hz) version of the ZX80.

A video of the game running on a real ZX80 can be viewed on YouTube.

The game file is available from the downloads section.


DESCRIPTION

The game implements a fully featured version of Pacman, supporting a screen display of 24 rows by 31 columns. Only 31 of the possible 32 columns are used to ensure that the maze is symmetrical.


Title screenshot of ZX80 Pacman Screenshot of ZX80 Pacman

Pacman, represented by an inverse 'O', must travel around the maze eating all the dots (worth 1 point each). He will be chased by four ghosts. If they catch him then one of the three lives is lost. If all lives are lost the game is over, and a return is made to the title screen. To even up the odds, the maze contains four power pills, situated in the four corners (worth 10 points each). If Pacman eats one of these then for a short period of time he can chase the ghosts. Catching one ghost scores 100 points, the second is worth 200 points, the third 400 points and the fourth 800 points. If a ghost is caught then its eyes float back to the cage before the game continues.

At random, a money bonus will appear below the ghosts' cage but will only remain available for a brief period of time. A dollar bonus is worth 30 points, a pound bonus is worth 50 points, and a mystery bonus (represented by a question mark) is worth is random number of points. The Pacman and ghosts can make use of the tunnels leading off the sides of the screen and will reappear at the opposite side. An extra life is awarded for every 10,000 points collected and the game is won if a score of 100,000 is reached. The game keeps track of the highest score achieved and this is displayed both on the title screen and in the bottom right hand corner of the game screen. Once a maze has been cleared, a new identical maze commences.

The game can be played using either the cursor keys (5 for left, 6 for down, 7 for up and 8 for right, 0 for jump), Sinclair joystick/keys (6 for left, 7 for right, 8 for down, 9 for down, 0 for jump), or a Kempston joystick. Press key C to cycle through the control options.


LOADER OPERATION

The game is written entirely in machine code and, like 3K Space Invaders, is encoded within a BASIC program. This makes it easy (if a little tedious) to type in the program. The loader routine at lines 560 to 630 is more compact than the equivalent in Space Invaders but the machine code loader routine (defined in M$ in line 550) is more elaborate and introduces several enhancements.

The machine code loader rouitne performs a more comprehensive check of the format of the BASIC listing to ensure that only correctly formatted PRINT lines are present. The data strings within each PRINT line begin with a hexadecimal pair of characters that form a running total checksum of all preceding PRINT lines. The first PRINT line (line 10) begins with the hex pair '00', which is the initial value of the checksum. The loader routine will compute the current checksum after each PRINT line has been processed and will test this value against the first hex pair found in the next PRINT line. It is for this reason that the final PRINT line (line 86) consists of only the checksum hex characters. The use of the checksum therefore allows errors to be identified to a particular PRINT line. The loader routine parses the BASIC program twice, processing all PRINT lines until a line number greater than 255 is found. On the first pass the routine simply validates the checksum hex pairs at the start of each PRINT line. If all checksums are correct then a second pass commences but this time all hex pairs are decoded and poked into memory (beginning at $4000). If a checksum error was found during the validation pass then the program cursor is set to the line where the checksum failure was detected and the BASIC program listed from this line. A checksum failure can be caused either by the checksum hex pair itself being typed incorrectly or (more probably) due to a typing error in the hex pairs contained within the previous PRINT line.

The program listing for Pacman is shown below:


Program Listing of ZX80 Pacman (Part 1) Program Listing of ZX80 Pacman (Part 2)

When typing in the program, it is advisable to save the program frequently to cassette. The program should definitely be saved once all lines have been typed in. This is because if all lines are correct and the program is run then it will not be possible to return to BASIC. As with Space Invaders, the decoded game bytes are poked into RAM beginning at $4000 thereby overwritting the system variables and the BASIC program.

When the program is run, it takes about 15 seconds for the BASIC routine at lines 560 to 630 to process the hex pairs held in variable M$. It then takes a fraction of a second for the machine code loader to process all PRINT lines. During this time the ZX80 will not generate a TV picture and hence the screen will remain black.


GAME OPERATION

The game itself is structured to execute in six blocks of program functionality. These blocks are cycled through, with one block executed per TV field. The functionality blocks perform the following actions:

After eating a power pill, the cycle increases to seven blocks of program functionality. An additional read of the keyboard and moving of Pacman occurs in between moving the second and third ghosts.

A program cycle consists of cycling through all of the blocks of program functionality. At the start of a program cycle a variety of flags are tested. These flags are set by the functionality blocks from the previous program cycle. These flags test for conditions such as whether to display the score for a bonus, whether the game has been won, whether Pacman has been caught, and whether an extra life was awarded. The blocks of program functionality therefore determine whether any of these conditions has occurred and simply set flags to indicate this. This approach allows a program cycle to complete before further actions occur.

Miscellaneous activities - This routine handles several tasks. First it decrements the countdown timer until a money bouns is shown. When the timer expires then the routine displays the money bonus, and sets a countdown to remove the bonus with a random duration. This routine is also responsible for checking whether to open or close the cage door. The door will be closed once all ghosts have left it. If one or more ghosts are locked in then the door will open after a random duration has expired. Next the routine tests whether the ghosts are in 'flee' mode and if so it will flash them. Finally, the routine decrements the countdown timer for a power pill if there is one active.

Read keyboard and move Pacman - This routine determines whether any of the cursor keys have been pressed and attempts to move Pacman in the new direction. Pacman will continue to move in the direction he is travelling until either a wall is encountered or the player selects a new direction. If Pacman can move (either in the new direction selected or continue in the current direction) then a test is made to see whether he has eaten a bonus, or a dot, or a power pill. If a bonus was encountered then the score is increased appropriately and a new timer is set to a random value until another bonus is shown. If a dot was eaten then the score increments and a test is made to see whether all dots in the maze have been eaten. If they have then a new round is begun. If a power pill was eaten then the ghosts are set into 'flee' mode and a timer set to a random duration. Pacman can chase the ghost until this timer expires. If neither a bonus, dot, or a power pill was found then a test is made to see if Pacman has encountered a ghost. If he has then a test is made to see whether the ghosts are in 'hunt' mode or 'flee' mode and a group of flags are set appropriately. These flags will be tested at the start of the next program cycle, thereby allowing Pacman and all the ghosts to be updated first. If the countdown timer for an active power pill is about to expire then this routine is responsible for flashing Pacman to indicate this condition.

Move ghost n - This routine is used to move a particular ghost. It begins by checking whether the ghost is in the cage and if so whether the cage door is open. If it is then the ghost will be moved upwards. If the ghost is outside the cage then the routine determines which directions are available for the ghost to move in. The ghost is only allowed to reverse its current direction if there are no other available directions to move in, e.g. other ghosts or walls block the way. If in 'hunt' mode the directions that would bring the ghost closer to Pacman are the determined, but if in 'flee' mode then those directions that would move the ghost further away are determined. The direction to move the ghost is then selected at random out of the shortlist of suitable possibilities. The ghost is then moved and a check made to see whether it has caught Pacman, or been caught by Pacman. Status flags are set as appropriate.

Start of program cycle tasks - At the start of each program cycle the various flags and counters that the blocks of program functionality may have set are checked. A test is made to see whether the player has exceeded a 10,000 point threshold, and hence whether to award an extra life. Another test checks whether all of the dots have been eaten and if they have then a new maze is commenced. A check is also made to see whether the player has scored 100,000 or more, and hence whether they have won the game. Another test checks whether Pacman has been caught by a ghost and if so a life is decremented. Tests are made to see whether a money bonus was earned or whether a ghost was caught, and hence whether to display the points awarded for these. A separate display loop is used to shows the awarded points. If a ghost was caught by Pacman then a further display loop is used to animate moving the ghost's eyes back to the cage.


DOWNLOADS

The game can be downloaded below, and is made available for private use or for public demonstrations. It is not to be included in emulator distributions or sold as part of a commercial package. Please do not re-distribute the program file but link to this site instead.

Click here to download ZX80 Pacman in .O program format. Run the game using RUN. [Version 1.03]

I have produced a small batch of cassettes with printed inlay cards and labels for the ZX80 Pacman game. Please contact me if you are interested in obtaining a copy of the cassette.



If you have a Spectrum 128 or +2 and an Interface 2 then you can use the ZX80 Pacman game with my ZX80 Emulator ROM cartridge.

I have also ported the game to the ZX81, and have produced a small batch of cassettes for it.

Click here to download ZX81 Pacman in .P and .P81 program formats. The file name is "ZX81 PACMAN". [Version 1.00]

  -   Disclaimer