--
--	interface_in.occ -- input interface to the external environment
--	Copyright (C) 2000 Fred Barnes
--      Separated from CCSP and updated April 2006, Fred Barnes <frmb@kent.ac.uk>
--
--	This program is free software; you can redistribute it and/or modify
--	it under the terms of the GNU General Public License as published by
--	the Free Software Foundation; either version 2 of the License, or
--	(at your option) any later version.
--
--	This program is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--	GNU General Public License for more details.
--
--	You should have received a copy of the GNU General Public License
--	along with this program; if not, write to the Free Software
--	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--

#PRAGMA EXTERNAL "PROC BX.read.keyboard (CHAN OF INT c, INT ch) = 3"

PROC kroc.keyboard.process (CHAN OF BYTE out, CHAN OF INT kill.chan)
  SEQ
    INITIAL BOOL had.eof IS FALSE:
    WHILE TRUE
      BYTE ch:
      INT c.in:
      IF
        NOT had.eof
          SEQ
            c.in := MOSTNEG INT
            WHILE c.in = (MOSTNEG INT)
              SEQ
                BX.read.keyboard (kill.chan, c.in)
                -- if we were killed forcefully, c.in will still be MINT
            IF
              c.in = (-1)
                had.eof, ch := TRUE, #FF
              TRUE
                ch := BYTE c.in
            out ! ch
        TRUE
          out ! #FF
:

