--- title: "Galaxy Invaders" id: 51886 type: "computer_media" slug: "galaxy-invaders" url: "http://localhost/computer_media/galaxy-invaders/" markdown_url: "http://localhost/computer_media/galaxy-invaders.md" published_at: "2023-08-16T01:42:21+00:00" modified_at: "2026-04-01T18:14:23+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2023/08/GalaxyInvaders.jpg" excerpt: "A full Space Invaders clone with seven alien craft, laser fire, collision detection, and a configurable speed — all driven by a substantial machine code engine hidden in REM statements." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "International Publishing & Software Inc" slug: "international-publishing-software-inc" taxonomy: "post_tag" url: "http://localhost/tag/international-publishing-software-inc/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Arcade" slug: "arcade" taxonomy: "genre" url: "http://localhost/type/arcade/" - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_type: "Cassette" download_url: "https://archive.org/download/timex-sinclair-software-archive/Galaxy Invaders (1982)(IPS)(CA)(TS1000)(Cassette).zip" mediadate: "1982" producer_company: - id: 10960 title: "International Publishing & Software Inc" type: "company" url: "http://localhost/company/international-publishing-software-inc/" images: - url: "http://localhost/wp-content/uploads/2023/08/GalaxyInvaders.jpg" related_products: - id: 12669 title: "Galaxy Invaders" type: "product" url: "http://localhost/product/galaxy-invaders-2/" media_type_tags: "Arcade, Game" --- # Galaxy Invaders Galaxy Invaders is a Space Invaders-style arcade game featuring seven alien craft that can fire at or crash into the player’s laser base, which can withstand seven hits before being destroyed. The player moves left and right and fires a laser using keys 5, 8, and 0. The bulk of the program is a large machine code routine stored in REM lines 10 and 15, loaded into memory via a USR call at line 30. Game speed is configurable from 1 to 100 and is POKEd into address 16680, which controls the interrupt timing register (the ZX81’s R register delay), with the formula 255 minus twice the input value written directly to that address. *** ## Program Analysis ### Program Structure The program is split into two layers: a small BASIC loader/setup section (lines 20–94) and a large machine code payload embedded in the REM statements at lines 10 and 15. Line 16 contains a decorative title banner using inverse characters. The BASIC section handles screen setup, the instruction display, speed input, and then hands control to machine code via a `GO TO 1` at line 94 — targeting a non-existent line, which is a well-known technique to transfer execution into the machine code that was initialized by the earlier `USR` call. ### Machine Code Loading Line 30 executes `LET X=USR 18177`. Address 18177 decimal is 0x4701, which falls within the REM data area of line 10 (the ZX81 stores REM content starting a few bytes into the line, at address 0x4009 for the first REM). The machine code in the REM lines is thus directly executed by the `USR` call, which sets up the game engine in RAM. The REM at line 10 contains several hundred bytes of Z80 machine code; line 15 continues with additional routines. Together they implement all game logic: alien movement, collision detection, laser handling, scoring, and display. ### Speed Control via POKE Lines 93 and 35 both POKE address 16680 (0x4128). Line 35 writes 252 as an initial value; line 93 writes `INT(255 - 2*X)` where X is the player’s chosen speed (1–100). Address 16680 is within the system variables area and is used here to control the game loop’s delay constant, effectively scaling game speed. A higher input value results in a lower POKE value and thus a faster game. ### Input Validation Lines 85–91 implement a manual integer-parsing routine for the speed input rather than using `VAL`. The code checks each character’s `CODE` value against the range 28–37 (ZX81 digit tokens 0–9), rejects strings longer than 3 characters, and reconstructs the numeric value digit by digit using powers of ten. This avoids the overhead of the BASIC `VAL` function and also guards against non-numeric input. - Line 86: Gets string length into `B` - Line 87–90: Loops over each character, accumulating the numeric value in `X` using `10**(V-1)` weighting on reversed digits - Line 91: Rejects zero or values above 100, looping back to re-prompt ### Screen Initialization Lines 62–64 clear the play area by printing spaces across rows 1–21. Line 72 prints the key legend using a combination of block graphics characters for a decorative border. The title at line 70 is displayed entirely in inverse video using the `%` escape sequences for each character. ### Notable Techniques - The `GO TO 1` at line 94 transfers control into unlisted machine code — a standard technique to invoke an ML game loop from BASIC. - The machine code in the REM lines uses Z80 structured code with call/return patterns visible in the hex: sequences of `CD` (CALL), `C9` (RET), `ED 53`/`ED 5B` (LD (nn),DE / LD DE,(nn)), indicating well-structured subroutine architecture. - The `SLOW` command at line 20 ensures the display is updated during the game loop, which is necessary for the machine code to produce visible output. - The SAVE command at line 69 uses an inverse-video filename. ### Key Variables | Variable | Usage | | --- | --- | | `X` | Loop counter, USR return value, parsed speed value | | `X$` | Raw string input for speed | | `B` | Length of input string | | `V` | Loop index for digit parsing | ### Potential Anomalies Line 65 jumps to line 72 with `GO TO 72`, skipping line 69 (the SAVE command) and line 70 (the title print). This means the title banner at line 70 is never displayed during normal program execution — it would only be reached if the program were run from line 70 directly. This is likely intentional: the title was used during development or loading, and line 65 bypasses it to go straight to the instructions screen. ## Source Code ``` 10 REM \1E\00\00\00\FF\FF\00\00\00\00\00\00\B2\4C\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\02\00\01\00\00\00\00\00\00\00\00\00\00\00\4D\4F\06\15\2C\4F\06\14\00\00\00\00\00\00\00\00\00\00\00\00\62\4D\0B\06\00\02\49\4D\13\05\00\02\9C\4E\1C\0F\05\03\8A\4E\0A\0F\03\05\6D\4D\16\06\07\02\1A\4E\1E\0B\04\03\0A\4F\06\13\04\01\01\01\2B\4F\06\14\2C\4F\06\14\00\00\2A\F8\40\C9\22\C4\40\C9\ED\5B\7A\45\C9\ED\53\00\00\C9\FD\21\00\40\3E\1E\ED\47\C9\3E\06\0E\FC\0D\20\FD\3D\20\F8\C9\11\10\27\CD\4E\41\11\E8\03\CD\4E\41\11\64\00\CD\4E\41\11\0A\00\CD\4E\41\3A\8A\40\C3\6B\41\3E\00\32\8C\40\B7\2A\8A\40\ED\52\22\8A\40\38\06\21\8C\40\34\18\F0\19\22\8A\40\3A\8C\40\C6\1C\2A\8E\40\77\23\22\8E\40\C9\3E\16\2A\0C\40\23\32\B4\40\06\20\3E\80\77\23\10\FC\23\3A\B4\40\3D\20\EE\C9\21\08\00\22\96\40\2A\0C\40\11\BC\02\19\22\C0\40\3E\AE\77\3E\15\32\C3\40\3E\06\32\C2\40\C9\21\96\40\3E\00\BE\20\01\C9\CD\1E\42\CD\91\43\21\87\40\3E\7E\BE\20\07\CD\48\42\00\00\00\00\21\86\40\3E\AF\BE\20\1B\21\C2\40\3E\01\BE\28\0F\35\3E\80\2A\C0\40\77\2B\22\C0\40\CD\0D\42\00\CD\85\48\C9\3E\7B\BE\20\F7\21\C2\40\3E\1E\BE\28\EF\34\3E\80\2A\C0\40\77\23\22\C0\40\CD\0D\42\CD\85\48\C9\3E\80\BE\20\00\3E\AE\77\C9\77\CD\BE\44\CD\1E\42\C9\CD\DE\48\00\00\00\20\01\C9\21\96\40\35\28\0F\2A\C0\40\3E\2E\77\3E\40\CD\27\41\3E\AE\77\C9\2A\C0\40\3E\89\77\3E\80\CD\27\41\C9\06\02\21\AA\40\22\0F\41\22\0B\41\23\3E\00\BE\28\06\23\23\23\10\EF\C9\21\B3\40\3E\00\BE\28\01\C9\3E\08\77\2A\C0\40\B7\11\21\00\ED\52\CD\0E\41\3E\95\77\2A\0F\41\23\23\22\0F\41\3A\C2\40\6F\3A\C3\40\3D\67\CD\0E\41\C9\06\02\21\AA\40\22\0F\41\22\0B\41\23\3E\00\BE\20\06\23\23\23\10\EF\C9\CD\0A\41\3E\95\BE\3E\80\77\20\27\2A\0F\41\23\23\23\3E\01\BE\28\1C\35\CD\0A\41\11\21\00\B7\ED\52\3E\80\BE\20\0C\CD\0E\41\3E\95\77\2A\0F\41\23\18\C9\77\2A\0F\41\23\3E\00\77\18\BF\06\03\21\C4\40\22\0F\41\22\0B\41\23\3E\00\BE\20\0B\2A\0B\41\23\23\23\23\23\10\EA\C9\CD\0A\41\3E\8D\BE\3E\80\77\28\08\21\00\00\CD\0E\41\18\E2\11\21\00\19\CD\0E\41\2A\0F\41\23\23\23\3E\15\BE\28\E6\34\CD\0A\41\3E\80\BE\28\03\77\18\DA\3E\8D\77\18\BF\2A\0C\40\11\01\00\19\22\8E\40\2A\82\40\22\8A\40\CD\30\41\2A\0C\40\11\0F\00\19\22\8E\40\2A\84\40\22\8A\40\CD\30\41\2A\0C\40\11\1C\00\19\22\8E\40\2A\96\40\22\8A\40\CD\30\41\C9\00\00\00\CD\8F\42\CD\25\41\C9\06\86\21\84\40\3E\00\77\23\10\FC\3E\02\32\96\40\CD\76\41\CD\2B\44\CD\8F\41\C9\21\FF\FF\22\86\40\CD\BB\02\22\8A\40\B7\11\F7\DF\ED\52\20\05\3E\AF\CD\F5\43\2A\8A\40\B7\11\E7\DD\ED\52\20\08\3E\AF\CD\F5\43\CD\FA\43\2A\8A\40\B7\11\EF\F7\ED\52\20\05\3E\7B\CD\F5\43\2A\8A\40\B7\11\EF\F5\ED\52\20\08\3E\7B\CD\F5\43\CD\FA\43\2A\8A\40\B7\11\EF\FD\ED\52\20\03\CD\FA\43\C9\00\00\00\00\00\00\21\86\40\77\C9\3E\7E\21\87\40\77\C9\51\00\0F\02\04\05\8E\00\0A\04\04\04\98\00\14\04\04\04\CB\00\05\06\04\03\D5\00\0F\06\04\05\DF\00\19\06\04\03\38\01\0F\09\04\05\01\2A\00\21\01\44\11\D4\40\ED\B0\06\07\21\D4\40\22\0B\41\22\0F\41\ED\5B\0C\40\CD\0A\41\19\CD\0E\41\2A\0B\41\23\23\23\23\23\23\10\E4\CD\76\44\3E\80\CD\27\41\C9\21\D5\40\06\07\3E\00\BE\20\0B\23\23\23\23\23\23\10\F5\CD\2B\44\C9\06\07\21\D4\40\22\0B\41\CD\8D\44\2A\0B\41\23\23\23\23\23\23\10\EF\C9\2A\0B\41\23\3E\00\BE\20\01\C9\CD\0A\41\3E\0B\23\77\21\FE\40\3E\00\BE\20\0C\CD\0A\41\3E\86\77\23\23\3E\06\77\C9\CD\0A\41\3E\06\77\23\23\3E\86\77\C9\21\D4\40\06\07\22\0B\41\23\3E\00\BE\28\10\CD\0A\41\3E\80\BE\28\14\23\BE\28\10\23\BE\28\0C\2A\0B\41\23\23\23\23\23\23\10\DC\C9\C3\72\48\11\01\00\19\22\84\40\CD\0A\41\3E\80\77\23\77\23\77\2A\0B\41\23\3E\00\77\C9\CD\BE\44\CD\60\44\3A\FE\40\EE\01\32\FE\40\06\07\21\D4\40\22\0B\41\22\0F\41\23\3E\00\BE\28\03\CD\31\45\2A\0B\41\23\23\23\23\23\23\10\E6\2A\0B\41\23\23\23\23\23\35\20\06\3E\05\77\CD\49\45\CD\8A\45\CD\8D\44\C9\3A\34\40\E6\07\2A\0B\41\23\23\23\23\77\2B\7E\D6\07\30\0D\23\7E\E6\03\C6\00\20\02\C6\01\C6\02\77\C9\DF\FF\00\FF\DE\FF\FF\FF\FF\FF\FF\00\20\00\FF\01\21\00\00\01\22\00\01\01\01\00\01\00\E0\FF\01\FF\21\FF\40\70\01\04\00\2A\0B\41\11\00\41\ED\B0\2A\0B\41\23\23\23\23\46\04\21\6A\45\18\04\23\23\23\23\10\FA\3A\02\41\23\23\86\32\02\41\23\3A\03\41\86\32\03\41\2B\2B\2B\22\14\41\CD\12\41\2A\00\41\19\22\00\41\3A\02\41\C6\00\28\1C\D6\1F\30\18\3A\03\41\D6\02\38\11\D6\14\30\0D\2A\00\41\3E\80\BE\28\18\3E\AE\BE\28\2E\2A\0B\41\23\23\23\23\23\3E\01\77\21\FF\40\46\C9\00\00\00\23\BE\28\07\3E\AE\BE\28\12\18\E2\23\BE\28\07\3E\AE\BE\28\07\18\D7\CD\24\46\18\DD\CD\3B\46\18\F9\CD\0A\41\3E\80\77\23\77\23\77\ED\5B\0B\41\21\00\41\01\04\00\ED\B0\C9\CD\24\46\2A\00\41\3E\08\77\23\77\23\77\CD\1E\42\21\01\41\3E\00\77\CD\24\46\C9\06\02\21\C4\40\22\0F\41\22\0B\41\23\3E\00\BE\28\07\23\23\23\23\10\EE\C9\06\07\21\D4\40\22\0B\41\23\23\3A\C2\40\BE\28\0C\2A\0B\41\23\23\23\23\23\23\10\EA\C9\23\3E\15\96\CA\7D\46\D6\01\32\07\41\CA\B9\46\21\FF\40\70\21\07\41\46\11\21\00\CD\0A\41\23\19\3E\80\BE\20\05\10\F8\C3\B9\46\21\FF\40\46\C3\7D\46\CD\0A\41\11\22\00\19\22\04\41\3E\8D\77\3A\C2\40\32\06\41\2A\0B\41\23\23\23\7E\C6\01\32\07\41\ED\5B\0F\41\01\04\00\21\04\41\ED\B0\C9\CD\BB\02\00\00\00\2A\0C\40\11\10\00\19\22\8E\40\21\86\40\22\88\40\CD\30\41\C3\1C\41\CD\77\43\CD\33\43\21\B2\40\3E\04\77\CD\AD\41\CD\25\41\CD\8F\42\21\B3\40\3E\00\BE\28\01\35\CD\E1\42\CD\55\46\CD\25\41\CD\46\43\21\96\40\3E\00\BE\CA\4D\47\3E\08\BE\DA\4D\47\21\B2\40\35\C2\0D\47\CD\04\45\21\96\40\3E\00\BE\C2\07\47\2A\84\40\ED\5B\82\40\B7\ED\52\38\06\2A\84\40\22\82\40\CD\33\43\C3\1C\41\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C\1C 15 REM \2A\84\40\3A\28\41\3D\C8\3D\C8\32\28\41\C3\EB\44\35\35\35\CD\8F\42\2A\C0\40\2B\1E\89\7E\73\FE\80\28\08\BB\28\05\FE\AE\C4\C0\48\23\23\7E\73\FE\80\20\08\BB\20\05\FE\AE\C4\C0\48\23\7E\BB\20\02\36\80\2B\2B\2B\2B\7E\BB\C0\36\80\C9\35\35\35\E5\C4\1E\42\E1\C9\35\35\35\35\35\35\35\35\35\35\35\35 16 REM OOOOOOE""RNDY%I%Y""FY\;;%Y""77%YTAN OOOOOOOOOOOOOOOOOOOOOO 20 SLOW 30 LET X=USR 18177 35 POKE 16680,252 40 FOR X=1 TO 300 50 NEXT X 62 FOR X=1 TO 21 63 PRINT AT X,0;" " 64 NEXT X 65 GOTO 72 69 SAVE "GA%L" 70 PRINT TAB 6;"% %G%A%L%A%X%Y% %I%N%V%A%D%E%R%S% " 72 PRINT AT 2,0;"KEY FUNCTION",,"\''\''\'' \''\''\''\''\''\''\''\''" 74 PRINT " 5 LEFT",," 8 RIGHT",," 0 FIRE LASER" 76 PRINT ,,"THE 7 ALIEN CRAFT CAN FIRE AT YOUR LASER BASE OR CRASH INTO IT.THE BASE CAN WITHSTAND 7 HITSBEFORE IT IS DESTROYED." 78 PRINT ,,"THE 3 NUMBERS ON THE TOP LINE SHOW:" 80 PRINT ,,"% %M%A%X% %S%C%O%R%E% % %S%C%O%R%E% % %L%I%V%E%S% " 82 PRINT AT 20,0;"INITIAL SPEED? (1 TO 100. THE SPEED INCREASES DURING THE GAME)" 84 LET X=0 85 INPUT X$ 86 LET B=LEN X$ 87 FOR V=1 TO B 88 IF CODE X$(V)<28 OR CODE X$(V)>37 OR B>3 THEN GOTO 84 89 LET X=X+10**(V-1)*(CODE X$(B+1-V)-28) 90 NEXT V 91 IF X>=101 OR X=0 THEN GOTO 84 93 POKE 16680,INT (255-2*X) 94 GOTO 1 ```