⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitread.pas

📁 在delphi中实现windows核心编程.原书光盘代码核心编程.原书光盘代码
💻 PAS
字号:
unit Unitread;

interface

uses
  SysUtils, WinTypes,WINPROCS, Messages, Classes, Graphics, Controls,
  StdCtrls, Dialogs;

type
  TRegs=packed record
     edi, esi, ebp, RESERVED, ebx, edx, ecx, eax:Longint;
     wFlags, es, ds, fs, gs, ip, cs, sp, ss:WORD;
  end;
  PRegs=^TRegs;
  TInt13Reg = packed record
     SecCount:byte; {AL}
     SecStart:byte; {CL的0-5bit,表示范围是:0-63}
     Cylinder:word; {CH和CL的6-7bit,表示范围是:0-1023}
     Head:byte;  {DH}
     drv:byte;   {DL}
     BufferSegment,BufferOffset:word;
  end;
  PInt13Reg=^TInt13Reg;

  function WJSReadDisk16(var Int13Reg:TInt13Reg):boolean;export;
  function WJSWriteDisk16(var Int13Reg:TInt13Reg):boolean;export;

implementation


function RM_Int (bIntNum:byte;var RegStruct:TRegs):boolean;
var
   r:boolean;
label END1;
begin
   r:=false;
   asm
         pusha
         push es
         mov  ax, 0300h         { DPMI Simulate Real Mode Int }
         mov  bl, bIntNum       { Number of the interrupt to simulate }
         mov  bh, 01h           { Bit 0 = 1; all other bits must be 0 }
         xor  cx, cx            { No words to copy }
         les  di, RegStruct
         int  31h                   { Call DPMI }
         jc   END1                  { CF set if error occurred }
         mov  r, TRUE
   END1:
         pop es
         popa
   end;
   result:=r;
end;

  function WJSReadDisk16(var Int13Reg:TInt13Reg):boolean;
  var
     callStruct:TRegs;
     Buffer_Bak:longint;
     Buffer_WIN_SEG,Buffer_DOS_SEG:word;
     Buffer_WIN:Pchar;
  begin
     if (Int13Reg.Cylinder>$3FF)or(Int13Reg.SecStart>$3F)or(Int13Reg.SecStart<1)then
     begin
        result:=false;
        exit;
     end;
     fillchar(callStruct,sizeof(callstruct),0);

     Buffer_Bak:=GlobalDosAlloc(512 * Int13Reg.SecCount);
     Buffer_WIN_SEG:=LOWORD(Buffer_Bak);
     Buffer_DOS_SEG:=HIWORD(Buffer_Bak);
     Buffer_WIN:=ptr(Buffer_WIN_SEG,0);

     callStruct.eax := $0200 + Int13Reg.SecCount;
     callStruct.ebx := 0;
     callStruct.ecx := (Int13Reg.Cylinder and $FF)*$100 +
                       ((Int13Reg.Cylinder shr 8) shl 6) + Int13Reg.SecStart;
     callStruct.edx := Int13Reg.Head * $100 + Int13Reg.drv;
     callStruct.es  := Buffer_DOS_SEG;
     result := RM_Int ($13, callStruct) and (callstruct.wflags and 1<>1);
     if result then
        move( Buffer_WIN^ , ptr(Int13Reg.BufferSegment,Int13Reg.BufferOffset)^ , 512 * Int13Reg.SecCount);
     GlobalDosFree (Buffer_WIN_SEG);
  end;

  function WJSWriteDisk16(var Int13Reg:TInt13Reg):boolean;
  var
     callStruct:TRegs;
     Buffer_Bak:longint;
     Buffer_WIN_SEG,Buffer_DOS_SEG:word;
     Buffer_WIN:Pchar;
  begin
     if (Int13Reg.Cylinder>$3FF)or(Int13Reg.SecStart>$3F)or(Int13Reg.SecStart<1)then
     begin
        result:=false;
        exit;
     end;
     fillchar(callStruct,sizeof(callstruct),0);

     Buffer_Bak:=GlobalDosAlloc(512 * Int13Reg.SecCount);
     Buffer_WIN_SEG:=LOWORD(Buffer_Bak);
     Buffer_DOS_SEG:=HIWORD(Buffer_Bak);
     Buffer_WIN:=ptr(Buffer_WIN_SEG,0);
     move(ptr(Int13Reg.BufferSegment,Int13Reg.BufferOffset)^, Buffer_WIN^, 512 * Int13Reg.SecCount);

     callStruct.eax := $0300 + Int13Reg.SecCount;
     callStruct.ebx := 0;
     callStruct.ecx := (Int13Reg.Cylinder and $FF)*$100 +
                       ((Int13Reg.Cylinder shr 8) shl 6) + Int13Reg.SecStart;
     callStruct.edx := Int13Reg.Head * $100 + Int13Reg.drv;
     callStruct.es  := Buffer_DOS_SEG;
     result := RM_Int ($13, callStruct) and (callstruct.wflags and 1<>1);
     GlobalDosFree (Buffer_WIN_SEG);
  end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -