Classic Computer Magazine Archive ANTIC VOL. 2, NO. 1 / APRIL 1983

Window on GTIA

by David Sanders

Lots of excitement has been generated by the new GTIA chip now being installed in ATARI computers. The older CTIA chip could support only a maximum of five playfield colors at one time, and only in a few modes. The GTIA chip offers three modes which allow up to nine arbitrary colors, 16 shades of one hue, or 15 hues of one luminance plus black.

The real power of the GTIA, however, is that each and every point in the GTIA modes can be set to any of the available colors. They could also be set independently of all other points on the screen.

While it is possible to extend the number of colors on the screen at one time with the CTIA by using Player/Missile graphics, display-list interrupts, or page flipping, all such techniques suffered from serious limitations. Either you could not place colors wherever you wanted, or you experienced unpleasant side effects such as flicker or wash-out.

It also turned out that ATARI BASIC and the OS have been designed so that they could eventually support these three modes. These modes are set up as Graphics Modes 9, 10, and 11. Each mode uses the same amount of memory as Graphics Mode 8. There is one difference in the support of these modes, though, as compared to Modes 1 through 8. Modes 1 through 8 can be specified either as full-screen modes, by adding 16 to the mode number or as split screen modes with four lines of text at the bottom. Normally, you may use the three GTIA modes only as full-screen modes.

So, why aren't the GTIA modes supported with text windows? If you examine the hardware setup you will discover that all of Graphics Modes 0 through 8, with or without text windows, are supported by the display list which is processed by the ANTIC chip. ANTIC gets display data from memory, interprets it, and sends out simple point-by-point codes to CTIA/GTIA. The new GTIA modes are handled by the GTIA chip itself. There is no provision to manipulate GTIA modes from ANTIC's display list.

Even with these features it would still be nice to have a text window available just below the GTIA graphics for use by BASIC programs. Here I have described exactly how to do that.

Program Listing 1 is a BASIC demonstration that shows GTIA modes combined with a text window. While the demo is rather attractive by itself, its real purpose is to show how to set up a GTIA mode combined with a four line text window. It also fools BASIC into thinking this is a "normal" configuration.

First, line 10 POKEs 64 into 54286, which is the location of the "interrupt enable" for both vertical blanking and display lists. This ensures that the display list interrupts are turned off while the setup is being created. Then, Graphics Mode 8 is opened with a four line text window below it. Note that the display list is the same for all three GTIA modes and for Mode 8, except for the fact that the GTIA modes do not normally support the text window.

Line 20 modifies the display list so that a display-list interrupt is generated at the end of the graphics portion of the display. The display-list byte to be modified is at a fixed point from the start of the display list. Locations 560 and 561 point to the start of the display list.

Lines 30-50 set up a short machine language routine at the top of Page Six, then POKE its location into locations 512-513, which is the point for the display list interrupt. The actual data for the routine is from lines 220-240.

Program Listing 2 shows the Assembly Language code for the machine language routine. This routine does two things when it is executed. It copies the color from the color shadow register for Player/Missile 0 into the background color register (making changes as necessary for attract mode operation). This is done because of the fact that the GTIA modes assign color register usage in a completely different manner than normal CTIA usage.

For example, the background color for Mode 10 comes from Player / Missile 0's color, rather than the normal background color. And, more importantly, the priority register is set to zero, which causes any further display to be shown in normal CTIA mode. Since the OS will set the priority register to the value contained in the shadow location at the top of the display, the result is that the display will be segmented into GTIA and non-GTIA portions.

Use of the display-list interrupt permits the middisplay changes to be synchronized to a fixed part of the display to ensure that there is no annoying jumpiness to the point of change.

Computer buffs who want to try playing around with this routine should remember that codes corresponding to lines 0180-0200 and 0270-0280 in the Assembly Language listing are essential. Novice machine language programmers should probably not bother with this for now.

Line 50 also POKEs 192 into location 54286, enabling the display-list interrupt, then POKEs 9 into location 87 to fool BASIC into believing that Mode 9 had originally been set up. BASIC believes that our text window is still present. This is exactly what we wanted!

Remember that Modes 9, 10 and 11 all look alike to BASIC: 80 pixels (dots) across, 192 down, with 16 color codes to choose from for each pixel. Mode 10 has only 9 colors actually available. Codes 9-15 are duplicates of other colors. The POKE to 87 is necessary, otherwise BASIC will believe that it is still in Mode 8 (which is what we started with) and will not plot points as expected for a GTIA mode. Also, because of the text window, there are actually only 160 pixels in the vertical direction.

Lines 60-80 set up the color by POKEing into the nine shadow registers for the colors. Locations 704707 are used to shadow the Player / Missile colors which are available in Mode 10, and locations 708-712 shadow the usual five playfield color registers.

Line 80 also POKEs location 623 which is essential to enable the GTIA display. If the mode is expressed as a value 9-11, then the value POKEd should equal 648(Mode 8). The program in Listing 1 expresses the mode as a value 1-3 internally, and converts it for printout by adding 8.

Line 90-120 are the actual demo program. The program draws random rectangles in one of the GTIA modes, then prints out the current mode and a count of rectangles in the text window. The [OPTION] button advances the GTIA mode, [SELECT] clears the screen without changing the mode, and [START] freezes or restarts the rectangle drawing process.

As you begin to use this program, be aware that some of the following will happen. Whenever you access the disk, the printer or the cassette, display-list interrupts are disabled. This will cause garbage to appear where the text window is normally shown. Don't panic-the text window is okay. All that's happening is that it's now also being shown using a GTIA mode. You must re-enable the interrupt yourself. POKE 192 into location 54286 to do this. Alternately, set up a normal graphics mode before doing your input/output, then execute the following to restore your special GTIA mode.

GR.8:POKE PEEK(560)+265*PEEK(561)+166,143
POKE 54286,192:POKE 623,64*(mode-8)

Note: mode = 9-11.

Also, re-POKE your color register values.

PRINT#6;CHR$(125) will clear your GTIA display window, as you would expect. It will also blank out your text window. The position of the text window cursor will be left unchanged by this operation.

This program requires a bit of work but I think that you will find the window to be worth the extra trouble.

10 POKE 54286,64:GRAPHICS 8
20 POKE PEEK(560)+256*PEEK(561)+166,143
30 FOR I=1768 TO 1791:READ A:POKE I,A:NEXT I
40 POKE 512,232:POKE 513,6
50 POKE 54286,192:POKE 87,9:M=1
60 POKE 704,0:POKE 705,26:POKE 706,54:POKE 707,84
70 POKE 708,104:POKE 709,130:POKE 710,184:POKE 711,218
80 POKE 712,6+122*(M=1)+6*(M=2):POKE 623,64*M:C=0
90 COLOR (8+6*(M<>2))*RND(0)+1
100 I=INT(72*RND(0))+4:J=INT(72*RND(0))+4
110 A=INT(144*RND(0))+8:B=INT(144*RND(0))+8
140 C=C+1:POKE 752,1:PRINT "   MODE=";M+8;" #";C
150 A=PEEK(53279):IF A=7 THEN 90
160 POKE 77,0:IF A<4 THEN GOSUB 210:M=M+1-3*(M=3):GOTO 80
170 IF A<6 THEN GOSUB 210:C=0:GOTO 90
180 PRINT " **** FREEZE ****":FOR I=1 TO 200:NEXT I
190 IF PEEK(53279)<>6 THEN 190
200 POKE 77,0:FOR I=1 TO 50:NEXT I:GOTO 90
210 PRINT #6;CHR$(125):FOR I=1 TO 200:NEXT I:RETURN
220 DATA 72,141,15,212,141,10,212
230 DATA 173,192,2,69,79,37,78,141,26,208
240 DATA 169,0,141,27,208,104,64