Joystick-Controlled Player (De Re Atari)

Type
Graphics
Category
Player/missile graphics tutorial program
Author
Chris Crawford (Section 4 of De Re Atari)
Published in
De Re Atari: A Guide to Effective Programming (Atari Program Exchange, APX-90008, 1982), Section 4, "Player-Missile Graphics"
Year
1982
Language
Atari BASIC
Requirements
Any Atari 8-bit, 16K RAM, Atari BASIC, joystick in port 1
A small purple arrow-shaped player on a black screen

About the program

De Re Atari ("All About Atari") was written by Atari's Software Development Support Group as a training manual for professional programmers. Early versions went to registered developers in 1981, and the 1982 edition was sold through the Atari Program Exchange as APX-90008. Chris Crawford wrote its first six sections, including the player/missile chapter. This short program comes at the end of the chapter's set-up checklist. It is the bare minimum needed to put a player on screen and move it, and many Atari programmers started out by typing it in.

What you need

Any Atari 8-bit with Atari BASIC, and a joystick in port 1.

Typing it in

Plain ASCII. Lines 1–6 give names to the hardware addresses, and everything after each REM is commentary that you can leave out. Type GRAPHICS 0 before you RUN it again, so that player memory is set up afresh.

How to use it

RUN it, and a small pink shape appears on a black screen. Push the joystick left or right to move it sideways, and up or down to move it vertically. Diagonals are ignored. Press BREAK to stop. The player stays on the screen until you press RESET or type a GRAPHICS command.

How it works

  • Line 40 takes RAMTOP (location 106), the top of free RAM in pages, and backs off 8 pages (2K) for player/missile memory. Line 50 tells ANTIC where that memory is through PMBASE (54279).
  • Line 70 sets SDMCTL (559), the shadow of DMACTL, to 46. That keeps the normal playfield and turns on player and missile DMA at double-line resolution. Line 80 sets GRACTL (53277) to 3 so that GTIA displays what ANTIC fetches.
  • In double-line resolution, player 0's 128 bytes start 512 bytes into PM memory. Lines 100–120 clear them, and lines 130–170 copy in the 7-byte shape at vertical offset Y.
  • Horizontal movement is a single POKE to HPOSP0 (53248). Vertical movement means moving the shape's bytes up or down in memory. Lines 240–260 and 290–310 copy each byte to its neighbour, one byte at a time, which is why vertical movement is visibly slower than horizontal.

Variations to try

  • Change SDMCTL to 62 and the offset to +1024 for single-line resolution (back off 16 pages instead of 8). The ship becomes half as tall.
  • Replace the DATA in line 170 with your own 7-byte shape. Each byte is one row, and each bit is a pixel.
  • Add POKE 53256,1 (SIZEP0) to make the player double width.

Listing

1  PMBASE=54279:REM                    Player-missile base pointer
2  RAMTOP=106:REM                      OS top of RAM pointer
3  SDMCTL=559:REM                      RAM shadow of DMACTL register
4  GRACTL=53277:REM                    CTIA graphics control register
5  HPOSP0=53248:REM                    Horizontal position of P0
6  PCOLR0=704:REM                      Shadow of player 0 color
10 GRAPHICS 0:SETCOLOR 2,0,0:REM       Set background color to black
20 X=0:REM                             BASIC's player horizontal position
30 Y=48:REM                            BASIC's player vertical position
40 A=PEEK(RAMTOP)-8:REM                Get RAM 2K below top of RAM
50 POKE PMBASE,A:REM                   Tell ANTIC where PM RAM is
60 MYPMBASE=256*A:REM                  Keep track of PM RAM address
70 POKE SDMCTL,46:REM                  Enable PM DMA with 2-line res
80 POKE GRACTL,3:REM                   Enable PM display
90 POKE HPOSP0,100:REM                 Declare horizontal position
100 FOR I=MYPMBASE+512 TO MYPMBASE+640:REM this loop clears player
110 POKE I,0
120 NEXT I
130 FOR I=MYPMBASE+512+Y TO MYPMBASE+518+Y
140 READ A:REM                         This loop draws the player
150 POKE I,A
160 NEXT I
170 DATA 8,17,35,255,32,16,8
180 POKE PCOLR0,88:REM                 Make the player pink
190 A=STICK(0):REM                     Read joystick
200 IF A=15 THEN GOTO 190:REM          If inactive, try again
210 IF A=11 THEN X=X-1:POKE HPOSP0,X
220 IF A=7 THEN X=X+1:POKE HPOSP0,X
230 IF A<>13 THEN GOTO 280
240 FOR I=8 TO 0 STEP -1
250 POKE MYPMBASE+512+Y+I,PEEK(MYPMBASE+511+Y+I)
260 NEXT I
270 Y=Y+1
280 IF A<>14 THEN GOTO 190
290 FOR I=0 TO 8
300 POKE MYPMBASE+511+Y+I,PEEK(MYPMBASE+512+Y+I)
310 NEXT I
320 Y=Y-1
330 GOTO 190

Credits