Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 9, NO. 12 / DECEMBER 1983 / PAGE 272

A monitor program for Vic 20. Warren Clark.

A Monitor Program For Vic 20

"What's a monitor program?' my sister asked. I had just returned to the family homestead for the Christmas holidays and had been very anxious to try out Janice's new Vic 20 computer. Naturally, I wasn't satisfied to play with Basic for very long, and I wanted to do some PEEKing around.

As an old Apple user, I was very surprised to find that the Vic did not come with a monitor program. I decided to write one for her. This article briefly explains the need for a monitor program, what it should do, and the structure and organization of this one.

To answer my sister's question as to what a monitor program is, we must first discuss what memory is. Almost everyone knows how many K of memory he has in his computer. Each K of memory represents 1024 bytes of information. Each byte has a unique location in the computer memory which is referred to as the address of the byte. Each of these bytes holds eight bits of information.

This information could represent any of a number of different things. The byte could represent part of a machine language program. It could represent the value of a variable or one character in a character string. It could also be a pointer to other information. There are pointers to the start of the Basic program, to the current line of the Basic program, to the start of variable storage, and all kinds of really neat and interesting things. The information that I wanted to look at on the Vic was the high-resolution bit patterns used by the Vic for writing characters on the screen.

If a programmer wants to examine or change these locations while writing a program, he can do so by using the PEEK and POKE commands. This can be very time consuming since the sequence PRINT PEEK (address) must be keyed for each byte being examined. Similarly, the sequence POKE address, value must be keyed for each value entered.

The problem passes the point of ridiculousness when a machine language program must be entered. The novice machine language programmer often does not have an assembler. Without an assembler, the programmer must assemble the program by hand, and then enter it by hand. Even a small program could require hundreds of POKEs followed by hundreds of PEEKs to verify that everything has been entered correctly.

A good monitor gets around these problems. It allows the programmer to examine memory locations sequentially. As each location is examined, the operator has the option of changing it or looking at the next one. A good monitor program also allows the operator to list a range of memory all at once. A third monitor feature allows the operator to move a range of memory to a new location in the computer. A final feature in a good monitor is the ability to execute and return from a machine language program.

Hex To Decimal And Back

Everything entered into or printed by the program is in hexadecimal. This is good because it allows the experienced user to visualize the actual bit patterns of the addresses and data. It is bad because the Vic manual gives most addresses and the contents of those addresses in decimal. To get around that problem, I decided that my Vic monitor would also provide utilities for hex to decimal and decimal to hex conversion.

Writing The Program

Given this set of requirements, I set out to write the monitor program. I wondered if it would be possible to write such a program in Basic. To be perfectly honest, I have never heard of a monitor program being written in anything but machine language. Unfortunately, writing it in machine language promised to be a very time-consuming task (especially considering that I would have had no good way of getting it into the machine until after it was already there). Also, I couldn't think of any reason not to write it in Basic, and I must admit that my laziness got the best of me.

The program consists of a primary loop, two secondary loops, and several subroutines called by these loops. All three of the loops look for various delimiters. These delimiters are actually the commands to the monitor program from the operator. Spacebands tell it to display a memory location. A return tells it to go back to the primary loop or if it is already in the primary loop to exit the monitor program. A period tells it to save what was just entered as an address for future use and to allow the operator to enter another address. The letters G, L, and M command the monitor to GOTO a particular location, LIST a range of memory, or MOVE a range of memory. H and T tell it to do a number conversion.

The primary loop (100-160) gets an input byte followed by a delimiter and branches accordingly.

If the primary loop finds a spaceband, it calls the examine and change subroutine (1000-1210). Examine and change displays the memory location, allows the operator the opportunity to change it, and then displays the next location. This process continues until the operator hits RETURN.

If the primary loop finds a period, it calls the period processing subroutine (3000-3080). Period processing allows the operator to enter up to two more addresses and then branches to either the list or the move subroutine.

If the primary loop finds any of the other control delimiters, it either performs the action directly or branches to a single subroutine which performs the action. Commands which are processed directly are the exit program and hex to decimal conversion. Commands which are processed by subroutines are those which execute machine language routines and convert from decimal to hex.

Two subroutines at the end of the program function as utilities for the loops and other subroutines. These are the input and output routines. The input routine nstarting at 9000) gets a hexadecimal character string from the keyboard. It allows characters to be entered until it encounters a nonhexadecimal character. When it does find the non-hex character, it returns. When it returns, the value of the hex string is held in variable IV. If no hex characters were entered, IV returns a value of negative one.

The second utility subroutine (starting at 9100) is for output. It outputs the hexadecimal value held by IV. It gives the output string a length which is one greater than the value in I. In other words, if I holds a value of 1, a two-character sequence will be produced; if I holds a value of 3, a four-character sequence will be set to the screen.

Compatibility

One additional note is in order at this point. Line 2020 varies depending on host machine. This is a case where "standard' Basic is not standard. In Applesoft, for example, the command to execute a machine language routine is CALL. On the Vic 20, the command is SYS. Because my Apple is equipped with a disk drive and a printer, I used it for the program development effort. That one line was the only incompatibility between the two programs. Although I haven't tried it, I presume that this program will work on most other small computers, as well.

Table: Listing 1.