home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / tsr / tsrsrc33.zip / EMS.PAS < prev    next >
Pascal/Delphi Source File  |  1992-01-08  |  5KB  |  185 lines

  1. {**************************************************************************
  2. *   EMS - unit of EMS functions                                           *
  3. *   Copyright (c) 1991 Kim Kokkonen, TurboPower Software.                 *
  4. *   May be freely distributed and used but not sold except by permission. *
  5. *                                                                         *
  6. *   Version 3.0 9/24/91                                                   *
  7. *     first release                                                       *
  8. *   Version 3.1 11/4/91                                                   *
  9. *     no change                                                           *
  10. *   Version 3.2 11/22/91                                                  *
  11. *     no change                                                           *
  12. *   Version 3.3 1/8/92                                                    *
  13. *     no change                                                           *
  14. ***************************************************************************}
  15.  
  16. {$R-,S-,I-,V-,B-,F-,A-,E-,N-,G-,X-}
  17.  
  18. unit Ems;
  19.   {-EMS functions needed for MAPMEM, MARKNET, RELNET}
  20.  
  21. interface
  22.  
  23. const
  24.   MaxHandles = 255;
  25.   EmsDevice : string[8] = 'EMMXXXX0';
  26. type
  27.   HandlePageRecord =
  28.   record
  29.     Handle : Word;
  30.     NumPages : Word;
  31.   end;
  32.   PageArray = array[1..MaxHandles] of HandlePageRecord;
  33.   PageArrayPtr = ^PageArray;
  34.  
  35. function EmsPresent : Boolean;
  36.   {-Return true if EMS memory manager is present}
  37.  
  38. function EmsPagesAvailable : LongInt;
  39.   {-Return Total pages in high word, Available pages in low word}
  40.  
  41. function EmsHandles(var PageMap : PageArray) : Word;
  42.   {-Return number of handles allocated and page map}
  43.  
  44. function EmsVersion : Byte;
  45.   {-Return EMM version number}
  46.  
  47. procedure GetHandleName(Handle : Word; var Name : String);
  48.   {-Return name of EMS block, if any}
  49.  
  50. function FreeEms(Handle : Word) : Boolean;
  51.   {-Deallocate EMS handle}
  52.  
  53.   {=========================================================================}
  54.  
  55. implementation
  56.  
  57.   function EMSpresent : Boolean; assembler;
  58.     {-Return true if EMS memory manager is present}
  59.   asm
  60.     mov ax,$3567
  61.     int $21
  62.     mov ax,es
  63.     or ax,bx            {is int $67 nil?}
  64.     jz @AbsentNoClose
  65.     cmp byte ptr es:[bx],$CF  {does int $67 point to iret?}
  66.     je @AbsentNoClose
  67.     mov dx,offset EmsDevice+1
  68.     mov ax,$3D02
  69.     int $21             {can we open EMM device?}
  70.     mov bx,ax
  71.     jc @AbsentNoClose
  72.     mov ax,$4400
  73.     int $21             {can we get its device properties?}
  74.     jc @Absent
  75.     and dx,$80          {does bit 7 = 1?}
  76.     jz @Absent
  77.     mov ax,$4407
  78.     int $21             {device ready for output?}
  79.     jc @Absent
  80.     or al,al
  81.     jz @Absent
  82.     push bx
  83.     mov ah,$30
  84.     int $21
  85.     pop bx
  86.     xchg ah,al
  87.     cmp ax,$030A
  88.     jb @Present
  89.     mov ax,$440A
  90.     int $21             {local device?}
  91.     jc @Present
  92.     and dx,$8000
  93.     jnz @Absent
  94. @Present:
  95.     mov ah,$3E           {close handle}
  96.     int $21
  97.     mov al,1
  98.     jmp @Done
  99. @Absent:
  100.     mov ah,$3E           {close handle}
  101.     int $21
  102. @AbsentNoClose:
  103.     xor ax,ax
  104. @Done:
  105.   end;
  106.  
  107.   function EmsPagesAvailable : LongInt; assembler;
  108.     {-Return Total pages in high word, Available pages in low word}
  109.   asm
  110.     mov ah, $42
  111.     int $67
  112.     or ah,ah
  113.     jnz @error
  114.     mov ax,bx     {available pages now in ax}
  115.     jmp @done
  116. @error:
  117.     xor ax,ax
  118.     mov dx,ax
  119. @done:
  120.   end;
  121.  
  122.   function EmsHandles(var PageMap : PageArray) : Word; assembler;
  123.     {-Return number of handles allocated and page map}
  124.   asm
  125.     mov ah,$4D
  126.     les di,PageMap
  127.     xor bx,bx
  128.     int $67
  129.     or ah,ah
  130.     mov ax,bx
  131.     jz @done
  132.     xor ax,ax
  133. @done:
  134.   end;
  135.  
  136.   function EmsVersion : Byte; assembler;
  137.     {-Return EMM version number}
  138.   asm
  139.     mov ah,$46
  140.     int $67
  141.     or ah,ah
  142.     jz @Done
  143.     xor al,al
  144. @Done:
  145.   end;
  146.  
  147.   procedure GetHandleName(Handle : Word; var Name : String); assembler;
  148.     {-Return name of EMS block, if any}
  149.   asm
  150.     mov dx,Handle
  151.     les di,Name
  152.     mov si,di         {save offset}
  153.     inc di            {point past length byte}
  154.     mov ax,$5300
  155.     int $67
  156.     mov al,0          {assume zero length}
  157.     or ah,ah
  158.     jnz @Done
  159.     mov cx,8
  160.     xor al,al
  161.     cld               {scan for null terminator}
  162.     repne scasb
  163.     mov al,8          {assume all 8 chars significant}
  164.     jne @Done
  165.     sub al,cl
  166.     dec al
  167. @Done:
  168.     mov es:[si],al    {store length byte}
  169.   end;
  170.  
  171.   function FreeEms(Handle : Word) : Boolean; assembler;
  172.     {-Deallocate EMS handle}
  173.   asm
  174.     mov ah,$45
  175.     mov dx,Handle
  176.     int $67
  177.     mov al,0
  178.     or ah,ah
  179.     jnz @Done
  180.     inc al
  181. @Done:
  182.   end;
  183.  
  184. end.
  185.