Solved

need memory-unit(xms or ems)

Posted on 1998-11-28
3
285 Views
Last Modified: 2010-05-18
Where can i find memory-unit(xms or ems or else)?
0
Comment
Question by:mitya83
3 Comments
 
LVL 4

Accepted Solution

by:
jack_p50 earned 0 total points
ID: 1216229
Greets, here's unit I got somewhere. It's easy to use, so don't ask, just grab it :


Unit xms;

  interface
  var
    XMSerrorcode : byte;    { Error Code - Defined in XMS Spec }
    XMSaddr      : Pointer;  { Entry Point for HIMEM.SYS Driver }
    XMSswap      : pointer;

  Function XMSinstalled:boolean;
  Function XMSgetfreemem:word;
  Function XMSlargestblock:word;
  Function XMSallocate(KBSize:word):word;
  Function XMSrelease(handle:word): Boolean;
  Function XMSMoveDataTo(SourceAddr: Pointer; NumBytes: LongInt;
             XMSHandle: Word; XMSOffset: LongInt): Boolean;
  Function XMSGetDataFrom(XMSHandle: Word; XMSOffset: LongInt;
             NumBytes: LongInt; LowMemAddr: Pointer): Boolean;
  Function XMS2swap(handle,size:word):boolean;
  Function swap2XMS(var handle:word;size:word):boolean;

  implementation

    type
      XMSmovestruct=record
        movelen:longint;   { length of block to move in bytes }
        case integer of
          { Case 0 Variant for Low Memory to XMS }
          0: (SHandle   : Word;      { source handle = 0
                                       for conventional memory }
              SPtr      : pointer;   { source address }
              XMSHdl    : Word;      { XMS destination handle }
              XMSOffset : LongInt);  { 32 bit XMS offset }
          { Case 1 Variant for XMS to Low Memory }
          1: (XMSH      : Word;      { XMS source handle }
              XMSOfs    : LongInt;   { starting offset in XMS}
              DHandle   : Word;      { 0 when conventional memory
                                       destination }
              DPtr      : pointer);  { address in conventional memory }
        END;

    VAR moveparms : XMSMoveStruct;   { structure for moving to and
                                       from XMS }

    {**************************************************************}
    { XMSInstalled - Returns true IF Extended Memory Driver     }
    {                   HIMEM.SYS Loaded                           }
    {                 - Sets Entry Point Address - XMSAddr         }
    {**************************************************************}
    FUNCTION XMSInstalled: Boolean;
    CONST
      himemseg: Word = 0;
      himemofs: Word = 0;
    BEGIN
      XMSErrorCode := 0;
      ASM
        mov ax,4300h      { Check to see IF HIMEM.SYS installed }
        int 2fh
        cmp al,80h        { Returns AL = 80H IF installed }
        jne @1
        mov ax,4310h      { Now get the entry point }
        int 2fh
        mov himemofs,bx
        mov himemseg,es
      @1:
      END;
      XMSinstalled:=(himemseg <> 0);
      XMSaddr:=ptr(himemseg,himemofs);
    END;

    {**************************************************************}
    { XMSgetfreemem - Returns Total XMS Memory Available }
    {**************************************************************}
    FUNCTION XMSgetfreemem: Word;
    BEGIN
      XMSerrorcode := 0;
      XMSgetfreemem := 0;
      IF XMSAddr = nil THEN        { Check IF HIMEM.SYS Loaded }
        IF NOT XMSinstalled THEN exit;
      ASM
        mov  ah,8
        call XMSAddr
        or   ax,ax
        jnz  @1
        mov  XMSErrorCode,bl  { Set Error Code }
        xor  dx,dx
        @1:
        mov  @Result,dx       { DX = total free extended memory }
      END;
    END;

    {**************************************************************}
    { XMSLargestBlock - Returns Largest Contiguous        }
    {                            XMS Block Available               }
    {**************************************************************}
    FUNCTION XMSLargestBlock: Word;
    BEGIN
      XMSErrorCode := 0;
      XMSLargestBlock := 0;
      IF XMSAddr = nil THEN         { Check IF HIMEM.SYS Loaded }
        IF NOT XMSinstalled THEN exit;
      ASM
        mov  ah,8
        call XMSAddr
        or   ax,ax
        jnz  @1
        mov  XMSErrorCode,bl { On Error, Set Error Code }
        @1:
        mov  @Result,ax      { AX=largest free XMS block }
      END;
    END;

    {***************************************************************}
    { XMSAllocate - Allocates Block of XMS Memory              }
    {                  - Input - KBSize: No of Kilobytes requested  }
    {                  - Returns Handle for memory IF successful    }
    {***************************************************************}
    FUNCTION XMSAllocate(KBSize: Word): Word;
    BEGIN
      XMSAllocate := 0;
      XMSErrorCode := 0;
      IF XMSAddr = nil THEN { Check IF HIMEM.SYS Loaded }
        IF NOT XMSinstalled THEN exit;
      ASM
        mov  ah,9
        mov  dx,KBSize
        call XMSAddr
        or   ax,ax
        jnz  @1
        mov  XMSErrorCode,bl { On Error, Set Error Code }
        xor  dx,dx
        @1:
        mov  @Result,dx      { DX = handle for extended memory }
      END;
    END;

    {**************************************************************}
    { XMSRelease - Releases Block of XMS Memory               }
    {                 - Input:   Handle identifying memory to be   }
    {                   released                                   }
    {                 - Returns  true IF successful                }
    {**************************************************************}
    FUNCTION XMSRelease(Handle: Word): Boolean;
    VAR OK : Word;
    BEGIN
      XMSErrorCode := 0;
      XMSRelease := false;
      IF XMSAddr = nil THEN   { Check IF HIMEM.SYS Loaded }
        IF NOT XMSinstalled THEN exit;
      ASM
        mov  ah,0Ah
        mov  dx,Handle
        call XMSAddr
        or   ax,ax
        jnz  @1
        mov  XMSErrorCode,bl  { On Error, Set Error Code }
        @1:
        mov  OK,ax
      END;
      XMSRelease := (OK <> 0);
    END;

    {**************************************************************}
    { XMSMoveDataTo - Moves Block of Data from Conventional        }
    {                 Memory to XMS Memory                         }
    {               - Data Must have been previously allocated     }
    {               - Input - SourceAddr : address of data in      }
    {                                      conventional memory     }
    {                       - NumBytes   : number of bytes to move }
    {                       - XMSHandle  : handle of XMS block     }
    {                       - XMSOffset  : 32 bit destination      }
    {                                      offset in XMS block     }
    {               - Returns true IF completed successfully       }
    {**************************************************************}
    FUNCTION XMSMoveDataTo(SourceAddr: Pointer; NumBytes: LongInt;
               XMSHandle: Word; XMSOffset: LongInt): Boolean;
    VAR Status    : Word;
    BEGIN
      XMSErrorCode := 0;
      XMSMoveDataTo := false;
      IF XMSAddr = nil THEN  { Check IF HIMEM.SYS Loaded }
        IF NOT XMSinstalled THEN exit;
      MoveParms.MoveLen   := NumBytes;
      MoveParms.SHandle   := 0;         { Source Handle=0 For
                                          Conventional Memory}
      MoveParms.SPtr      := SourceAddr;
      MoveParms.XMSHdl    := XMSHandle;
      MoveParms.XMSOffset := XMSOffset;
      ASM
        mov  ah,0Bh
        mov  si,offset MoveParms
        call XMSAddr
        mov  Status,ax       { Completion Status }
        or   ax,ax
        jnz  @1
        mov  XMSErrorCode,bl { Save Error Code }
        @1:
      END;
      XMSMoveDataTo := (Status <> 0);
    END;

    {**************************************************************}
    { XMSGetDataFrom - Moves Block From XMS to Conventional Memory }
    {                - Data Must have been previously allocated    }
    {                  and moved to XMS                            }
    {               - Input - XMSHandle  : handle of source        }
    {                                      XMS block               }
    {                       - XMSOffset  : 32 bit source offset    }
    {                                      in XMS block            }
    {                       - NumBytes   : number of bytes to move }
    {                       - LowMemAddr : destination addr in     }
    {                                      conventional memory     }
    {               - Returns true IF completed successfully       }
    {**************************************************************}
    FUNCTION XMSGetDataFrom(XMSHandle: Word; XMSOffset: LongInt;
               NumBytes: LongInt; LowMemAddr: Pointer): Boolean;
    VAR Status    : Word;
    BEGIN
      XMSErrorCode := 0;
      XMSGetDataFrom := false;
      IF XMSAddr = nil THEN   { Check IF HIMEM.SYS Loaded }
        IF NOT XMSinstalled THEN exit;
      MoveParms.MoveLen := NumBytes;  { Set-Up Structure to Pass }
      MoveParms.XMSh    := XMSHandle;
      MoveParms.XMSOfs  := XMSOffset;
      MoveParms.DHandle := 0;         { Dest Handle=0 For
                                        Conventional Memory}
      MoveParms.DPtr    := LowMemAddr;
      ASM
        mov  ah,0Bh
        mov  si,offset MoveParms
        call XMSAddr
        mov  Status,ax       { Completion Status }
        or   ax,ax
        jnz  @1
        mov  XMSErrorCode,bl { Set Error Code }
        @1:
      END;
      XMSGetDataFrom := (Status <> 0);
    END;

    Function xms2swap;
      begin
        getmem(xmsswap,size);
        xms2swap:=xmsgetdatafrom(handle,0,size,xmsswap);
      end;

    Function swap2xms;
      begin
        handle:=xmsallocate((size div 1024)+1);
        if xmserrorcode<>0 then
          begin
            swap2xms:=false;
            exit;
          end;
        swap2xms:=xmsmovedatato(xmsswap,size,handle,0);
      end;

    BEGIN
      XMSAddr      := nil; { Initialize XMSAddr }
      XMSErrorCode := 0;
      XMSinstalled;
    END.
0
 

Author Comment

by:mitya83
ID: 1216230
Wow! This is exactly what I wanted. Thanx
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question