Pencils
- Type
- Graphics
- Category
- Scan-line colour kernel demo
- Author
- Gregg Tavares
- Published in
- Antic disk, June 1985 (Vol. 4, No. 2)
- Year
- 1985
- Language
- Atari BASIC (with a 51-byte machine-language routine)
- Requirements
- Atari BASIC; no joystick. Press RESET to stop it.
About the program
Pencils came on the Antic disk for June 1985, the magazine's computer-art issue. It is listed simply as a graphics demo by Gregg Tavares, and it had no article. It doesn't appear in the printed listings either, so it seems to have been a disk-only bonus. What it does is simple and striking. It draws a box of twelve coloured pencils, each in its own hue, shaded from light to dark to look round, with sharpened wooden tips and metal-banded erasers. The Atari normally offers four playfield colours plus a background, but this picture uses dozens of distinct colours at once.
Everything below comes from reading and running the program itself.
Typing it in
The listing is plain Atari BASIC with no special characters. Lines 890–900 hold the machine-language routine as DATA. Check those numbers with special care, because the routine takes over the computer and a mistake will lock it up. SAVE before you RUN.
How to use it
RUN it. The picture appears after a few seconds and stays on screen. The machine-language routine never returns to BASIC, so press RESET to get the computer back. The BREAK key won't work.
How it works
- The picture is simple. The pencil bodies are just solid stripes of colour 1 in GRAPHICS 3 (
GRAPHICS 19, lines 160–190). The tips, points, bands and erasers are the four players, each a 16-line shape repeated twelve times down the screen (lines 130–140, DATA 230–380). - The colour comes from a kernel. The routine POKEd into page 6 (lines 740–900) waits until the ANTIC line counter VCOUNT (54283) matches the value in location 204 (set to 15). For each of the next 192 scan lines it then reads one byte from each of five tables and writes them, synchronised with WSYNC, into the playfield colour and all four player colour registers. Lines 780–870 patch the routine's store addresses to choose those registers. The routine then jumps back and waits for the next frame, for ever.
- The tables. The subroutine at 390 fills five 256-byte tables just below the lowered RAMTOP (located in lines 680–720). For each 16-line pencil the hue is the same and the luminance rises and falls symmetrically (lines 420–430), which is what makes the bodies look cylindrical. The wood, graphite and eraser shadings come from DATA 510–670.
The technique, a routine that changes colours on every scan line in step with the TV beam, was usually done with display list interrupts. Doing it in a loop that never stops gives the most colours possible, but it leaves no time for anything else to run.
Variations to try
Change the hue formula (INT(I/16)+1)*16 in lines 420–430 to give different pencil colours, or change the POKE 204,15 in line 200 to move the colours up or down relative to the shapes.
Listing
10 REM PENCILS
20 REM BY GREGG TAVARES
30 REM (c) 1985, ANTIC PUBLISHING
40 POKE 106,PEEK(740):GRAPHICS 8:GOSUB 740
50 PMBASE=PEEK(740)-8:POKE 106,PMBASE-8
60 ST=PEEK(106)*256:GOSUB 680
70 GRAPHICS 19:SETCOLOR 4,0,10:POKE 559,62
80 POKE 54279,PMBASE:PM=PMBASE*256+1024+32:FOR I=0 TO 150:POKE PM+I-33,0:NEXT I
90 POKE 623,1:POKE 53277,3
100 POKE 53248,40:POKE 53249,40+12:POKE 53250,185:POKE 53251,185+5
110 POKE 53256,1:POKE 53257,1
120 POKE 704,4:POKE 705,250:POKE 706,6:POKE 707,36
130 FOR J=0 TO 11:RESTORE 230:FOR I=0 TO 15:READ B1,B2,B3,B4:POKE PM+J*16+I,B1:POKE PM+256+J*16+I,B2
140 POKE PM+J*16+I+512,B3:POKE PM+J*16+I+768,B4:NEXT I:NEXT J
150 GOSUB 390
160 FOR I=0 TO 23
170 COLOR 1
180 PLOT 5,I:DRAWTO 35,I
190 NEXT I
200 POKE 204,15
210 X=USR(1536)
220 IF PEEK(53279)=7 THEN 220
230 DATA 0,0,0,0
240 DATA 0,1,231,30
250 DATA 0,3,231,31
260 DATA 0,7,231,31
270 DATA 0,15,231,31
280 DATA 0,31,231,31
290 DATA 0,63,231,31
300 DATA 1,63,231,31
310 DATA 3,63,231,31
320 DATA 1,63,231,31
330 DATA 0,63,231,31
340 DATA 0,31,231,31
350 DATA 0,15,231,31
360 DATA 0,7,231,31
370 DATA 0,3,231,31
380 DATA 0,1,231,30
390 X=0:FOR I=0 TO 191 STEP 16
400 RESTORE 510
410 FOR J=0 TO 15
420 POKE ST+I+INT(J/2)+1,(INT(I/16)+1)*16+J
430 POKE ST+I+(15-INT(J/2))+1,(INT(I/16)+1)*16+J
440 READ B1,B2,B3,B4
450 POKE ST+I+J+513,B1
460 POKE ST+I+J+257,B2+16
470 POKE ST+I+J+769,B4+48
480 POKE ST+I+J+1025,B3
490 NEXT J:POKE ST+I+1,10
500 NEXT I:RETURN
510 DATA 0,0,0,0
520 DATA 0,0,0,0
530 DATA 2,2,0,2
540 DATA 4,4,0,4
550 DATA 6,6,0,6
560 DATA 8,8,0,8
570 DATA 10,10,4,10
580 DATA 10,12,6,10
590 DATA 10,12,4,10
600 DATA 10,12,0,10
610 DATA 10,10,0,10
620 DATA 8,8,0,8
630 DATA 6,6,0,6
640 DATA 4,4,0,4
650 DATA 2,2,0,2
660 DATA 0,0,0,0
670 DATA 0,0,0,0
680 POKE 1547,0:POKE 1548,ST/256
690 POKE 1550,0:POKE 1551,ST/256+1
700 POKE 1562,0:POKE 1563,ST/256+2
710 POKE 1568,0:POKE 1569,ST/256+3
720 POKE 1574,0:POKE 1575,ST/256+4
730 RETURN
740 RESTORE 890
750 FOR I=1 TO 51:READ B
760 POKE 1535+I,B
770 NEXT I
780 POKE 6*256+16+7,16+3
790 POKE 6*256+16+8,13*16
800 POKE 6*256+16+13,16+4
810 POKE 6*256+16+14,13*16
820 POKE 6*256+32+3,16+5
830 POKE 6*256+32+4,13*16
840 POKE 6*256+32+9,16+2
850 POKE 6*256+32+10,13*16
860 POKE 6*256+16+4,16+6
870 POKE 6*256+16+5,13*16
880 RETURN
890 DATA 104,165,204,205,11,212,208,251,162,0,189,0,33,188,0,32,141,10,212,141,26,208,140,19,208
900 DATA 189,0,31,141,18,208,189,0,34,141,20,208,189,0,35,141,21,208,232,224,192,208,218,76,1,6
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: PENCILS.BAS.
Credits
- Program listing: Pencils — program listing (Antic disk, June 1985 (Vol. 4, No. 2)) — Gregg Tavares
- Picture: Pencils: 12 hues, each shaded through several luminances, on a screen that normally allows five colours. — Gregg Tavares (program); screenshot by the site
- Antic disk, June 1985 - Vol. 4 No. 2: PENCILS.BAS (detokenized listing) — Gregg Tavares, 1985
