Classic Computer Magazine Archive COMPUTE! ISSUE 87 / AUGUST 1987 / PAGE 8

Commodore Monitor Commands

I have been trying to teach myself to program in machine language, but I haven't been able to figure out how to get my monitor to save the programs I write. I am using a program called "Supermon 64."

Cliff Anderson

All Commodore machine language monitor programs use similar commands for saving, but the syntax differs slightly from one monitor to the next. Say that you want to save a program that occupies memory locations $C000–$C020. Here is the syntax to use from "Supermon 64:"

.S "TEST", 08, C000, C021

(The monitor program supplies the period at the beginning of the command; you type the rest.)

Of course, you would substitute your filename for TEST. The S command stands for Save, and the name inside quotation marks can be any legal Commodore filename. After the filename come three parameters: the device number (use 08 for disk, 01 for tape), the starting address, and the ending address. Notice that the ending address is actually one byte beyond the last byte that you want to save. This peculiarity is common to most Commodore monitors. If you are using the Commodore 128's built-in machine language monitor, the syntax of the save command is the same, except that commas are not needed and you need not put a leading zero in front of the 8.

Here's the syntax for saving the same program using "Micromon," another popular Commodore 64 monitor:

.S C000 C021 "TEST" 08

All the same parameters are present, simply in different order. Whereas Supermon 64 insists that the last four parameters be separated by commas, Micromon expects them to be separated by spaces. Other monitors may use a slightly different syntax.

To load a file, you need only specify the filename and device number. Here is a typical monitor load command:

.L "TEST", 08

Again, some monitors may expect to see the device number in front of the filename, or they may insist on a space where the comma appears. Note that all loads from a monitor are nonrelocating: The data goes into the same memory area it was originally saved from.

Another useful trick is knowing how to divert the monitor's output to a disk file or to a printer. If you're examining a long program, for instance, it's much easier to deal with a printed disassembly rather than a disassembly on the screen. The printout lets you see more than one screenful of information at a time and can also be annotated with comments.

A few monitors provide a separate command for printer output (typically, P) or one for generally diverting output (typically, O). Supermon and Micromon don't support printer output or general diversion, but there's still a way to accomplish the job. To illustrate; say that you are using Micromon, which starts at location 49152, and you want a printed disassembly of the first 32 bytes of the program, in locations $C000–$C020. After loading Micromon and performing a NEW, you could enter these commands and press RETURN:

OPEN 4, 4 : CMD 4

The OPEN statement opens a file to the printer (device 4) and the CMD statement diverts to the printer all output that would normally go to the screen. You'll have to type blind, for the most part: When you enter Micromon, you won't see the program's normal display, but characters which you type will still appear on the screen. Enter this command to start Micromon:

SYS 49152

If you are using Supermon and have previously installed it at its normal location, you would substitute SYS 38893 for the preceding command. In either case, you are now in the monitor; the program's normal register display goes to the printer rather than appearing on the screen. This command disassembles the bytes in locations $C000-$C020:

.D C000 C020

The printer prints a disassembly of those bytes and waits for your next command. Exit the monitor with X and then enter this statement to close the file to the printer:


The naked PRINT# statement is needed to insure that all printer output gets sent to that device. The resulting printout will contain a couple of superfluous READY statements in addition to the output from the monitor. Remember, CMD causes all output to be diverted, even BASIC prompts and error messages.

You can divert the monitor's output to a disk or tape file with the same technique. Just open the file before you enter the monitor. This session shows how to send a Micromon disassembly of the bytes in locations $C000–$C020 to a disk file named TEST:

OPEN 2, 8, 2, "0 : TEST, P, W" : CMD 2
SYS 49152
.D C000 C020

Again, you must take care to close the file properly after exiting the monitor. The same method works with Supermon 64; however, you should not start Supermon with RUN after opening the disk file, since RUN has the effect of closing all disk channels (although it doesn't properly close all open files). If you have not yet run Supermon, start it with GOTO 130 rather than with RUN. If it's already installed, restart it with SYS 38893. In much the same way, you can divert the output of other monitor commands such as M (Memory) and R (Registers) that normally print information on the screen.

Supermon 64 and Micromon are both public domain programs, available from many Commodore user groups and other public domain, sources. Supermon 64 is also included in Raeto West's Programming the 64, available from COMPUTE! Books.