home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / researchmachines.zip / rmlspi.c < prev    next >
Text File  |  1985-07-11  |  6KB  |  254 lines

  1.  
  2. /***********************************************************************/
  3.  
  4. /* File KSPIC.C - S4 Drivers for Nimbus Piconet; interface from
  5.     Kermit calls to Mike Maloney standard interface for SIM.
  6.             Chris Kennington    9th July 1985    */
  7.  
  8. /* All procedures in this file map down into calls to the functions
  9.     described In Mike Maloney's "Nimbus Piconet interface
  10.     specification" of 1st July 1985.
  11.    Preferred Piconet addresses for SIMs are 1-8; user is asked to
  12.     select between these before program starts.        */
  13.  
  14. #include  "a:ctype.h"
  15.  
  16. #define   CR    0x0d
  17.  
  18. extern    int    p_break(), p_close(), p_flush(),  p_getc(),  p_open(), p_init(),
  19.         p_putc(),  p_speed(), p_status(), p_xonxoff();    /* MikeM procs    */
  20.  
  21. static  int    picsim = 0, status;
  22. static  char    alive = 0;        /* initialized flag        */
  23. static  char    awake = 0;        /* awake flag            */
  24. static    char    parity = 0;
  25. static    char    speed = 1;
  26. static    int    picspeed[] = {110,300,600,1200,2400,4800,9600,19200,0};
  27.     /* all valid speeds:    0   1    2    3      4    5    6      7   */
  28. static  char  partab[] = {
  29. /* character-parity table, 7-bit chars;    0 if even, 1 if odd.    */
  30.     0,1,1,0, 1,0,0,1,  1,0,0,1, 0,1,1,0,    /*  0-15, 00-0f    */
  31.     1,0,0,1, 0,1,1,0,  0,1,1,0, 1,0,0,1,    /* 16-31, 10-1f    */
  32.     1,0,0,1, 0,1,1,0,  0,1,1,0, 1,0,0,1,    /* 32-47, 20-2f    */
  33.     0,1,1,0, 1,0,0,1,  1,0,0,1, 0,1,1,0,    /* 48-63, 30-3f    */
  34.     1,0,0,1, 0,1,1,0,  0,1,1,0, 1,0,0,1,    /* 64-79, 40-4f    */
  35.     0,1,1,0, 1,0,0,1,  1,0,0,1, 0,1,1,0,    /* 80-95, 50-5f    */
  36.     0,1,1,0, 1,0,0,1,  1,0,0,1, 0,1,1,0,    /* 96-111, 60-6f */
  37.     1,0,0,1, 0,1,1,0,  0,1,1,0, 1,0,0,1    /* 112-127, 70-7f */
  38.     };                /* end of parity table    */
  39.     
  40.  
  41. static kill()            /* tidy return to MSDOS            */
  42. {
  43.     printf(" Hit any char to return to MSDOS");
  44.     while (kbdin() == 0)
  45.     ;
  46.     kermkill(1);
  47. }                /* end of kill()            */
  48.  
  49.  
  50.  
  51. static char par(c,p)        /* return with parity            */
  52. /* strips to 7 bits, then adds correct parity; even if p=0, else odd    */
  53. char    c, p;
  54. {
  55.     char  b, d;
  56.  
  57.     c &= 0x7f;
  58.     b = (partab[c] == 0) ? 0 : 0x80;
  59.     if (p != 0)
  60.     b ^= 0x80;
  61.     d = b | c;
  62.     return(d);
  63. }            /* end of par()                    */
  64.  
  65.  
  66.  
  67. s4break(len)        /* send break - official        */
  68. char    len;
  69. {
  70.     int      time;
  71.  
  72.     if ( (alive == 0) || (awake == 0) ) {
  73.     printf(" not in contact ");
  74.     return(-1);
  75.     }
  76.     time = len << 7;            /* sec/8 => msec    */
  77.     p_break(picsim,time);
  78.     outc(' ');
  79.     return(0);
  80. }            /* end of s4break()            */
  81.  
  82.  
  83. s4env()            /* return environment value        */
  84. /* Environment codes are:-
  85.     0  -  480Z, via SIO4;        1  -  480Z, via IDC;
  86.     2  -  Nimbus, via DCC;        3  -  Nimbus, via RS422 Aux;
  87.     4  -  Nimbus, via Piconet SIM;
  88.     5  -  either, via Network Comms Server (n.y.i.).
  89. (see KDATA.C for texts used on bottom header)            */
  90. {
  91.     return(4);
  92. }            /* end of s4env()            */
  93.  
  94.  
  95. s4get(n,buff)        /* read some character, maybe        */
  96. char    n, *buff;
  97. {
  98.     awake = 1;
  99.     if ( (p_getc(picsim,buff)) != 0 )
  100.     return(0);
  101.     else
  102.     return(1);
  103. }            /* end of s4get()            */
  104.  
  105.  
  106. s4get7(n,buff)        /* read some 7-character, maybe        */
  107. char    n, *buff;
  108. {
  109.     awake = 1;
  110.     if ( (p_getc(picsim,buff)) != 0 )
  111.     return(0);
  112.     else {
  113.     *buff &= 0x7f;
  114.     return(1);
  115.     }
  116. }            /* end of s4get7()            */
  117.  
  118.  
  119. s4go()            /* fire up piconet comms        */
  120. {
  121.     int       i;
  122.     char   c, *addr;
  123.  
  124.     awake = 1;
  125.     if (alive != 0)
  126.     return(0);
  127.     while (picsim == 0) {
  128.     printf("\nRMKermit: Enter Piconet SIM address (1-8): ");
  129.     while ( (c = kbdin()) == 0 )
  130.         ;
  131.     if (c == CR)
  132.         picsim = 1;
  133.     else if (isdigit(c) == 0)
  134.         continue;            /* invalid entry    */
  135.     else {
  136.         c &= 0x0007;        /* range 0 - 7        */
  137.         picsim = (c == 0) ? 8 : c;    /* address in binary    */
  138.         printf("Address is %d",picsim);
  139.     }    }
  140.     if ( (addr = malloc (1610)) == 0 ) {
  141.     printf("\nNo store for comms.\n");
  142.     goto Kill;
  143.     }
  144.     else {
  145.     if ( (i = p_open(picsim,'I',1600,addr)) != 0 ) {
  146.         printf("\nCannot open comms, error-code %xx.\n",i);
  147.         goto Kill;
  148.     }
  149.     if ( (i = p_init(picsim,0x0066,0x0010,0x004c,0x0000,0,0)) != 0 ) {
  150.   /* these parameters are cookbook from Mike M.; control-line handling
  151.     is not guaranteed.                    */
  152.         printf("\nCannot initialize Piconet, error-code %xx.\n",i);
  153.         goto Kill;
  154.     }
  155.     alive = 1;
  156.     }
  157.     return(0);
  158.  
  159. Kill:                /* error so terminate        */
  160.     txtout(" Hit any char to return to MSDOS ");
  161.     while (kbdin() == 0)
  162.     ;
  163.     kermkill(1);
  164. }            /* end of s4go()            */
  165.  
  166.  
  167. s4put(n,buff)        /* send some chars            */
  168. char    n, *buff;
  169. {
  170.     char    c;
  171.  
  172.     awake = 1;
  173.     c = *buff;
  174.     switch(parity) {
  175.       default:            /* 0 or > 3 (impossible)    */
  176.     break;
  177.       case 1:            /* 1 = odd            */
  178.     c = par(c,1);
  179.     break;
  180.       case 2:            /* 2 = even            */
  181.     c = par(c,0);
  182.     break;
  183.       case 3:            /* 3 = mark            */
  184.     c |= 0x80;
  185.     break;
  186.     }            /* end switch                */
  187.     if (p_putc(picsim,c) == 0)
  188.     return(1);
  189.     else
  190.      return(0);
  191. }            /* end of s4put                */
  192.  
  193.  
  194. s4set(facil,wr5)    /* set facilities - dummy        */
  195. int    facil;
  196. char    wr5;
  197. {
  198.     char    x;
  199.  
  200.     parity = (facil & 0x0300) >> 8;
  201.     x = ( (facil & 0x0002) == 0 ) ? 0 : 0xff;
  202.     p_xonxoff(picsim,x);
  203.     return(0);
  204. }            /* end of s4set()            */
  205.  
  206.  
  207. s4sleep()        /* dummy deactivate            */
  208. {
  209.     awake = 0;
  210.     return(0);
  211. }
  212.  
  213.  
  214. s4speed(kspeed)        /* set line-speed            */
  215. char    kspeed;            /* 480Z speed-code        */
  216. {
  217.     int     i, spd;
  218.  
  219.     speed = kspeed;
  220.     if (alive != 0) {
  221.     spd = picspeed[kspeed];
  222.     if ( (i = p_speed(picsim,spd,spd)) != 0 ) {
  223.         printf("\nCannot set speed, error-code %xx.\n",i);
  224.         kermkill(1);
  225.     }    }
  226.     return(0);
  227. }            /* end of s4speed()            */
  228.  
  229.  
  230. s4status()        /* return status-byte (in int)        */
  231. {
  232.     return(p_status(picsim));
  233. }            /* end of s4status()            */
  234.  
  235.  
  236. s4stop()        /* close down communications        */
  237. {
  238.     if (alive = 0)
  239.     return(0);
  240.     alive = awake = 0;
  241.     p_close(picsim);
  242.     return(0);
  243. }            /* end of s4stop()            */
  244.  
  245.  
  246.  
  247. s4test()        /* return status - dummy        */
  248. {
  249.     return(0);
  250. }            /* end of s4test()            */
  251.  
  252.  
  253. /******************  END of file KSMIKE.C  *******************************/
  254.