Alphabet Train
- Type
- Education
- Category
- Spelling game for young children
- Author
- Stan Ockers
- Published in
- Atari Computer Enthusiasts (ACE, Eugene, Oregon) program, 1983; reprinted in Atari User (UK), issue 1
- Year
- 1983
- Language
- Atari BASIC
- Requirements
- Atari 400/800/XL/XE, 16K RAM or more, Atari BASIC, joystick (or keyboard)
About the program
Stan Ockers was one of the most prolific authors in the Atari Computer Enthusiasts (ACE) user group of Eugene, Oregon. His public-domain BASIC games went round the world on club disks. Alphabet Train is one of his learning games for small children. A word appears in the middle of the screen. Below it, a goods train runs along a track with one letter on each wagon. The child drives the train back and forth until the right letter sits under a crane hook, then presses the button. The hook comes down, lifts the letter and swings it across to a truck at the top of the screen. If the letter is wrong, the crane drops it back on the train. When the whole word has been spelled, the truck drives away to a little tune and a new word appears.
As well as circulating on ACE disks, it was handed round on the BELLCOM public-domain library disks and was printed in the first issue of the UK magazine Atari User. The word list gives the British reprint away: TYRE, WICKET, BAIL, PITCH and JUMPER, plus "INITIALISING" on the title screen.
What you need
- Any 8-bit Atari with at least 16K and Atari BASIC (on an XL/XE, boot with BASIC enabled).
- A joystick in port 1. The
+and*keys (the arrow keys, pressed without CTRL) also work, because the program reads their raw key codes. SPACE does the same job as the fire button.
Typing it in
The listing is plain ASCII. The only inverse-video text is in the REM on line 142, and it doesn't affect the program. You can type it as normal text or leave the REMs out altogether. Two quirks in the listing are worth knowing about:
- Line 242 was published as
...96,96,0.160,160..., a typo for0,160. The listing here has the corrected 24 values (see Changes from the published listing). - Line 272 ends with a trailing comma. Leave it there: the loop reads exactly 28 values.
SAVE the program before you RUN it. It changes the variable table on the fly (see below), and a typo in lines 350–430 can lock the machine. The listing here runs on genuine Atari BASIC and on the Altirra BASIC replacement used by many emulators (see Changes from the published listing).
How to play
Push the joystick left or right (or press +/*) to slide the train. When the letter you want sits under the hook, press fire or SPACE. Spell the word from left to right. There are 100 words, grouped into themes: animals, the body, vehicles, cricket, food, weather, plants, numbers and clothes.
How it works
The program is a fine example of Ockers' favourite trick. Lines 350–430 find the variable value table through locations 134/135 and rewrite the address and length fields of two string variables. After that, A$ points straight at player/missile memory and SCR$ points straight at screen RAM. Moving the hook (player 0) or the letter (player 1) up and down is then a single string assignment such as A$(Y,Y+11)=B$. Scrolling the train is a slice copy such as SCR$(181,200)=TRN1$(X,X+19). Both run at machine speed inside BASIC's string routines.
Lines 910–1000 use a 23-byte machine-language block-move routine (in MV$) to copy the ROM character set into RAM, so that the program can define its own wheel and wagon shapes. Line 640 reads letter shapes straight out of the ROM font at 57344 to build the sprite for the letter that is being carried.
Variations to try
- Swap in your own word lists in lines 1020–1047. Keep it to 100 words, or change the
RND(0)*100in line 1010 to match. - Change the tune data in lines 2032–2034. The values are pitch/duration pairs, and a pitch of 0 gives a rest.
Changes from the published listing
Two changes. The first fixes a typo: in line 242 the published 0.160 (a decimal point) should be 0,160, so the DATA line holds the 24 values the loop in line 240 reads; as printed it borrowed one value from the next line and the car graphic came out one byte off. The second lets the program also run under Altirra BASIC, the free replacement BASIC built into many emulators. Altirra BASIC adds a command called DIR, so it rejected the published lines that use that word as the start of a variable name. The variable is renamed everywhere in the program. The new name is the same length, so the memory layout is unchanged and the program behaves exactly as published on genuine Atari BASIC. If you type it in from the magazine, the original names work fine on a real Atari.
| Published | Now | Lines |
|---|---|---|
DIR |
DRN |
500, 510, 540, 550 |
0.160 (line 242) |
0,160 |
242 |
Listing
100 REM *****************************
110 REM * ALPHABET TRAIN *
120 REM * Atari Computer Enthusiasts*
130 REM * by Stan Ockers *
140 REM *****************************
141 REM
142 REM **** {inverse} DEFINE STRINGS {/inverse} ****
144 OPEN #1,4,0,"K:"
148 GRAPHICS 18:POSITION 4,4:PRINT #6;"AlPhAbEt tRaIn":POSITION 4,5:? #6;"--------------"
149 POSITION 5,8:? #6;"INITIALISING"
159 DIM A$(1),SCR$(1),B$(12),TRN1$(180),TRN2$(180),TRN3$(180),TRK1$(28),TRK2$(28),TRK3$(28),W$(6)
160 DIM L$(10):L$(10)=CHR$(0):L$(1,1)=CHR$(0):L$(2)=L$:DIM BL$(10):BL$=L$
170 DIM P$(8):RESTORE 180:FOR J=1 TO 8:READ A:P$(J,J)=CHR$(A):NEXT J
180 DATA 1,3,7,255,255,7,3,1
190 DIM R$(8):RESTORE 200:FOR J=1 TO 8:READ A:R$(J,J)=CHR$(A):NEXT J
200 DATA 128,192,224,255,255,224,192,128
210 RESTORE 220:FOR J=1 TO 12:READ A:B$(J,J)=CHR$(A):NEXT J
220 DATA 24,36,66,129,129,129,129,129,129,129,66,0
230 TRN1$(180)=" ":RESTORE 232:FOR J=1 TO 24:READ A:TRN1$(J,J)=CHR$(A):NEXT J:TRN1$(25)=TRN1$
232 DATA 77,84,84,0,84,84,205,212,212,128,212,212,13,20,20,0,20,20,141,148,148,128,148,148
240 TRN2$(180)=" ":RESTORE 242:FOR J=1 TO 24:READ A:TRN2$(J,J)=CHR$(A):NEXT J:TRN2$(25)=TRN2$
242 DATA 0,32,32,32,32,32,0,96,96,96,96,96,0,160,160,160,160,160,0,224,224,224,224,224
250 TRN3$(180)=CHR$(0):TRN3$(1,1)=CHR$(0):TRN3$(2)=TRN3$:FOR J=10 TO 160 STEP 6:TRN3$(J,J)=CHR$(J/6+95):NEXT J
260 RESTORE 262:FOR J=1 TO 28:READ A:TRK1$(J,J)=CHR$(A):NEXT J
262 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,84,84,0,0,0,0,84,84,0,84,0,0
264 RESTORE 266:FOR J=1 TO 28:READ A:TRK2$(J,J)=CHR$(A):NEXT J
266 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,224,224,224,224,224,224,21,32,32,32,32,0
270 RESTORE 272:FOR J=1 TO 28:READ A:TRK3$(J,J)=CHR$(A):NEXT J
272 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,13,22,0,8,
278 REM ** SET ASIDE PM AREA **
280 GRAPHICS 7:POKE 106,PEEK(106)-5:PM=PEEK(106)+1:POKE 54279,PM:GRAPHICS 18:GOSUB 910
290 RESTORE 300:FOR J=704 TO 712:READ A:POKE J,A:NEXT J
300 DATA 32,255,18,82,50,255,34,52,57
310 POSITION 5,1:PRINT #6;CHR$(142);CHR$(142);CHR$(142):POSITION 6,6:PRINT #6;"--------------"
320 POSITION 0,10:FOR I=1 TO 20:PRINT #6;CHR$(171);:NEXT I
330 POKE 559,46:POKE 53277,3
340 REM ** MAP A$ ONTO PM AREA **
350 VVTP=PEEK(134)+PEEK(135)*256:STARP=ADR(A$)
380 OFFS=PM*256+512-STARP:HI=INT(OFFS/256):LO=OFFS-HI*256
390 POKE VVTP+2,LO:POKE VVTP+3,HI:POKE VVTP+5,2:POKE VVTP+6,0:POKE VVTP+7,2
392 REM ** MAP SCR$ ONTO SCREEN AREA **
400 SCR=PEEK(88)+256*PEEK(89):OFFS=SCR-STARP:HI=INT(OFFS/256):LO=OFFS-HI*256
420 POKE VVTP+10,LO:POKE VVTP+11,HI
430 POKE VVTP+12,5:POKE VVTP+13,1:POKE VVTP+14,5:POKE VVTP+15,1
440 Y=60:Z=80:X=50
450 A$(Y,Y+11)=B$:POKE 53248,Z:FOR J=1 TO 59:A$(J,J)=CHR$(24):NEXT J
460 A$(280,287)=P$:XP=64:POKE 53250,XP
470 A$(408,415)=R$:XR=158:POKE 53251,XR
478 REM ** TRUCK COMES IN FROM RIGHT **
480 FOR J=1 TO 15:XT=J:GOSUB 1050:SOUND 0,100,4,XT/2:FOR K=1 TO 20:NEXT K:NEXT J:POKE 77,0:POKE 764,255
485 REM
488 REM ** PRINT WORD **
490 GOSUB 1010:POSITION 10-LEN(W$)/2,11:? #6;W$
491 REM ** LOOP TO MOVE TRAIN **
500 S=STICK(0):K=PEEK(764):IF S=7 OR K=7 AND X>6 THEN X=X-1:DRN=-1:POKE 764,255
510 IF S=11 OR K=6 AND X<156 THEN X=X+1:DRN=1:POKE 764,255
520 IF S<15 THEN 560
530 IF INT(X/6)=X/6 THEN 560
540 IF DRN=-1 THEN X=X-1
550 IF DRN=1 THEN X=X+1
558 REM ** MOVE TRAIN **
560 SCR$(181,200)=TRN1$(X,X+19)
570 SCR$(161,180)=TRN2$(X,X+19)
578 REM ** SOUND IF TRAIN COMING **
580 SCR$(141,160)=TRN3$(X,X+19)
590 IF X=SX THEN SOUND 0,0,0,0
600 IF X<>SX THEN SOUND 0,100,4,6:SX=X
610 IF STRIG(0)=1 AND K<>33 THEN 500
618 REM ** PICK UP LETTER **
620 C=ASC(TRN3$(X+4)):IF C=0 THEN 500
630 FOR J=1 TO 11:Y=Y+1:A$(Y,Y+11)=B$:SOUND 0,(Y+100)*(Y/3=INT(Y/3)),10,6:FOR K=1 TO 20:NEXT K:NEXT J
640 CS=57344+256+8*X/6:FOR J=1 TO 8:L$(J+1,J+1)=CHR$(PEEK(CS+J-1)):NEXT J
650 A$(129+Y,139+Y)=L$:POKE 53249,Z
660 P=4+X:TRN3$(P,P)=CHR$(0):SCR$(141,160)=TRN3$(X,X+19)
670 FOR J=1 TO 50:Y=Y-1:A$(Y,Y+11)=B$:A$(129+Y,139+Y)=L$:SOUND 0,(Y+100)*(Y/3=INT(Y/3)),10,6:FOR K=1 TO 10
680 NEXT K:NEXT J:SOUND 0,0,0,0:FOR J=1 TO 8:XP=XP+1:POKE 53250,XP:NEXT J
688 REM ** IF LETTER NOT CORRECT DROP IT **
690 IF C-32<>ASC(W$(LTR+1)) THEN GOSUB 820
700 FOR J=1 TO 32+8*LTR:Z=Z+1:XP=XP+1:POKE 53250,XP:POKE 53249,Z
710 SOUND 0,Y+100*(XP/3=INT(XP/3)),10,6:NEXT J:LTR=LTR+1
720 FOR J=1 TO 15:Y=Y+1:A$(129+Y,139+Y)=L$:SOUND 0,Y+100,10,6:NEXT J:A$(129+Y,139+Y)=BL$
730 P=16+LTR:TRK3$(P,P)=CHR$(X/6+96):SCR$(67,80)=TRK3$(XT,XT+13):POSITION (Z-48)/8,1:PRINT #6;CHR$(142)
740 FOR J=1 TO 30:SOUND 0,100+100*RND(0),8,(30-J)/3:NEXT J
750 XP=XP-1:POKE 53250,XP:SOUND 0,Y+100*(XP/3=INT(XP/3)),10,6:IF XP>64 THEN 750
760 Z=80:POKE 53249,Z:Y=Y-15
770 FOR J=1 TO 39:Y=Y+1:A$(Y,Y+11)=B$:SOUND 0,Y+100,10,6:NEXT J
780 SOUND 0,0,0,0:IF LTR<LEN(W$) THEN POKE 764,255:GOTO 500
788 REM ** WORD CORRECT - MOVE TRUCK OUT **
790 FOR J=15 TO 1 STEP -1:XT=J:GOSUB 1050:SOUND 0,100,4,XT/2:FOR K=1 TO 20:NEXT K:NEXT J
795 GOSUB 2040
800 POSITION 7,11:PRINT #6;" ":FOR J=10 TO 160 STEP 6:TRN3$(J,J)=CHR$(J/6+95):NEXT J
810 LTR=0:FOR J=17 TO 22:TRK3$(J,J)=CHR$(0):NEXT J:POSITION 8,1:PRINT #6;" ":GOTO 480
818 REM ** ROUTINE FOR PUTTING INCORRECT LETTER BACK **
820 FOR J=1 TO 14:SOUND 0,50+50*(XP/3=INT(XP/3)),10,6
830 Z=Z+1:XP=XP+1:XR=XR-4:POKE 53249,Z:POKE 53250,XP:POKE 53251,XR:NEXT J:SOUND 0,0,0,0
840 FOR J=1 TO 14:Z=Z-1:XP=XP-1:XR=XR-1:POKE 53249,Z:POKE 53250,XP:POKE 53251,XR:NEXT J
850 FOR J=1 TO 8:XP=XP-1:XR=XR+2:POKE 53250,XP:POKE 53251,XR:Y=Y+1:A$(129+Y,139+Y)=L$:A$(Y,Y+11)=B$:NEXT J
860 FOR J=1 TO 27:XR=XR+2:POKE 53251,XR:Y=Y+1:A$(129+Y,139+Y)=L$:A$(Y,Y+11)=B$:SOUND 0,Y+100,10,8:NEXT J
870 FOR J=1 TO 15:SOUND 0,Y+100,10,8:Y=Y+1:A$(Y,Y+11)=B$:A$(129+Y,139+Y)=L$:NEXT J:TRN3$(P,P)=CHR$(C)
880 FOR J=1 TO 30:SOUND 0,100+100*RND(0),8,(30-J)/3:NEXT J
890 SCR$(141,160)=TRN3$(X,X+19):A$(129+Y,139+Y)=BL$:FOR J=1 TO 11:Y=Y-1:A$(Y,Y+11)=B$:NEXT J
900 SOUND 0,0,0,0:POKE 764,255:GOTO 500
908 REM ** MACHINE LEVEL - MOVE CHARACTER SET **
910 POKE 756,PM
920 DIM MV$(23):RESTORE 930:FOR J=1 TO 23:READ A:MV$(J,J)=CHR$(A):NEXT J
930 DATA 104,104,133,204,104,133,203,104,133,206,104,133,205,160,0,177,203,145,205,136,208,249,96
940 CS=57344+512:NCS=PM*256:A=USR(ADR(MV$),CS,NCS)
950 FOR J=NCS TO NCS+7:POKE J,0:NEXT J
960 CS=57344+256:NCS=PM*256+256:A=USR(ADR(MV$),CS,NCS)
970 FOR J=NCS TO NCS+7:POKE J,255:NEXT J
980 NCS=PM*256:RESTORE 990:FOR J=160 TO 167:READ A:POKE NCS+J,A:NEXT J
990 DATA 0,0,60,102,219,219,102,60
1000 POKE 756,PM:RETURN
1008 REM ** PICK A WORD SUBROUTINE **
1010 RESTORE 1020:FOR J=1 TO INT(RND(0)*100)+1:READ W$:NEXT J:RETURN
1020 DATA DOG,CAT,BIRD,HAND,COW,HORSE,PET,FROG,FLY,ARM
1030 DATA HAIR,TOE,FINGER,LEG,FACE,EAR,MOUTH,BAT,WORK,PLAY
1040 DATA WAGON,BIKE,CAR,VAN,TYRE,CHAIN,BRAKE,GEAR,HORN,PEDAL
1041 DATA BAT,WICKET,PITCH,BAIL,NET,CLUB,SCORE,WIN,BOWL,BOUNCE
1042 DATA TEA,MILK,SUGAR,SAUCE,GRAVY,WATER,SPICE,HONEY,FRUIT,CAKE
1043 DATA SUN,RAIN,WIND,CLOUD,SHINE,SNOW,HAIL,ICE,FROST,SHOWER
1044 DATA FLOWER,ROSE,ROCK,THORN,BUSH,STONE,LEAF,PETAL,BRANCH,BARK
1045 DATA RAT,MOUSE,CAMEL,LION,DOG,CAT,HORSE,PIG,TIGER,COW
1046 DATA ONE,TWO,FOUR,FIVE,SIX,EIGHT,TEN,FORTY,ZERO,HALF
1047 DATA HAT,COAT,BELT,SHIRT,VEST,BLOUSE,SHOE,SOCK,JUMPER,TIE
1048 REM ** PRINT TRUCK SUBROUTINE **
1050 SCR$(107,120)=TRK1$(XT,XT+13):SCR$(87,100)=TRK2$(XT,XT+13):SCR$(67,80)=TRK3$(XT,XT+13):RETURN
2030 REM ** TUNE SUBROUTINE **
2032 DATA 91,6,121,1,91,2,121,1,91,2,81,1,72,8,91,8,68,6,68,1,91,4,81,4,72,8,0,4
2034 DATA 91,6,121,1,91,2,121,1,91,2,81,1,72,8,91,4,72,2,72,1,72,4,81,4,81,4,72,4,81,8
2040 RESTORE 2032:FOR J=1 TO 29:READ P,T:IF P=0 THEN FOR K=1 TO 20*T:NEXT K:GOTO 2070
2050 SOUND 0,P,10,8:SOUND 1,2*P,10,6:FOR L=1 TO 12*T
2060 NEXT L:SOUND 0,0,0,0:SOUND 1,0,0,0
2070 NEXT J:RETURN
Credits
- Program listing: Alphabet Train — program listing (Atari Computer Enthusiasts (ACE, Eugene, Oregon) program, 1983; reprinted in Atari User (UK), issue 1) — Stan Ockers
- Gury's Atari 8-bit Forever — Alphabet Train (source code listing) — Stan Ockers
- Atari User (UK) magazine issue 1 at the Internet Archive (cited by Gury) — Gury; Internet Archive
