#INCLUDE "external_srv_ffi_pragmas.occ"
#INCLUDE "out.occ"

VAL INT MILLIS          IS 1:
VAL INT SECONDS         IS (1000 * MILLIS):

PROC delay.millis(VAL INT milli)
  TIMER tim:
  INT t:
  SEQ
    tim ? t
    tim ? AFTER t PLUS (milli * MILLIS)
:

PROC delay.seconds (VAL INT sec)
  delay.millis(sec * SECONDS)
:

-- This is the wrapper for outputting bytes
-- to the console. It replaces a notional
-- "screen?" channel end.
PROC print.bytes(CHAN BYTE ch?)
  BYTE c:
  WHILE TRUE
    SEQ
      ch ? c
      ffi.print.char(c)
:

PROC boeing.lasers()
  WHILE TRUE
    SEQ
      ffi.lasers.on()
      delay.millis(747)
      ffi.lasers.off()
      delay.millis(777)
:

PROC counter (CHAN BYTE ch!)
  INITIAL INT c IS 0:
  WHILE TRUE
    SEQ
      out.int(c, 6, ch!)
      c := c + 1
      delay.seconds(1)
:

PROC main ()
  CHAN BYTE ch:
  PAR
    print.bytes(ch?)
    counter(ch!)
    boeing.lasers()
: