CLR

From C64-Wiki
Jump to navigationJump to search
BASIC keyword
Keyword: CLR
Abbreviation: C Shift+L
Type: Command
Token code: 156/$9C
Handling routine
in BASIC ROM:
42590–42637
$A65E–A68D
List of all BASIC keywords


Remark: This article describes the BASIC command CLR in BASIC V2 at the Commodore 64.

Type: Command
General Programming-Syntax: CLR

The BASIC-Command CLR deletes all variables, arrays, data read position from DATA lines, defined functions (DEF FN), return addresses of subroutines (GOSUB) and the state of loops (FOR and NEXT) by releasing the space in BASIC RAM and on stack previously allocated for those structures. Furthermore the state of open files (OPEN) and possibly buffered data for devices like diskette or datasette of the associated files gets lost because the data is freed.
The CLR action is part of the RUN command and releases the space which has been temporarily allocated before. The use of CLR after a user break or program break (STOP) prevents the continuation of a program with CONT.

The command does not allow any parameters. In case a parameter is given the execution terminates with the BASIC error message ?SYNTAX ERROR.

Examples[edit | edit source]

10 A=64 : B$="COMMODORE" : C%=128
20 PRINT B$ A "AND " B$ C% ; FRE(0)+65536
30 CLR
40 PRINT : PRINT B$ A "AND " B$ C% ; FRE(0)+65536
0 POKE 56,52: CLR: REM make some free space after the BASIC program area for sprite, character or sound data
10 A$=""         : REM the above usage of the CLR command MUST precede the first variable usage
20 POKE 13312,8  : REM this would be dangerous if the BASIC program area was not limited in line 0 or CLR was omitted - program code could be overwritten


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