An Enhanced Machine Language Monitor
R. Arthur Cochrane Beech Island, SC
Editor's note: Micromon is for Upgrade and 4.0 BASICs, all memory sizes, all keyboards and is in the public domain. We present it here because many readers live where there are no computer clubs to permit the exchange of public domain programs. If you have enough memory, you can add the additional commands of "Micromon Plus" as well. "Plus" is from $5B00 to $5F48 and you will want to move Micromon from $1000 up to $6000.
There is quite a bit of typing here so we've provided two checksum programs which will find and flag any errors. If you are unfamiliar with machine language programming, see the instructions for typing in "Supermon" in last month's COMPUTE!, page 134. — RTM
For those who may not know what Micromon is, I will start with a little background. Micromon started as Extramon which is an extended machine language monitor for the TIM monitor in the PET. Extramon was originally written by Bill Seiler. It is for Upgrade BASIC and has the following commands;
A — A simple one line assembler.
B — Set a break point.
C — Compare two ranges of memory and print the addresses of any differences.
D — Disassemble a range of memory.
F — Fill a range of memory with a byte.
H — Hunt a range of memory for a certain HEX or ASCII pattern and print the addresses where they occur.
I — Do a memory dump or a range of memory by printing the HEX and ASCII values.
N — New Locate a machine language program by adding an offset to the three byte instructions.
Q — Start execution of a machine language program and stop execution when the break point is reached.
T — Transfer a range of memory to another part of memory.
W — Single step execution of a machine language program.
Extramon loads into the address range $1000 to $17FF, but the T and N commands can be used to relocate Extramon to another part of memory.
Micromon is an improved version of Extramon and is also by Bill Seiler. Micromon has the same commands as Extramon plus those of the TIM monitor and works on Upgrade BASIC and BASIC 4.0. It works on both BASICs because only 4 ROM routines are used, two of these routines are in the jump table at the top of memory and the other two used by Micromon are found by checking a location to determine the BASIC. The ability to use the up and down cursor control keys to scroll the memory dump and disassembler is added.
Now Micromon has been improved by the addition of more instructions to make it a full 4K program. The following instructions have been added:
E — Kill Micromon by restoring the TIM break vector and IRQ vector and return to BASIC.
K — Kill Micromon by restoring the TIM break vector and IRQ vector and do a BRK to the TIM monitor.
O — Calculate a branch instruction offset given a starting and target address.
Z — Change to the opposite character set from the one currently in use.
$ — Print the decimal value, the ASCII values for the two bytes, and the binary value for an input HEX value.
# — Print the HEX value, the ASCII values for the two bytes, and the binary value for an input decimal value.
% — Print the HEX value, the decimal value, and the ASCII values for the two bytes for an input binary value.
" — Print the HEX value, the decimal value, and the binary value for an input ASCII value.
+ — Add two HEX numbers.
- — Subtract two HEX numbers.
& — Print the checksum for a range of memory.
An additional module (Micromon Plus) to work with Micromon is also available. This module is about an additional 1K of program and it has the following commands:
I — Set form feeds and a heading for disassemblies and memory dump printouts.
P — Switch output to a printer for hard copy disassemblies and memory dumps.
J — Print the address at which a file loads.
Y — Load a file starting at a specific address and not the load address in the file.
> or @ — The DOS commands for reading the disk error channel, sending commands to the disk, or displaying the disk directory.
Micromon is very useful for debugging machine language programs. The disassembler allows the code to be examined and the single step command allows following the execution of code to spot bugs. The Transfer and New Locate commands allow code to be relocated to another part of memory without the need for reassembly. Micromon is a must for any PET machine language programmer.
There are several extended monitors available for the PET. Supermon is one example. Most of the other monitors have some of the same commands as Micromon and maybe a few others. One of the problems with these monitors is that there are different versions for Upgrade BASIC and BASIC 4.0. Micromon will work, as is, on either BASIC. It does not work on Original BASIC though it might be possible to modify it. There is a version of Supermon for each of the three BASICs if a super monitor is needed for Original BASIC.
Because the VIC-20 has Upgrade Basic it will be possible to modify Micromon for VIC use, giving it a powerful machine language monitor. The modification will involve checking the subroutine calls and modifying the scroll for the screen size of the VIC. If anyone is successful in this modification they should be sure to publish the results for others. Because the full Micromon is a 4K program, it would be a good program for programming into a VIC plug-in program cartridge.
Micromon is free (so is Supermon), but where do you get it? A PET user group is one source. For those who would like source code, Micromon source code in Carl Moser's MAE assembler format is available. Micromon can be assembled and burned into an EPROM and plugged into an empty socket in the PET so Micromon is available with a SYS and does not have to be loaded each time the PET is reset or powered up.
I hope that you will pass Micromon on to your friends. This program is in the public domain and should be passed around freely. If anyone finds bugs or has comments please contact me about them.
I would like to thank James Strasma for all the information which he provided me for this work on Micromon.
Note To Other 6502 Users
Because Micromon uses only four ROM routines (input a character, output a character, load a program, and save a program) and a few zero page locations (IRQ vector, BRK vector, and screen line pointers) it may be possible for Apple, Atari, or other 6502 users to modify Micromon for their machine. If someone is successful at this be sure to pass the information on to others.
.A 2000 A9 12 LDA#$12 .A 2002 9D 00 80 STA $8000,X .A 2005 DEX:GARBAGE
In the above example, the user started assembly at 2000 HEX. The first instruction was load a register with immediate 12 HEX. In the second line the user did not need to type the A and address. The simple assembler retypes the last entered line and prompts with the next address. To exit the assembler, type a return after the address prompt. Syntax is the same as the Disassembler output. A colon (:) can be used to terminate a line.
.B 1000 00FF
The example sets a break at 1000 HEX on the FF HEX occurrence of the instruction at 1000. Break set is used with the QUICK TRACE command. A BREAK SET with count blank stops at the first occurrence of the break address.
.C 1000 2000 C000
Compares memory from HEX 1000 to HEX 2000 to memory beginning at HEX C000. Compare will print the locations of the unequal bytes.
DISASSEMBLER .D 2000 3000 ., 2000 A9 12 LDA#$12 ., 2002 9D 00 80 STA $8000,X ., 2005 AA TAX
Disassembles from 2000 to 3000. The three bytes following the address may be modified. Use the CRSR KEYS to move to and modify the bytes. Hit return and the bytes in memory will be changed. MICROMON will then disassemble that line again.
Disassembly can be done under the control of the cursor. To disassemble one at a time from $1000.
If the cursor is on the last line, one instruction can be disassembled for each pressing of the cursor down key. If it is held down, the key will repeat and continuous disassembly will occur. Disassembly can even be in reverse! If the screen is full of a disassembly listing, place the cursor at the top line of the screen and press the cursor up key.
Combine the killing of MICROMON and exit to BASIC.
.F 1000 1100 FF
Fills the memory from 1000 HEX to 1100 HEX with the byte FF HEX.
Go to the address in the PC Register display and begin run code. All the registers will be replaced with the displayed values.
Go to address 1000 HEX and begin running code.
.H C000 D000 READ
Hunt thru memory from C000 HEX to D000 HEX for the ASCII string "read" and print the address where it is found. Maximum of 32 characters may be used.
.H C000 DO0O 20 D2 FF
Hunt memory from C000 HEX to D000 HEX for the sequence of bytes 20 D2 FF and print the address. A maximum of 32 bytes may be used. Hunt can be stopped with the STOP key.
Restore the Break vector and IRQ that was saved before MICROMON was called and break into the TIM monitor. A return to MICROMON can be done with a Go to the value in the PC register.
.L "RAM TEST",08
Load the program named RAM TEST from the disk. Note for cassette users: To load or save to cassette. Kill MICROMON with the K command to return to the TIM monitor. Then use the TIM monitor L and S commands to load and save to the cassettes. This has to be done because of the repeat keys of MICROMON. BASIC 4.0 users then can return to MICROMON with a Go command to the PC value but BASIC 2.0 users should return to BASIC then SYS to Micromon because the TIM overwrites the IRQ value for loads and saves with a filename.
.M 0000 0008 .: 0000 30 31 32 33 34 35 36 37 1234567 .: 0008 38 41 42 43 44 45 46 47 89ABCDE
Display memory from0000 HEX to 0008 in HEX and ASCII. The bytes following the address may be modified by editing and then typing a RETURN.
Memory display can also be done with the cursor control keys.
.N 1000 17FF 6000 1000 1FFF .N 1FB0 1FFF 6000 1000 1FFF W
The first line fixes all three byte instructions in the range 1000 HEX to 1FFF HEX by adding 6000 HEX offset to the bytes following the instruction. New Locater will not adjust any instruction outside of the 1000 HEX to 1FFF HEX range. The second line adjusts Word values in the same range as the first line. New Locater stops and disassembles on any bad op code.
CALCULATE BRANCH OFFSET
.O 033A 033A FE
Calculate the offset for branch instructions. The first address is the starting address and the second address is the target address. The offset is then displayed.
.Q .Q 1000
The first example begins trace at the address in the PC of the register display. The second begins at 1000 HEX. Each instruction is executed as in the WALK command, but no disassembly is shown. The Break Address is checked for the break on Nth occurrence. The execution may be stopped by pressing the STOP and = (left arrow on business) keys at the same time.
.R PC IRQ SR AC XR YR SP .: 0000 E455 01 02 03 04 05
Displays the register values saved when MICROMON was entered. The values may be changed with the edit followed by a RETURN.
.S "1:PROGRAM NAME",08,0800,OC80
Save to disk drive #1 memory from 0800 HEX up to, but not including, 0C80 HEX and name it PROGRAM NAME. See note in LOAD command for cassette users.
.T 1000 1100 5000
Transfer memory in the range 1000 HEX to 1100 HEX and start storing it at address 5000 HEX.
Single step starting at address in register PC.
Single step starting at address 1000 HEX. Walk will cause a single step to execute and will disassemble the next instruction. Stop key stops walking. The J key finishes a subroutine that is walking then continues with the walk.
EXIT TO BASIC
Return to BASIC READY mode. The stack value saved when entered will be restored. Care should be taken that this value is the same as when the MONITOR was entered. A CLR in BASIC will fix any stack problems. Do not X to BASIC then return to MICROMON via a SYS to the cold start address. Return via a SYS to a BRK (SYS 1024) or SYS to the Warm start of MICROMON (Warm start = Cold start + 3) An X and cold start will write over the TIM break vector that was saved.
CHANGE CHARACTER SETS
Change from uppercase/graphics to lower/ uppercase mode or vice versa.
.$4142 16706 A B 0100 0001 0100 0010
A HEX number is input and the decimal value, the ASCII for the two bytes, and the binary values are returned. The ASCII control values are returned in reverse.
HEX conversion can also be scrolled with the cursor control keys.
.#16706 7142 A B 0100 0001 0100 0010
A decimal number is input and the HEX value, the ASCII for the two bytes, and the binary values are returned.
.%0100000101000010 4142 16706 A B
A binary number is input and the HEX value, the decimal number, and the ASCII values are returned.
."A 41 65 0100 0001
An ASCII character is input and the HEX value, decimal value, and binary values are returned. Because of the quote, the control characters can be determined also.
.+ 11112222 3333
The two HEX numbers input are added, and the sum displayed.
The second number is subtracted from the first number and the difference displayed.
.& A000 AFFF 67E2
The checksum between the two addresses is calculated and displayed.
|X||EXIT TO BASIC|
|Z||CHANGE CHARACTER SETS|
MICROMON also has repeat for all keys.
MICROMON is executed by the following: SYS 4096 as listed in Program 2 where it resides in $1000to$lFFF.
For 8032, make the following changes for MICROMON operation. In location the X stands for the start of MICROMON. Values in HEX.
|Location||Old Value||New Value|
|X3E7||08||10 To display 16 instead|
|X3EC||08||10 of 8 bytes.|
|XCFC||28||50 To fix scroll.|
|X681||24||00 To print all characters in Walk command.|
Micromon Plus Instructions
.(Shift) D 1000 1FFF
The same as the Disassembler but no ., printed before each line. Also the ASCII values for the bytes are output at the end of the line.
FORM FEED SET
Sets a form feed for printout. Gives 57 printed lines per page. Works with the Shift D and Shift M commands.
Sets form feed with a message to be printed at the top of each page.
Cancels form feed.
PRINT LOAD ADDRESS
.J "File name"
Read the load address of the file and print it in hex. Device number 8 is used.
KILL MICROMON ADDITIONS
Kill MICROMON and its additions and BRK to the TIM monitor. This is the same as the unshifted K command except now a G command will reinitialize MICROMON and the additions.
LOAD FROM DISK
.(Shift) L "Filename"
This is the same as the normal load command except that the disk (device #8) is used as the default, not the cassette.
PRINTING MEMORY DUMP
.(Shift) M F0O0 F100
The same as the normal Memory dump, but does not print the .: and prints out 16 hex bytes and the ASCII for them.
If the output is to the CRT then switch the output to the printer (device #4). If the output is not the CRT then clear the output device and restore the output to the CRT.
Make device #6 the output device if the current out put is the CRT.
SEND TO PROM PROGRAMMER
.U 06 7000 7FFF
This command will send out bytes to a PROM programmer on the IEEE bus. The first byte is the device number and the two addresses are the range of memory to output. A CHR$(2) is sent first to start the programmer. This is followed by the memory bytes as ASCII characters separated by spaces. After all bytes have been sent, a CHR$(3) is sent to stop the programmer. MICROMON then does a checksum on the range to compare against the programmer checksum. Although this is for a particular programmer, it could be modified for others.
SPECIFY LOAD ADDRESS
.Y 7000 "Filename"
This command allows a file to be loaded starting at the address you specify and not the load address it would normally load into. The disk (device #8) is used for loading.
TEXT FLIP FOR 8032 & FAT 40's
This is for 8032 and Fat 40's to go from Text to Graphics mode or vice versa.
.@ or .>
This reads the error channel from disk device number 8.
.@ disk command or .> disk command
This sends the disk command to disk device number 8.
This reads the directory from disk device number 8. The SPACE BAR will hold the display and any other key will start it again and the STOP key will return to command mode.
This command will print the control character of the ASCII character input.
Examples of controls:
|i||Tab set and clear|
MICROM ON ADDITIONAL INSTRUCTIONS
(Shift) D PRINTING DISASSEMBLER I HEADING AND FORM FEED CONTROL J PRINT LOAD ADDRESS (Shift) K KILL MICROMON ADDITIONS (Shift) L LOAD FROM DISK (Shift) M PRINT MEMORY DISPLAY P PRINTER SWITCHING U SEND TO PROM PROGRAMMER Y SPECIFY LOAD ADDRESS (Shift) Z TEXT/GRAPHICS FLIP > DOS SUPPORT COMMANDS @ DOS SUPPORT COMMANDS (Up arrow) CONTROL CHARACTERS