Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

ST

Keyword Abbreviation Token (hex) Version(s) Classification
ST none 53 54 1.0+ Reserved variable
Note the 'token' is really the character codes of the keyword.

  Syntax  
ST
 
Returns Type Value(s) Note(s)
deviceStatus Signed Byte
-128 ~ 127
Device specific 
 
  Purpose  
Get I/O status byte.
 
  Remarks  
This reserved variable returns the KERNAL's I/O status byte corresponding to the last (non-screen, non-keyboard) communication (such as CMD, GET#, INPUT#, OPEN, or PRINT#).  The meaning is a device-specific combination of bit values (see table below), but it is important to note that for RS-232 devices, the ST value will be zeroed once it is accessed; in other words you should save ST in a user variable if you want to perform multiple operatons on the value (like test multiple bits seperately and/or print the value).  In general, any non-zero value means some kind of "error" or other special condition has been detected (like "end of file").
 
Also note the "real" deviceStatus maintained by the KERNAL is just a byte with value 0 to 255, but when reading ST, BASIC will interpret this as a signed byte for some obscure reason... This means if the the (unsigned) byte has a value of 128 or more (i.e., bit 7 is set), ST will report a deviceStatus of -128 to -1.  Due to the way signed bytes work, you can easily convert ST into an unsigned value of 0 to 255 with (for example) S = ST AND 255 (be sure you have at least one space between ST and AND or BASIC will parse it as S = S TAN D 255 causing a SYNTAX ERROR).
 
Note bit values listed as '128' will by default be -128, but if you convert deviceStatus into an unsigned number it will be +128.
Device Bit Number Bit Value Note(s)
cassette 2 4 short block
cassette 3 8
long block
cassette
4
16 parity error (read); byte mismatch (verify) 
cassette 5 32
checksum error 
cassette
6 64 
end of file
cassette
7 128 end of tape 
IEEE/IEC bus 0 1 time out write (device did not acknowledge data) 
IEEE/IEC bus 1 2 time out read (device did not respond to request) 
IEEE/IEC bus 16  verify error 
IEEE/IEC bus 6 64 end-or-identify (end of file)
IEEE/IEC bus 7 128 device not present 
RS-232 parity error
RS-232 1 2 framing error (missing stop bit) 
RS-232  2 receiver buffer overflow 
RS-232  receiver buffer empty 
RS-232  16  CTS missing 
RS-232  64  DSR missing 
RS-232  128  Break detected 
 
Unfortunately, the ST variable does not tell you when the RS-232 transmit buffer is empty!  It does tell you when the receive buffer is empty, but this usually isn't very important because BASIC GET# will simply fetch an empty string if it is.  In order to know if the transmit buffer is empty (so you can safely CLOSE a "file" without loosing data), you need to test if bit 0 of the secret variable "enable" is clear [i.e., test ( value AND 1 ) = 0].  Here is the location of that secret variable for some machines:
 
Machine PEEK Address for RS-232 "Enable"
C128 2575
C16 none?  check 1998 and 2000 for less than 128 ?
C64 673
CBM-II ?
PET
?
Plus/4
none?  check 1998 and 2000 for less than 128 ?
VIC-20 673
 
Like all BASIC variables, only the first two characters of the name are significant.  So you may also use (and early documentation shows) STATUS if you prefer (note the "ATUS" characters are superfluous).  Like most BASIC reserved variables, attempting to assign a value to it or supply an argument will generate SYNTAX ERROR.
  
Example (for cassette):
10 OPEN 2,1,0,"CASSETTE FILE"
20 GET#2,A$ : PRINT A$;
30 IF ST=0 THEN 20
40 IF ST AND 255-64 THEN PRINT "ERROR";ST :REM no error if end-of-file
50 CLOSE 2

  
Example (for disk):
10 OPEN 2,8,8,"DISK FILE"
20 GET#2,A$ : PRINT A$;
30 IF ST=0 THEN 20
40 IF ST AND 255-64 THEN PRINT "ERROR";ST :REM no error if end-of-file
50 CLOSE 2

 
 
Example for RS-232 on C64:
10 OPEN 2,2,0,CHR$(6)
20 PRINT #2,"HELLO MODEM"
30 S = ST : IF (S AND 255-8)=0 AND (PEEK(673) AND 1)=1 THEN 30 : REM wait transmit
40 IF S AND 255-8 THEN PRINT "ERROR";S :REM no error if receiver empty
50 CLOSE 2
 
 
  Compare With  
DS, ERTI
 
  See Also  

© H2Obsession, 2014
Comments