[comp.sys.transputer] Using keyboard interruption in TDS3 EXEs

mdp@lion.inmos.co.uk (Michael Poole) (10/22/90)

Herman Roebbers' posting about writing interruptable programs under TDS3
prompts me to break the normal INMOS rule about not responding to software
queries on the network. INMOS have a worldwide network of business centres
in SGS-Thomson offices and all queries should be referred to a Field
Applications Engineer at one of these centres. (Holland is served from
Marlow, UK).

The reasons for Herman's difficulties are based in the design decision
to support TDS3 with the new general purpose server, ISERVER, which does
not have faciltities for detecting unsolicited keyboard input. All keyboard
input must be explicitly polled or demanded from the transputer using
one of the library procedures so.pollkey or so.getkey.

The keyboard is polled by the code of the TDS while supporting an EXE.
Unfortunately there are a couple of coding errors in this part of the TDS
which make it not work quite as flexibly as it should. The best workaround
is to do explicit keyboard polling from the EXE on the transputer.
Two solutions to Herman's problem are presented below:

----------------------------------
Solution 1: Not using ALT at all.

SEQ
  running := TRUE
  WHILE running
    SEQ
      ...  write something to screen
      --{{{  poll the keyboard
      BYTE bkey, bres:
      SEQ
	so.pollkey (from.isv, to.isv, bkey, bres)
	running := bres <> spr.ok
      --}}}
----------------------------------
Solution 2: Taking advantage of forced poll in TDS after any SP transaction

SEQ
  running := TRUE
  WHILE running
    PRI ALT
      keyboard ? key
	running := FALSE
      TRUE & SKIP
	SEQ
	  ...  write something to screen (using channel screen)
	  so.write.string(from.isv,to.isv,"") -- Forces TDS to poll keyboard
----------------------------------

The algorithm determining when a keyboard poll is done inside the TDS is
too complex to state in full here, but it may be useful to know that in the
absence of any activity on the server channels it is kicked by the clock
at intervals which decay slowly from one sixteenth of a second to half a
second. It is also done after any explicit server transaction or any
transaction on TDS filer channels which need to access the host.
It is NOT done (bug?) after outputs on the TDS EXE parameter channel screen
and a continuous stream of outputs on this channel can mean the timer branch
of the ALT will never be taken!
Note that all this applies to set.abort.key testing on kernel channels also.

When a poll occurs the key is immediately output to the EXE on the
channel keyboard.

The second bug is the non-working of the set.poll command on the
screen channel (TDS manual, 2nd Edition, p374)

Michael Poole, INMOS Bristol.