home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 193_01 / deff4.c < prev    next >
Text File  |  1985-11-14  |  12KB  |  289 lines

  1. /*-----------------------------------------------------------------*/
  2. /*  LINKING FUNCTIONS  ==>  DEFF4                                  */
  3. /*  Some additional functions to be used with CLINK when turning   */
  4. /*  a CRL programme into a COM programme with BDS C.               */
  5. /*                                                                 */
  6. /*  This file contains the following functions -                   */
  7. /*                                                                 */
  8. /*       SET_BIT        PUT_ERROR           UP_STR                 */
  9. /*       LOWER_STR      ENTAB               PLIST                  */
  10. /*       LIST_STATUS    LISTS               LISTD                  */
  11. /*       MAKE_FCB       PEC_CLEAR                                  */
  12. /*                                                                 */
  13. /*  all of which are described in the file DEFF4.TXT.              */
  14. /*                                                                 */
  15. /*  WRITTEN:  14th July, 1986                                      */
  16. /*  -------                                                        */
  17. /*  Copyright 1986 by Cogar Computer Services Pty. Ltd.            */
  18. /*  All rights reserved.                                           */
  19. /*-----------------------------------------------------------------*/
  20. #include <pec.h>    /* Required for these functions            */
  21. /*=================================================================*/
  22. /*  SUBROUTINE  ==>  set_bit                                       */
  23. /*  Will set the nominated BYTE in the file control block          */
  24. /*  Choices are -                                                  */
  25. /*                 R/O       Read only                             */
  26. /*                 R/W       Read/Write (re-sets the bit)          */
  27. /*                 SYS       System file                           */
  28. /*                 DIR       Directory (re-sets SYS bit)           */
  29. /*                 ARC       Archive bit                           */
  30. /*                 CPY       Copy (re-sets Archive bit)            */
  31. /*-----------------------------------------------------------------*/
  32.  
  33. set_bit(fcb_buf,str)
  34. char fcb_buf[36], str[3];
  35. {
  36.     up_str(str);    /* convert to upper case */
  37.  
  38.     if(strcmp(str,"R/O") == 0)
  39.         fcb_buf[9] = fcb_buf[9] | 0x80;
  40.     else if(strcmp(str,"R/W") == 0)
  41.         fcb_buf[9] = fcb_buf[9] & 0x7f;
  42.     else if(strcmp(str,"SYS") == 0)
  43.         fcb_buf[10] = fcb_buf[10] | 0x80;
  44.     else if(strcmp(str,"DIR") == 0)
  45.         fcb_buf[10] = fcb_buf[10] & 0x7f;
  46.     else if(strcmp(str,"ARC") == 0)
  47.         fcb_buf[11] = fcb_buf[11] | 0x80;
  48.     else if(strcmp(str,"CPY") == 0)
  49.         fcb_buf[11] = fcb_buf[11] & 0x7f;
  50.     else put_error(str);
  51.  
  52.     if(set_attributes(fcb_buf) == -1)
  53.         printf("\nUnable to find the nominated file.\n");
  54. }
  55. /*-----------------------------------------------------------------*/
  56. /*  SUBROUTINE  ==>  put_error                                     */
  57. /*  Used with set_bit                                              */
  58. /*-----------------------------------------------------------------*/
  59.  
  60. put_error(string)
  61. char *string;
  62. {
  63. printf("\n\nThe mode  %s is unknown...terminating programme.", string);
  64. exit();
  65. }
  66. /*-----------------------------------------------------------------*/
  67. /*  LIBRARY FILE  ==  up_str                                       */
  68. /*  Will convert a string to UPPER case ASCII                      */
  69. /*-----------------------------------------------------------------*/
  70.  
  71. up_str(s)
  72. char *s;
  73. {
  74.     short i;
  75.     i = 0;
  76.     
  77.     while(s[i])
  78.     {
  79.         s[i] = toupper(s[i]);
  80.         i++;
  81.     }
  82.     s[i] = '\0';
  83. }
  84. /*-----------------------------------------------------------------*/
  85. /*  LIBRARY FILE  ==  lower_str                                    */
  86. /*  Will convert a NULL-terminated string to ASCII lower case      */
  87. /*-----------------------------------------------------------------*/
  88.  
  89. lower_str(s)
  90. char *s;
  91. {
  92.     short i;
  93.     i = 0;
  94.  
  95.     while(s[i])
  96.     {
  97.         s[i] = tolower(s[i]);
  98.         i++;
  99.     }
  100.     s[i] = '\0';
  101. }
  102. /*-----------------------------------------------------------------*/
  103. /*  LIBRARY FILE  ==>  ENTAB                                       */
  104. /*  Will compensate for TAB characters on those printers which     */
  105. /*  don't recognise the ASCII tab.   Can be altered for different  */
  106. /*  tab sizes, as needed.                                          */
  107. /*-----------------------------------------------------------------*/
  108.  
  109. entab(position, size)
  110. short position, size;
  111. {
  112.     short tab_count;
  113.  
  114.     for(tab_count = 0; tab_count <= size - position%size; tab_count++)
  115.         listc(SPACE);
  116.     tab_count--;    /* Must go back one                        */
  117.  
  118.     position = position + tab_count;
  119.     return(position);
  120. }
  121. /*-----------------------------------------------------------------*/
  122. /*  LIBRARY FILE  ==>  plist                                       */
  123. /*  Will list one character to the line printer using the actual   */
  124. /*  I/O port addresses.                                            */
  125. /*  Presently configured for GODBOUT INTERFACER II board but can   */
  126. /*  be modified for any "Centronics" connection provided the       */
  127. /*  ports and the strobe signals are known.                        */
  128. /*  NOTE:  The strobe signals used are those for the Itoh 8510     */
  129. /*  ----   printer.                                                */
  130. /*                                                                 */
  131. /*  Written for BDS C but should be portable to other C's.         */
  132. /*  Copyright 1986 by Cogar Computer Services Pty. Ltd.            */
  133. /*-----------------------------------------------------------------*/
  134. /*      INTERFACER II EQUATES                                      */
  135. /*-----------------------------------------------------------------*/
  136. #define BASE_PORT 0x0c8        /* Interfacer II printer ports     */
  137. #define HAND_SHAKE BASE_PORT + 1    /* Handshaking port        */
  138. #define LIST_PORT HAND_SHAKE + 1    /* Printer data port       */
  139. /*-----------------------------------------------------------------*/
  140. /*      ITOH 8510 PRINTER EQUATES                                  */
  141. /*-----------------------------------------------------------------*/
  142. #define OFF_STROBE 0x0ff    /* To turn all strobes off         */
  143. #define IN_DATA    0x0bf       /* Active, data input signal       */
  144. #define BUSY_INPUT 0x07f    /* Active, input busy signal       */
  145. #define BUSY       0x080    /* Printer busy signal             */
  146. #define DELAY      100        /* 1 millisecond delay ?           */
  147. #define LOOPS      1000        /* To do BUSY test                 */
  148. /*-----------------------------------------------------------------*/
  149.  
  150. plist(c)
  151. int c;                /* The character to list           */
  152. {
  153.     short i;            /* Delay counter                   */
  154.  
  155.     if(list_status() != TRUE)  /* Test the printer status      */
  156.     {
  157.         printf("\nPrinter must be turned off.");
  158.         exit();
  159.     }
  160.     else outp(LIST_PORT,c);  /* OK, so print character         */
  161.     outp(HAND_SHAKE,IN_DATA); /* Tell printer we've sent it    */
  162.     outp(HAND_SHAKE,OFF_STROBE); /* Sequence finished          */
  163. /*-----------------------------------------------------------------*/
  164. /*  We now have to wait 1 millisec until the printer can accept    */
  165. /*  more data.   I don't know how to get a 1 millisec delay in     */
  166. /*  BDS C, as the smallest allowable delay is 1/30 = 33.3 millisec */
  167. /*  for a 6 mHz clock, if we use the "sleep" function.   So what   */
  168. /*  I have done is just to use an empty loop until I got the delay */
  169. /*  approximately right for this printer.                          */
  170. /*-----------------------------------------------------------------*/
  171.     for(i = 0; i < DELAY; i++)
  172.         ;            /* Empty loop              */
  173.  
  174. }
  175. /*-----------------------------------------------------------------*/
  176.  
  177. list_status()
  178. {
  179.     short i, n;
  180.     i = n = 0;        /* Has to be changed if successful */
  181.     while(i < LOOPS && n != 1)
  182.     {
  183.     outp(HAND_SHAKE, BUSY_INPUT); /* Ask what the status is    */
  184.     outp(HAND_SHAKE, OFF_STROBE); /* End of enquiry            */
  185.     if(inp(LIST_PORT) != 0)            /* Then printer is busy    */
  186.          i++;                /* So do it again          */
  187.     else n = 1;            /* Not busy, so tell us    */
  188.     }
  189.     return(n);
  190. }
  191. /*-----------------------------------------------------------------*/
  192. /*---------------END OF PLIST--------------------------------------*/
  193. /*-----------------------------------------------------------------*/
  194. /*  LIBRARY FILE  ==>  LISTS                                       */
  195. /*  Will transmit a null-terminated string to the line printer.    */
  196. /*  Uses function ==>  listc  -  from DEFF3                        */
  197. /*-----------------------------------------------------------------*/
  198. lists(str)    /* To list a null-terminated string                */
  199. char *str;
  200. {
  201.     char c;
  202.     
  203.     while(c = *str++)
  204.         listc(c);
  205. }
  206. /*-----------------------------------------------------------------*/
  207. /*  LIBRARY FILE  ==>  LISTD                                       */
  208. /*  The listing (printer) equivalent of print_dec in DEFF3.        */
  209. /*  Will print out a decimal number in the listing.                */
  210. /*-----------------------------------------------------------------*/
  211. listd(count)    /* To list a decimal number                        */
  212. short count;
  213. {
  214.     short i;        /* Counter                                 */
  215.  
  216.     if(count < 0)
  217.     {
  218.         listc('-');    /* For negative number             */
  219.         count = -count; /* Make number positive            */
  220.     }
  221.  
  222.     i = 0;        /* Starting condition                      */
  223.     if((i = count/10) != 0)
  224.         listd(i);    /* Recursive call                  */
  225.     listc(count % 10 + '0'); /* Make the digit printable       */
  226. }
  227. /*-----------------------------------------------------------------*/
  228. /*  SUBROUTINE  ==>  make_fcb                                      */
  229. /*  Needs to know -                                                */
  230. /*                   where to look for the name                    */
  231. /*                   where name is to go  (fcb)                    */
  232. /*-----------------------------------------------------------------*/
  233.  
  234. make_fcb(name,fcb)
  235. char  name[15], fcb[36];
  236. {
  237.     char c;
  238.     short i, j, count;
  239.  
  240. /*-----------------------------------------------------------------*/
  241. /*  Note this routine DOESN'T set the drive name in the file       */
  242. /*  control block.   You must do that separately.                  */
  243. /*-----------------------------------------------------------------*/
  244.     if(name[2] == ':')
  245.         i = 2;    /* Then skip over drive name               */
  246.     else i = 0;    /* Or there is no drive name               */
  247.  
  248.     count = 0;
  249.     
  250.     for (j = 1; j < 9; j++)    /* Do the "name" part              */
  251.     {
  252.         if((c = name[i]) != '.')
  253.         {
  254.             fcb[j] = c;
  255.             i++;
  256.         }
  257.         else if((c = name[i]) == '.')
  258.         {
  259.             fcb[j] = SPACE;
  260.         }
  261.     }
  262.     if (name[i] == '.')
  263.         i++;        /* Skip over the period            */
  264.         
  265.     for (j =9; j < 12; j++)    /* Now do the "type" part          */
  266.     {
  267.     if (isalnum(name[i]) == TRUE)    /* A character             */
  268.         {
  269.             fcb[j] = name[i];
  270.             i++;
  271.         }
  272.     else fcb[j] = SPACE;
  273.     }
  274. }
  275. /*-----------------------------------------------------------------*/
  276. /*  UTILITY:       pec_clear                                       */
  277. /*  Will clear the screen of any terminal without using any of     */
  278. /*  the special terminal functions.                                */
  279. /*-----------------------------------------------------------------*/
  280.  
  281. pec_clear()
  282. {
  283.     short i;
  284.  
  285.     for(i = 0; i < 25; i++)
  286.         putchar('\n');
  287. }
  288. /*-----------------------------------------------------------------*/= 0)
  289.         l