To demonstrate the versatility of the flicker-free mechanism I've produced this version of the arcade classic Pacman for the 4K ROM ZX80. A version to run on the ZX80 fitted with the 8K ROM upgrade is also available. The game uses concepts based on those found in Macronics' 3K Space Intruders game. However, all program code has been written from scratch, which has allowed the opportunity to incorporate improvements to the techniques. The game requires a minimum of 8K 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 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.
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.
MACHINE CODE STORAGE
The game is written entirely in machine code, and this is held in a single giant REM statement. Storing machine code within a REM statement introduces a problem in that the ZX80 generally cannot list a BASIC program containing such a line. A system crash is likely to occur if the machine code contains any bytes that would be translated into non-displayable characters by the BASIC editor. Further, if the machine code contains a newline character (code $76) then the BASIC listing will be displayed incorrectly and subsequent lines cannot be edited. A crash may also occur. This problem is due to the ZX80 mistakenly assuming the newline character denotes the end of the REM statement. The bytes that follow the newline character are therefore interpreted as the start of the next line, and it is very unlikely that these bytes will (by chance) form a valid BASIC line. Both issues only cause a problem if the REM statement is listed, but storing the machine code in the first BASIC line is not practical since the ZX80 will automatically list a program once loaded from cassette. A way to overcome this problem is to add a sufficient number of BASIC lines before the REM containing the machine code. In this way, the listing is displayed after loading will only consist of standard BASIC lines. This is the approach used in ZX80 Pacman.
When first run, the game performs an integrity test to ensure that it has loaded from cassette correctly. If an error is detected then a return to BASIC is made and an error message displayed.
The game 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:
- Miscellaneous activities (handle display of bonuses, open/close cage door, flash ghosts, decrement power pill timer).
- Read the keyboard and move Pacman.
- Move the first ghost.
- Move the second ghost.
- Move the third ghost.
- Move the fourth ghost.
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.
I have produced two versions of the game - one for the ZX80 with its original 4K ROM and one for ZX80 fitted with the 8K ROM upgrade. The 8K ROM version will also run on the ZX81. The two versions differ only with regard to the video display loop, character codes and the BASIC program.
Both game versions can be downloaded below, and are made available for private use or for public demonstrations. They are not to be included in emulator distributions or sold as part of a commercial package. Please do not re-distribute the program files but link to this site instead. Should you like it and wish to make a small payment for the download then any amount would be appreciated and can be done using the Donate link at the bottom right.
|Click here to download 16K ZX80 (4K ROM) Pacman in .O program format (G8001). Run the game using RUN. [Version 1.05]|
|Click here to download ZX80 (8K ROM) / ZX81 Kong in .P and .P81 program formats (G8102). The file name is "ZX81 PACMAN". [Version 1.03]|
I have produced a small batch of cassettes with printed inlay cards and labels for the ZX80 Pacman game. Two versions exists - one for the 4K ROM ZX80 and one for 8K ROM ZX80 / ZX81. Please contact me if you are interested in obtaining a copy of either cassette. The 4K ROM version is shown below.
If you have a Spectrum 128 or +2 and an Interface 2 then you can use the 4K ROM ZX80 Pacman game with my ZX80 Emulator ROM cartridge.