home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 165 / DSKPARM.ZIP / DOSFNS.H < prev    next >
C/C++ Source or Header  |  1986-10-06  |  5KB  |  229 lines

  1. /* ================================================
  2. ** dosfns.h -- Miscellaneous routine to call MS-DOS
  3. **        system functions or perform system
  4. **        specific tasks.
  5. ** ================================================
  6. */
  7.  
  8. /* getdfs -- Get Disk Free Space.  Returns
  9. **        information on disk capacity
  10. **        and available space.
  11. **    Input:
  12. **        drive = target drive (A=0, B=1,...)
  13. **
  14. **    Output:
  15. **        avail = number of available clusters
  16. **        total = total clusters on disk
  17. **        sectsize = bytes/sector for disk
  18. **    Returns:
  19. **        Number of sectors per cluster
  20. **        -1 if drive has invalid sectors/cluster
  21. */
  22. getdfs(drive, avail, total, sectsize)
  23. int drive;
  24. unsigned *avail, *total, *sectsize;
  25. {
  26.     union REGS regs;
  27.     
  28.     regs.x.dx = drive+1;
  29.     regs.x.ax = 0x3600;
  30.     intdos(®s, ®s);
  31.     *avail = regs.x.bx;
  32.     *total = regs.x.dx;
  33.     *sectsize = regs.x.cx;
  34.     return(regs.x.ax);
  35. }
  36. /* parse -- Parse filename into FCB.  This
  37. **        function takes a command line and
  38. **        parses it for a file name of the form
  39. **        d:filename.ext.
  40. **
  41. **        Bits in mode control parsing:
  42. **
  43. **        bit 0=1 : ignore leading separators
  44. **        bit 1=1 : change drive id only if one given
  45. **        bit 2=1 : change filename only if one given
  46. **        bit 3=1 : change extension only if one given
  47. **
  48. **        returnse -1 if drive invalid
  49. */
  50. parse(filename, fcb, mode)
  51. char filename[];
  52. struct ext_fcb *fcb;
  53. int mode;
  54. {
  55.     union REGS regs;
  56.     struct SREGS segregs;        /* V3.0 is union SREGS segregs; */
  57.     
  58.     regs.x.si = (unsigned) filename;
  59.     segread(&segregs);
  60.     segregs.es = segregs.ds;
  61.     regs.x.di = (unsigned) fcb;
  62.     regs.h.al = (unsigned char) mode;
  63.     regs.h.ah = 0x29;
  64.     intdosx(®s, ®s, &segregs);
  65.     return((int) regs.h.al);
  66. }
  67. /* setdta -- Set Disk Transfer Address.
  68. **        Sets the DOS disk transfer address
  69. **        to the address of buffer.
  70. */
  71. setdta(buffer)
  72. char buffer[];
  73. {
  74.     union REGS regs;
  75.     
  76.     regs.x.ax = 0x1A00;
  77.     regs.x.dx = (unsigned) buffer;
  78.     intdos(®s, ®s);
  79. }
  80. /* search_first -- Search for First Directory Entry
  81. **        On entry fcb contains an extended
  82. **        File Control Block with file name
  83. **        and attribute bits set.  On exit
  84. **        fcb contains matched entry unless
  85. **        return code is 255, in which case
  86. **        no match was found.
  87. */
  88. search_first(fcb)
  89. struct ext_fcb *fcb;
  90. {
  91.      union REGS regs;
  92.     
  93.     regs.x.ax = 0x1100;
  94.     regs.x.dx = (unsigned) fcb;
  95.     intdos(®s, ®s);
  96.     return((int) regs.h.al);
  97. }
  98. /* search_next -- Search for Next Directory Entry.
  99. **        Same as search_first except for
  100. **        use on subsequent calls.
  101. */
  102. search_next(fcb)
  103. struct ext_fcb *fcb;
  104. {
  105.      union REGS regs;
  106.     
  107.     regs.x.ax = 0x1200;
  108.     regs.x.dx = (unsigned) fcb;
  109.     intdos(®s, ®s);
  110.     return((int) regs.h.al);
  111. }
  112. /* current_drv -- This function returns the drive number
  113. **        of the current default drive (A=0,
  114. **        B=1, C=2, etc.).
  115. */
  116. current_drv()
  117. {
  118.     union REGS regs;
  119.     
  120.     regs.x.ax = 0x1900;
  121.     intdos(®s, ®s);
  122.     return((int) regs.h.al);
  123. }
  124. /* select_drv -- This function changes the current default
  125. **        drive to the specified drive (A=0,
  126. **        B=1, C=2, etc.).  Returns the total number of
  127. **        drives.
  128. */
  129. select_drv(drv)
  130. int drv;
  131. {
  132.     union REGS regs;
  133.     
  134.     regs.x.ax = 0x0E00;
  135.     regs.x.dx = (unsigned) drv;
  136.     intdos(®s, ®s);
  137.     return((int) regs.h.al);
  138. }
  139. /* get_table -- This function return a "far" pointer to
  140. **        the parameters table for the specified
  141. **        disk drive (A=0, B=1, etc.).
  142. */
  143. struct disk_table far *get_table(drv)
  144. int drv;
  145. {
  146.     struct disk_table far *t;
  147.     
  148.     union REGS regs;
  149.     struct SREGS segregs;
  150.     
  151.     regs.x.ax = 0x3200;
  152.     regs.x.dx = drv+1;
  153.     segread(&segregs);
  154.     intdosx(®s, ®s, &segregs);
  155.     FP_SEG(t) = segregs.ds;
  156.     FP_OFF(t) = regs.x.bx;
  157.     return(t);
  158. }
  159. /* dtoa -- Takes date in Microsoft packed
  160. **        format and converts it to an ASCII
  161. **        string as : "Mmm, dd, yr"
  162. */
  163. dtoa(date, s)
  164. struct ms_date date;
  165. char s[];
  166. {
  167.     static char *mo_str[] = {
  168.         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  169.         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  170.     };
  171.     
  172.     strcpy(s,"        ");
  173.     if (date.m  != 0)
  174.       sprintf(s, "%s %2d, %4d",
  175.         mo_str[date.m-1], date.d, date.y+1980);
  176. }
  177. /* ttoa -- Takes time in Microsoft packed
  178. **        format and converts it to an ASCII
  179. **        string as : "HH:MMx", where x is
  180. **        'a' for A.M. and 'p' for P.M.
  181. */
  182. ttoa(time, s)
  183. struct ms_time time;
  184. char s[];
  185. {
  186.     int hr;
  187.     char am_pm;
  188.     
  189.     hr = time.hh;
  190.     strcpy(s, "      ");
  191.     if ((hr != 0) || (time.mm != 0) || (time.xx != 0)) {
  192.         am_pm = (hr >= 12) ? 'p' : 'a';
  193.         hr %= 12;
  194.         if (hr == 0)
  195.           hr += 12;
  196.         sprintf(s, "%2d:%02d%c", hr, time.mm, am_pm);
  197.     }
  198. }
  199. /* fatval -- This function calculates the logical
  200. **        "chaining" of cluster numbers in a File
  201. **        Allocation Table.  Given an entry
  202. **        cluster number it calculates the next
  203. **        cluster using the array fat[].
  204. **
  205. **        If is12 is TRUE then fat[] is assumed to
  206. **        contain 12 bit entries, otherwise fat[]
  207. **        is assumed to contain 16 bit entries.
  208. */
  209. fatval(is12, cluster, fat)
  210. int is12;
  211. unsigned cluster;
  212. unsigned char fat[];
  213. {
  214.     unsigned clword, cloffset;
  215.     
  216.     if (is12) {
  217.         /* 12 bit FAT lookup */
  218.         cloffset = 3*cluster/2;
  219.         clword = fat[cloffset] + (fat[cloffset + 1] << 8);
  220.         if (cluster & 1)
  221.           return(clword >> 4);  /* odd cluster */
  222.         else
  223.           return(clword & 0x0FFF);    /* even cluster */
  224.     }
  225.     else
  226.       /* 16 bit FAT lookup */
  227.       return(((unsigned int *) fat)[cluster]);
  228. }
  229.