home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 225_01 / deff4.c < prev    next >
Text File  |  1987-06-10  |  25KB  |  705 lines

  1. /*-----------------------------------------------------------------*/
  2. /*  FILE:          DEFF4.C
  3.     ----
  4.     COMPILER:      BDS C  V 1.50
  5.     --------
  6.     WRITTEN:       22/10/85
  7.     -------
  8.     REVISED:       16/11/86
  9.     -------
  10.     VERSION:       1.4
  11.     -------
  12.     ADDED FCTs:    B_TEST
  13.     ----------                                                     */
  14.  
  15. /*  This file contains the following functions -                   */
  16. /*                                                                 */
  17. /*       SET_BIT        PUT_ERROR           UP_STR                 */
  18. /*       LOWER_STR      ENTAB               PLIST                  */
  19. /*       LIST_STATUS    LISTS               LISTD                  */
  20. /*       MAKE_FCB       PEC_CLEAR           HAZ_CLEAR              */
  21. /*       BRIGHT         NORMAL              LINE(S)                */
  22. /*       PRINT_U        GO_TO               OUT_CHAR               */
  23. /*       ISNUM          INKEY               PRT_HEX                */
  24. /*       VIDEO_CHAR     B_TEST                                     */
  25. /*-----------------------------------------------------------------*/
  26. /*            BIOS Functions
  27.               --------------
  28.  
  29.          W_BOOT         CONST               CONIN
  30.          CONOUT         LIST_C              SELDSK
  31.          SET_TRK        SET_SEC             SET_DMA
  32.          READ_SEC       WRITE_SEC           LISTST                 */
  33. /*-----------------------------------------------------------------*/
  34. /*                                                                 */
  35. /*  all of which are described in the file DEFF4.TXT.              */
  36. /*                                                                 */
  37. /*  WRITTEN:  14th July, 1986                                      */
  38. /*  -------                                                        */
  39. /*  BIOS functions added September 27, 1986                        */
  40. /*  Copyright 1986 by Cogar Computer Services Pty. Ltd.            */
  41. /*  All rights reserved.                                           */
  42. /*-----------------------------------------------------------------*/
  43. #include <pec.h>    /* Required for these functions            */
  44. /*=================================================================*/
  45. /*  LIBRARY FUNCTION:   B_TEST
  46.  
  47.     Will test the nominated bit in a byte and return TRUE if it
  48.     is set ( = 1) or FALSE if it is not set.   Note that "bit"
  49.     must be one of "B_ZERO" to "B_SEVEN" as per pec.h              */
  50. /*-----------------------------------------------------------------*/
  51.  
  52. char b_test(byte, bit)
  53. int bit;
  54. char byte;
  55. {
  56.     int set_bit;
  57.  
  58.     if(bit == 0)
  59.         set_bit = 0x1;
  60.     else if(bit == 1)
  61.         set_bit = 0x2;
  62.     else if(bit == 2)
  63.         set_bit = 0x4;
  64.     else if(bit == 3)
  65.         set_bit = 0x8;
  66.     else if(bit == 4)
  67.         set_bit = 0x10;
  68.     else if(bit == 5)
  69.         set_bit = 0x20;
  70.     else if(bit == 6)
  71.         set_bit = 0x40;
  72.     else if(bit == 7)
  73.         set_bit = 0x80;
  74.  
  75.     if((byte & set_bit) > 0)
  76.         return(1);
  77.     else return(0);
  78. }
  79. /*-----------------------------------------------------------------*/
  80. /*  SUBROUTINE  ==>  set_bit                                       */
  81. /*  Will set the nominated BYTE in the file control block          */
  82. /*  Choices are -                                                  */
  83. /*                 R/O       Read only                             */
  84. /*                 R/W       Read/Write (re-sets the bit)          */
  85. /*                 SYS       System file                           */
  86. /*                 DIR       Directory (re-sets SYS bit)           */
  87. /*                 ARC       Archive bit                           */
  88. /*                 CPY       Copy (re-sets Archive bit)            */
  89. /*-----------------------------------------------------------------*/
  90.  
  91. void set_bit(fcb_buf,str)
  92. char fcb_buf[36], str[3];
  93. {
  94.     up_str(str);    /* convert to upper case */
  95.  
  96.     if(strcmp(str,"R/O") == 0)
  97.         fcb_buf[9] = fcb_buf[9] | 0x80;
  98.     else if(strcmp(str,"R/W") == 0)
  99.         fcb_buf[9] = fcb_buf[9] & 0x7f;
  100.     else if(strcmp(str,"SYS") == 0)
  101.         fcb_buf[10] = fcb_buf[10] | 0x80;
  102.     else if(strcmp(str,"DIR") == 0)
  103.         fcb_buf[10] = fcb_buf[10] & 0x7f;
  104.     else if(strcmp(str,"ARC") == 0)
  105.         fcb_buf[11] = fcb_buf[11] | 0x80;
  106.     else if(strcmp(str,"CPY") == 0)
  107.         fcb_buf[11] = fcb_buf[11] & 0x7f;
  108.     else put_error(str);
  109.  
  110.     if(set_attributes(fcb_buf) == -1)
  111.         printf("\nUnable to find the nominated file.\n");
  112. }
  113. /*-----------------------------------------------------------------*/
  114. /*  SUBROUTINE  ==>  put_error                                     */
  115. /*  Used with set_bit                                              */
  116. /*-----------------------------------------------------------------*/
  117.  
  118. void put_error(string)
  119. char *string;
  120. {
  121. printf("\n\nThe mode  %s is unknown...terminating programme.", string);
  122. exit();
  123. }
  124. /*-----------------------------------------------------------------*/
  125. /*  LIBRARY FILE  ==  up_str                                       */
  126. /*  Will convert a string to UPPER case ASCII                      */
  127. /*-----------------------------------------------------------------*/
  128.  
  129. void up_str(s)
  130. char *s;
  131. {
  132.     short i;
  133.     i = 0;
  134.  
  135.     while(s[i])
  136.     {
  137.         s[i] = toupper(s[i]);
  138.         i++;
  139.     }
  140.     s[i] = '\0';
  141. }
  142. /*-----------------------------------------------------------------*/
  143. /*  LIBRARY FILE  ==  lower_str                                    */
  144. /*  Will convert a NULL-terminated string to ASCII lower case      */
  145. /*-----------------------------------------------------------------*/
  146.  
  147. void lower_str(s)
  148. char *s;
  149. {
  150.     short i;
  151.     i = 0;
  152.  
  153.     while(s[i])
  154.     {
  155.         s[i] = tolower(s[i]);
  156.         i++;
  157.     }
  158.     s[i] = '\0';
  159. }
  160. /*-----------------------------------------------------------------*/
  161. /*  LIBRARY FILE  ==>  ENTAB                                       */
  162. /*  Will compensate for TAB characters on those printers which     */
  163. /*  don't recognise the ASCII tab.   Can be altered for different  */
  164. /*  tab sizes, as needed.                                          */
  165. /*-----------------------------------------------------------------*/
  166.  
  167. char entab(position, size)
  168. short position, size;
  169. {
  170.     short tab_count;
  171.  
  172.     for(tab_count = 0; tab_count <= size - position%size; tab_count++)
  173.         listc(SPACE);
  174.     tab_count--;    /* Must go back one                        */
  175.  
  176.     position = position + tab_count;
  177.     return(position);
  178. }
  179. /*-----------------------------------------------------------------*/
  180. /*  LIBRARY FILE  ==>  plist                                       */
  181. /*  Will list one character to the line printer using the actual   */
  182. /*  I/O port addresses.                                            */
  183. /*  Presently configured for GODBOUT INTERFACER II board but can   */
  184. /*  be modified for any "Centronics" connection provided the       */
  185. /*  ports and the strobe signals are known.                        */
  186. /*  NOTE:  The strobe signals used are those for the Itoh 8510     */
  187. /*  ----   printer.                                                */
  188. /*                                                                 */
  189. /*  Written for BDS C but should be portable to other C's.         */
  190. /*  Copyright 1986 by Cogar Computer Services Pty. Ltd.            */
  191. /*-----------------------------------------------------------------*/
  192. /*      INTERFACER II EQUATES                                      */
  193. /*-----------------------------------------------------------------*/
  194. #define BASE_PORT 0x0c8            /* Interfacer II printer ports     */
  195. #define HAND_SHAKE BASE_PORT + 1    /* Handshaking port        */
  196. #define LIST_PORT HAND_SHAKE + 1    /* Printer data port       */
  197. /*-----------------------------------------------------------------*/
  198. /*      ITOH 8510 PRINTER EQUATES                                  */
  199. /*-----------------------------------------------------------------*/
  200. #define OFF_STROBE 0x0ff    /* To turn all strobes off         */
  201. #define IN_DATA    0x0bf       /* Active, data input signal       */
  202. #define BUSY_INPUT 0x07f    /* Active, input busy signal       */
  203. #define BUSY       0x080    /* Printer busy signal             */
  204. #define DELAY      100        /* 1 millisecond delay ?