home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / C-FDC / FMTRACK.C < prev    next >
Text File  |  1986-08-01  |  2KB  |  69 lines

  1. /*
  2.  *    Track format function
  3.  *
  4.  *    This routine formats a track on a floppy diskette
  5.  *    The parameters are:
  6.  *        drive: 01 = A:, 02 = B, etc.
  7.  *        head: 0 - 1 (same as cylinder)
  8.  *        max_sect: maximum sectors (8/9/15)
  9.  *        sect_type: sector type
  10.  *            00 = 128 bytes per sector
  11.  *            01 = 256 bytes per sector
  12.  *            02 = 512 bytes per sector
  13.  *            03 = 1024 bytes per sector
  14.  *
  15.  *    Prior to the first invocation of this function on a diskette,
  16.  *    setdasd() must be called to establish the type of diskette in
  17.  *    the appropriate type of drive.
  18.  *
  19.  * If formatting a 320/360K in either a 320/360 or 1.2M drive in an AT,
  20.  * setdpb() must be called with the format gap length set to 050H.
  21.  * Additionally, the EOT parameter must be set to the maximum number of
  22.  * sectors for the track (8/9).
  23.  *
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <dos.h>
  28. #include "fdc.h"
  29.  
  30. int fmtrack(int drive, int head, int track, int max_sect, int sect_type)
  31. {
  32.  
  33.     int i;
  34.     int times = 0;
  35.     static char fmtparm[4 * MAXSECT];
  36.     struct REGVAL r;
  37.     extern int errno;
  38.     
  39.     for (i = 0; i < max_sect; ++i) {    /* fill format fields */
  40.         fmtparm[i * 4] = track;
  41.         fmtparm[i * 4 + 1] = head;
  42.         fmtparm[i * 4 + 2] = i + 1;
  43.         fmtparm[i * 4 + 3] = sect_type;
  44.     }
  45.     for (i = 0; i < 4; ++i)              /* end with four 0's */
  46.         fmtparm[(max_sect  * 4) + i] = 0;
  47.  
  48.     r.ax = FORMATTR | max_sect;
  49.     r.es = getds();
  50.     r.bx = fmtparm;
  51.     r.cx = (track << 8);
  52.     r.dx = (head << 8) | drive;
  53.     do {                /* do it a max of three times */
  54.         if(sysint(DISKINT, &r, &r) & 1) 
  55.             ++times;
  56.         else {
  57.             times = 0;        
  58.             break;
  59.         }
  60.     } while (times < 4);
  61.     if (!times) 
  62.         return(0);
  63.     else {
  64.         errno = (int)(r.ax >> 8);
  65.         return(-1);
  66.     }
  67.  
  68. }        
  69.