# ntbatch32 rev[0.01]
################################### check_stty ################################
check_stty ()
{
	echo "###### dp $i0" >> ntdump32
	./dp $i0 >> ntdump32
	echo "###### duart $i0" >> ntdump32
	./duart $i0 >> ntdump32
	echo "###### stty $i0" >> ntdump32
	stty -a < $DEVICES$i0 >> ntdump32
	let i0=i0+1
	if test $i0 -gt $i1
	then 
		return 1
	fi
	return 0
}
################################### main ######################################
i0=1
i1=16

#Check to see if the passed in arguement is a real serial device?
if test $1
then 
	echo "looking for prefix $1$i0"
	if test -r $1$i0
	then 
		echo "Prefix $1$i0 found"
		DEVICES=$1
		echo "Using prefix $DEVICES for NT960 ports"
	else
		echo "Prefix $1$i0 not found"
		exit
	fi

else 
	#If no argument then try for /dev/nt?
	if test -r /dev/nt$i0
	then
		DEVICES="/dev/nt"
		echo "Prefix $DEVICES found"
		echo "Using prefix $DEVICES for NT960 ports"
	else
		echo "No valid NT960 port prefix found"
		exit
	fi
fi

read ans?'Continue (y/n)'
if test $ans != y
then
 	exit
fi

if test -r $DEVICES"17"

then
	i1=32
fi
date > ntdump32
echo "ntbatch" >> ntdump32

# dump port information
echo "Dumping NT960 port information $i0"
while check_stty
do
	echo "Dumping NT960 port information $i0"
done

echo "######" >> ntdump32
echo "Dumping system information"
sin  >> ntdump32
echo "######" >> ntdump32
sin ir >> ntdump32
echo "######" >> ntdump32
sin ar >> ntdump32
echo "######" >> ntdump32
sin in >> ntdump32
echo "######" >> ntdump32
./irq_cnt -a -A >> ntdump32
echo "######" >> ntdump32

echo "Dumping driver memory"
./drvrmem32 >> ntdump32

echo "Dumping NT960 Dual ported memory 64k"
./dm 800000 65536 >> ntdump32

if test $i1 -eq 16
then
	# 16 port system
	echo "Dumping NT960 Main Memory 64k"
	echo "######" >> ntdump32
	./dm 200000 65536 >> ntdump32
	./dm 210000 131072 >> ntdump32
	./dm 230000 65536 >> ntdump32
else
	# 32 port system
	echo "Dumping NT960 Main Memory 128k"
	echo "######" >> ntdump32
	./dm 200000 65536 >> ntdump32
	./dm 210000 131072 >> ntdump32
	./dm 230000 131072 >> ntdump32
fi

date >> ntdump32

if test -r ntdump32.F
then
	echo "ntdump32.F already exists, moving to ntdump32.F"
	mv ntdump32.F ntdump32a.F
fi

echo "Compressing file ntdump32 to ntdump32.F"
freeze ntdump32
echo "Operation complete, transfer file ntdump32.F to Connect Tech"
