home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / memory / xmslibs / xmslib.doc < prev    next >
Encoding:
Text File  |  1991-07-28  |  20.8 KB  |  504 lines

  1.                                     XMSLIB
  2.                          C Interface to XMS Functions
  3.                               XMSLIB version 1.3
  4.                              by James W. Birdsall
  5.                                    07/27/91
  6.  
  7.  
  8. 1. INTRODUCTION
  9. ---------------
  10.  
  11.    XMSLIB provides a high-level interface to XMS control functions for common
  12. operations such as allocating and freeing XMS extended memory blocks (EMBs)
  13. and copying data to and from EMBs. A raw interface has been included to allow
  14. more exotic functions which are not directly supported.
  15.  
  16.  1.1 LEGALESE
  17.  ------------
  18.  
  19.    XMSLIB is not in the public domain. It is copyright 1991 by James W.
  20. Birdsall, all rights reserved. Permission is granted to do the following:
  21.  
  22.           You may freely redistribute this archive, so long as it contains
  23.           all the files listed here {XMSLIB.DOC, XMSLIBS.OBJ, XMSLIBC.OBJ,
  24.           XMSLIBM.OBJ, XMSLIBL.OBJ, XMSTEST.C, XMSLIB.H, XMSLIB.HPP} intact
  25.           and unmodified.
  26.  
  27.           You may use the object files in programs for your own use. You
  28.           may not distribute programs linked with these object files.
  29.  
  30.    Payment of the $5 shareware registration fee ($50 for commercial use)
  31. grants the following additional permissions:
  32.  
  33.           You may obtain the source to XMSLIB, upon request. You may modify
  34.           the source as necessary for use in your programs. However, you may
  35.           not redistribute either the original or modified source.
  36.  
  37.           You may distribute programs linked with either the original
  38.           object files or object files generated from source you have
  39.           modified, without royalty.
  40.  
  41.    For the purposes of this license, commercial use is defined as use by an
  42. incorporated entity in a software product that is regarded as the product
  43. of the corporation, no matter how the software product is distributed, but
  44. only if 100 or more copies of the product are expected to be made.
  45.  
  46.    The contents of this archive, and all other related files, information,
  47. and services are provided as-is. While every effort has been made to ensure
  48. that the files, information, and services are accurate and correct, the
  49. author cannot be held liable for damages arising out of the use of or
  50. inability to use this product.
  51.  
  52.    Information on contacting the author is provided at the end of this
  53. file.
  54.  
  55.  
  56. 2. USE
  57. ------
  58.  
  59.    XMSLIB is provided as an object file for maximum flexibility. It is
  60. written in Turbo Assembler 2.5, to be compatible with Borland C++ 2.0. Since
  61. Borland C++ has the same calling conventions as Turbo C(++), XMSLIB is
  62. compatible with Turbo C(++).
  63.    According to the documentation for Microsoft C 6.0, the calling
  64. conventions used by MSC are essentially the same. XMSLIB should be compatible
  65. with MSC also, but extensive testing has not been done. What tests could
  66. be performed worked.
  67.  
  68.    XMSLIB is provided for small, medium, compact, and large models. The model
  69. for which the object is intended is indicated by the last letter of the
  70. filename proper, which is the same as the first letter of the model. For
  71. example, XMSLIBL.OBJ is the large-model object. The small object should
  72. probably work with the tiny model, but it has not been tested. Huge model is
  73. not supported, but should require only trivial changes to the source.
  74.  
  75.    To use XMSLIB, choose the appropriate object for the model in which the
  76. rest of your program is compiled, and include that object. Note that every
  77. source file which uses XMSLIB functions should include the file XMSLIB.H.
  78.  
  79.    If you are compiling and linking in the Integrated Development Environment
  80. of Turbo C(++), you have two options:
  81.  
  82.       1) Include the name of the appropriate object in the project file.
  83.          For example, if you are working in the compact memory model, you
  84.          should include XMSLIBC.OBJ in your project file.
  85.  
  86.       2) Add the appropriate object file to the appropriate standard library
  87.          file. To do this, you will need to use the librarian utility
  88.          (TLIB.EXE) provided by Borland. For example, the command
  89.  
  90.             tlib cc+xmslibc
  91.  
  92.          will add the XMSLIBC.OBJ file to the standard library file for
  93.          the compact memory model, assuming both files are in the current
  94.          directory.
  95.  
  96.    If you are using the command-line compiler to compile and/or link, simply
  97. place the full name of the XMSLIB object on the command line. If you are
  98. linking manually (using LINK, TLINK, et al.), simply place XMSLIB in with the
  99. names of the other object files being linked. Examples follow.
  100.  
  101.    An example program, XMSTEST.C, has been included. To use it, simply
  102. compile it in whatever memory model you choose and link it with the
  103. appropriate XMSLIB object for that memory model. For example, using the
  104. Borland C++ command-line compiler, the following command would compile
  105. XMSTEST.C in the medium model and link it with XMSLIBM.OBJ:
  106.  
  107.       bcc -mm xmstest.c xmslibm.obj
  108.  
  109. Users of Turbo C(++) can simply substitute "tcc" for "bcc". The following
  110. two commands perform the same function, but demonstrate using TLINK
  111. directly:
  112.  
  113.       bcc -mm -c xmstest.c
  114.       tlink c0m xmstest xmslibm, xmstest, , cm
  115.  
  116. Again, users of Turbo C(++) can simply substitute "tcc" for "bcc". TLINK is
  117. the same for both packages. The files "c0m" and "cm" on the TLINK command
  118. line are the standard medium-model startup object and medium-model library,
  119. respectively.
  120.  
  121.  2.1 USE WITH C++
  122.  ----------------
  123.  
  124.    Use of XMSLIB with C++ is very similar to use with C. C++ files which
  125. use XMSLIB functions should include XMSLIB.HPP instead of XMSLIB.H. If you
  126. forget to include it, or include the wrong one, you will probably see
  127. "Undefined symbol" errors when linking.
  128.  
  129.  
  130. 3. GENERAL CONSIDERATIONS
  131. -------------------------
  132.  
  133.    XMSLIB provides a set of functions which are intended to be orthogonal
  134. with the standard C functions malloc()/free(), and the Turbo C function
  135. coreleft().
  136.  
  137.    One point that cannot be stressed sufficiently is that the library
  138. initialization function XMMlibinit() _must_ be called before any other
  139. XMSLIB calls are made. Failure to do so will result in undefined behavior
  140. or crash. One of the important things that XMMlibinit() does is determine
  141. whether there is an XMS driver in the system at all.
  142.  
  143.    All files which call XMSLIB functions should #include the file XMSLIB.H
  144. or XMSLIB.HPP, as appropriate. These files define the return and error code
  145. symbols shown in section 5, declare the global variables provided by XMSLIB,
  146. and provide prototypes for the XMSLIB functions.
  147.  
  148.  
  149. 4. LIBRARY FACILITIES
  150. ---------------------
  151.  
  152.  4.1 GLOBAL VARIABLES
  153.  --------------------
  154.  
  155.    XMSLIB provides the following global variables, as shown in the header
  156. files XMSLIB.H and XMSLIB.HPP:
  157.  
  158.   4.1.1 _XMMerror
  159.   ---------------
  160.  
  161.    _XMMerror is an unsigned char which contains the XMS driver error
  162. code from the last XMS driver call. If there was no error, it will be 0.
  163. A list of error code values and symbolic values is in section 5.
  164.  
  165.   4.1.2 _XMMversion
  166.   -----------------
  167.  
  168.    _XMMversion is an unsigned int which contains the XMS version that the
  169. XMS driver implements. It is in packed BCD format. For example, if the XMS
  170. version is 2.0, the value of _XMMversion will be 0x0200. The high byte of
  171. _XMMerror represents two digits to the left of the decimal point (one digit
  172. per nibble) and the low byte represents two digits to the right of the
  173. decimal point (one digit per nibble).
  174.  
  175.   4.1.3 xmslib_vers_vers, xmslib_vers_date, xmslib_vers_time
  176.   ----------------------------------------------------------
  177.  
  178.    These variables are null-terminated strings containing information about
  179. the name and version of the library, the date of compilation, and the time
  180. of compilation, respectively.
  181.  
  182.  4.2 FUNCTIONS
  183.  -------------
  184.  
  185.    All functions set the variable _XMMerror. If the function completed
  186. successfully, _XMMerror is set to 0. If there was an error, _XMMerror is
  187. set to the appropriate error code. Thus, it is always possible to check
  188. the value of _XMMerror after a function call to check for errors. However,
  189. many functions also indicate success or error by their return value. Those
  190. functions where the return value may be ambiguous are noted, and it is
  191. recommended that _XMMerror be checked instead of the return value.
  192.  
  193.   4.2.1 XMMlibinit()
  194.   ------------------
  195.  
  196.    int XMMlibinit(void)
  197.  
  198.    This function initializes the library. It _must_ be called before any
  199. other XMSLIB calls are made. It returns 0 on success, XMMOOPS if there was
  200. an XMS driver error, or NOXMM if an XMS driver was not detected.
  201.  
  202.   4.2.2 XMMgetversion()
  203.   ---------------------
  204.  
  205.    unsigned int XMMgetversion(void)
  206.  
  207.    This function returns the XMS version implemented by the XMS driver. It
  208. is in packed BCD format, the same as in the global variable _XMMversion (see
  209. above).
  210.    The value of _XMMerror should be checked after calling this function.
  211. If an error occurred, _XMMerror will be set to the error code. If the function
  212. completed successfully, _XMMerror will be 0.
  213.  
  214.   4.2.3 XMMcoreleft()
  215.   -------------------
  216.  
  217.    unsigned long XMMcoreleft(void)
  218.  
  219.    This function returns the size of the largest EMB, in bytes. Since it is
  220. not possible to allocate a single block larger than the largest EMB, the
  221. size of the largest EMB is generally more useful than the total amount of
  222. free XMS extended memory.
  223.    Note that when all EMBs have been allocated, the driver itself returns an
  224. error (0xA0, XMM_NOFREEX). This behavior is masked by the XMMcoreleft()
  225. function -- if there are no free EMBs, XMMcoreleft() returns 0L instead of
  226. an error.
  227.    The value of _XMMerror should be checked after calling this function.
  228. If an error occurred, _XMMerror will be set to the error code. If the function
  229. completed successfully, _XMMerror will be 0.
  230.  
  231.   4.2.4 XMMallcoreleft()
  232.   ----------------------
  233.  
  234.    unsigned long XMMallcoreleft(void)
  235.  
  236.    This function returns the total amount of free XMS extended memory, in
  237. bytes.
  238.    Note that when all EMBs have been allocated, the driver itself returns an
  239. error (0xA0, XMM_NOFREEX). This behavior is masked by the XMMallcoreleft()
  240. function -- if there are no free EMBs, XMMallcoreleft() returns 0L instead of
  241. an error.
  242.    The value of _XMMerror should be checked after calling this function.
  243. If an error occurred, _XMMerror will be set to the error code. If the function
  244. completed successfully, _XMMerror will be 0.
  245.  
  246.   4.2.5 XMMalloc()
  247.   ----------------
  248.  
  249.    int XMMalloc(unsigned long bytes)
  250.       bytes -- number of bytes to allocate
  251.  
  252.    This function allocates an EMB. It takes the given number of bytes and
  253. rounds upward to the next kilobyte (the XMS driver can allocate EMBs only
  254. in units of kilobytes) and allocates that many kilobytes. It returns the EMB
  255. handle assigned by the XMS driver.
  256.    The value of _XMMerror should be checked after calling this function.
  257. If an error occurred, _XMMerror will be set to the error code. If the
  258. function completed successfully, _XMMerror will be 0.
  259.    Note that EMBs cannot be allocated in units smaller than a kilobyte.
  260. Requesting one byte will allocate 1024 bytes; requesting 1025 bytes will
  261. allocate 2048. However, requesting 0 bytes will allocate a handle but no
  262. bytes. This is explicitly allowed by the XMS specification.
  263.  
  264.   4.2.6 XMMfree()
  265.   ---------------
  266.  
  267.    int XMMfree(int handle)
  268.       handle -- EMB handle to free
  269.  
  270.    This function accepts an EMB handle obtained from the XMMalloc() function
  271. or directly from the XMS driver, and releases it and the EMB allocated to it.
  272. If an error occurred, XMMfree() returns XMMOOPS and _XMMerror will be set to
  273. the error code. If the function completed successfully, XMMfree() returns 0
  274. and _XMMerror will be 0.
  275.  
  276.   4.2.7 _XMMcopy()
  277.   ------------------
  278.  
  279.    int _XMMcopy(unsigned long copylen, int shan, unsigned long soff,
  280.                                                   int dhan, unsigned long doff)
  281.       copylen -- number of bytes to be copied
  282.       shan    -- EMB handle of source
  283.       soff    -- offset in shan of source, or far pointer to source if
  284.                  source in conventional memory
  285.       dhan    -- EMB handle of destination
  286.       doff    -- offset in dhan of destination, or far pointer to destination
  287.                  if destination in conventional memory
  288.  
  289.    This function allows painless copying from conventional memory to an EMB,
  290. from an EMB to conventional memory, from one EMB to another, or even from
  291. one point in conventional memory to another. Areas larger than 64K can be
  292. copied without special treatment. Macros XMMcopyto() and XMMcopyfrom()
  293. (see below) are provided for even easier copying from conventional memory
  294. to an EMB and vice versa, respectively.
  295.    Copylen bytes of data are copied. If shan is nonzero, it is assumed to be
  296. the handle of an EMB, and soff is treated as a byte offset into the EMB owned
  297. by shan. If shan is zero, soff is treated as a segment:offset far pointer to
  298. conventional memory. The pair of shan and soff indicate where the data is to
  299. be copied from (the source). Dhan and doff work the same way as shan and soff,
  300. but indicate where the data is to be copied to (the destination).
  301.    If an error occurred, XMMOOPS is returned and _XMMerror is set to an error
  302. code. If the function completed successfully, 0 is returned and _XMMerror is
  303. 0.
  304.    Note that copies of odd numbers of bytes are slower than copies of even
  305. numbers of bytes, and that copies of one byte are even slower. For best
  306. performance, copy even numbers of bytes at a time.
  307.  
  308.   4.2.8 XMMrawcall()
  309.   ------------------
  310.  
  311.    int XMMrawcall(struct XMMregs *regs)
  312.       regs -- pointer to structure holding values for registers
  313.  
  314.    This function is a raw interface directly to the XMS driver. The XMMregs
  315. structure has fields for the AX, BX, DX, SI, and DS registers, which are the
  316. only ones used by the XMS driver. The values in the structure are placed
  317. in the appropriate registers before the XMS driver is called, and the values
  318. in the registers are copied back into the structure after the XMS driver
  319. call returns.
  320.    Since the XMS specification provides a uniform error indication,
  321. XMMrawcall() is able to tell if the call performed caused an error. If it
  322. did, XMMOOPS is returned and _XMMerror is set to the error code. If it
  323. completed successfully, 0 is returned and _XMMerror is set to 0. The low byte
  324. of the regBX field of the XMMregs structure will also contain the error code
  325. if an error occurred.
  326.    The details of the XMMregs structure are shown in the header file XMSLIB.H.
  327.  
  328.  4.3 MACROS
  329.  ----------
  330.  
  331.    XMSLIB provides a few macros to make calls to _XMMcopy easier.
  332.  
  333.   4.3.1 XMMcopyto()
  334.   -----------------
  335.  
  336.    int XMMcopyto(unsigned long copylen, unsigned char far *source,
  337.                                                   int dhan, unsigned long doff)
  338.       copylen -- number of bytes to be copied
  339.       source  -- far pointer to conventional memory source
  340.       dhan    -- EMB handle of destination
  341.       doff    -- offset in dhan of destination
  342.  
  343.    This macro allows painless copying from conventional memory to an EMB.
  344. Areas larger than 64K can be copied without special treatment.
  345.    Copylen bytes of data are copied. Source is a far pointer to conventional
  346. memory and indicates where the data is to be copied from. Dhan is the handle
  347. of an EMB, and doff is a byte offset into the EMB owned by dhan. The pair of
  348. dhan and doff indicate where the data is to be copied to.
  349.    If an error occurred, XMMOOPS is returned and _XMMerror is set to an error
  350. code. If the function completed successfully, 0 is returned and _XMMerror is
  351. 0.
  352.    Note that copies of odd numbers of bytes are slower than copies of even
  353. numbers of bytes, and that copies of one byte are even slower. For best
  354. performance, copy even numbers of bytes at a time.
  355.  
  356.   4.3.2 XMMcopyfrom()
  357.   -------------------
  358.  
  359.    int XMMcopyfrom(unsigned long copylen, int shan, unsigned long soff,
  360.                                                        unsigned char far *dest)
  361.       copylen -- number of bytes to be copied
  362.       shan    -- EMB handle of source
  363.       soff    -- offset in shan of source, or far pointer to source if
  364.                  source in conventional memory
  365.       dest    -- far pointer to conventional memory destination.
  366.  
  367.    This macro allows painless copying to conventional memory from an EMB.
  368. Areas larger than 64K can be copied without special treatment.
  369.    Copylen bytes of data are copied. Shan is the handle of an EMB, and soff
  370. is a byte offset into the EMB owned by shan. The pair of shan and soff
  371. indicate where the data is to be copied from. Dest is a far pointer to
  372. conventional memory and indicates where the data is to be copied to.
  373.    If an error occurred, XMMOOPS is returned and _XMMerror is set to an error
  374. code. If the function completed successfully, 0 is returned and _XMMerror is
  375. 0.
  376.    Note that copies of odd numbers of bytes are slower than copies of even
  377. numbers of bytes, and that copies of one byte are even slower. For best
  378. performance, copy even numbers of bytes at a time.
  379.  
  380. 5. ERROR CODES
  381. --------------
  382.  
  383.    This section is a list of the error codes to which the global variable
  384. _XMMerror may be set, and the values and meanings thereof.
  385.  
  386.  5.1 INTERNAL CODES
  387.  ------------------
  388.  
  389.    XMSLIB does not generate any error codes internally.
  390.  
  391.  5.2 XMS DRIVER CODES
  392.  --------------------
  393.  
  394.    These codes are defined in the XMS specification and are returned by
  395. the XMS driver. They are saved in _XMMerror by XMSLIB without alteration.
  396.  
  397.    NAME                 VALUE     MEANING
  398.    ----                 -----     -------
  399.    XMM_UNIMP             0x80     Function is not implemented
  400.  
  401.    XMM_VDISK             0x81     VDISK device driver was detected
  402.  
  403.    XMM_A20ERROR          0x82     A20 error occurred
  404.  
  405.    XMM_GENERROR          0x83     General driver error occurred
  406.  
  407.    XMM_UNRECERROR        0x84     Unrecoverable driver error occurred
  408.  
  409.    XMM_NOHMA             0x90     HMA (High Memory Area) does not exist
  410.  
  411.    XMM_HMAUSED           0x91     HMA already allocated
  412.  
  413.    XMM_HMATOOBIG         0x92     Request to allocate HMA denied because
  414.                                   amount of HMA requested is less than
  415.                                   minimum parameter given to XMS driver
  416.                                   on its command line
  417.  
  418.    XMM_HMANOALLOC        0x93     HMA is not allocated
  419.  
  420.    XMM_A20STILLEN        0x94     A20 line is still enabled
  421.  
  422.    XMM_NOFREEX           0xA0     All EMBs (Extended Memory Blocks) are
  423.                                   allocated
  424.  
  425.    XMM_NOFREEXHAN        0xA1     No free EMB handles
  426.  
  427.    XMM_BADXHAN           0xA2     EMB handle is invalid
  428.  
  429.    XMM_BADSRCHAN         0xA3     Source EMB handle is invalid
  430.  
  431.    XMM_BADSRCOFF         0xA4     Source offset in EMB is beyond end of EMB
  432.  
  433.    XMM_BADDESTHAN        0xA5     Destination EMB handle is invalid
  434.  
  435.    XMM_BADDESTOFF        0xA6     Destination offset in EMB is beyond end
  436.                                   of EMB
  437.  
  438.    XMM_BADLENGTH         0xA7     Length is invalid
  439.  
  440.    XMM_COPYOVERLAP       0xA8     Overlap in copy request is invalid
  441.  
  442.    XMM_PARITY            0xA9     Parity error was detected
  443.  
  444.    XMM_NOLOCK            0xAA     EMB is not locked
  445.  
  446.    XMM_LOCKED            0xAB     EMB is locked
  447.  
  448.    XMM_TOOMANYLOCKS      0xAC     EMB lock count overflowed
  449.  
  450.    XMM_LOCKFAIL          0xAD     EMB lock failed
  451.  
  452.    XMM_UMBSMALLER        0xB0     UMB (Upper Memory Block) of size requested
  453.                                   is not available; however, a smaller UMB
  454.                                   is available
  455.  
  456.    XMM_NOFREEUMB         0xB1     All UMBs are allocated
  457.  
  458.    XMM_BADUMBHAN         0xB2     UMB handle (same as segment address of
  459.                                   start of UMB) is invalid
  460.  
  461.  
  462. 6. THE END
  463. ----------
  464.  
  465.    Technical support via email is available from the following addresses:
  466.  
  467.    INTERNET:
  468.       First choice (the following are alternate addresses for the same place):
  469.          picarefy!support@amc.com
  470.          amc-gw!picarefy!support@coco.ms.washington.edu
  471.          halcyon!picarefy!support@sumax.seattleu.edu
  472.          eskimo!picarefy!support@quick.com
  473.          uunet!uw-coco!amc-gw!picarefy!support
  474.  
  475.       Second choice:
  476.          jwbirdsa@amc.com
  477.  
  478.    COMPUSERVE:
  479.       71261,1731
  480.  
  481.    AMERICA ON-LINE:
  482.       GreenTiger
  483.  
  484.    GENIE:
  485.       J.BIRDSALL2
  486.  
  487.    Registrations should be sent to:
  488.  
  489.       James W. Birdsall
  490.       11112 NE 124 LN #D204
  491.       Kirkland, WA 98034
  492.  
  493.    If you have an email address on any of the networks listed above, please
  494. include it when registering, especially if you are requesting source code.
  495. It is much easier to send the source code by email. Also, please specify
  496. what sort of archive (ZIP, ZOO, ARC, LZH, ARJ, UNIX shar) you can handle
  497. most easily.
  498.  
  499.  6.1 ACKNOWLEDGEMENTS
  500.  --------------------
  501.  
  502.    Thanks to Bob Parsons of Parsons Technology Inc. for some good suggestions
  503. on the documentation and the C++ header file.
  504.