;****************************************************************************
; TNAME.M68	-	"Terminal Name Subroutine"
;
; 	Written by:	Dave Heyliger - AMUS Staff
;
;	Purpose:	To return the JOB's terminal name in string format
;
;	Usage:		XCALL TNAME,terminal'name
;
;	Sample BASIC program:
;
;		MAP1	terminal'name,S,8,""
;
;		XCALL TNAME,terminal'name
;		PRINT "This JOB's terminal is "terminal'name
;		END
;****************************************************************************

	SEARCH SYS				;search the regulars
	SEARCH SYSSYM

	OBJNAM	TNAME.SBR			;final product

	VMAJOR=1				;original by Dave Heyliger
	VMINOR=0				;version 1.0(100)
	VEDIT=100.

	PHDR    -1,0,PH$REE!PH$REU      	; Re-entrant and re-usable

	;first do some error checking....
        CMPW    @A3,#1				;number of arguments must be 1
	BNE	10$				;error on input - show usage
	CMPW	2(A3),#2			;should be a string variable
	BEQ	20$				;looking good, Louis!

	;error on usage - display usage to the user
10$:	TYPECR	<Usage: XCALL TNAME,terminal'name>
	TYPECR	<	where "terminal'name" is a string variable.>
	RTN					;return user

	;real simple... point to JCB, then get the terminal name 4 bytes below
20$:	JOBIDX	A1			;A1 points to JCB
	MOV	JOBTRM(A1),A1		;A1 points to terminal status word
	SUB	#4,A1			;A1 points to the terminal name
	MOV	4(A3),A2		;A2 points to "terminal'name" variable
	UNPACK				;unpack the terminal name
	UNPACK
	RTN				;and return!

	END				;end of TNAME.M68