TTY(IV)                      5/27/74                      TTY(IV)


     tty - general typewriter interface


     All of the low-speed asynchronous communications  ports  use

     the  same  general  interface,  no  matter  what hardware is

     involved.  This section discusses the common features of the

     interface;  the  KL,  DC,  and  DH  writeups  (IV)  describe

     peculiarities of the individual devices.

     When a typewriter file is opened, it causes the  process  to

     wait  until a connection is established.  In practice user's

     programs seldom open these files; they are  opened  by  init

     and  become  a user's input and output file.  The very first

     typewriter file  open  in  a  process  becomes  the  control

     typewriter for that process.  The control typewriter plays a

     special role in  handling  quit  or  interrupt  signals,  as

     discussed  below.   The control typewriter is inherited by a

     child process during a fork.

     A terminal associated with one  of  these  files  ordinarily

     operates  in  full-duplex  mode.  Characters may be typed at

     any time, even while output is occurring, and are only  lost

     when  the system's character input buffers become completely

     choked, which is rare, or when the user has accumulated  the

     maximum  allowed  number  of input characters which have not

     yet been read by some program.  Currently this limit is  256

     characters.   When  the input limit is reached all the saved

     characters are thrown away without notice.

     When first opened, the interface mode is  300  baud;  either

     parity  accepted;  10  bits/character  (one  stop  bit); and

     newline action character.  The  system  delays  transmission

     after  sending  certain  function  characters.   Delays  for

     horizontal tab, newline, and form feed  are  calculated  for

     the  Teletype  Model  37;  the  delay for carriage return is

     calculated for the GE TermiNet 300.  Most of these operating

     states can be changed by using the system call stty(II).  In

     particular, provided the hardware permits, the speed of  the

     received  and  transmitted  characters  can  be changed.  In

     addition, the  following  software  modes  can  be  invoked:

     acceptance  of  even parity, odd parity, or both; a raw mode

     in which all characters  may  be  read  one  at  a  time;  a

     carriage return (CR) mode in which CR is mapped into newline

     on input and either CR or line feed (LF)  cause  echoing  of

     the sequence LF-CR; mapping of upper case letters into lower

     case; suppression of echoing; suppression  of  delays  after

     function  characters;  and  the  printing of tabs as spaces.

     See getty (VIII) for the way that terminal  speed  and  type

     are detected.

     Normally, typewriter input is processed in units  of  lines.

     This  means  that  a  program  attempting  to  read  will be

     suspended until an entire line has  been  typed.   Also,  no

     matter  how  many characters are requested in the read call,

     at most one line  will  be  returned.   It  is  not  however

     necessary  to  read  a  whole  line  at  once; any number of

     characters may be requested in a  read,  even  one,  without

     losing information.

     During input, erase and kill processing  is  normally  done.

     The  character  `#'  erases the last character typed, except

     that it will not erase beyond the beginning of a line or  an

     EOT.   The  character  `@'  kills  the entire line up to the

     point where it was typed, but not beyond an EOT.  Both these

     characters operate on a keystroke basis independently of any

     backspacing or tabbing that may have been done.  Either  `@'

     or  `#' may be entered literally by preceding it by `\'; the

     erase or kill character remains, but the `\' disappears.

     In upper-case mode, all upper-case letters are  mapped  into

     the  corresponding lower-case letter.  The upper-case letter

     may be generated by preceding it by `\'.  In  addition,  the

     following  escape  sequences  are  generated  on  output and

     accepted on input:

            for     use

             `       \'

             |       \!

             ~       \^

             {       \(

             }       \)

     In raw  mode,  the  program  reading  is  awakened  on  each

     character.   No  erase  or  kill processing is done; and the

     EOT,  quit  and  interrupt  characters   are   not   treated

     specially.   The  input  parity  bit  is  passed back to the

     reader, but parity is still generated for output characters.

     The ASCII EOT character may be used to generate  an  end  of

     file  from  a  typewriter.  When an EOT is received, all the

     characters waiting to be read are immediately passed to  the

     program,  without waiting for a new-line.  Thus if there are

     no characters waiting, which is to say the EOT  occurred  at

     the  beginning  of  a  line,  zero characters will be passed

     back, and this is the standard end-of-file indication.   The

     EOT is passed back unchanged in raw mode.

     When the carrier signal  from  the  dataset  drops  (usually

     because  the  user has hung up his terminal) a hangup signal

     is sent to all processes  with  the  typewriter  as  control

     typewriter.   Unless other arrangements have been made, this

     signal causes the processes to  terminate.   If  the  hangup

     signal  is  ignored,  any  read  returns with an end-of-file

     indication.  Thus programs which read a typewriter and  test

     for  end-of-file  on their input can terminate appropriately

     when hung up on.

     Two characters have a special meaning when typed.  The ASCII

     DEL character (sometimes called `rubout') is not passed to a

     program but generates an interrupt signal which is  sent  to

     all   processes  with  the  associated  control  typewriter.

     Normally each such  process  is  forced  to  terminate,  but

     arrangements  may  be made either to ignore the signal or to

     receive a simulated trap to an  agreed-upon  location.   See

     signal (II).

     The ASCII character  FS  generates  the  quit  signal.   Its

     treatment  is  identical to the interrupt signal except that

     unless a receiving process has made  other  arrangements  it

     will  not  only  be terminated but a core image file will be

     generated.  See signal (II).  If you find it  hard  to  type

     this character, try control-\ or control-shift-L.

     When one or more characters are written, they  are  actually

     transmitted  to  the  terminal as soon as previously-written

     characters  have  finished  typing.   Input  characters  are

     echoed  by  putting them in the output queue as they arrive.

     When a process produces characters more  rapidly  than  they

     can  be  typed,  it  will be suspended when its output queue

     exceeds some limit.  When the queue has drained down to some

     threshold  the  program  is  resumed.  Even parity is always

     generated on output.  The EOT character is  not  transmitted

     (except  in  raw mode) to prevent terminals which respond to

     it from hanging up.


     dc (IV), kl (IV), dh (IV), getty (VIII), stty (I, II),  gtty

     (I, II), signal (II)


     Half-duplex  terminals  are  not  supported.   On   raw-mode

     output,  parity  should  be  transmitted as specified in the

     characters written.