2

Using SETCOLOR,
COLOR, and POKE
to Color Your Screen

titlebar.gif

Stephen Levy


The SETCOLOR and COLOR statements are important to Atari graphics, but are often misunderstood by beginners. Here are simple examples to help newcomers get the most from their Ataris.

One confusing aspect of Atari graphics for the beginner is the relationship between the COLOR and SETCOLOR statements. Once the relationship between these statements is understood, the beginner can control the color patterns he or she wishes to create.


SETCOLOR in Mode 0

The SETCOLOR statement is used to define the colors which will appear on the screen. In mode 0 the statement will function alone. Try entering the following without a line number:

SETCOLOR 2,0,14

The screen should have turned white. But characters on a white screen are difficult to read. To remedy this situation, enter the following line:

SETCOLOR 1,0,4

The print on the screen is now dark enough to read easily. To try one more color change, enter this line exactly as it's printed:

SE. 4,3,6

SE. is the abbreviation for SETCOLOR and may be used to enter the statement, even within a program line. As an example, try entering this line using the SETCOLOR and GRAPHICS abbreviations as follows:

100 GR. 0:SE.2,8,6

Now list the line by typing L. (RETURN) (L. is the same as LIST). Notice that the computer has printed the entire word for SETCOLOR and GRAPHICS.

Take a closer look at the SETCOLOR statement. The first number is the color register, the second number is the hue, and the last number is the luminance. There are 16 hues to choose from and 8 luminances for each hue. Table 1 summarizes the hues.

Table 1. Color Numbers
Number
0
1
2
3
4
5
6
7
Color*
Gray
Gold
Orange
Red-Orange
Pink
Violet
Purple Blue
Blue
Number
8
9
10
11
12
13
14
15
Color
Light Blue
Blue-Green
Turquoise
Green-Blue
Green
Yellow-Green
Orange-Green
Light Orange
*Colors may vary on different color TVs.

The simple examples of the SETCOLOR statement given previously used registers 1, 2, and 4. The use of these registers varies for the different modes. In mode 0, SETCOLOR 1 controls the print color and should have the same hue as register 2, which controls the screen color. Register 4 controls the border color for mode 0. Table 2 summarizes which color registers are used in which modes. It is important to remember that the term colorregister refers to the first number in the SETCOLOR statement, not to the first number in the COLOR statement, which is discussed below.


SETCOLOR and COLOR in Modes 3, 5, and 7

Look at Program 1. Lines 20, 30, and 40 set the color registers 0, 1, and 2. But just setting the registers does nothing to put color on the screen. A COLOR statement is needed to tell the computer which of the colors you wish to use, and something must be PLOTted or drawn.

The numbering can be a bit confusing. Refer to the first two columns of Table 2. Notice that to get the color established by the SETCOLOR 0,4,6 statement, you must issue the command COLOR 1. The COLOR statement number is always one more than the first number in the SETCOLOR statement, except for SETCOLOR 4, when COLOR 0 would be used.

If you haven't already typed in Program 1, do so now. Line 50 is the COLOR statement that decides which of the three SETCOLOR statements will be used when the box is drawn. This program will continue to rotate through the three colors endlessly until the BREAK key is pressed. Experiment with the program, change the colors, and see what happens.


Changing the Background Color

Program 2 illustrates how to change the background color in modes 3, 5, and 7. SETCOLOR 4 has just been hinted at so far. It is the color register that controls the background color in each of the four-color modes (3, 5, and 7).

Line 50 sets the background color. Lines 20, 30, and 40 set the colors for the rectangles. The text window keeps you informed about the colors. Again, the best way to learn about these colors is to experiment.


POKE Instead of SETCOLOR

Replace lines 20, 30, 40, and 50 of Program 2 with those lines from Program 3. Once this is done, run the program. All that was done was to replace each of the SETCOLOR statements with a POKE statement. The new lines act exactly the same as the originals.

Here's how to figure the second number in the POKE statement: multiply the hue by 16 and add the luminance. For example, SETCOLOR 0, 3, 10 would become 3 times 16 (48) plus 10, for a total of 58--POKE 708, 58. Table 2 shows which POKE location to use for each color register.


Table 2. SETCOLOR, COLOR, and POKE
SETCOLOR*
0,a,b
1,a,b
2,a,b
3,a,b
4,a,b
COLOR
1
2
3
-
0
POKE t
708,c
709,c
710,c
711,c
712,c
MODES
1-7
0,1,2,3,5,7
0-8
1 and 2
0-8
____________________________
*a = any number from 0 to 15.
b = zero or any even number from 2 to 14.
t c = a x 16 + b (a times 16 plus b).

Selecting the Right Colors

One problem that many new programmers have is selecting the best combination of colors. Each time a color is added or changed on the screen, it affects the other colors on the screen. Program 4, a simple color editor, is intended to help with this problem. It will tell you the number to POKE to get the color you have selected. It will also tell you which color number to use in the COLOR statement.

Once the program is typed in and run, you will see one number flashing. That is the current register that will be affected by the joystick plugged into port one. Moving the joystick forward advances the numbers, and pulling back makes the numbers decrease. Pressing the fire button will change the register that is affected by the joystick. Trial and error will be the best teacher here. When you discover a combination of colors you believe would fit your application, make a note of it so you can use that combination in your own program.


Only the Beginning

This article is just an introduction to the world of Atari graphics. There is much more to be learned, but with the simple techniques shown here, you should be able to make some very impressive displays.


Program 1. SETCOLOR Example

Download P032L1.BAS (Saved BASIC)
Download / View P032L1.LST (Listed BASIC)

Program 2. Background Colors

Download P032L2.BAS (Saved BASIC)
Download / View P032L2.LST (Listed BASIC)

Program 3. POKE Instead of SETCOLOR

Download P032L3.BAS (Saved BASIC)
Download / View P032L3.LST (Listed BASIC)

Program 4. Color Editor

Download P032L4.BAS (Saved BASIC)
Download / View P032L4.LST (Listed BASIC)

Return to Table of Contents | Previous Section | Next Section