From:	CSBVAX::MRGATE!info-vax-request@kl.sri.com@SMTP 23-MAR-1988 03:08
To:	ARISIA::EVERHART
Subj:	Re: Need single character input on VAX Pascal...


Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Sun 20 Mar 88 00:27:05-PST
Received: by ucbvax.Berkeley.EDU (5.58/1.26)
	id AA26088; Sat, 19 Mar 88 17:53:40 PST
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 18 Mar 88 22:33:45 GMT
From: bsu-cs!cfchiesa@iuvax.cs.indiana.edu  (Christopher Chiesa)
Organization: CS Dept, Ball St U, Muncie, Indiana
Subject: Re: Need single character input on VAX Pascal...
Message-Id: <2394@bsu-cs.UUCP>
References: <7787@cisunx.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <7787@cisunx.UUCP>, bumpy@cisunx.UUCP (Michael Stopper) writes:

> Does anyone out there have a routine for VAX Pascal to read a single char
> from the terminal in VAX Pascal without having to press the ever-present
> RETURN key??  I have a prog which prompts for a single character response

Yes.  Below you will find a MACRO Assembly routine which will do what you re-
quest.  It may be called from any Vax/VMS programming language, including Pas-
cal, without strenuous or obscure data-type-matching effort. 

To use this routine with your program, follow the guidelines below for declar-
ing and using the routine, then compile your program (PASCAL filename), assem-
ble whatever you've named my routine (MACRO filename), then LINK both filenames,
yours first.  You can then run the program and it will accept terminal key-
strokes.

In Vax Pascal, you can obtain either a character, or an integer ASCII code, 
directly from my IN_CHAR routine, depending on how you declare it to the PASCAL
compiler:

To obtain a character:                 To obtain an integer:
--------------------------------       _____________________________

[EXTERNAL]                              [EXTERNAL]
PROCEDURE In_Char (VAR c:char);         PROCEDURE In_Char (VAR n: integer); 
  EXTERN;                                 EXTERN;

To use it, of course, just invoke it by name:

    In_Char(x);    (* 'x' gets the next character from the terminal. *)

   IN_CHAR follows the Vax/VMS calling/passing standard, so may be called from 
VMS languages other than Pascal.  IN_CHAR accepts and returns ONE parameter, a
BYTE by REFERENCE.  On return from IN_CHAR, that byte will contain the latest 
character from the terminal.  

   If anyone has any questions, comments, compliments, flames, etc. about this
routine, please let me know.  I'm really pleased to be able to contribute some-
thing to the Net.

-- Chris Chiesa


<><><><><><><><><><><><><><><><><><><><><><><><><><><><> Chris Chiesa <><><><><>
<> {ihpn4|seismo}!{iuvax|pur-ee}!bsu-cs!cfchiesa                              <>
<> cfchiesa@bsu-cs.UUCP                                                       <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

============8<======CUT HERE==========8<===========CUT HERE=========8<=========

		.TITLE	IN_CHAR - Single-character terminal input
		.IDENT	/1-001/		; File: IN_CHAR.MAR
					; Edit: CFC1001

        ;++
        ;  FACILITY: Single-character immediate input 
        ;
        ;  ABSTRACT:
        ;
	;      One function that seems to come up fairly often during
	;   programming, is the desire to "get a single character from 
	;   the terminal, without the user having to press RETURN.  Un-
	;   fortunately, with only minor exceptions (Vax BASIC, for one),
	;   such an operation is noticeably missing from the set of "built
	;   in" language facilities under Vax/VMS. 
	;
	;      This routine assigns a channel, if necessary, to the
	;   SYS$INPUT device (assumed to be a terminal), and obtains a
	;   single character this device each time it (the routine) is 
	;   called.
	;
	;      The character obtained from the terminal is returned to the
	;   calling program as a single byte ASCII code.
        ;
	;  ENVIRONMENT:   User mode, callable from any higher-level Vax
	;                 programming language.
        ;
        ; AUTHOR:  Christopher F. Chiesa,   CREATION DATE: 10-FEB-1988, approx.
        ;
        ; MODIFIED BY: (Christopher F. Chiesa)
        ;
        ; 1-001 -- original.                CFC 10-FEB-1988
	; 1-002 -- edited text of ABSTRACT, CFC 18-MAR-1988
        ;--

		.SBTTL	DECLARATIONS
        ;
        ; EQUATED SYMBOLS:
        ;
			buffer_length = 1	; Length of buffer

        ;
        ; OWN STORAGE:
        ;

			.PSECT	DATA	NOEXE,WRT

    DEVNAM:		.ASCID	/SYS$INPUT/	; device to read from
    CHAN:		.LONG	0		; channel to use (init'd to 0)

        ;
        ; EXECUTABLE CODE BEGINS:
        ;
			.PSECT	CODE	EXE,NOWRT
    
			.ENTRY	IN_CHAR,^M<>

			CMPL	CHAN,#0		; Channel already assigned?

			BNEQ	GET_INPUT	; Yes - don't assign again

	CHAN_ASGN:	$ASSIGN_S -		; Assign channel for input
			DEVNAM=DEVNAM,-
			CHAN=CHAN
			BLBC	R0,OOPS		; Exit with error status


	GET_INPUT:	$QIOW_S	CHAN=CHAN,-	; Perform input on channel
				FUNC=#<IO$_READVBLK!IO$M_NOECHO!IO$M_NOFILTR>,-
				P1=@4(AP),-
				P2=#<buffer_length>
			BLBC	R0,OOPS		; Exit with QIO error

	RETURN:		RET			; Return when successful

	OOPS:		$EXIT_S	R0		; Exit with status code

			.END
-- 
<><><><><><><><><><><><><><><><><><><><><><><><><><><><> Chris Chiesa <><><><><>
<> {ihpn4|seismo}!{iuvax|pur-ee}!bsu-cs!cfchiesa                              <>
<> cfchiesa@bsu-cs.UUCP                                                       <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
