Browsing The VIC Chip
Jim Butterfield
Toronto, Canada
The computer is called VIC, for Video Interface Computer … but there's a chip inside which is also called VIC, for Video Interface Chip. The chip bears the number 6560 or 6561; it's used to make good things happen on your television screen.
Beginners often don't realize that memory addresses are used for more than memory storage. In the VIC computer, addresses 36864 to 36879 may be PEEKed or POKEd. These locations are not used for memory – they hold controlling information for the VIC chip. We're going to look through those addresses, experimenting as we go. We may learn some new things about our computer.
• Location 36864 (Hex 9000). Values 0 to 127 set the position of0 the left border on your screen. The usual value is five. Try the following quick "slide change" line:
FOR J = 5 TO 30:POKE 36864J:NEXT J :FOR J = 30 TO 5 STEP -1:POKE 36864,J:NEXT J
If you add 128 to the value in 36864, the screen will go into interlace mode. In most cases, all you'll notice if you POKE 36864,133 is a little "dither" in the screen detail. However, a few television sets are built in such a way that they won't work unless you set interlace mode with this POKE.
• Location 36865 (Hex 9001). Value 0 to 255 set the position of the top border on your screen. The usual value is 25. Try making the screen "curtsy" with:
FOR J = 25 TO 45:POKE 36865, J:NEXT J:FOR J = 45 TO 25 STEP -1:POKE 36865, J:NEXT J
• Location 36866 (Hex 9002). Part of this location tells the chip how many columns on the screen. This will always be 22. But there's an extra – a value of 128 may be added to set "alternate screen" mode. Normally, the 128 is added in, and you'll find 150 stored in this location. If you want to go to an alternate screen, remove the 128 element with POKE 36866,22 and the screen will now take its information from a new area. There are quite a few things you need to do if you wish to play with this – see "VIC: Alternate Screens" in Home and Educational COMPUTINC, Fall, 1981.
• Location 36867 (Hex 9003) is a busy one. In fact, it's always changing. "Try typing ?PEEK(36867) several times and you'll see that you get different values – sometimes 46, sometimes 174. Let's ignore that extra 128 for the moment; we'll deal with it again when we describe the following location.
The basic value held in this location, normally 46, is the number of rows on the screen multiplied by two (23 rows, right?). You won't want to change this one.
There's one more thing hidden in this location, and it's important. If you add one to the value, the character generator will switch to "double character mode." This means that each character you type will occupy double the usual screen space.
This won't work automatically, however. If we want to draw characters that are twice as big, we must supply the VIC with "pictures" of the new characters; the old pictures won't do since they are not big enough to fill the new space. So prepare for a little confusion when you try this next experiment. Strange things will happen because we haven't built and connected up new character tables.
Type POKE 36867,47. The screen will go rather strange. Don't worry about it for the moment; just press the screen clear key (shifted, of course). The screen will clear, although the cursor looks rather odd. Not to worry, we'll forge right ahead.
The first character in the VIC's table of characters is the "@" symbol; the next is an "A," then a "B" and so on. Now: type the @ key. Instead of getting the first character, we get the first two, one above the other. Try typing the "A" and you'll get B-over-C, the next two characters in the list.
What's happening here? Each character you type is filling double its normal screen area. In doing so, it's grabbing twice as much information from the "character picture" table…and, since that table hasn't been changed, that means two characters. Since the VIC knows (or at least thinks) that the character pictures are twice as big, it reaches further into that table for each character that it needs.
When you decide to use this feature, you'll write your own character picture tables and everything will sort itself out. This feature is likely to be used most for high-resolution graphics. The elements of the character picture table will control individual dots, or pixels, on the screen.
You may bring your VIC back to normal by typing POKE 36867,46 but you'll need to type blind since the screen isn't much help. You might prefer to turn the computer off for a moment; when you turn on again, everything will be back as it was.
• Location 36868 (Hex 9004). This location changes continuously. It's connected with the high-bit (128 value) in the previous location. In principle, it tells you precisely where on the screen the picture is being drawn at this instant. In practice, it's not much use to BASIC] programmers – by the time you read it, a different part of the screen will be active.
• Location 36869 (Hex 9005). This is a very important address. It controls the location of two tables: the table where screen characters are held, and the table which holds the character pictures. Let's take them one at a time.
The screen table holds the five hundred or so characters that are displayed on the screen. It's quite a job to calculate the screen address: let's take a shot at it.
Take the contents of location 36869, divide by 16, and throw away the remainder. That should give you a number from 8 to 15. Subtract 8 and double it, giving an even number from 0 to 14. Now: if the contents of 36866 are 128 or greater, add one to get a value from 0 to 15. Multiply the result by 512. At this point you should have a value from 0 to 7680. That's where your screen table is located; it will normally be at location 7680, but it might move if you add extra memory.
That's quite a calculation; some of the things it implies deserve a separate article. For the moment, let's observe that the screen table address must always be in the range of 0 to 7680, and must be a multiple of 512. If you wish to set up your own screen table within this range, do the calculation in reverse: divide by 512, subracting 1 if odd, dividing by two, adding eight, and, finally, multiplying by 16. Whew! We can see that the "alternate screen" bit (128 value) in 36866 is really part of the much larger screen address.
The character picture table address is also defined in this location. We'd need to change this if we wanted to define our own characters, single or double. Of course, we'd also need to define character pictures for all characters we wished to print. The computation of the address is complex.
Take the contents of location 36869 and divide by 16. Now take the remainder – not the quotient –and, if it's greater than seven subtract eight. On the other hand, if the remainder is not greater than seven, add 32. By this time, you'll have an adjusted remainder which is either less than seven or between 32 and 39. Multiply this value by 1024 and you've found your character picture table address. It will be in the range of either zero to 7168 or 32768 (the normal value) to 39936, and will be an exact multiple of 1024. If you wish to set up your own character picture table, you'll usually want it to point to a RAM address in the range of zero to 7168. In such a case, you'd reverse the calculation: take the address, divide by 1024 and add eight and you're there.
Don't forget that the screen table address and the character picture address are packed together into this location. You'll need to set them both at the same time. By the way, the official name for the two tables are the "Video Matrix" and the "Character Cell table."
Feel free to play with this location; POKE values as you wish. But, unless you plan carefully, all you'll get is a crazy screen.
This was a tough one … now we can try some easier locations.
• Locations 36870 to 36871 (Hex 9006 and 9007). Here's your input from a Light Pen. No, a light pen isn't a ballpoint that weighs less than half an ounce – it isn't a pen at all. It's a device that plugs into your VIC that looks a little like a pen. Point it at the screen, and these locations will tell you where you are pointing.
A standard Atari light pen may be used. It is expected that Commodore will manufacture their own light pen soon. Many light pens have either a button or a spring-loaded switch in the tip which signals whenever the light pen operator wants attention. The switch is implemented in the VIC computer, but is not connected to the VIC chip (you'll find it mixed in with other things in location 37151).
You can read the X and Y positions of the light pen in locations 36870 and 36871 respectively. You won't read row and column values: the numbers will vary between zero and 255, and you'll need to do some calibration for the particular-model of light pen that you have fitted.
Watch for "jitter" on these values. Even though the light pen doesn't move, the readings may jump about a little on successive readings. Depending on what you're doing, you may wish to use an averaging technique to make the readings smoother. Another method is called "hysteresis"; in simple terms, it means that a value is ignored unless it differs from previous readings by more than a given threshold amount.
• Locations 36872 to 36873 (Hex 9008 and 9009). These are paddle input values. Two paddles, similar to Atari paddles, may be connected and their values will be read here. You may not be able to track the full range of rotation of the paddles.
Once again, watch for jitter on the input values here.
To keep the record straight, a joystick can also be connected to the VIC … but the position of its buttons are not detected by the VIC chip. They arrive in other locations (37151 and 37152).
• Locations 36874 to 36876 (Hex 900A to 900C). These are VIC's voices. Setting a value of 128 or higher into any of these locations produces sound; the value you POKE produces the pitch. By POKEing two or three locations, you can produce harmony. All voices are controlled by the sound level which is set at address 36878; try POKE 36878,15 before you play with the voices so that you'll get good volume. A value of less than 128 in any of the voice locations makes that voice silent.
It's interesting to note that the voice controlled by 36874 is the softest, and the voice at 36876 is the sharpest. So you'd use 36876 to carry the melody, and the two other voices as the sidemen.
• Location 36877 (Hex 900D). This is similar to the music voices, except that it generates noise. A value of 128 or more produces noise. The higher the value, the higher the pitch of the noise (from growl to hiss). Once again, this is controlled by the sound level of 36878.
• Location 36878 (Hex 900E). If the number in here is less than sixteen, it represents the sound amplitude (see the four previous locations). If it's sixteen or more, an extra factor is at work: multicolor.
Normally, each character position on the VIC, contains only two colors: background and foreground. If we decide to use multi-color, we can add an extra two colors to each character: the border color plus one more that we may select. We select this color in the high part of location 36878. If you divide the contents of this location by 16, discarding the remainder, you'll get the designation of the ‘auxiliary color."
Interestingly, each character on VIC's screen is independently selected as two-color or multicolor, allowing us to have a mixed screen. This is done in the color nybble table which sets each character's color. Try the following: Clear the screen and type the letter A in the upper left-hand corner. Now go to a new line and type POKE 38400,8. You'll see that the letter A has suddenly turned weird and multi-colored, but the rest of the screen is unchanged. Notice that we did not POKE the VIC chip, but an entirely different memory location that is keyed to the one screen address. To do the job properly, you'll need to define your own character pictures.
• Location 36879 (Hex 900F). The last location in the VIC chip, but a busy one. Let's break it down into its three elements.
Divide the contents of this location by 16, and note the result as "Screen Background Color." Now take the remainder; if it's eight or more, subtract and note: Foreground/Background = ON. The remaining value of zero to seven can be labelled "Frame Color."
The Frame Color is a favorite of mine; it's an easy signal to the user of some situation I want to tell him about without affecting the contents of the screen itself. If there's a danger, an error, or a game explosion, I can flip the border to red with POKE 36879,26 and later restore it with POKE 36879,27. Another example: Rather than typing a PLEASE WAIT message, I might walk the border through a range of colors so that the user can tell something is happening.
Screen Background color can be a very nice psychological support. If you set up a system so that accounts receivable can be done on one background color and accounts payable on a different one, the user can be ";keyed" to recognize that he's in the right program. It's a little like decorating each floor of a building in a different color so that people won't get the wrong one. Try combinations such as POKE 36879, 155 and see how you like the effect.
Now for the Foreground/Background business. Normally (F/B = On) we know that we can type characters of many colors on a single color background. Sometimes, it can be very handy to do the opposite; in other words, we want to type single color characters on a background whose color may vary from character to character.
Try POKE 36879, 19. Now clear the screen and type a few characters. Change color and type some more. Do you see what's happening? You are changing the color of the background, not the color of the characters themselves.
By playing around with these locations, you can discover potential that you never knew existed. Once you know it's there, you can then exploit it for your own special effects.
There's a rich variety of controls and information available in the VIC chip. You may not need to use them all .. but isn't it fascinating to play around?
Copyright © 1982 Jim Butterfield
Table 1: VIC 6560 Chip