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]

  Interrupt 25H (decimal 37) and its companion, interrupt 26H (decimal 38),
  are used to read and write specific disk sectors. They are the only DOS
  services that ignore the logical structure of a disk and work only with
  individual sectors, paying no attention to the locations of files, file
  directories, or the File Allocation Table.

  Interrupts 25H and 26H are similar to the corresponding ROM BIOS disk
  services, except that the sectors are located by a different numbering
  method. With the ROM BIOS services, the sectors are selected by their
  three-dimensional coordinate locations (cylinder, head, and sector),
  whereas with interrupts 25H and 26H, the sectors are selected by their
  sequential logical sector numbers. (DOS's sector-numbering system is
  discussed on page 109.)

  The following BASIC formula converts three-dimensional coordinates used by
  the ROM BIOS to logical sector numbers used by DOS:

  LOGICAL.SECTOR = (SECTOR - 1) + (HEAD * SECTORS.PER.TRACK) +
  (CYLINDER * SECTORS.PER.TRACK * NUMBER.OF.HEADS)

  And here are the formulas for converting logical sector numbers to
  three-dimensional coordinates:

  SECTOR = 1 + LOGICAL.SECTOR MOD SECTORS.PER.TRACK
  HEAD = (LOGICAL.SECTOR \ SECTORS.PER.TRACK) MOD NUMBER.OF.HEADS
  CYLINDER = LOGICAL.SECTOR \ (SECTORS.PER.TRACK * NUMBER.OF.HEADS)

  --------------------------------------------------------------------------
  NOTE:
    Don't forget that the ROM BIOS counts heads and cylinders from 0 but
    counts sectors from 1; DOS logical sectors are numbered from 0.
  --------------------------------------------------------------------------

  To use interrupt 25H or 26H to read or write a block of logical sectors,
  load the necessary parameters into the CPU registers and execute the
  interrupt. The number of sectors is specified in the CX register, the
  starting sector number is specified in DX, and the memory address for data
  transfer is specified in DS:BX. The disk drive is selected by placing a
  number in the AL register: Drive A is 0, drive B is 1, and so on.

  Although ROM BIOS services work with true physical drives, DOS services
  work with logical drive numbers. DOS assumes every computer has at least
  two logical drives. If no physical drive B exists, DOS will simulate it by
  using the one physical drive as either A or B, whichever is needed. You
  can then remap these logical drives by using the DOS ASSIGN command.

  The results of interrupts 25H and 26H are reported in the carry flag (CF)
  and the AL and AH registers. If no error occurred, CF = 0. If an error did
  occur (CF = 1), AL and AH contain the error codes in two somewhat
  redundant groups. The AL codes in Figure 15-2 are based on those used by
  the DOS critical-error handler through interrupt 24H (see page 308), and
  the AH codes in Figure 15-3 are based on the error codes reported by the
  ROM BIOS (see page 201).

  Error Code         Meaning
  Hex    Dec
  --------------------------------------------------------------------------
  00H     0          Write-protect error: attempt to write on protected
                     diskette
  01H     1          Unknown unit: invalid drive number
  02H     2          Drive not ready (e.g. no disk, or door open)
  04H     4          CRC (cyclical redundancy check) error: parity error
  06H     6          Seek error: move to requested cylinder failed
  07H     7          Unknown media: disk format not recognized
  08H     8          Sector not found
  0AH    10          Write error
  0BH    11          Read error
  0CH    12          General, nonspecific error
  0FH    15          Invalid disk change
  --------------------------------------------------------------------------

  Figure 15-2.  The error-code values and meanings returned in the AL
  register following an error in a disk read or write through DOS interrupt
  25H or 26H.

  Error Code
  Hex    Dec         Meaning
  --------------------------------------------------------------------------
  02H      2         Bad address mark: sector ID marking invalid or not
                     found
  03H      3         Write-protect error: attempt to write on protected disk
  04H      4         Bad sector: requested sector not on disk
  08H      8         DMA (direct memory access) failure
  10H     16         Bad CRC: read found invalid parity check of data
  20H     32         Controller failed: disk drive controller malfunction
  40H     64         Bad seek: move to requested track failed
  80H    128         Time out: drive did not respond
  --------------------------------------------------------------------------

  Figure 15-3.  The error-code values and meanings returned in the AH
  register following an error in a disk read or write through DOS interrupt
  25H or 26H.

  Normally, interrupt handlers and other service routines leave the stack
  clean when they exit, returning it to its original size and contents. DOS
  interrupts 25H and 26H deliberately do not clean up the stack. Instead,
  they finish and return to the program with one word left on the stack.
  This word holds the contents of the flag register, showing how the flags
  were set when the program invoked the service. This is purportedly done to
  preserve the program's flag status before the service was used, because
  interrupts 25H and 26H use the flags for their return codes. We think this
  is a silly precaution because any program that needs to preserve the flags
  can simply do what programs normally do when they need something saved:
  PUSH them onto the stack themselves. Any program that uses interrupts 25H
  and 26H should POP the two extra flag-status bytes off the stack after the
  interrupt returns. These bytes can either be placed in the flags register
  with a POPF command (which should be done after testing CF for an error)
  or be discarded by incrementing the stack pointer register by 2 (ADD
  SP,2).

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