APPENDIX FOUR

GTIA GRAPHICS MODES NINE, TEN, AND ELEVEN

First of all, I'm going to assume that you've already read the information about GTIA at location GPRIOR (623) and at the GTIA chip (53248). If you haven't, then do so now.

Do I have a GTIA?

All of you should now know what a GTIA chip is, so let's try and figure out a way to tell if your Atari has one. Try the following:

POKE 623,64

If the screen goes black, then you have a GTIA. If it doesn't, well then you have a CTIA. Real simple test, right? But what happens if you're writing a program that has to know whether or not it's running on a GTIA. You can't use the preceding method unless your program asks the user whether the screen went black or not. This is not a good idea. Instead, the program needs a way of finding out what's there itself. How? In graphics modes nine and eleven, the computer can't detect collisions between players/missiles and playfield. What we do then, is set up a collision and see whether or not it was detected. If it was, then we know that there is a CTIA chip, otherwise there is a GTIA. The following program will do the trick:

100 GRAPHICS 9:POKE 710,0
120 POKE 53248,45
130 POKE 53261,255
140 POKE 53278,0
150 COLOR 1:PLOT 0,0
160 TI=PEEK(20)
170 IF TI=255 THEN TI=-1
180 IF PEEK(20)<TI+1 THEN 180
190 POKE 53248,0:COLID=PEEK(53252)
200 GRAPHICS 0
210 IF COLID=0 THEN PRINT "GTIA":END
220 PRINT "CTIA"

So you can understand a little better what's going on here, let's substitute the location names for the addresses:

100 GRAPHICS 9:POKE COLOR2,0
120 POKE HPOSP0,45
130 POKE GRAFP0,255
140 POKE HITCLR,0
150 COLOR 1:PLOT 0,0
160 TI = PEEK(RTCLOK+2)
170 IF PEEK(RTCLOK+2)<TI+1 THEN 170
180 POKE HPOSP0,0:COLID=PEEK(P0PF)
190 GRAPHICS 0
200 IF COLID=0 THEN PRINT "GTIA":END
210 PRINT "CTIA":END

What does GTIA have to offer me?

OK, so now we know whether or not we have a GTIA. Assuming we do have one, what can we do with it? Well, GTIA gives us three extra graphics modes which we can use to get many more colors on the screen than usual. Graphics mode nine lets you put all 16 brightnesses of one color on the screen at the same time. Graphics mode ten lets you have 9 colors on the screen at the same time (you pick the brightness for each). Finally, graphics mode eleven lets you put 16 colors at the same brightness on the screen at the same time. Now at this point you may be wondering if there are any strings attached to these great new graphics capabilities. Yes! Each mode takes the same amount of memory as graphics mode eight (a little less than 8K), and each pixel is four times as wide as those in graphics mode eight. That means the screen is 80 pixels wide and 192 high. Why four times as wide? Each pixel in graphics mode eight is only one bit wide, since it can only be on or off. In these new modes, however, a pixel can have up to 16 different values depending on what color it is (in case you hadn't guessed, the value of a pixel determines what color it is). You need four bits to get 16 values, so each pixel has to be four bits wide. In graphics mode ten, even though there are only 9 colors, four bits are still needed since three bits would only give you eight values. In this mode, the extra seven values just pick the same colors as the first nine. By the way, if you try to use a GTIA program on a CTIA machine, it will run fine as long as it doesn't use the GTIA modes (with the exception of the artifacting problem). If it uses the GTIA modes, then it will still run, but the graphics will look funny.

How do I use these extra modes?

All of these modes can be set up just the same as the other nine. For example, graphics nine, graphics ten, and graphics eleven all work from BASIC. Note that you can't have a text window in these modes. If you set up your own display list with machine language, you need to set GPRIOR according to the mode you want to use. Also, if you are going to be using the OS PLOT and DRAW routines, make sure you set DINDEX to the correct mode number. Incidentally, as you probably guessed, all three modes have the same screen memory requirements as graphics mode eight.

Now that you've got the mode set up and ready to go, how do you use it? Each one is a little different in this respect, so let's look at each separately:

Graphics Nine

As mentioned before, graphics nine gives you one color with 16 brightnesses. The background color register is used to tell GTIA what color you want to use. From BASIC, you just do the following:

SETCOLOR 4,color,0

Or this, which is more pertinent for machine language programmers:

POKE 712,color*16

To pick the brightness, use the COLOR command before you PLOT or DRAWTO. For example,

COLOR brightness

"Brightness" can be any value from 0 to 15, with 15 being the brightest. From machine language, store the brightness value directly into the pixel in screen memory. If you're using the PLOT and DRAW routines, store it in ATACHR (763).

The following BASIC program will set up a graphics mode nine screen and put all 16 brightnesses on it:

100 GRAPHICS 9
110 SETCOLOR 4,6,0
120 FOR C=0 TO 15
130 COLOR C
140 FOR ROW=88 TO 103
150 PLOT C*4+ROW-88,ROW
160 DRAWTO C*4+ROW-85,ROW
170 NEXT ROW
180 NEXT C
190 GOTO 190

Line 190 is necessary because we don't have a text window on the screen. Take it out and see what happens.

Graphics Ten

Graphics mode ten only lets you have nine different colors at the same time, but you can have different color and brightness values for each. It uses the regular playfield color registers along with the player/missile color registers to specify these colors. Just POKE the color and brightness values into these registers and you can then use the COLOR command to pick the one you want to use (or POKE the COLOR value directly into screen memory). Figure 58 shows you which COLOR value picks which register.

 COLOR REGISTER LOCATION 0 PCOLR0 704 1 PCOLR1 705 2 PCOLR2 706 3 PCOLR3 707 4 COLOR0 708 5 COLOR1 709 6 COLOR2 710 7 COLOR3 711 8 COLOR4 712

FIGURE 58. Color register locations

(PCOLR0 no specifies the background color instead of COLOR4.) The following program is an example of using graphics mode ten:

100 GRAPHICS 10
110 FOR LP=0 TO 8
120 POKE 704+LP,LP*16+LP*2+10
130 NEXT LP
140 FOR C=1 TO 8
150 COLOR C
160 FOR ROW=C TO 71 STEP 8
170 PLOT ROW,88
180 DRAWTO ROW+6,103
190 NEXT ROW
200 NEXT C
210 T=PEEK(712)
220 FOR REG=712 TO 706 STEP -1
230 POKE REG,PEEK(REG-1)
240 NEXT REG
250 POKE 705,T
260 GOTO 210

Graphics Eleven

Graphics mode eleven is the same as graphics mode nine except that we have 16 colors with the same brightness instead of the other way around. To pick the brightness, use the following from BASIC:

SETCOLOR 4,0,brightness

Or this:

POKE 712,brightness

where brightness has an even value between 0 and 14. To pick a color, use

COLOR C

where "C" has a value between 0 and 15. Machine language programmers should just store the color value in either the pixel or in ATACHR, as for the brightness value in graphics mode nine.

Try the following changes to the graphics mode nine program:

100 GRAPHICS 11
110 SETCOLOR 4,0,6
120 FOR C=0 TO 15
130 COLOR C
140 FOR ROW=88 TO 103
150 PLOT C*4+ROW-88,ROW
160 DRAWTO C*4+ROW-85,ROW
170 NEXT ROW
180 NEXT C
190 GOTO 190

As you can see, modes nine and eleven really are almost the same.

One final note: You can still use players and missiles in graphics modes nine and eleven for a grand total of 21 different colors on the screen at one time! You will not, however, be able to detect collisions between players/missiles and playfield.