; File VA2400PA.SCR
;
; To be used with MS-DOS Kermit 3.11 or later.
;
; An MS-DOS Kermit script program for dialing Vadic 2400PA modems and
; compatibles.  Note that the once-popular Vadic 3451 is slightly different
; and will not work with this script except for internally-stored numbers.
;
;   -- WARNING:  This is no more than 95% debugged, and may not work 
;      properly in some fringe cases. --
;
; Stored in Kermit Distribution as MSMVA2400.SCR; rename to VA2400PA.SCR
; if necessary so the DIAL macro can find it.  Place this file in your
; current directory or in any directory in your DOS PATH, and then set the
; DOS environment variable, MODEM, to be VA2400PA.  Give the following command
; at the DOS prompt before starting Kermit, or add it to your AUTOEXEC.BAT
; file:
;
;   SET MODEM=VA2400PA
;
; Expects variable \%1 to contain the phone number or index number for number
; stored in the modem.  If actually providing a number, preceed it by "D".
; The number is normally provided by the DIAL macro defined in MSKERMIT.INI.
;  If you lack the DIAL macro definition, use this simple substitute:
;   DEFINE DIAL TAKE VA2400PA
; To use, just type DIAL Dnnnnnnn at the MS-Kermit> prompt, where nnnnnnn is
; the desired phone number.  Or type DIAL nn, where nn is the index for a
; number stored in the modem.
;
; The Vadic 2400PA is a pulse-only modem.
;
; Sets SUCCESS flag if dialing succeeds, sets FAILURE flag if it fails, for
; use with IF SUCCESS, IF FAILURE, \v(status).
;
;  Author: John C. Klensin, August 1992 (modified from HAYES.SCR by
;     Christine M. Gianone (July 1991).  MSKERMIT 3.11 or later.
;
echo  Using Vadic 2400PA modem\13\10  ; Comforting in multimodem environment
;
def errfail echo \%1,hangup,goto fail ; Macro to handle failures.
;
if < VERSION 311 errfail {MS-DOS Kermit 3.11 or later required.}
set input timeout proceed       ; Allow IF SUCCESS, IF FAILURE
set input echo off		; hide ^E interactions.
;
hangup				; Modem gets very confused if not started
clear                           ; from a clear state.
;
if not equ \%1 = goto dialnow   ; This provides for initialization only
echo Modem initialization completed, no number to dial
end 0

:DIALNOW
;  connect to, and dial, the modem - 05 decimal is control-E.
;  Try up to four times to get a response from control-E.  If not, give up.
:reinitstar
set count 4
:getstar
output \13
output \05
pause 0
output \13
input 2 *
if SUCCESS goto dialnum
if count goto getstar
errfail {Modem not responding.  Turn on, connect, or manually reset it!}

:DIALNUM
set input echo on		; From now on, show responses
echo \13\10Dialing \%1, wait...\13\10
goto dial                       ; 1st time, skip Redialing message

:REDIAL
pause 30			; Wait 30 seconds before redialing.
echo \13\10Redialing...\13\10   ; Message for redialing.
pause 1

:DIAL
output \%1			; Have to talk slowly to the Vadic
pause 0
output \13
set alarm 60			; Detect keyboard interruptions.
input 40 DIAL			; First thing said is "Dialing"

:GETMSG
input 40 \10			; ending in LF
if success goto gotmsg		; Got a message.
if alarm errfail {No response from modem.} ; No response in 60 secs.
hangup				; User interrupted from keyboard,
goto reinitstar			; so try again right away

:GOTMSG
reinput 0 {ON LINE}             ; Got message, was it ONLINE?
if success goto speed           ; Yes, go check the speed.
reinput 0 {ANSWER TONE}		; More noise
if success goto getmsg
reinput 0 RINGING		; check for RINGING (not real Hayes).
if success goto getmsg	        ; RINGING, just wait for next message.
reinput 0 DIALING		; Got message.  Normally, first two are
if success goto getmsg		; just noise
reinput 0 {NO CARRIER}		; NO CARRIER?
if success goto nocarrier	; Hang up again, then start over
reinput 0 {BUSY!}               ; BUSY?
if success goto busy 		; Go wait a bit, then dial again.
reinput 0 {INVALID COMMAND}       ; modem confused
if success errfail {Modem returns 'invalid command'}
reinput 0 {NO DIAL TONE}
if success goto nodialtn
errfail {No dialtone or no answer.  Try again later.}

:NODIALTN
output I\13			; try to explicitly place modem in IDLE
errfail {No dialtone.  Try again later.}

:NOCARRIER
hangup				; try to clear modem, then retry
clear
goto reinitstar

:BUSY
if < \v(count) 2 goto quit	; Don't wait 60 seconds if tries used up.
Echo \13\10Busy or No Carrier, will dial again in 30 seconds...\13\10
:AGAIN
if count goto redial            ; Then go redial.
:QUIT
errfail {It never answers!  I give up.} ; Too many tries.

:SPEED                          ; Connected!
echo \7                         ; Celebrate with a beep.
reinput 0 1200                  ; Was the message ON LINE 1200?
if success set speed 1200       ; Yes, change the speed.
reinput 0 2400			; Was it ON LINE 2400?
if success set speed 2400	; Yes, change speed.
reinput 0 300			; Try 300, just in case
if success set speed 300	; And set
;
input 60 ERROR CONTROL
if fail errfail {Can't get confirmation of error control} ; Give up
;
define errfail			; Erase ERRFAIL definition
end 0				; Finished, return success code.

:FAIL				; Dialing failed.
define errfail			; Erase ERRFAIL definition
end 1				; Return failure code.
