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

  1.  kermit:
  2.  
  3. do;
  4.  
  5.  
  6.  
  7. declare true literally '0FFH';
  8.  
  9. declare false literally '00H';
  10.  
  11.  
  12.  
  13. declare port1cmd literally '0F5H';
  14.  
  15. declare port1dat literally '0F4H';
  16.  
  17. declare port1clk literally '0F0H';
  18.  
  19. declare timing1 literally '036H';
  20.  
  21. declare port2cmd literally '0F7H';
  22.  
  23. declare port2dat literally '0F6H';
  24.  
  25. declare port2clk literally '0F1H';
  26.  
  27. declare timing2 literally '076H';
  28.  
  29. declare modesel literally '0F3H';
  30.  
  31. declare reset literally '040H';
  32.  
  33. declare EnaTxRx literally '025H';
  34.  
  35. declare tx$rdy literally '01H';
  36.  
  37. declare rx$rdy literally '02H';
  38.  
  39.  
  40.  
  41. declare null literally '000H';
  42.  
  43. declare lf literally '0AH';
  44.  
  45. declare cr literally '0DH';
  46.  
  47. declare crlf literally 'cr,lf,null';
  48.  
  49. declare space literally '20H';
  50.  
  51. declare dollar literally '24H';
  52.  
  53.  
  54.  
  55. declare buflen literally '122';
  56.  
  57. declare buffer(buflen) byte;
  58.  
  59. declare (cmdstr, temp, cmdptr, realspeed) address;
  60.  
  61.  
  62.  
  63. declare cmd byte;
  64.  
  65. declare speed byte public;
  66.  
  67. declare port byte public;
  68.  
  69.  
  70.  
  71. declare filename address public;
  72.  
  73.  
  74.  
  75. declare debug byte public;
  76.  
  77.  
  78.  
  79.  
  80.  
  81. /* here are the subroutines */
  82.  
  83.  
  84.  
  85. co:    procedure(char)external;
  86.  
  87.     declare char byte;
  88.  
  89. end co;
  90.  
  91.  
  92.  
  93.  
  94.  
  95. ci:    procedure byte external;
  96.  
  97. end ci;
  98.  
  99.  
  100.  
  101.  
  102.  
  103. read:    procedure(jfn, buf, max, count, status)external;
  104.  
  105.     declare(jfn, buf, max, count, status)address;
  106.  
  107. end read;
  108.  
  109.  
  110.  
  111.  
  112.  
  113. error:    procedure(errnum)external;
  114.  
  115.     declare(errnum)address;
  116.  
  117. end error;
  118.  
  119.  
  120.  
  121.  
  122.  
  123. exit:    procedure external; end exit;
  124.  
  125.  
  126.  
  127.  
  128.  
  129. connect:
  130.  
  131.     procedure external;
  132.  
  133. end connect;
  134.  
  135.  
  136.  
  137.  
  138.  
  139. send:     procedure byte external;
  140.  
  141. end send;
  142.  
  143.  
  144.  
  145.  
  146.  
  147. recv:    procedure external;
  148.  
  149. end recv;
  150.  
  151.  
  152.  
  153.  
  154.  
  155. newline:
  156.  
  157.     procedure public;
  158.  
  159.     call co(13);
  160.  
  161.     call co(10);
  162.  
  163. end newline;
  164.  
  165.  
  166.  
  167.  
  168.  
  169. spin:    procedure(string)address public;
  170.  
  171.     declare string address;
  172.  
  173.         declare char based string byte;
  174.  
  175.  
  176.  
  177.     do while (char <> null) and (char < 021H);
  178.  
  179.       string = string + 1;
  180.  
  181.     end;
  182.  
  183.     return string;
  184.  
  185. end spin;
  186.  
  187.  
  188.  
  189.  
  190.  
  191. strcmp:    procedure(s1,s2)byte public;
  192.  
  193.     declare(s1,s2)address;
  194.  
  195.     declare c1 based s1 byte;
  196.  
  197.     declare c2 based s2 byte;
  198.  
  199.     declare retval byte;
  200.  
  201.  
  202.  
  203.     retval = 0;
  204.  
  205.     s1 = spin(s1);
  206.  
  207.     s2 = spin(s2);
  208.  
  209.     if not(c1 = c2) then retval = c1 - c2;
  210.  
  211.     do while (c1 > 0) and (c2 > 0) and (retval=0);
  212.  
  213.       retval = c1 - c2;
  214.  
  215.       s1 = s1+1;
  216.  
  217.       s2 = s2+1;
  218.  
  219.     end;
  220.  
  221.     return retval;
  222.  
  223.  
  224.  
  225. end strcmp;
  226.  
  227.  
  228.  
  229.  
  230.  
  231. /* TOKEN: returns a pointer to a null-terminated token pointed        */
  232.  
  233. /* to prior to the call by cmdptr.  after the call, cmdptr points    */
  234.  
  235. /* to the end of the original string, or the first character after    */
  236.  
  237. /* the null character replacing the first whitespace after the first    */
  238.  
  239. /* token.                                */
  240.  
  241.  
  242.  
  243. token:     procedure address public;
  244.  
  245.     declare result address;
  246.  
  247.     declare char based cmdptr byte;
  248.  
  249.  
  250.  
  251.     result = 0;
  252.  
  253.     cmdptr = spin(cmdptr);
  254.  
  255.     if char <> null then 
  256.  
  257.       do;
  258.  
  259.         result = cmdptr;
  260.  
  261.         do while char > ' ';
  262.  
  263.           cmdptr = cmdptr + 1;
  264.  
  265.         end;
  266.  
  267.         if char <> null then
  268.  
  269.           do;
  270.  
  271.             char = null;
  272.  
  273.             cmdptr = cmdptr + 1;
  274.  
  275.           end;
  276.  
  277.       end;
  278.  
  279.     return result;
  280.  
  281. end token;
  282.  
  283.  
  284.  
  285.  
  286.  
  287. nout:    procedure(n) public;
  288.  
  289.     declare n address;
  290.  
  291.     declare (quotient, digit, curr) address;
  292.  
  293.     declare numbuf(20) byte;
  294.  
  295.     declare index byte;
  296.  
  297.  
  298.  
  299.     if n = 0 then
  300.  
  301.       do;
  302.  
  303.         call co('0');
  304.  
  305.         return;
  306.  
  307.       end;
  308.  
  309.     index = 1;
  310.  
  311.     do while (n > 0);
  312.  
  313.       digit = n mod 10;
  314.  
  315.       numbuf(index) = digit+030H;
  316.  
  317.       index = index + 1;
  318.  
  319.       n = n / 10;
  320.  
  321.     end;
  322.  
  323.     do while ((index := index - 1) > 0);
  324.  
  325.       call co(numbuf(index));
  326.  
  327.     end;
  328.  
  329. end nout;
  330.  
  331.  
  332.  
  333.  
  334.  
  335. nin:    procedure(string) address public;
  336.  
  337.     declare string address;
  338.  
  339.     declare result address;
  340.  
  341.     declare c based string byte;
  342.  
  343.  
  344.  
  345.     result = 0;
  346.  
  347.     if (string <> 0) then do;
  348.  
  349.       string = spin(string);
  350.  
  351.       do while (c >= 030H) and (c <= 039H);
  352.  
  353.         result = result * 10 + (c - 030H);
  354.  
  355.         string = string + 1;
  356.  
  357.       end;
  358.  
  359.     end;
  360.  
  361.     return result;
  362.  
  363. end nin;
  364.  
  365.  
  366.  
  367.  
  368.  
  369. print:    procedure(msg) public;
  370.  
  371.     declare msg address;
  372.  
  373.     declare c based msg byte;
  374.  
  375.  
  376.  
  377.     do while (c > 0) and (c <> '$');
  378.  
  379.       if c = '\' then
  380.  
  381.         call newline;
  382.  
  383.       else
  384.  
  385.         call co(c);
  386.  
  387.       msg = msg + 1;
  388.  
  389.         end;
  390.  
  391. end print;
  392.  
  393.  
  394.  
  395.  
  396.  
  397. /* IOINIT:  this routine takes a port number, 0,1 or 2, and a speed in the   */
  398.  
  399. /* range 1-4 and initializes the require port to work at the required speed. */
  400.  
  401. /* The routine returns no parameters.                         */
  402.  
  403.  
  404.  
  405. ioinit:    procedure;
  406.  
  407.     declare ispeed byte;
  408.  
  409.     declare baud structure (code(5) byte,
  410.  
  411.                 mult(5) byte)
  412.  
  413.         data (40H, 10H, 20H, 10H, 08H, 0CFH, 0CFH, 0CEH, 0CEH, 0CEH);
  414.  
  415.  
  416.  
  417.     ispeed = speed - 1;
  418.  
  419.     if debug then
  420.  
  421.       do;
  422.  
  423.          call newline;
  424.  
  425.          call print(.('initializing serial port',crlf));
  426.  
  427.       end;
  428.  
  429.     do case port;
  430.  
  431.       do;
  432.  
  433.         if debug then call print(.('port 0 initialized',crlf));
  434.  
  435.       end;
  436.  
  437.       do;
  438.  
  439.         if debug then call print(.('port 1 initialized',crlf));
  440.  
  441.         output(port1cmd) = reset;
  442.  
  443.         output(modesel) = timing1;
  444.  
  445.         output(port1clk) = baud.code(ispeed);
  446.  
  447.         output(port1clk) = 0H;
  448.  
  449.         output(port1cmd) = baud.mult(ispeed);
  450.  
  451.         output(port1cmd) = EnaTxRx;
  452.  
  453.       end;
  454.  
  455.       do;
  456.  
  457.         if debug then call print(.('port 2 initialized',crlf));
  458.  
  459.         output(port2cmd) = reset;
  460.  
  461.         output(modesel) = timing2;
  462.  
  463.         output(port2clk) = baud.code(ispeed);
  464.  
  465.         output(port2clk) = 0H;
  466.  
  467.         output(port2cmd) = baud.mult(ispeed);
  468.  
  469.         output(port2cmd) = EnaTxRx;
  470.  
  471.       end;
  472.  
  473.     end;
  474.  
  475. end ioinit;
  476.  
  477.  
  478.  
  479.  
  480.  
  481. usage:    procedure;
  482.  
  483.     call print(.('usage: kermit (300|1200|2400|4800|9600) (1|2)',crlf));
  484.  
  485.     call exit;
  486.  
  487. end usage;
  488.  
  489.  
  490.  
  491.  
  492.  
  493. readln:    procedure;
  494.  
  495.     declare (count, status) address;
  496.  
  497.  
  498.  
  499.     call read(1, .buffer, buflen, .count, .status);
  500.  
  501.     if status > 0 then
  502.  
  503.           do;
  504.  
  505.         call print(.('READLN FAILED',crlf));
  506.  
  507.         call error(status);
  508.  
  509.         call exit;
  510.  
  511.       end;
  512.  
  513.     buffer(count-2) = 0;
  514.  
  515.     cmdptr = .buffer;
  516.  
  517. end readln;
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525. /* *** main program *** */
  526.  
  527.  
  528.  
  529. debug = false;
  530.  
  531. call readln;
  532.  
  533.  
  534.  
  535. realspeed = 2400;
  536.  
  537. port = 1;
  538.  
  539.  
  540.  
  541. /* read desired baud rate, if supplied */
  542.  
  543.  
  544.  
  545. temp = token;
  546.  
  547. if temp > 0 then realspeed = nin(temp);
  548.  
  549.  
  550.  
  551. /* get desired port, if supplied */
  552.  
  553.  
  554.  
  555. temp = token;
  556.  
  557. if temp > 0 then port = nin(temp);
  558.  
  559.  
  560.  
  561. /* make sure there's garbage on the end of the line */
  562.  
  563.  
  564.  
  565. if token > 0 then call usage;
  566.  
  567.  
  568.  
  569.   if (port < 1) or (port > 2) then call usage;
  570.  
  571.  
  572.  
  573. if realspeed = 9600 then speed = 5;
  574.  
  575.   else
  576.  
  577.     if realspeed = 4800 then speed = 4;
  578.  
  579.       else
  580.  
  581.         if realspeed = 2400 then speed = 3;
  582.  
  583.           else
  584.  
  585.             if realspeed = 1200 then speed = 2;
  586.  
  587.               else
  588.  
  589.                 if realspeed = 300 then speed = 1;
  590.  
  591.                   else
  592.  
  593.                     call usage;
  594.  
  595.  
  596.  
  597. call print(.('Serial port ',null));
  598.  
  599. call nout(port);
  600.  
  601. call print(.(', Baud rate ',null));
  602.  
  603. call nout(realspeed);
  604.  
  605. call newline;
  606.  
  607.  
  608.  
  609. call ioinit;
  610.  
  611.  
  612.  
  613. do while (true);
  614.  
  615.     cmdstr = 0;
  616.  
  617.     do while (cmdstr = 0);
  618.  
  619.       call print(.('ISIS-Kermit>',null));
  620.  
  621.       call readln;
  622.  
  623.       cmdstr = token;
  624.  
  625.     end;
  626.  
  627.  
  628.  
  629.     if (strcmp(cmdstr,.('connect',null)) = 0) then cmd = 1;
  630.  
  631.       else
  632.  
  633.         if (strcmp(cmdstr,.('send',null)) = 0) then cmd = 2;
  634.  
  635.           else
  636.  
  637.             if (strcmp(cmdstr,.('receive',null)) = 0) then cmd = 3;
  638.  
  639.               else
  640.  
  641.             if (strcmp(cmdstr,.('exit',null)) = 0) then cmd = 4;
  642.  
  643.               else
  644.  
  645.             if (strcmp(cmdstr,.('debug',null)) = 0) then cmd = 5;
  646.  
  647.               else cmd = 0;
  648.  
  649.  
  650.  
  651.     if (cmd <> 2) then
  652.  
  653.       if token > 0 then
  654.  
  655.         cmd = 0;
  656.  
  657.  
  658.  
  659.     do case cmd;
  660.  
  661.       call print(.('Syntax error',crlf));
  662.  
  663.       call connect;
  664.  
  665.       do;
  666.  
  667.         filename = token;
  668.  
  669.         if (filename = 0) then call print(.('No files specified',crlf));
  670.  
  671.           else if send then call print(.(cr,lf,'OK',crlf));
  672.  
  673.             else call print(.('Send failed',crlf));
  674.  
  675.       end;
  676.  
  677.       do;
  678.  
  679.         call recv;
  680.  
  681.         call print(.(cr,lf,'OK',crlf));
  682.  
  683.       end;
  684.  
  685.       call exit;
  686.  
  687.       debug = not debug;
  688.  
  689.     end;
  690.  
  691. end;
  692.  
  693.  
  694.  
  695. end kermit;
  696.  
  697.