	SUBROUTINE REMOTE_AST
C
C	This AST routine is entered when the read request for the remote
C	terminal completes.  It then writes the data read from the remote
C	to the local terminal and the log file (if any).
C
	INCLUDE 'COM.INC/NOLIST'

	RECEIVER_BUSY = .FALSE. 	! Set receiver not busy.
	REMOTE_ASTS = REMOTE_ASTS - 1	! Adjust our AST count.
	STATUS_CODE = RIOSB(1)		! Copy the status code.
	NBYTES = RIOSB(2)		!  and the byte count.
C
C	Save the maximum typeahead buffer count for output in the
C	status report for debugging.
C
	IF (NBYTES .GT. MAX_TYPEAHEAD) THEN
		MAX_TYPEAHEAD = NBYTES	! Save the maximum read.
	ENDIF
C
C	Don't issue the local write if the read failed.
C
	IF (STATUS_CODE .EQ. SS$_ABORT) THEN
	    GO TO 100			! We've been canceled.
	ELSE
	    IF (.NOT. STATUS_CODE) THEN
		IF (STATUS_CODE .NE. SS$_TIMEOUT) THEN
		    CALL CHECK_STATUS('REMOTE_QIO',STATUS_CODE)
		    GO TO 100		! Continue ...
		ENDIF
	    ENDIF
	ENDIF
C
C	Copy incoming characters to the logfile buffer.
C
	CALL WRITE_LOGFILE(RBUFFER,NBYTES)
C
C	Echo character(s) from the remote at the local terminal.
C
	IF (NBYTES .GT. 0) THEN
		STATUS = SYS$QIO(%VAL(LEFN_OUT),%VAL(LCHAN_OUT),
	1	%VAL(IO$_WRITELBLK + IO$M_NOFORMAT),
	1	XLIOSB,,,RBUFFER,%VAL(NBYTES),,,,)
		CALL CHECK_STATUS('LOCAL_WRITELBLK',STATUS)
	ENDIF
C
C	If the interrupt character hasn't been typed, we wakeup the
C	mainline code to re-arm the remote read.  We don't re-arm the
C	remote read in this routine because we're at AST level which
C	blocks an AST generated by the local read completing.
C
100	IF (.NOT. INTERRUPT_TYPED) THEN
		CALL WAKE_UP()		! Wakeup the mainline code.
	ENDIF
	RETURN
	END

	SUBROUTINE LOCAL_AST
C
C	This AST routine is entered when the local read completes.
C	The character(s) read are then written to the remote system.
C	If local echo is enabled, the characters are also written to
C	the log file (if any).
C
	INCLUDE 'COM.INC/NOLIST'

	XMITTER_BUSY = .FALSE.		! Set transmitter not busy.
	LOCAL_ASTS = LOCAL_ASTS - 1	! Adjust our AST count.
	STATUS_CODE  = LIOSB(1)		! Copy the status code.
	NBYTES = LIOSB(2)		!  and the byte count.
C
C	If the read failed, don't write to the remote.
C
	IF (STATUS_CODE .EQ. SS$_ABORT) THEN
		GO TO 200		! We've been canceled.
	ELSE
		IF (.NOT. STATUS_CODE) THEN
			CALL CHECK_STATUS('LOCAL_QIO',STATUS_CODE)
			GO TO 200	! And continue ..
		ENDIF
	ENDIF
C
C 	Since we're doing a Read Pass All I/O function, we must check
C	for the interrupt character (i.e., CTRL/Y).  When the interrupt
C	character is detected, the INTERRUPT_TYPED flag is set, and we
C	wakup the hibernate in the mainline code.
C
	IF (LBUFFER(1) .EQ. INTERRUPT_CHAR(1)) THEN
		INTERRUPT_TYPED = .TRUE.! Show interrupt was typed.
		CALL WAKE_UP()		! Wake up the mainline.
		GO TO 200		! And continue ...
	ENDIF
C
C	If doing local echoing, all incoming characters from the local
C	terminal are copied to the logfile buffer to simulate echoing
C	from the remote system.
C
	IF (LOCAL_ECHO) CALL WRITE_LOGFILE(LBUFFER,NBYTES)
C
C	Write the characters read to the remote system.
C
100	IF (NBYTES .GT. 0) THEN
		STATUS = SYS$QIO(%VAL(REFN_OUT),%VAL(RCHAN_OUT),
	1		%VAL(IO$_WRITELBLK + IO$M_NOFORMAT),
	1		XRIOSB,,,LBUFFER,%VAL(NBYTES),,,,)
		CALL CHECK_STATUS('REMOTE_WRITELBLK',STATUS)
	ENDIF
C
C	If the interrupt character hasn't been typed, we re-enable
C	the local read at this time.
C
200	IF (.NOT. INTERRUPT_TYPED) THEN
		CALL LOCAL_READ()	! Re-enable the local read.
	ENDIF
	RETURN
	END
