If all the talk of display lists in the last few installments is getting you down, take a break as we explore the colorful world of GTIA. If you own an Atari® 400/800 bearing a shipping label dated January, 1981, or later, or an Atari 1200, congratulations! You have a GTIA computer; skip the next paragraph. If you're still not sure whether you have CTIA or GTIA, from GRAPHICS 0 try POKEing memory location 623 decimal with 64 decimal and type some characters on the screen. If the text looks like normal ATASCII characters, you have CTIA. Otherwise, the screen will be an interesting blur of graphics blocks that vaguely resemble AT ASCII characters. This is caused by GTIA.
To upgrade to GTIA, you must spend a little money, and part with your Atari for a week or two. All Atari Service Centers perform GTIA upgrades. To locate the center nearest you, call the following toll free number provided by Atari, Inc.: 1-800-538-8543. Then, call ahead and make arrangements to have your computer upgraded, or buy the GTIA chip and install it yourself. The chip costs about $22.50. If the service center installs it, you can expect to pay an additional $60.00. The extra cost includes a thorough check-out of your computer, so it may be a worthwhile expense if your Atari needs a "tune-up." Note that this price is a general figure; actual prices may vary from center to center. You may be interested to know that SoltSide is planning to follow the GTIA trend. Within the next year, we hope to convert our Atari support to GTIA computers only.
Many mysteries enshroud the GTIA chip. The GTIA adds three totally new graphics modes to any Atari 400/800 computer, and also affects the old graphics modes. Right now, let's get some general concepts down.
When we talk about color on the Atari, we are actually talking about three distinctly different things. To make sure we understand each other, I will explain each type.
Each new mode consists of a graphics screen with a resolution of 80 vertical by 192 horizontal blocks. This creates a Y coordinate range that allows you to plot color graphics on every scan line of the television display.
Although the width of a graphics dot in the new GTIA modes is several times longer than a GRAPHICS 8 dot, it is still only half the width of a GRAPHICS 0 text character. Add the multicolor capabilities to this and you can create some truly stunning displays.
The Operating System (OS) treats each of the new GTIA modes as a modified GRAPHICS 24 screen. GRAPHICS 24 is a full screen (no text window) GRAPHICS 8. The same data can be displayed in modes 8, 9, 10, or 11. The only differences are a smaller upper-limit for the X coordinate, and that none of the new GTIA modes have provisions for a text window. However, the similarities, when combined with the magic of Machine Language, overcome the few GTIA limitations. We'll find out more about this in the next installment. Right now, let's learn more about each new mode.
The first new GTIA mode is GRAPHICS 9, which is excellent for creating images of startling depth. It allows sixteen different luminances for any single hue. Yes, I said sixteen! Those not easily impressed may say: "So what? If I use CTIA in GRAPHICS 8 along with Display List Interrupts (DLIs), I can do the same thing." This is true, but CTIA supports only eight luminances for any given hue. Even though the SETCOLOR statement allows a value of 0 through 15 for luminances, the first bit is ignored by ANTIC. This means that every other luminance value (i .e. an odd numbered luminance) is treated as one value less. This results in eight different luminances of sixteen hues, or 128 colors. GTIA graphics mode 9 allows sixteen luminances. With GRAPHICS 9 and DLIs, the Atari can support a grand total of 256 distinct colors, more than any CTIA computer could ever display. In fact, it's more than any other personal computer I know of! There is only one minor restriction; you can only have one hue on anyone scan line of the display.
From normal BASIC operation, GRAPHICS 9 allows sixteen luminances of anyone hue for all scan lines of the display. The background/border color is always the lowest luminance level of the selected main hue.
To use these new colors, we must set the base hue for GRAPHICS 9. This is done by setting color register 4 to the desired hue. From BASIC, this is as easy as SETCOLOR 4,n,0: where "n" equals the base hue number. Since color register 4 is located at RAM location 712 decimal, we could also POKE the hue value there.
You'll get greater benefit from using POKEs instead of SETCOLORs for hue/luminance values because all numeric constants in Atari BASIC require six bytes of storage in RAM. The SETCOLOR statement takes three values, and each must be calculated. The POKE uses only two, and is therefore faster. If you use constants, SETCOLOR takes eighteen bytes of memory for them, but POKE only uses twelve bytes. The color register location holds the value computed by the formula: hue number multiplied by sixteen plus the luminance value. For example: hue 10, luminance 4 = (10 * 16) + 4 or 164. The POKE method also speeds up the calculation of this value from BASIC.
Since the hue of location 712 is the only value required for GRAPHICS 9, we must POKE 712 with the hue number multiplied by sixteen. This takes care of the base hue. The COLOR statement sets the different luminances. The value specified in a COLOR statement determines the luminance in which to PLOT. Luminances of 0 through 15 correspond to the statements COLOR 0 through COLOR 15. All graphics commands work in the normal manner.
GRAPHICS 11 allows one luminance in sixteen different hues. From normal BASIC operation, you can display up to sixteen different hues on each scan line of the screen. The background/border color is pure black, and cannot be changed. The luminance for all other colors is derived from the luminance value in color register 4. From BASIC, you can set the luminance with SETCOLOR 4,0,n or POKE 712,n: where "n" equals a luminance value from 0 to 15. Note, however, that in this mode, you can choose from only eight luminance levels.
This mode, when linked with DLIs, gives 128 different colors; up to sixteen hues in one luminance per scan line. Not bad at all! GRAPHICS 11 works like GRAPHICS 9. After setting the base luminance, select hues 0 through 15 with the statements COLOR 0 through COLOR 15.
I've intentionally left the explanation of GRAPHICS 10 for last. It is the most impressive GTIA mode of all, and the hardest to understand and use.
GRAPHICS 10 allows you to create graphic masterpieces with eight main colors and one background/border color. How can this compare to modes offering sixteen hues or luminances? You can select GRAPHICS 10 colors from any hue and luminance combination. You can, with no internal trickery, display nine out of 128 possible colors on the display.
In GRAPHICS 9 and 11, you would never see a brown color (hue 15, luminance 2) next to a bright orange color (hue 2, luminance 10) on the same scan line of the display. You could have a different luminance or a different hue, but never a different luminance and hue. When using DLIs, GRAPHICS 9 can display 256 colors - sixteen different luminances of one hue per scan line, and GRAPHICS 11 can display 128 colors - sixteen different hues of one luminance per scan line. GRAPHICS 10 can display 128 colors - nine different colors per scan line! This is what makes GTIA so powerful.
Using GRAPHICS 10 from BASIC is a little tricky. The SETCOLOR command only works for color registers 0 through 4: To set up the other registers involved in GRAPHICS 10, you must POKE the colors into place. It's now obvious why I explained the use of POKE in place of SETCOLOR.
|Memory Location||COLOR#||SETCOLOR#||Default Color|
|704 (02C0 hex)||COLOR 0||n/a||0 (00 hex)|
|705 (02C1 hex)||COLOR 1||n/a||0 (00 hex)|
|706 (02C2 hex)||COLOR 2||n/a||0 (00 hex)|
|707 (02C3 hex)||COLOR 3||n/a||0 (00 hex)|
|708 (02C4 hex)||COLOR 4||0||40 (28 hex)|
|709 (02C5 hex)||COLOR 5||1||202 (CA hex)|
|710 (02C6 hex)||COLOR 6||2||148 (94 hex)|
|711 (02C7 hex)||COLOR 7||3||70 (46 hex)|
|712 (02C8 hex)||COLOR 8||4||0 (00 hex)|
The GRAPHICS 10 memory locations are shown in Figure 1. For determined purists, those registers that can be modified with SETCOLOR are shown as well. The background/border color is at location 704 decimal. Its color is selected from BASIC with a COLOR 0 statement. All colors are selected with COLOR 0 through COLOR 8. Refer to Figure 1 for memory locations corresponding to a particular COLOR statement. All other graphics commands work in the normal-manner.
The Atari's ability to change the color of graphics blocks already drawn on the display is noteworthy. This technique is known as "Graphics Indirection." In GRAPHICS 9, changing the hue of location 712 decimal causes all graphics blocks to change their base hue while maintaining their luminance level. In GRAPHICS 11, changing the luminance in location 712 decimal causes all of the graphics blocks to change their luminance while staying the same hue.
In GRAPHICS 10, however, we have nine different registers to modify. The possibilities available here are very numerous. Consider an arcade game like Centipede. The graphics blocks always follow the same rules for movement. In fact, the animation is done with the same graphics characters on every rack. The only difference between racks, other than the increasing level of difficulty, is the value of the color register associated with each type of graphics block. This technique is impressive when used in Atari BASIC programs as well, and is only one of many capabilities built into the Atari. When these abilities are teamed with GTIA, look out.
Now that you know GTIA's advantages, let's review its disadvantages. GTIA displays all colors differently, i.e. CTIA colors look different on GTIA. You need to modify CTIA programs to make the colors look the same. Most new Atari programs with extensive color provide corrections for CTIA owners.
Sometimes, however, you can't modify the program satisfactorily. Take GRAPHICS 8 for instance. When you draw with COLOR 1, you get white. But, by plotting every other dot (only on even or odd X coordinates) you can trick the Atari hardware into displaying two more colors through a technique known as artifacting. (For a further explanation of artifacting, see Appendix IV of De Re Atari, Television Artifacts .) This method was used to get the high resolution color display for the program Solitaire. Solitaire was written on a CTIA machine before GTIA was common. The result: instead of red hearts and diamonds, and black clubs and spades, GTIA shows green hearts and diamonds, and blue clubs and spades.
In this instance, no other color combination or plot position renders a red and black combination, or anything close to red and black. To give a much sharper text display, Atari chose to use different primary colors in the text. The color red is now impossible to artifact. The only possible colors to artifact are blue and green. Some people kiddingly call the GTIA chip the Green Television Interface Adapter because of this effect.
What is the result? Even though GTIA makes Solitaire unsightly, it is an isolated case. GTIA's new color graphics modes compensate for the few incompatabilities. There really isn't any great need for the artifacting technique. GTIA promises even more graphically exciting games and simulations than CTIA. Take a look at the photographs at the beginning of this article, produced with GTIA. Think of the possibilities!
Turn your attention now to Program Listings 1, 2, and 3, a collection of GTIA demos. Each displays one of the GTIA's hidden abilities and warrants some explanation.
To use the demos, type them in, one at a time, SAVE them and type RUN. Each demo consists of a number of smaller demos, and repeatedly pressing any of the console keys sends you to the next one.
Program Listing 1 is a computer-controlled, quad-drawing program. It uses GRAPHICS 11 for a total of sixteen hues on the display at one time. When you have seen enough of one drawing, press any console key to display a new one. To exit the program, use BREAK.
10 GRAPHICS 11:POKE 712,6:CLR 20 XM=(RND(0)*39)+40:X=1 30 YM=(RND(0)*95)+96:Y=1 40 XI=RND(0)+0.2:YI=RND(0)+0.55 50 COLOR INT(RND(0)*9)+1 60 PLOT X,Y 70 PLOT 79-X,Y 80 PLOT X,191-Y 90 PLOT 79-X,191-Y 100 X=ABS(X+XI):Y=ABS(Y+YI) 110 IF X+XI>XM-1 THEN XI=-XI:GOTO 50 120 IF Y+YI>YM-I THEN YI=-YI:GOTO 50 130 IF X+XI<1 THEN XI=-XI:GOTO 50 140 IF Y+YI<1 THEN YI=-YI:GOTO 50 150 IF PEEK(53279)<>7 THEN RUN 160 GOTO 60
Among other things, Program Listing 2 demonstrates the technique of color indirection with GRAPHICS 10. All of the colors are selected and placed in memory locations 704 through 712 decimal, and then shifted by one. By this, I mean that location 705 is POKEd with the value of 704, and so on, up to location 712, which is brought back around to location 704. This causes all of the colors to rotate, simulating motion on the screen. To step through the demos, press any console key. This program contains many demos, so just keep watching.
10 CLR:GRAPHICS 9 20 FOR X=0 TO 69 STEP 10 30 C=0:COLOR 0 40 FOR Y=90 TO 189 STEP 3 50 PLOT X,Y:DRAWTO X+10,200-Y 55 C=C+0.42:IF C>15 THEN C=0 56 COLOR C 60 NEXT Y:NEXT X:C=0 70 GOSUB 145:C=C+1:POKE 712,C*16 80 IF C<15 THEN 70 100 CLR:GRAPHICS 9:Y=0 110 Y=Y+1:COLOR 15-INT(Y/12) 120 PLOT 0,Y:DRAWTO 79,Y 130 IF Y<191 THEN 110 140 C=0:GOTO 160 145 P=PEEK(53279):IF P=7 THEN 145 150 P=PEEK(53279):IF P=7 THEN RETURN 155 POKE 53279,0:GOTO 150 160 GOSUB 145:C=C+1:POKE 712,C*16 170 IF C<15 THEN 160 200 GRAPHICS 10:FOR X=4 TO 11:POKE X+701,X*16+6:NEXT X:CLR 210 COLOR 1 220 FOR X=0 TO 69 STEP 10:C=1 230 FOR Y=80 TO 190 STEP 3 240 PLOT X, Y:DRAWTO X+10,200-Y 250 C=C+0.16:IF C>7 THEN C=1 260 COLOR C 270 NEXT Y:NEXT X 280 A=PEEK(705):FOR X=706 TO 712:POKE X-1,PEEK(X):NEXT X:POKE 712,A:IF PEEK(53279)=7 THEN 280 300 GRAPHICS 11:CLR :POKE 712,4 305 X=-1 310 X=X+1:COLOR INT(X/5) 315 IF X/5=INT(X/5) THEN COLOR 0 320 PLOT X,0:DRAWTO X,191 330 IF X<79 THEN 310 340 IF PEEK(53279)=7 THEN 340 400 GRAPHICS 11:CLR :POKE 712,2 405 Y=-1 410 Y=Y+1:COLOR INT(Y/12) 415 IF Y/12=INT(Y/12) THEN COLOR 0 420 PLOT 0,Y:DRAWTO 79,Y 430 IF Y<191 THEN 410 440 IF PEEK(53279)=7 THEN 440
Program Listing 3 demonstrates another hidden feature of GTIA. Since each horizontal line has a resolution of one physical scan line on the display, you can use this to create more than 256 colors directly from BASIC without DLIs! The method used is a technique I call color interlacing. By plotting a block of one color directly above or below a block of another color, the two colors seem to blend because of the way the human eye interprets color. The result is a graphics block of slightly less resolution (effectively a display of 80 by 96) but of a color normally unavailable on the Atari. I call Program Listing 3 Painter because it demonstrates how two primary colors of the same luminance can be interlaced to produce a totally different color. When using Painter, you can select new colors by pressing any console key, or pressing BREAK to exit.
10 GRAPHICS 11 20 POKE 712,2 30 P=INT(RND(0)*16):S=INT(RND(0)*16) 40 IF P=S OR P=0 OR S=0 THEN 30 50 FOR Y=0 TO 100 STEP 2 60 COLOR P:PLOT 5,Y:DRAWTO 43,Y 70 PLOT 55,Y/2:DRAWTO 75,Y/2 80 COLOR S:PLOT 12,Y+1:DRAWTO 50,Y+l 90 PLOT 55,Y/2+53:DRAWTO 75,Y/2+53 100 NEXT Y 200 IF PEEK(53279)=7 THEN 200 210 RUN
While this program is written in GRAPHICS 11, color interlacing is most effective in GRAPHICS 10 where you can mix the hues as well as their luminances. A clever Atari programmer can create graphic displays on a screen with 80 by 96 resolution in literally thousands of new and different colors! The possibilities are endless.
The program Doodle, by Scott Berfield, allows you to paint on the screen in any of the new GTIA graphics modes. You can choose from two brush sizes, and select the bank of colors to use. You will discover GTIA's versatility as you experiment with Doodle. Play with it awhile, and you're sure to come up with ideas for writing your own GTIA programs.
You may have noticed how often I mentioned DLIs in this column. I said some pretty astonishing things like "128 colors" and "256 colors." In the next installment, I will prove my statements with graphic examples, as the ominous subject of Display List Interrupts rears it's ugly head for the last time. GTIA presents some drawbacks and advantages to the Machine Languages programmer. To ANTIC, GTIA is literally not what it seems. In any case, you will be amazed at your Atari's capabilities when we discover GTIA Part II: The Interrupted Color. Also in the near future, by popular request, we'll have a tutorial on screen scrolling/mapping techniques, and, later, an entire Frontier series on Player/Missile Graphics. Until next time; sit back, relax, write a letter with suggestions, comments, or just plain questions; and above all, explore your Atari's frontier!
SS SS SS SS SS SS SS SS SS SS SS SS SS SS Atari BASIC SS SS "Doodle" SS SS Program by: Scott Berfield SS SS SS SS Copyright (c) 1983 SS SS SoftSide Publications, Inc SS SS SS SS SS SS SS SS SS SS SS SS SS SS 10 GRAPHICS 0:POKE 752,1:?:GOTO 270 20 Z=PEEK(704):POKE 77,0:IF Z<>255 THEN POKE 764,255:GOSUB 90 30 IF STRIG(0)=0 THEN 200 40 XP=XP+XD(STICK(0)):YP=YP+YD(STICK(0)):IF XP<0 THEN XP=79 50 IF XP>79 THEN XP=0 60 IF YP>160 THEN YP=0 70 IF YP<0 THEN YP=160 80 COLOR ABS(C-CMAX):PLOT XP, YP:COLOR C:PLOT XP,YP:GOTO 20 90 IF Z=6 THEN 140 100 IF Z=35 THEN GRAPHICS 0:B=BMIN:C=CMIN:GOTO 330 110 OB=B:OB1=B+1:OC=C:B=B+2:C=C+1:IF C>CMAX THEN C=CMIN 120 IF B>BMAX THEN B=BMIN 130 GOTO 160 140 OB=B:OB1=B+1:OC=C:B=B-2:C=C-1:IF C<CMIN THEN C=CMAX 150 IF B<BMIN THEN B=BMAX 160 COLOR OC:PLOT BAR(OB),183:DRAWTO BAR(OB1),183 170 IF C<INT(0.5*CMAX) THEN COLOR CMAX 180 IF C>=INT(0.5*CMAX) THEN COLOR CMIN 190 PLOT BAR(B),183:DRAWTO BAR(B+1),183:COLOR C:RETURN 200 IF STRIG(0) THEN 20 210 XP=XP+XD(STICK(0)):YP=YP+YD(STICK(0)):IF XP>78 THEN XP=1 220 IF XP<1 THEN XP=78 230 IF YP<1 THEN YP=159 240 IF YP>159 THEN YP=1 250 PLOT XP-1,YP-1:DRAWTO XP+1,YP-1:PLOT XP+1,YP:DRAWTO XP-1,YP:PLOT XP-1,YP+1:DRAWTO XP+1,YP+1 260 GOTO 200 270 DIM XD(15),YD(15),BAR(32),C(8) 280 CMIN=0:FOR I=1 TO 15:READ N:XD(I)=N:READ N:YD(I)=N:NEXT I 290 DATA 0,0,0,0,0,0,0,0,1,1,1,-1,1,0,0,0,-1,1,-1,-1,-1,0,0,0,0,1,0,-1,0,0 300 FOR Q=1 TO 32:READ L:BAR(Q)=L:NEXT Q 310 DATA 8,11,12,15,16,19,20,23,24,27,28,31,32,35,36,39,40,43,44,47,48,51,52,55,56,59,60,63,64,67,68,71 320 ? CHR$(125);"INSTRUCTIONS?":OPEN #1,4,0,"K:":GET #1,A:CLOSE #1:IF A=89 THEN 600 330 GRAPHICS 0:? CHR$(125);"ENTER GRAPHICS MODE(9,10,11)';:INPUT M 340 IF M=11 THEN ? "WHAT LUMINANCE";:INPUT L:BMIN=1:BMAX=31:CMAX=15:GRAPHICS M:SETCOLOR 4,0,L:B=BMIN:GOTO 390 350 IF M=9 THEN ? "WHAT BACKGROUND COLOR";:INPUT BC:BMIN=1:BMAX=31:CMAX=15:GRAPHICS M:SETCOLOR 4,BC,0:B=1:GOTO 390 360 GRAPHICS 0:? "GRAPHICS 10 ALLOWS YOU TO USE ANY": ? "9 OF THE 128 POSSIBLE ATARI COLORS." 365 ? "THE BACKGROUND IS SET BY THE FIRST ":? "COLOR YOU CHOOSE." 370 FOR Q=0 TO 8 372 POSITION 2,15:? CHR$(156);CHR$(156);CHR$(156); "COLOR #";Q;" HUE,LUMINANCE";:INPUT H,L 374 IF H<0 OR L<0 OR H>15 OR L>15 THEN 372 376 C(Q)=H*16+L:NEXT Q 380 BMIN=9:BMAX=25:CMAX=8:GRAPHICS 10:FOR Q=704 TO 712:POKE Q,C(Q-704):NEXT Q:B=BMIN 390 C=CMIN:COLOR C:FOR I=BAR(BMIN) TO BAR(BMAX) STEP 4: FOR J=0 TO 3: PLOT I+J,168:DRAWTO I+J,183:NEXT J 400 C=C+1:COLOR C:NEXT I:C=CMIN 410 COLOR C:XP=39:YP=95:PLOT XP,YP:COLOR ABS(C-CMAX):PLOT BAR(BMIN),183:DRAWTO BAR(BMIN+1),183:GOTO 20 600 ? CHR$(125);" WHEN THEN SCREEN IS SET UP YOU":? "WILL SEE A PALETTE BAR AT THE BOTTOM" 610 ? "WITH A BLINKING DOT IN THE MIDDLE OF":? "THE SCREEN.":? 615 ? " TO CHOOSE A COLOR PRESS THE LEFT":? "OR RIGHT ARROW KEYS UNTIL THE MARKER" 620 ? "IS BENEATH THE COLOR YOU WANT. THE":? "CURSOR WILL THEN CHANGE TO THE COLOR": ? "OF YOUR CHOICE." 630 ? :? " TO DRAW, JUST PICK THE COLOR YOU":? "WANT AND MOVE THE JOYSTICK. TO DRAW" 640 ? "WITH A THICKER LINE, HOLD DOWN THE":? "TRIGGER WHILE MOVING THE JOYSTICK." 650 ? :? " IF YOU WANT TO START OVER, JUST":? "PRESS 'N' AT ANY TIME." 660 POSITION 9,21:? "PRESS RETURN TO START" 670 OPEN #1,4,0,"K:":GET #1,R:CLOSE #1:GOTO 330