Classic Computer Magazine Archive COMPUTE! ISSUE 36 / MAY 1983 / PAGE 97

Programming Multicolor Characters On The VIC

Bill McDannell

If you know how to create standard programmable characters, you can create four-color characters and multicolor graphics. Here's how to select colors for the screen, border, character, and auxiliary colors. For the unexpanded VIC.

In order to understand the creation of multicolor characters on the VIC-20, you must first have a working knowledge of standard programmable characters. You can easily pick this information up from the Programmer's Reference Manual, or from some excellent articles in past issues of COMPUTE!.

For standard programmable characters, drawing is done using an eight by eight grid. Each point on the grid represents one bit, which is turned either on or off by designating a value of one or zero for the bit.

You can use as many as four colors in one character when using multicolor graphics. Since you must designate one of four color choices, rather than simply on or off, you cannot program each individual bit. However, if adjacent bits are combined to produce a piece of information, you have four choices:

  1. Both bits off (00)
  2. First bit off, second on (01)
  3. First bit on, second off (10)
  4. Both bits on (11)

You now have the four possibilities necessary to designate four colors, but you have them at the sacrifice of horizontal resolution. Since it takes two bits to specify a color, you will be able to specify only four individual blocks of color across one horizontal line of your character (as opposed to the eight blocks available with a standard character). You still have eight vertical rows available.

Available Colors

Each possible two-bit value corresponds to a specific selectable color.

00 = screen color
01 = border color
10 = character color
11 = auxiliary color

For border and character colors, you have the choice of the eight standard VIC colors. For screen and auxiliary colors, you can choose from the 16 colors depicted in the screen and border color chart in the back of your owner's manual. More about selecting individual colors later.

First, let's see how we designate our four initial choices. The figure shows the same programmable character in both standard and multicolor mode. Notice that the numerical value of each horizontal byte is the same. The DATA statements you use to create each character are identical. The difference is that in the multicolor mode, each pair of bits is combined and read as one nybble to identify the appropriate color group.

Getting Into Multicolor

Accessing multicolor mode and setting the desired character color are done simultaneously. For standard characters, you POKE the appropriate screen location to the desired color using the numbers zero (black) through seven (yellow). To go into multicolor mode, you simply add eight to the desired color value. This both selects your character color and sets that particular character to multicolor mode. For example, POKEing screen location 38400 to a value of 15 would both change the character color in the upper left corner of the screen to yellow, and turn on the multicolor mode in that space.

Setting border and screen colors is done the same as always: by POKEing 36879 to the desired value from the color chart in your user's manual (POKE 36879,9 will give you a black screen and a white border).

The choice of auxiliary color is made, believe it or not, in the same memory location you use to control volume, with a POKE to location 36878.

There are 256 possible values for this POKE location (0-255), and each of the consecutive 16 values corresponds to one of the 16 available colors, in descending order, from the chart.

In other words, any value between zero and 15 POKEd into location 36878 will produce an auxiliary color of black. Values 16 through 31 will produce white, and so forth. This creates a slight problem when we're writing a program where we want to control both volume and multicolor graphics. We can solve it with this formula:

POKE 36878, A * 15  +  V

A is the number of the desired color (0 is black, 1 is white, etc.), and V is the desired volume.

That's what you need to know to create multicolor graphics. The rest of the operation is identical to creating standard graphics.

These two programs illustrate how to use multicolor characters. The first program creates a four-color spaceship and moves it down the screen. The spaceship is drawn using two separate characters and POKEing them side by side.

The second program is a coloring game my children seem to love. It allows you to choose the colors in which the character will be drawn. I created the character using a grid that is five characters wide and five deep, and which yields a 20 × 40 area of programmable blocks. The screen and border colors are set to black and white by the program. You select the auxiliary color and three different areas of character color. Because character color blocks are set individually, a multicolor figure consisting of more than one character can be programmed to more than four colors. In this case, I could have selected up to 28 different colors for the figure. Six were sufficient.

Program 1: Four-Color Spaceship

10 PRINT "{CLEAR}"
100 POKE36869, 255
105 POKE36879, 61
110 FORI = 7168TO7679 : POKEI, PEEK(I + 25600): NEXT
130 FORI = 7176TO7191
150 READA : POKEI, A : NEXT
154 X = 7690 : C = 30720
155 POKEX, 1 : POKEX + C, 10 : POKEX + 1, 2 : POKEX + C + 1, 10
156 FORT = 1TO80 : NEXT : POKEX, 32 : POKEX + 1, 32
157 X = X + 22 : IFX> 8185THEN154
158 GOTO155
160 DATA8, 2, 5, 23, 85, 93, 85, 40, 32, 128, 80, 212, 85, 117, 85, 40

Program 2: Coloring Game

10 PRINT"{CLEAR}"
20 PRINT"{10 DOWN}  JUST A MINUTE…"
110 FORI = 7168to7679 : POKEI, PEEK(I + 25600) : NEXT
120 FORI = 7176TO7375
130 READA : POKEI, A : NEXT
139 POKEX + 89, 10 : POKEX + 89 + C, 10
140 DATA48, 252, 239, 235, 235, 235, 232, 232, 235