# Retro-computing: old school programming

In my last post, I spoke about the TRS-80 Model 100 Portable Computer and how I wrote up a crude little game that sort of resembles Space Invaders. Well, if you take away all of the invaders except for one of them, neuter their ability to return fire and take away the sound, that is. Anyway, I thought I would post the code from an enhanced version of that one hour exercise. I found an emulator that let me take screen shots and test the code before hand keying it on the real thing.  The code is posted twice: once as you would actually enter it into the Model 100 and once formatted and commented.

Type it into the Model EXACTLY as you see here (you do not need to enter blank lines between each line of code):

10 CLS

20 LINE(0,38)-(66,48),1,B

100 SC=0:BP=20

105 PRINT @201,”Score: 0″;

110 H=669:L=75:X=0

115 B\$=CHR\$(230)+CHR\$(239)+CHR\$(229):B=(40*7)+19

116 C\$=CHR\$(144):C1\$=CHR\$(145):L\$=CHR\$(152)

117 ALIEN\$=C\$:D=LEN(ALIEN\$)

120 PRINT @X, ALIEN\$;

121 PRINT @B, B\$;

122 IF X/2 = INT(X/2) THEN ALIEN\$=C1\$ ELSE ALIEN\$=C\$

130 PRINT @X, ” “;

140 X=X+D

200 K\$=INKEY\$

210 IF K\$=”q” THEN END

215 IF K\$=”,” THEN BP=BP-1:BM=-1

216 IF K\$=”.” THEN BP=BP+1:BM=-1

217 IF BP<13 THEN BP=13 ELSE IF BP>27 THEN BP=27

220 IF K\$=” ” THEN F=6:SHOOT=1

221 IF BM=-1 THEN PRINT @B,”   “;:B=(40*7)+BP:PRINT @B,B\$;

230 IF SHOOT=1 THEN PRINT @(40*F)+BP+1, L\$;

231 F1=F

232 IF SHOOT=1 THEN F=F-1:IF F=0 THEN SHOOT=2

233 MP=(F*40)+BP+1

234 IF SHOOT=2 AND X=MP THEN FOR Z=1 TO 4: PRINT @X,”*”;: FOR YY=1 TO

100:NEXT YY:PRINT @X,”+”;: FOR YY=1 TO 100:NEXT YY:NEXT Z:PRINT @X,” “;

235 IF SHOOT=2 AND X=MP THEN PRINT @140,”HIT!”;:SOUND H,L:FOR DL=1 TO

300:NEXT:PRINT @140,”     “;

238 IF SHOOT=2 AND X=MP THEN SC=SC+10:X=0:D=LEN(ALIEN\$): PRINT

@201,”Score:”+STR\$(SC);
239 IF SHOOT=2 THEN F=6

240 IF SHOOT=-1 THEN PRINT @(F1*40)+BP+1, ” “;

245 IF SHOOT<>-1 THEN PRINT @(F1*40)+BP+1,” “;

390 IF X<40-LEN(ALIEN\$) THEN D=+D ELSE D=-D

395 IF X<0 THEN X=1: D=LEN(ALIEN\$)

400 GOTO 120

And here is the formatted, commented code:

10 CLS                ‘Clear the screen
20 LINE(0,38)-(66,48),1,B    ‘Draw the score box
100 SC=0:BP=20            ‘Set score and base position
105 PRINT @201,”Score: 0″;    ‘Write our score label
110 H=669:
L=75:
X=0            ‘Set the pitch and length for our sound
and set the initial alien position to zero
115 B\$=CHR\$(230)+CHR\$(239)+CHR\$(229):
B=(40*7)+19        ‘Create the base and set the position
116 C\$=CHR\$(144):
C1\$=CHR\$(145):
L\$=CHR\$(152)        ‘Create the alien and missile character
117 ALIEN\$=C\$:
D=LEN(ALIEN\$)        ‘D holds the direction for the alien
120 PRINT @X, ALIEN\$;        ‘Draw the alien
121 PRINT @B, B\$;        ‘Draw the missile
122 IF X/2 = INT(X/2) THEN
ALIEN\$=C1\$
ELSE
ALIEN\$=C\$    ‘Animate the alien
130 PRINT @X, ” “;        ‘Erase alien from previous position
140 X=X+D            ‘Calculate the new position for the alien
200 K\$=INKEY\$            ‘poll the keyboard
210 IF K\$=”q” THEN END    ‘Q will quit
215 IF K\$=”,” THEN
BP=BP-1:
BM=-1            ‘comma (<) moves base left
216 IF K\$=”.” THEN
BP=BP+1:
BM=-1            ‘period  (>) moves base right
217 IF BP<13 THEN
BP=13
ELSE
IF BP>27 THEN
BP=27    ‘determine the boundary for the base
220 IF K\$=” ” THEN
F=6:
SHOOT=1        ‘space bar fires your missile
221 IF BM=-1 THEN
PRINT @B,”   “;:B=(40*7)+BP:
PRINT @B,B\$;        ‘Move the base
230 IF SHOOT=1 THEN
PRINT @(40*F)+BP+1, L\$; ‘Show Missile
231 F1=F            ‘Remember the missile’s previous position
232 IF SHOOT=1 THEN
F=F-1:
IF F=0 THEN
SHOOT=2    ‘Row calculation
233 MP=(F*40)+BP+1        ‘Calculate the new missile position
234 IF SHOOT=2 AND X=MP THEN
FOR Z=1 TO 4:
PRINT @X,”*”;:
FOR YY=1 TO  100:
NEXT YY:
PRINT @X,”+”;:
FOR YY=1 TO 100:
NEXT YY:
NEXT Z:
PRINT @X,” “;        ‘If the alien was hit, show an explosion
235 IF SHOOT=2 AND X=MP THEN
PRINT @140,”HIT!”;:
SOUND H,L:
FOR DL=1 TO  300:
NEXT:
PRINT @140,”     “;    ‘If alien was hit, show ‘hit!’ on screen and play sound
238 IF SHOOT=2 AND X=MP THEN
SC=SC+10:
X=0:
D=LEN(ALIEN\$):
PRINT  @201,”Score:”+STR\$(SC); ‘If alien was hit, update score and reset alien position and direction
239 IF SHOOT=2 THEN
F=6            ‘Reset the missile row after destruction of alien
240 IF SHOOT=-1 THEN
PRINT @(F1*40)+BP+1, ” “;     ‘Erase the Missile
245 IF SHOOT<>-1 THEN
PRINT @(F1*40)+BP+1,” “;    ‘Erase the Missile (added to fix a bug)
390 IF X<40-LEN(ALIEN\$) THEN
D=+D
ELSE
D=-D        ‘ Update the alien direction
395 IF X<0 THEN
X=1:
D=LEN(ALIEN\$)
400 GOTO 120            ‘Loop back for more

Yeah, the code is crap, but it was fun to go back in time and mess around with such an ancient language on an ancient computer (that still works and works well.)

## The Game Objective: Shoot the alien until you are bored of doing so.

Controls:

 , {comma} Move base to the left . {period} Move base to the right {space bar} Fire missile