TWADE@CSVAX.UCD.HEA.IRL.UUCP (03/02/87)
A couple of people mentioned that they needed to do single-character I/O
without waiting for carriage return. Here is a small routine to do this.
status = READ_KEY (ch_code)
will read a single character from SYS$COMMAND (including DEL, CTRL/X and
CTRL/U characters) without echoing and without waiting for CR. 'Status'
is the return status from the $QIO call (low order bit set for success,
so your HL language treats it as boolean TRUE for success). 'Ch_code' is
the address of a character which will receive the ASCII code of the
character entered (so C calls passes this parameter using the '&' operator
I think). I've tested it with a FORTRAN calling program. Usual disclaimer:
I take no responsibility for anything whatsoever.
---- File READKEY.MAR -----------X Cut Here X---------------------------
.Title READ_CHAR_FROM_TERMINAL
; Routine to read characters from terminal.
; Tom Wade, UCD computer science twade@csvax.ucd.hea.irl
Char: .Byte 0
Iosb: .Quad 0
Ttchan: .Long 0
Tty: .Ascid "SYS$COMMAND"
.Entry READ_KEY M <>
; Read a character from the keyboard without echo or <CR>
Tstl ttchan ; channel open ?
Bneq get_key ; yes.
Bsbw OPEN_CHAN
Get_key:
$QIOW_S -
chan = ttchan, -
func = #<IO$_READVBLK!IO$M_NOECHO!IO$M_NOFILTR>, -
iosb = iosb, -
p1 = char, -
p2 = #1
Blbc R0, exit
Movzwl iosb, R0
Blbc R0, exit
Movl #SS$_NORMAL, R0
Movzbl char, @4(AP)
Exit: Ret
OPEN_CHAN:
$ASSIGN_S - ; open a channel to TTY
chan = ttchan, -
devnam = tty
Rsb
.End
------------ End of file READKEY.MAR -----X Cut Here X------------------
-------------------------------------------------------------------------
Tom Wade Internet: twade@csvax.ucd.hea.irl
Systems Programmer Ean: twade@csvax.ucd.irl
Dept Computer Science PSI: PSI%27243154000721::TWADE
University College Dublin Telex: (0500) 91196 UCD EI
Ireland. Voice: +353-1-693244 Ext 2472
-------------------------------------------------------------------------