 	ALWAYS	17APR4	HELP		<HELP MESSAGE, AND CLI COMMAND>		;17APR4
;************************************************************************	;**-1
;*									*
;*	Module: HELP - Print HELP message				*
;*	   and: .    - Pass command to CLI for execution		*
;*									*
;*	Author: Chris Doran						*
;*									*
;*	Date:	14-Jul-83						*
;*									*
;*	Input Parameters:						*
;*									*
;*		R0 Points to the command line in process		*
;*									*
;*	Output parameters:						*
;*									*
;*		R0 points just beyond the last character of the line	*
;*									*
;*	 Process command HELP {topic}					*
;*									*
;* If parent/offspring tasking is available, use the HELP utility,	*
;* by spawning:								*
;*									*
;*	HELP HEX COMMAND {topic} to MCR					*
;*									*
;* In addition, the . command, which just sends the rest of the line	*
;* to the current CLI, is available.					*
;*									*
;* If parent/offspring tasking is not available, HELP just prints a	*
;* command syntax summary, and . does a suspend or stop, ignoring rest	*
;* of line.								*
;*									*
;* MODIFICATIONS RECORD							*
;* ====================							*
;* CJD Jan 84								*
;*	Edit fixed HELP message to show Aug 83 additions.		*
;*									*
;* 17-APR-84 Scott Smith, Telex Computer Products, Raliegh, NC		*	;17APR4
;*	Disabled "." command with no argument if VMS coditional		*	;17APR4
;*	assembly symbol is defined.					*	;17APR4
;*									*	;17APR4
;*	Reworked call to help so that default qualifier is still	*	;17APR4
;*	"COMMANDS" but specific commands are not sub-qualifiers of the	*	;17APR4
;*	"COMMANDS" qualifier.  (So that outside of hex you can say	*	;17APR4
;*	"HELP HEX READ" instead of "HELP HEX COMMANDS READ")		*	;17APR4
;************************************************************************

	.MCALL	DIR$,SPWN$,STSE$S,WTSE$S,GTSK$C,STOP$S,SPND$S,CALLR

HELP::
QM::				; Also invoked by '?'
.IF NDF P$$OFF
	OUTPUT	HLP		; Output command syntax summary
	CALLR	EXTRA		; Warn about command argument and return
.IFF
	.ENABL	LSB
	MOV	#SUFFIX,%2	; Address space for suffix
	TSTB	(%0)		; Is there a qualifier?				;17APR4
	BHI	10$		;  YES - continue				;17APR4
	MOV	#COMMND,%0	;  NO - use default (COMMANDS)			;17APR4
10$:	MOVB	(%0)+,(%2)+	; Copy byte
	BEQ	20$		; Until end of HELP argument
	CMP	%2,#CMDMAX	; or end of command line space
	BLO	10$
20$:	MOV	#HLPCMD,%0	; Address start of command
	SUB	%0,%2		; Compute command length
				;  (less null, & allowing for following DEC)

; . (=CLI) command. STOP or SUSPEND if null.
.IFT
; . (=CLI) command. Ignore rest of line, STOP or SUSPEND for user to issue
; CLI commands directly.
.IFF
; Entry value of %2 is length of command, including "."
.IFTF
CLI::
	DEC	%2		; Don't count . command introducer
.IFF
	BLE	60$		; Stop/suspend if all blank line
40$:	MOV	%0,SPWN+S.PWCA	; Store address of start of command
	MOV	%2,SPWN+S.PWCL	; and length
	MOV	#0,SPWN+S.PWVT							;17APR4
	DIR$	#SPWN		; and spawn command
	BCC	50$		; OK if accepted
	OUTPUT	SPE		; Else output error message
	SEC			; Set carry
	RETURN			; and return as if done
50$:
  .IF DF S$$TOP
	STSE$S	#5		; STOP for spawned task
  .IFF
	WTSE$S	#5		; Wait for spawned task
  .ENDC
	.DSABL	LSB
.IFF
	RETURN			; and return (s/b cc from wait)
.IFTF

; Stop or suspend for user to issue multiple commands to CLI. First print out
; restart message, giving our task name for restart.
60$:
.IFTF										;**-3
	.ENABLE	LSB								;17APR4
	.IF	DF	VMS							;17APR4
	OUTPUT	NSV		; 'Command not supported by VMS'		;17APR4
	JMP	250$		;   and take error exit				;17APR4
	.ENDC									;17APR4
.IFT										;17APR4
	CALL	EXTRA		; Complain if end of line not blank		;17APR4
				; Stop anyway to let user issue command manually;17APR4
.IFTF										;17APR4
	GTSK$C	RECORD,HELP	; Get task info, inc name, to RECORD
	MOV	#RECORD+G.TSTN,%3 ; Address Radix-50 task name
	MOV	#STP+STPLEN-11.,%0 ; and space for ASCII name
	.REPT	2
	MOV	(%3)+,%1	; Get word
	CALL	$C5TA		; Convert Radix-50 to ASCII
	.ENDR			; Twice
	OUTPUT	STP		; Print stop or pause message
  .IF DF S$$TOP
	STOP$S			; STOP until UNS'd
  .IFF
	SPND$S			; PAUSE until RES'd
  .ENDC
; Typing RES<esc> or UNS<esc> doesn't return the carriage to the LH margin.
; Hence if the . command came from a command file, and echoing isn't
; suppressed, echo of the following line will start in column 5. Issue a
; CR if this is the case.
	TSTB	QUIET+1		; Input from TTY?
	BNE	255$		;  NE: yes, CR will be given by HEX prompt	;17APR4
	TSTB	QUIET		; Echo suppressed?				;**-1
	BEQ	255$		;  EQ: yes, not required			;17APR4
	MOV	#1,OUTDIR+Q.IOPL+2 ; Neither, do need a CR			;**-1
	CLR	OUTDIR+Q.IOPL+4	; (1st char only of STP message)
	DIR$	#OUTDIR
	MOV	#40,OUTDIR+Q.IOPL+4 ; Re-standardise DPB
250$:										;17APR4
255$:	RETURN			; Then return to caller				;17APR4
.IFTF										;17APR4
	.DSABL	LSB								;17APR4
	.PSECT	DATA	RW,D							;**-2
.IFF

; HLPCMD is global so that "HEX" can be patched if task name changed.
HLPCMD::.ASCII	"HELP HEX "		; HELP command starter			;17APR4
SUFFIX:	.BLKB	20.			; Space for longest HEX command name	;17APR4
CMDMAX:	.BYTE	0			; Sentinel byte				;**-2
COMMND: .ASCIZ "COMMANDS"
.IFTF
  .IF DF S$$TOP
	DEFM	STP	^/Stopping. To continue type UNS       <esc>/
  .IFF
	DEFM	STP	^/Pausing. To continue type RES       <esc>/
  .ENDC
	.EVEN
  .IF DF A$$CLI
SPWN:	SPWN$	CLI...,,,,,5		; Spawn current CLI
  .IFF
SPWN:	SPWN$	MCR...,,,,,5		; Spawn MCR
  .ENDC	; {multi-}CLI support

	.PSECT	PURE	RO,D

.IFF
	DEFM	SPE	<Spawn failed>
.IFT
; Command syntax summary message for use when HELP can't be spawned.
; Create this message from the COMMAND section of HEX.HLP.
HLP:
.ASCII	<15>"AND range WITH pp		  MULTIPLY { SIGNED } range BY pp"<15><12>
.ASCII	"APPEND range {PARTIAL} {WIDTH vv/vvvv} FILE f		NAME { nnnnnnnn }"<15><12>
.ASCII	"COMPARE { range } FILE f	  NEGATE range"<15><12>
.ASCII	"COMPLEMENT range		  NOECHO"<15><12>
.ASCII	"COPY range TO cccc {REPEAT vvvv}  OFFSET { aaaa }"<15><12>
.ASCII	"CRC range { TO **** }		  OR range WITH pp"<15><12>
.ASCII	"CSUM range   			  READ { range } FILE filespec"<15><12>
.ASCII	"DECREMENT range { BY pp }	  REMAINDER { SIGNED } range BY pp"<15><12>
.ASCII	"DISPLAY {ASCII} range {FILE f}	  REVERSE range"<15><12>
.ASCII	"DIVIDE { SIGNED } range BY pp	  ROTATE LEFT/RIGHT { SIGNED } range { BY pp }"<15><12>
.ASCII	"ECHO				  SEARCH range FOR pp/qqqq"<15><12>
.ASCII	"EDIT aaaa { STEP ww }		  SHIFT LEFT/RIGHT { SIGNED  } range { BY pp }"<15><12>
.ASCII	"EXIT				  SUM range { TO **** }"<15><12>
.ASCII	"FILL range WITH pp		  TRANSFER { aaaa }"<15><12>
.ASCII	"FORMAT { type {char}}		  WRITE range {PARTIAL} {WIDTH vv/vvvv} FILE f"<15><12>
.ASCII	"HELP { HFE command }		  XOR range WITH pp"<15><12>
.ASCII	"INCREMENT range { BY pp }	  . { CLI command }"<15><12>
.ASCII	"INIT { WITH pp }		  ? { HFE command }"<15><12>
.ASCII	"MOVE BYTE/WORD FROM **** TO ****  ctrl/Z = EXIT"<15><12>
.ASCII	<12>"**** is an address or pseudo-register (%vv), f is a filename,"<15><12>
.ASCII	"type is format:	INTEL/MOTOROLA/ROCKWELL/RCA/TEKTRONIX/EXTENDED/TEXAS/MOSTEK/"<15><12>
.ASCII	"		WHITESMITHS/RIM/BIN/HEX/OCTAL"
.IIF DF TCI,.ASCII	"/TCI"
.ASCII	"/SIRA/OBJECT/ABSOLUTE"
.IIF DF TASK,.ASCII	"/TASK"
HLPLEN=.-HLP
.ENDC
	.EVEN

.IIF DF VMS,DEFM	NSV	<Command not supported by VMS>			;17APR4
	.END
