6 Advanced Graphics Techniques

Part III:
Atari Video Graphics
And The New GTIA


Craig Chamberlain


In this conclusion of the three-part series, several demonstration programs teach the concepts of (and show off) the new Atari GTIA graphics chip.

Welcome back to our discussion of Atari playfield graphics and the exciting new GTIA chip. In Parts I and II I presented definitions of various terms related to graphics, explained the normal graphics modes, and then introduced the three new modes provided by the GTIA. Specifically, these new modes are:

MODE
9
10
11
DESCRIPTION
16 shades of one color
8 indirected colors
16 colors (one luminance)

Here are several programs in Atari BASIC to demonstrate how these new modes might be put to use. But first, let's tie up a few loose ends from the previous articles.

We used a standard method to show bit designations in the first parts of this article. If you are not familiar with this convention, here's how it works. Any given memory location or hardware address consists of one byte made up of eight binary units called bits. These bits are numbered zero to seven and are frequently shown as D0, D1, D7, etc. Individually, each bit can have two values, zero or one, but from the viewpoint of a byte, they take on quite different values known as "powers of two." For example, D3 means "two to the power of three," which also means "the number two used as a factor three times." Two times two times two is eight, so if we wanted to turn on only bit three in a given hardware register, we would POKE it with an eight. If we want to turn several bits on, we must add all the proper values together.

BIT
0
1
2
3
4
5
6
7
VALUE
1
2
4
8
16
32
64
128

Mode 11 can be invoked by turning on bits six and seven of GPRIOR, location 623 (decimal). Thus we would POKE 623 with 64 + 128, which is 192. This brief explanation should help you deal with the memory locations and hardware registers described in the previous articles. Now for a review of the primary graphics statements of Atari BASIC and some special notes about the GTIA.


Graphics Statements

GRAPHICS aexp

This statement is the same as OPEN #6, 12 + 16,aexp, "S:", and tells the screen handler to open the screen to one of 12 modes. The number "aexp", which means "arithmetic expression," can range from zero to 11. Characteristics of these modes are explained in chapter nine of the Atari BASIC Reference Manual.

Some modes allow split screen configurations, which means that a text window appears at the bottom of the screen. Of course, mode zero does not allow a text window because mode zero is the text mode, although you can experiment with POKE 703,4. Modes one through eight do support text windows, and the only way to get a full screen (no text window) in one of these modes is to add 16 to aexp in the GRAPHICS statement. When using a full screen mode, Atari BASIC forces a mode zero if it has to print normal text. It is impossible to use these full screens in the immediate programming mode because the "READY" prompt forces the mode zero screen.

Due to technical reasons explained in the previous article, modes nine, ten, and eleven do not normally allow text windows. You can fool the operating system into giving you one of these modes with a text window by asking for mode 8 and then doing a couple of POKE statements, like this:

MODE
9
10
11
POKES
POKE 87,9: POKE 623,64
POKE 87,10: POKE 623,128
POKE 87,11: POKE 623,192

Location 87, known as DINDEX, tells the operating system the current mode and is used in the computation of row and column addresses for plotting, so any number from nine to eleven will give the same results. Unfortunately, the text window obtained by this method looks weird. The only way to get a real text window is to use a display list interrupt, discussed later.

If you add 32 to aexp, the screen will not be cleared when the new mode is requested.

Finally, the CTIA and GTIA support five other modes which the operating system does not recognize. They are the eight by ten matrix character version of mode zero, the multicolor text character modes, and the single scan line versions of modes six and seven, for 160 by 192 plotting in one or three colors. The only way to access these modes is to write a custom display list.

COLOR aexp

This specifies the playfield that will be used for PLOT and DRAWTO statements, until changed by another COLOR statement. It does not in any way change any of the color/luminance registers for the various playfields! The range of aexp depends on the number of different playfields available in the current graphics mode. This still holds true for the new GTIA modes. For example, a COLOR 2 in mode 9 means that future plotted points will be rather dark, whereas bright lines will be drawn after a COLOR 12.

In mode 11, COLOR 5 chooses a purple color, as indicated by the chart in part one of this article. For all modes, COLOR 0 (zero) is the background or "erasing" color. Normally, the operating system wants you to specify the playfield each time you write to the screen, but Atari BASIC automatically tells the operating system which playfield you have chosen every time you use PLOT or DRAWTO. Incidentally, the data part of the COLOR statement is stored in memory location 200 (decimal), but I would not recommend using that.

One other note. To be technically accurate, COLOR 1 corresponds to playfield zero, COLOR 2 means playfield one, and so on.

POSITION aexp1,aexp2

This statement moves the graphics cursor to the location on the screen designated by the two numbers, according to the Cartesian coordinate system. No range checking is done.

PLOT aexp1,aexp2

This is the same as POSITION aexp1,aexp2: PUT #6, color where "color" is the playfield type chosen by the most recent COLOR statement. You will get an error number 141 if you try to PLOT outside the bounds of the screen. All three new modes have resolution of 80 by 192.

DRAWTO aexp1,aexp2

Essentially, this is the same as PLOT except that a line is drawn from the most recently plotted point to the new point indicated by aexp1 and aexp2. You can also do this with an XIO 17,#6,0, 0,"S:". See page 54 of the Atari BASIC Reference Manual to see how XIO 18 can be used to fill areas with a playfield.

LOCATE aexp1,aexp2,avar

I don't know why, but nobody seems to know about this statement. It could be considered the reverse of PLOT. Instead of putting a playfield point at a certain location on the screen, this statement returns to you, in the arithmetic variable "avar", the playfield number of the point at location aexp1,aexp2. This playfield number will be the same as the value of COLOR that was in effect when the point was plotted. LOCATE is actually quite handy. It is very useful in games where collisions occur between differently colored players, but it has many other applications, too. LOCATE is the same as POSITION aexp1,aexp2:GET #6,avar.

SETCOLOR aexp1,aexp2,aexp3

This is the statement which changes the color and luminance of a playfield register. The number aexp1 designates which playfield register is being changed, and is related to the number in the COLOR statement in the following way:

COLOR
1
2
3
-
0
SETCOLOR (playfield number)
0
1 (also used for luminance in modes zero and eight)
2
3 (used only in four-color text modes one and two)
4 (background, or border in modes zero and eight)

The value for aexp2 is a number from zero to 15 which specifies one of 16 colors. See the chart in part one of this article, or on page 50 of the Atari BASIC Reference Manual, to find which numbers go with which colors. The luminance is chosen by aexp3, which can range from zero to 15, but only eight true luminances can be selected. A value of zero here gives the same luminance as one, two the same as three, and so on. The larger the number, the greater the luminance.

Remember that modes 9 and 11 do not use color indirection or the playfield registers, so SETCOLOR has little use in these modes. It can be used to set the background color/luminance in these two modes, but that's about it.

Now for mode 10. This mode uses the player/missile color/ luminance registers, which cannot be accessed using SETCOLOR. An equivalent POKE statement must be used instead. The location to POKE is similar to the aexp1 of SETCOLOR. The shadows of the playfield registers run from locations 708 (decimal) to 712. The value to POKE contains the color and luminance information and is a combination of aexp2 and aexp3. This value is the sum of 16 times the color number, plus the luminance. In effect, SETCOLOR X,Y,Z will do the same as POKE 708 + X, 16*Y + Z. If you want to change the player/missile color/luminance registers, which run from locations 704 to 707, use the same procedure of multiplying the color by 16 and then adding the luminance. Refer to part one of this article for a chart that tells which COLOR numbers match with which registers.


Some Lively Demos

Now comes the good part, where the action is! If your Atari computer has a GTIA in it, here are some programs to show off the talents of this remarkable chip.

How to put 16 colors on the screen? It could be done in one line:

GRAPHICS 11: FOR K=0 TO 79: COLOR K: PLOT K,0:DRAWTO K,191: NEXT K: FOR K=0 TO 0 STEP 0: NEXT K

The endless loop is necessary to prevent Atari BASIC from printing a "READY" prompt which would force mode zero. To make the vertical color bands wider, change the COLOR K to COLOR K/5. To see 16 shades, change the GRAPHICS 11 to GRAPHICS 9.

A fancier way of showing 16 shades is found in Program 1. After drawing the shades, the background color is rotated through all 16 colors.

Program 3 randomly draws lines in 16 colors. You can make these colors appear darker or more pastel by changing the luminance of the background. Please note that mode 11 is the only mode in which the background is set by the operating system to a luminance of six. All other modes have backgrounds of color/luminance zero (black).

Program 2 demonstrates the color indirection capabilities of mode 10. Location 20 is the lowest counter of the realtime clock, so it is always changing. Continuously PEEKing this location and POKEing the value into a color register gives a nice "throbbing" color spectrum effect.

How about a doodling program that lets you draw in 16 colors using the joystick? Program 4 does this in only three lines of Atari BASIC code! Press the joystick trigger to change colors.

Program 5 is a really beautiful color kaleidoscope generator, considering it is only four lines long. It's not something you will spend hours watching, but it can produce some nice pictures. Try changing the K = I + J in the second line to K = I for a different picture. Or you can reverse the direction of the main loops, as in FOR I = 31 TO 1 STEP -1. If you change the J loop (note that it starts at zero, FOR J = 31 TO 0 STEP -1), you will also want to change the H loop (FOR H = 1 TO 3 STEP 1).

To show 256 colors on the screen all at once, use Program 6. This program does not show the colors. Rather, it produces a single line which you can ENTER from disk or cassette. This single line performs all the magic. What is also neat about this program is that when you ENTER the line in, the program already in memory is untouched. If you examine Program 6, you will see that it writes a line to the chosen device, but the line has no line number in front of it. When you ENTER this line, it is the same as typing it in the immediate mode. When Program 6 asks for a device specification, respond with C: for cassette or D:filename for disk.

I included the assembly source code and Atari BASIC installation routine for a display list interrupt service routine (Program 8) that creates a text window on modes 9, 10, or 11. An interrupt is requested at the last mode line of the graphics mode portion of the screen. The service routine takes the value of GPRIOR, sets the GTIA mode select bits to zero, and stores the result in PRIOR, the hardware register. PRIOR gets reset to the value of GPRIOR as part of the vertical blank service routine. The routine also stores a zero into the background hardware register. This was necessary to fix a conflict in mode 11. Setting the luminance in 712 also changes the border around the text window. But this "fix" created another problem in mode 10. For mode 10, change the fourteenth DATA element, which normally should be a zero, to be the same as the number POKEd into 704.

The service routine is written using relocatable code, so you can put the routine anyplace in memory simply by changing the assignment of ADDRES in the second line. It is currently set to start at the beginning of page six. The first three lines of Program 7 actually install the routine. The fourth line just draws a picture for purposes of demonstration. Notice the luminance change of the colors when 712 is POKEd.

My routine shares the problem of many display list interrupt service routines; keyboard clicks can affect the display. Obviously this routine is suitable only for programs that do not accept keyboard input (use the joystick or PEEK the hardware keycode register 764 directly) or use serial I/O (the vertical blank routine is abbreviated and PRIOR does not get reset).

Program 9 is a handy little routine which allows your Atari to test itself for a CTIA or GTIA chip--without your having to interpret screen colors, as other routines do. Now your programs can adapt themselves to either chip.

Download P230L1.BAS (Saved BASIC)
Download / View P230L1.LST (Listed BASIC)
Download P230L2.BAS (Saved BASIC)
Download / View P230L2.LST (Listed BASIC)
Download P230L3.BAS (Saved BASIC)
Download / View P230L3.LST (Listed BASIC)
Download P230L4.BAS (Saved BASIC)
Download / View P230L4.LST (Listed BASIC)
Download P230L5.BAS (Saved BASIC)
Download / View P230L5.LST (Listed BASIC)
Download P230L6.BAS (Saved BASIC)
Download / View P230L6.LST (Listed BASIC)
Download P230L7.BAS (Saved BASIC)
Download / View P230L7.LST (Listed BASIC)
Download P230L8.SRC (Assembly source)
Download P230L9.BAS (Saved BASIC)
Download / View P230L9.LST (Listed BASIC)


Return to Table of Contents | Previous Section | Next Section