128 Colours on One Screen (DLI Demo)

Type
Graphics
Category
Display list interrupt demo
Author
Dave Small
Published in
The Creative Atari (Creative Computing Press, 1983), "Display List Interrupts", Program 12 with Program 10
Year
1983
Language
Atari BASIC
Requirements
Any Atari 8-bit, 16K RAM, Atari BASIC
A GRAPHICS 7 screen divided into a grid of colour patches, each column ramping through shades of different hues

About the program

The Atari can show 128 distinct colours (16 hues × 8 luminances), but only five colour registers at a time. In The Creative Atari Dave Small mentioned that the first program he had seen show all 128 at once did nothing else with the processor. His version does it with display list interrupts and leaves BASIC free. Program 12 draws four vertical stripes in GRAPHICS 7, one for each colour register. Then it reloads all four registers every three display blocks down the screen, so every colour gets its own small rectangle.

What you need

Any Atari 8-bit with Atari BASIC.

Typing it in

Type the main program and the driver as one program. The driver's DATA lines (10180–10270) are machine code, so check every number. A mistake can crash the machine as soon as interrupts are switched on. SAVE before you RUN. The REM lines can be left out.

When you press BREAK, the colours stay, because the interrupt routine is still running from PR$. If you then edit the program, BASIC may move the strings and the machine will lock up. Press RESET first, or remove the interrupts from the display list.

How to use it

RUN it. The four stripes are drawn first. Then the driver starts and the screen turns into a grid of colour patches. The program loops at line 410 until you press BREAK (then press RESET, as explained above).

How it works

  • Lines 125–210 open a full-screen GRAPHICS 7 display (7+16) and fill four 40-pixel-wide stripes with COLOR 1, 2 and 3 and the background.
  • Lines 240–320 build 33 groups of five colour bytes. Each group has four registers set to the same step CL, offset by 64, 128 and 192 so that each register shows a different quarter of the colour range. CL goes up by 2 per group. That is the smallest step that changes the colour, because the lowest bit of a colour value is ignored. 32 groups × 4 visible registers = 128 shades.
  • Every DLI program in the chapter shares the same driver, Program 10 (lines 10000–10660). It READs a 40-byte 6502 interrupt routine into PR$, patches in the addresses of COL$ and of a one-byte counter, points the DLI vector at locations 512/513 to the routine, and enables display list interrupts with POKE 54286,192. Each time an interrupt fires, the routine copies the next five bytes of COL$ into the five playfield and background colour registers (53270–53274). At the very top of the screen (when VCOUNT, location 54283, reads 7), it starts again at the beginning of the string. That is why the first display-list instruction, the 112 that makes the blank lines at the top, must always carry an interrupt.
  • Lines 370–400 put an interrupt on the top blank-line instruction and on every third GRAPHICS 7 instruction (code 13+128), giving 33 interrupts in all.

Variations to try

  • Rotate the colours, as the article suggests: build COL1$=COL$(6):COL1$(161)=COL$(1,5):COL$=COL1$ into the loop at line 410 (with DIM COL1$(255)). Register 3 is not visible in GRAPHICS 7, so a "hole" travels through the pattern as it rotates.
  • Change the step in line 380 to 2 for 48 interrupts and finer bands. Keep within the driver's limit of 51 groups.

Listing

110 DIM COL$(255)
120 REM * DRAW FIGURE
125 GRAPHICS 7+16
126 FOR R=0 TO 4
127 SETCOLOR R,0,R*2
128 NEXT R
129 COLOR 1
130 CL=1
140 FOR X=1 TO 120 STEP 40
150 COLOR CL
160 CL=CL+1
170 FOR Y=1 TO 95
180 PLOT X,Y
190 DRAWTO X+40,Y
200 NEXT Y
210 NEXT X
230 REM * LOAD COLORS
240 CL=0
250 FOR T=1 TO 33*5 STEP 5
260 COL$(T)=CHR$(CL):REM COL REG 0
270 COL$(T+1)=CHR$(CL+64):REM COLREG 1
280 COL$(T+2)=CHR$(CL+128):REM COLREG 2
290 COL$(T+3)=CHR$(CL+192):REM UNUSED
300 COL$(T+4)=CHR$(CL+192):REM COLREG 4
310 CL=CL+2
320 NEXT T
330 REM * CALL DRIVER
340 GOSUB 10000
350 REM * SET INTERRUPTS
360 START=PEEK(560)+256*PEEK(561)
370 POKE START,112+128
380 FOR D=START+7 TO START+7+96 STEP 3
390 POKE D,13+128:REM GR.7
400 NEXT D
410 GOTO 410
10000 REM **************************
10010 REM
10020 REM * DLI DRIVER / DAVE SMALL
10030 REM * YOU MUST DIM AND FILL
10040 REM * COL$ PRIOR TO GOSUB HERE
10050 REM
10060 DIM PR$(50)
10080 REM
10090 REM * READ PROGRAM INTO PR$
10100 REM
10110 READ X
10120 IF X=255 THEN 10300
10130 PR$(LEN(PR$)+1)=CHR$(X)
10140 GOTO 10110
10150 REM
10160 REM * PROGRAM AS BYTES
10170 REM
10180 DATA 72,138,72,152,72
10190 DATA 162,0,173,11,212,201,07,240,3
10200 DATA 174,01,02
10210 DATA 160,0
10220 DATA 189,03,04
10230 DATA 153,22,208
10240 DATA 232,200,192,5,208,244
10250 DATA 142,05,06
10260 DATA 104,168,104,170,104,64
10270 DATA 00,01,02,03,04,05
10280 DATA 255
10290 REM
10300 REM * LINK COL$ TO PR$
10310 REM
10320 P=ADR(PR$)
10330 PHI=INT(P/256)
10340 PLO=(P-PHI*256)
10350 REM
10360 C=ADR(COL$)
10370 CHI=INT(C/256)
10380 CLO=(C-CHI*256)
10390 REM
10400 REM * FORE IN COL$ ADDRESS
10410 REM
10420 PR$(21,21)=CHR$(CLO):REM LOWCOL
10430 PR$(22,22)=CHR$(CHI):REM HI COL
10440 REM
10450 REM * POKE IN PROGRAM LOAD ADDR
10460 REM
10470 PXHI=INT((P+41)/256)
10480 PXLO=(P+41)-(PXHI*256)
10490 PR$(16,16)=CHR$(PXLO):REM XLO
10500 PR$(17,17)=CHR$(PXHI):REM XHI
10510 PR$(33,33)=CHR$(PXLO):REM XLO
10520 PR$(34,34)=CHR$(PXHI):REM XHI
10530 REM
10540 REM * POKE IN INTERRUPT ADDRESS
10550 REM
10560 POKE 512,PLO
10570 POKE 513,PHI
10580 REM
10590 REM * ENABLE INTERRUPTS (ANTIC)
10600 REM
10610 POKE 54286,128+64
10620 REM
10630 REM * ALL SET! RETURN,
10640 REM
10650 RETURN
10660 REM ******************

Credits