home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / midas / ems.h < prev    next >
C/C++ Source or Header  |  1994-08-06  |  8KB  |  283 lines

  1. /*      EMS.H
  2.  *
  3.  * EMS heap manager, v1.10
  4.  *
  5.  * Copyright 1994 Petteri Kangaslampi and Jarno Paananen
  6.  *
  7.  * This file is part of the MIDAS Sound System, and may only be
  8.  * used, modified and distributed under the terms of the MIDAS
  9.  * Sound System license, LICENSE.TXT. By continuing to use,
  10.  * modify or distribute this file you indicate that you have
  11.  * read the license and understand and accept it fully.
  12. */
  13.  
  14.  
  15. #ifndef __EMS_H
  16. #define __EMS_H
  17.  
  18.  
  19. struct emsHdl;
  20.  
  21.  
  22. /****************************************************************************\
  23. *       struct emsBlock
  24. *       ---------------
  25. * Description:  Allocated EMS block structure
  26. \****************************************************************************/
  27.  
  28. typedef struct emsBlk
  29. {
  30.     ushort      addr;                   /* address of block inside handle
  31.                                            memory area */
  32.     ushort      bytes;                  /* size of block */
  33.     struct emsBlk   *next;              /* pointer to next block in same
  34.                                            handle */
  35.     struct emsBlk   *prev;              /* pointer to previous block */
  36.     ushort      used;                   /* 1 if used, 0 if not */
  37.     struct emsHdl   *handle;                /* handle of the block */
  38. } emsBlock;
  39.  
  40.  
  41.  
  42.  
  43. /****************************************************************************\
  44. *       struct emsHandle
  45. *       ----------------
  46. * Description:  One EMS handle consisting of four pages. Used internally by
  47. *               heap manager.
  48. \****************************************************************************/
  49.  
  50. typedef struct emsHdl
  51. {
  52.     ushort      handle;                 /* EMM handle number */
  53.     emsBlock    *block;                 /* pointer to first block */
  54.     struct emsHdl   *next;              /* pointer to next handle */
  55.     struct emsHdl   *prev;              /* pointer to previous handle */
  56. } emsHandle;
  57.  
  58.  
  59.  
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63.  
  64.  
  65.  
  66. /****************************************************************************\
  67. *
  68. * Function:     int emsInit(int *emmOK);
  69. *
  70. * Description:  Initializes EMS heap. Must be called before other EMS heap
  71. *               manager functions.
  72. *
  73. * Input:        int *emmOK              pointer to variable containing EMM
  74. *                                       status
  75. *
  76. * Returns:      MIDAS error code.
  77. *               *emmOK contains 1 if Expanded Memory Manager was found (EMS
  78. *               initialized succesfully) or 0 if not. Note that the lack
  79. *               of Expanded Memory Manager is _not_ an error.
  80. *
  81. \****************************************************************************/
  82.  
  83. int CALLING emsInit(int *emmOK);
  84.  
  85.  
  86.  
  87. /****************************************************************************\
  88. *
  89. * Function:     int emsClose(void);
  90. *
  91. * Description:  Uninitializes EMS heap freeing all allocated blocks. Must be
  92. *               called before program exits if emsInit() has been called.
  93. *
  94. * Returns:      MIDAS error code
  95. *
  96. \****************************************************************************/
  97.  
  98. int CALLING emsClose(void);
  99.  
  100.  
  101.  
  102. /****************************************************************************\
  103. *
  104. * Function:     int emsAlloc(ushort bytes, emsBlock **ems);
  105. *
  106. * Description:  Allocates an EMS memory block
  107. *
  108. * Input:        ushort bytes            number of bytes to be allocated
  109. *               emsBlock **ems          Pointer to EMS Block pointer
  110. *
  111. * Returns:      MIDAS error code.
  112. *               EMS block pointer stored in *ems, NULL if failure
  113. *
  114. \****************************************************************************/
  115.  
  116. int CALLING emsAlloc(ushort bytes, emsBlock **ems);
  117.  
  118.  
  119.  
  120. /****************************************************************************\
  121. *
  122. * Function:     int emsFree(emsBlock *ems);
  123. *
  124. * Description:  Deallocates an EMS block allocated with emsAlloc
  125. *
  126. * Input:        emsBlock *ems           pointer to block to be deallocated
  127. *
  128. * Returns:      MIDAS error code
  129. *
  130. \****************************************************************************/
  131.  
  132. int CALLING emsFree(emsBlock *ems);
  133.  
  134.  
  135.  
  136.  
  137. /****************************************************************************\
  138. *
  139. * Function:     int emsMap(emsBlock *ems, void **memPtr);
  140. *
  141. * Description:  Maps an EMS block to conventional memory.
  142. *
  143. * Input:        emsBlock *ems           pointer to block to be mapped
  144. *               void **memPtr           pointer to conventional memory ptr
  145. *
  146. * Returns:      MIDAS error code.
  147. *               Pointer to the conventional memory area where the block
  148. *               was mapped is stored in *memPtr, NULL if failure.
  149. *
  150. \****************************************************************************/
  151.  
  152. int CALLING emsMap(emsBlock *ems, void **memPtr);
  153.  
  154.  
  155.  
  156. /****************************************************************************\
  157. *
  158. * Function:     int emsSave(void);
  159. *
  160. * Description:  Saves the EMS status. To be used by TempoTimer. Can only be
  161. *               called once.
  162. *
  163. * Returns:      MIDAS error code
  164. *
  165. \****************************************************************************/
  166.  
  167. int CALLING emsSave(void);
  168.  
  169.  
  170.  
  171. /****************************************************************************\
  172. *
  173. * Function:     int emsRestore(void);
  174. *
  175. * Description:  Restores EMS status saved with emsSave(). To be used by
  176. *               TempoTimer. Can only be called once.
  177. *
  178. * Returns:      MIDAS error code
  179. *
  180. \****************************************************************************/
  181.  
  182. int CALLING emsRestore(void);
  183.  
  184.  
  185.  
  186.  
  187. /****************************************************************************\
  188. *
  189. * Function:     int emsAllocPages(emsHandle **emsh);
  190. *
  191. * Description:  Allocates 4 pages of EMS memory to a handle. Used internally
  192. *               by EMS heap manager.
  193. *
  194. * Returns:      MIDAS error code.
  195. *               Pointer to a emsHandle structure for the pages stored in
  196. *               *emsh, NULL if failure.
  197. *
  198. \****************************************************************************/
  199.  
  200. int CALLING emsAllocPages(emsHandle **emsh);
  201.  
  202.  
  203.  
  204.  
  205. /****************************************************************************\
  206. *
  207. * Function:     int emsFreePages(emsHandle *handle);
  208. *
  209. * Description:  Deallocates an EMS handle allocated by emsAllocPages(). Used
  210. *               internally by EMS heap manager.
  211. *
  212. * Input:        emsHandle *handle       pointer to handle to be deallocated.
  213. *
  214. * Returns:      MIDAS error code
  215. *
  216. \****************************************************************************/
  217.  
  218. int CALLING emsFreePages(emsHandle *handle);
  219.  
  220.  
  221.  
  222.  
  223. /****************************************************************************\
  224. *
  225. * Function:     int emsSafe(void);
  226. *
  227. * Description:  Sets the EMS safety flag on so that the EMS heap manager
  228. *               can optimize page mappings. Until emsStopSafe() is restored,
  229. *               no other routine than emsMap() must touch the EMS page
  230. *               mappings
  231. *
  232. * Returns:      MIDAS error code
  233. *
  234. \****************************************************************************/
  235.  
  236. int CALLING emsSafe(void);
  237.  
  238.  
  239.  
  240. /****************************************************************************\
  241. *
  242. * Function:     int emsStopSafe(void);
  243. *
  244. * Description:  Sets the EMS safety flag off.
  245. *
  246. * Returns:      MIDAS error code
  247. *
  248. \****************************************************************************/
  249.  
  250. int CALLING emsStopSafe(void);
  251.  
  252.  
  253.  
  254.  
  255. /****************************************************************************\
  256. *       enum emsFunctIDs
  257. *       ----------------
  258. * Description:  ID numbers for EMS Heap Manager functions
  259. \****************************************************************************/
  260.  
  261. enum emsFunctIDs
  262. {
  263.     ID_emsInit = ID_ems,
  264.     ID_emsClose,
  265.     ID_emsAlloc,
  266.     ID_emsFree,
  267.     ID_emsMap,
  268.     ID_emsSave,
  269.     ID_emsRestore,
  270.     ID_emsAllocPages,
  271.     ID_emsFreePages,
  272.     ID_emsSafe,
  273.     ID_emsStopSafe
  274. };
  275.  
  276.  
  277. #ifdef __cplusplus
  278. }
  279. #endif
  280.  
  281.  
  282. #endif
  283.