Sunset (DLI Demo)

Type
Graphics
Category
Display list interrupt colour animation
Author
Dave Small
Published in
The Creative Atari (Creative Computing Press, 1983), "Display List Interrupts", Program 13 with Program 10
Year
1983
Language
Atari BASIC
Requirements
Any Atari 8-bit, 16K RAM, Atari BASIC
A multicoloured spiral over horizontal bands of orange and grey, with scattered stars above

About the program

Dave Small closed his display list interrupt chapter in The Creative Atari with what he called "the Sunset program which takes such a terrible toll on prospective Apple buyers". It takes an earlier Creative Computing spiral program, sprinkles stars in the sky, and then sets a display list interrupt on every second line of a GRAPHICS 7 screen. The colour table is split in two halves that rotate in opposite directions, so the colours rise in one half of the screen and sink in the other, like a sunset reflected in water.

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.

Lines 590 and 860 are given here as printed in the book: R=20 and COL$(T+1,T+1)=CHR$(T1). Check these two lines carefully. With R=2 the spiral comes out far too small, and without line 860 the variable T1 is never used and one colour register stays black.

How to use it

RUN it. The spiral and the stars are drawn first. Then the colour animation starts, and it runs until you press BREAK. Press RESET before you edit the program.

How it works

  • Lines 550–770 draw three rings of a spiral (each ring in a different colour register) with DEG trigonometry. Then they scatter 50 random points as stars across the upper part of the screen.
  • Lines 800–900 fill all 255 bytes of COL$ with 51 five-byte groups. Each colour register starts a third of the way round the colour range from the others (T, T+80, T+160), and the background bytes start at zero (black).
  • 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 270–310 add interrupts to the top blank lines, to the first GRAPHICS 7 line (13+64+128) and to every second mode line after it. That makes 51 interrupts, exactly the number of five-byte groups the table holds.
  • The main loop (340–510) splits COL$ into two halves. It rotates the first half by one group in one direction and the second half in the other, and feeds a slowly increasing value (ROT) into one background byte. Then it writes both halves back with only two assignments, so the interrupt routine never reads a half-finished table.

Variations to try

  • Change the offsets 80 and 160 in lines 820–830 for different colour combinations.
  • Use STEP 3 or STEP 4 in line 290 for wider colour bands, which also leaves the interrupt routine less work.

Listing

110 REM ***
120 REM *** DAVE SMALL
130 REM ***
140 DIM TOP1$(128),BOT1$(128)
150 DIM TOP$(128),BOT$(128)
160 DIM COL$(255)
170 REM *********************
180 REM INITIALIZE SCREEN FOR DISP
190 GOSUB 550
200 REM * INITIALIZE COL$
210 GOSUB 790
220 REM * INITIALIZE ASSEMBLY
230 GOSUB 10000
240 REM
250 REM * DISPLAY LIST
260 ST=PEEK(560)+256*PEEK(561)
270 POKE ST,112+128:REM TOP INT(15)
280 POKE ST+3,13+64+128:REM LMS,DLI
290 FOR Y=6 TO 6+96 STEP 2:REM HI SRS
300 POKE ST+Y,13+128
310 NEXT Y
320 REM ************************
330 REM ROTATE COL$ IN HALVES
340 FOR ROT=0 TO 300 STEP 2
350 SANDY=0
360 BOT$=COL$(1,125)
370 TOP$=COL$(126,250)
380 REM **
390 TOP1$=TOP$(1,120)
400 TOP$=TOP$(121,125)
410 TOP$(6)=TOP1$
420 TOP$(5,5)=CHR$(ROT)
426 IF ROT>255 THEN TOP$(5,5)=CHR$(0)
430 REM
440 BOT1$=BOT$(1,5)
450 BOT$=BOT$(6)
460 BOT$(121)=BOT1$
470 REM
480 COL$(1,125)=BOT$
490 COL$(126)=TOP$
500 NEXT ROT
510 GOTO 340
530 REM ************************
540 REM FROM CREATIVE COMPUTING. .
550 GRAPHICS 23:DEG :SETCOLOR 2,4,10:DIM C(3)
560 SETCOLOR 0,0,10
570 SETCOLOR 1,0,6
580 SETCOLOR 2,0,2
590 R=20:COLOR 1:C=1
600 X0=79:Y0=47
610 FOR K=0 TO 3:C(K)=K+1*2:NEXT K
620 FOR K=1 TO 3
630 X=X0+R*COS(360):Y=Y0:PLOT X,Y
640 FOR I=0 TO 5*360 STEP 75
650 X=X0+R*COS(I):Y=Y0+R*SIN(I)
660 DRAWTO X,Y
670 NEXT I:R=R+12:C=C+1:COLOR C
680 NEXT K
690 Z8=1
700 FOR LOOP=1 TO 50
710 COLOR Z8
720 X8=INT(RND(0)*159)+1
730 Y8=INT(RND(0)*47)+1
740 PLOT X8,Y8
750 Z8=Z8+1:IF Z8=4 THEN Z8=1
760 NEXT LOOP
770 RETURN
780 REM ************************
790 REM *** INT COL$
800 FOR T=1 TO 255 STEP 5
810 COL$(T,T)=CHR$(T)
820 T1=T+80
830 T2=T+160
840 IF T1>255 THEN T1=T1-256
850 IF T2>255 THEN T2=T2-256
860 COL$(T+1,T+1)=CHR$(T1)
870 COL$(T+2,T+2)=CHR$(T2)
880 COL$(T+3,T+3)=CHR$(0)
890 COL$(T+4,T+4)=CHR$(0)
900 NEXT T
910 RETURN
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