home *** CD-ROM | disk | FTP | other *** search
- PBASMLIB Assembly Language Routines for PB3C
- Version 1.0
- Extended Memory (XMS) Module
- (C) Copyright 1994 by Tim Gerchmez
- All Rights Reserved.
-
- This module interfaces you to XMS (Extended Memory) in your computer,
- available on the PC-AT and up. You will be able to access any or all of
- these routines by including the statements $INCLUDE "PBASMLIB.INC" and
- $LINK "PBASMLIB.PBL" at the top of your PowerBASIC programs. An interface
- to EMS (Expanded Memory) is included in a separate module.
-
- Many of these functions let you access XMS at a very low level. For the
- easiest way to access XMS, see XMSSTORESTRING and XMSRECALLSTRING.
-
- The following error messages are returned for the
- XMS routines, unless otherwise indicated. Most
- routines that return errors will return only a few of
- the error numbers indicated below.
-
- 80h = function not implemented
- 81h = VDISK was detected
- 82h = A20 error occurred
- 8Eh = general driver error
- 8Fh = unrecoverable driver error
- 90h = HMA does not exist
- 91h = HMA is already in use
- 92h = DX is less than the /HMAMIN= parameter
- 93h = HMA is not allocated
- 94h = A20 line still enabled
- A0h = all extended memory is allocated
- A1h = all XMS handles are allocated
- A2h = invalid handle
- A3h = source handle is invalid
- A4h = source offset is invalid
- A5h = destination handle is invalid
- A6h = destination offset is invalid
- A7h = length is invalid
- A8h = move has an invalid overlap
- A9h = parity error occurred
- AAh = block is not locked
- ABh = block is locked
- ACh = block lock count overflowed
- ADh = lock failed
- B0h = only a smaller UMB is available
- B1h = no UMB's are available
- B2h = UMB segment number is invalid
-
- ================================================================================
- function xmsdetect
-
- Returns -1 if an XMS (Extended Memory) handler is
- installed, or 0 if not. Doesn't actually detect the
- presence of extended memory though (see XMSFREE for this).
- This routine should be called before any of the other XMS
- routines to make sure a handler is available.
-
- Example: if xmsdetect then print "XMS will be used, if present."
-
- ================================================================================
- sub xmsgetver(mj%,mn%,hm%)
-
- Gets the version of the XMS driver installed. You should make
- sure the XMS driver is present with XMSDETECT first.
-
- mj%: Returns major version number
- mn%: Returns minor version number
- hm%: Returns 1 if HMA (High Memory Area) exists. This is
- the area between 1 meg and 1 meg + 64K that holds TSR's,
- device drivers, etc. without using regular DOS memory.
-
- Example: xmsgetver ma%,mn%,hm%
-
- ================================================================================
- sub xmsgetfree(lem??,tem??,er%)
-
- Gets the amount of free XMS, total XMS available, and
- an error code if an err was encountered.
-
- lem??: Returns size of largest available XMS block in K (lem??*1024)
- tem??: Returns total XMS memory
- er%: Returns 0 if no error, or error code if error (80h,81h,A0h)
-
- Example: xmsgetfree lem??,tem??,er%
-
- ================================================================================
- function xmserror
-
- Returns the error code from the most recent XMS operation,
- for those operations that don't automatically return an error code
- such as XMSSTORESTRING and XMSRECALLSTRING. Future versions of
- PBASMLIB may remove the er% parameter from many of the XMS commands
- and go exclusively with this routine for checking errors (this is
- the approach the EMS module takes).
-
- Example: print xmserror
-
- ================================================================================
- function xmsrecallstring$(ln%,h??)
-
- Recalls the string from XMS memory that you previously
- stored with XMSSTORESTRING. You should have saved the
- ln% and h?? variables that XMSSTORESTRING returned to you.
- To recall the string you saved, just call this routine (see
- example below). The handle that was used is automatically
- deallocated, so recalling a previously saved string frees
- up a handle for a new string to be saved with XMSSTORESTRING.
- A null string will be returned if an error is encountered, and
- you can check the error with XMSERROR.
-
- ln%: Set to value for original string provided by XMSSTORESTRING. You
- can intentionally decrease the value of ln% to recall less than the full
- string that was originally saved, if desired.
-
- h??: Set to value for handle provided by XMSSTORESTRING for original string
-
- xmsrecallstring$: Returns the original string
-
- Example: s$ = xmsrecallstring$(ln%,h??) 'Recalls string and deallocates h?? handle.
-
- ================================================================================
- sub xmsstorestring(s$,ln%,h??)
-
- Stores a string in XMS memory, returning a handle and string
- length for future accesses to that string in XMS memory. This
- is one of the simplest XMS routines, and does most of the work
- for you. Simply use XMSDETECT first to make sure an XMS handler
- is available. Only a limited number of XMS handles are available,
- so this routine won't work well for storing many small strings.
- You should consolidate smaller strings into one large string before
- storing to XMS memory, then parse the string out after recalling.
- Note: If you don't deallocate the handle passed to you in h?? by
- calling XMSRECALLSTRING or using XMSFREE, that handle and portion of
- XMS memory will remain allocated until you reboot the computer! This
- also applies if the program terminates abnormally or early for some reason.
-
- s$: Set to the string to store (0 to max $STRING length).
-
- ln%: Returns the length of the string you passed in s$ -
- save this value for XMSRECALLSTRING.
-
- h??: Returns a handle for future accesses (see XMSRECALLSTRING),
- or 0 if function was unsuccessful in some way. Possible
- problems include no XMS, or not enough XMS available, no
- remaining handles, etc. Each string will take a minimum of
- 1K of XMS memory, and this will be in 1K multiples - for example,
- a 1025 byte string will take 2K of XMS memory. Use XMSERROR
- to see which error occurred if h??=0 upon return.
-
- Example: xmsstorestring s$,ln%,h??
- if h??=0 then print "Error encountered when storing:";xmserror
- s$="" 'Deallocate the memory taken by s$ since it's in XMS now
- 'Save values in h?? and ln% - needed for XMSRECALLSTRING!
-
- ================================================================================
- sub xmsalloc(kb??,h??,er%)
-
- Allocates XMS memory, and returns a handle to that memory
- for future accesses. This is the first step in directly
- accessing XMS.
-
- kb??: Set to number of K (bytes\1024) of XMS needed
- h??: Returns a handle to XMS memory (if er% = 0)
- er%: Returns 0 if OK (memory allocated), or 80h/
- 81h/A0h error code (see XMSGETFREE).
-
- Example: xmsalloc 10,h??,er%
- if er%=0 then print "10K Allocated under handle ";h??
-
- ================================================================================
- sub xmsfreeumb(sg??,er%)
-
- Frees the specified upper memory block (UMB).
-
- sg??: Set to the segment address of the UMB to release
- er%: Returns 0 if OK (released), or error code (80h,B2h)
-
- Example: xmsfreeumb(sg??,er%)
-
- ================================================================================
- sub xmsallocumb(sz??,sg??,az??,er%)
-
- Allocates an upper-memory block (UMB), which is
- non-EMS memory above the 640K limit.
-
- sz??: Set to size of UMB desired in paragraphs (16-byte chunks)
- sg??: Returns segment of UMB if successful
- az??: Returns actual size of UMB allocated, or largest available if failed
- er%: Returns 0 if successful, or error code if failed (80h,B0h,B1h)
-
- Example: call xmsallocumb(sz??,sg??,az??,er%)
-
- ================================================================================
- sub xmsresize(kb??,h??,er%)
-
- Resizes a previously-allocated XMS handle.
-
- kb??: Set to new block size in K
- h??: Set to handle returned by XMSALLOC
- er%: Returns 0 if ok (block resized), or
- error code 80h,81h,A0h-A2h,ABh)
-
- Example: xmsresize kb??,h??,er%
- if er%=0 then print "Resize successful."
-
- ================================================================================
- sub xmshandleinfo(h??,nfh%,sz??)
-
- Gets the size of an allocated XMS handle, and the
- number of free XMS handles left.
-
- h??: Set to handle to get info for
- nfh%: Returns number of free handles left
- sz??: Returns size of XMS block allocated to h?? in K.
- if sz?? returns zero, an error was encountered.
-
- Example: call xmshandleinfo(h??,nfh%,sz??)
-
- ================================================================================
- sub xmsfree(h??,er%)
-
- Frees a block of XMS memory previously allocated with
- XMSALLOC.
-
- h??: Set to handle returned by XMSALLOC routine
- er%: Returns 0 if ok (memory deallocated), or error
- code if error (80h,81h,A2h,ABh)
-
- Example: xmsfree h??,er%
-
- ================================================================================
- function xmsrecall(h??,sg??,ofs??,nbytes???,xofs???)
-
- Moves data from XMS memory to standard (addressable) memory.
- To store data, use XMSSTORE instead.
-
- h??: Set to handle returned by XMSALLOC
- sg??: Set to segment of regular memory to recall to
- ofs??: Set to offset of regular memory to recall to
- nbytes???: Set to number of bytes to recall from XMS. This should
- be an even number - if not, an extra byte is recalled.
- xofs???: Set to offset INTO the XMS block to start recalling
- from.
-
- Example: s% = xmsrecall(h??,sg??,ofs??,1024,0) 'Recall 1K of XMS starting at offset 0
- if s% then print "Recall was successful."
-
- ================================================================================
- function xmsstore(h??,sg??,ofs??,nbytes???,xofs???)
-
- Moves data from standard (addressable) memory to XMS
- memory. To recall the data, use XMSRECALL.
-
- h??: Set to handle returned by XMSALLOC
- sg??: Set to segment of regular memory (EX: VARSEG of array)
- ofs??: Set to offset of regular memory (EX: VARPTR of array)
- nbytes???: Set to number of bytes to move to XMS. This should
- be an even number - if not, an extra byte is stored.
- xofs???: Set to offset INTO the XMS block you allocated, in bytes.
- This would be zero if using the entire XMS block allocated.
- xmsstore: Returns -1 if successful, or error code if not:
-
- Example: s% = xmsstore(h??,sg??,ofs??,1024,0) 'Stores 1K at XMS offset 0
- if s% then print "Store Successful"
-
-