Bouncing Player via String Pointer (De Re Atari)

Type
Graphics
Category
Player/missile animation technique
Author
Lane Winner (Section 10 of De Re Atari)
Published in
De Re Atari: A Guide to Effective Programming (Atari Program Exchange, APX-90008, 1982), Section 10, "Atari BASIC" (Advanced Programming Techniques, Example 3)
Year
1982
Language
Atari BASIC
Requirements
Any Atari 8-bit, 16K RAM, Atari BASIC
A small purple hollow square player on a dark brown 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. Section 10, by Lane Winner, explains how Atari BASIC stores programs and variables, and ends with three "advanced techniques" that use that knowledge. Example 3 became one of the best-known Atari BASIC tricks of all. Atari BASIC copies strings with fast internal machine code. If a string's address can be made to point at player/missile memory, a single assignment such as A$(Y,Y+11)=B$ redraws a player at a new height almost instantly. This program bounces a hollow square around the screen that way.

What you need

Any Atari 8-bit with Atari BASIC.

Typing it in

The trick depends on A$ being the first variable in the variable table. Line 2090 changes the entry for variable number 0. So:

  • Type NEW first, and then type the program in order, so that line 110's DIM A$(512),B$(20) is the first place a variable name appears. (X appears in line 120, after A$.)
  • If you edit the program a lot, the variable table can keep old names. LIST it to disk or cassette, type NEW, and ENTER it back to clean the table.

How to use it

RUN it. A pink square bounces diagonally around the screen. Press BREAK to stop, and RESET to clear the player.

How it works

  • Lines 2000–2030 turn on single-line player DMA (SDMCTL=62), make player 0 pink (704), reserve PM memory 16 pages below RAMTOP, tell ANTIC with PMBASE (54279), and enable GRACTL.
  • VTAB (locations 134/135) points at the variable value table, and ATAB (140/141) at the string/array area. Each entry is eight bytes. For a string, bytes 2–3 hold its offset from ATAB.
  • Line 2060 works out the offset that makes A$ start at player 0's memory (PMBASE + 1024 in single-line mode). Line 2090 writes that offset into A$'s entry. From then on, A$ is player 0.
  • B$ holds the 12-byte shape: a 10-line hollow square with a zero byte at each end. When the shape moves by one line, the zero at the trailing edge wipes out the old copy, so no separate erase step is needed.
  • Lines 4000–4030 move the square: the string assignment moves it vertically, POKE 53248,Z moves it horizontally, and the IF tests reverse the direction at the edges.

Variations to try

  • Use a bigger B$ with more zero bytes at the ends, and move it two or three lines per step for speed.
  • Set up a second string for player 1 the same way. It has to be the second variable (entry 1, at VTAB+10/11), and its memory is 256 bytes further on.

Listing

100 REM PLAYER/MISSILE EXAMPLE
110 DIM A$(512),B$(20)
120 X=X+1:READ A:IF A<>-1 THEN B$(X,X)=CHR$(A):GOTO 120
130 DATA 0,255,129,129,129,129,129,129,129,129,255,0,-1
2000 POKE 559,62:POKE 704,88
2020 I=PEEK(106)-16:POKE 54279,I
2030 POKE 53277,3:POKE 710,224
2040 VTAB=PEEK(134)+PEEK(135)*256
2050 ATAB=PEEK(140)+PEEK(141)*256
2060 OFFS=I*256+1024-ATAB
2070 HI=INT(OFFS/256):LO=OFFS-HI*256
2090 POKE VTAB+2,LO:POKE VTAB+3,HI
3000 Y=60:Z=100:V=1:H=1
4000 A$(Y,Y+11)=B$:POKE 53248,Z
4010 Y=Y+V:Z=Z+H
4020 IF Y>213 OR Y<33 THEN V=-V
4030 IF Z>206 OR Z<49 THEN H=-H
4420 GOTO 4000

Credits