STATUS

From C64-Wiki
Jump to: navigation, search
BASIC keyword
Keyword: STATUS
Abbreviation: -
Type: Command
Token code: -/$-
Handling routine
in BASIC ROM:
-–-
$-–-
List of all BASIC keywords


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

Typ: Numeric system variable
General Programming-Syntax: STATUS or ST

The system variable STATUS (short: ST) is used for querying the system state after data input and output on various peripherals like datasette, serial bus devices such as floppy disk drive and printer. By using this I/O devices the KERNAL generats a numeric value in the range from -128 to +127 (0 to 255 if ANDed with 255, respectively) which is directly derived from the memory byte located at address $0090 (144).

Implementation notes:

  • The significant part of the variable name is just ST. Any letter or digit combination following still refers to this system variable. The long written name STATUS is used only by convention. E.g. STAT or STATUE and every other name beginning with ST refers to this system variable.
  • This variable is read-only. An assignment to it raises a ?SYNTAX ERROR. This may lead to confusion if one uses a variable like START (which is also ST) and tries to assign a value to it, which unexpectedly shows an error.

STATUS bits and values[edit]

Depending on the device and executed operation the corresponding bit in the STATUS variable is set as a result.

STATUS
Bit
Bit-
Value
Datasette Serial Bus RS-232
0 1 - indicates data direction if a timeout occurred
0 = reading, 1 = writing
parity error
1 2 - timeout error framing error
2 4 block was too short
(less than 192 bytes)
- recieve buffer overrun
3 8 block was too long
(greater than 192 bytes)
- recieve buffer empty
4 16 VERIFY error
(errornous read bytes from pass 1 could not read correctly even in pass 2)
VERIFY error CTS signal missing
5 32 checksum error - -
6 64 end of file has been reached
(only while reading)
end of file has been reached RTS signal missing
7 128 - device not present error BREAK detected

Examples[edit]

Directmode:

PRINT STATUS

The value of STATUS is taken from memory location at address $0090 and can be viewed with following BASIC snippet:

PRINT PEEK(144)

Value may appear as negative value because of BASIC implicit sign expansion. To get unsigned results (in range 0 to 255) use

PRINT ST AND 255

To check only a distinct bit (according to the table above) mask the desired bit like this

PRINT ST AND 64

Prints 64 in case the end of file has been reached, otherwise 0.
Note: the blank after "ST" prevents the tokenizer from recognize it as STAND 64, which leads to a ?SYNTAX ERROR (because BASIC tokens like TAN are favored against variable names).

In Programs:

10 REM FILE TEST
20 OPEN 1, 8, 4, "TESTFILE,SEQ,W"
30 IF ST <> 0 THEN PRINT "FILE ERROR"
40 IF ST = 0 THEN PRINT "FILE EXISTS"
50 CLOSE 1

This program is using STATUS to recognize the end-of-file condition even in case of errors. It opens a text file, reads the contents byte by byte and prints these bytes on the screen. If the file has been read without errors STATUS has the end-of-file bit 6 set. This condition is checked and the output "OK" is given if no error occurred.

10 REM READ FILE
20 OPEN 1,8,2,"0:TEXT FILE,S,R": REM OPEN FILE FILE
20 FOR S=0 TO 1: REM INFINITE LOOP, WHILE S = 0 
30 GET#1,A$: REM READ A BYTE
40 PRINT A$;: REM VIEW THE BYTE ON THE SCREEN
50 S=255 AND ST: REM I NOT EQUAL TO 0 WHEN BIT 6 IS SET (END OF FILE)
60 NEXT S : REM LEAVE IF S > 0
70 CLOSE 1: REM CLOSE FILE
80 IF S AND 64 THEN PRINT "OK"


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