	SUBROUTINE DIAL_VA3450
C
C	This routine dials the phone number for the RACAL-VADIC 
C       VA3450 modem.
C
	INCLUDE 'COM.INC/NOLIST'

	CHARACTER*(*) NFG_MSG, BAD_MSG
        PARAMETER DIALING_TERMINATOR = 58
	PARAMETER TMO = 100		! Read timeout count.

	LOGICAL WAIT_FOR_READ
        INTEGER*4 DESC(2)
	INTEGER*4 AUTO_RETRY, STATUS

	PARAMETER (NFG_MSG = SS//
	1 '*** The modem is not responding, aborting... ***'//BELL//SS)
	PARAMETER (BAD_MSG = SS//
	1 '*** Bad response from the modem, aborting... ***'//BELL//SS)

	IF (PHONE_SIZE .EQ. 0) RETURN	! No phone number to dial.
C***********************************************************************
C	Setup the terminator table to terminate the read on the
C	RACAL prompt character (* = 42 decimal).
C***********************************************************************
	CALL SET_TERMINATOR(TPTR,TTBL,%REF('*'))

	AUTO_RETRY = 0			! Initialize retry counter.
C
C	Now queue a read from the remote port.
C       Set up to read "Hello: I'm Ready<CR><LF>*"
C 
100	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
C
C	To put the RACAL in autodial (interactive) mode, we must
C	send a control E and a carriage return and then wait for the read.
C
	XBUFFER(1) = ENQ		! Fill in a CTRL E
	CALL WRITE_REMOTE(XBUFFER(1),1)	! WRITE_REMOTE adds carriage return
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) THEN
		IF (CONTROLC_TYPED) GO TO 900 ! CTRL/C typed to abort.
		AUTO_RETRY = AUTO_RETRY + 1 ! Bump the retry count.
		IF (AUTO_RETRY .EQ. AUTODIAL_LIMIT) THEN
			CALL WRITE_USER(NFG_MSG)
			GO TO 900
		ELSE
			GO TO 100	! Try it again ...
		ENDIF
	ENDIF
	AUTO_RETRY = 0			! Reinitialize the retry counter.
C
C	Now we'll do a keyboard dial command.
C
C	*D
C       NUMBER? <CR><LF>
C
	CALL SET_TERMINATOR(TPTR,TTBL,LF)! Terminate read on linefeed.
C
C	Set up to read "*NUMBER?<CR><LF>message from modem.
	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
	XBUFFER(1) = 'D'		! Fill in a D
	CALL WRITE_REMOTE(XBUFFER(1),1)	! carriage return gets filled in later
300     IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) THEN
310             CALL WRITE_USER(BAD_MSG)       ! Tell user its no good.
	        GO TO 900
	ENDIF
	CALL SET_TERMINATOR(TPTR,TTBL,LF)! Terminate read on linefeed.
C
C   Set to read "phone number<CR><LF>".
C
	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
C
C	Now send the phone number.
C
	CALL WRITE_REMOTE(%REF(PHONE_NUMBER),PHONE_SIZE) ! Send the number.
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) GO TO 310
C
C   Set up to read DIALING:
C
	CALL SET_TERMINATOR(TPTR,TTBL,DIALING_TERMINATOR)
	IF (.NOT. POST_READ(RBUFFER,100,TPTR)) GO TO 900! Read "DIALING:".
	CALL WRITE_RIXON(CR,1)			! Finish with RETURN.
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .TRUE.)) GO TO 310
C
C	Now set the read terminator to LF.  The RACAL will display
C	one of the following messages after dialing:
C
C	*** DIALING: phone_number ON LINE<CR><LF>
C				  FAILED CALL <CR><LF>
C
	CALL SET_TERMINATOR(TPTR,TTBL,LF)
	IF (.NOT. POST_READ(RBUFFER,120,TPTR)) GO TO 900! Get the dial response.
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .TRUE.)) GO TO 310
C
C
C	If the modem is really online, set the flags to say so.
C
	IF (FIND_SUBSTRING('ON LINE',RDESC) .GT. 0) THEN
		MODEM_ONLINE = .TRUE.		! Show modem is online.
		REMOTE = .TRUE.			! Make VMS look online.
	ELSEIF (FIND_SUBSTRING('FAILED CALL',RDESC) .GT. 0) THEN
		MODEM_ONLINE = .FALSE.		! Show modem is not online.
		REMOTE = .FALSE.
C
C	Have modem go into IDLE mode so a DIAL or REDIAL Command will
C	work correctly.
C
		XBUFFER(1) = 'I'		! Fill in a I
		CALL WRITE_REMOTE(XBUFFER(1),1)	! carriage return gets filled in later
	CALL SET_TERMINATOR(TPTR,TTBL,LF)! Terminate read on linefeed.
C
C	Set up to read "*IDLE<CR><LF>" message from modem.
	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
	CALL WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)
	ENDIF
900	RETURN
	END

	SUBROUTINE DIAL_VA212
C
C	This routine dials the phone number for the RACAL-VADIC
C	VA212 modem.
C
	INCLUDE 'COM.INC/NOLIST'

	CHARACTER*(*) NFG_MSG, BAD_MSG, NO_ANSWER
	PARAMETER TMO = 100		! Read timeout count.

	LOGICAL WAIT_FOR_READ
        INTEGER*4 DESC(2)
	INTEGER*4 AUTO_RETRY, STATUS

	PARAMETER (NFG_MSG = SS//
	1 '*** The modem is not responding, aborting... ***'//BELL//SS)
	PARAMETER (NO_ANSWER = SS//
	1 '*** System did not answer, call terminated   ***'//BELL//SS)
	PARAMETER (BAD_MSG = SS//
	1 '*** Bad response from the modem, aborting... ***'//BELL//SS)

	IF (PHONE_SIZE .EQ. 0) RETURN	! No phone number to dial.
C***********************************************************************
C	Setup the terminator table to terminate the read on the
C	RACAL prompt character (* = 42 decimal).
C***********************************************************************
	CALL SET_TERMINATOR(TPTR,TTBL,%REF('*'))

	AUTO_RETRY = 0			! Initialize retry counter.
C
C	Now queue a read from the remote port.
C       Set up to read "Hello: I'm Ready<CR><LF>*"
C 
100	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
C
C	To put the RACAL in autodial (interactive) mode, we must
C	send a control E and a carriage return and then wait for the read.
C
	XBUFFER(1) = ENQ		! Fill in a CTRL E
	CALL WRITE_REMOTE(XBUFFER(1),1)	! WRITE_REMOTE adds carriage return
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) THEN
		IF (CONTROLC_TYPED) GO TO 900 ! Return if aborted.
		AUTO_RETRY = AUTO_RETRY + 1 ! Bump the retry count.
		IF (AUTO_RETRY .EQ. AUTODIAL_LIMIT) THEN
			CALL WRITE_USER(NFG_MSG)
			GO TO 900
		ELSE
			GO TO 100	! Try it again ...
		ENDIF
	ENDIF
	AUTO_RETRY = 0			! Reinitialize the retry counter.
C
C	Now we'll do a keyboard dial command.
C
C	D
C       NUMBER? <CR><LF>
C
	CALL SET_TERMINATOR(TPTR,TTBL,LF)! Terminate read on linefeed.
C
C	Set up to read "D<CR><LF>" message from modem.
C
	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
	XBUFFER(1) = 'D'		! Fill in a D
	CALL WRITE_REMOTE(XBUFFER(1),1)	! carriage return gets filled in later
300     IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) THEN
310             CALL WRITE_USER(BAD_MSG)       ! Tell user its no good.
	        GO TO 900
	ENDIF
C
C	Read "NUMBER?<CR><LF>" from modem
C
	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) GO TO 310
	CALL SET_TERMINATOR(TPTR,TTBL,LF)! Terminate read on linefeed.
C
C   Set to read "phone number<CR><LF>".
C
	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
C
C	Now send the phone number.
C
	CALL WRITE_REMOTE(%REF(PHONE_NUMBER),PHONE_SIZE) ! Send the number.
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) GO TO 310
C
C	Now read the phone number the second time.
C
	IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) GO TO 310
C
C   Set up to read DIALING:
C
	CALL SET_TERMINATOR(TPTR,TTBL,LF)
	IF (.NOT. POST_READ(RBUFFER,100,TPTR)) GO TO 900 ! Read <CR><LF>
	CALL WRITE_BYTE(CR,1)			! Finish with RETURN.
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)) GO TO 310
	IF (.NOT. POST_READ(RBUFFER,100,TPTR)) GO TO 900 ! Read "DIALING..."
	IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .TRUE.)) GO TO 310
C
C	Now set the read terminator to LF.  The RACAL will display
C	one of the following messages after dialing:
C
C	DIALING... <CR><LF>	or NO DIAL TONE
C	RINGING... <CR><LF>     (may not appear or may appear several times)
C	ANSWER TONE <CR><LF>     or VOICE or BUSY
C	ON LINE<CR><LF>
C				  FAILED CALL <CR><LF>
C
C	Zero ringing count
C
	RING_COUNT = 0
C
	IF (FIND_SUBSTRING('DIALING',RDESC) .GT. 0) THEN    ! IF #1
	  IF (.NOT. POST_READ(RBUFFER,120,TPTR)) GO TO 900 ! Get "RINGING..."
	  IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .TRUE.)) GO TO 310
		IF (FIND_SUBSTRING('RINGING',RDESC) .GT. 0) THEN ! IF #2
		RING_COUNT = RING_COUNT + 1
700	  IF (.NOT. POST_READ(RBUFFER,120,TPTR)) GO TO 900 ! Get "ANSWER TONE"
	  IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .TRUE.)) GO TO 310
		IF (FIND_SUBSTRING('ANSWER',RDESC) .GT. 0) THEN  ! IF #3A
	  IF (.NOT. POST_READ(RBUFFER,120,TPTR)) GO TO 900 ! Get "ON LINE"
	  IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .TRUE.)) GO TO 310
C
C	If the modem is really online, set the flags to say so.
C
		IF (FIND_SUBSTRING('ON LINE',RDESC) .GT. 0) THEN  ! IF #4
			MODEM_ONLINE = .TRUE.		! Show modem is online.
			REMOTE = .TRUE.			! Make VMS look online.
		ENDIF  !  IF #4
C
C	Modem will continue to display "RINGING..." every time it 'hears'
C	a ringing.  If it hears five rings, then assume the other end will
C	not be answering and send a <CR> to terminate the call.  After the call
C	has been terminated, go to send the IDLE command.
C
	     ELSEIF (FIND_SUBSTRING('RINGING',RDESC) .GT. 0) THEN  ! IF #3A
		RING_COUNT = RING_COUNT + 1
		IF (RING_COUNT .LE. 5) GO TO 700
		CALL WRITE_USER(NO_ANSWER)
		CALL WRITE_BYTE(CR,1) 
		GO TO 800
	     ELSE
C
C	Either the "BUZY" "VOICE" or "FALIED CALL" response was returned.
C
		GO TO 800
	       ENDIF  ! IF #3A
	ELSEIF (FIND_SUBSTRING('ANSWER',RDESC) .GT. 0) THEN !IF #2
	  IF (.NOT. POST_READ(RBUFFER,120,TPTR)) GO TO 900 ! Get "ON LINE"
	  IF (.NOT. WAIT_FOR_READ (RBUFFER, RDESC, .TRUE.)) GO TO 310 
C
C	If the modem is really online, set the flags to say so.
C
		IF (FIND_SUBSTRING('ON LINE',RDESC) .GT. 0) THEN  ! IF #3B
			MODEM_ONLINE = .TRUE.		! Show modem is online.
			REMOTE = .TRUE.			! Make VMS look online.
		ENDIF  !  IF #3B
	ELSE
800		MODEM_ONLINE = .FALSE.		! Show modem is not online.
		REMOTE = .FALSE.
C
C	Have modem go into IDLE mode so a DIAL or REDIAL Command will
C	work correctly.
C
C
C	Set up to read "<LF>*I<CR><LF>IDLE<CR><LF>" message from modem.
C
		CALL SET_TERMINATOR(TPTR,TTBL,LF)! Terminate read on linefeed.
		IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900  ! Read <LF>
		CALL WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)
		IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900  ! Read "*I"
		XBUFFER(1) = 'I'		! Fill in a I
		CALL WRITE_REMOTE(XBUFFER(1),1)	! carriage return gets filled in later
		CALL WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)
C
C	Now read "IDLE<CR><LF>
C
		IF (.NOT. POST_READ(RBUFFER,TMO,TPTR)) GO TO 900
		CALL WAIT_FOR_READ (RBUFFER, RDESC, .FALSE.)
        ENDIF  ! IF #2
	ENDIF
900	RETURN
	END
