Classic Computer Magazine Archive COMPUTE! ISSUE 89 / OCTOBER 1987 / PAGE 98

Stringing The Atari Screen

Rhett Anderson

If you envy the speed with which machine language programmers can manipulate the graphics screen, type in this program to see just how fast BASIC can be.


For years, Atari BASIC programmers have been using strings to manipulate player-missile graphics. Atari BASIC strings are ideally suited for this task. While most BASICs limit the size of strings to 255 characters, Atari BASIC allows huge strings. In addition, Atari BASIC makes sub-string manipulation very easy.

Even if you are familiar with this trick, you may not have realized that it is possible to treat the entire display memory (or playfield, as Atari calls it) as a string. This technique allows you to do some things that are otherwise very slow in Atari BASIC. Among these are

  • Erasing or filling the screen or part of the screen with any solid color or pattern.
  • Duplicating part of the screen.
  • Fast swapping of full or partial screen displays.

Although I have used GRAPHICS 7 for this program, these techniques are easily applied to all the graphics modes—even the text modes.

Typing It In

The program found at the end of this article is written entirely in BASIC. This program assumes that the first variable used will be placed in the first slot in the variable name table. To insure that this is the case, be sure to type NEW before entering the program. Type it in and save it to tape or disk. If you forget to type NEW, or if the program does not operate properly, save the program to tape or disk with the LIST command (see your BASIC manual for an example). Then type NEW and use the ENTER command to retrieve the program. You may now save the program again with the SAVE command.

The program is broken up into several sections. You can use any of these sections in your own programs. Just be sure that lines 10-60 are at the beginning of your program.

You must be sure to dimension the strings you use to the proper size. The amount of memory used by the screen (and therefore by the string) depends upon the screen mode. The size of the screen can be found with this formula:

size = (number of bytes needed per scan line) * (number of pixels available vertically)
ModesBytes per Scan Line
0, 7, 8, 9, 10, 11, 1540
1, 2, 5, 610
3, 410

For example, a GRAPHICS 0 screen would require 40 * 24 bytes of storage, while a GRAPHICS 7 screen requires 40*80.a

As written, the program points the variable A$ to the screen area. You may change the name of the variable in your own programs, but it must be the first variable used in the program.

Once the string is reassigned to the screen, any operations you perform on the string will show up on the screen.

Addressing the screen as a string may seem awkward at first, but it is incredibly fast. Once you understand it, you'll be able to write programs that do screen manipulations with machine language speed. In the case of the GRAPHICS 7 screen, a byte represents four pixels. This makes color selection rather odd. Instead of using the COLOR statement to select colors 0–3, the values 0, 85, 170, and 255 represent the four different colors.

Although the memory representation makes working with solid colors rather arcane, it makes working with patterns a breeze (for an example, see the Atari version of Laser Chess ™ in the July 1987 issue of COMPUTE!). In some graphics modes such as mode 15 (available only on XLs and XEs), the two colors blend well enough to appear to be a new color. A patterned screen fill is done in the demo program in lines 320–360. Use this table to replace the numbers in lines 320 and 340 for other color combinations.

ColorsValues
0 and 117, 68
0 and 234, 136
0 and 351, 204
1 and 2102, 153
1 and 3119, 221
2 and 3187, 238

For instance, if you want to use colors 2 and 3 in the demo, replace the 102 in line 320 with 187 and replace the 153 in line 340 with 238.

For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs" elsewhere in this issue.

Stringing The Atari Screen

NO	1	 REM Copyright 1987 COMPUTE! PUBLICATIONS, INC. ALL RIGHTS RESERVED.
LA	2	 PRINT "{CLEAR}" : POSITIO N 12, 8 : PRINT "Copyright 1987" : POSITION 7, 10 : PRINT "COMPUTE! Publications, Inc."
GN	3	 POSITION 10, 12 : PRINT "A 11 Rights Reserved "
PN	4	 FOR 1 = 1 TO 1500 : NEXT I
JO	10	 GRAPHICS 7 : CLR : DIM A$ (40 * 80), COL (4), B$ (40 * 80), TEMP$ (40 * 8O) : A$ (40 * 80) = CHR$ (0)
NL	20	 VTAB = PEEK (134) + PEEK (135) * 256
MB	30	 ATAB = PEEK (140) + PEEK (141) * 256
ND	40	 OFFS = PEEK (88) + PEEK (89) * 256 - ATAB
CD	50	 HI = INT (OFFS/256) : LO = OF FS - HI * 256
JH	60	 POKE VTAB + 2, LO : POKE VT AB + 3, HI
JE	70	 REM * * SOLID COLOR FILL * *
NJ	75	 PRINT "SOLID COLOR FILL" : GOSUB 1000
PD	80	 FOR T = 0 TO 4 : READ COL : COL (T) = COL
BK	90	 A$ (1, 1) = CHR$(COL)
BL	100	 A$ (2) = A$
NH	105	 GOSUB 1000
CF	110	 NEXT T
FD	120	 DATA 0, 85, 170, 225, 0
PB	200	 REM * * FILL PAT OF SCREEN * *
HE	210	 PRINT "PARTIAL SCREEN FILL" : FOR T = 0 TO 3 : W HERE = 400 * T + 1 : REM USE 400 BECAUSE 10 LINES OF 40 BYTES EACH
HO	220	 A$ (WHERE, WHERE) = CHRS$ (COL (T))
AK	230	 A$ (WHERE + 1, WHERE + 399) = A$ (WHERE, WHRE + 398) : REM DO 10 LINES
NL	235	 GOSUB 1000
CJ	240	 NEXT T
ME	300	 REM * * PATTERN FILL *
PD	310	 PRINT "PATTERNED SCREEN FILL"
NK	315	 GOSUB 1000
PL	320	 A * (1, 1) = CHR$ (102)
KO	330	 A * (2, 40) = A$ : REM 40 BECAUSE USING GR. 7
CL	340	 A$ (41, 41) = CHR$ (153) : REM NEXT LINE DOWN
KA	350	 A * (42, B0) = A * (41)
AH	360	 A * (81) = A * : REM DUPLICATE FIRST 2 LINES DOWN ENTIRE SCREEN
NL	370	 GOSUB 1000
NM	400	 REM * * SCREEN DUPLICATION * *
IN	410	 PRINT "DUPLICATE PART OF SCREEN "
NL	415	 GOSUB 1000
CH	420	 FOR X = 0 TO 159 : COLOR X/54
OK	430	 PLOT X, 0 : DRAWTO X/2, 79
CP	440	 NEXT X
AN	450	 FOR 1 = 1 TO 3
MD	560	 A$(I * 800 + 1, I * 800 + 800) = A$ : REM 800 FOR 20 LINES
CE	570	 NEXT I
ND	580	 GOSUB 1000
PJ	600	 REM * * FAST SCREEN SAPPING * *
IB	610	 PRINT "SCREEN FLIPPING"
KA	620	 B * = A *
CE	630	 FOR Y = 1 TO 30 : COLOR RND (0) * 3 + 1
JB	640	 PLOT RND (0) * 159, RND (0) * 79 : DRAWTO RND (0) * 159, RND (0) * 79
DD	650	 NEXT Y
EC	660	 FOR K = 1 TO 30
BC	670	 TEMP$ = A$ : A$ = B$ = TEMP$
CI	680	 NEXT K
OA	690	 GOSUB 1000
FJ	700	 REM * * PARTIAL SCREEN SWAPPING * *
II	710	 PRINT "PARTIAL SCREEN SWAPING" : ? "(TOP WITH BOTTOM"
EG	720	 FOR K = 1 TO 30 : B$ = A$ (1, 40 * 40) : A$ (1, 40 * 40) = A$ (40 * 40 + 1) : A$ (40 * 40 + 1) = B$ : NEXT K
IE	800	 REM * * ANIMATION * *
AK	810	 PRINT "ANIMATION"
BB	820	 A$ (1, 1) = CHR$ (0) : A$ (2) = A$
BJ	830	 FOR T = 0 TO 3
LE	840	 COLOR 1 : FOR Y = 1 TO 10 : COLOR Y : PLOT T + 4, Y + T * 20 : DRAWTO T + 30 + 4, Y + T * 20 : NEXT Y
DA	850	 NEXT T
OD	855	 GOSUB 1000
KG	860	 B$ = A$
GG	870	 A$(1, 1) = CHR$(0) : A$(2) = A$
FA	880	 X = 10 : Y = 10 : DX = 1 : DY = 1
LE	900	 IF X = 100 THEN DX = -1
CM	910	 IF X = 5 THEN DX = 1
IN	920	 IF X = 5 THEN DY = -1
DB	930	 IF Y = 60 THEN DY = 1
AH	940	 H = INT (X/4) : L = X - H * 4
LG	950	 A$ (H + 40 * Y + 1, H + 40 * Y + 480) = B$ (L * 800 + 1, L * 800 + 480
HJ	960	 GOTO 890
KB	1000	 FOR DELAY = 1 TO 100 : N EXT DELAY
KC	1010	 RETURN