home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / dos / bdisk / bdisk.doc < prev    next >
Encoding:
Text File  |  1987-12-14  |  8.2 KB  |  175 lines

  1.                           BDISK Library Documentation
  2.                                  By Eric Tauck
  3.                                     12/14/87
  4.  
  5. The BDISK Library is a library file containing routines for accessing the ROM 
  6. BIOS 5 1/4" 360K floppy disk services.  Routines are provided for formatting 
  7. disks and reading and writing absolute disk sectors.  Library interfaces for 
  8. Macro Assembler 5.0, QuickBASIC 4.0, and Turbo C 1.0 are also provided along 
  9. with a fast format program written in each language. 
  10.  
  11. The format, read, write, and verify routines interface directly with the BIOS 
  12. services under interrupt 13.  The BIOS disk routines are dependent on the 
  13. diskette parameters pointed at by interrupt 1E.  The routines SETBASE and 
  14. RESBASE are provided to modify these parameters.  SETBASE works by saving the 
  15. original interrupt 1E, copying the parameters to a local data area, setting 
  16. its own number of sectors per track and bytes per sector, and then pointing 
  17. interrupt 1E the local data area parameters.  RESBASE restores the original 
  18. interrupt 1E.  SETBASE should be called before using any of the other disk 
  19. routines, and RESBASE should be called when finished and before calling any 
  20. other disk routines (the DOS disk routines, for instance). 
  21.  
  22. All library routines accept 16 bit arguments, preserve all registers (except 
  23. AX), and return a 16 bit value in AX.  The return value is zero if there was 
  24. no error, otherwise the error code is returned.  The least significant 8 bits 
  25. of the error code are set by the BIOS.  The most significant 8 bits are set by 
  26. the library.  The library routines are as follows:
  27.  
  28. SETBASE: TRACK_SIZE, SECTOR_SIZE
  29.  
  30.   Copies and modifies the diskette parameters.  TRACK_SIZE is the number of 
  31.   sectors per track (9 is normal) and SECTOR_SIZE is the number of bytes per 
  32.   sector (512 is normal).  Should be called before the other library routines. 
  33.  
  34. RESBASE: 
  35.  
  36.   Restores the original diskette parameters.  Should be called when finished 
  37.   with the library routines (failure to do so will probably make all floppy 
  38.   disk drives unreadable until the computer is restarted). 
  39.  
  40. SECRED: DRIVE, HEAD, TRACK, SECTOR, COUNT, SEGMENT, OFFSET
  41.  
  42.   Reads absolute disk sectors.  The DRIVE, HEAD, TRACK, and SECTOR specify the 
  43.   starting disk location of the read operation.  COUNT is the number of 
  44.   sectors to read. Note: I don't think track boundaries can be crossed with a 
  45.   single read/write/verify, and certainly not in the correct sector order.  
  46.   SEGMENT and OFFSET are the location in memory that will receive the data 
  47.   from the disk. 
  48.   
  49. SECVER: DRIVE, HEAD, TRACK, SECTOR, COUNT
  50.  
  51.   Verifies absolute disk sectors.  The DRIVE, HEAD, TRACK, and SECTOR specify 
  52.   the starting disk location of the verify operation.  COUNT is the number of 
  53.   sectors to write. Note: I don't think track boundaries can be crossed with a 
  54.   single read/write/verify, and certainly not in the correct sector order.  If 
  55.   the verify is unsuccessful, a BIOS error code will be returned.
  56.  
  57. SECWRT: DRIVE, HEAD, TRACK, SECTOR, COUNT, SEGMENT, OFFSET
  58.  
  59.   Writes absolute disk sectors.  The DRIVE, HEAD, TRACK, and SECTOR specify 
  60.   the starting disk location of the write operation.  COUNT is the number of 
  61.   sectors to write. Note: I don't think track boundaries can be crossed with a 
  62.   single read/write/verify, and certainly not in the correct sector order.  
  63.   SEGMENT and OFFSET are the location in memory of the data to write. 
  64.  
  65. TRKFRM: DRIVE, HEAD, TRACK, TRACK_SIZE, SECTOR_SIZE
  66.  
  67.   Formats absolute disk tracks.  The DRIVE, HEAD, and TRACK specify the 
  68.   starting disk location of the format operation.  TRACK_SIZE is the number of 
  69.   sectors per track (9 is normal) and SECTOR_SIZE is the number of bytes per 
  70.   sector (512 is normal).  
  71.  
  72.                               Fast Format Program
  73.  
  74. The fast format program, Fast Floppy Format (FFF), formats standard 5 1/4" 
  75. 360K (double sided, 9 sector) DOS 2.x and DOS 3.x disks.  The disk format is 
  76. the boot sector first, two file allocation tables, and then the directory.  No 
  77. verifying of sectors is done, thus the FAT's list all sectors as being 
  78. available. 
  79.  
  80. The format programs, though in different languages, perform the same 
  81. operations and are very similar to each other.  The format sequence consists 
  82. of: 
  83.  
  84.   1. Set the diskette parameters with SETBASE.
  85.   2. Format the disk with TRKFRM.
  86.   3. Write the boot, FAT, and directory sectors with SECWRT.
  87.   4. Restore the diskette parameters with RESBASE.
  88.  
  89. Interrupt vector 1E is modified by SETBASE and it is important that the 
  90. interrupt be restored by RESBASE before exiting.  For this reason, all the 
  91. programs attempt to trap any BREAK occurring during the program and call 
  92. RESBASE before exiting. 
  93.   
  94.                     BDISK.INC, Assembly Language Interface
  95.  
  96. The library interface and fast format program are written in Macro Assembler 
  97. 5.0.  The file STDDEF.INC contains some general purpose macros for loading 
  98. the stack and are not specific to the BDISK interface. 
  99.  
  100. The defined assembler macros are:
  101.  
  102.   setbase trksize, secsize
  103.   resbase 
  104.   secred  drive, head, track, sector, count, segment, offset
  105.   secver  drive, head, track, sector, count
  106.   secwrt  drive, head, track, sector, count, segment, offset
  107.   trkfrm  drive, head, track, trksize, secsize
  108.  
  109.                          BDISK.H, C Language Interface
  110.  
  111. The library interface and fast format program are written in Turbo C 1.0.  The 
  112. other include files used in FFF.C are standard C include files that are 
  113. provided with Turbo C. 
  114.  
  115. The defined C functions are:
  116.  
  117.   setbase (int secs, int byts)
  118.   resbase (void)
  119.   secred (int drv, int hed, int trk, int sec, int cnt, void far *buf)
  120.   secver (int drv, int hed, int trk, int sec, int cnt)
  121.   secwrt (int drv, int hed, int trk, int sec, int cnt, void far *buf)
  122.   trkfrm (int drv, int hed, int trk, int secs, int byts)
  123.  
  124.                       BDISK.BI, BASIC Language Interface
  125.  
  126. The library interface and fast format program are written in QuickBASIC 4.0.  
  127. Since I don't know of any way to directly access the library symbol _BOTSEC, I 
  128. wrote a pair of small BASIC functions (BOOTSSEG and BOOTSOFF) to return the 
  129. segment and offset of _BOTSEC.  You could, for instance, set the number of 
  130. disk sides to 1 with the following code: 
  131.  
  132.   DEF SEG = bootsseg            'set segment
  133.   POKE bootsoff + 26, 1         'least significant byte
  134.   POKE bootsoff + 27, 0         'most significant byte
  135.  
  136. The routines BOOTSSEG and BOOTSOFF are contained in the file BOOTLOC.OBJ 
  137. (assembler source code in BOOTLOC.ASM).  BOOTLOC.OBJ must be included with 
  138. FFF.OBJ during linking. 
  139.  
  140. The defined BASIC functions are:
  141.  
  142.   bootsseg% ()
  143.   bootsoff% ()
  144.   setbase% (secs%, byts%)
  145.   resbase% ()
  146.   secred% (drv%, hed%, trk%, sec%, cnt%, bufseg%, bufoff%)
  147.   secver% (drv%, hed%, trk%, sec%, cnt%)
  148.   secwrt% (drv%, hed%, trk%, sec%, cnt%, bufseg%, bufoff%)
  149.   trkfrm% (drv%, hed%, trk%, secs%, byts%)
  150.  
  151.                                   Disk Layout
  152.  
  153. The first sectors on a disk are used by the system for reading and writing the 
  154. rest of the disk.  These sectors are the only ones that must be initialized, 
  155. after formatting the entire disk, to make the disk usable. 
  156.  
  157. The first physical sector (head 0, track 0, sector 1) is the boot sector.  It 
  158. contains information about the type of disk and a short program which is 
  159. executed if the disk used to boot up the computer.  The library contains a 
  160. boot sector (addressed by _BOOTSEC) usable for standard 2 sided / 9 sector / 
  161. 40 track disks. 
  162.  
  163. The next four sectors are used by two identical FAT's (file allocation 
  164. tables).  A FAT consists of a media descriptor byte, two reserved bytes (value 
  165. FFH), and then the FAT entries.  The FAT entries contain information about 
  166. what sectors (allocated in units of clusters) are unusable and what files the 
  167. clusters belong to.  The sample format programs do not check for bad sectors, 
  168. thus all the clusters are marked as free and usable (i.e. all zeros). 
  169.  
  170. The next seven sectors are used by the directory.  An empty directory entry is 
  171. all zeros, thus the format programs write 7 consecutive sectors of all zeros.
  172.  
  173. Most of this information about disks come from the book "Advanced MS DOS" by 
  174. Ray Duncan (Microsoft Press, 1986). 
  175.