Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎


Keyword Abbreviation Token (hex) Version(s) Classification
MONITOR M{Shift+O} FA 3.5 Command and Statement*
MONITOR MO{Shift+N} FA 7.0 Command and Statement*

MONITOR junk ]
Parameters Type Legal Value(s) Default Value Note(s)
junk any any Ignored
State management.  Exit BASIC interpreter and enter the machine-language monitor.

MONITOR is the BASIC command to enter the built-in machine-language (ML) monitor.  This will (usually) not invoke an add-on ML monitor which has been loaded into RAM or is stored in an external cartridge.  Bug: on the C128, entering the ML monitor by any means will most likely corrupt BASIC's DS and DS$ because the ML monitor uses the string descriptior of DS$ as a temporary work space when parsing entered commands.
Although MONITOR is only available in version 3.5 and 7.0, some other machines have a built-in ML monitor.  On the PETs with BASIC 4.0, SYS 4 might call up the built-in ML monitor.  On the CBM-II series (BASIC 4.7) using SYS 5 will often enter the built-in ML monitor.  On these machines, the SYS is jumping to an opcode which cause the ML monitor to be called due to a CPU "break" opcode.  However, there is no gaurantee a zero will be at the given address so strange things may happen.  This is why a MONITOR keyword is a good thing.
Older versions of BASIC don't have an ML-monitor in ROM.  For the C64 (maybe VIC-20 too), I recommend SuperMon by the late Jim Butterfield.  His ML monitor is nearly identical to the one in the C128 (BASIC v7.0), but does not allow a bank number (the C64/VIC-20 do not have multiple banks).
* Although MONITOR may be used as a statement in a program, it clears the secret variable "Run Mode" so if you return to BASIC, the program will normally not continue.  You might be able to change some secret variables while in the ML monitor so the program would continue, but this would be very machine-specific.  Using the SYS method to enter the ML monitor might allow the BASIC program to continue, but the CPU stack pointer would need to be fixed due to the data pushed by the "break" opcode.
On any machine with an ML monitor, weather it is a built-in or installed by the user, the monitor will normally be called up automatically with the word BREAK or similar along with a display of registers if the CPU ever executes a BRK opcode (byte value 0).  On machines without an ML monitor, this will cause BASIC to soft-reset (like pressing STOP + Restore).
Below is a short list of commands available in the ML monitor.  The most important one for BASIC users is X.  Type this character and press RETURN to get back to BASIC.  Several of the commands are not available on the 4.x series of the ML-monitor or may work a bit differently.  In particular, they generally require an address to be entered as a 4-digit hexadecimal number (i.e., leading zeros are required).  On the otherhand, the C128 (v7.0) allows (does not require) a 5-digit hexadecimal number.  In these cases, the first digit is the BANK number and the remaining four digits are the normal 16-bit address.
In all the ML monitors, the default input of numbers is hexadecimal.  In version 7.0 and with SuperMon, you may also use a decimal value by prefixing the number with a + or use a binary value with a prefix of % or an octal value with a prefix of @.  You can also prefix a number with $ for hexadecimal, but because that is the default radix it is normally not needed.  The one exception is the number conversion feature: enter only a number with a prefix (i.e., no command) and the number will be listed in all forms (binary, octal, decimal, hexadecimal).  This is nice because no CBM BASIC has a BINARY function, and many versions of BASIC don't have the DEC and HEX$ functions either.  I don't know why you'd need octal, but there it is anyway!  See examples.
In all the ML monitors, spacing is often critical due to very simple parsing.  I will not go into the details of any of the ML commands because they are outside the scope of BASIC.  I will say if there is an error in your command, the ML monitor simply prints a question mark (?).  You will have to figure out the cause of the error.
Read "disk" error/status channel:
deviceNumber ]
List "disk" directory:
deviceNumber ] ,$ [ parameters ]
Send "disk" command:
deviceNumber ] , command
Set CPU registers:
PC [ P [ A [ X [ Y [ S ] ] ] ] ]
Enter byte(s) into memory:
addressStart byte ] ...
Assemble a 6502 instruction:
A address opcode [ operand [ , register ] ]
Compare bytes in memory:
C sourceStart sourceEnd compareStart
Disassemble memory:
D addressStart [ addressEnd ]
Fill memory:
addressStart addressEnd fillByte
GOTO an ML program (JMP):
Hunt (search) for byte(s) in memory:
addressStart addressEnd wantByte [ , wantByte ] ...
GOSUB an ML program (JSR):
Load a "file" (filename may only be omitted with cassette):
L [ "filename" [ , deviceNumber [ , loadAddress ] ] ]
Display a range memory:
addressStart [ addressEnd ]
Display CPU registers:
Save a "file" (limitAddress = endAddress + 1):
Transfer (copy) bytes from a range in memory to another location:
sourceStart sourceEnd copyStart
Verify memory with a "file" (filename may only be omitted with cassette):
V [ "filename" [ , deviceNumber [ , loadAddress ] ] ]
Exit the ML monitor (return to BASIC):

; FB000 00 FF FF FF F8
$400               list the hexadecimal value '400' in every radix
+400               list the decimal value '400' in every radix
X                  return to BASIC

  Compare With  
  Contrast With  
  See Also  

© H2Obsession, 2014, 2015