Home > CBM > BASIC > Keywords > St
180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Usr, Val, Verify, Vol, Wait, While, Width, Window, Xor

KeywordAbbreviationToken (hex)Version(s)Classification
STnone53 541.0+Reserved variable
Note the 'token' is really the character codes of the keyword.

  Syntax  
ST

ReturnsTypeValue(s)Note(s)
deviceStatusSigned 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.

DeviceBit NumberBit ValueNote(s)
cassette24short block
cassette38
long block
cassette
4
16parity error (read); byte mismatch (verify) 
cassette532
checksum error 
cassette664 
end of file
cassette7128end of tape 
IEEE/IEC bus01time out write (device did not acknowledge data) 
IEEE/IEC bus12time out read (device did not respond to request) 
IEEE/IEC bus4 16 verify error 
IEEE/IEC bus664end-or-identify (end of file)
IEEE/IEC bus7 128device not present 
RS-2320 1 parity error
RS-23212framing error (missing stop bit) 
RS-232 24 receiver buffer overflow 
RS-232 3 8 receiver buffer empty 
RS-232 4 16 CTS missing 
RS-232 6 64 DSR missing 
RS-232 7 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 a certain bit  of the secret variable "enable" is clear [i.e., test ( value AND mask ) = 0].  Here is the location of that secret variable for some machines:

MachinePEEK AddressMask Value
C12825751
C161998
64769
128
16
C646731
CBM-II??
PET??
Plus/41998
64769
128
16
VIC-206731

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

Example for RS-232 on Plus/4:
10 OPEN 2,2,0,CHR$(6)
20 PRINT #2,"HELLO MODEM"
30 S = ST : IF (S AND 255-8)=0 AND (PEEK(1998) AND 128)=128 THEN 30 : REM wait buffer
40 IF S AND 255-8 THEN PRINT "ERROR";S :REM no error if receiver empty
50 IF PEEK(64769) AND 16 THEN 50: REM wait hardware
60 CLOSE 2

  Compare With  
DS, ER, TI

  See Also  
CMD, CLOSE, GET#, INPUT#, OPEN, PRINT#,  Secret Variables


© H2Obsession, 2014