Wouldn’t it be nice if we could start a memory monitor from within our C program? For example if we want to see where the program counter is, what value a certain memory address holds, or what a machine language subroutine stores in the registers?
Even in a virtual environment with VICE it might be nice to start the memory monitor we know well. The build-in memory monitor in VICE might be too powerful with too many commands.
There are plentiful memory monitors out there. I found out that Micromon from Bill Yee is working fine for my purpose. I am using the one starting at RAM address 0x9000, this should give our C program enough space to coexist.
There is a detailed explanation on how Micromon works in the book „COMPUTE!’s First Book of COMMODORE 64“. Other memory monitors I tested like SMON and SuperMon are not careful with the stack; a return from the memory monitor back into the C program is not always possible. With SMON, I could only jump back to the shell of POWER C.
Before we write C code to start Micromon, we have to load Micromon into memory:
LOAD"MICROMON9000",8,1
We can now write a piece of C code that calls the memory monitor whenever we wish. The following code demonstrates how the concept works:
/* Calling micromon from POWER C */
/* Jan Klingel, 04/2026 */
#include <stdio.h>
#include <strings.h>
#include <poke.h>
#define MMON 0x9000
#define SMON 0x9e72
int main(void) {
/* Tell C to stay out of the memory */
/* area of Micromon */
highmem(MMON);
char a;
printf("\nC program is doing something...\n");
printf("Start Micromon now? (y/n) ");
scanf("%c", &a);
switch(a) {
case 'y':
/* Start the memory monitor */
if(startMMON() != 0) {
printf("Micromon could not be started!\n");
return(1);
}
break;
default:
break;
}
printf("\nC program continues!\n");
return(0);
}
Now we need a function startMMON() to jump to address MMON and execute machine language code there. MMON is the start address of Micromon, SMON is the memory address where the banner „MICROMON“ is stored. If we detect this banner at address SMON, we assume that Micromon has been loaded.
The function startMMON() looks like this:
int startMMON(void) {
int i;
static char ts;
char banner[9];
/* Read 8 bytes from address SMON*/
for(i=0;i<=7;i++)
banner[i] = peek(char,SMON+i);
/* Terminate the string */
banner[8] = '\0';
/* Test if Micromon is in memory */
if(strcmp(banner, "micromon")!=0) {
return(1);
}
else {
printf("Micromon starting\n");
char a, x, y;
sys(MMON, &a, &x, &y);
}
return(0);
}
The core of this function is the sys command. In POWER C, this lets us jump to a certain memory address and start executing machine language code. a, x, and y are the registers of the MOS 6502 CPU. We can set these registers before calling the machine language code, but the machine language code can also return values to the POWER C program using these registers.
I called my C program „micromon.sh“. After starting it from the shell, the above C program is asking me if I would like to start Micromon:

A ‚y‘ and enter will start the memory monitor:

After printing the banner, Micromon wil display the program counter, IRQ address, the registers, and other values. With the command
m 9000 9010
I asked Micromon to display the content of memory addresses 0x9000 to 0x9010.
d 9000 9010
disassembles the same memory address range. ‚x‘ jumps back to the C program, which prints „C Program continues!“.
Note that after loading Micromon into memory at the beginning, a BASIC NEW command is necessary before the POWER C shell is loaded:
LOAD"MICROMON9000",8,1
NEW
LOAD"SHELL",8,1
RUN
If we link the C program with the -s parameter, the program works even from the BASIC command line:
$ link -s
> micromon.o
> ARROW-UP
> ENTER
output file name: micromon
$ bye
Now the compiled C program can be started from the BASIC prompt:

And Micromon starts up:
