home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / _LIB_ / XMS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-07-18  |  4.7 KB  |  244 lines

  1. {$F+}
  2. {$G+}
  3.  
  4. Unit XMS;
  5.  
  6. {
  7.   Extended memory (via XMS) handling routines
  8.   by Maple Leaf, 1996
  9. }
  10.  
  11. Interface
  12.  
  13. Type
  14.   EMM_Struct = record
  15.                  Count            : LongInt;
  16.                  SourceHandle     : Word;
  17.                  OffsetIntoSource : LongInt;
  18.                  DestHandle       : Word;
  19.                  OffsetIntoDest   : LongInt;
  20.                end;
  21.  
  22. Var
  23.   XMS_Driver_Address : Pointer;
  24.   XMS_Installed      : Boolean;
  25.   XMS_Error          : byte;
  26.   XMS_Move           : EMM_Struct;
  27.   XMS_Total,
  28.   XMS_Largest        : word;
  29.  
  30. Procedure CheckXMSInstall;                           far;
  31. Function  XMSVersion : word;                         far;
  32. Procedure AllocXMS ( Var Handle:word; Size:word );   far;
  33. Procedure FreeXMS ( Handle:Word );                   far;
  34. Procedure LockXMS ( Handle:word; Size:word );        far;
  35. Procedure UnLockXMS ( Handle:word; Size:word );      far;
  36. Procedure MoveXMS ( Var EmmStruc:EMM_Struct );       far;
  37. Procedure LocalEnableA20;                            far;
  38. Procedure LocalDisableA20;                           far;
  39. Procedure CopyToXMS    ( Var Source; Handle:Word; Offs:LongInt; Count:LongInt ); far;
  40. Procedure CopyFromXMS  ( Handle:Word; Offs:LongInt; Var Dest; Count:LongInt ); far;
  41. Procedure CopyXMStoXMS ( SHandle:Word; SOffs:LongInt; DHandle:Word; DOffs:LongInt; Count:LongInt ); far;
  42. Procedure QueryXMS;                                  far;
  43. Function  CountXMS : Word;                           far;
  44.  
  45. Implementation
  46.  
  47. Procedure CheckXMSInstall;assembler;
  48. asm
  49.   push es
  50.   mov ax,4300h
  51.   int 2fh
  52.   cmp al,80h
  53.   je @Inst
  54.   mov byte ptr XMS_Installed,0
  55.   jmp @Outta
  56. @Inst:
  57.   mov byte ptr XMS_Installed,1
  58.   { Get driver address }
  59.   mov ax,4310h
  60.   int 2fh
  61.   mov word ptr XMS_Driver_Address,bx
  62.   mov word ptr XMS_Driver_Address[2],es
  63. @Outta:
  64.   pop es
  65. end;
  66.  
  67. Function XMSVersion;Assembler;
  68. asm
  69.   mov ah,0
  70.   call dword ptr XMS_Driver_Address
  71.   { returns in AX version }
  72. end;
  73.  
  74. Procedure AllocXMS;Assembler;
  75. asm
  76.   mov dx,Size
  77.   mov ah,9
  78.   call dword ptr XMS_Driver_Address
  79.   cmp ax,1
  80.   jne @Failure
  81.   push bx
  82.   les bx,dword ptr Handle
  83.   mov word ptr es:[bx],dx
  84.   pop bx
  85.   mov XMS_Error,0
  86.   jmp @Outta
  87. @Failure:
  88.   mov XMS_Error,bl
  89. @Outta:
  90. end;
  91.  
  92. Procedure QueryXMS;Assembler;
  93. asm
  94.   mov ah,8
  95.   xor bx,bx
  96.   call dword ptr XMS_Driver_Address
  97.   cmp ax,1
  98.   jne @Failure
  99.   mov word ptr XMS_Total,dx
  100.   mov word ptr XMS_Largest,ax
  101.   mov XMS_Error,0
  102.   jmp @Outta
  103. @Failure:
  104.   mov XMS_Error,bl
  105. @Outta:
  106. end;
  107.  
  108. Procedure FreeXMS;Assembler;
  109. asm
  110.   mov ah,10
  111.   mov dx,Handle
  112.   call dword ptr XMS_Driver_Address
  113.   cmp ax,1
  114.   jne @Failure
  115.   mov XMS_Error,0
  116.   jmp @Outta
  117. @Failure:
  118.   mov XMS_Error,bl
  119. @Outta:
  120. end;
  121.  
  122. Procedure LockXMS;Assembler;
  123. asm
  124.   mov ah,12
  125.   mov dx,Handle
  126.   call dword ptr XMS_Driver_Address
  127.   cmp ax,1
  128.   jne @Failure
  129.   mov XMS_Error,0
  130.   jmp @Outta
  131. @Failure:
  132.   mov XMS_Error,bl
  133. @Outta:
  134. end;
  135.  
  136. Procedure UnLockXMS;Assembler;
  137. asm
  138.   mov ah,13
  139.   mov dx,Handle
  140.   call dword ptr XMS_Driver_Address
  141.   cmp ax,1
  142.   jne @Failure
  143.   mov XMS_Error,0
  144.   jmp @Outta
  145. @Failure:
  146.   mov XMS_Error,bl
  147. @Outta:
  148. end;
  149.  
  150. Procedure MoveXMS;Assembler;
  151. asm
  152.   push ds
  153.   mov ah,11
  154.   lds si,EmmStruc
  155.   call dword ptr XMS_Driver_Address
  156.   cmp ax,1
  157.   jne @Failure
  158.   mov XMS_Error,0
  159.   jmp @Outta
  160. @Failure:
  161.   mov XMS_Error,bl
  162. @Outta:
  163.   pop ds
  164. end;
  165.  
  166. Procedure LocalEnableA20;Assembler;
  167. asm
  168.   mov ah,5
  169.   call dword ptr XMS_Driver_Address
  170.   cmp ax,1
  171.   jne @Failure
  172.   mov XMS_Error,0
  173.   jmp @Outta
  174. @Failure:
  175.   mov XMS_Error,bl
  176. @Outta:
  177. end;
  178.  
  179. Procedure LocalDisableA20;Assembler;
  180. asm
  181.   mov ah,6
  182.   call dword ptr XMS_Driver_Address
  183.   cmp ax,1
  184.   jne @Failure
  185.   mov XMS_Error,0
  186.   jmp @Outta
  187. @Failure:
  188.   mov XMS_Error,bl
  189. @Outta:
  190. end;
  191.  
  192. Procedure CopyToXMS;
  193. Var P:Pointer;
  194. begin
  195.   P:=@Source;
  196.   XMS_Move.Count:=Count;
  197.   XMS_Move.SourceHandle:=0;
  198.   Move(p,XMS_Move.OffsetIntoSource,4);
  199.   XMS_Move.DestHandle:=Handle;
  200.   XMS_Move.OffsetIntoDest:=Offs;
  201.   MoveXMS(XMS_Move);
  202. end;
  203.  
  204. Procedure CopyFromXMS;
  205. Var P:Pointer;
  206. begin
  207.   P:=@Dest;
  208.   XMS_Move.Count:=Count;
  209.   XMS_Move.SourceHandle:=Handle;
  210.   XMS_Move.OffsetIntoSource:=Offs;
  211.   XMS_Move.DestHandle:=0;
  212.   Move(p,XMS_Move.OffsetIntoDest,4);
  213.   MoveXMS(XMS_Move);
  214. end;
  215.  
  216. Procedure CopyXMStoXMS;
  217. begin
  218.   XMS_Move.Count:=Count;
  219.   XMS_Move.SourceHandle:=SHandle;
  220.   XMS_Move.OffsetIntoSource:=SOffs;
  221.   XMS_Move.DestHandle:=DHandle;
  222.   XMS_Move.OffsetIntoDest:=DOffs;
  223.   MoveXMS(XMS_Move);
  224. end;
  225.  
  226. Function  CountXMS : Word;
  227. var k,hand:word;
  228. begin
  229.   k:=1; XMS_Error:=0;
  230.   AllocXMS(hand,k);
  231.   while XMS_Error=0 do begin
  232.     FreeXMS(hand);
  233.     inc(k);
  234.     AllocXMS(hand,k);
  235.   end;
  236.   dec(k);
  237.   CountXMS:=k;
  238. end;
  239.  
  240. begin
  241.   XMS_Driver_Address:=Nil;
  242.   XMS_Installed:=False;
  243.   CheckXMSInstall;
  244. end.