home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / midas / ems.inc < prev    next >
Text File  |  1994-08-06  |  7KB  |  257 lines

  1. ;*    EMS.INC
  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. ;/***************************************************************************\
  16. ;*     struct emsBlock
  17. ;*     ---------------
  18. ;* Description:  Allocated EMS block structure
  19. ;\***************************************************************************/
  20.  
  21. STRUC    emsBlock
  22.     addr        DW    ?
  23.     bytes        DW    ?
  24.     next        DD    ?
  25.     prev        DD    ?
  26.     used        DW    ?
  27.     handle        DD    ?
  28. ENDS
  29.  
  30.  
  31.  
  32.  
  33. ;/***************************************************************************\
  34. ;*     struct emsHandle
  35. ;*     ----------------
  36. ;* Description:  One EMS handle consisting of four pages. Used internally by
  37. ;*         heap manager.
  38. ;\***************************************************************************/
  39.  
  40. STRUC    emsHandle
  41.     handle        DW    ?
  42.     block        DD    ?
  43.     next        DD    ?
  44.     prev        DD    ?
  45. ENDS
  46.  
  47.  
  48.  
  49.  
  50. ;/***************************************************************************\
  51. ;*
  52. ;* Function:     int emsInit(int *emmOK);
  53. ;*
  54. ;* Description:  Initializes EMS heap. Must be called before other EMS heap
  55. ;*               manager functions.
  56. ;*
  57. ;* Input:        int *emmOK              pointer to variable containing EMM
  58. ;*                                       status
  59. ;*
  60. ;* Returns:      MIDAS error code.
  61. ;*               *emmOK contains 1 if Expanded Memory Manager was found (EMS
  62. ;*               initialized succesfully) or 0 if not. Note that the lack
  63. ;*               of Expanded Memory Manager is _not_ an error.
  64. ;*
  65. ;\***************************************************************************/
  66.  
  67. GLOBAL  LANG emsInit : far
  68.  
  69.  
  70.  
  71. ;/***************************************************************************\
  72. ;*
  73. ;* Function:     int emsClose(void);
  74. ;*
  75. ;* Description:  Uninitializes EMS heap freeing all allocated blocks. Must be
  76. ;*               called before program exits if emsInit() has been called.
  77. ;*
  78. ;* Returns:      MIDAS error code
  79. ;*
  80. ;\***************************************************************************/
  81.  
  82. GLOBAL  LANG emsClose : far
  83.  
  84.  
  85.  
  86. ;/***************************************************************************\
  87. ;*
  88. ;* Function:     int emsAlloc(ushort bytes, emsBlock **ems);
  89. ;*
  90. ;* Description:  Allocates an EMS memory block
  91. ;*
  92. ;* Input:        ushort bytes            number of bytes to be allocated
  93. ;*               emsBlock **ems          Pointer to EMS Block pointer
  94. ;*
  95. ;* Returns:      MIDAS error code.
  96. ;*               EMS block pointer stored in *ems, NULL if failure
  97. ;*
  98. ;\***************************************************************************/
  99.  
  100. GLOBAL  LANG emsAlloc : far
  101.  
  102.  
  103.  
  104. ;/***************************************************************************\
  105. ;*
  106. ;* Function:     int emsFree(emsBlock *ems);
  107. ;*
  108. ;* Description:  Deallocates an EMS block allocated with emsAlloc
  109. ;*
  110. ;* Input:        emsBlock *ems           pointer to block to be deallocated
  111. ;*
  112. ;* Returns:      MIDAS error code
  113. ;*
  114. ;\***************************************************************************/
  115.  
  116. GLOBAL  LANG emsFree : far
  117.  
  118.  
  119.  
  120.  
  121. ;/***************************************************************************\
  122. ;*
  123. ;* Function:     int emsMap(emsBlock *ems, void **memPtr);
  124. ;*
  125. ;* Description:  Maps an EMS block to conventional memory.
  126. ;*
  127. ;* Input:        emsBlock *ems           pointer to block to be mapped
  128. ;*               void **memPtr           pointer to conventional memory ptr
  129. ;*
  130. ;* Returns:      MIDAS error code.
  131. ;*               Pointer to the conventional memory area where the block
  132. ;*               was mapped is stored in **memPtr, NULL if failure.
  133. ;*
  134. ;\***************************************************************************/
  135.  
  136. GLOBAL  LANG emsMap : far
  137.  
  138.  
  139.  
  140. ;/***************************************************************************\
  141. ;*
  142. ;* Function:     int emsSave(void);
  143. ;*
  144. ;* Description:  Saves the EMS status. To be used by TempoTimer. Can only be
  145. ;*               called once.
  146. ;*
  147. ;* Returns:      MIDAS error code
  148. ;*
  149. ;\***************************************************************************/
  150.  
  151. GLOBAL  LANG emsSave : far
  152.  
  153.  
  154.  
  155. ;/***************************************************************************\
  156. ;*
  157. ;* Function:     int emsRestore(void);
  158. ;*
  159. ;* Description:  Restores EMS status saved with emsSave(). To be used by
  160. ;*               TempoTimer. Can only be called once.
  161. ;*
  162. ;* Returns:      MIDAS error code
  163. ;*
  164. ;\***************************************************************************/
  165.  
  166. GLOBAL  LANG emsRestore : far
  167.  
  168.  
  169.  
  170.  
  171. ;/***************************************************************************\
  172. ;*
  173. ;* Function:     int emsAllocPages(emsHandle **emsh);
  174. ;*
  175. ;* Description:  Allocate 4 pages of EMS memory to a handle. Used internally
  176. ;*               by EMS heap manager.
  177. ;*
  178. ;* Returns:      MIDAS error code.
  179. ;*               Pointer to a emsHandle structure for the pages stored in
  180. ;*               *emsh, NULL if failure.
  181. ;*
  182. ;\***************************************************************************/
  183.  
  184. GLOBAL  LANG emsAllocPages : far
  185.  
  186.  
  187.  
  188.  
  189. ;/***************************************************************************\
  190. ;*
  191. ;* Function:     int emsFreePages(emsHandle *handle);
  192. ;*
  193. ;* Description:  Deallocates an EMS handle allocated by emsAllocPages(). Used
  194. ;*               internally by EMS heap manager.
  195. ;*
  196. ;* Input:        emsHandle *handle       pointer to handle to be deallocated.
  197. ;*
  198. ;* Returns:      MIDAS error code
  199. ;*
  200. ;\***************************************************************************/
  201.  
  202. GLOBAL  LANG emsFreePages : far
  203.  
  204.  
  205.  
  206.  
  207. ;/***************************************************************************\
  208. ;*
  209. ;* Function:     int emsSafe(void);
  210. ;*
  211. ;* Description:  Sets the EMS safety flag on so that the EMS heap manager
  212. ;*               can optimize page mappings. Until emsStopSafe() is restored,
  213. ;*               no other routine than emsMap() must touch the EMS page
  214. ;*               mappings
  215. ;*
  216. ;* Returns:      MIDAS error code
  217. ;*
  218. ;\***************************************************************************/
  219.  
  220. GLOBAL  LANG emsSafe : far
  221.  
  222.  
  223.  
  224. ;/***************************************************************************\
  225. ;*
  226. ;* Function:     int emsStopSafe(void);
  227. ;*
  228. ;* Description:  Sets the EMS safety flag off.
  229. ;*
  230. ;* Returns:      MIDAS error code
  231. ;*
  232. ;\***************************************************************************/
  233.  
  234. GLOBAL  LANG emsStopSafe : far
  235.  
  236.  
  237.  
  238.  
  239. ;/***************************************************************************\
  240. ;*       enum emsFunctIDs
  241. ;*       ----------------
  242. ;* Description:  ID numbers for EMS Heap Manager functions
  243. ;\***************************************************************************/
  244.  
  245. ENUM    emsFunctIDs \
  246.         ID_emsInit = ID_ems, \
  247.         ID_emsClose, \
  248.         ID_emsAlloc, \
  249.         ID_emsFree, \
  250.         ID_emsMap, \
  251.         ID_emsSave, \
  252.         ID_emsRestore, \
  253.         ID_emsAllocPages, \
  254.         ID_emsFreePages, \
  255.         ID_emsSafe, \
  256.         ID_emsStopSafe
  257.