Solved

need memory-unit(xms or ems)

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now