! &>>Smartcat<<
! 11/12/1986 - Added more extensive dialer support   
! 10/20/1986 - Original version
!
! smartcat.cmd		-	Novation Smartcat

! WARNING: BINARY FILES CANNOT BE SENT WITH AN 8-BIT ERROR-CHECKED
!          PROTOCOL WITH THIS MODEM!  THIS MODEM CANNOT BE TOLD TO
!	   SEND IT'S COMMAND CHARACTER!  IN NO CASE SHOULD AN XMODEM,
!	   TERM, CROSSTALK, OR ANY OTHER 8-BIT PROTOCOL TRANSFER WITH
!	   THIS OR ANY OTHER COMMUNICATION PROGRAM BE ATTEMPTED OR
!	   STRANGE THINGS WILL HAPPEN!
!
! Modem switches should be 1=off, 2=off, 5=on
! (note: 5=off for ibm-pc)
!
! usage: term -termopts smartcat parameter1 parameter2
!    or: ^E:do smartcat parameter1 parameter2
!    or: F1 E S smartcat parameter1 parameter2
!
! example: term -VS300 smartcat D 1-801-399-5711
!	will run term, emulating a vt100 at 300 baud, and cause a smartcat
!	modem to dial time in Ogden, Utah.
!
! parameter1 must be A,D,H, or O (uppercase)
! paramater2 is only for A or D.  A only needs parameter 2 if you are setting
!            the number of rings to wait before answering. D ALWAYS requires
!            a parameter2, which is the phone number to dial.
!
!	Parameters allowed and what they mean are listed below:
!
! parameter1 parameter2 Description
! ---------- ---------- -----------------------------------------------------
! A                     Answer the phone NOW.  Picks up phone in answer mode.
! A          Rings      Answer the phone if it rings this many times
! D          Number     Dial Number (hit control C to interrupt)
! H                     Hang up the phone (terminate call)
! O                     Originate - for use when number is manually dialed

xmit "^NL 1\r"		! give short (1 character) responses
dwait "1"
xmit "^NE 1\r"		! disable command echo
dwait "1"
xmit "^NF 4\r"		! 8 data bits, 1 stop, no parity (software handles)
dwait "1"
flush

setkey f3 "^NB\r"	! f3 is break
break off

if $1="A"
	if $2=""
		Display "Picking up phone now:"
		xmit "^NA\r"
		dwait "1"
		return
	else
		Display "Modem will now answer phone if it rings $2 times"
		xmit "^NC "
		xmit "$2"
		xmit "\r"
		dwait "1"
		return
	endif
endif

if $1="H"
	Display "Hanging up phone..."
	xmit "^NH\r"
	dwait "1"
	return
endif

if $1="O"
	Display "Picking up phone now:"
	xmit "^NO\r"
	dwait "1"
	return
endif
!
! stuff with two parameters (give error if < 2 used)
!

if $2=""
	display "The $1 command requires 2 parameters"
	abort
endif

if $1="D"
	Display "Dialing $2... type ^C (Control-C) to abort:"
	xmit "^ND "
	xmit "$2"			! in no case multiple params
	xmit "\r"
	setvar x -1
	repeat
		cread x,0,1
		if x="0"
			display "Busy... aborting"
			return
		endif
		if x="1" or x="4"
			display "Connected"
			xmit "^NL 0\r"	! give long responses
			return
		endif
		if x="2" or x="6"
			display "There was no answer... aborting"
			return
		endif
		if x="3"
			display "ERROR: No dial tone"
			abort
		endif
		if x="5"
			display "Ringing..."
		endif
		if x="7"
			display "ERROR: Somebody's calling us"
			abort
		endif
		if x="8"
			display "ERROR: Connect has been lost"
			abort
		endif
	until -1=-2
	return
endif

