Solved

need memory-unit(xms or ems)

Posted on 1998-11-28
3
296 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Disable ctrl+alt+del 7 696
Rave Reports - Adding a Data Band 1 1,026
Convert date 6 409
TVirtualStringTree  search using TEdit 7 167
Changing a few Outlook Options can help keep you organized!
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

739 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