home *** CD-ROM | disk | FTP | other *** search
/ nisttime.carsoncity.k12.mi.us / nisttime.carsoncity.k12.mi.us.tar / nisttime.carsoncity.k12.mi.us / pub / acts / inilin.c < prev    next >
C/C++ Source or Header  |  1996-11-07  |  6KB  |  206 lines

  1. void inilin()
  2. {
  3. /*
  4.         this subroutine initializes the com port defined by
  5.         global cmport (0=com1, 1=com2, ... etc).
  6.         the initialization parameters are set using param
  7.  
  8.         if BIOS is not defined, do not use bios calls but access the
  9.         hardware directly.  this is done by determining the hardware
  10.         address of the comport by looking in low core locations.
  11. */
  12. #include <stdio.h>
  13. #include "nistime.h"
  14. #ifdef IBMPC
  15. #include <dos.h>
  16. char param;
  17. #endif
  18. extern int cmport; /* which comport to use ? */
  19. extern int hs;     /* which speed to use ?   */
  20. extern int debug;  /* debug is on if = 1 */
  21. #ifdef IBMPC
  22. void wait();        /*wait for DSR to come true */
  23. extern int lpadr;   /* address of line printer -- determined here */
  24. #ifndef BIOS
  25. extern int cmadr;   /* hardware address of comport -- determined here*/
  26. #endif
  27. extern int lpt;     /* pulse line printer? 1=yes, 0= no */
  28. #endif
  29. extern char number[];   /* which number to dial, first char = mode*/
  30. int j;
  31. #ifdef SUN
  32. #include <sgtty.h>
  33. struct sgttyb blah,*arg;     /* parameters used for ioctl calls */
  34.     arg= &blah;           /* blah is structure */
  35.     if(hs == 1)
  36.        {
  37.         arg->sg_ispeed=B1200;
  38.         arg->sg_ospeed=B1200;
  39.        }
  40.     else
  41.        {
  42.        arg->sg_ispeed=B300;
  43.        arg->sg_ospeed=B300;
  44.        }
  45.     arg->sg_erase='\177';
  46.     arg->sg_kill='\025';
  47.     arg->sg_flags=RAW;
  48.     j=ioctl(cmport,TIOCSETP,arg);
  49.     if(j != 0) printf("\n Watch out! ioctl status=%d",j);
  50. #endif
  51. #ifdef IBMPC
  52. unsigned char stat;
  53. #endif
  54. /*
  55.     operation of the IBMPC version:
  56.  
  57.         if this is the direct access version of the program, then the
  58.         hardware address of the comport must be either specified in the
  59.         configuration file or determined by looking in low memory.  if
  60.         it was specified in the configuration file, then cmport was set
  61.         to -1 there and cmadr was read from line 6.  in that case we
  62.         don't have to do anything here.  if cmadr is positive, then
  63.         the value must be determined here by looking at the table starting
  64.         at address 400 (hex).
  65.         following variables and code are used to look in low memory
  66.         to get the address of the comport requested in the config. file
  67.         if the address in low memory is zero, then exit with an error.
  68.         since the line printer addresses are stored just after the tty
  69.         port addresses, these variables are also used for getting the
  70.         hardware address of lpt1 (see below)
  71.  
  72.     operation of the SUN version:
  73.  
  74.     the port was opened in setcfg and this subroutine sets the
  75.     speed and other parameters based on values in the config.
  76.     file.
  77. */
  78. #ifdef IBMPC
  79. unsigned int ttyseg = 0x40;
  80. unsigned int ttyoff =    0;
  81. int far *cmptr;
  82. #ifndef BIOS
  83. /*
  84.         first get hardware address of requested comport if necessary
  85.         these address are stored starting at 400.  if cmport is -1,
  86.         then the address was already gotten by setcfg from the configuration
  87.         file and we don't have to do that here.
  88. */
  89.         if(cmport >= 0)
  90.         {
  91.         ttyoff=2*cmport;
  92.         cmptr=MK_FP(ttyseg,ttyoff);
  93.         cmadr=*cmptr;
  94.         if(cmadr == 0)
  95.            {
  96.            printf("\n Port COM%d not present in configuration.",cmport+1
  97. );
  98.            exit();
  99.            }
  100.         }
  101. /*
  102.         disable interrupts, turn on DTR and RTS, then
  103.         set 8 bits, no parity, 1 stop bit, Div. Latch Acc Bits on
  104. */
  105.         param=0;
  106.         outportb(cmadr+intena,param);
  107.         param=3;
  108.         outportb(cmadr+modreg,param);
  109.         param='\x83';
  110.         outportb(cmadr+lcreg,param);
  111. /*
  112.         now set requested speed using two halves of divisor
  113.         from tables in interface manual
  114. */
  115.         if(hs == 1)
  116.            {
  117.            param=96;
  118.            outportb(cmadr+divlsb,param);
  119.            param=0;
  120.            outportb(cmadr+divmsb,param);
  121.            }
  122.         else
  123.            {
  124.            param='\x80';
  125.            outportb(cmadr+divlsb,param);
  126.            param=1;
  127.            outportb(cmadr+divmsb,param);
  128.            }
  129. /*
  130.         now turn off divisor latch access bits
  131. */
  132.         param=3;
  133.         outportb(cmadr+lcreg,param);
  134.         wait();
  135.         wait();
  136.         wait();        /*wait for ROLM system to wake up*/
  137. /*
  138.         get modem status
  139. */
  140.         stat=inportb(cmadr+msreg);
  141. #endif
  142. #ifdef BIOS
  143. /*
  144.         if we get here then we are going to do the same stuff using
  145.         BIOS calls. the parameters are:
  146.  
  147.         300 baud        no parity       1 stop bit      8 bits
  148.         0 1 0           0 0             0               1 1
  149.  
  150.         1200 baud       no parity       1 stop bit      8 bits
  151.         1 0 0           0 0             0               1 1
  152.  
  153.         9600 baud       no parity       1 stop bit      8 bits
  154.         1 1 1           0 0             0               1 1
  155. */
  156.         if(hs == 1)param='\x83';
  157.         else       param='\x43';
  158.         _AL=param;
  159.         _AH=0;
  160.         _DX=cmport;
  161.         geninterrupt(0x14);
  162.         stat=_AL;           /* return with modem status  */
  163. #endif
  164. /*
  165.         if this is automatic dialing using either manual or pulse mode
  166.         then be sure that the modem is ready to go.  check DSR
  167. */
  168.         if( (number[3] == 't') || (number[3] == 'T') ||
  169.             (number[3] == 'p') || (number[3] == 'P') )
  170.         {
  171.         if( (stat & 0x20) == 0)
  172.            {
  173.            printf("\nWarning!  modem does not ");
  174.            printf("show data set ready (DSR).");
  175.            }
  176.         }
  177. /*
  178.         now set line printer address if lpt is set to pulse it. if
  179.         lpt is zero so that pulsing is disabled, then return now.
  180.  
  181.         get lpt1 address by looking in low core at address 408
  182. */
  183.         if(lpt == 0) return;
  184.         ttyoff=8;
  185.         cmptr=MK_FP(ttyseg,ttyoff);
  186.         lpadr=*cmptr;
  187.         if(lpadr == 0)
  188.         {
  189.         printf("\n printer-port not installed in system.");
  190.         printf("\n pulsing selection disabled.");
  191.         lpt=0;
  192.         return;
  193.         }
  194.         outportb(lpadr,1);
  195.         for(j=0; j<200; j++);   /*wait a bit*/
  196.         if( (inportb(lpadr) & 0x1f) == 1)
  197.         {
  198.         outportb(lpadr,0);
  199.         return;
  200.         }
  201.         printf("\n printer-port does not respond to pulse.");
  202.         printf("\n pulsing selection will be disabled.");
  203.         lpt=0;
  204. #endif
  205. }
  206.