Color Palette
- Type
- Utility
- Category
- Colour selection utility
- Author
- John W. Felton
- Published in
- Antic, June 1985 (Vol. 4, No. 2)
- Year
- 1985
- Language
- Atari BASIC (with machine-language interrupt routines)
- Requirements
- Any Atari 8-bit computer, any memory size, Atari BASIC, joystick in port 1; disk or cassette
- Tags
- antic, color, setcolor, joystick, dli, vbi, fine-scrolling, player-missile, string-pointer, utility, 1985
About the program
Choosing colours for a program used to mean typing SETCOLOR statements, running it, breaking out, adjusting and running again, "to find the perfect green for your slime monsters, or just the right red for the sky over Barsoom", as John Felton put it. Felton, a computer science student at Cal Poly in San Luis Obispo, wrote Color Palette for Antic's June 1985 graphics issue so you could compare shades side by side and pick them with the joystick.
The top window shows 12 colour patches, each labelled with its hue, its luminance and the value to POKE into a colour register. The bottom right patch is the background. The first four start out as the Atari's default colours. Felton remarked how many programs use those defaults simply because finding better ones was too much trouble.
Typing it in
Several lines contain special characters. {inv} … {/inv} means press the Atari (inverse) key before and after. {CTRL-,} and {CTRL-A} mean hold CTRL and press the comma or the A. {INS CHAR} (lines 650 and 790) is ESC followed by SHIFT-INSERT, typed inside the quotes. These strings are copied straight into player memory, so the codes matter. The DATA lines hold the display list and the interrupt routines. Antic printed TYPO II checksums beside each line of the magazine listing. They are not part of the program. The magazine's Listing 2 was the assembly source of the machine code, and you don't need it.
How to use it
RUN it and wait a moment. Move the cursor over a patch with the joystick and press fire. In the lower window, push the stick up and down to change the hue and left and right to change the luminance. The X in the lower window shows your current values. Press fire to set the colour and go on to the next one.
How it works
- More than five colours. The screen is built from a custom display list (DATA at line 80), with display list interrupts (DATA at line 90) that reload the colour registers partway down the screen. Each band of patches can therefore have its own colours. The vector is set by
POKE 512,14:POKE 513,6andPOKE 54286,192. - Smooth scrolling. The lower window is moved by a short routine,
ROUTINE$, that changes the screen address in the display list. A vertical blank routine started withUSR(1768)runs alongside it. - The string trick. Lines 570–610 edit BASIC's variable value table so that the string
PM$starts exactly at player-missile memory. Assigning toPM$(lines 920–950) then draws or erases the cursor player at full string-copy speed. - Line 420 copies part of the ROM character set into the new character area, which shares the same block of memory.
Listing
10 REM COLOR PALETTE
20 REM BY JOHN W. FELTON
30 REM (c) 1985, ANTIC PUBLISHING
40 REM INITIAL COLORS
50 DATA 40,202,148,70
60 DATA 50,82,252,114,172,244,198,0
70 REM DISPLAY LIST
80 DATA 112,112,64,69,0,0,133,0,130,0,5,133,0,130,0,5,133,0,2,0,2,66,0,0,2,2,2,2,2,66,0,0,65
90 REM DISP. LIST INTERRUPTS
100 DATA 72,173,200,2,69,79,37,78,141,10,212,141,24,208,173,7,6,69,79,37,78,141,23,208,169,50,141,0,2,169,6,141
110 DATA 1,2,104,64
120 DATA 72,173,0,6,69,79,37,78,141,10,212,141,22,208,173,1,6,69,79,37,78,141,23,208,173,2,6,69,79,37,78,141,24
130 DATA 208,173,3,6,69,79,37,78,141,25,208,169,106,141,0,2,169,6,141,1,2,104,64
140 DATA 72,173,200,2,69,79,37,78,141,10,212,141,24,208,173,7,6,69,79,37,78,141,23,208,169,142,141,0,2,169,6,141
150 DATA 1,2,104,64
160 DATA 72,173,4,6,69,79,37,78,141,10,212,141,22,208,173,5,6,69,79,37,78,141,23,208,173,6,6,69,79,37,78,141,24
170 DATA 208,169,188,141,0,2,169,6,141,1,2,104,64
180 DATA 72,173,200,2,69,79,37,78,141,10,212,141,24,208,169,224,141,9,212,173,7,6,69,79,37,78,141,23,208,104,64
190 REM V/B INTERRUPT
200 DATA 169,14,141,0,2,169,6,141,1,2,76,95,228
210 DATA 104,160,219,162,6,169,6,32,92,228,96
220 REM SCROLL SUBROUTINE
230 DATA 104,104,141,0,0,104,141,0,0,96
240 DATA GREY,GOLD,ORANGE,RED,PINK,VIOLET,PURPLE,BLUE,CYAN,LT BLUE,TURQUOISE
250 DATA BLUE-GRN,GREEN,YLLW-GRN,ORNG-GRN,LT ORANGE
260 DIM PM$(1024),SC$(700),C(12),CRS$(10),BLANK(10),A$(20),BLK$(10),ROUTINE$(10)
270 REM TITLE PAGE
280 POKE 106,PEEK(740)
290 GRAPHICS 0:SETCOLOR 3,5,6:SETCOLOR 0,14,10:POKE 710,0:POKE 752,1
300 X=PEEK(560)+PEEK(561)*256+9:POKE X,6:POKE X+1,6
310 POSITION 4,4:? "{inv}color palette{/inv} _____________"
320 POSITION 18,10:? "BY"
330 POSITION 13,12:? "JOHN W. FELTON"
340 REM INITIALIZE
350 RESTORE 100:FOR N=1550 TO 1778:READ A:POKE N,A:NEXT N
360 POSITION 11,20:? "(BACK IN A MOMENT)"
370 RESTORE 50:FOR N=1 TO 12:READ A:C(N)=A:NEXT N
380 RESTORE 60:FOR N=0 TO 7:READ A:POKE 1536+N,A:NEXT N
390 SC$(1)=" ":SC$(700)=SC$:SC$(2)=SC$
400 PMBASE=256*(PEEK(106)-8)
410 BSCH=INT(PMBASE/256-5):BSCL=0
420 FOR N=96 TO 208:POKE PMBASE+N,PEEK(57344+N):NEXT N
430 REM SET UP DISPLAY LIST
440 GRAPHICS 17:POKE 559,0
450 DL=PMBASE-256*6:SCRLOW=DL+22:SCRHIGH=DL+23
460 RESTORE 80:FOR N=0 TO 32:READ A:POKE DL+N,A:NEXT N
470 POKE SCRLOW,BSCL:POKE SCRHIGH,BSCH:POKE DL+33,PEEK(560):POKE DL+34,PEEK(561)
480 POKE DL+4,PEEK(88):POKE DL+5,PEEK(89):POKE 560,DL-INT(DL/256)*256:POKE 561,DL/256
490 N=PEEK(88)+PEEK(89)*256+400:HIGH=INT(N/256):LOW=N-HIGH*256:POKE DL+30,LOW:POKE DL+31,HIGH
500 POKE 512,14:POKE 513,6:POKE 54286,192:POKE 1543,10
510 REM INIT SCROLL SUBROUTINE
520 RESTORE 230:FOR N=1 TO 10:READ A:ROUTINE$(N,N)=CHR$(A):NEXT N
530 HIGH=INT(SCRLOW/256):LOW=SCRLOW-HIGH*256:ROUTINE$(8,8)=CHR$(LOW):ROUTINE$(9,9)=CHR$(HIGH)
540 HIGH=INT(SCRHIGH/256):LOW=SCRHIGH-HIGH*256:ROUTINE$(4,4)=CHR$(LOW):ROUTINE$(5,5)=CHR$(HIGH)
550 A=USR(1768)
560 REM SET UP P/M GRAPHICS
570 VVTP=PEEK(134)+PEEK(135)*256
580 STARP=PEEK(140)+PEEK(141)*256
590 OFFSET=PMBASE-STARP
600 HI=INT(OFFSET/256):LOW=OFFSET-HI*256
610 POKE VVTP+2,LOW:POKE VVTP+3,HI
620 PM$(512)="{CTRL-,}":PM$(640)=PM$(512):PM$(513)=PM$(512)
630 POKE 623,1:POKE 704,12:POKE 53256,1
640 POKE 54279,INT(PMBASE/256):POKE 53277,3:POKE 756,INT(PMBASE/256)
650 PM$(9,33)="UUUUUUUU{inv}********{/inv}{INS CHAR}{INS CHAR}{INS CHAR}{INS CHAR}{INS CHAR}{INS CHAR}{INS CHAR}{INS CHAR}"
660 REM DRAW SCREEN
670 TSCH=PEEK(89):TSCL=PEEK(88):POKE 89,BSCH:POKE 88,BSCL
680 POKE 87,0:POKE 752,1:POSITION 0,0:? SC$
690 RESTORE 240:FOR N=0 TO 15:READ A$:POSITION 1,N:? "{inv} {/inv} ";A$:POSITION 16-(N>9),N:? N:POSITION 39,N:? "{inv} {/inv}":NEXT N
700 POKE 88,TSCL:POKE 89,TSCH:POKE 87,0
710 FOR N=1 TO 31 STEP 10:COLOR 33+(N=11)+(N=21)*2+(N=31)*130:FOR M=0 TO 6 STEP 3
720 FOR I=0 TO 8:FOR J=0 TO 1:PLOT N+I,M+J-(M=6 AND N=31)*3:NEXT J:NEXT I
730 NEXT M:NEXT N
740 POKE 87,0:POKE 752,1
750 FOR C=1 TO 12:GOSUB 1280:NEXT C
760 POSITION 1,9:? #6;"{inv} HUE LUMINANCE {/inv}";
770 POSITION 1,10:? #6;"{inv} 0 2 4 6 8 10 12 14 {/inv}";
780 POKE 89,BSCH:POKE 88,BSCL
790 CRS$="{CTRL-,}{INS CHAR}{inv}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{/inv}{INS CHAR}{CTRL-,}"
800 BLK$="{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}"
810 POKE 559,46
820 LY=520:Y=1:X=1:GOTO 920
830 REM UPPER WINDOW ROUTINE
840 IF STRIG(0)=0 THEN 840
850 IF STRIG(0)=0 THEN GOSUB 1350:GOTO 980
860 FOR DELAY=1 TO 15:NEXT DELAY
870 GOSUB 1210
880 IF DX=0 AND DY=0 THEN 850
890 POKE 77,0
900 X=X+DX:Y=Y+DY
910 X=X-(X=5)*4+(X=0)*4:Y=Y-(Y=4)*3+(Y=0)*3
920 PM$(LY,LY+9)=BLK$
930 LY=Y*21+509
940 POKE 53248,X*40+22
950 PM$(LY,LY+9)=CRS$
960 GOTO 850
970 REM LOWER WINDOW ROUTINE
980 CLOC=1527+X+Y*4:CLOC=CLOC-(Y=1)*824:IF Y=3 AND X=4 THEN CLOC=712
990 C=X+(Y-1)*4:COLR=INT(C(C)/16):LUM=C(C)-(COLR)*16
1000 BSCRN=BSCL+BSCH*256
1010 SCLOC=BSCRN+(COLR>2 AND COLR<13)*(COLR-2)*40+(COLR>12)*400
1020 GOSUB 1240
1030 BX=LUM+19+(LUM>9)*(LUM-8)/2:BY=COLR:POSITION BX,BY:? "X":LBX=BX:LBY=BY
1040 IF STRIG(0)=0 THEN 980
1050 GOSUB 1210
1060 IF STRIG(0)=0 THEN POSITION BX,BY:? " ":GOSUB 1350:GOTO 840
1070 BX=BX+DX*2:BX=BX+(BX>27)*DX:BY=BY+DY
1080 IF BX=LBX AND BY=LBY THEN 1050
1090 POKE 77,0
1100 IF BX>37 OR BX<19 THEN BX=LBX:DX=0
1110 IF BY>15 OR BY<0 THEN BY=LBY:DY=0
1120 POSITION LBX,LBY:? " "
1130 IF BSCRN+BY*40<SCLOC THEN SCLOC=SCLOC-40:GOSUB 1240
1140 IF BSCRN+BY*40>SCLOC+200 THEN SCLOC=SCLOC+40:GOSUB 1240
1150 POSITION BX,BY:? "X":LBX=BX:LBY=BY
1160 LUM=LUM+DX*2:CC=LUM+16*BY:POKE CLOC,CC:C(C)=CC:GOSUB 1260
1170 POKE 88,TSCL:POKE 89,TSCH:GOSUB 1300
1180 POKE 88,BSCL:POKE 89,BSCH
1190 GOTO 1050
1200 REM READ JOYSTICK SUB
1210 S=STICK(0):DX=(S>4 AND S<8)-(S>8 AND S<12):DY=(S=5 OR S=9 OR S=13)-(S=6 OR S=10 OR S=14)
1220 POKE 16,112:POKE 53774,112:RETURN
1230 REM SCROLL SUB
1240 A=USR(ADR(ROUTINE$),SCLOC):RETURN
1250 REM SET TEXT COLOR SUB
1260 A=PEEK(712)-INT(PEEK(712)/16)*16:POKE 1543,10-(A>9)*2:RETURN
1270 REM WRITE HUE/LUM SUB
1280 BY=INT(C(C)/16):LUM=C(C)-BY*16
1290 Y=1+(C>4)+(C>8):X=C-INT((C-1)/4)*4
1300 POSITION X*10-9-(BY>9),Y*3-1:? " ";BY;",";
1310 POSITION X*10-6,Y*3-1:? LUM;" ";
1320 POSITION X*10-3,Y*3-1:IF C(C)<99 THEN ? " ";:IF C(C)<10 THEN ? " ";
1330 ? C(C):RETURN
1340 REM BEEP SUB
1350 SOUND 0,50,14,6:FOR N=0 TO 10:NEXT N:SOUND 0,0,0,0:RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: PALETTE.BAS.
Credits
- Program listing: Color Palette — program listing (Antic, June 1985 (Vol. 4, No. 2)) — John W. Felton
- Picture: Twelve patches compared side by side, more than the Atari's five colour registers normally allow. — John W. Felton (program); screenshot by the site
- Antic, June 1985 - Vol. 4 No. 2: scan of the printed magazine, PDF page 21 (article) — Internet Archive, 1985
- Antic disk, June 1985 - Vol. 4 No. 2: PALETTE.BAS (detokenized listing) — John W. Felton, 1985
