CMD

From C64-Wiki
Jump to navigationJump to search
Disambiguation The title of this article is ambiguous. CMD (Disambiguation).
BASIC keyword
Keyword: CMD
Abbreviation: C Shift+M
Type: Command
Token code: -/$-
Handling routine
in BASIC ROM:
-–-
$-–-
List of all BASIC keywords


Remark: This article describes the BASIC command CMD in BASIC V2 of the Commodore 64.

Type: Command
General Programming-Syntax: CMD <logical filenumber>[, [<expresson>] [ [ ";" ¦ "," ]<expression>...] ]

The BASIC command CMD changes the data output from the screen to another peripheral device like datasette, modem, printer or disk drive. CMD can be used directly or in programs. The logical filenumber may lay in the range from 1 to 255 (reasonably < 128) and must be selected with the BASIC command OPEN. When CMD is used without the previous OPEN command, the BASIC error ?FILE NOT OPEN ERROR is reported. The logical filenumber used with CMD has to match the one from the previous OPEN command.

Further parameters introduced by a comma (,) follow the syntax and behavior known from PRINT.

After the BASIC command CMD is executed, all PRINT and LIST commands are performed on the selected peripheral device. The command PRINT#<logical filenumber> is necessary to direct the data output back to the screen (disables the CMD redirection) before the device is to be closed with the BASIC command CLOSE<logical filenumber>.

If a BASIC error occurs the data output is switched back to the screen, with the side-effect that a space characters will be sent to the logical file of the selected device. So the command sequence PRINT#<logical filenumber> followed by a CLOSE <logical filenumber> must be executed to effectively terminate the effect of CMD.

Caution: The usage of GET also terminates the CMD redirection.

Examples[edit | edit source]

Redirection of the BASIC program listing to a printer:

OPEN 1,4,7: CMD 4, "Test on printer capital/small letters in  program listing X": PRINT: LIST 
PRINT#1: CLOSE 1: REM finishing the redirection of the data output

Writing a sequential file with exactly 50 characters on datasette just by using PRINT:

10 OPEN 1,1,1, "TESTFILE": CMD 1,;: REM without any output
20 FOR X=1 TO 50: PRINT "A";: NEXT X
30 PRINT#1,;: CLOSE 1: REM finishing the redirection of the data output

A demonstration of the crucial function of the semicolon in line 110 and 140, which suppresses the output of a line break (a CHR$(13)):

100 OPEN 3,3
110 CMD 3, "TEST";
120 PRINT "TEXT"
130 PRINT "DEMO"
140 PRINT#3,;
150 CLOSE 3
160 PRINT "END";

This is the output on screen:

RUN
TESTTEXT
DEMOEND
READY.


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