Solved

need memory-unit(xms or ems)

Posted on 1998-11-28
3
293 Views
Last Modified: 2010-05-18
Where can i find memory-unit(xms or ems or else)?
0
Comment
Question by:mitya83
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Positioning and setting color of buttons on a Firemonkey form 12 2,203
Threads Delphi Programs 2 1,629
websites monitor c++ or delphi 9 452
calling Tcolordialog in dll make the form disappear 8 125
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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