home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / intelmdsb / mdscon.p80 < prev    next >
Text File  |  2020-01-01  |  6KB  |  203 lines

  1. $TITLE ('CONNECT MODULE - ESTABLISH A "VIRTUAL TERMINAL" CONNECTION')
  2. conn$module:
  3.  
  4. /* COPYRIGHT (C) 1985, Trustees of Columbia University in the City of New */
  5. /* York.  Permission is granted to any individual or institution to use,  */
  6. /* copy, or redistribute this software so long as it is not sold for      */
  7. /* profit, provided this copyright notice is retained. /*
  8.  
  9. /* Contains the following public routines: */
  10. /*   conhelp and connect */
  11. do;
  12.  
  13. /* CONNECT: Establish a "virtual terminal" connection through a         */
  14. /* specified serial i/o port.  Here, port 0 represents the console.  */
  15.  
  16. declare port byte external;
  17. declare debug byte external;
  18. declare escchar byte external;
  19. declare halfduplex byte external;
  20. declare true literally '0FFH';
  21. declare false literally '00H';
  22. declare bel literally '07H';
  23.  
  24. declare port1cmd literally '0F5H';
  25. declare port2cmd literally '0F7H';
  26. declare tx$rdy literally '01H';
  27. declare EnaTxRx literally '025H';
  28. declare Sbrk literally '08H';
  29.  
  30. declare brklength address initial(233); /* length of VT100 BREAK in msecs */
  31.  
  32. print:    procedure(msg) external;
  33.     declare msg address;
  34. end print;
  35.  
  36. nout:    procedure(n) external;
  37.     declare n address;
  38. end nout;
  39.  
  40. newline: procedure external; end newline;
  41.  
  42. ready:    procedure (port) byte external;
  43.     declare port byte;
  44. end ready;
  45.  
  46. putc:    procedure (c, port) external;
  47.     declare (c, port) byte;
  48. end putc;
  49.  
  50. getc:    procedure (port) byte external;
  51.     declare port byte;
  52. end getc;
  53.  
  54. ctl: procedure(char) byte external;
  55.     declare char byte;
  56. end ctl;
  57.  
  58. co: procedure(char) external;
  59.     declare char byte;
  60. end co;
  61.  
  62. /* Display help for the CONNECT command */
  63. conhelp:    procedure public; 
  64.     call print(.('\CONNECT\\$'));
  65.     call print(.('  The CONNECT command is used to establish a $'));
  66.     call print(.('terminal session with the\$'));
  67.     call print(.('remote host.\\$'));
  68.     call print(.('Syntax:\\$'));
  69.     call print(.('    CONNECT\\$'));
  70.     call print(.('To revert connect mode to Kermit command level, $'));
  71.     call print(.('you must use the escape\$'));
  72.     call print (.('character followed by the letter "C".  For help $'));
  73.     call print(.('on the escape character\$'));
  74.     call print(.('options, enter the escape character during connect $'));
  75.     call print(.('mode and follow it with\$'));
  76.     call print(.('a question mark.\\$'));
  77. end conhelp;
  78.  
  79. /* Delay one millisecond */
  80. msecdelay:    procedure;
  81.     declare ctr byte;
  82.     ctr = 45;
  83.     do while ctr > 0;
  84.       ctr = ctr - 1;
  85.     end;
  86. end msecdelay;
  87.  
  88. /* Delay the requested number of milliseconds */
  89. delay:    procedure (time);
  90.     declare time address;
  91.     do while time > 0;
  92.       call msecdelay; /* wait one millisecond */
  93.       time = time - 1;
  94.     end;
  95. end delay;
  96.  
  97. /* Send a BREAK signal to the remote Kermit */
  98. sendbreak:    procedure;
  99.     declare status byte;
  100.  
  101.     do case port; /* turn on the BREAK signal */
  102.       do; /* do nothing for console */
  103.       end;
  104.       do;
  105.         do while (status := input(port1cmd) and tx$rdy) = 0; end;
  106.         output(port1cmd) = Sbrk;
  107.         call delay(brklength); /* leave BREAK on specified time */
  108.         output(port1cmd) = EnaTxRx; /* turn off the BREAK signal */
  109.       end;
  110.       do;
  111.         do while (status := input(port2cmd) and tx$rdy) = 0; end;
  112.         output(port2cmd) = Sbrk;
  113.         call delay(brklength); /* leave BREAK on specified time */
  114.         output(port2cmd) = EnaTxRx; /* turn off the BREAK signal */
  115.       end;
  116.     end;
  117.  
  118. end sendbreak;
  119.  
  120. /* Display escape character options */
  121. eschelp:procedure public;
  122.     call print(.('\Supported post-escape characters are:\$'));
  123.     call print(.('  B   Send a BREAK signal\$'));
  124.     call print(.('  C   Close connection, return to KERMIT $'));
  125.     call print(.('command level\$'));
  126.     call print(.('  ?   List available arguments\$'));
  127.     call print(.('  $'));
  128.     if escchar < ' ' then do; /* escape char is a control character */
  129.       call co('^');
  130.       call co(ctl(escchar));
  131.       end;
  132.     else do;
  133.       call co(escchar);
  134.       call co(' ');
  135.       end;
  136.     call print(.('  Typing the escape character itself sends $'));
  137.     call print(.('one copy of it to the\$'));
  138.     call print(.('        remote host\$'));
  139. end eschelp;
  140.  
  141. connect:
  142.     procedure public;
  143.     declare c byte;
  144.     declare currstate byte;
  145.     /* currstate = 1 during normal character entry. */
  146.     /* currstate = 2 immediately after the entry of the */
  147.     /*   declared escape character */
  148.     declare connected byte;
  149.  
  150.     call print(.('[Connecting to serial port $'));
  151.     call nout(port);
  152.     call print(.('. Type $'));
  153.     if escchar < ' ' then do; /* escape char is a cntrl char */
  154.       call print(.('CTRL-$'));
  155.       call co(ctl(escchar));
  156.     end;
  157.     else call co(escchar);
  158.     call print(.('C to return to ISIS-KERMIT.]\$'));
  159.     currstate = 1;  /* normal state */
  160.     connected = true;
  161.     do while (connected);
  162.       /* Process a comm port input character */
  163.       if ready(port) > 0 then call putc(getc(port), 0);
  164.       /* Process a console input character */
  165.       if ready(0) > 0 then do; /* a character is available */
  166.         c = getc(0);
  167.         if currstate = 1 then
  168.           do;
  169.             if c = escchar then currstate = 2; /* waiting for ctl */
  170.             else
  171.               do;
  172.                 call putc(c, port); /* write it out */
  173.                 if halfduplex then call putc(c, 0); /* local echo */
  174.               end;
  175.           end;
  176.         else
  177.           do;
  178.             currstate = 1; /* Reset to state 1 */
  179.             /* Process the character after the escape */
  180.             /* Convert to uppercase if necessary */
  181.             if (c >= 'a' and c <= 'z') then c = c - 'a' + 'A';
  182.             if c = escchar then
  183.               do;
  184.                 call putc(c, port); /* write the esc */
  185.                 if halfduplex then call putc(c,0); /* local echo */
  186.               end;
  187.             else do;
  188.               if c = 'B' then call sendbreak;
  189.               else
  190.                 if c = 'C' then connected = false; /* close conn. */
  191.                 else
  192.                   if c = '?' then call eschelp;
  193.                   /* Unsupported character entered after escape */
  194.                   else call co(bel);
  195.               end;
  196.         end;
  197.       end;
  198.     end;
  199.     call print(.('\[Back at ISIS.]\$'));
  200. end connect;
  201.  
  202. end conn$module;
  203.