--
--	softalt.occ -- ALTing over user-defined channels
--	Copyright (C) 2002 Fred Barnes <frmb2@ukc.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.
--


--{{{  includes, uses
#INCLUDE "udc.module"
#INCLUDE "course.module"
--}}}  

--{{{  PROC timed.outputs (VAL INT delay, CHAN INT out!)
PROC timed.outputs (VAL INT delay, CHAN INT out!)
  TIMER tim:
  INT t, v:
  SEQ
    v := MOSTPOS INT
    tim ? t
    t := (t PLUS delay)
    WHILE TRUE
      SEQ
        out ! v
        tim ? AFTER t
        t := (t PLUS delay)
        v := (v PLUS 1)
:
--}}}  

--{{{  PROC printed.inputs (CHAN INT in.0?, in.1?, CHAN BYTE out!)
PROC printed.inputs (CHAN INT in.0?, in.1?, CHAN BYTE out!)
  WHILE TRUE
    ALT
      INT x:
      in.0 ? x
        SEQ
          out.int (x, 0, out!)
          out ! '*n'
      INT y:
      in.1 ? y
        SEQ
          out.int (y, 0, out!)
          out ! '*n'
:
--}}}  

--{{{  PROC softalt (CHAN BYTE kyb?, scr!, err!)
PROC softalt (CHAN BYTE kyb?, scr!, err!)

  INT addr, addr2:
  BOOL use.bufchan:
  SEQ
    ask.bool ("Use buffered channel? ", use.bufchan, kyb?, scr!)
    IF
      use.bufchan
        INT buf.size:
        SEQ
          ask.int ("Buffer size? ", buf.size, 4, kyb?, scr!)
          udc.bufchan.alloc (buf.size, addr)
          udc.bufchan.alloc (buf.size, addr2)
      TRUE
        SEQ
          udc.softchan.alloc (addr)
          udc.softchan.alloc (addr2)

    PLACED CHAN INT c addr:
    PLACED CHAN INT d addr2:
    PAR
      timed.outputs (500000, c!)
      timed.outputs (470000, d!)
      printed.inputs (c?, d?, scr!)
:
--}}}  

