INTRODUCTION

Macronics produced a version of Space Invaders for the 3K ZX80 and also a cut-down version of Space Intruders for the 1K ZX80. Both were produced in 1981 (or possibly 1980), and could be purchased pre-recorded on cassette or as a printed listing. The game was referred to as both Space Intruders (Source: Your Computer, Vol. 1 No. 5, December 1981) and Space Invaders (Souce: Computer & Video Games, Issue 1, November 1981), and was also ported to the ZX80 with 8K ROM upgrade. Note that this game will only work with a UK (50 Hz) version of the ZX80, but it can be easily modified to run on a USA model (60 Hz) as detailed later.


DESCRIPTION

Macronics' 3K Space Intruders implements a full screen (24 row by 31 column) cut-down version of the arcade classic.


Screenshot of 3K ZX80 Space Intruders
ZX80 (4K ROM) Space Intruders 3K

There are 40 invaders to destroy and the player only has a single life to do this with. The player moves left using keys 5 or 6 and right using keys 8 or 3. A missile is fired using keys 0 or 1. Only one missile may be fired at a time, and the invaders can only drop one bomb at a time. It is sometimes possible for a missile and a bomb to annihilate each other. Each time an invader is hit, the score increases by the numerical value shown as part of that invader. Once a wave has been destroyed, it is replaced by new wave identical to the previous one. The display shows the current score in the bottom left hand corner and the previous game's score in the bottom right hand corner.



LOADER OPERATION

Although the game is written entirely in machine code, it is encoded within a BASIC program. This method was probably chosen to allow the game to be presented in a manner which could be sold as a printed listing. However, it has another advantage. If the program had been embedded in a REM statement (as typically done for machine code programs on the ZX81) then the ZX80 would likely become corrupt if any attempt to list the REM statement were made. Corruption would occur because the ZX80 interprets a newline character as signifying the end of a BASIC line. When a newline character is encountered within a REM statement then the bytes following it are interpreted as the start of a new BASIC line, and the ROM attempts to display them as such. Since the ROM locates each BASIC line by scanning for the terminating newline character, it becomes unable to locate genuine BASIC lines within the program and so cannot run them.

The program listing for Space Intruders is shown below:


Program Listing of ZX80 4K ROM Space Intruders Program Listing of ZX80 8K ROM Space Intruders
4K ROM Version 8K ROM Version

The BASIC program begins by jumping to line 300. This routine reads the characters stored in string M$, converts pairs of hexadecimal characters into byte values, and pokes these into memory forming a short machine code routine. This machine code routine is then run, and it performs a similar function to the BASIC routine that constructed it. The routine interprets the pairs of hexadecimal characters found in all BASIC lines with line number less than 256 and commencing with a PRINT command, and stores them in memory. The bytes form the Space Intruders game. The last line to interpret is identified when the high byte of the line number is $00, and hence the last possible line that the routine could process is line 255.

The machine code loader routine stores the interpreted byte values at address $4000 onwards, which is where the system variables and BASIC program normally reside. Therefore as the bytes of the Space Intruders game are being constructed in RAM, the BASIC program listing it is being constructed from is overwritten. Note that there is no danger of the constructed game inadvertently overwriting BASIC program lines that are still to be interpreted since two hexadecimal characters within a PRINT command corresponds to only a single byte of the game. The fact that the BASIC program gets overwritten means that the loader routine must end by running the game. If it were to attempt to return to BASIC then a crash would result. While the game is being constructed in RAM, the ZX80 will not generate a TV picture and hence the screen will remain black.

To modify the game to run on USA models of the ZX80 (60 Hz), change the two hex digits coloured red in line 30 from value '30' to '18', and for the 8K ROM version only also change the two hex digits coloured red in line 40 from value '2F' to '17'.


GAME OPERATION

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

Move row of invaders left or right - This routine shifts all the invaders left or right, handling the toggling of the side characters for invaders in the second and fourth rows. At each invocation, the routine moves all characters on a particular row by one position left or right. Every character on a row is shifted each time, whether blank or not, and hence this ensures that the routine completes after a fixed duration of time. The area that the invaders can occupy spans rows 0 to 14, although once the invaders move onto row 14 the game is over. On the odd rows the invaders are shifted to the right, and on the even rows they are shifted to the left. Hence the invaders appear to zig-zag their way down the screen. Rows are shifted in decending order, beginning with row 13 and ending with row 0. Initially the invaders are located at the left hand side of the screen and so are shifted to the right. The invaders are shifted by eight columns before they reach the edge of the screen and are moved down a row. The invaders cannot occupy columns 0 or 31, and so these are always filled with black spaces. These black spaces are shifted along with the invaders, thereby overwriting the 'trail' character left by the outer invader. Only the black space 'following' the invaders is shifted for a row and so neither columns of black spaces are ever overwritten.

Move invader bomb and fired missile - This routine first checks whether there is an active invader bomb and if so it moves it one row down the screen. If it reaches row 22 then the bomb has missed the base and so is discarded. If it has not reached row 22 then a check is made to see if the bomb has hit a shield. If it has then that character in the shield is removed. If a shield was not hit then a check is made to see if the bomb has hit the missile base. If it has then the game is over. If the bomb has not hit anything then it is drawn at its new position. The routine then checks whether there is an active missile and moves it up one row if there is one. A check is made to see whether the missile has moved off the top of the screen, and hence can be discarded. If the missile is still on screen then a check is made to see whether it has hit an invader bomb. If it has then the missile destroys the bomb. If the missile has not hit an invader bomb then a test is performed to see if it has hit a shield. If it has then that character in the shield is removed. If a shield was not hit then a test is made to see if an invader was hit. If one was then it is erased from the screen and its numeric value added to the score. If the missile did not hit anything then it is drawn at its new position.

Read keyboard and move missile base - This routine reads the top row of the keyboard. The row is electrically wired as two sets of 5 keys, and normally only one set would be read at a time. By reading them together means that cursor keys 5 (left) and 8 (right) and 0 (fire) are all read in one go. However, it also means that key 1 cannot be differentiated from key 0, key 8 cannot be differentiated from key 3, and key 5 cannot be differentiated from key 6. The missile base can be moved between columns 2 to 28 on row 21.

Test whether to drop an invader bomb - This routine searches the invader area from row 13 up to row 0 at the column where the missile base is. It searches for an invader that is directly above the missile base and sets a flag when one is found. Since all rows are checked, this flag ensures that the lowest invader found is the one that drops the bomb. The way the routine has been written means that it is possible for the routine to write to the first page of the ROM area when there is no active invader bomb and no active missile.


DOWNLOADS

Click here to download 3K ZX80 (4K ROM) Space Intruders in .O program format.
Click here to download a disassembly of the 3K ZX80 (4K ROM) Space Intruders loader routine.
Click here to download a disassembly of the 3K ZX80 (4K ROM) Space Intruders game.
Click here to download 3K ZX80 (8K ROM) Space Intruders in .P and .P81 program formats. The file name is "SI". Run the game using RUN.
Click here to download a disassembly of the 3K ZX80 (8K ROM) Space Intruders loader routine.
Click here to download a disassembly of the 3K ZX80 (8K ROM) Space Intruders game.