	PROGRAM MTEST

C	TEST SYSLIB MULTI-TERMINAL ROUTINES	8/9 - LCP

	INTEGER*2 UNIT,SBLOK(4),STAT(8),ASW,STRING(41),PROMT(8)
	LOGICAL*1 TEND(11)
	REAL*4 TESTM(9)
	DATA PROMT/'EN','TE','R ','ST','RI','NG','>',"200/
	DATA TEND/'*','E','N','D',' ','T','E','S','T','*',0/
	DATA TESTM/'STAT','ATCH','GET','SET','','','','','DTCH'/

C	USE MTSTAT TO GET & DISLPAY # OF UNITS

	TYPE 106					! ANNOUNCE TEST
	L=1						! L = FUNC CODE
	IF(MTSTAT(STAT).NE.0)GOTO 999			! GET MTTY STATUS
5	TYPE 99,STAT(3)+1				! DISPLAY # UNITS

C	GET UNIT # TO TEST

	TYPE 100					! TYPE PROMPT
	ACCEPT 101,UNIT					! GET UNIT #
	IF(UNIT.EQ.99) STOP 'END OF MULTI-TERMINAL TEST'! UNIT #99 STOPS TEST

C	ATTACH UNIT TO THIS JOB THEN GET TCB STATUS WORDS

	TYPE 110					! SEE IF ASW TEST
	ACCEPT 111,IASW					! IS TO BE DONE
	IF(IASW.EQ.'Y')IER=MTATCH(UNIT,ASW,JOB) 	! ATT W/ ASW IF YES
	IF(IASW.NE.'Y')IER=MTATCH(UNIT,0,JOB)		! ATT W/O ASW IF NO
	L=2
	IF(IER)GOTO 999					! REPORT ERROR IF ANY
	L=3
	IF(MTGET(UNIT,SBLOK(1)).NE.0)GOTO 999		! GET TCB WORDS
	TYPE 102,UNIT,SBLOK				! DISPLAY CONTENTS

C	GET NEW STATUS, PUT IT IN TCB, THEN DISPLAY IT

	CALL SETUP(SBLOK,UNIT)				! GET CHANGES IF ANY
	L=4
	IF(MTSET(UNIT,SBLOK(1)).NE.0)GOTO 999		! SET NEW TCB STATUS
	TYPE 102,UNIT,SBLOK				! THEN DISPLAY IT...

C	PERFORM TEST - FIRST ECHO INPUT THEN REPEAT IT USING MTIN & MTOUT

20	TYPE 103					! ANNOUNCE RULES OF
	TYPE 104					! THE TEST...
	TYPE 105
30	CALL MTIN(UNIT,J)				! GET LINE OF INPUT
	CALL MTOUT(UNIT,J)				! REPEAT 1ST/ECHO 2ND
	IF(J.NE.10)GOTO 30				! LF = END OF LINE
	CALL MTRCTO(UNIT)				! RESET CTRL/O

C	NOW TEST W/ TTSPC$ BIT ON - ECHO INPUT WITH MTOUT (DON'T REPEAT)
C	THEN TURN TTSPC$ BIT OFF...

	IF(SBLOK(1).AND."10000)GOTO 40			! IF TTSPC$ ON BRANCH
	SBLOK(1)=SBLOK(1).OR."10000			! SET TTSPC$ BIT
	IF(MTSET(UNIT,SBLOK(1)).NE.0)GOTO 999		! UPDATE TCB
	GOTO 30						! GO DO 2ND TEST
40	SBLOK(1)=SBLOK(1).AND..NOT."10000 		! TURN OFF TTSPC$ BIT
	IF(MTSET(UNIT,SBLOK(1)).NE.0)GOTO 999		! UPDATE TCB
	IF(IASW.NE.'Y')GOTO 60				! SKIP ASW TEST?

C	ASYNCHRONOUS STATUS WORD TEST - "POLL" TERMINAL UNTIL INPUT
C	AVAILABLE - ECHO INPUT THEN REPEAT IT ON NEXT LINE

	TYPE 109					! ANNOUNCE TEST
50	TYPE 97,IADDR(ASW),ASW
97	FORMAT(' ',2O6)
	IF(.NOT.ASW.AND."40000)GOTO 50			! WAIT FOR INPUT
55	CALL MTIN(UNIT,J)				! GET CHAR
	CALL MTOUT(UNIT,J)				! OUTPUT CHAR
	IF(J.NE.10)GOTO 55				! END ON LINE FEED
	CALL MTRCTO(UNIT)				! RESET CTRL/O

C	TEST MTPRNT BY OUTPUTTING 2 STRINGS, 1 FROM USER & 1 INTERNAL

60	CALL GTLIN(STRING,PROMT)			! GET STRING VIA GTLIN
	CALL MTPRNT(UNIT,STRING)			! OUTPUT TO TERMINAL
	CALL MTPRNT(UNIT,TEND)				! ANNOUNCE END OF TEST

C	DETATCH UNIT FROM JOB AND START OVER

	L=9
	TYPE 108,UNIT					! DETATCH UNIT
	IF(MTDTCH(UNIT).EQ.0)GOTO 5			! FROM JOB THEN LOOP

C	ERROR REPORTING

999	TYPE 909,TESTM(L),IER				! ANNOUNCE ERROR
	GOTO 5						! THEN START OVER

99	FORMAT('0THERE ARE',I3,' UNITS ON THIS SYSTEM')
100	FORMAT(' UNIT # TO BE TESTED?'$)
101	FORMAT(I2)
102	FORMAT('0UNIT',I3,' STATUS =',4O8)
103	FORMAT('0GO TO TERMINAL BEING TESTED...ENTER 2 LINES + <RET>')
104	FORMAT(' 1ST LINE: INPUT WILL BE ECHOED THEN REPEATED')
105	FORMAT(' 2ND LINE: TEST TTSPC$ ON - INPUT ECHOED VIA MTOUT'/)
106	FORMAT('1     SYSLIB MULI-TERMINAL ROUTINE TEST PROGRAM')
108	FORMAT(' ABOUT TO DETATCH UNIT # ',I2)
109	FORMAT(' TEST ASW - INPUT WILL BE ECHOED, THEN REPEATED'/)
110	FORMAT(' TEST ASYNCH STATUS WORD FUNCTION?'$)
111	FORMAT(A1)
909	FORMAT('0MT',A4,'  ERROR CODE =',I3)
	END

C	SUBROUTINE TO GET NEW STATUS WORD VALUES

	SUBROUTINE SETUP(SBLOK,UNIT)

	INTEGER SBLOK(4),UNIT

	TYPE 100				! PROMPT FOR NEW CONFIG WORD
	ACCEPT 101,J				! ACCEPT INPUT
	IF(J)SBLOK(1)=J				! UPDATE IF ANY INPUT
	TYPE 102				! ASK FOR FILL CHAR
	ACCEPT 101,J				! ACCEPT IT
	TYPE 103				! ASK FOR # OF FILL CHARS
	ACCEPT 101,I				! ACCEPT IT TOO
	IF(I.OR.J)SBLOK(3)=I*256+J		! PUT IN PROPER BYTES
5	TYPE 104				! ASK FOR CARRIAGE WIDTH
	ACCEPT 105,I				! ACCEPT IT
	IF(I)SBLOK(4)=SBLOK(4)/256*256+I 	! SET BUT DON'T MESS WITH
	RETURN					! STATE WORD ... RETURN

100	FORMAT(' CONFIG BIT MASK:'$)
101	FORMAT(O6)
102	FORMAT(' CHAR REQUIRING FILLER:'$)
103	FORMAT(' # OF FILL CHARS:'$)
104	FORMAT(' CARRIAGE WIDTH:'$)
105	FORMAT(I3)
	END
