Dale’s Atari 800 Games › Stan Ockers
By Stan Ockers, in the ACE newsletter of February 1984.
Play Angleworms IIWhen I got my Atari, one of the first games I wrote was called “Angleworms”. It's the classic ‘Blocade’ type game where you try to keep from running into the other guy's worm, your own or walls etc. It was written in Basic and was slow but enjoyable, especially if the two players were of about equal ability. I often wanted to speed up the game but dreaded the thought of all the assembly language and debugging necessary. Then I recently purchased an Action! cartridge by OSS.
Action! is a natural language for arcade style games. The language is compiled and fast! Instead of worrying about whether things run fast enough, I now have to put in delay loops between plotting of each pixel. The highly structured form takes a little getting use to. You have to put a lot more thought into writing the program but the result is actually readable. You can return to the program a month later and follow it without spending an hour to outline the structure.
You can get the flavor of Action! by looking over the source code of Angleworms II. The primary building block is a subroutine-like structure called the procedure or PROC. Any parameters passed to the procedure follow the name in parenthesis. The procedure called when the program is run is the last one, the one I've labeled ‘Main()’. Other PROCs are called by simply naming them (they must have been defined previously).
The structure turns out to be loops within loops. The indentation helps you follow what constitutes a loop. Loops are also marked at the beginning and end by DO and OD (DO backwards). If the loop is to be repeated a definite number of times, the DO is preceded by a FOR ... TO ... STEP statement. You can also get out of the loop with an EXIT statement, usually conditional, (part of an IF ... THEN EXIT). Other loop control statements are the WHILE which appears just before the DO or the UNTIL appearing just before the OD. These cause the loop to repeat WHILE a condition is true or UNTIL a condition becomes true.
Another major construct is the statement beginning with IF and ending with FI (IF backward). Following the IF is an expression, a THEN and maybe an ELSE or even ELSEIF ... THEN. If the expression evaluates as true, all statements following the THEN up until the ELSE are executed. If not, all statements following the ELSE are used. The ELSEIF ... THEN allows more conditional expressions without going to another IF..FI construction. IF's will often be nested and the indentation helps you follow which condition is active at the time.
All variables must be declared and there are three fundamental types, BYTE, CARD and INT. Sorry, no floating point so forget about those trig functions etc., just integers 0-255 (BYTE), 0-65,535 (CARD) and -32768 to 32767 (INT). You have to be careful, especially when subtracting numbers from BYTE or CARD values; they ‘roll over’ instead of going to negative numbers. IF variable < 0 THEN ... has no meaning if variable is CARD because CARD is never negative. Another problem is fractions ... there are none! If you have an expression and part way through it evaluates to a fraction, you will lose it because the fraction will be treated as zero. The operator MOD (which gives the remainder of integer division) helps somewhat.
If variables are to be valid throughout all PROC's they should be defined globally under the heading MODULE, otherwise they can be defined at the beginning of the PROC to which they apply. When defined they can also be initalized by putting an equal sign and the value in brackets. Besides the fundamental types there are the extended types of POINTERS, ARRAYS and RECORDS. I found byte arrays to be most useful. I use them as I used strings in Basic. At the beginning of the program you can see the tune notes and duration of notes defined as byte arrays.
I've not included many comments in the source because it was already getting so long. Programs tend to give long listings because of the indentation and spaces necessary to outline the structure. You could do away with a lot of this but it tends to get unreadable. The editor has a find command which helps you get to any portion of the source quickly. The editor also allows very long line lengths (240 characters) and lets you shift the viewing window over past 40 columns as well as shifting individual lines left when you enter more than 40 columns. I find it difficult to keep track in my mind of what I can't see on the screen and end up with very jagged listings, wasting even more space when printed. So, I've arbitrarily limited myself to 40 columns.
A really great feature of Action! is the fact that it is on cartridge, flipping back and forth between the editor and compiler is instantaneous — no disk accesses. Both the source and compiled object code are resident in memory at the same time and I've found it difficult (but not impossible) to clobber the source. I suppose a program which doesn't use any of the Action! library might run as a binary file. You are not likely to write a program without using at least one library routine which include most input, output, graphcs and sound statements like Basic plus some additional ‘goodies’ like SndRst, Zero, Setblock and Moveblock. This means you need the Action! cartridge to run the programs.
The editor is a screen editor and better than the Basic editor. You can even have a split screen, working in two different windows. I find the cut-and-paste feature especially useful. The compiler is fast, taking only a few seconds to compile most programs. The source of ‘Angleworms II’ takes 99 disk sectors while the object takes 68. One reason for the length of the program are many embelishments I made to the original. I had the rudimentary program working when the source was only 25-30 sectors long. Because of the cartridge, Action! is one of the few higher level languages I might consider using with a cassette based system.
Angleworms can be played by two players or by one against the computer. Using joystick 1 you can choose the number of players, difficulty or final score. Move vertically to select the variable and left or right to change the value. Press fire to start the game. The second player uses joystick #2. You can't run into anything including your own worm (you can't ‘go back’ on yourself). The worms will gradually lengthen as time goes on. You have five shots (fire button) which will blast a path through anything, (use them sparingly). After each collision the score of the player who didn't collide is increased depending on the time elapsed. Pressing SELECT at this time will return you to the choices so you can change the difficulty level or final score in midgame. Pressing OPTION will start a new game.
I've still neglected to mention a lot of the features of Action! I especially like the ability for bit manipulation including left and right shifts as well as the ability to assign memory locations directly to variables. Notice the assignment of consol to location 53279 in the global variables. After this assignment the consol keys can be used directly in a conditional statement like ‘UNTIL consol=5’. Machine language can be inserted also. I've used a display list interrupt sequence to change colors for the bottom part of the screen (see PROC Bkgd()). By the way, I have not implemented the attract mode for this process so don't leave the program unattended for a long time.
In summary, I'm quite pleased with Action! It's perfect for designing arcade style games and the library of routines makes programming them quite straight forward. The structured style takes some getting use to but makes the code more readable. The best thing though is the fast speed! Being on cartridge, everything is immediately available, a real blessing when working with a compiled language.
—Stan Ockers

The listing, “ANGLEWORMS (ACTION!) by Stan Ockers”, is on pages 10, 11, 12, 13 of the issue. Stan wrote it in Action!, the compiled language from Optimized Systems Software, and readers needed the Action! cartridge to type it in and compile it. There is no Action! compiler here, so the game page runs a hand translation of the listing into JavaScript: one function for each of Stan’s procedures, with his variable names, sizes and memory addresses, driving the same emulated Atari 800 (its screen, player-missile graphics, collisions and sound) that runs the BASIC games.
Where this copy came from: Written in Action!. The listing was transcribed by hand from the scan (pages 10-13; there is no typed-in copy), and its tune, title line, sound table and machine-code display list interrupt were checked byte for byte against a compiled copy of the game from the Atari archives. The game page runs a hand translation of the listing into JavaScript. In the write-up, the printer dropped the ‘<’ from “IF variable < 0 THEN”; it is restored here.
; ANGLEWORMS II
; Stan Ockers 12/83
; ACE Newsletter, 3662 Vine Maple
; Eugene, Or 97405 $12 year
; FEB 1984 ACTION! Listing
MODULE ;Some global variables
BYTE ARRAY Xsave0 (200),Xsave1(200),
Ysave0(200),Ysave1 (200),xpos (2),
ypos(2),sndflg(3),pit(3),vol(3),
dur(3),sxpos(2),sypos(2),savestk(2)
BYTE head0,tail0,head1,tail1,stk,
consol=53279,txtrow=656,txtcol=657,
color1=709,color2=710,sflag0=[0],
sflag1=[0],x,y,longcnt,grow,plyrs,
level,shots0,shots1,win,del,tunepos
CARD cnt,speed,score0,score1,goal
INT ARRAY delx (2),dely (2),sdelx(2),
sdely(2)
BYTE ARRAY tunenote=[64 72 81 81 81
128 121 108 108 108 81 72 64 64 64
72 81 72 64 72 72 64 72 81 81 81
128 121 108 108 108 81 72 64 53 53
64 81 72 64 72 81 128 108 128 108
128 121 108 108 121 96 121 96 121
108 96 96 108 81 81 108 108 128
128 144 81 72 64 53 53 64 81 72 64
72 81]
BYTE ARRAY tunedur=[8 8 16 16 16 8 8
16 16 16 8 8 16 16 8 8 8 8 16 16
16 8 8 16 16 16 8 8 16 16 16 8 8
16 16 8 8 8 8 16 16 32 16 16 16 16
8 8 16 32 16 16 16 16 8 8 16 16 16
16 16 16 16 16 16 16 8 8 16 16 8 8
8 8 16 16 16]
PROC Init() ; Worms to starting pos.
FOR cnt=0 TO 199
DO
Xsave0(cnt)=10 Ysave0(cnt)=10
Xsave1(cnt)=10 Ysave1(cnt)=10
OD
FOR cnt=0 TO 4
DO
Xsave0(cnt)=9+cnt Xsave1(cnt)=70-cnt
OD
FOR cnt=0 TO 3
DO
sndflg(cnt)=0 pit(cnt)=0 vol(cnt)=0
OD
xpos(0)=13 ypos(0)=10 delx(0)=1
dely(0)=0 xpos(1)=66 ypos(1)=10
delx(1)=-1 dely(1)=0 savestk(0)=15
savestk(1)=15 speed=2000/level grow=3
longcnt=grow head0=4 head1=4 tail0=0
tail1=0
RETURN
PROC Bkgd() ; Draw walls & rectangles
BYTE x,y,line,height,width
CARD dl
BYTE ARRAY dli=[72 138 72 152 72 169
56 162 32 160 82 141 10 212 141 26
208 142 22 208 140 23 208 104 168
104 170 104 64]
Graphics(5) dl=Peek(560)
dl==+Peek(561)*256 Poke(dl+44,$8A)
Poke(dl+45,70) Poke(dl+48,6)
Poke(dl+49,6) Poke(dl+50,6)
Poke(708,138) Poke(709,202)
Poke(710,70) Poke(712,130)
txtrow=0 txtcol=0
FOR cnt=1 to shots0
DO
Put(42)
OD
IF plyrs=2 THEN txtcol=15
FOR cnt=1 to shots1
DO
Put(170)
OD
FI
txtrow=0 txtcol=6 Print("level ")
PrintB(level)
txtrow=1 txtcol=23 Print("plyr#1")
PokeC(512,dli) Poke(54286,192)
IF plyrs=2 THEN Print(" plyr#2")
ELSE Print(" computer")
FI
txtrow=1 txtcol=4 PrintC(score0)
txtcol=12 PrintC(score1)
color=1 Position(0,0) DrawTo(79,0)
DrawTo(79,39) DrawTo(0,39) DrawTo(0,0)
FOR cnt=1 to Rand(3)+2
DO
x=Rand(80) y=Rand(40)
height=Rand(10)+3 width=Rand(10)+3
IF x+width>79 THEN width=79-x
FI
IF y+height>39 THEN height=39-y
FI
color=1
FOR line=y to y+height
DO
Plot(x,line) DrawTo(x+width,line)
OD
OD
color=0 Plot(1,10) DrawTo(78,10)
FOR cnt=0 TO 4
DO
color=2
Plot(Xsave0(cnt),Ysave0(cnt))
color=3
Plot(Xsave1(cnt),Ysave1(cnt))
OD
RETURN
PROC Note (BYTE chan,pitch,duration)
IF sndflg(chan)=0 THEN
Poke($D200+2*chan,pitch)
pit(chan)=pitch vol(chan)=8
Poke($D201+2*chan,168)
sndflg(chan)=1 dur(chan)=duration
FI
RETURN
PROC Play(BYTE chan) ; Play tune
IF sndflg(chan)=1 THEN
IF dur(chan)>0 THEN dur(chan)==-1
ELSE vol(chan)==-1
Poke($D201+2*chan,160+vol(chan))
IF vol(chan)=0 THEN sndflg(chan)=0
FI
FI
FI
RETURN
PROC Stkupdate(BYTE stknum)
BYTE ARRAY clank
BYTE snd
clank="!%*29DLUfr" snd=clank(Rand(10))
stk=Stick(stknum)
IF stk<>savestk(stknum) THEN
Note(stknum,snd,1)
FI
savestk(stknum)=stk
IF stk=14 THEN
dely(stknum)=-1 delx(stknum)=0
ELSEIF stk=13 THEN
dely(stknum)=1 delx(stknum)=0
ELSEIF stk=7 THEN
dely(stknum)=0 delx(stknum)=1
ELSEIF stk=11 THEN
dely(stknum)=0 delx(stknum)=-1
FI
xpos(stknum)==+delx(stknum)
ypos(stknum)==+dely(stknum)
RETURN
PROC Lookfwd() ;For computers worm
IF Locate (xpos(1)+2*delx(1),
ypos(1)+2*dely(1))<>0 OR
Rand(100)<5 THEN
IF delx(1)<>0 THEN delx(1)=0
IF Rand(2)=0 THEN dely(1)=1
ELSE dely(1)=-1
FI
ELSEIF dely(1)<>0 THEN dely(1)=0
IF Rand(2)=0 THEN delx(1)=1
ELSE delx(1)=-1
FI
FI
IF Locate (xpos(1)+2*delx(1),
ypos(1)+2*dely(1))<>0 THEN
delx(1)=-delx(1)
dely(1)=-dely(1)
FI
FI
xpos(1)==+delx(1) ypos(1)==+dely(1)
RETURN
PROC Addhead0() ; Extend head
head0==+1
IF head0=200 THEN head0=0
FI
Xsave0(head0)=xpos(0)
Ysave0(head0)=ypos(0)
color=2 Plot(xpos(0),ypos(0))
RETURN
PROC Addhead1()
head1==+1
IF head1=200 THEN head1=0
FI
Xsave1(head1)=xpos(1)
Ysave1(head1)=ypos(1)
color=3 Plot(xpos(1),ypos(1))
RETURN
PROC Erasetail0() ; Remove from tail
color=0 Plot(Xsave0(tail0),
Ysave0(tail0))
tail0==+1
IF tail0=200 THEN
tail0=0
FI
RETURN
PROC Erasetail1()
color=0 Plot(Xsave1(tail1),
Ysave1(tail1))
tail1==+1
IF tail1=200 THEN
tail1=0
FI
RETURN
PROC Dly(CARD maxwait)
CARD wait
FOR wait=1 to maxwait
DO
OD
RETURN
PROC Title() ; Opening screen-choices
BYTE wait=[1],choice,ypos
CARD dl
BYTE ARRAY firstline(14)=[13 65 238
103 76 197 247 79 210 109 83 32
105 105]
DO
UNTIL consol<>6
OD
Graphics(17) Poke(712,64) tunepos=0
dl=Peek(560) dl==+Peek(561)*256
Poke(dl+12,7) Poke(dl+8,2)
Poke(dl+18,2)
Position(3,8) PrintD(6,firstline)
Position(4,10)
PrintD(6,"by S. OCKERS")
Position(11,14)
PrintD(6,"Written in ACTION!")
Position(3,23)
PrintD(6,"{inv}fire{/inv}-start game") choice=17
DO
wait==-1
IF wait<=0 THEN wait=15
Position(7,17)
PrintBD(6,plyrs) PrintD(6," players")
Position(7,19) PrintD(6,"level ")
PrintBD(6,level)
Position(7,21) PrintD(6,"goal ")
PrintCD(6,goal)
FOR ypos=17 TO 21 STEP 2
DO
Position(5,ypos) PutD(6,32)
OD
Position(5,choice) PutD(6,138)
stk=Stick(0)
IF stk=14 AND choice>17 THEN
choice==-2
ELSEIF stk=13 AND choice<21 THEN
choice==+2
ELSEIF choice=17 AND (stk=7 OR
stk=11) THEN
IF plyrs=1 THEN plyrs=2
ELSE plyrs=1
FI
ELSEIF stk=7 AND choice=19 AND
level<9 THEN level==+1
ELSEIF stk=11 AND choice=19 AND
level>1 THEN level==-1
ELSEIF stk=7 AND choice=21 AND
goal<9900 THEN goal==+100
ELSEIF stk=11 AND choice=21 AND
goal>1000 THEN goal==-100
FI
FI
Play(0) DLY(350)
IF sndflg(0)=0 THEN
Note(0,tunenote(tunepos),
tunedur(tunepos))
tunepos==+1
IF tunepos=73 THEN tunepos=0
FI
FI
UNTIL Strig(0)=0
OD
SndRst()
RETURN
PROC Flash0() ; Worm hit something
FOR cnt=1 to 10
DO
color1=color1+8
Sound(0,20+5*cnt,12,10) Dly(3000)
color1=color1-8 Sound(0,0,0,0)
Dly(3000)
OD
RETURN
PROC Flash1()
FOR cnt=1 to 10
DO
color2=color2+8
Sound(1,50+5*cnt,12,10) Dly(3000)
color2=color2-8 Sound(1,0,0,0)
Dly(3000)
OD
RETURN
PROC Sinit0() ; Set up shot movement
sflag0=1 sxpos(0)=xpos(0)+delx(0)
sypos(0)=ypos(0)+dely(0)
sdelx(0)=delx(0) sdely(0)=dely(0)
Poke(656,0) Poke(657,shots0-1)
Put(32) shots0==-1
RETURN
PROC Sinit1()
sflag1=1 sxpos(1)=xpos(1)+delx(1)
sypos(1)=ypos(1)+dely(1)
sdelx(1)=delx(1) sdely(1)=dely(1)
Poke(656,0) Poke(657,shots1+14)
Put(32) shots1==-1
RETURN
PROC Smove0() ; Move shot
color=0 Plot(sxpos(0),sypos(0))
Sound(0,60,2,10)
FOR cnt=1 to 2
DO
sxpos(0)==+sdelx(0) sypos(0)==+sdely(0)
color=0 plot(sxpos(0),sypos(0))
IF sxpos(0)<=1 OR sxpos(0)>=78 OR
sypos(0)<=1 OR sypos(0)>=38 THEN
sflag0=0 Sound(0,0,0,0) EXIT
FI
OD
IF sflag0=0 THEN color=0
ELSE color=2
FI
Plot(sxpos(0),sypos(0))
RETURN
PROC Smove1()
color=0 Plot(sxpos(1),sypos(1))
Sound(1,70,2,10)
FOR cnt=1 to 2
DO
sxpos(1)==+sdelx(1) sypos(1)==+sdely(1)
color=0 plot(sxpos(1),sypos(1))
IF sxpos(1)<=1 OR sxpos(1)>=78 OR
sypos(1)<=1 OR sypos(1)>=38 THEN
sflag1=0 Sound(1,0,0,0) EXIT
FI
OD
IF sflag1=0 THEN color=0
ELSE color=3
FI
Plot(sxpos(1),sypos(1))
RETURN
PROC Marque() ; Used in end display
FOR x=1+del TO 16+del STEP 3
DO
Play(0)
Position(x,1) PutD(6,170)
IF x<18 THEN Position(x+1,1)
PutD(6,42)
ELSE Position(1,1) PutD(6,42)
FI
OD
FOR y=2+del TO 20+del STEP 3
DO
Position(18,y) PutD(6,170)
IF y<22 THEN Position(18,y+1)
PutD(6,42)
ELSE Position(18,2) PutD(6,42)
FI
OD
FOR x=3-del TO 18-del STEP 3
DO
Position(x,23) PutD(6,170)
IF x>1 THEN Position(x-1,23)
PutD(6,42)
ELSE Position(18,23) PutD(6,42)
FI
OD
FOR y=4-del TO 22-del STEP 3
DO
Position(1,y) PutD(6,170)
IF y>2 THEN Position(1,y-1) PutD(6,42)
ELSE Position(1,22) PutD(6,42)
FI
OD
RETURN
PROC Gameover() ; Ending screen
Graphics(17) Poke(712,32) tunepos=0
Position(3,5) PrintD(6,"the {inv}winner{/inv} is")
Position(4,7)
IF score0>=goal THEN
PrintD(6," PLAYER #1")
ELSEIF plyrs=2 THEN
PrintD(6," PLAYER #2")
ELSE PrintD(6,"THE COMPUTER")
FI
Position(2,9)
PrintD(6,"{inv}WITH A SCORE OF{/inv}")
Position(4,11)
IF score0>=goal THEN PrintCD(6,score0)
ELSE PrintCD(6,score1)
FI
PrintD(6," VS ")
IF score0>=goal THEN PrintCD(6,score1)
ELSE PrintCD(6,score0)
FI
Position(4,13)
PrintD(6,"{inv}ON{/inv} LEVEL# ") PrintBD(6,level)
Position(3,18) PrintD(6,"press START")
Position(4,19) PrintD(6,"to play again")
color=170 Plot(1,1) DrawTo(18,1)
DrawTo(18,23)
DrawTo(1,23) DrawTo(1,1) color=42
FOR x=1 TO 16 STEP 3
DO
Plot(x,1) Plot(x+2,23)
OD
FOR y=1 TO 22 STEP 3
DO
Plot(1,y) Plot(18,y+1)
OD
del=0 cnt=1
DO ; Flashing lights & music
Marque() del==+1
IF del=3 THEN del=0
FI
IF sndflg(0)=0 THEN
Note(0,tunenote(tunepos),
tunedur(tunepos)) tunepos==+1
IF tunepos=73 THEN tunepos=0
FI
FI
UNTIL Consol=6
OD
RETURN
PROC Main() ; The game
BYTE next0=[0],next1=[0]
CARD time
DO ; This loop is endless
DO ; Restart game
plyrs=1 level=1 score0=0 score1=0
shots0=5 shots1=5 win=0 goal=1000
DO ; Get playing choices
Title()
DO ; Draw a new playfield
Init() Bkgd() time=0
DO ; Move worms until collision
Stkupdate(0)
IF plyrs=1 THEN Lookfwd()
ELSE stkupdate(1)
FI
Addhead0() Addhead1()
longcnt==-1
IF longcnt>0 THEN
Erasetail0() Erasetail1()
ELSE longcnt=grow
FI
IF sflag0=0 AND Strig(0)=0
AND shots0>0 THEN Sinit0()
FI
IF sflag1=0 AND Strig(1)=0
AND shots1>0 THEN Sinit1()
FI
IF sflag0=1 THEN Smove0()
FI
IF sflag1=1 THEN Smove1()
FI
Dly(speed) Play(0) Play(1)
time=time+1 txtrow=0 txtcol=29
IF time MOD 5=0 THEN
PrintC(time)
FI
txtrow=0 txtcol=6
IF time MOD 50=0 THEN
Print("level ")
PrintB(level) Print(" ")
ELSEIF time MOD 30=0 THEN
Print("win=") PrintC(goal)
FI
next0=Locate(xpos(0)+delx(0),
ypos(0)+dely(0))
next1= Locate(xpos(1)+delx(1),
ypos(1)+dely(1))
UNTIL next0>0 OR next1>0
OD
SndRst()
IF next0>0 THEN flash0()
ELSE flash1()
FI
time=time/5*5
DO ; Update score
time==-5
IF next0>0 THEN score1==+5
Note(0,50,6)
ELSEIF next1>0 THEN
score0==+5 Note(1,60,6)
FI
txtrow=1 txtcol=4 PrintC(score0)
txtcol=12 PrintC(score1) Poke(77,0)
txtrow=0 txtcol=29 PrintC(time)
Print(" ")
FOR cnt=1 TO 10
DO
Dly(200) Play(0) Play(1)
OD
UNTIL time<=0 OR time>64000
OD
SndRst()
IF score0>=goal OR score1>=goal
THEN win=1 EXIT
FI
DO
UNTIL Strig(0)=0 OR Strig(1)=0
OR consol=5 OR consol=3
OD
UNTIL consol=5 OR consol=3
; Exit only if consol key pushed
OD
UNTIL win=1 OR consol=3
; Exit on win or option key
OD
IF consol=3 THEN EXIT ; skip gameover
FI
Gameover()
OD
OD
RETURN