home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / bbs / fil_lis / tin_door.c < prev    next >
C/C++ Source or Header  |  1993-01-09  |  17KB  |  410 lines

  1. /**********************************************************************/
  2. /*            Low-Level I/O Routines with Carrier Detect              */
  3. /*                                                                    */
  4. /* By: Bryan D. Hall                                   Date: 03/15/89 */
  5. /* GEnie Address: BDHALL                                              */
  6. /* Fnet  Address: Bryan Hall, Node 227 CO (719)543-1869 12/24/96 HST  */
  7. /*                                        M-F 4PM-10AM, 24Hrs Weekends*/
  8. /*                                                                    */
  9. /* Modified for Turbo C by Wolfgang Zweygart           Date: 01/09/89 */
  10. /**********************************************************************/
  11.  
  12. /** cd_check() ********************************************************/
  13. /*   INPUT: None (hardware) CD Line                                   */
  14. /* PROCESS: This is a routine to check for carrier. Exits program if  */
  15. /*          no carrier                                                */
  16. /*  OUTPUT: None.  Exits with status 1                                */
  17. /**********************************************************************/
  18.  
  19. void cd_check(void)
  20. {
  21. long old_stack;
  22. char *gpip;
  23. char test;
  24.  
  25.     gpip=(char *)0xFFFFFA01L;
  26.     old_stack = Super(0L);
  27.     test= *gpip;    
  28.     Super((void *) old_stack);
  29.     if (test & 2) exit(1); /* no carrier.. get out of this! */
  30. }
  31.  
  32.  
  33. /** cd_bconin(int) ****************************************************/
  34. /*   INPUT: Device number. 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See    */
  35. /*          Bconin for more info.                                     */
  36. /* PROCESS: Same as for Bconin, but also checks for a carrier.        */
  37. /*  OUTPUT: See Bconin                                                */
  38. /**********************************************************************/
  39.  
  40. int cd_bconin(int device)
  41. {
  42. switch(device) {
  43.   case 1: while(1){     /* AUX: set as primary device */
  44.             cd_check();    /* first make sure there is a carrier */
  45.             if (Bconstat(2) != 0) 
  46.                return((int)Bconin(2));  /* then get char from console */
  47.             if (Bconstat(device) != 0) 
  48.                return((int)Bconin(device));  /* then get char from device */
  49.           }
  50.   case 2: /* CON: set as primary device */
  51.           return((int)Bconin(device));  /* then get char from console */
  52.   case 3: /* MIDI: set as primary device */
  53.           if (Bconstat(2) != 0) return((int)Bconin(2));  /* then get char from console */
  54.           else return((int)Bconin(device));  /* then get char from device */
  55.   default: return(0);
  56.   }
  57. }
  58.  
  59.  
  60. /** cd_bconout(int,int) ***********************************************/
  61. /*   INPUT: (1) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. see*/
  62. /*          Bconout for more info.                                    */
  63. /*          (2) Character to output, in low byte.                     */
  64. /* PROCESS: Same as for Bconout, except checks for a carrier, and also*/
  65. /*          sends the character to the keyboard if aux: is selected.  */
  66. /*  OUTPUT: None                                                      */
  67. /**********************************************************************/
  68.  
  69. void cd_bconout(int device, char character)
  70. {
  71. switch(device) {
  72.   case 1:   /* aux: set as the primary device */
  73.             cd_check();    /* first make sure there is a carrier */
  74.             Bconout(device,(int)character); /* sent to device and console */
  75.             Bconout(2,(int)character);
  76.             break;
  77.   case 0:   /* Any other legal device */
  78.   case 2:
  79.   case 3:
  80.   case 4:
  81.   case 5:   Bconout(device,(int)character); /* send to device only */
  82.             break;
  83.   }
  84. }
  85.      
  86.  
  87. /** cd_bconstat(int) **************************************************/
  88. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See     */
  89. /*          Bconstat for more info.                                   */
  90. /* PROCESS: Same as for Bconstat, except checks for a carrier, and    */
  91. /*          also checks the keyboard if aux: is selected.             */
  92. /*  OUTPUT: Returns -1 if at least one character is ready, else 0     */
  93. /**********************************************************************/
  94.  
  95. int cd_bconstat(int device)
  96. {
  97. switch(device) {
  98.   case 1:   /* AUX: set as primary device */
  99.             cd_check();    /* first make sure there is a carrier */
  100.             if (Bconstat(2) != 0)
  101.                  return((int)Bconstat(2));  /* then send "console is ready" */
  102.             else return((int)Bconstat(device)); /* otherwise check AUX: */
  103.   case 0:   /* PRN:, CON:, or MIDI: */
  104.   case 2:
  105.   case 3:   return(Bconstat(device));
  106.   default:  return(0);
  107.   }
  108. }
  109.  
  110.  
  111. /** cd_bcostat(int) ***************************************************/
  112. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc.  See   */
  113. /*          Bcostat for more info.                                    */
  114. /* PROCESS: Same as for Bcostat, except it also checks for a carrier. */
  115. /*  OUTPUT: Returns -1 if device is ready, else 0.                    */
  116. /**********************************************************************/
  117.  
  118. int cd_bcostat(int device)
  119. {
  120. switch(device) {
  121.   case 1:   /* AUX: set as primary device */
  122.             cd_check();    /* first make sure there is a carrier */
  123.             return((int)Bcostat(device));
  124.   case 0:   /* Any other legal device */
  125.   case 2:
  126.   case 3:
  127.   case 4:
  128.   case 5:   return((int)Bcostat(device));
  129.   default:  return(0);
  130.   }
  131. }
  132.  
  133.  
  134. /** cd_getchar(int) ***************************************************/
  135. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See     */
  136. /*          Bcostat for more info                                     */
  137. /* PROCESS: Waits for a character from the specified device.  Then it */
  138. /*          checks to see if the chatacter is printable.  If so, it   */
  139. /*          is displayed and returned.  However, if the character is  */
  140. /*          a <CTRL-S>, the routine remembers this, and the next time */
  141. /*          called, will not echo the character, but will return it   */
  142. /*          and cancel the pause.                                     */
  143. /*          NOTE: If the device is not con:, it will also get the     */
  144. /*                from the keyboard.                                  */
  145. /*  OUTPUT: Returns the character, as an int.                         */
  146. /**********************************************************************/
  147.  
  148. int cd_getchar(int device)
  149. {
  150. int temp;
  151. static int paused;
  152.  
  153.  while (cd_bconstat(device) == 0);   /* wait for a character */
  154.  temp = cd_bconin(device);     /* get character */
  155.  if ((isprint(temp) || (temp==10) || (temp==13) || (temp==8)) && !paused )
  156.       {
  157.       cd_bconout(device,temp);    /* echo out to device */
  158.       }
  159.  else {
  160.       if (temp == 19)  /* CTRL-S */
  161.            paused = 1;  /* set flag */
  162.       else
  163.            paused = 0; /* not paused */
  164.       }
  165.  return( temp );     /* return ASCII code */
  166. }
  167.  
  168.  
  169. /** cd_hgetchar(int) **************************************************/
  170. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See     */
  171. /*          Bcostat for more info.                                    */
  172. /* PROCESS: Waits for a character from the specified device.  Does NOT*/
  173. /*          echo character to device or screen.                       */
  174. /*  OUTPUT: Returns the character as an int.                          */
  175. /**********************************************************************/
  176.  
  177. int cd_hgetchar(int device) /* hidden get character (no echo) */
  178. {
  179.  while (cd_bconstat(device) == 0) ;  /* wait for a character */
  180.  return( cd_bconin(device) );     /* return ASCII code */
  181. }
  182.  
  183.  
  184. /** cd_putchar(char,int) **********************************************/
  185. /*   INPUT: (1) Character to output.                                  */
  186. /*          (2) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  187. /*          Bcostat for more info.                                    */
  188. /* PROCESS: Sends out a character to the specified device.  If the    */
  189. /*          character is a LineFeed, then it also sends a <CR>.       */
  190. /*          NOTE: If the device is not con:, it will also send the    */
  191. /*                char. to the screen.                                */
  192. /*  OUTPUT: None                                                      */
  193. /**********************************************************************/
  194.  
  195. void cd_putchar(char outchar, int device)
  196. {
  197.  static int pause = 0;
  198.  
  199.  cd_bconout(device, outchar);   /* send out character */
  200.  if (outchar == 10)    /* LF */
  201.       cd_bconout(device, 13);   /* send out CR */
  202.  
  203.  do
  204.   {
  205.      if(cd_bconstat(device)==-1)
  206.       {
  207.        if(cd_bconin(device)==19) pause=-1; else pause=0;
  208.       }
  209.   }
  210.  while(pause==-1);
  211. }
  212.  
  213.  
  214. /** cd_gets(char,int,int) *********************************************/
  215. /*   INPUT: (1) "String" pointer.                                     */
  216. /*          (2) Maximum number of chars to get.                       */
  217. /*          (3) Device number 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See */
  218. /*          Bcostat for more info.                                    */
  219. /* PROCESS: Works somewhat like gets(), except that you can set the   */
  220. /*          maximum number of characters to be typed in, plus allows  */
  221. /*          for non-redirectable input.  It also sends out a <BELL>   */
  222. /*          character when a user tries to backspace past the         */
  223. /*          beginning of the line, and also after the last acceptable */
  224. /*          character space has been filled.  This allows the user to */
  225. /*          then backspace for corrections.                           */
  226. /*          NOTE: If the device is not con:, it will also get the     */
  227. /*                "string" from the keyboard.                         */
  228. /*  OUTPUT: None.                                                     */
  229. /**********************************************************************/
  230.  
  231. void cd_gets(char *s, int n, int device)
  232. {
  233. register int c;
  234. int at_now=0;
  235.  while(1)
  236.   {
  237.   while (cd_bconstat(device) == 0) ;   /* wait for a character */
  238.   c = cd_bconin(device);     /* get character */
  239.   if (c == 8) /* BS */
  240.    {
  241.    if (at_now > 0)
  242.         {
  243.         n+=1;
  244.         at_now-=1;
  245.         cd_bconout(device,c);    /* echo out to device */
  246.         }
  247.    else {
  248.         cd_bconout(device,7); /* echo bell out to device */
  249.         }                    
  250.    }
  251.   else {
  252.        if ((isprint(c) || (c == 10) || (c == 13) || (c == 8)))
  253.         {
  254.         s[at_now++] = c;
  255.         if (!(n-2)) cd_bconout(device,7); /* echo bell out to device */
  256.         if ((--n <= 0) || (c == 13) || (s[at_now-1] == '\n'))
  257.              {
  258.              s[at_now-1] = '\0';
  259.              return;
  260.              }
  261.         cd_bconout(device,c);    /* echo out to device */
  262.         }
  263.        }
  264.   }
  265. }
  266.  
  267.  
  268. /** cd_puts(char,int) *************************************************/
  269. /*   INPUT: (1) Pointer to "string" to output.                        */
  270. /*          (2) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  271. /*          Bcostat for more info.                                    */
  272. /* PROCESS: Works just like puts() (except for re-direction           */
  273. /*          protection), plus adds the pause features found in the    */
  274. /*          cd_putchar routine.                                       */
  275. /*          NOTE: If the device is not con:, it will also send the    */
  276. /*                "string" to the screen.                             */
  277. /*  OUTPUT: None.                                                     */
  278. /**********************************************************************/
  279.  
  280. void cd_puts(char *s, int device)
  281. {
  282.  char c;
  283.  while ((c = *s++) !=0) cd_putchar(c, device);
  284. }
  285.  
  286. /** cd_printf(int device, const char *format, ...) ********************/
  287. /*   INPUT: (1) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  288. /*          Bcostat for more info.                                    */
  289. /*          (2) Format string like printf()                                     */
  290. /*                (.) Parameters like printf()                                         */
  291. /* PROCESS: Works just like printf() (except for re-direction         */
  292. /*          protection), plus adds the pause features found in the    */
  293. /*          cd_putchar routine.                                       */
  294. /*          NOTE: If the device is not con:, it will also send the    */
  295. /*                "string" to the screen.                             */
  296. /*  OUTPUT: None.                                                     */
  297. /**********************************************************************/
  298.  
  299. void cd_printf(int device, const char *format, ...)
  300. {
  301.  va_list arg_point;
  302.  char temp[255];
  303.  
  304.  va_start(arg_point, format);
  305.  vsprintf(temp, format, arg_point);
  306.  cd_puts(temp, device);
  307.  va_end(arg_point);
  308. }
  309.  
  310.  
  311. /** cd_nputs(char,int,int) ********************************************/
  312. /*   INPUT: (1) Pointer to "string" to be output.                     */
  313. /*          (2) Maximum number of chars to output.                    */
  314. /*          (3) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  315. /*          Bcostat for more info                                     */
  316. /* PROCESS: Works just like cd_puts() but allows you to specify the   */
  317. /*          maximum number of characters to be output.                */
  318. /*          NOTE: If the device is not con:, it will also send the    */
  319. /*                "string" to the screen.                             */
  320. /*  OUTPUT: None.                                                     */
  321. /**********************************************************************/
  322.  
  323. void cd_nputs(char *s, int n, int device)
  324. {
  325.  char c;
  326.  while (((c = *s++) !=0) && (--n)) cd_putchar(c, device);
  327. }
  328.  
  329.  
  330. /** clr_scrn(int) *****************************************************/
  331. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. see    */
  332. /*          Bcostat for more info                                     */
  333. /* PROCESS: Sends both a VT-52 clear screen & home cursor, and a <LF> */
  334. /*          to the device, and just the VT-52 code to con:            */
  335. /*  OUTPUT: None.                                                     */
  336. /**********************************************************************/
  337.  
  338. void clr_scrn(int device)
  339. {
  340.  cd_puts("\033E \f",device); /* clear screen */
  341.  cd_puts("\033E",2);
  342. }
  343.  
  344.  
  345. /** read_file(char,int) ***********************************************/
  346. /*   INPUT: (1) Pointer to file path\name. Exp: "c:\txt\read.me"      */ 
  347. /*          (2) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  348. /*          Bcostat for more info                                     */
  349. /* PROCESS: Opens an ASCII (non-binary) file in read-only mode and    */
  350. /*          sends it one character at a time, to the device.  If a    */
  351. /*          <CTRL-S> is recieved (not echoed to device), it will pause*/
  352. /*          until any other character is received.  If <CTRL-C> is    */
  353. /*          recieved when not paused, it will close the file and      */
  354. /*          abort.  If the file cannot be opened, a message will be   */
  355. /*          displayed and the function will abort.                    */
  356. /*          NOTE: If the device is not con:, it will also send the    */
  357. /*                file to the screen.                                 */
  358. /*  OUTPUT: None.                                                     */
  359. /**********************************************************************/
  360.  
  361. void read_file(char filename[], int device)
  362. {
  363. FILE *fp;
  364. int stat =0;
  365. char ch;
  366.  
  367.  if ((fp = fopen(filename,"r")) != NULL)
  368.   {
  369.   while (((ch = fgetc(fp)) != EOF) && (stat != 1))
  370.        {
  371.        cd_putchar(ch,device); /* send out char */
  372.        if (cd_bconstat(device) == -1L) /* If true, char is availible*/
  373.         {
  374.         ch=cd_hgetchar(device);       /* Get input */
  375.         if (ch == 19) /* CTRL - S */
  376.              {
  377.              cd_hgetchar(device); /* wait for key */
  378.              stat = 0;
  379.              }
  380.         else if (ch == 3) /* CTRL - C */
  381.              stat = 1;
  382.         }
  383.        }
  384.   }
  385.  else
  386.   {
  387.    cd_puts("\nCannot open file: ", device);
  388.    cd_puts(filename, device);
  389.    return;
  390.   }
  391. fclose(fp);
  392. }
  393.  
  394.  
  395. /** do_pushany(int) ***************************************************/
  396. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc.  See   */
  397. /*          Bcostat for more info.                                    */
  398. /* PROCESS: Sends out a "Press any key message", then waits for a     */
  399. /*          character.                                                */
  400. /*          NOTE: If the device is not con:, it will also send the    */
  401. /*                message to the screen.                              */
  402. /*  OUTPUT: None.                                                     */
  403. /**********************************************************************/
  404.  
  405. void do_pushany(int device)
  406. {
  407.  cd_puts("\n << Press ANY Key to Continue >>\n",device);
  408.  cd_hgetchar(device);
  409. }
  410.