home *** CD-ROM | disk | FTP | other *** search
- BDISK Library Documentation
- By Eric Tauck
- 12/14/87
-
- The BDISK Library is a library file containing routines for accessing the ROM
- BIOS 5 1/4" 360K floppy disk services. Routines are provided for formatting
- disks and reading and writing absolute disk sectors. Library interfaces for
- Macro Assembler 5.0, QuickBASIC 4.0, and Turbo C 1.0 are also provided along
- with a fast format program written in each language.
-
- The format, read, write, and verify routines interface directly with the BIOS
- services under interrupt 13. The BIOS disk routines are dependent on the
- diskette parameters pointed at by interrupt 1E. The routines SETBASE and
- RESBASE are provided to modify these parameters. SETBASE works by saving the
- original interrupt 1E, copying the parameters to a local data area, setting
- its own number of sectors per track and bytes per sector, and then pointing
- interrupt 1E the local data area parameters. RESBASE restores the original
- interrupt 1E. SETBASE should be called before using any of the other disk
- routines, and RESBASE should be called when finished and before calling any
- other disk routines (the DOS disk routines, for instance).
-
- All library routines accept 16 bit arguments, preserve all registers (except
- AX), and return a 16 bit value in AX. The return value is zero if there was
- no error, otherwise the error code is returned. The least significant 8 bits
- of the error code are set by the BIOS. The most significant 8 bits are set by
- the library. The library routines are as follows:
-
- SETBASE: TRACK_SIZE, SECTOR_SIZE
-
- Copies and modifies the diskette parameters. TRACK_SIZE is the number of
- sectors per track (9 is normal) and SECTOR_SIZE is the number of bytes per
- sector (512 is normal). Should be called before the other library routines.
-
- RESBASE:
-
- Restores the original diskette parameters. Should be called when finished
- with the library routines (failure to do so will probably make all floppy
- disk drives unreadable until the computer is restarted).
-
- SECRED: DRIVE, HEAD, TRACK, SECTOR, COUNT, SEGMENT, OFFSET
-
- Reads absolute disk sectors. The DRIVE, HEAD, TRACK, and SECTOR specify the
- starting disk location of the read operation. COUNT is the number of
- sectors to read. Note: I don't think track boundaries can be crossed with a
- single read/write/verify, and certainly not in the correct sector order.
- SEGMENT and OFFSET are the location in memory that will receive the data
- from the disk.
-
- SECVER: DRIVE, HEAD, TRACK, SECTOR, COUNT
-
- Verifies absolute disk sectors. The DRIVE, HEAD, TRACK, and SECTOR specify
- the starting disk location of the verify operation. COUNT is the number of
- sectors to write. Note: I don't think track boundaries can be crossed with a
- single read/write/verify, and certainly not in the correct sector order. If
- the verify is unsuccessful, a BIOS error code will be returned.
-
- SECWRT: DRIVE, HEAD, TRACK, SECTOR, COUNT, SEGMENT, OFFSET
-
- Writes absolute disk sectors. The DRIVE, HEAD, TRACK, and SECTOR specify
- the starting disk location of the write operation. COUNT is the number of
- sectors to write. Note: I don't think track boundaries can be crossed with a
- single read/write/verify, and certainly not in the correct sector order.
- SEGMENT and OFFSET are the location in memory of the data to write.
-
- TRKFRM: DRIVE, HEAD, TRACK, TRACK_SIZE, SECTOR_SIZE
-
- Formats absolute disk tracks. The DRIVE, HEAD, and TRACK specify the
- starting disk location of the format operation. TRACK_SIZE is the number of
- sectors per track (9 is normal) and SECTOR_SIZE is the number of bytes per
- sector (512 is normal).
-
- Fast Format Program
-
- The fast format program, Fast Floppy Format (FFF), formats standard 5 1/4"
- 360K (double sided, 9 sector) DOS 2.x and DOS 3.x disks. The disk format is
- the boot sector first, two file allocation tables, and then the directory. No
- verifying of sectors is done, thus the FAT's list all sectors as being
- available.
-
- The format programs, though in different languages, perform the same
- operations and are very similar to each other. The format sequence consists
- of:
-
- 1. Set the diskette parameters with SETBASE.
- 2. Format the disk with TRKFRM.
- 3. Write the boot, FAT, and directory sectors with SECWRT.
- 4. Restore the diskette parameters with RESBASE.
-
- Interrupt vector 1E is modified by SETBASE and it is important that the
- interrupt be restored by RESBASE before exiting. For this reason, all the
- programs attempt to trap any BREAK occurring during the program and call
- RESBASE before exiting.
-
- BDISK.INC, Assembly Language Interface
-
- The library interface and fast format program are written in Macro Assembler
- 5.0. The file STDDEF.INC contains some general purpose macros for loading
- the stack and are not specific to the BDISK interface.
-
- The defined assembler macros are:
-
- setbase trksize, secsize
- resbase
- secred drive, head, track, sector, count, segment, offset
- secver drive, head, track, sector, count
- secwrt drive, head, track, sector, count, segment, offset
- trkfrm drive, head, track, trksize, secsize
-
- BDISK.H, C Language Interface
-
- The library interface and fast format program are written in Turbo C 1.0. The
- other include files used in FFF.C are standard C include files that are
- provided with Turbo C.
-
- The defined C functions are:
-
- setbase (int secs, int byts)
- resbase (void)
- secred (int drv, int hed, int trk, int sec, int cnt, void far *buf)
- secver (int drv, int hed, int trk, int sec, int cnt)
- secwrt (int drv, int hed, int trk, int sec, int cnt, void far *buf)
- trkfrm (int drv, int hed, int trk, int secs, int byts)
-
- BDISK.BI, BASIC Language Interface
-
- The library interface and fast format program are written in QuickBASIC 4.0.
- Since I don't know of any way to directly access the library symbol _BOTSEC, I
- wrote a pair of small BASIC functions (BOOTSSEG and BOOTSOFF) to return the
- segment and offset of _BOTSEC. You could, for instance, set the number of
- disk sides to 1 with the following code:
-
- DEF SEG = bootsseg 'set segment
- POKE bootsoff + 26, 1 'least significant byte
- POKE bootsoff + 27, 0 'most significant byte
-
- The routines BOOTSSEG and BOOTSOFF are contained in the file BOOTLOC.OBJ
- (assembler source code in BOOTLOC.ASM). BOOTLOC.OBJ must be included with
- FFF.OBJ during linking.
-
- The defined BASIC functions are:
-
- bootsseg% ()
- bootsoff% ()
- setbase% (secs%, byts%)
- resbase% ()
- secred% (drv%, hed%, trk%, sec%, cnt%, bufseg%, bufoff%)
- secver% (drv%, hed%, trk%, sec%, cnt%)
- secwrt% (drv%, hed%, trk%, sec%, cnt%, bufseg%, bufoff%)
- trkfrm% (drv%, hed%, trk%, secs%, byts%)
-
- Disk Layout
-
- The first sectors on a disk are used by the system for reading and writing the
- rest of the disk. These sectors are the only ones that must be initialized,
- after formatting the entire disk, to make the disk usable.
-
- The first physical sector (head 0, track 0, sector 1) is the boot sector. It
- contains information about the type of disk and a short program which is
- executed if the disk used to boot up the computer. The library contains a
- boot sector (addressed by _BOOTSEC) usable for standard 2 sided / 9 sector /
- 40 track disks.
-
- The next four sectors are used by two identical FAT's (file allocation
- tables). A FAT consists of a media descriptor byte, two reserved bytes (value
- FFH), and then the FAT entries. The FAT entries contain information about
- what sectors (allocated in units of clusters) are unusable and what files the
- clusters belong to. The sample format programs do not check for bad sectors,
- thus all the clusters are marked as free and usable (i.e. all zeros).
-
- The next seven sectors are used by the directory. An empty directory entry is
- all zeros, thus the format programs write 7 consecutive sectors of all zeros.
-
- Most of this information about disks come from the book "Advanced MS DOS" by
- Ray Duncan (Microsoft Press, 1986).
-