The SYS command in Commodore 64 BASIC starts a machine language subroutine stored on specified absolute memory location. For example,
starts a program that is stored in the famous 4-kilobyte memory bank, $C000 and forward. It can be used to start programs anywhere in memory, no matter how ridiculous it may be. It is particularly useful for calling system routines in Kernal (sic) ROM, for example,
performs a warm boot from a BASIC program. Mysterious BASIC routines can also be called, but that'd often be somewhat pointless =)
The routine is expected to end with an RTS instruction. Upon encountering RTS, the BASIC interpreter resumes control (itself, of course, being implemented in machine language and implementing the SYS command with a JSR instruction!)
SYS command can also take parameters, as in
SYS 49152,20,A%,6942 - the first one is the address of the routine, the rest are left for the subroutine to process. This provides a great way of passing parameters to m/l subroutines - the alternative would be POKEing values and reading them back in the routine. Clean!
In order to read these parameters, you need to first
JSR $AEFD - this will check that the SYS command is followed by a comma, and if it isn't, the program execution will end with ?SYNTAX ERROR. This comma check is also provided by some other subroutines:
- Read two parameters, separated by comma. First parameter is a word, stored to $14 and $15; the other is a byte, stored to X register.
- Read a byte (and store to X), check for a following comma.
- Read a byte (and store to X).
- Read a word, store to $14 and $15. Datatype check routine at $AD8A must be called beforehand.
- Read a variable pointer. Address of the variable is stored to $47 and $48, name of the variable is stored to $45 and $46.
- If both variable name bytes have bit 7 set, it's an integer (%), stored as highbyte + lowbyte.
- If only the second one has bit 7 set, it's a string, stored as string length + address of the string as Lowbyte+Highbyte.
- If neither has bit 7 set, it's an untyped (float?) variable. Floats are stored as exponent + 4 byte mantissa.
(Note: this information was paraphrased from MikroBitti 11/86, I have not tested it yet myself - there may be errors. /msg me corrections =)