$TITLE ('CONNECT MODULE - ESTABLISH A "VIRTUAL TERMINAL" CONNECTION') conn$module: /* COPYRIGHT (C) 1985, Trustees of Columbia University in the City of New */ /* York. Permission is granted to any individual or institution to use, */ /* copy, or redistribute this software so long as it is not sold for */ /* profit, provided this copyright notice is retained. /* /* Contains the following public routines: */ /* conhelp and connect */ do; /* CONNECT: Establish a "virtual terminal" connection through a */ /* specified serial i/o port. Here, port 0 represents the console. */ declare port byte external; declare debug byte external; declare escchar byte external; declare halfduplex byte external; declare true literally '0FFH'; declare false literally '00H'; declare bel literally '07H'; declare port1cmd literally '0F5H'; declare port2cmd literally '0F7H'; declare tx$rdy literally '01H'; declare EnaTxRx literally '025H'; declare Sbrk literally '08H'; declare brklength address initial(233); /* length of VT100 BREAK in msecs */ print: procedure(msg) external; declare msg address; end print; nout: procedure(n) external; declare n address; end nout; newline: procedure external; end newline; ready: procedure (port) byte external; declare port byte; end ready; putc: procedure (c, port) external; declare (c, port) byte; end putc; getc: procedure (port) byte external; declare port byte; end getc; ctl: procedure(char) byte external; declare char byte; end ctl; co: procedure(char) external; declare char byte; end co; /* Display help for the CONNECT command */ conhelp: procedure public; call print(.('\CONNECT\\$')); call print(.(' The CONNECT command is used to establish a $')); call print(.('terminal session with the\$')); call print(.('remote host.\\$')); call print(.('Syntax:\\$')); call print(.(' CONNECT\\$')); call print(.('To revert connect mode to Kermit command level, $')); call print(.('you must use the escape\$')); call print (.('character followed by the letter "C". For help $')); call print(.('on the escape character\$')); call print(.('options, enter the escape character during connect $')); call print(.('mode and follow it with\$')); call print(.('a question mark.\\$')); end conhelp; /* Delay one millisecond */ msecdelay: procedure; declare ctr byte; ctr = 45; do while ctr > 0; ctr = ctr - 1; end; end msecdelay; /* Delay the requested number of milliseconds */ delay: procedure (time); declare time address; do while time > 0; call msecdelay; /* wait one millisecond */ time = time - 1; end; end delay; /* Send a BREAK signal to the remote Kermit */ sendbreak: procedure; declare status byte; do case port; /* turn on the BREAK signal */ do; /* do nothing for console */ end; do; do while (status := input(port1cmd) and tx$rdy) = 0; end; output(port1cmd) = Sbrk; call delay(brklength); /* leave BREAK on specified time */ output(port1cmd) = EnaTxRx; /* turn off the BREAK signal */ end; do; do while (status := input(port2cmd) and tx$rdy) = 0; end; output(port2cmd) = Sbrk; call delay(brklength); /* leave BREAK on specified time */ output(port2cmd) = EnaTxRx; /* turn off the BREAK signal */ end; end; end sendbreak; /* Display escape character options */ eschelp:procedure public; call print(.('\Supported post-escape characters are:\$')); call print(.(' B Send a BREAK signal\$')); call print(.(' C Close connection, return to KERMIT $')); call print(.('command level\$')); call print(.(' ? List available arguments\$')); call print(.(' $')); if escchar < ' ' then do; /* escape char is a control character */ call co('^'); call co(ctl(escchar)); end; else do; call co(escchar); call co(' '); end; call print(.(' Typing the escape character itself sends $')); call print(.('one copy of it to the\$')); call print(.(' remote host\$')); end eschelp; connect: procedure public; declare c byte; declare currstate byte; /* currstate = 1 during normal character entry. */ /* currstate = 2 immediately after the entry of the */ /* declared escape character */ declare connected byte; call print(.('[Connecting to serial port $')); call nout(port); call print(.('. Type $')); if escchar < ' ' then do; /* escape char is a cntrl char */ call print(.('CTRL-$')); call co(ctl(escchar)); end; else call co(escchar); call print(.('C to return to ISIS-KERMIT.]\$')); currstate = 1; /* normal state */ connected = true; do while (connected); /* Process a comm port input character */ if ready(port) > 0 then call putc(getc(port), 0); /* Process a console input character */ if ready(0) > 0 then do; /* a character is available */ c = getc(0); if currstate = 1 then do; if c = escchar then currstate = 2; /* waiting for ctl */ else do; call putc(c, port); /* write it out */ if halfduplex then call putc(c, 0); /* local echo */ end; end; else do; currstate = 1; /* Reset to state 1 */ /* Process the character after the escape */ /* Convert to uppercase if necessary */ if (c >= 'a' and c <= 'z') then c = c - 'a' + 'A'; if c = escchar then do; call putc(c, port); /* write the esc */ if halfduplex then call putc(c,0); /* local echo */ end; else do; if c = 'B' then call sendbreak; else if c = 'C' then connected = false; /* close conn. */ else if c = '?' then call eschelp; /* Unsupported character entered after escape */ else call co(bel); end; end; end; end; call print(.('\[Back at ISIS.]\$')); end connect; end conn$module;