home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / PCL4C30.ZIP / MODEM.C < prev    next >
Text File  |  1992-01-20  |  4KB  |  168 lines

  1. /*
  2. **           --- modem.c ---
  3. **
  4. **   EXAMPLE CODE: Sets/clears DTR and RTS, and
  5. **                 displays DSR,CTS,DCD, and RI
  6. **
  7. **   This example program (not the PCL4C library) is donated to
  8. **   the Public Domain by MarshallSoft Computing, Inc. It is
  9. **   provided as an example of the use of the PCL4C.
  10. **
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <dos.h>
  15. #include "pcl4c.h"
  16.  
  17. char Buffer[8];
  18.  
  19. main(argc,argv)
  20. int argc;
  21. char *argv[];
  22. {
  23.  int Port;
  24.  int BaudCode = 0;
  25.  int row;
  26.  int col;
  27.  int xrow;
  28.  char *p;
  29.  int rc, i;
  30.  char c;
  31.  if(argc!=2)
  32.        {puts("Usage: 'MODEM x' where x=1,2,3, or 4\n");
  33.         exit(1);
  34.        }
  35.  p = argv[1];
  36.  if((strlen(p)!=1)||(*p<'1')||(*p>'4'))
  37.        {printf("Port selected was %s; expected 1,2,3, or 4\n",argv[1]);
  38.         exit(2);
  39.        }
  40.  Port = *p - '1';
  41.  /* must call SioRxBuf before SioReset */
  42.  SioRxBuf(Port,Buffer,Size8);
  43.  /* reset port */
  44.  rc = SioReset(Port,NORESET);
  45.  if(rc<0)
  46.     {printf("Cannot reset port COM%d\n",1+Port);
  47.      SioError(rc);
  48.      exit(1);
  49.     }
  50.  s_clear();
  51.  xrow = s_getrow();
  52.  display(Port);
  53.  putchar('\n');
  54.  printf("1) Set DTR    3) Clear DTR    5) Redisplay\n");
  55.  printf("2) Set RTS    4) Clear RTS    0) QUIT\n");
  56.  putchar('\n');
  57.  row = s_getrow();
  58.  while(1)
  59.        {/* clear keyboard */
  60.         while(kbhit()) s_getc();
  61.         /* get users' response */
  62.         s_pos(row,0);
  63.         printf("Select 0 to 4:   ");
  64.         s_pos(row,14);
  65.         c = (char) s_getc();
  66.         if((c<'0')||(c>'5'))
  67.               {s_pos(row+1,0);
  68.                printf("Must select 0 to 5. Type ENTER to continue");
  69.                getchar();
  70.                s_pos(row+1,0);
  71.                for(i=0;i<40;i++) putchar(' ');
  72.                continue;
  73.               }
  74.         switch(c)
  75.               {
  76.                case '0':  /* QUIT */
  77.                      SioDone(Port);
  78.                      exit(0);
  79.                case '1':  /* Set DTR */
  80.                      SioDTR(Port,'S');
  81.                      break;
  82.                case '2':  /* Set RTS */
  83.                      SioRTS(Port,'S');
  84.                      break;
  85.                case '3':  /* Clear DTR */
  86.                      SioDTR(Port,'C');
  87.                      break;
  88.                case '4':  /* Clear RTS */
  89.                      SioRTS(Port,'C');
  90.                      break;
  91.                case '5':  /* redisplay */
  92.                      break;
  93.               }
  94.         s_pos(xrow,0);
  95.         display(Port);
  96.        }
  97. }
  98.  
  99. int display(Port)
  100. int Port;
  101. {int i;
  102.  s_pos(0,0);
  103.  printf("     MODEM CONTROL\n\n");
  104.  printf("Data Terminal Ready (DTR): ");
  105.  if(SioDTR(Port,'R')) puts("ON "); else puts("OFF");
  106.  printf("Request to Send     (RTS): ");
  107.  if(SioRTS(Port,'R')) puts("ON "); else puts("OFF");
  108.  printf("\n     MODEM STATUS\n\n");
  109.  printf("Data Set Ready      (DSR): ");
  110.  if(SioDSR(Port)) puts("ON "); else puts("OFF");
  111.  printf("Clear To Send       (CTS): ");
  112.  if(SioCTS(Port)) puts("ON "); else puts("OFF");
  113.  printf("Data Carrier Detect (DCD): ");
  114.  if(SioDCD(Port)) puts("ON "); else puts("OFF");
  115.  printf("Ring Indicator      (RI):  ");
  116.  if(SioRI(Port)) puts("ON "); else puts("OFF");
  117. }
  118.  
  119. int s_pos(row, col)       /* sets current screen position */
  120. unsigned row, col;
  121. {union REGS reg;
  122.  reg.h.ah = 2;
  123.  reg.h.bh = 0;
  124.  reg.h.dh = row;
  125.  reg.h.dl = col;
  126.  int86(0x10, ®, ®);
  127. }
  128.  
  129. int s_getrow()       /* gets current screen cursor row position */
  130. {union  REGS  reg;
  131.  reg.h.ah = 3;
  132.  reg.h.bh = 0;
  133.  int86(0x10, ®, ®);
  134.  return(reg.h.dh);
  135. }
  136.  
  137. int s_getcol()       /* gets current screen cursor col position */
  138. {union  REGS  reg;
  139.  reg.h.ah = 3;
  140.  reg.h.bh = 0;
  141.  int86(0x10, ®, ®);
  142.  return(reg.h.dl);
  143. }
  144.  
  145. int s_clear()
  146. {s_scroll(0,0,24,79,0,7);
  147. }
  148.  
  149. int s_scroll(urow, lcol, lrow, rcol, nrows, attrib)
  150. unsigned  urow, lcol, lrow, rcol;
  151. int nrows, attrib;
  152. {union REGS reg;
  153.  reg.h.ah = 6;
  154.  reg.h.ch = urow;
  155.  reg.h.cl = lcol;
  156.  reg.h.al = nrows;
  157.  reg.h.bh = attrib;
  158.  reg.h.dh = lrow;
  159.  reg.h.dl = rcol;
  160.  int86(0x10, ®, ®);
  161. }
  162.  
  163. int s_getc()       /* read next character from keyboard */
  164. {union REGS reg;
  165.  reg.h.ah = 0;
  166.  int86(0x16, ®, ®);
  167.  return(reg.h.al);
  168. }