

;**************************************************************************
;
;                    Microsoft Mail Script File
;
;       Filename: MS56VL.MDM
;       Script  : Script file for Compaq 56VL Global Internal Modem
;       Version : V1.0
;
;
;**************************************************************************


INITIALIZE:
	title "Compaq 56VL Global Internal Modem"

	$attempts = 0
init_retry:
	inc $attempts
	if ($attempts > 10)                             ; if 10 attempts have failed...
	    return 4                                    ; return ERROR
	$ret = 4                                        ; default return code is ERROR

	clearrsp                                        ; clear the response buffer

	sendln "AT&FE0V1S0=0S7=45W2S95=3M1"
	waitrsp 5                               ; wait 5 seconds for response from modem

	if (response = "^M")
	   waitrsp 5

	if ("OK" isin response)
	   goto Init_Basics_Done
	else
	   waitrsp 5

	if ("OK" isin response)
	   goto Init_Basics_Done
	else
	   goto init_retry

Init_Basics_Done:                       ; Basic initialization successful
	$ret = 0                        ; Return code = OK
	clearrsp                        ; clear the response buffer

Init_exit:
	clearrsp                        ; clear the response buffer
	return $ret                     ; return the result


;-------------------------------------------------------------------------------
RESET:
	$attempts = 0
reset_retry:
	inc $attempts
	if ($attempts > 10)             ; if 10 attempts have failed...
	    return 4                    ; return ERROR

	clearrsp                        ; clear the response buffer

	sendln "AT&FE0V1S0=0S7=45W2S95=3M1"
	waitrsp 5
	if (response = "^M")
	   waitrsp 5

	if ("OK" isin response)
	   return 0
	else
	   waitrsp 5

	if ("OK" isin response)
	   return 0
	else
	   goto reset_retry


;-------------------------------------------------------------------------------
CALL:
	clearrsp                        ; clear the response buffer
	$ret = 8                        ; set return value default NO ANSWER
	echo 0                          ; do not display phone number

	sendln "ATD" + dial_mode + phone_number  ; execute the dial up 

	echo 1                          ; turn echo back on

ring_loop:
	waitrsp 120                     ; wait up to 2 minutes for response code
	if ("CONNECT" isin response)
	   {
	   if ("33600" isin response)
	      {
	      display ">>> CONNECT 33600 bps <<<"
	      $ret = 34                  ; return CONNECT 33600
	      }
	   if ("31200" isin response)
	      {
	      display ">>> CONNECT 31200 bps <<<"
	      $ret = 33                  ; return CONNECT 31200
	      }
	   if ("28800" isin response)
	      {
	      display ">>> CONNECT 28800 bps <<<"
	      $ret = 15                  ; return CONNECT 28800
	      }
	   if ("26400" isin response)
	      {
	      display ">>> CONNECT 26400 bps <<<"
	      $ret = 32                  ; return CONNECT 26400
	      }
	   if ("24000" isin response)
	      {
	      display ">>> CONNECT 24000 bps <<<"
	      $ret = 30                  ; return CONNECT 24000
	      }
	   if ("21600" isin response)
	      {
	      display ">>> CONNECT 21600 bps <<<"
	      $ret = 29                  ; return CONNECT 21600
	      }
	   if ("19200" isin response)
	      {
	      display ">>> CONNECT 19200 bps <<<"
	      $ret = 14                  ; return CONNECT 19200
	      }
	   if ("16800" isin response)
	      {
	      display ">>> CONNECT 16800 bps <<<"
	      $ret = 86                  ; return CONNECT 16800
	      }
	   if ("14400" isin response)
	      {
	      display ">>> CONNECT 14400 bps <<<"
	      $ret = 13                  ; return CONNECT 14400
	      }
	   if ("12000" isin response)
	      {
	      display ">>> CONNECT 12000 bps <<<"
	      $ret = 25                  ; return CONNECT 12000
	      }
	   if ("9600" isin response)
	      {
	      display ">>> CONNECT 9600 bps <<<"
	      $ret = 12                  ; return CONNECT 9600
	      }
	   if ("7200" isin response)
	      {
	      display ">>> CONNECT 7200 bps <<<"
	      $ret = 24                  ; return CONNECT 7200
	      }
	   if ("4800" isin response)
	      {
	      display ">>> CONNECT 4800 bps <<<"
	      $ret = 11                  ; return CONNECT 4800
	      }
	   if ("2400" isin response)
	      {
	      if ($ret != 30)              ; check NOT 24000 baud
		 {
		 display ">>> CONNECT 2400 bps <<<"
		 $ret = 10                  ; return CONNECT 2400
		 }
	      }
	   if ("1200" isin response)
	      {
	      if ($ret != 25)              ; check NOT 12000 baud
		 {                 
		 display ">>> CONNECT 1200 bps <<<"
		 $ret = 5                  ; return CONNECT 1200
		 }              
	      }
	   if ("/ARQ" isin response)
	      {
	      display ">>> V.42 LAPM Error Corrected Link <<<"
	      if ("2400" isin response)
		$ret = 10                  ; return CONNECT 2400
	      else if ("1200" isin response)
		$ret = 5                  ; return CONNECT 1200
	      }
	   }
	   else if ("NO CARRIER" isin response)           
	      {
	      display "<<< HOST MODEM CARRIER NOT DETECTED >>>"
	      $ret = 3
	      }
	   else if ("ERROR" isin response)           
	      {
	      display "<<< MODEM ERROR >>>"
	      $ret = 4
	      }
	   else if ("DELAYED" isin response)           
	      {
	      display "<<< DELAYED NUMBER >>>"
	      $ret = 4
	      }
	   else if ("BLACKLISTED" isin response)           
	      {
	      display "<<< BLACKLISTED NUMBER >>>"
	      $ret = 4
	      }
	   else if ("NO DIALTONE" isin response)           
	      {
	      display "<<< NO DIALTONE DETECTED >>>"
	      $ret = 6
	      }
	   else if ("BUSY" isin response)           
	      {
	      display "<<< HOST MODEM BUSY >>>"
	      $ret = 7
	      }
	   else if ("NO ANSWER" isin response)           
	      {
	      display "<<< NO ANSWER FROM HOST >>>"
	      $ret = 8
	      }
	   else if ("RING" isin response) 
	      goto ring_loop
	   else $ret = 8

	   return $ret
;-------------------------------------------------------------------------------
ANSWER:
	
	$ret = 8
	waitrsp 5                       ; see if phone is ringing 
	echo 0
	if (listen = 1)
	   sendln "ATD"
	else if (response = "^M")
	   waitrsp 5
	else if ("RING" isin response)
	   sendln "ATA"   ; answer the phone normally
	else
	   return 8             ; return "NO ANSWER"
	echo 1
	waitrsp 120             ; wait up to 2 minutes for response from modem
	if ("CONNECT" isin response)
	   {
	   if ("33600" isin response)
	      {
	      display ">>> CONNECT 33600 bps <<<"
	      $ret = 34                  ; return CONNECT 33600
	      }
	   if ("31200" isin response)
	      {
	      display ">>> CONNECT 31200 bps <<<"
	      $ret = 33                  ; return CONNECT 31200
	      }
	   if ("28800" isin response)
	      {
	      display ">>> CONNECT 28800 bps <<<"
	      $ret = 15                  ; return CONNECT 28800
	      }
	   if ("26400" isin response)
	      {
	      display ">>> CONNECT 26400 bps <<<"
	      $ret = 32                  ; return CONNECT 26400
	      }
	   if ("24000" isin response)
	      {
	      display ">>> CONNECT 24000 bps <<<"
	      $ret = 30                  ; return CONNECT 24000
	      }
	   if ("21600" isin response)
	      {
	      display ">>> CONNECT 21600 bps <<<"
	      $ret = 29                  ; return CONNECT 21600
	      }
	   if ("19200" isin response)
	      {
	      display ">>> CONNECT 19200 bps <<<"
	      $ret = 14                  ; return CONNECT 19200
	      }
	   if ("16800" isin response)
	      {
	      display ">>> CONNECT 16800 bps <<<"
	      $ret = 86                  ; return CONNECT 16800
	      }
	   if ("14400" isin response)
	      {
	      display ">>> CONNECT 14400 bps <<<"
	      $ret = 13                  ; return CONNECT 14400
	      }
	   if ("12000" isin response)
	      {
	      display ">>> CONNECT 12000 bps <<<"
	      $ret = 25                  ; return CONNECT 12000
	      }
	   if ("9600" isin response)
	      {
	      display ">>> CONNECT 9600 bps <<<"
	      $ret = 12                  ; return CONNECT 9600
	      }
	   if ("7200" isin response)
	      {
	      display ">>> CONNECT 7200 bps <<<"
	      $ret = 24                  ; return CONNECT 7200
	      }
	   if ("4800" isin response)
	      {
	      display ">>> CONNECT 4800 bps <<<"
	      $ret = 11                  ; return CONNECT 4800
	      }
	   if ("2400" isin response)
	      {
	      if ($ret != 30)              ; check NOT 24000 baud
		 {
		 display ">>> CONNECT 2400 bps <<<"
		 $ret = 10                  ; return CONNECT 2400
		 }
	      }
	   if ("1200" isin response)
	      {
	      if ($ret != 25)              ; check NOT 12000 baud
		 {                 
		 display ">>> CONNECT 1200 bps <<<"
		 $ret = 5                  ; return CONNECT 1200
		 }              
	      }
	   if ("/ARQ" isin response)
	      {
	      display ">>> V.42 LAPM Error Corrected Link <<<"
	      if ("2400" isin response)
		$ret = 10                  ; return CONNECT 2400
	      else if ("1200" isin response)
		$ret = 5                  ; return CONNECT 1200
	      }
	   }
	   else if ("NO CARRIER" isin response)           
	      {
	      display "<<< HOST MODEM CARRIER NOT DETECTED >>>"
	      $ret = 3
	      }
	   else if ("ERROR" isin response)           
	      {
	      display "<<< MODEM ERROR >>>"
	      $ret = 4
	      }
	   else if ("DELAYED" isin response)           
	      {
	      display "<<< DELAYED NUMBER >>>"
	      $ret = 4
	      }
	   else if ("BLACKLISTED" isin response)           
	      {
	      display "<<< BLACKLISTED NUMBER >>>"
	      $ret = 4
	      }
	   else if ("NO DIALTONE" isin response)           
	      {
	      display "<<< NO DIALTONE DETECTED >>>"
	      $ret = 6
	      }
	   else if ("BUSY" isin response)           
	      {
	      display "<<< HOST MODEM BUSY >>>"
	      $ret = 7
	      }
	   else if ("NO ANSWER" isin response)           
	      {
	      display "<<< NO ANSWER FROM HOST >>>"
	      $ret = 8
	      }
	   else $ret = 8

	   return $ret

;-------------------------------------------------------------------------------
DISCONNECT:
	wait 2                 ; wait 2 seconds 

	send "+++"             ; send escape sequence to put modem back to 
			       ;    command state 
	wait 2                 ; wait 2 seconds 

	clearrsp               ; clear the response buffer 

	sendln "ATH0"          ; hang up the phone 

	waitrsp 5              ; wait for a response 

	if ("OK" isin response)
	   {
	   display "<<< DISCONNECT COMMAND SUCCESSFUL >>>"
	   return 0
	   }
	else                    ; if hang up failed, drop DTR to force hang up
	   {
	   display "<<< DISCONNECT COMMAND FAILED >>>"           
	   DTR 0               ; drop DTR to reset modem 
	   wait 2              ; some modems require a delay here
	   DTR 1               ; raise DTR 
	   clearrsp            ; clear response buffer
	   display "<<< DISCONNECT VIA DTR DROP >>>"           
	   }

	return 0                ; always return OK 
