SYS

From C64-Wiki
Jump to: navigation, search
BASIC keyword
Keyword: SYS
Abbreviation: S Shift+Y
Type: Command
Token code: 158/$9E
Handling routine
in BASIC ROM:
57642–57685
$E12A–E155
List of all BASIC keywords


Remark: This article describes the BASIC-Command SYS in BASIC V2 at the Commodore 64.

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[edit]

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[edit]

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

Examples[edit]

SYS 64738 
Reset
SYS 49152
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)
BASIC V2.0 (second release) Commands

ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | π  |POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT