home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / c / XMSLIB12.ZIP / XMSLIB.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-08  |  8.9 KB  |  203 lines

  1. /*  Copyright 1990,1991 by Michael Graff.        USE AT YOUR OWN RISK       */
  2. /*              See end of this file for more information.                  */
  3. /*                                                                          */
  4. /*  Version 1.2, 08-Mar-91                                                  */
  5.  
  6.  
  7. #ifndef __LARGE__
  8.     #error Hey!  You gotta use the LARGE memory model for this!
  9.     /* well, I haven't tried others yet.  They SHOULD work, other than HUGE */
  10. #endif
  11.  
  12. /* One thing for sure... */
  13. #ifdef __HUGE__
  14.     #error I KNOW the HUGE memory model will NOT work with XMSLIB AT ALL!
  15. #endif
  16.  
  17. #include <dos.h>
  18.  
  19. void far *HMAAddr = MK_FP(0xffff, 0x0010);
  20.     /*  Area of the HMA.  Can be used for data storage and code.            */
  21.  
  22. struct EMMMoveStruct {
  23.     unsigned long int   Length;
  24.     unsigned int        SourceHandle;
  25.     unsigned long int   SourceOffset;
  26.     unsigned int        DestHandle;
  27.     unsigned long int   DestOffset;
  28. };  /*  Needed for the 640k to extended memory move routines                */
  29.  
  30. extern unsigned int XMS_Setup(void);    /* MUST BE CALLED PRIOR TO OTHER    */
  31.                                         /* XMS_ ROUTINES!                   */
  32.  
  33. extern unsigned char far XMS_FreeMem(   /* returns free and total extended  */
  34.          unsigned int far *freemem,     /* free extended memory in K        */
  35.          unsigned int far *totmem);     /* total extended memory in K       */
  36.  
  37. extern unsigned char far XMS_Version(   /* Returns version information      */
  38.          unsigned int far *version,     /* BCD protocol version (2.0)       */
  39.          unsigned int far *internal,    /* BCD internal version number      */
  40.          unsigned int far *HMA);        /* is the HMA free?                 */
  41.  
  42. extern unsigned char far XMS_RequestHMA(    /* Try to allocate HMA          */
  43.          unsigned int size);    /* amount you'll be using in K.             */
  44.                                 /*  Applications should use 0xffff to       */
  45.                                 /*  allocate all 64k                        */
  46.  
  47. extern unsigned char far XMS_ReleaseHMA(void);  /* give up the HMA          */
  48.  
  49. extern unsigned char far XMS_GlobalEnableA20(void);  /* when the A20 line   */
  50. extern unsigned char far XMS_GlobalDisableA20(void); /* is enabled, the HMA */
  51. extern unsigned char far XMS_LocalEnableA20(void);   /* can be accessed.    */
  52. extern unsigned char far XMS_LocalDisableA20(void);
  53.  
  54. extern unsigned char far XMS_QueryA20(  /* Find out if A20 is enabled       */
  55.          unsigned int far *state);
  56.  
  57. extern unsigned char far XMS_AllocEMB(  /* Allocate extended momory         */
  58.          unsigned int size,         /* size in K needed                     */
  59.          unsigned int far *handle); /* handle for this EMB                  */
  60.  
  61. extern unsigned char far XMS_FreeEMB(   /* Release an EMB                   */
  62.          unsigned int handle);      /* handle to release                    */
  63.  
  64. extern unsigned char far XMS_MoveEMB(       /* Move between real memory and */
  65.          struct EMMMoveStruct far *MoveRec);/* extended memory.             */
  66.  
  67. extern unsigned char far XMS_LockEMB(   /* make sure a memory block doesn't */
  68.          unsigned int handle,           /* move.                            */
  69.          void far *address);    /* LINEAR memory address for this block     */
  70.  
  71. extern unsigned char far XMS_UnlockEMB( /* undo a lock                      */
  72.          unsigned int handle);
  73.  
  74. extern unsigned char far XMS_GetEMBHandleInfoEMB(   /* info on a handle     */
  75.          unsigned int handle,               /* handle info wanted on        */
  76.          unsigned char far *LockCount,      /* number of locks enabled      */
  77.          unsigned char far *EMBHandlesFree, /* total handles free in system */
  78.          unsigned int far *length);         /* size of this handle in K     */
  79.  
  80. extern unsigned char far XMS_ReallocEMB(    /* Try to change the size of    */
  81.          unsigned int handle,               /* this block.                  */
  82.          unsigned int newsize);             /* new size in K                */
  83.  
  84. extern unsigned char far XMS_RequestUMB(    /* request UPPER MEMORY BLOCK   */
  85.          unsigned int SizeWanded,           /* size in PARAGRAPHS needed    */
  86.          unsigned int far *segaddr,         /* segment address of block     */
  87.          unsigned int far *SizeUgot);       /* size of block you got        */
  88.  
  89. extern unsigned char far XMS_ReleaseUMB(    /* Release UMB                  */
  90.          unsigned int segaddr);
  91.  
  92. /*
  93. ------------------------------------------------------------------------------
  94.  
  95. If you find any errors, want to suggest improvements, or wish to use these
  96. routines in a commercial application, please write me at the following
  97. address:
  98.             Michael Graff
  99.             418 8th Avenue
  100.             Grinnell, IA  50112
  101.  
  102.             E-MAIL:  explorer@iastate.edu, ga.mlg@isumvs.bitnet
  103.  
  104.  
  105. You can use these routines for personal use without restrictions, other than
  106. I would like to get a copy of YOUR source.
  107.  
  108. If you use these routines in a program and make a profit, please share some
  109. small part of it with me!  (Donations of all kinds accepted, from very old
  110. hardware to old compact disks to a copy of part or all of your source to
  111. a thank you.)
  112.  
  113.  
  114. --Michael
  115.  
  116.  
  117. ------------------------------------------------------------------------------
  118.  
  119.  
  120. DEFINITIONS: ( stolen from the XMS 2.0 spec doc )
  121. -------------------------------------------------
  122.  
  123.     Extended
  124.     Memory      -   Memory in 80286 and 80386 based machines which is located
  125.                     above the 1MB address boundary.
  126.  
  127.     High Memory
  128.     Area (HMA)  -   The first 64K of extended memory.  The High Memory
  129.             Area is unique because code can be executed in it while
  130.             in real mode.  The HMA officially starts at FFFF:10h
  131.             and ends at FFFF:FFFFh making it 64K-16 bytes in length.
  132.  
  133.     Upper Memory
  134.     Blocks (UMBs)-  Blocks of memory available on some 80x86 based machines
  135.                     which are located between DOS's 640K limit and the
  136.                     1MB address boundary.  The number, size, and location
  137.                     of these blocks vary widely depending upon the types
  138.                     of hardware adapter cards installed in the machine.
  139.  
  140.     Extended Memory
  141.     Blocks (EMBs)-  Blocks of extended memory located above the HMA which
  142.                     can only be used for data storage.
  143.  
  144.     A20 Line    -   The 21st address line of 80x86 CPUs.  Enabling the A20
  145.                     line allows access to the HMA.
  146.  
  147. HIGH MEMORY AREA RESTRICTIONS:
  148. ------------------------------
  149.  
  150. -   Far pointers to data located in the HMA cannot be passed to DOS.  DOS
  151.     normalizes any pointer which is passed into it.  This will cause data
  152.     addresses in the HMA to be invalidated.
  153.  
  154. -   Disk I/O directly into the HMA (via DOS, INT 13h, or otherwise) is not
  155.     recommended.
  156.  
  157. -   Programs, especially drivers and TSRs, which use the HMA *MUST* use
  158.     as much of it as possible.  If a driver or TSR is unable to use at
  159.     least 90% of the available HMA (typically ~58K), they must provide
  160.     a command line switch for overriding HMA usage.  This will allow
  161.     the user to configure his machine for optimum use of the HMA.
  162.  
  163. -   Device drivers and TSRs cannot leave the A20 line permanently turned
  164.     on.  Several applications rely on 1MB memory wrap and will overwrite the
  165.     HMA if the A20 line is left enabled potentially causing a system crash.
  166.  
  167. -   Interrupt vectors must not point into the HMA.  This is a result of
  168.     the previous restriction.  Note that interrupt vectors can point into
  169.     any allocated upper memory blocks however.
  170.  
  171. ERROR CODE INDEX:   ( functions of type UNSIGNED CHAR return these codes )
  172. --------------------------------------------------------------------------
  173.  
  174.     80h if the function is not implemented
  175.     81h if a VDISK device is detected
  176.     82h if an A20 error occurs
  177.     8Eh if a general driver error occurs
  178.     8Fh if an unrecoverable driver error occurs
  179.     90h if the HMA does not exist
  180.     91h if the HMA is already in use
  181.     92h if DX is less than the /HMAMIN= parameter
  182.     93h if the HMA is not allocated
  183.     94h if the A20 line is still enabled
  184.     A0h if all extended memory is allocated
  185.     A1h if all available extended memory handles are in use
  186.     A2h if the handle is invalid
  187.     A3h if the SourceHandle is invalid
  188.     A4h if the SourceOffset is invalid
  189.     A5h if the DestHandle is invalid
  190.     A6h if the DestOffset is invalid
  191.     A7h if the Length is invalid
  192.     A8h if the move has an invalid overlap
  193.     A9h if a parity error occurs
  194.     AAh if the block is not locked
  195.     ABh if the block is locked
  196.     ACh if the block's lock count overflows
  197.     ADh if the lock fails
  198.     B0h if a smaller UMB is available
  199.     B1h if no UMBs are available
  200.     B2h if the UMB segment number is invalid
  201.  
  202. */
  203.