Classic Computer Magazine Archive COMPUTE! ISSUE 37 / JUNE 1983 / PAGE 175

Atari Player/Missile
Graphics Simplified

Staffan Sandberg

You've seen the wonderful things the Atari can do with player/missile graphics, but until now you've either had to settle for slow moving wabbles or learn machine language. Here is an overlay method which is simple to use and results in extremely fast animation of up to five players.

In the overlay method we will design overlays or patterns that we can place on the screen. We can create as many patterns as we want and use them as often as we want. Each overlay is eight dots wide and anything from one to 128 dots high. The overlay allows specified dots to be lit up on the screen. When we want an object to appear to be moving, we place one of the overlays on the screen by specifying its X and Y coordinates. We then give it new X and Y coordinates, and it appears to move. This process is very fast, so the object appears to move quite quickly. These overlays are totally separate from player/missile graphics. It is the combination of the overlays and player/missile graphics that allows us the freedom of movement of the overlay method.
    To use overlays, just follow these steps:

    Step 1: Decide how many players you wish to use and set aside enough memory to hold them. That is, what is the maximum number of objects you want on the screen at one time? You can have up to five. We must give each one a name and set aside 128 spaces for it because each player is potentially 128 dots high. We do this by DIMensioning the space:

10 DIM PM1$(128), PM2$(128), PM3$(128)

    The DIMensioning must be the first thing the computer sees when it is turned on, so before you start programming, turn off the computer and turn it back on. This is necessary because as the computer constructs a variable table, the variables are stored in the order that they are entered. The variable table is not cleared by typing NEW. We want these variables at the beginning of the table so we can find them easily later. If they are not the first thing that the computer sees, the method will not work.

    Step 2: Design the overlays or patterns that you wish to use. Remember, you can create as many overlays as you wish. They are stored in strings (ALIEN$, SHIP$, etc. ), so you must give each overlay a name and DIMension its size. When deciding the size of each overlay, keep the following questions in mind:

1. How tall do you want to make your overlay?
2. What directions do you want to move your player?
3. How fast do you want to move your players?

    You don't need to worry about the width of the overlay. But you must decide how many dots high you wish to make an overlay. It can be up to 128 dots in height (an average spaceship might be six dots high). If you are going to be moving your players down the screen, you must leave blank spaces to cover up the old overlay, and you must take into account the speed at which your player will move. The speed is measured in Dots Per Move (DPM). If your players will be moving at a top speed of three DPM up and down the screen, then you need to leave three spaces above and three spaces below. To help decide the size to be DIMensioned for each overlay, use the formula:

    SIZE = height of overlay + DPM up + DPM down

SHIP$ And ALIEN$ Examples
In our example we will have one ship which we'll call SHIP$, with a height of six moving up and down at the speed of five DPM, and another ship which we'll call ALIEN$, with a height of eight moving neither up nor down.

20 SIZE1=16:SIZE2=8
30 DIM SHIP$(SIZE1), ALIEN$(SIZE2)

We also want a blank overlay that we use to erase the player from the screen quickly. We'll call this overlay CLEAR$. It should be 128 dots high so that it can erase anything on the 128 dot high player.

40 DIM CLEAR$(128)

    Now you must create the overlays line by line. Each line or row is made up of dots or "boxes." Each box is numbered from right to left 1, 2, 4, 8, 16, 32, 64, and 128 (see Figure 1).

Figure 1

    To create the overlays you must decide which boxes you want filled or lit up on the screen. You then add the value of each filled box for each row (see Figures 2 and 3).

Figures 2 and 3

    Now that you have the totals for each row, you must put them in the string that you have DIMensioned for them. This is done in a short loop such as the one below.

50 FOR ROWS=1 TO SIZE1
60 READ DOTS
70 SHIP$(ROWS,ROWS)=CHR$(DOTS)
80 NEXT ROWS
90 DATA 0,0,0,0,0
100 DATA 16,56,56,124,108,68
110 DATA 0,0,0,0,0
120 FOR ROWS=1 TO SIZE2
130 READ DOTS
140 ALIEN$(ROWS,ROWS)=CHR$(DOTS)
150 NEXT ROWS
160 DATA 60,126,219,126,36,36,66,129

You need a loop for each overlay that you have.
    You also need to create the blank overlay, CLEAR$, by entering 128 blank lines into CLEAR$.

170 FOR ROWS=1 TO 128
180 CLEAR$(ROWS,ROWS)=CHR$(0)
190 NEXT ROWS

    Step 3: Tell the computer that you are going to be using Player/Missile Graphics with overlay method by entering the following lines, substituting a value for NUMBEROFPLAYERS.

200 A=4*(INT(PEEK(742)/4)-1)
210 POKE 54279,A
220 VSA=256*PEEK(135)+PEEK(134)
230 BOA=256*PEEK(141)+PEEK(140)
240 PM=256*A+512
250 DISP=PM-BOA
260 ADD=2
270 FOR T=1 TO NUMBEROFPLAYERS
280 PMHIGH=INT(DISP/256)
290 PMLOW=DISP-256*PMHIGH
300 POKE VSA+ADD,PMLOW
310 POKE VSA+ADD+A,PMHIGH
320 DISP=DISP+128:ADD=ADD+8
330 NEXT T

    If you are going to have five players on the screen at one time, you must change line 240 from PM = 256*A + 512 to PM = 256*A + 384. This tells the computer to let us use the fourth missile as a player.

    Step 4: Now we are ready to add the initial specifications, such as color, size and shape to the players. First, line 340 places the blank overlay on each player, clearing out any stray data.

340 PM1$=CLEAR$: PM2$=CLEAR$: PM3$=CLEAR$

Next we set the Player/Missile Graphics to double line resolution and turn on the P/M Graphics (a 3 enables them and a 0 disables them).

350 POKE 559,46: POKE 53277,3

    To set the colors of the players, we must POKE the color register for each player with the proper color number. The registers go from 704 (for Player 0) through 707 (for Player 3). The fifth player takes on a combination of the colors of the other four. The colors that I have chosen are: COLORI is yellow, COLOR2 is white, and COLOR3 is pink.

360 COLOR1=25:COLOR2=11:COLOR3=74
370 POKE 704,COLOR1: POKE 705,COLOR2: POKE 706,COLOR3

    The size of the players is automatically set to normal. If you want to change the size, POKE 0 for normal, 1 for double, and 3 for quadruple size into the size register for the corresponding player. These registers go from 53256 (for Player 0) through 53259 (for Player 3).

    POKE 53256,1 would make Player 0 double size.

    Now we can place the player on the screen. First, we give the player an X (horizontal) value and POKE it into the horizontal position register for each player. The registers go from 53248 (for Player 0) through 53251 (for Player 3). The horizontal positions that show up on the screen range from about 50 to 200 (depending on your TV). Numbers lower than 50 and greater than 200 are to the right and left of the screen.

380 X1=125:X2=75:X3=175
390 POKE 53248,X1: POKE 53249,X2: POKE 532
   50,X3


    Now we must give our player a Y (vertical) value and an overlay. The format is PM$ (Y value) = overlay.

400 Y1=150:Y2=25:Y3=25
410 PM1$(Yl)=SHIP$: PM2$(Y2)=ALIEN$: PM3$(
   Y3)=ALIEN$

    To move the player around the screen, change the X and/or the Y value and repeat steps 390 and 410. Be sure not to change the X value more than the maximum DPM that you decided earlier. If you do, you will leave parts of the overlay on the screen.

Program 1.
Player/Missile Graphics Example 1

5 REM PMSAMPLEI
10 DIM PM1$(128),PM2$(128),PM3$(128)
20 SIZE1=16:SIZE2=8
30 DIM SHIP$(SIZE1),ALIEN$(SIZE2)
40 DIM CLEAR$(128)
50 FOR ROWS=1 TO SIZE1
60 READ DOTS
70 SHIP$(ROWS,ROWS)=CHR$(DOTS)
80 NEXT ROWS
90 DATA 0,0,0,0,0
100 DATA 16,56,56,124,108,68
110 DATA 0,0,0,0,0
120 FOR ROWS=1 TO SIZE2
130 READ DOTS
140 ALIEN$(ROWS,ROWS)=CHR$(DOTS)
150 NEXT ROWS
160 DATA 60,126,219,126,36,36,66,129
170 FOR ROWS=1 TO 128
180 CLEAR$(ROWS,ROWS)=CHR$(0)
190 NEXT ROWS
200 A=4*(INT(PEEK(742)/4)-1)
210 POKE 54279,A
220 VSA=256*PEEK(135)+PEEK(134)
230 BOA=256*PEEK(141)+PEEK(140)
240 PM=256*A+512
250 DISP=PM-BOA
260 ADD=2
270 FOR T=1 TO 3
280 PMHIGH=INT(DISP/256)
290 PMLOW=DISP-256*PMHIGH
300 POKE VSA+ADD,PMLOW
310 POKE VSA+ADD+1,PMHIGH
320 DISP=DISP+128:ADD=ADD+8
330 NEXT T
340 PM1$=CLEAR$:PM2$=CLEAR$:PM3$=CLE
    AR$
350 POKE 559,46:POKE 53277,3
360 COLR1=25:COLR2=11:COLR3=74
370 POKE 704,COLR1:POKE 705,COLR2:PO
    KE 706,COLR3
380 X1=125:X2=75:X3=175
390 POKE 53248,X1:POKE 53249,X2:POKE
    53250,X3
400 Y1=75:Y2=25:Y3=25
410 PM1$(Y1)=SHIP$:PM2$(Y2)=ALIEN$:P
    M3$(Y3)=ALIEN$
420 IF STICK(0)<8 THEN X1=X1+3
430 IF STICK(0)>8 AND STICK(0)<13 TH
    EN X1=X1-3
440 IF STICK(0)=14 THEN Y1=Y1-3
450 IF STICK(0)=13 THEN Y1=Y1+3
460 POKE 53248,X1:PM1$(Y1)=SHIP$
470 IF STICK(1)<8 THEN X2=X2+2
480 IF STICK(1)38 AND STICK(1)<13 TH
    EN X2=X2-2
490 POKE 53249,X2
500 IF STICK(2)<8 THEN X3=X3+2
510 IF STICK(2)>8 AND STICK(2)<13 TH
    EN X3=X3-2
520 POKE 53250,X3
530 GOTO 420

Program 2.
Player/Missile Graphics Example 2

5 REM PMSAMPLE2
10 DIM PM$(128)
20 DIM SHIP$(16),CLEAR$(128)
30 FOR ROW=1 TO 16
40 READ DOTS
50 SHIP$(ROW,ROW)=CHR$(DOTS)
60 NEXT ROW
70 DATA 0,0,0,0,0
80 DATA 16,56,56,124,108,68
90 DATA 0,0,0,0,0
100 FOR ROW=1 TO 128
110 CLEAR$(ROW,ROW)=CHR$(0)
120 NEXT ROW
130 A=4*(INT(PEEK(742)/4)-1)
140 POKE 54279,A
150 VSA=256*PEEK(135)+PEEK(134)
160 BOA=256*PEEK(141)+PEEK(140)
170 PM=256*A+512
180 DISP=PM-BOA
190 ADD=2
200 FOR T=1 TO 1
210 PMHIGH=INT(DISP/256)
220 PMLOW=DISP-256*PMHIGH
230 POKE VSA+ADD,PMLOW
240 POKE VSA+ADD+1,PMHIGH
250 DISP=DISP+128:ADD=ADD+8
260 NEXT T
270 PM$=CLEAR$
280 POKE 559,46:POKE 53277,3
290 POKE 704,12
300 POKE 53248,50
310 PM$(10)=SHIP$
320 N=1
330 FOR X=60 TO 190 STEP N
340 POKE 53248,X
350 NEXT X
360 FOR Y=10 TO 100 STEP N
370 PM$(Y)=SHIP$
380 NEXT Y
390 FOR X=190 TO 60 STEP -N
400 POKE 53248,X
410 NEXT X
420 FOR Y=100 TO 10 STEP -N
430 PM$(Y)=SHIP$
440 NEXT Y
450 N=N+0.1
460 IF N>5 THEN N=1
470 GOTO 330