	SUBROUTINE WAIT_CROSSFILE
C
C	This routine is entered when the GE Crossfile system is being used.
C	It will wait for the REMOTE bit to be set on the remote port (this
C	is set when carrier is detected), then it will post a read request
C	to get the user number prompt (U#=), and then sends Crossfile the
C	character "H" every 1 second until the "U#=" prompt is sent to us.
C
C	Crossfile waits approximatly 10 seconds for the first "H" before
C	it hangs up the modem.  After the "U#=" prompt is displayed, you
C	have approximatly 1 minute to login; then the modem is hung up.
C	Since it normally takes more than 10 seconds to get to our terminal
C	from the modem after calling Crossfile, this routine was written.

	INCLUDE 'COM.INC/NOLIST'
	INCLUDE 'TTDEF.FOR/NOLIST'

	CHARACTER*(*) CONNECT_MESSAGE
	PARAMETER (CONNECT_MESSAGE = SS//
	1 '*** You may now call Crossfile, type CTRL/C to abort. ***'//SS)

	ASSIGN 9900 TO ABORT		! Go here when aborting.
	IF (REMOTE) GO TO 150		! Continue if already online.
C
C	Wait for the remote bit to be set.
C
	CALL WRITE_USER(CONNECT_MESSAGE)
100	REMOTE_STATUS = SYS$QIOW(%VAL(REFN_IN),%VAL(RCHAN_IN),
	1	%VAL(IO$_SENSEMODE),RIOSB,,,REMOTE_CHAR,,,,,)
	CALL CHECK_STATUS('WAIT_CROSSFILE',REMOTE_STATUS)

	IF (CONTROLC_TYPED) GO TO ABORT ! Tell user we're aborting.
	IF ((REMOTE_CHAR(2) .AND. TT$M_REMOTE) .EQ. 0) THEN
		CALL WAITABIT('01.00')	! Wait for 1 second.
		GO TO 100		!  and try again.
	ENDIF
	REMOTE = .TRUE.			! Set for hangup.
C
C	Post a read to get Crossfile prompt.
C
C	RBUFFER(1) = 0			! Init receive buffer.
C	STATUS = SYS$QIO(%VAL(REFN_IN),%VAL(RCHAN_IN),
C	1	%VAL(IO$_READLBLK + IO$M_NOECHO + IO$M_TIMED),
C	1	RIOSB,,,RBUFFER,%VAL(100),
C	1	%VAL(30),TERMPTR,,)	! 30 second timeout.
C
C	Because we want the auto login routine to read the prompt,
C	we will check the typeahead buffer every second to determine
C	if we've started to receive anything from the remote.
C
150	CALL CLEAR_TYPEAHEAD()		! Make sure no garbage exists.
C
C	We must send the upper case character "H" at one second
C	intervals until we get the user number prompt "U#=".
C
	XBUFFER(1) = 'H'		! Fill in ASCII "H".
	ASSIGN 200 TO LOOP		! Come here to loop.

200	CALL WRITE_BYTE(XBUFFER(1),1)	! Write character to remote.
	IF (CONTROLC_TYPED) GO TO ABORT	! Tell user we're aborting.
C
C	We should use an AST routine to flag completion.
C
	CALL WAITABIT('01.00')		! Wait for Crossfile prompt.
C	IF (RBUFFER(1) .EQ. 0) THEN
C		GO TO LOOP		! Loop if no response yet.
C	ENDIF
C	NBYTES = RIOSB(2)		! Copy the byte count.
C	CALL WRITE_BUFFER(RBUFFER,NBYTES) ! Output the prompt.
C
C	Loop until something is in the typeahead buffer.
C
	IF (CHECK_TYPEAHEAD() .EQ. 0) GO TO LOOP
	RETURN
C
C	Come here if we're aborting the CROSSFILE wait.
C
9900	CALL WRITE_USER(SS//
	1	'*** Aborting wait for CROSSFILE. ***'//SS)
	RETURN
	END
