home *** CD-ROM | disk | FTP | other *** search
- XMS (eXtended Memory Specification) Unit For Turbo Pascal 6.0
- Version 1.0
- Written by Yuval Tal
- 04-Mar-91
-
- This program may be freely distributed for non-commercial, non-business,
- and non-governmental uses, provided this notice is attached with it. My
- only request is that if you plan to use it regularly, let me know of know
- about it through e-mail or postal mail, so that I have an idea of how useful
- this program is (if you will add some cash to that letter it would be nice,
- ofcourse :-)). Also, if you have any problems, suggestions etc' please let
- me know.
-
- InterNet:
- nyyuval@weizmann.weizmann.ac.il
- or
- yuvalt@wisdocs.weizmann.ac.il
-
- Home address:
- 13 Glazer st.
- Rehovot, 76283
- Israel
-
- Introduction
- ------------
- The primitive method of accessing the extended memory is by using the AT's
- BIOS interrupt 15h. These methods have several weaknesses which I will not
- describe here. At 1988 Microsoft, Intel, AST Research and Lotus Corp. made
- a more sophisticated use of extended memory under MS-DOS - eXtended Memory
- Specification (XMS). The XMS defines software interface for 80286, 80386
- and 80486 based PCs that allow real-mode application to use extended memory
- (EMB) and some areas of conventional memory which MS-DOS does not manage
- (UMB and HMA). Here is a figure which descirbes the memory:
-
- ┌─────────────────┐ 0K \
- │ │ |
- │ Base Memory │ |
- │ │ | Conventional Memory
- │ │ |
- ├─────────────────┤ 640K |
- │ Upper Memory │ |
- │ Blocks (UMB) │ /
- ├─────────────────┤ 1024K (1MB)
- │ High Memory │ \
- │ Area (HMA) │ |
- ├─────────────────┤ 1088K |
- │ │ |
- │ │ |
- . . |
- . . | Extended Memory
- . Extended Memory . |
- │ Blocks (EMB) │ |
- │ │ |
- │ │ |
- │ │ |
- │ │ |
- │ │ /
- └─────────────────┘ 16384K (16MB)
-
- XMS defines function calls that allocate, release, resize memory blocks.
- The XMS also provides some control over the CPU's address line A20 which
- must be enabled inorder to read or write extended memory. An installable
- device driver that implements the XMS is called XMM (eXtended Memory Manager).
- The two most commonly used device drivers are:
-
- 1. The one supplied by MicroSoft (HIMEM.SYS).
- 2. Quarterdeck's Extended Memory Manager (QEMM.SYS).
-
- Using the XMS Unit you are able to call all the XMS functions from Turbo
- Pascal without having to worry about assembly or anything else. Here is a
- short and simple example of the XMS unit which copies the numbers 1 to 9 to
- the extended memory and then reads them from there:
-
- Program XMSExample;
-
- Uses
- XMS;
-
- Const
- Numbers: Array [0..9] Of Byte = (0,1,2,3,4,5,6,7,8,9);
-
- Var
- Handler: Word;
-
- Begin
- Handler:=EMBGetMem(1); {Allocate 1K from the extended memory}
- MoveToEMB(Numbers,Handler,10); {Move from conventional memory to}
- {allocated extended memory}
- MoveFromEMB(Handler,Numbers,10); {Move from extended memory to}
- {conventional memory}
- EMBFreeMem(Handler); {Release extended memory}
- End.
-
- This example didn't do much it just demonstrated the ease of the XMS unit.
-
- Procedures/Functions
- --------------------
- XMS comes with the source code so it is very easy to understand how the
- interface withe the XMM is done. The source code should be compiled on
- Turbo Pascal 6.0 since it uses the ASM command. Here is a list of all
- the procedures/function with the XMS unit contains:
-
- +-------------------+
- | General functions |
- +-------------------+--------------------------------------------------------
-
- Function XMMPresent: Boolean;
-
- This function returns True is the extended memory manager device driver
- is installed in memory and active. True if installed, false if not installed.
-
- -----------------------------------------------------------------------------
-
- Function XMSErrorString(Error: Byte): String;
-
- This functions translated the error code which is returned by all the
- procedures/functions in the unit from a number to a string. The error code is
- written to the global variable XMSError (byte). If XMSError is equal to 0
- than no error was encountered.
-
- -----------------------------------------------------------------------------
-
- Function XMSMemAvail: Word;
-
- This function returns the total free extended memory in kilo-bytes.
-
- -----------------------------------------------------------------------------
-
- Function XMSMaxAvail: Word;
-
- This function returns the largest free extended memory block in kilo-bytes.
-
- -----------------------------------------------------------------------------
-
- Function GetXMMVersion: Word;
-
- This function returns the version of the extended memory manger device driver
- version. If the result is 500 then the version is 5.00.
-
- -----------------------------------------------------------------------------
-
- Function GetXMSVersion: Word;
-
- This function returns the version of the extended memory specifications
- version. If the result is 200 then the version is 2.00.
-
- +------------------------------------------------+
- | Extended memory blocks (EMB) related functions |
- +------------------------------------------------+--------------------------
-
- Function EMBGetMem(Size: Word): Word;
-
- This function allocated extended memory and returns a handler which is used
- by the other EMB commands to refer to this block. Size defines the size of
- the requested block in kilo-bytes.
-
- -----------------------------------------------------------------------------
-
- Procedure EMBFreeMem(Handle: Word);
-
- This procedure releases allocated extended memory. Handle is a handle number
- which was given by EMBGetMem. Note: If a program fails to release its
- extended memory before it terminates, the memory becmoes unavailable to other
- programs until the system is restarted. Blocks may not be released while they
- are locked.
-
- -----------------------------------------------------------------------------
-
- Procedure EMBResize(Handle, Size: Word);
-
- This procedure changes the size of a block. Handle is a handle number which
- was given by EMBGetMem. Size is the new size of the block. Blocks may not be
- resized while they are locked.
-
- -----------------------------------------------------------------------------
-
- Procedure MoveToEMB(Var Source; Handle: Word; BlockLength: LongInt);
-
- This procedure moves data from the conventional memory to the extended
- memory. Source is a non-typed variable so any kind of data can be written
- there. Handle is a handle number given by EMBGetMem. BlockLength is the
- number of byes which should be moved. The state of the A20 line is preserved.
-
- -----------------------------------------------------------------------------
-
- Procedure MoveFromEMB(Handle: Word; Var Dest; BlockLength: LongInt);
-
- This procedure moves data from the extended memory to the conventional
- memory. Dest is a non-typed variable so any kind of data can be written
- there. Handle is a handle number given by EMBGetMem. BlockLength is the
- number of byes which should be moved. The state of the A20 line is preserved.
-
- -----------------------------------------------------------------------------
-
- Function GetAvailEMBHandles: Byte;
-
- This function returns the number of free handlers which are available.
-
- -----------------------------------------------------------------------------
-
- Function GetEMBLock(Handle: Word): Byte;
-
- This function returns the lock count of a specified EMB. Handle is a handle
- number given by EMBGetMem. If the function returns 0 it means that the block
- is not locked.
-
- -----------------------------------------------------------------------------
-
- Function GetEMBSize(Handle: Word): Word;
-
- This function returns the size of a specified EMB. Handle is a handle number
- given by EMBGetMem. The result is the size of the block in kilo-bytes.
-
- -----------------------------------------------------------------------------
-
- Function LockEMB(Handle: Word): LongInt;
-
- This function locks a specified EMB. This fucntion is intended for use by
- programs which enable the A20 line and the access extended memory directly.
- The result is a 32-bit linear address of the locked block. Handle is a handle
- number given by EMBGetMem.
-
- -----------------------------------------------------------------------------
-
- Procedure UnlockEMB(Handle: Word);
-
- This procedure unlocks previously locked blocks (by LockEMB). After the EMB
- is unlocked the 32-bit linear address returned by LockEMB becomes invalid and
- should not be used. Handle is a handle number given by EMBGetMem.
-
- +---------------------------------------------+
- | Upper memory blocks (UMB) related functions |
- +---------------------------------------------+------------------------------
-
- Function UMBGetMem(Size: Word; Var Segment: Word): Word;
-
- This function allocates upper memory blocks. Size is the size of the block
- in paragraphs. Segment is retured by this function and it contains the
- segment base of the allocated block. The result of this function is the
- actual block size in paragraphs. In case of an error the result will be the
- size of the largest available block in paragraphs.
-
- -----------------------------------------------------------------------------
-
- Procedure UMBFreeMem(Segment: Word);
-
- This procedure releases the memory that was allocated by UMBGetMem. Segment
- should contains the segment base of the block which should be released.
-
- +--------------------------------------------+
- | High memory blocks (HMA) related functions |
- +--------------------------------------------+-------------------------------
-
- Procedure HMAGetMem(Size: Word);
-
- This function allocates high memory area (HMA). Size contains the the bytes
- which are needed. The maximum HMA allocation is 65520 bytes. The base address
- of the HMA is FFFF:0010h. If an application fails to release the HMA before it
- terminates, the HMA becmoes unavailable to the other programs until the
- system is restarted.
-
- -----------------------------------------------------------------------------
-
- Procedure HMAFreeMem;
-
- This procedure releases the high memory area (HMA).
-
- -----------------------------------------------------------------------------
-
- Function GetHMA: Boolean;
-
- This function obtains the status of the high memory area (HMA). If the result
- is true, HMA exists. If the result is false no HMA exists.
-
- +-----------------------+
- | A20 related functions |
- +-----------------------+----------------------------------------------------
-
- Function GetA20Status: Boolean;
-
- This function returns the status of the A20 address line. If the result is
- true then the A20 line is enabled. If false, it is disabled.
-
- -----------------------------------------------------------------------------
-
- Procedure EnableLocalA20;
-
- This procedure enables the A20 line and should only be used by programs that
- have successfully allocated the HMA. The A20 line should be disabled before
- the program releases control of the system.
-
- -----------------------------------------------------------------------------
-
- Procedure EnableGlobalA20;
-
- This procedure disables the A20 line and should only be used by programs that
- have successfully allocated the HMA.
-
- -----------------------------------------------------------------------------
-
- Procedure EnableLocalA20;
-
- This procedure enables the A20 line and should only be used by programs that
- do not own the HMA. The A20 line should be disabled before the program
- releases control of the system.
-
- -----------------------------------------------------------------------------
-
- Procedure DisableGlobalA20;
-
- This procedure disables the A20 line and should only be used by programs that
- do not own the HMA.
-
- -----------------------------------------------------------------------------
-