Full name for this game is Space Invaders. It is related to OLYMP.NSG. In both cases player has to peck on a keyboard with highest possible frequency.


Start from the upper left corner and move towards bottom right corner invading as much space as you can in the allocated time you have.

Code and comments

Download the INVADOR.NSG code or its internationalized version.

The real trick here is not in the game itself (which only occupies one line), but in the way it stores top score.

Whenever top score is changed the code of a program is modified the way that assignment R$="???" now has different value. It assumes that its BASIC code is located at &h8000. It looks at pair of bytes at &h8001 and &h8002 to determine the address of second line (that is line 1). Then it adds an offset (F=165, determined empirically). Why not use the hardcoded address? The problem is in line 0. If you save program with ,a flag (save "file.bas",a), then saubsequent load will add extra space before comment symbol in line 0, so the address of code containing string initialization may change depending on whether user saved the program with ,a flag or not. This minor MSX BASIC bug intefered with established by this time convention of putting (C) comment in line 0 and had to be dealt with.

True MSX BASIC connoisseur would have known that whenever string variable is assigned literal value in program code, then interpreter instead of allocating space in string variable area points variable descriptor (address to which is returned by VARPTR() function) right into program code area. Using POKE on that address will update program code. Alas, I was no connoisseur, otherwise I would have written it differently.

Try this program to see what I mean.

10  'zzz
20 Z$="????????"
30 INPUT "New value for Z";Z1$
40 Z1$=LEFT$(Z1$+STRING$(LEN(Z$),"?"),LEN(Z$))
50 PRINT"New value is ";Z1$
60 A1=VARPTR(Z$) ' address of variable descriptor
70 A2=PEEK(A1+1)+256*PEEK(A1+2) ' bytes 2 and 3 of the descriptor point to variable contents
80 FOR I=1 TO LEN(Z$)
90 POKE A2-1+I,ASC(MID$(Z1$,I,1))
100 NEXT
110 LIST 20
When variable is assingnend non-literal value, such as result of concatenation of 2 other strings, then interpreter allocates space in string variable area and repoints descriptor to that space. Change line 20 to
20 Z$="????????"+""
and program starts working differently. It still changes value of Z$, just not in the program code.

I learned all this years later when I was writing TRITRIS.NSG and could not force string variables at the addresses I expected them to go until I added ...+"" to the definitions.

[ MSX BASIC | << Previous | Next >> | Feedback ]