in BASIC ROM:
|List of all BASIC keywords|
Typ: Command General Programming-Syntax: SYS <memory adress>
SYS is a command in Commodore BASIC V2, hands the CPU over to a the machine language subroutine at a specific address. The <Address> parameter is a 16-bit unsigned integer, i.e. an integer in the range 0 thru 65535, or $0000 thru $FFFF. If the given address is outside these limits, the C64 will report an ?ILLEGAL QUANTITY ERROR.
Passing parameters via registers
Before calling the specified address, SYS “loads” the accumulator, the X and the Y index register, and the status register with the bytes stored at addresses 780–783/$030C–030F: From BASIC, one can set up parameters and data here, to be processed by the machine language routine.
If or when the routine at the specified address returns control to BASIC (via an RTS instruction), SYS immediately saves the contents of the accumulator, the X and Y index registers and the status register, back into the 780–783 memory range: This can be used to transfer results from the machine language routine to BASIC for further processing.
Passing parameters through BASIC
In order to pass parameters from BASIC to the machine code routine, one can also exploit the “mechanisms” in BASIC ROM that handles parameters in other BASIC commands, using routines like e.g.
- CHKCOM (at 44797/$AEFD) which checks that the next character in the command is a comma
- GETBYT (at 47006/$B79E) which reads an unsigned byte parameter
- GETPAR (at 47083/$B7EB) which reads a 16-bit unsigned integer parameter followed by a comma followed by an 8-bit unsigned integer parameter
Start a machine code program, which is beginning at memory map address 49152 ($C000).
POKE 211,R :POKE 214, LN: SYS 58640
Using a system routine, which is positioning the cursor at row (R) and line (LN)