The VIC 40-Column Operating System is a PET-emulating, 40X25 character generator for your VIC 20. A minimum of 8K RAM expansion is needed for its use. The program will work successfully for both tape and disk users alike. This article 1s divided into two parts. The first contains the entry program which allows you to enter the all-machine language V/C 40 in normal BASIC. The second portion of the article concerns the actual VIC 40 itself, with a BASIC demo explaining some of the programs power. [...]
The VIC 40 is an all-machine language program which cannot be loaded and RUN as BASIC programs are. A special loader is needed, and one is
provided for you in the listing section (marked LOADER). It will work with either tape or disk, as the VIC 40 does.
This section is only for tape users; disk owners, skip to the next paragraph. Tape users, take note! Make sure that the loader comes before the main
VIC 40 program. Because the tape has to search sequentially for programs, unlike the disk which can go anywhere on a surface, programs must follow in the order in which they are going to be run. The loader has to go right BEFORE the main VIC 40 program in order for a proper LOAD to occur. Any other sequence will not work!
After LOADing and RUNning the loader, the main VIC 40 program will be found, loaded, and executed. If all goes well, you should see a display screen unlike that which you have seen to date on your ole’ VIC 20. A power-up message similar to the one you receive when the power is turned on will be displayed, only now in 40-character across format. In fact, your VIC will now act like a PET in many respects. For one thing, PET screen POKES will now work (32768-33767) along with PET sound generation (59464, 59466, 59467). Even the trusty upper/lower case switch (59468) will work, allowing any old PET BASIC software to work with relative ease on your expanded VIC!
Some of you may now say, “I don’t know what those PET POKEs are for; therefore I have no use for them!” If you are in that group, read on to discover functions which the VIC 40 can perform unrelated to the PET (but which are still powerful). Old CBM/PET users will, however, respect the versatility this gives them!
As stated before, VIC 40 operates almost identically to the way the VIC does on power-up, except that now everything is in 40 columns. One noticeable difference is the presence of a real control key. The CTRL key used to change colors; now it will cause an indefinite pause until either SHIFT key gets pressed. To use the CTRL key to change colors or to turn on/off reverse field, SHIFT-CTRL must now be used. This feature is designed as an aid when LISTing programs, or making the computer wait until you are ready.
Another key with a different function than normal is the RESTORE key. If you need to break out of a dead program, or for some reason you wish to return temporarily to 22-column mode, press the RESTORE key by itself. No STOP key press is necessary to generate the warm-start. To reenter the VIC 40 from 22-column mode, type SYS 8841 if the power-up message is desired. If no message is needed, and you want the screen colors to remain
the same, type SYS 11768. Either way, you will be back in the VIC 40. As a rule of thumb, use SYS 8841 if you enter from direct mode, i.e., right from the keyboard. Use SYS 11768 if you enter VIC 40 from a program, as the VIC 40 Demo does.
VIC 40 contains both of CBM’s character sets and has the special capability to display both on the same screen at once! To change character sets you must either do a POKE or a PRINT. To go to lower case use POKE 59468,14 or PRINT CHR$ (14). To switch to upper case/graphic mode type POKE
59468,12 or CHR$ (142). The normal way of using the SHIFT and COMMODORE key to change cases does NOT work in VIC 40, so please learn the other methods.
Characters are stored in a 4X7 matrix inside VIC 40’s memory. Two characters are stored in each byte, up to a total of 128 characters (the normal number of VIC 20 characters). Reverse-field characters are not stored, but are generated on the fly by simply reversing the bits of a stored character, then displaying it on the hi-res screen. Hence, 128, not 256, programmable characters are at your disposal. Remember, if you do design a programmable character, you will have to change an already existing one, perhaps for a game or special business application. The reversed field version of your character will also be available at no extra memory cost, thanks to the way reversed characters are generated.
As previously mentioned, to change a color using VIC 40 you must press CTRL and a number as is normally done. But you must also include the
SHIFT key so the pause won't occur. Note that if ‘your machine seems to lock up it is because the pause is on; to turn it off simply tap a SHIFT key. In any event, when you successfully do a cursor color change, notice that every character on the screen is changed to that color. To allow a full 8-color palette on the screen at once requires some POKEing around!
Color on the VIC 40 is static. That is, it does not change until changed; even after a screen scroll the color remains intact. There are a total of 220 color blocks which you may set to any of the VIC’s colors. Every block encompasses a 16x8 dot area, so every 4 characters on the screen may be a different color. Only those within the 16x8 (4 characters maximum) will have to be the same. On each horizontal line are 20 available color blocks. In each vertical column are 11 color blocks. To change values, or to read current ones, the POKE and PEEK statements may be used. The first color block is at 37888, with each incrementing value going horizontally. Here is a small diagram explaining that idea.
Color Line 1 37888 37889 37890 ... 37907
Color Line 2 37908 37909 37910 ... 37927
This pattern continues for each of the 11 horizontal lines, with color memory going across to the end of the line, then down to the next one. To see this block effect more closely, type:
POKE 36879,9 : POKE 37888,6
then hit the RETURN key. Note that the block in the upper left hand corner gets changed to blue. Move your cursor in there and type a few letters. Note how the background is independent of the characters over them (almost like color sprites). Experiment with location 36879 (the screen/border control in the VIC) and with different color block values. Some truly remarkable and graphically amazing screens are possible! (Remember that the color blocks are static. In case you scroll down and the characters move up, notice that the color does not! This is very useful when preparing displays for any purpose.)
Storing characters via POKE works in the same manner as with all Commodore computers. You use the method
VIC 40’s screen is not a typical screen in the sense that it is not stored as characters, but rather as bits. VIC 40’s screen is a bit-mapped hi-res page in RAM. VIC 40 gives you the ability to POKE characters onto the screen as with a standard PET. Why use hi-res then? Simply because you can now control every dot on the screen, and therefore create superb hi-res pictures combining both dots and text.
The hi-res screen in VIC 40 measures 160 dots across by 176 dots vertically. The VIC 20 allows larger than normal characters (16x8, instead of 8x8) on its graphics chip, and this is the mode which allows VIC 40 to allow such a large display. By placing these 168 characters one on top of another in rows in RAM, and by repeatedly changing their values for each different character displayed, the VIC 40 can simulate a 40X25 machine. To allow quicker scrolls and altogether smoother operation, the programmable characters are stored vertically (as said before) so simple byte moves suffice when a scroll takes place. (Older methods involve storing characters side by side in rows, which forces you to do bit-shifts in order to move the screen up or down! This method is better suited for sideways scrolling [as in games].) Notice that the scroll does slow VIC 40 down a bit, as it has to move all the hi-res lines up 8 bytes, but the speed required for the older method would have taken 3 times as long!
If the previous paragraph confused you, take heed, this one is for you. Whereas the previous info was for more advanced graphics users, the data given here will be of use to all. Now you can learn how to plot on the hi-res screen, with characters also there!
Remember that the VIC 40 screen is only a hi-res page 160 dots across by 176 dots vertically. By using the following formula you can actually light single dots (pixels) on the screen. You have a large selection as there are 176x160 points to choose from. More advanced people will be able to write routines to turn points off, to draw lines, and to actually paint in certain polygons. I leave that up to you, but in line 5000 of the VIC 40 Demo is a general purpose plot subroutine which the demo uses to generate pixels (picture elements) on the screen. Feel free to use it in your own VIC 40 programs, and try to use the knowledge given so far to further understand its operations.
Type in, SAVE, and RUN the demo for the VIC 40. Notice how neat color displays can be created easily, how both character sets can be used onscreen at once, and how points can be plotted (overlayed) onto the VIC 40 screen. Notice that I say overlay because the points plotted can be over the entire screen, yet the characters underneath them may be recalled in a flash (even if your plot routine erases them). To see what I mean, break out of the Demo during the sine wave generation. Move your cursor over a character with points plotted over it. See what happens? The points plotted will disappear and the character previously underneath it will reappear intact. This is another power of VIC 40; a whole hi-
res screen can be plotted, but underneath it can be a screen full of CBM characters which can be recalled instantly. This is another case of pseudo-sprite ability, which emulates the foreground-background ability of the Commodore 64 sprites.
As always, the key to getting nice display screens is experimentation! A word processor with graphic charts, or a database combining all elements that a businessman could desire (similar to LOTUS 1-2-3), or even a graphics tablet for game design is entirely possible with VIC 40. With 8K RAM expansion (or even 32K), the software possible for this operating system can rival that of any Commodore computer, 64 included! Don't fret, VIC users, this package will keep you and your initial computer investment busy for a long, long time, even though CBM no longer manufactures VIC 20's.
For any ultimately serious and marketable product, machine language is a key. To execute number-crunching quick sorts, or fast I/O, ML is the answer.
If you do not yet know machine language, please skip this area and go on to the SOUND section.
The VIC 40 changes the IRQ vector to its own special input and output handlers. All input and output called by the kernal first goes through the VIC 40 Operating System routines before branching to the standard Commodore ones. The reason for this is obvious. Since all routines are character-oriented, and formatted for 22 columns, the ROM routines would never work in 40 columns. By changing vectors at the beginning of page 3 ($300-$330), VIC 40 is wedged into the standard operating system.
The VIC 40 is very intelligent with regard to interrupts in that it will allow IRQ’s besides its own to occur. In other words, you may want to have a special keyboard reader, or perhaps a music maker, use the normal 60 times a second IRQ interrupt besides the VIC 40. VIC 40 can handle it with ease by modifying itself and jumping to the old interrupt when finished. This ‘chaining’ of interrupts can lead to very powerful structures, all occurring 60 times a second.
The NMI (warm start interrupt) is checked the same way as the IRQ. If one different from the norm is present when the VIC 40 is executed, it will prevail over VIC 40's. This is useful if you have some business software which uses the NMI to reset itself or to trap errors. The normal NMI of the VIC 40 sends the VIC back into 22-column mode with all program lines and variables left intact.
Note that to initiate a warm start, the STOP key need not be pressed along with the RESTORE key. Since this NMI is non-destructive to memory (variables and program lines) it eases its use. Of course, you can change the NMI to meet your needs, which may mean disabling it entirely!
The ML portion of the VIC 40 devotes itself to maintaining the bitmap and executing time-consuming tasks such as maintaining the screen editor’s line links and executing character (bit by bit) scrolls. Another feature of VIC 40 which requires ML intervention is the acceptance of PET/CBM POKE'’s. Even though there is no RAM at 32768 to 33/67, the VIC is tricked into thinking that there is, This requires a test of all BASIC statements as they are executed, and patches to change PET/CBM POKE’s to ones which can be used on the VIC. See the memory map for “real” locations of the character screen. The upper/lower case changer along with the sound POKE’s are handled the same way. A little interception and a bit of gritty programming can fool BASIC into POKEing and PEEKing RAM which doesn't exist and never will.
Sound on the VIC 40 maintains the same characteristics as the VIC 20 possesses. A few additions are made, though. PET/CBM sounds will now work on your VIC, sounding quite similar to the PET speaker. Consult the memory map in the next section of this article for all of the PET/CBM POKE’s which the VIC 40 will accept.
All locations are in decimal unless preceded by a dollar sign ($), in which case they are in hex (base 16).
4096-4316 | Real screen in RAM, holding locations of programmable characters (which make up the hi-res bit map). |
4320-7839 | Hi-res screen made up of programmable characters aligned in incrementing columns instead of the often-used row method. |
7840-8839 | REAL 40X25 screen which is emulated by BASIC at 32768 by the VIC 40’s I/O routines. Use STA or JSR $FFD2 to access this screen from ML. |
8840-8959 | Subroutines for VIC 40. |
8960-9855 | This is the stored programmable characters section. To create custom characters, changes must be made in this area, Characters are stored 2 per byte, with the order of characters following the same order that the standard CBM ones have. |
9856-11880 | Main VIC 40 program. |
11881-up | Free BASIC (or ML) RAM. You have 4500 bytes free with an 8K expander, plus another 8192 bytes for every 8K board you add. |
IRQ VECTOR-10932 ($2AB9) | |
PET/CBM POKE’s & PEEK’s | |
32768-33767 | Screen RAM. |
59464 | PET/CBM Sound Frequency. Higher values generate lower tones. |
59466 | Selects timbre of note. |
59467 | Controls volume and turns speaker on or off. |
59468 | Flips character set from only upper case with all graphics to entire alphabet with limited graphics characters. |
This is a short reminder of what the four parts of the VIC 40 program listing do, and which ones are actually needed to RUN VIC 40.
VIC 40 Entry: used only to enter the hex digits into the computer. After entering the digits, a version of VIC 40 is created for you on either disk or tape, ready to ultimately LOAD and RUN.
VIC 40 Hex: the VIC 40 in hex format. Use only for entry with the VIC 40 Entry program. After entering VIC 40, this is not used again.
VIC 40 Loader: actually boots the VIC 40 system. Must be located right before the main VIC 40 program on tape.
VIC 40 Demo: a demonstration of some of the power of the VIC 40. It is by no means a comprehensive study of all the program’s power, but it can point you in the general direction for grander things. Study it to gain insight on color control, simple hi-res plots, and overall character mixing. Feel free to use any of the routines within it in your original programs.
As I have shown, VIC 40 is a powerful addition to your library of software. Whether you use it to run PET software, to create hi-res text/graphics adventure games, or to do serious word processing, the VIC 40 can take the insanity out of using the normal 22 column display. Now your VIC can compete with its newer brother, the 64, as well as converse amiably with the older PET/CBM’s. The better of both computers can be found in your little old VIC 20, the computer that started the whole mass-marketed microcomputer revolution. Have fun with this program, and please remember to experiment to find out how VIC 40 can meet the best of your specific needs!