Getting Along Without TAB --
An Atari Translation

Fred Pinho

The lack of a TAB command in Atari Basic is a source of irritation to many Atari users. The most common problem occurs when outputting formatted text; cumbersome programming is necessary to accomplish what is relatively simple in other Basic dialects.

It can also be a problem in other areas such as games where a given character must be printed at varying locations on a line. To illustrate this, the car race program shown in Listing 1 was translated into Atari Basic. This program originally appeared in the November 1980 Creative Computing as a translation from DEC PDP/11 to PET Basic. The game depends on the printing of the walls of the road and of the car under control of the TAB command.

The Atari does have a keyboard-controlled tab function which can he used in the programming mode by printing it in properly configured strings. However, running the game in that manner would be difficult. Fortunately there is another way.

The Atari does not print at the keyboard-set tabs unless specifically requested to do so by an imbedded tab request within the string to be printed. Rather it prints at standard "print positions" positions 0, 11, 21, 31 on a 38-character line).

Separating the desired strings by a comma causes each string to be printed starting at a standard position. The width between each print position is controlled by memory location 201. Don't be fooled by its name in the Atari reference manual. Although it is called the "Print Tab Width," it really controls the width of the print positions (sneaky).

The Atari translation is shown in Listing 2. The parameters to be used in controlling the width of the print positions are in line 40: B1 (left side of the road), B2 (right side of the road) and T (the car). The actual printing is controlled by lines 150-153. Here location 201 is POKEd with the width for the left side of the road. Then printing a blank followed by a comma spaces the invisible cursor to the second print position (controlled by B1). D$, which forms the sides of the road, is then printed.

Since the cursor has now moved down to the start of the next line, location 84 (current cursor row) is decremented by 1 to cause a return to the original line. The procedure is now repeated with the width set for the car (line 152). Here a graphics heart is used for the car. It doesn't show on the listing so type control-comma between the second pair of quotes in line 152. The procedure is repeated once more for the right side of the road.

The keys N, M and space were used to move the car. Rather than "opening" the keyboard and using a GET command, memory location 764 (last keyboard key pressed) was used. If you PEEK this location, you'll find an entirely different character set code is used instead of the one detailed in the Atari manual. This code is read and converted for use in lines 120-129. Finally, line 140 checks whether the car has collided with the side of the road. If so, it branches to the end-of-race routine.

Once I had the program working properly, like most programmers, I could not resist the urge to improve and upgrade it. What better way than to make use of the built-in sound and color capabilities of the Atari. The sound of a race car was easy (line 154) since a distortion level of 2 in the SOUND statement gives a very realistic sound.

For the inevitable crash (Mario Andretti I'm not), I turned to the January 1981 issue of Creative Computing for a "percussive sound generator." Modifying the explosion routine slightly worked well (lines 403-408).

For the visual portion of the explosion, a simple rapid rotation of the screen colors was effective (lines 401-402). Note that the SETCOLOR had to be reset in line 402 to return the screen to the original color.

Finally I added a crude scoring system (lines 410-414) and a method of playing repetitively under player control. In line 420, location 764 had to be POKEd with 255 otherwise the last direction key pressed, prior to a crash, would be printed after line 60 was executed.

If you get too good for the program, reduce B2 in line 40. Happy racing!

Listing 1.

40 B1=20
50 B2=B+10
60 T=24
80 REM
90 GET C$
100 IF C$=" " THEN S=S+1:IF S<2 THEN 90
101 S=0
120 IF C$=<>"1" AND C$<>"2" THEN 140
130 ON VAL(C$) GOSUB 220,230
140 IF (B1=T) OR (B2=T) THEN 400
150 PRINT TAB(B1);D$;TAB(T);"+";TAB(B2);D$
160 A=INT(RND(1)*5)+1
170 ON A GOSUB 200,210,210,210,200
180 ON B GOSUB 250,240
190 M=M+1:GOTO 80
200 B=1:RETURN
210 B=2:RETURN
220 T=T-1:RETURN
230 T=T+1:RETURN
240 GOSUB 350:RETURN
250 Y=INT(RND(1)*3)+1
260 IF X=Y THEN 250
270 X=Y
280 IF X=1 THEN D$="/"
290 IF X=2 THEN D$="I"
300 IF X=3 THEN D$="\"
310 GOSUB 350
320 RETURN
350 B1=B1+X-2
360 IF B1<1 THEN B1=1
370 B2=B1+10
380 IF B2>39 THEN B1=29:GOTO 370
390 RETURN
400 PRINT TAB(T);"* CRASH!!!"
410 PRINT "YOU SCORED ";M;" POINTS."
420 M=0
430 FOR I=1 TO 500:NEXT I
460 GOTO 40

Listing 2.

1 REM ATARI TRANSLATION BY FRED PINHO
2 REM FROM PET TRANSLATION BY D. LUDAR AND R. FORSEN
3 ? " "
5 DIM D$(1),A$(3)
10 POKE 752,1
20 S=0:M=0
40 B1=20:B2=B1+7:T=24
45 ? " INDIANAPOLIS SPEED TRIALS"
50 ? " SPEED DEMONS WANTED"
60 ? " ARE YOU WILLING TO GIVE IT A TRY";:INPUT A$
70 IF A$<>"Y" AND A$<>"YES" THEN END
80 ? :? :? "PRESS N TO GO LEFT,M TO GO RIGHT,"
81 ? "AND SPACE TO GO STRAIGHT":FOR P=1 TO 2000:NEXT P
85 ? " "
90 IF PEEK(764)=255 THEN S=S+1:IF S<2 THEN 90
100 S=0
120 IF PEEK(764)<>33 AND PEEK(764)<>35 AND PEEK(764)<>37 THEN 140
129 I=PEEK(764)-32
130 ON I GOSUB 235,235,220,220,230
140 IF B1>=T OR B2<=T THEN 400
150 POKE 201,B2:? " ",D$
152 J=PEEK(84):POKE 84,J-1:POKE 201,T:? " ","`"
153 J=PEEK(84):POKE 84,J-1:POKE 201,B1:? " ",D$
154 SOUND 0,70,2,7
160 A=INT(5*RND(1))+1
170 GOSUB 250
190 M=M+1:GOTO 90
220 T=T-1:RETURN
230 T=T+1:RETURN
235 T=T:RETURN
250 X=INT(3*RND(1))+1
280 IF X=1 THEN D$="/"
290 IF X=2 THEN D$="|"
300 IF X=3 THEN D$="\"
350 B1=B1+X-2
360 IF B1<1 THEN B1=1
361 IF B1>26 THEN B1=26
370 B2=B1+7
390 RETURN
400 POKE 201,T:? "","*":? "CRASH!!!":SOUND 0,0,0,0
401 FOR K=1 TO 10:FOR I=1 TO 10:SETCOLOR 2,I,14:NEXT I:NEXT K
402 SETCOLOR 2,9,4
403 NTE=200:GOSUB 405:SOUND 1,0,0,0:SOUND 2,0,0,0
404 GOTO 410
405 SOUND 2,75,8,15:ICR=0.79+7/100:V1=15:V2=15:V3=15
406 SOUND 0,NTE,8,V1:SOUND 1,NTE+20,8,V2:SOUND 2,NTE+50,4,V3
407 V1=V1*ICR:V2=V2*(ICR+0.05):V3=V3*(ICR+0.08):IF V3>1 THEN 406
408 SOUND 0,0,0,0:RETURN
410 ? "YOU SCORED ";M;" POINTS."
411 IF M<=20 THEN ? "TRY AGAIN WITH A SLOWER CAR"
412 IF M>20 AND M<50 THEN ? "YOU'RE GETTING BETTER. KEEP PRACTICING!"
413 IF M>=50 AND M<80 THEN ? "YOU'RE A HOT ROD!"
414 IF M>=80 THEN ? "WOW!!! LET'S GO TO THE DRAG STRIP!!"
420 FOR I=1 TO 700:NEXT I:POKE 764,255
430 ? "}":GOTO 20

Fred Pinho, 676 Rollingwood Way, Valley Cottage, NY 10989.

Table of Contents
Previous Section: Atari Languages
Next Section: Telecommunications & Memory Locations