[comp.lang.pascal] Help me with absolute disk accesses using Turbo

ajayshah@aludra.usc.edu (Ajay Shah) (08/26/90)

I keep getting weird errors while trying to read in a floppy 
while writing a diskcopy-type program.  It reports AH = 4 (sector not
found) or AH = 6 (diskette removed).  What does the AH = 6 mean?  Any
ideas what is going on?

const  {Hardcoded 3.5" HD floppy}
     MaxSides = 2;
     MaxTracks = 80;
     MaxSectors = 18;
     BytesPerSector = 512;
     BytesPerChunk = BytesPerSector*MaxSectors;

type
    ChunkType : array[1..BytesPerChunk] of byte;

     procedure BIOSRead(side, track, NumSectors : integer;
                        var chunk:ChunkType);
     var
        r : Registers;

     begin
          with r do
          begin
               ah := 2;              {read function}
               al := NumSectors;     {how many sectors?}
               ch := track-1;        {track number}
               cl := 1;              {sector number}
               dh := side-1;         {"head number"}
               dl := 0;              {drive number}

               es := seg(chunk);
               bx := ofs(chunk);     {es:bx pointer to buffer}
          end;
          intr($13, r);
          if r.ah <> 0 then
          begin
               writeln('Disk read failed.');
               writeln('AH = ', r.ah);
               halt(1);
          end;
          if r.al <> NumSectors then
          begin
               writeln('Not all requested sectors read.');
               halt(1)
          end;
     end;

var
   chunk : ChunkType;
   side, track, sector : integer;
   r : Registers;

begin
     r.ah := 0;
     intr($13, r); {BIOS reset; don't know if it's essential.}

     for side := 1 to MaxSides do
         for track := 1 to MaxTracks do
         begin
              gotoxy(1, wherey); clreol;
              write('Side = ', side, ' Track = ', track);
              BIOSRead(side, track, MaxSectors, chunk);
         end;
end.

-- 
_______________________________________________________________________________
Ajay Shah, (213)747-9991, ajayshah@usc.edu
                              The more things change, the more they stay insane.
_______________________________________________________________________________