Board index » delphi » Direct Disk Reading

Direct Disk Reading

Does anyone have any sample source to read directly from a certain
sector on the HD?  Either Pascal, ASM or a mixture of both is fine,
thanks.
 

Re:Direct Disk Reading


In article <315f36f3.16550...@news.bconnex.net>, from cr...@bconnex.net
(Stephen A. Legge), the following was written:

Quote
> Does anyone have any sample source to read directly from a certain
> sector on the HD?  Either Pascal, ASM or a mixture of both is fine,
> thanks.

Try interrupts 25h / 26h. They're not quite easy to use for they're
a bit special. Interested in source code? E-mail me...

   Basti

(Have you seen my new quote line? Dvorak OUI TE at its best!)

--
-----------------------------------------------------------------------
       Bastisoft      101674.2...@compuserve.com

       Fleestedt, Germany
-----------------------------------------------------------------------

Re:Direct Disk Reading


cr...@bconnex.net (Stephen A. Legge) writes:
: Does anyone have any sample source to read directly from a certain
: sector on the HD?  Either Pascal, ASM or a mixture of both is fine,
: thanks.

Try this.. I haven't tested it very extensively yet, but it should do the
trick quite nicely.  Anyone can feel free to use it, just read through it
and figure out what you're doing first.  Don't use the write routine
unless you're sure you know how, I only tested it on a diskette drive, my
hard-drive wasn't worth trying it on until I have a good use for it.
Distribute as you will, but don't charge any money for it.

unit biosdisk;

interface
const
 {drive number codes}
  adrive = $00;
  bdrive = $01;
  cdrive = $80;
  ddrive = $81;
  edrive = $82;
 {disk status codes}
  noerror = 0;
  badcommand = 1;
  badsector = 2;
  writeprotected = 3;
  sectornotfound = 4;
  diskchange = 6;
  invalidmedia = $0C;
  contollererror = $20;
  seekfailure = $40;
  timeout = $80;

type
  tsector = array[0..512] of byte;
  psector = ^tsector;

function diskstatus: byte;
procedure resetdisk(drive:byte);
function getcx(sector,track:word):word;
procedure readsector(drive:byte; sector,track,head:word; dest:psector);
procedure writesector(drive:byte; sector,track,head:word; dest:psector);

implementation
{-----------------------------}
function diskstatus: byte;
begin
  asm
    push ds             {save ds}
    mov ah, 1
    int 13h
    mov @result, al
    pop ds
  end;  {asm}
end;  {diskstatus}
{-----------------------------}
procedure resetdisk(drive: byte);
begin
  asm
    push ds             {save ds}
    xor ah, ah
    mov dl, drive
    int 13h
    pop ds
  end;  {asm}
end;  {resetdisk}
{-----------------------------}
function getcx(sector,track: word): word;
var
  tcx: word;
begin
  tcx:= 0;
  sector:= sector AND NOT $3F;    {set sector bits}
  tcx:= tcx OR sector;

  if (track AND $100) = $100 then {set track bits}
    tcx:= tcx OR $40;
  if (track AND $200) = $200 then
    tcx:= tcx OR $80;
  tcx:= tcx OR (track SHL 8);

  getcx:= tcx;
end;
{-----------------------------}
procedure readsector(drive:byte; sector,track,head:word; dest:psector);
var
        tcx: word;
begin
        tcx:= getcx(sector,track);
        resetdisk(drive);
        asm
                push ds           {save ds}
                mov ah, 2         {BIOS disk read}
                mov al, 1         {read 1 sector}
                mov dl, drive     {from drive}
                mov cx, tcx       {sector & track #}
                mov bx, head      {head # (drop high byte)}
                mov dh, bl
                les bx, dest      {to here}
                int 13h
                pop ds            {restore ds}
         end;  {asm}
end;  {readsector}
{-----------------------------}
procedure writesector(drive:byte; sector,track,head:word; dest:psector);
var
        tcx: word;
begin
        tcx:= getcx(sector,track);
        resetdisk(drive);
        asm
                push ds           {save ds}
                mov ah, 3         {BIOS disk write}
                mov al, 1         {write 1 sector}
                mov dl, drive     {to drive}
                mov cx, tcx       {sector & track #}
                mov bx, head      {head # (drop high byte)}
                mov dh, bl
                les bx, dest      {from here}
                int 13h
                pop ds            {restore ds}
        end;  {asm}
end;  {writesector}
{-----------------------------}
End.  {biosdisk}

Good luck.
-chris

Re:Direct Disk Reading


In article <315f36f3.16550...@news.bconnex.net>
           cr...@bconnex.net "Stephen A. Legge" writes:

Quote
> Does anyone have any sample source to read directly from a certain
> sector on the HD?  Either Pascal, ASM or a mixture of both is fine,
> thanks.

There was a whole tutorial about this on the net once.. I have it here..
Email me if you want me to send or post it. It's only one txt file.

Chz :)

--
Peter Cooper

Re:Direct Disk Reading


In <315f36f3.16550...@news.bconnex.net>, cr...@bconnex.net (Stephen A. Legge) writes:

Quote
>Does anyone have any sample source to read directly from a certain
>sector on the HD?  Either Pascal, ASM or a mixture of both is fine,
>thanks.

Do you mean physical sector or logical sector (i.e. DOS or BIOS?).
Well, in both cases you can find the answer in Ralf Brown Interrupt List (can
be found in msdos/info/inter*.zip on SIMTEL mirrors). If you need to read
a physical sector, then it's on interrupt 13h, otherwise it's interrupt 21h (DOS
services; function 26h? - don't remember now) - if you'll use the DOS version,
be sure to pop one word left on the stack after the function call!!!

                                 Tomas Hajny, XHaj...@mbox.vol.cz on Internet

Other Threads