	.TITLE	HG$GET_INPUT
	.IDENT	/01-001/
;++
;
;  Routine:	HG$GET_INPUT
;
;  Author:	Hunter Goatley
;		Clyde Digital Systems
;		371 East 800 South
;		Orem, Utah  84058
;		801-224-5306
;
;  Date:	July 11, 1988
;
;  Functional Description:
;
;	This  routine implements an easy-to-call interface to the SMG$
;	routines  to  provide  command  recall   when   reading   from
;	SYS$INPUT.   It  takes the same arguments as LIB$GET_INPUT and
;	may be substituted directly in any call to LIB$GET_INPUT. 
;
;	Example:
;
;		CALL LIB$GET_INPUT (buffer, prompt, buffer)
;			to
;		CALL HG$GET_INPUT (buffer, prompt, buffer)
;
;  To assemble and use:
;
;	$ MACRO HG$GET_INPUT
;	$ LINK  your_program,HG$GET_INPUT
;	$ RUN   your_program
;
;  Modified by:
;
;	01-001		Hunter Goatley		11-JUL-1988 21:28
;		Original version.
;
;--

;+
;
;	HG$GET_INPUT  get-str [,prompt-str] [,out-len]
;
;  Inputs:
;
;	4(AP)	- String which is read from SYS$INPUT.
;		  Address of string descriptor.   Write-only.
;	8(AP)	- Prompt message that is displayed (optional).
;		  Address of string descriptor.  Read-only.
;	12(AP)	- Number of bytes written into @4(AP) (optional).
;		  Address of word.  Write-only.
;
;  Returns:
;
;	String in 4(AP) and status in R0.
;
;  Effects:
;
;	On first call, a key table and a virtual keyboard are created.
;
;-

BUFFER	= 1 * 4					; 1st arg is receiving buffer
PROMPT	= 2 * 4					; 2nd arg is prompt
RETLEN	= 3 * 4					; 3rd arg is receiving length

	$RMSDEF					; Include RMS symbols
	$SSDEF					; System service status symbols
	$SMGDEF					; Include SMG$ symbols

	.PSECT	_HG$GET_INPUT_DATA,NOEXE,WRT,LONG

KEY_TABLE_ID::	.LONG	0			; ID of key table created
KEYBOARD_ID::	.LONG	0			; ID of virtual keyboard created

	.PSECT	_HG$GET_INPUT_CODE,EXE,NOWRT,LONG,PIC,SHR

	.ENTRY	HG$GET_INPUT,^M<>

	TSTL	KEY_TABLE_ID			; Have we been called yet?
						; ... (KEY_TABLE_ID <> 0)
	BNEQU	10$				; Yes - skip initialization
	PUSHAL	KEY_TABLE_ID			; Create a key table by
	CALLS	#1,G^SMG$CREATE_KEY_TABLE	; ...  calling SMG$ routine
	BLBC	R0,40$				; Return on error
	PUSHAL	KEYBOARD_ID			; Create a virtual keyboard
	CALLS	#1,G^SMG$CREATE_VIRTUAL_KEYBOARD
	BLBC	R0,40$				; Return on error
;
;  Pass our parameters on to SMG$READ_COMPOSED_LINE.
;
 10$:	MOVL	#3,R0				; At least 3 args for SMG$READ
	CMPW	#2,(AP)				; How many params did we get?
	BEQL	20$				; If 2, go handle it
	BGTR	30$				; If 1, go handle it
						; Here, 3 parameters
	PUSHAW	@RETLEN(AP)			; Push address of length word
	INCL	R0				; Bump up SMG$READ args count
 20$:	PUSHAQ	@PROMPT(AP)			; Push prompt desc. address
	INCL	R0				; Bump up SMG$READ args count
 30$:	PUSHAQ	@BUFFER(AP)			; Push address of receive buffer
	PUSHAL	KEY_TABLE_ID			; Push the key table id
	PUSHAL	KEYBOARD_ID			; Push the keyboard id
	CALLS	R0,G^SMG$READ_COMPOSED_LINE	; Call SMG$ routine to read line
	CMPL	#SMG$_EOF,R0			; Was ^Z entered?
	BNEQU	40$				; No - go on and return
	MOVL	#RMS$_EOF,R0			; Make status RMS$_EOF (like LIB$)
 40$:	RET					; Return to the caller

	.END
