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