Add tty device command line option

Also broke out common a2 io routines into a2lib.c