16 Colours at Once (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 11 with Program 10
Year
1983
Language
Atari BASIC
Requirements
Any Atari 8-bit, 16K RAM, Atari BASIC
A text screen listing the program, with every text line on a different coloured background band

About the program

Display list interrupts (DLIs) are the trick behind the multicoloured screens of so many Atari games. You flag a line in ANTIC's display list, and the 6502 runs a short routine at that exact point on the screen, usually to change colour registers. Dave Small's tutorial in The Creative Atari came with a reusable BASIC-plus-machine-code driver (Program 10). This first demonstration, Program 11, uses it to give each of the first 16 lines of the ordinary text screen its own background colour, all at the same time.

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 program sets up the colours, installs the driver, sets the interrupts and then stops at line 500. The colour bands stay in place behind the READY prompt, which nicely shows that the interrupts run independently of BASIC.

How it works

  • Lines 140–210 build COL$ as 16 groups of five bytes. Only the third byte of each group changes. That byte goes to colour register 2, which is the background of the text area in GRAPHICS 0. It starts at 4 and goes up by 16 each time, so each group has the next hue at the same brightness. The fifth byte sets the border to 2 (dark grey).
  • 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.
  • Line 290 adds the interrupt flag (+128) to the first blank-line instruction. Line 295 does the same for the first text line, the 66 (mode 2 + 64 for Load Memory Scan). Lines 330–350 flag the mode-2 lines that follow. One interrupt per line gives one colour per line.

Variations to try

  • The article's suggestion is to rotate the colours. Add a DIM COL1$(255) to line 120, delete line 500, and add a loop that does COL1$=COL$(76,80):COL1$(6)=COL$(1,75):COL$=COL1$. The bands will then scroll smoothly up the screen. Always build the new table in the scratch string and copy it in one go, so that the routine never sees a half-made table.
  • Change the second byte of each group (register 1, the text brightness) so that the characters stay readable on the darker bands.

Listing

110 REM * 16 COLORS AT THE SAME TIME.
120 DIM COL$(255)
130 REM * INITIALIZE COL$ IN GROUPS
140 N=4
150 FOR C=1 TO 80 STEP 5
160 COL$(C)=CHR$(0):REM UNUSED
170 COL$(C+1)=CHR$(0):REM LUM
180 COL$(C+2)=CHR$(N):REM COLOR
190 COL$(C+3)=CHR$(0)
200 COL$(C+4)=CHR$(2):REM GREY BORDER
205 N=N+16
210 NEXT C
220 REM
230 REM * NOW CALL DLI HANDLER
240 REM
250 GOSUB 10000
260 REM
270 REM * NOW DO DL WORK
280 START=PEEK(560)+256*PEEK(561)
290 POKE START,112+128
295 POKE START+3,2+64+128
300 REM
310 REM * NOW POKE IN 14 MORE(GR/0)
320 REM
330 FOR D=START+6 TO START+6+14
340 POKE D,2+128
350 NEXT D
360 REM
370 REM PROGRAM IS NOW RUNNING.
380 REM
500 STOP
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