home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TSTDRIVE / FUNCTION.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  4.7 KB  |  318 lines

  1. /*    Function.c        11/2/88 - 2/23/89    D.Mui        */
  2. /*    Fix the scandisk    5/1/89    - 5/3/89    D.Mui        */
  3.  
  4. #include "define.h"
  5.  
  6.  
  7.  
  8. /*
  9.  * This routine convert binary number to ascii value
  10.  */
  11. itoa(inword, buffer)            
  12. UWORD    inword;
  13. BYTE    *buffer;
  14. {    
  15.     UWORD        temp1, value;
  16.     REG WORD    i, j;
  17.     BYTE        tmpbuf[10];
  18.     REG BYTE    *ascbuf;
  19.     
  20.     ascbuf = buffer;
  21.         
  22.     i = 0;                /* if the value is non zero  */
  23.  
  24.     if (!inword) {
  25.         *ascbuf++ = '0';
  26.     } else {
  27.         value = inword;
  28.         while(value) {
  29.             temp1 = value % 10;    /*  find the remainder    */
  30.             temp1 += 0x0030;    /*  convert to ASCII    */
  31.             tmpbuf[i++] = temp1;    /*  buffer is reverse    */
  32.               value = value / 10;
  33.         }
  34.  
  35.         for (j = i-1; j >= 0; j--)     /* reverse it back    */
  36.             *ascbuf++ = tmpbuf[j];
  37.     }
  38.  
  39.     *ascbuf = 0;            /* end of string mark    */
  40.     return;
  41. }
  42.  
  43.  
  44.  
  45. /*
  46.  * This routine convert binary number to ASCII hex
  47.  */
  48. itoh(inword, buffer)            
  49. UWORD        inword;
  50. BYTE        *buffer;
  51. {    
  52.     UWORD        temp1, value;
  53.     REG WORD    i, j;            
  54.     BYTE        tmpbuf[12];
  55.     REG BYTE    *ascbuf;
  56.     
  57.     ascbuf = buffer;
  58.     i = 0;                /* if the value is non zero  */
  59.  
  60.     if (!inword) {
  61.         *ascbuf++ = '0';
  62.     } else {
  63.         value = inword;
  64.         while(value) {
  65.             temp1 = value % 16;    /*  find the remainder    */
  66.             if (temp1 > 9)
  67.                 temp1 += 0x37;
  68.             else
  69.                 temp1 += 0x30;    /*  convert to ASCII    */
  70.             tmpbuf[i++] = temp1;    /*  buffer is reverse    */
  71.             value = value / 16;
  72.         }
  73.  
  74.         for (j = i-1; j >= 0; j--)     /* reverse it back    */
  75.             *ascbuf++ = tmpbuf[j];
  76.     }
  77.     *ascbuf = 0;            /* end of string mark    */
  78.     return;
  79. }
  80.  
  81.  
  82.  
  83. /*
  84.  * This routine convert binary number to ascii value
  85.  */
  86. ltoa(longval, buffer) 
  87. LONG    longval;
  88. BYTE    buffer[];
  89. {
  90.     UWORD    digit;
  91.     WORD    i, j, k;
  92.     LONG    divten;
  93.     BYTE    buf1[12];
  94.  
  95.     i = 0;
  96.     k = 0;
  97.     
  98.     if (!longval) {
  99.         buffer[k++] = '0';
  100.     } else {
  101.       while(longval) {
  102.         divten = longval / 10;
  103.         digit = (int)(longval - (divten * 0x0AL));
  104.         buf1[i++] = '0' + digit;
  105.         longval = divten;
  106.       }
  107.  
  108.       for (j = i-1; j >= 0; j--)
  109.           buffer[k++] = buf1[j];
  110.     }
  111.     buffer[k] = 0;
  112. }
  113.  
  114.  
  115.  
  116. /*
  117.  * This routine convert long binary number to ASCII hex
  118.  */
  119. ltoh(longval, buffer) 
  120. LONG    longval;
  121. BYTE    buffer[];
  122. {
  123.     WORD    i, j, k;
  124.     LONG    value;
  125.     BYTE    digit;
  126.     BYTE    buf1[12];
  127.  
  128.     for (i = 0, j = 0; j < 8; j++) {
  129.         value = longval & 0x0000000FL;
  130.         longval >>= 4;
  131.         
  132.         if ((value >= 0) && (value <= 9))
  133.             digit = (BYTE)(value) + '0';
  134.         else
  135.             digit = (BYTE)(value) + 0x37;
  136.  
  137.         buf1[i++] = digit;
  138.         
  139.         if (!longval)
  140.             break;
  141.     }
  142.  
  143.     k = 0;
  144.     for (j = i - 1; j >= 0; j--)
  145.         buffer[k++] = buf1[j];
  146.  
  147.     buffer[k] = 0;
  148. }
  149.  
  150.  
  151. /*
  152.  * Change from ASCII to a binary word
  153.  */
  154. atoi(ptr)
  155. char *ptr;
  156. {
  157.     REG WORD n;
  158.  
  159.     for (n = 0; (*ptr >= '0' && *ptr <= '9'); ptr++)
  160.     n = (10 * n) + *ptr - '0'; 
  161.  
  162.     return (n);
  163. }
  164.  
  165.  
  166. /*
  167.  * Change from ASCII hex to a binary word
  168.  */
  169. htoi(ptr)
  170. BYTE *ptr;
  171. {
  172.     REG WORD n;
  173.     BYTE t;
  174.  
  175.     for (n = 0; *ptr; ptr++) {
  176.         t = toupper(*ptr);
  177.         
  178.             if (t >= '0' && t <= '9')
  179.             n = (16 * n) + t - '0'; 
  180.             else if (t >= 'A' && t <= 'F')
  181.             n = (16 * n) + (t - 0x37); 
  182.     }
  183.  
  184.     return (n);
  185. }
  186.  
  187.  
  188. /*
  189.  * Change from ASCII to a binary long
  190.  *    TRUE is OK otherwise it is FALSE
  191.  */
  192. atol(ptr, value)
  193. BYTE    *ptr;
  194. LONG    *value;
  195. {
  196.     LONG    n, n1;
  197.     UWORD    i;
  198.  
  199.     for (n = 0L, i = 0, n1 = 0L; *ptr; ptr++) {
  200.         if (*ptr >= '0' && *ptr <= '9') {
  201.             n1 = (10 * n1) + (*ptr - '0');
  202.             if (n1 >= n)
  203.                 n = n1;
  204.             else
  205.                 return(FALSE);
  206.         } else
  207.             return(FALSE);
  208.     }
  209.     *value = n;
  210.     return (TRUE);
  211. }
  212.  
  213.  
  214.  
  215. /* 
  216.  * Change from ASCII hex to a long binary value
  217.  *    TRUE is OK , FALSE is overflow
  218.  */
  219. htol(ptr, value)
  220. BYTE    *ptr;
  221. LONG    *value;
  222. {
  223.     LONG    n;
  224.     WORD    i;
  225.     BYTE    t, toupper();
  226.  
  227.     for (n = 0L; *ptr; ptr++) {
  228.         t = toupper(*ptr);
  229.  
  230.         if (t >= '0' && t <= '9') {
  231.             n = (16 * n) + (t - '0');
  232.         } else {
  233.             if (t >= 'A' && t <= 'F')
  234.                 n = (16 * n) + (t - 0x37);
  235.             else
  236.                 return(FALSE);
  237.         }
  238.     }
  239.     *value = n;
  240.     return (TRUE);
  241. }
  242.  
  243.  
  244.  
  245. /*
  246.  * Do a byte comparsion    
  247.  */
  248. bcmp(source, dest, size)
  249. BYTE    *source;
  250. BYTE    *dest;
  251. UWORD    size;
  252. {
  253.     UWORD    i;
  254.  
  255.     for (i = 0; i < size; i++) {
  256.         if (source[i] != dest[i])
  257.         return(FALSE);
  258.     }
  259.     return(TRUE);
  260. }
  261.  
  262.  
  263. /*
  264.  * Return uppercase of `c'
  265.  *
  266.  */
  267. BYTE
  268. toupper(c)
  269. BYTE c;
  270. {
  271.     if(c >= 'a' && c <= 'z')
  272.     c -= 0x20;
  273.     return c;
  274. }
  275.  
  276.  
  277.  
  278. bfill(source, input, size)
  279. REG BYTE    *source;
  280. REG BYTE    input;
  281. REG UWORD    size;
  282. {
  283.     REG UWORD    i;
  284.  
  285.     for(i = 0; i < size; i++)
  286.       *source++ = input;
  287. }
  288.  
  289.  
  290.  
  291. llfill(source, input, size)
  292. REG LONG    *source;
  293. REG LONG    input;
  294. REG LONG    size;
  295. {
  296.     REG LONG    i;
  297.  
  298.     for(i = 0; i < size; i++)
  299.       *source++ = input;    
  300. }
  301.  
  302.  
  303.  
  304. lbfill(source, input, size)
  305. REG BYTE    *source;
  306. REG BYTE    input;
  307. REG LONG    size;
  308. {
  309.     REG LONG    i;
  310.  
  311.     for(i = 0; i < size; i++)
  312.       *source++ = input;
  313. }
  314.  
  315.  
  316.  
  317.  
  318.