Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  Service 02H (decimal 2) reads one or more disk sectors into memory. If you
  want to read more than one sector, every sector must be on the same track
  and read/write head. This is largely because the ROM BIOS doesn't know how
  many sectors might be on a track, so it can't know when to switch from one
  head or track to another. Usually, this service is used for reading either
  individual sectors or an entire trackful of sectors for bulk operations
  such as DISKCOPY in DOS. Various registers are used for control
  information in a read operation. They are summarized in Figure 10-3.

  Parameters                           Status Results
  --------------------------------------------------------------------------
  DL = drive number                    If CF = 0, then no error and AH = 0

  DH = head number                     If CF = 1, then error and AH contains
                                       service 01H status bits

  CH = cylinder number
(D) = diskette only

  low-order 8 bits of cylinder
  number
(F) = fixed disk only


  CL = sector number
(D) = diskette only

  high-order 2 bits of cylinder number
  plus 6-bit sector number
(F) = fixed disk only


  AL = number of sectors to be read
  ES:BX = address of buffer
  --------------------------------------------------------------------------

  Figure 10-3.  The registers used for control information by the read,
  write, verify, and format services.

  DL contains the drive number, and DH contains the diskette side or
  fixed-disk read/write head number.

  CH and CL identify, for diskettes, the cylinder and sector number to be
  read. CH contains the cylinder number, which should be less than the total
  number of cylinders on the formatted diskette. (See Chapter 5 for a table
  of standard IBM formats.) Of course, the cylinder number can be higher
  with non-IBM formats or with some copy-protection schemes. CL contains the
  sector number.

  For fixed disks, there may be more than 256 cylinders, so the ROM BIOS
  requires you to specify a 10-bit cylinder number in CH and CL: You must
  place the 8 low-order bits of the cylinder number in CH. The 2 high-order
  bits of CL contain the 2 high-order bits of the cylinder number. The 6
  low-order bits of CL designate the sector number to be read. Don't forget
  that sectors are numbered from 1, unlike drives, cylinders, or heads
  (sides).

  AL contains the number of sectors to be read. For diskettes, this is
  normally either 1, 8, 9, 15, or 18. We are warned by IBM not to request 0
  sectors.

  ES:BX contains the buffer location. The location of the memory area where
  the data will be placed is provided by a segmented address given in this
  register pair.

  The data area should be big enough to accommodate as much as is read; keep
  in mind that while normal DOS sectors are 512 bytes, sectors can be as
  large as 1024 bytes. (See the format service that follows.) When this
  service reads more than one sector, it lays the sectors out in memory one
  right after another.

  CF (the carry flag) contains the error status of the operation. The result
  of the operation is actually reported through a combination of the carry
  flag and the AH register. If CF = 0, no error occurred, AH will also be 0,
  and, for a diskette, the number of sectors read will be returned in AL. If
  CF = 1, an error did occur, and AH will contain the status value detailed
  under service 01H, the status service.

  When using service 02H with a diskette drive or any other active diskette
  service, remember that the diskette-drive motor takes some time to reach a
  working speed and that none of these services waits for this to happen.
  Although our own experience with the ROM BIOS diskette services suggests
  that this is rarely a problem, IBM recommends that any program using these
  services try three times before assuming that an error is real and that it
  use the reset service between tries. The logic of the suggested operation
  is as follows (partly expressed in BASIC):

  10 ERROR COUNT = 0
  20 WHILE ERROR.COUNT < 3
  30 ' do read/write/verify/format operation
  40 ' error checking here: if no error goto 90
  50   ERROR.COUNT = ERROR.COUNT + 1
  60 ' do reset operation
  70 WEND
  80 ' act on error
  90 ' carry on after success

  Be sure to see the section on page 209 for the effect of the disk-base
  table on the reset operation.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson