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 |
| 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. ST | Returns | Type | Value(s) | Note(s) | | deviceStatus | Signed Byte | -128 ~ 127 | Device specific |
Get I/O status byte. 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 | | 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 | 4 | 16 | verify error | | IEEE/IEC bus | 6 | 64 | end-or-identify (end of file) | | IEEE/IEC bus | 7 | 128 | device not present | | RS-232 | 0 | 1 | parity error | | RS-232 | 1 | 2 | framing error (missing stop bit) | | RS-232 | 2 | 4 | 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 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
|
© H2Obsession, 2014 |