Classic Computer Magazine Archive COMPUTE! ISSUE 20 / JANUARY 1982 / PAGE 180

VIC Color Tips

Charles Brannon Editorial Assistant

Users of other computers, such as the ATARI or Apple, will find the VIC harder to use for color graphics because there are no dedicated statements for controlling these features. First time users will not know the difference, but this article should make things easier. Before we begin, it should be noted that there will soon be available a VIC Super Expander Cartridge that will add special sound and graphics commands to BASIC, as well as adding 3K of memory.

"Poking" Graphics

The only command that can be used for graphics besides PRINT is POKE. POKE places a number into a memory location. Its format is POKE A, B. A is the memory location, and B is the value to be placed there, zero to 255. Some spots in memory can control Input/Output chips, such as the Video Interface Chip inside of the VIC. Location 36879 is the control register for background and border colors. To get each combination, you place a number from zero to 255 into 36879, as previously mentioned. For any particular combination, you can look up the colors in the table at the end of this article (Table 2). There is an easier way, however, at least from a programming standpoint.

An Easier Way

The DEF FN command allows the programmer to design his own function. The VIC has, for example, the standard INT function. INT(X) will give you the whole-number value of the argument X by dropping the fractional portion. It does not round X. To provide a rounding-up function, we can use the DEF FN command. To round dollar and cents amounts, the statement DEF FNR(V) = INT (V* 100 + .5)/100 is executed at the start of the program. After that, FNR(X) will give you the rounded version of X, or any value in parentheses. PRINT FNR(3.1415927) will return 3.14, while PRINT FNR(500.076) will give 500.08 The R after the FN is a label to remind you what the function does. Here R stands for Round. These labels have the same format as numerical variable names.

What we want to do is to devise a formula which will give us the right number from the table for each color, one to sixteen. We will give the background color from one to sixteen through the FN routine, and it will give us the number ready for POKEing. To get any background color from any of the sixteen possible colors, just multiply the color number by 16 and then subtract eight. We can code this as DEF FNC(V) = V*16-8. Remember, V is just a dummy variable used to define the relationship of the argument (what we give the routine) in the formula. Next we use a little shorthand. The number 36879 (the color control) is a little hard to remember, and it does not look much different than any other memory location. We will make it easier to remember (make it mnemonic) by making it a variable, SCREEN = 36879. Now we can call forth any of our sixteen colors with the statement: POKE SCREEN, FNC (color), where color is the number from one to sixteen. This almost looks like a real graphics command.

Adding Border Colors

What about the border colors? In addition to the background, you can have eight border colors, numbered from zero to seven. This is one less than the corresponding number on the color keys (CTRL-6 would be 5). Now just take this number and add it to the number that you POKE into SCREEN. Now we just use: POKE SCREEN, FNC(color) + border, where border is the border color, zero to seven. If you don't use border colors, or don't add anything to FNC(color), then the border will be black.

Remember that if the background is the same color as the text, the cursor will become invisible. If you need to, set things straight with POKE 36879,27 or hold down RUN/STOP and press RESTORE to reset.

The little program at the end of this article demonstrates what I've been talking about by displaying all the combinations of screen and border colors. It's simple to figure out so look it over, and get to work on your Victorious applications!

Table 1. Screen/Border Colors Screen
Screen Border
1 Black 0 Black
2 White 1 White
3 Red 2 Red
4 Cyan 3 Cyan
5 Purple 4 Purple
6 Green 5 Green
7 Blue 6 Blue
8 Yellow 7 Yellow
9 Orange
10 Light Orange
11 Pink
12 Light Cyan
13 Light Purple
14 Light Green
15 Light Blue
16 Light Yellow
100 REM * ANOTHER RAINBOW *
110 DEF FNC (V)=V*16-8
120 SCREEN=36879
130 FOR BK=1 TO 16
140 PRINT "{CLEAR}{WHT}";
150 IF BK>1 THEN PRINT "{BLK}"
160   PRINT "SCREEN";BK
170   FOR BD=0 TO 7
180   POKE SCREEN,FNC(BK)+BD
190   PRINT, "BORDER"; BD
200   FOR W=1 TO 500: NEXT W
210  NEXT BD
220 NEXT BK
230 POKE SCREEN, 27
240 END
Table 2. POKE Values
BAGKGROUND # BORDER
0 0 1 2 3 4 5 6 7
1: 8 9 10 11 12 13 14 15
2: 24 25 26 27 28 29 30 31
3: 40 41 42 43 44 45 46 47
4: 56 57 58 59 60 61 62 63
5: 72 73 74 75 76 77 78 79
6: 88 89 90 91 92 93 94 95
7: 104 105 106 107 108 109 110 111
8: 120 121 122 123 124 125 126 127
9: 136 137 138 139 140 141 142 143
10: 152 153 154 155 156 157 158 159
11: 168 169 170 171 172 173 174 175
12: 184 185 186 187 188 189 190 191
13: 200 201 202 203 204 205 206 207
14: 216 217 218 219 220 221 222 223
15: 232 233 234 235 236 237 238 239
16: 248 249 250 251 252 253 254 255