home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / intelmdsa / md2ker.plm < prev    next >
Text File  |  2020-01-01  |  17KB  |  580 lines

  1. kermit:
  2. do;
  3.  
  4. declare true literally '0FFH';
  5. declare false literally '00H';
  6.  
  7. declare port1cmd literally '0F5H';
  8. declare port1dat literally '0F4H';
  9. declare port1clk literally '0F0H';
  10. declare timing1 literally '036H';
  11. declare port2cmd literally '0F7H';
  12. declare port2dat literally '0F6H';
  13. declare port2clk literally '0F1H';
  14. declare timing2 literally '076H';
  15. declare modesel literally '0F3H';
  16. declare reset literally '040H';
  17. declare EnaTxRx literally '025H';
  18. declare tx$rdy literally '01H';
  19. declare rx$rdy literally '02H';
  20.  
  21. declare null literally '000H';
  22. declare lf literally '0AH';
  23. declare cr literally '0DH';
  24. declare crlf literally 'cr,lf,null';
  25. declare space literally '20H';
  26. declare dollar literally '24H';
  27.  
  28. declare buflen literally '122';
  29. declare buffer(buflen) byte;
  30. declare (cmdstr, temp, realspeed) address;
  31. declare cmdptr address public;
  32. declare cmd byte;
  33. declare speed byte public;
  34. declare port byte public;
  35. declare driver byte public ;
  36. declare filename address public;
  37. declare buff1 based filename (50) byte;
  38. declare lfilename address public;
  39. declare buff2 based lfilename (50) byte;
  40.  
  41. declare debug byte public;
  42.  
  43.  
  44. /* here are the subroutines */
  45.  
  46. co:     procedure(char)external;
  47.         declare char byte;
  48. end co;
  49.  
  50.  
  51. ci:     procedure byte external;
  52. end ci;
  53.  
  54.  
  55. read:   procedure(jfn, buf, max, count, status)external;
  56.         declare(jfn, buf, max, count, status)address;
  57. end read;
  58.  
  59.  
  60. error:  procedure(errnum)external;
  61.         declare(errnum)address;
  62. end error;
  63.  
  64.  
  65. exit:   procedure external; end exit;
  66.  
  67.  
  68. finish:
  69.         procedure byte external;
  70. end finish;
  71.  
  72. bye:
  73.         procedure byte external;
  74. end bye;
  75.  
  76. connect:
  77.         procedure external;
  78. end connect;
  79.  
  80. send:   procedure byte external;
  81. end send;
  82.  
  83. get:    procedure byte external;
  84. end get;
  85.  
  86. cwd:    procedure byte external;
  87. end cwd;
  88.  
  89. lsend:  procedure byte external;
  90. end lsend;
  91.  
  92.  
  93. recv:   procedure external;
  94. end recv;
  95.  
  96.  
  97. newline:
  98.         procedure public;
  99.         call co(13);
  100.         call co(10);
  101. end newline;
  102.  
  103.  
  104. spin:   procedure(string)address public;
  105.         declare string address;
  106.         declare char based string byte;
  107.  
  108.         do while (char <> null) and (char < 021H);
  109.           string = string + 1;
  110.         end;
  111.         return string;
  112. end spin;
  113.  
  114. strcmp: procedure(s1,s2)byte public;
  115.         declare(s1,s2)address;
  116.         declare c1 based s1 byte;
  117.         declare c2 based s2 byte;
  118.         declare retval byte;
  119.  
  120.         retval = 0;
  121.         s1 = spin(s1);
  122.         s2 = spin(s2);
  123.         if not(c1 = c2) then retval = c1 - c2;
  124.         do while (c1 > 0) and (c2 > 0) and (retval=0);
  125.           retval = c1 - c2;
  126.           s1 = s1+1;
  127.           s2 = s2+1;
  128.         end;
  129.         return retval;
  130.  
  131. end strcmp;
  132.  
  133.  
  134. /* TOKEN: returns a pointer to a null-terminated token pointed          */
  135. /* to prior to the call by cmdptr.  after the call, cmdptr points       */
  136. /* to the end of the original string, or the first character after      */
  137. /* the null character replacing the first whitespace after the first    */
  138. /* token.                                                               */
  139.  
  140. token:  procedure address public;
  141.         declare result address;
  142.         declare char based cmdptr byte;
  143.  
  144.         result = 0;
  145.         cmdptr = spin(cmdptr);
  146.         if char <> null then
  147.           do;
  148.             result = cmdptr;
  149.             do while char > ' ';
  150.               cmdptr = cmdptr + 1;
  151.             end;
  152.             if char <> null then
  153.               do;
  154.                 char = null;
  155.                 cmdptr = cmdptr + 1;
  156.               end;
  157.           end;
  158.         return result;
  159. end token;
  160.  
  161. /* to print out a decimal number */
  162.  
  163. nout:   procedure(n) public;
  164.         declare n address;
  165.         declare (quotient, digit, curr) address;
  166.         declare numbuf(20) byte;
  167.         declare index byte;
  168.  
  169.         if n = 0 then
  170.           do;
  171.             call co('0');
  172.             return;
  173.           end;
  174.         index = 1;
  175.         do while (n > 0);
  176.           digit = n mod 10;
  177.           numbuf(index) = digit+030H;
  178.           index = index + 1;
  179.           n = n / 10;
  180.         end;
  181.         do while ((index := index - 1) > 0);
  182.           call co(numbuf(index));
  183.         end;
  184. end nout;
  185.  
  186.  
  187. nin:    procedure(string) address public;
  188.         declare string address;
  189.         declare result address;
  190.         declare c based string byte;
  191.  
  192.         result = 0;
  193.         if (string <> 0) then do;
  194.           string = spin(string);
  195.           do while (c >= 030H) and (c <= 039H);
  196.             result = result * 10 + (c - 030H);
  197.             string = string + 1;
  198.           end;
  199.         end;
  200.         return result;
  201. end nin;
  202.  
  203.  
  204. print:  procedure(msg) public;
  205.         declare msg address;
  206.         declare c based msg byte;
  207.  
  208.         do while (c > 0) and (c <> '$');
  209.           if c = '\' then
  210.             call newline;
  211.           else
  212.             call co(c);
  213.           msg = msg + 1;
  214.         end;
  215. end print;
  216.  
  217.  
  218. /* IOINIT:  this routine takes a port number, 0,1 or 2, and a speed in the   */
  219. /* range 1-4 and initializes the require port to work at the required speed. */
  220. /* The routine returns no parameters.                                        */
  221.  
  222. ioinit: procedure;
  223.         declare ispeed byte;
  224.         declare baud structure (code(4) byte,
  225.                                 mult(4) byte)
  226.                 data (40H, 10H, 10H, 08H, 0CFH, 0CFH, 0CEH, 0CEH);
  227.  
  228.         ispeed = speed - 1;
  229.         if debug then
  230.           do;
  231.              call newline;
  232.              call print(.('initializing serial port',crlf));
  233.           end;
  234.         do case port;
  235.           do;
  236.             if debug then call print(.('port 0 initialized',crlf));
  237.           end;
  238.           do;
  239.             if debug then call print(.('port 1 initialized',crlf));
  240.             output(port1cmd) = reset;
  241.             output(modesel) = timing1;
  242.             output(port1clk) = baud.code(ispeed);
  243.             output(port1clk) = 0H;
  244.             output(port1cmd) = baud.mult(ispeed);
  245.             output(port1cmd) = EnaTxRx;
  246.           end;
  247.           do;
  248.             if debug then call print(.('port 2 initialized',crlf));
  249.             output(port2cmd) = reset;
  250.             output(modesel) = timing2;
  251.             output(port2clk) = baud.code(ispeed);
  252.             output(port2clk) = 0H;
  253.             output(port2cmd) = baud.mult(ispeed);
  254.             output(port2cmd) = EnaTxRx;
  255.           end;
  256.         end;
  257. end ioinit;
  258.  
  259.  
  260. usage:  procedure;
  261.         call print(.('usage: kermit (300|1200|4800|9600) (1|2)',crlf));
  262.         call exit;
  263. end usage;
  264.  
  265.  
  266. readln: procedure;
  267.         declare (count, status) address;
  268.  
  269.         call read(1, .buffer, buflen, .count, .status);
  270.         if status > 0 then
  271.           do;
  272.             call print(.('READLN FAILED',crlf));
  273.             call error(status);
  274.             call exit;
  275.           end;
  276.         buffer(count-2) = 0;
  277.         cmdptr = .buffer;
  278. end readln;
  279.  
  280.  
  281. help: procedure;
  282.      call print(.('                      HELP MENU $  ',crlf));
  283.      call newline;
  284.      call newline;
  285.      call print(.(' there are 10 commands used in ISIS-Kermit',crlf));
  286.      call print(.(' CONNECT connect to the host as a virtual terminal ',crlf));
  287.      call print(.('      The format of CONNECT command is   ',crlf));
  288.      call print(.('          ISIS-Kermit> Connect',crlf));
  289.      call newline;
  290.      call print(.(' SEND Send files from the MDS to the other Kermit. ',crlf));
  291.      call print(.('      The format of SEND command is   ',crlf));
  292.      call print(.('          ISIS-Kermit> Send Filename.Ext ',crlf));
  293.      call newline;
  294.      call print(.(' RECEIVE Receive files from the other Kermit ',crlf));
  295.      call print(.('      received filename has at most 6 characters ',crlf));
  296.      call print(.('      The format of RECEIVE command is   ',crlf));
  297.      call print(.('          ISIS-Kermit> Receive',crlf));
  298.      call newline;
  299.      call print(.(' DEBUG Display packet traffic , packet number ',crlf));
  300.      call print(.('      packet contents. ',crlf));
  301.      call print(.('      The format of DEBUG command is  ',crlf));
  302.      call print(.('          ISIS-Kermit> Debug',crlf));
  303.      call newline;
  304.      call print(.(' LSEND send files from the MDS to VAX-KERMIT . ',crlf));
  305.      call print(.('      The format of LSEND command is ',crlf));
  306.      call print(.('          ISIS-Kermit> LSEND Listfile.Ext ',crlf));
  307.      call print(.(' NOTE : Listfile contains the filenames of files ',crlf));
  308.      call print(.('        to be send to the VAX ',crlf));
  309.      call newline;
  310.      call print(.(' GET  Get files from the VAX to the MDS ',crlf));
  311.      call print(.('      when VAX-KERMIT is in SERVER mode .',crlf));
  312.      call print(.('      The format of GET command is   ',crlf));
  313.      call print(.('          ISIS-Kermit> Get Filename.Ext ',crlf));
  314.      call newline;
  315.      call print(.(' CWD  Change working directory on the VAX ',crlf));
  316.      call print(.('      when VAX-KERMIT is in SERVER mode .',crlf));
  317.      call print(.('      The format of CWG command is   ',crlf));
  318.      call print(.('          ISIS-Kermit> CWD [directory] ',crlf));
  319.      call newline;
  320.      call print(.(' EXIT EXIT ISIS-Kermit ',crlf));
  321.      call print(.('      The format of EXIT command is   ',crlf));
  322.      call print(.('          ISIS-Kermit> Exit ',crlf));
  323.      call newline;
  324.      call print(.(' FINISH EXIT  From VAX-KERMIT ',crlf));
  325.      call print(.('      when VAX-KERMIT is in SERVER mode .',crlf));
  326.      call print(.('      The format of FINISH command is   ',crlf));
  327.      call print(.('          ISIS-Kermit> FINISH ',crlf));
  328.      call newline;
  329.      call print(.(' BYE  Log out from VAX ',crlf));
  330.      call print(.('      when VAX-KERMIT is in SERVER mode .',crlf));
  331.      call print(.('      The format of BYE command is   ',crlf));
  332.      call print(.('          ISIS-Kermit> BYE ',crlf));
  333.      call newline;
  334.      call newline;
  335.    end help;
  336.  
  337.  
  338. /* to specify the disk driver number ( from 0 to 4 ) which will be used for
  339.    file transfer */
  340.  
  341. setdrnum : procedure;
  342.  
  343.             cmdstr = 0;
  344.             do while (cmdstr = 0);
  345.                 call print(.('disk driver number(0|1|2|3|4) ==> ',null));
  346.                 call readln;
  347.                 cmdstr = token;
  348.             end;
  349.             call newline;
  350.             if (strcmp(cmdstr,.('0',null)) = 0) then driver = 0;
  351.             else
  352.                if (strcmp(cmdstr,.('1',null)) = 0) then driver = 1;
  353.               else
  354.                 if (strcmp(cmdstr,.('2',null)) = 0) then driver = 2;
  355.                   else
  356.                     if (strcmp(cmdstr,.('3',null)) = 0) then driver = 3;
  357.                      else
  358.                        if (strcmp(cmdstr,.('4',null)) = 0) then driver = 4;
  359.                         else do;
  360.                           call print(.('error , try again ' ,crlf));
  361.                           call exit;
  362.                         end;
  363.  
  364. end setdrnum;
  365.  
  366.  
  367. /* *** main program *** */
  368. Call newline;
  369. Call newline;
  370. debug = false;
  371. call readln;
  372. cmdstr = 0;
  373. do while (cmdstr = 0);
  374.  call print(.('input your desired baud rate (300|1200|4800|9600)  ',null));
  375.  call readln;
  376.  cmdstr = token;
  377. end;
  378.  call newline;
  379.      if (strcmp(cmdstr,.('9600',null)) = 0) then do;
  380.                 realspeed = 9600;
  381.                 speed = 4;
  382.           end;
  383.           else
  384.             if (strcmp(cmdstr,.('4800',null)) = 0) then do;
  385.                 realspeed  = 4800;
  386.                 speed = 3;
  387.               end;
  388.               else
  389.                 if (strcmp(cmdstr,.('1200',null)) = 0) then do;
  390.                    realspeed = 1200;
  391.                    speed = 2;
  392.                   end;
  393.                   else
  394.                     if (strcmp(cmdstr,.('300',null)) = 0) then do;
  395.                         realspeed = 300;
  396.                         speed = 1;
  397.                       end;
  398.                       else call usage;
  399.  
  400. port = 1;
  401.  
  402. /* read desired baud rate, if supplied */
  403.  
  404. temp = token;
  405. if temp > 0 then realspeed = nin(temp);
  406.  
  407. /* get desired port, if supplied */
  408.  
  409. temp = token;
  410. if temp > 0 then port = nin(temp);
  411.  
  412. /* make sure there's garbage on the end of the line */
  413.  
  414. if token > 0 then call usage;
  415.  
  416. if (port < 1) or (port > 2) then call usage;
  417.  
  418. call print(.('Serial port ',null));
  419. call nout(port);
  420. call print(.(', Baud rate ',null));
  421. call nout(realspeed);
  422. call newline;
  423.  
  424. call ioinit;
  425.  
  426. do while (true);
  427.         cmdstr = 0;
  428.         do while (cmdstr = 0);
  429.           call print(.('ISIS-Kermit>',null));
  430.           call readln;
  431.           cmdstr = token;
  432.         end;
  433.  
  434.         if ((strcmp(cmdstr,.('connect',null)) = 0) or
  435.             (strcmp(cmdstr,.('CONNECT',null)) = 0)) then cmd = 1;
  436.           else
  437.             if ((strcmp(cmdstr,.('send',null)) = 0) or
  438.                 (strcmp(cmdstr,.('SEND',null)) = 0)) then cmd = 2;
  439.               else
  440.             if ((strcmp(cmdstr,.('lsend',null)) = 0) or
  441.                 (strcmp(cmdstr,.('LSEND',null)) = 0)) then cmd = 3;
  442.               else
  443.                 if ((strcmp(cmdstr,.('get',null)) = 0) or
  444.                     (strcmp(cmdstr,.('GET',null)) = 0)) then cmd = 4;
  445.                  else
  446.                 if ((strcmp(cmdstr,.('cwd',null)) = 0) or
  447.                     (strcmp(cmdstr,.('CWD',null)) = 0)) then cmd = 5;
  448.                  else
  449.                 if ((strcmp(cmdstr,.('receive',null)) = 0) or
  450.                     (strcmp(cmdstr,.('RECEIVE',null)) = 0)) then cmd = 6;
  451.                   else
  452.                     if ((strcmp(cmdstr,.('exit',null)) = 0) or
  453.                         (strcmp(cmdstr,.('EXIT',null)) = 0)) then cmd = 7;
  454.                       else
  455.                     if ((strcmp(cmdstr,.('finish',null)) = 0) or
  456.                         (strcmp(cmdstr,.('FINISH',null)) = 0)) then cmd = 8;
  457.                       else
  458.                     if ((strcmp(cmdstr,.('bye',null)) = 0) or
  459.                         (strcmp(cmdstr,.('BYE',null)) = 0)) then cmd = 9;
  460.                       else
  461.                         if ((strcmp(cmdstr,.('debug',null)) = 0) or
  462.                             (strcmp(cmdstr,.('DEBUG',null)) = 0)) then cmd = 10;
  463.                         else
  464.                           if ((strcmp(cmdstr,.('help',null)) = 0) or
  465.                             (strcmp(cmdstr,.('HELP',null)) = 0)) then cmd = 11;
  466.                              else cmd = 0;
  467.  
  468.         if ((cmd < 2) or (cmd > 5))then
  469.           if token > 0 then
  470.             cmd = 0;
  471.  
  472.         do case cmd;
  473.  
  474.           do; /* cmd = 0 */
  475.               call print(.('Syntax error',crlf));
  476.           end;
  477.  
  478.           do; /* cmd = 1*/
  479.               call connect;
  480.           end; /* cmd = 1 */
  481.  
  482.           do;/* send files   cmd = 2 */
  483.             filename = token;
  484.             if (filename = 0)
  485.             then
  486.               call print(.('No files specified',crlf));
  487.             else
  488.               if send
  489.               then
  490.                    call print(.(cr,lf,'OK',crlf));
  491.               else
  492.                    call print(.('Send failed',crlf));
  493.  
  494.           end; /* send files   cmd = 2 */
  495.  
  496.           do;/* send files     cmd = 3 */
  497.             lfilename = token;
  498.             if (lfilename = 0)
  499.             then
  500.                 call print(.('No list of files specified',crlf));
  501.             else
  502.                 if lsend
  503.                 then
  504.                    call print(.(cr,lf,' OK ',crlf));
  505.  
  506.           end; /* send files     cmd = 3 */
  507.  
  508.           do;/* get      cmd = 4 */
  509.             filename = token;
  510.             if (filename = 0)
  511.             then
  512.                  call print(.('No files specified',crlf));
  513.             else do;
  514.                  call setdrnum;
  515.                  if get
  516.                  then
  517.                      call print(.(cr,lf,'OK',crlf));
  518.                  else
  519.                       call print(.('Get failed',crlf));
  520.             end;
  521.           end; /* get      cmd = 4 */
  522.  
  523.           do;/* change directory  cmd = 5 */
  524.             call newline;
  525.             filename = token;
  526.             if (filename = 0)
  527.             then
  528.                 call print(.('No directory specified',crlf));
  529.             else do;
  530.                 if cwd
  531.                 then
  532.                       call newline;
  533.                 else
  534.                       call print(.(' Can not change working directory',crlf));
  535.             end;
  536.             call newline;
  537.           end; /* change directory  cmd = 5 */
  538.  
  539.           do; /* receive   cmd = 6 */
  540.             filename = token;
  541.             call setdrnum;
  542.             call recv;
  543.             call print(.(cr,lf,'OK',crlf));
  544.           end; /* receive   cmd = 6 */
  545.  
  546.           do; /* exit cmd = 7 */
  547.               call exit;
  548.           end ; /* exit cmd = 7 */
  549.  
  550.           do; /* finish cmd = 8 */
  551.             call newline;
  552.             if finish
  553.               then
  554.                         call print(.('end of SERVER mode on VAX-KERMIT ',crlf));
  555.               else
  556.                       call print(.('SERVER mode on VAX ',crlf));
  557.           end; /* finish cmd = 8 */
  558.  
  559.           do; /* bye cmd = 9 */
  560.             call newline;
  561.             if bye
  562.               then
  563.                     call print(.('logout from VAX-VMS ',crlf));
  564.               else
  565.                     call print(.('login VAX-VMS ',crlf));
  566.          end; /* bye cmd = 9 */
  567.  
  568.           do; /* debug cmd = 10 */
  569.                debug = not debug;
  570.           end; /* bye cmd = 10 */
  571.  
  572.           do; /* help cmd = 11 */
  573.                call help;
  574.           end ;/* help cmd = 11 */
  575.         end; /* case cmd */
  576. end;
  577.  
  578. end kermit;
  579.  
  580.