home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / AXMSLIB.ZIP / XMSLIB.DOC < prev    next >
Encoding:
Text File  |  1992-02-28  |  9.8 KB  |  279 lines

  1.                   ┌───────────────────────────────────┐
  2.                   │A(nother) C library for XMS memory │
  3.                   ├───────────────────────────────────┤
  4.                   │Version 1.0          February 1992 │
  5.                   └───────────────────────────────────┘
  6. Michael Wilson
  7.  
  8.         CIS:    100014,2743
  9.         email:  ucgb06m@uk.ac.bcc.ts
  10.  
  11.         Voice:  (+44) 279 429644 ext 230 (daytime)
  12.  
  13. ═════Introduction═══════════════════════════════════════════════════════════
  14.  
  15. I wrote this library when I needed a lot of data space for a program and
  16. couldn't afford to buy a commercial virtual memory system. It provides a
  17. reasonably familiar type of interface to memory allocation and freeing
  18. functions, and hides most of the XMS details from the caller.
  19.  
  20. The library *requires* XMS memory, that is, extended memory (above the
  21. 1Mbyte mark) conforming to the XMS specification (v2.0 or later). This
  22. type of memory can not be fitted in PC and XT (808x) machines. The
  23. library does *not* work with expanded (EMS) memory.
  24.  
  25. It is assumed that you will have an XMS driver (usually, the HIMEM.SYS
  26. that came with DOS 5 or WINDOWS 3.x) loaded, to provide the low level
  27. XMS interface that the library uses.
  28.  
  29. This is version 1.0. As usual that means that it's probably not fully
  30. debugged. I am also aware that the performance of the allocator is not
  31. great; try to repetitively allocate and free one hundred thousand
  32. 100-byte blocks and you'll see what I mean (unless you have more than 10
  33. Mbytes of XMS memory available...).
  34.  
  35. The system will perform more than adequately for large chunks of data,
  36. or for small chunks that are only allocated once. Improvements will be
  37. made in later versions, or you can roll your own (that's what source
  38. code is for, after all).
  39.  
  40. A small demonstration program, which loads one or more text files into
  41. extended memory and then lists it/them, is included, along with a
  42. makefile to help you build it.
  43.  
  44. The code has been tested with Microsoft C v6.00A and Borland C++ v3.0 in
  45. both small and large memory models.
  46.  
  47. The documentation below is also provided in Microsoft's QuickHelp
  48. format, for use with the QH program supplied with MSC v6+.
  49.  
  50. Please pass comments and suggestions to me at either of the above
  51. addresses.
  52.  
  53.  
  54. ═════XMSLIB Overview════════════════════════════════════════════════════════
  55.  
  56. Quick Reference Summary:
  57.  
  58. XMSHANDLE XMSalloc      (WORD uBytes);
  59. int       XMSclose      (void);
  60. WORD      XMSerrorCode  (void);
  61. int       XMSfree       (XMSHANDLE xhXM);
  62. int       XMSget        (void * pDest, XMSHANDLE xhXM);
  63. int       XMSgetExt     (void * pDest, XMSHANDLE xhXM, WORD uSrcOfs,
  64.                          WORD uBytes);
  65. WORD      XMSgetLen     (XMSHANDLE xhXM);
  66. WORD      XMSgetVersion (void);
  67. int       XMSinstalled  (void);
  68. int       XMSopen       (WORD uKbytes);
  69. int       XMSput        (XMSHANDLE xhXM, const void * pSrc, WORD uBytes);
  70.  
  71. Type and constant definitions:
  72.  
  73.         XMSHANDLE   Handle to an XMS memory buffer
  74.         XMSHNULL    The `null' handle; an error condition
  75.  
  76. Note:
  77.         WORD        2-byte, unsigned quantity
  78.         TRUE        Boolean value
  79.         FALSE       Boolean value
  80.  
  81. are defined in a file called TYPES.H. You probably have you own
  82. equivalents, so just replace the #include as necessary.
  83.  
  84. XMSLIB contains functions to allocate, free, read and write from 
  85. extended memory conforming to the XMS 2.0 (or later) specification.
  86. A driver such as HIMEM.SYS must be loaded to make the memory available.
  87.  
  88. The XMS access must be performed as follows:
  89.  
  90.     if (XMSopen(x))
  91.       {
  92.       // XMS access permitted here...
  93.       // .
  94.       // .
  95.       // .
  96.       // End of XMS access
  97.       
  98.       if (!XMSclose())
  99.         fprintf(stderr, "XMS error %x\n", XMSerrorCode());
  100.       }
  101.  
  102.  
  103. ─────XMSalloc───────────────────────────────────────────────────────────────
  104.  
  105. XMSHANDLE XMSalloc (WORD uBytes);
  106.  
  107. Allocates a buffer of size <uBytes> characters in extended memory.
  108.  
  109. Returns a handle to the memory if successful, or XMSHNULL if not.
  110.  
  111. XMSopen() must be called before attempting to use this function. The
  112. maximum size of the buffer is 65534 bytes (assuming that at least 64K
  113. of XMS memory is available).
  114.  
  115.  
  116. ─────XMSclose───────────────────────────────────────────────────────────────
  117.  
  118. int       XMSclose (void);
  119.  
  120. Terminates access to XMS memory, returning all associated buffer space
  121. (both in XMS and on the program's heap) to the system.
  122.  
  123. Returns TRUE if successful, else FALSE.
  124.  
  125. You must call this function before exiting the program. DOS does not
  126. automatically release XMS memory claimed by a process, so a failure
  127. to call XMSclose() will leave a reduced amount of XMS memory available
  128. for other programs, or later execution of the same program, until the
  129. system is reset.
  130.  
  131.  
  132. ─────XMSerrorCode───────────────────────────────────────────────────────────
  133.  
  134. WORD      XMSerrorCode (void);
  135.  
  136. Returns the XMS error code number pertaining to the most recent XMS
  137. operation. If you need information on why an operation failed, call
  138. this function immediately afterwards (and before calling any other
  139. XMSLIB function).
  140.  
  141. Return codes are (refer to the XMS spec for full details):
  142.  
  143.    (0x80    Function not implemented)
  144.     0x81    VDISK device detected
  145.     0x82    A20 error
  146.     0x8E    General driver error
  147.     0x8F    Unrecoverable driver error
  148.    (0x90    HMA does not exist)
  149.    (0x91    HMA already in use)
  150.    (0x92    DX less than /HMAMIN= parameter)
  151.    (0x93    HMA is not allocated)
  152.    (0x94    A20 line still enabled)
  153.     0xA0    All extended memory is allocated
  154.     0xA1    All available extended memory handles are in use
  155.     0xA2    Handle is invalid
  156.     0xA3    Source handle is invalid
  157.     0xA4    Source offset is invalid
  158.     0xA5    Destination handle is invalid
  159.     0xA6    Destination offset is invalid
  160.     0xA7    Length is invalid
  161.    (0xA8    Move has invalid overlap)
  162.     0xA9    Parity error
  163.    (0xAA    Block is not locked)
  164.    (0xAB    Block is locked)
  165.    (0xAC    Block's lock count has overflowed)
  166.    (0xAD    Lock failed)
  167.    (0xB0    Smaller UMB is available)
  168.    (0xB1    No UMBs are available)
  169.    (0xB2    UMB segment number is invalid)
  170.  
  171. Because XMSLIB only uses a subset of the XMS API calls, several of
  172. the error codes are most unlikely to occur. These are shown in 
  173. brackets. It would be unnecessary to, for example, store a descriptive
  174. string for each of these in a program.
  175.  
  176.  
  177. ─────XMSfree────────────────────────────────────────────────────────────────
  178.  
  179. int       XMSfree (XMSHANDLE xhXM);
  180.  
  181. Frees the memory associated with handle <xhXM> for re-use. The handle
  182. must have been returned previously be a call to XMSalloc(). Once the
  183. memory has been freed, you can not rely on it to contain any data 
  184. previously copied in. Do not use a handle once it has been passed to
  185. XMSfree().
  186.  
  187. Returns TRUE for success, FALSE for failure.
  188.  
  189.  
  190.  
  191. ─────XMSget─────────────────────────────────────────────────────────────────
  192.  
  193. int       XMSget (void * pDest, XMSHANDLE xhXM);
  194.  
  195. Copies data from extended memory addressed by handle <xhXM> to a buffer
  196. pointed to by <pDest>. The number of bytes copied is equal to the 
  197. argument passed to XMSalloc() to create the handle (i.e. the size of
  198. the allocated buffer), or 1 BYTE MORE if the number of bytes was odd.
  199.  
  200. Returns TRUE if successful, FALSE on failure.
  201.  
  202.  
  203.  
  204. ─────XMSgetExt──────────────────────────────────────────────────────────────
  205.  
  206. int       XMSgetExt (void * pDest, XMSHANDLE xhXM, WORD uSrcOfs,
  207.                      WORD uBytes);
  208.  
  209. Copies data from extended memory addressed by handle <xhXM> to a buffer
  210. pointed to by <pDest>. The number of bytes copied is equal to <uBytes>.
  211. Data will be copied from an offset of <uSrcOfs> from the start of the
  212. extended memory buffer addressed by the handle.
  213.  
  214. Returns TRUE if successful, FALSE on failure.
  215.  
  216.  
  217.  
  218. ─────XMSgetLen──────────────────────────────────────────────────────────────
  219.  
  220. WORD      XMSgetLen (XMSHANDLE xhXM);
  221.  
  222. Returns the number of bytes of data which may be stored at the extended
  223. memory buffer addressed by <xhXM>, or 0 on error.
  224.  
  225.  
  226.  
  227. ─────XMSgetVersion──────────────────────────────────────────────────────────
  228.  
  229. WORD      XMSgetVersion (void);
  230.  
  231. Returns the version number of the XMS specification as a two byte BCD
  232. number containing the major version number in the high byte and the
  233. minor version number in the low byte (e.g. 0x0321 = version 3.21),
  234. or 0 if XMS memory can not be accessed (call XMSopen() first).
  235.  
  236.  
  237.  
  238. ─────XMSinstalled───────────────────────────────────────────────────────────
  239.  
  240. int       XMSinstalled (void);
  241.  
  242. Returns TRUE if XMS memory is installed in the system (and a suitable
  243. driver is loaded), else FALSE.  Does not require a prior call to 
  244. XMSopen().
  245.  
  246.  
  247.  
  248. ─────XMSopen────────────────────────────────────────────────────────────────
  249.  
  250. int       XMSopen (WORD uKbytes);
  251.  
  252. Initialises internal library data and attempts to reserve <uKbytes>
  253. kilobytes of XMS memory for the program's use (e.g. XMSopen(100) will
  254. attempt to reserve 100K of XMS memory).
  255.  
  256. If <uKbytes> is 0, XMSopen() will attempt to acquire ALL available
  257. XMS memory for the program's use. (At least 64K of XMS memory must
  258. be available for this feature to work).
  259.  
  260. Returns TRUE if successful, FALSE on error.
  261.  
  262. This function must be called before any functions which allocate, read
  263. or write memory to or from XMS memory. It has a (small) overhead in
  264. conventional memory of about 16 bytes per 64K of XMS used.
  265.  
  266.  
  267.  
  268. ─────XMSput─────────────────────────────────────────────────────────────────
  269.  
  270. int       XMSput (XMSHANDLE xhXM, const void * pSrc, WORD uBytes);
  271.  
  272. Copies <uBytes> characters from buffer <pSrc> to the XMS buffer 
  273. addressed by the handle <xhXM>. The handle must have been returned
  274. by an earlier call to XMSalloc(), and must not have subsequently been
  275. released by a call to XMSfree().
  276.  
  277. Returns TRUE if successful, or FALSE if an error occurs.
  278.  
  279.