EURO_MEM.CPP 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "eurodefs.h"
  5. #include "euro_fxd.h"
  6. #include "euro_sym.h"
  7. #include "euro_def.h"
  8. #include "euro_var.h"
  9. #include "mallocx.h"
  10. //********************************************************************************************************************************
  11. void DeAllocateMemory( BYTE* MemAlloc )
  12. {
  13. if ( MemAlloc != 0 )
  14. freex( MemAlloc );
  15. if ( EUROverbose != 0 )
  16. {
  17. printf ("þ Memory check: %d\n",get_mem_info() );
  18. fflush(stdout);
  19. }
  20. }
  21. //********************************************************************************************************************************
  22. void Euro96_MemoryInitialise()
  23. {
  24. TexturePageMemHandle = 0;
  25. TextStringMemHandle = 0;
  26. }
  27. //********************************************************************************************************************************
  28. void AllocateDisplayBuffers()
  29. {
  30. EuroPseudoBuffer = (BYTE *) mallocx( 307200);
  31. if ( EuroPseudoBuffer == 0 )
  32. {
  33. printf ("þ Unable to allocate memory for Pseudo buffer.\n");
  34. fflush(stdout);
  35. }
  36. else
  37. {
  38. if ( EUROverbose != 0 )
  39. {
  40. printf ("þ Memory allocated for Pseudo buffer.\n");
  41. fflush(stdout);
  42. printf ("þ Memory check: %d\n",get_mem_info() );
  43. fflush(stdout);
  44. }
  45. }
  46. EuroBackgroundBuffer = (BYTE *) mallocx( 307200);
  47. if ( EuroBackgroundBuffer == 0 )
  48. {
  49. printf ("þ Unable to allocate memory for Background buffer.\n");
  50. fflush(stdout);
  51. }
  52. else
  53. {
  54. if ( EUROverbose != 0 )
  55. {
  56. printf ("þ Memory allocated for Background buffer.\n");
  57. fflush(stdout);
  58. printf ("þ Memory check: %d\n",get_mem_info() );
  59. fflush(stdout);
  60. }
  61. }
  62. }
  63. //********************************************************************************************************************************
  64. void DeAllocateDisplayBuffers()
  65. {
  66. if ( EuroBackgroundBuffer != 0 )
  67. {
  68. DeAllocateMemory(EuroBackgroundBuffer);
  69. if ( EUROverbose != 0 )
  70. {
  71. printf ("þ Memory for Background buffer DeAllocated.\n");
  72. printf ("þ Memory check: %d\n",get_mem_info() );
  73. fflush(stdout);
  74. }
  75. }
  76. else
  77. {
  78. printf ("þ ERROR.. Unable to deAllocate memory for Background Buffer (This could cause a crash).\n");
  79. fflush(stdout);
  80. }
  81. if ( EuroPseudoBuffer != 0 )
  82. {
  83. DeAllocateMemory(EuroPseudoBuffer);
  84. if ( EUROverbose != 0 )
  85. {
  86. printf ("þ Memory for Pseudo buffer DeAllocated.\n");
  87. fflush(stdout);
  88. printf ("þ Memory check: %d\n",get_mem_info() );
  89. fflush(stdout);
  90. }
  91. }
  92. else
  93. {
  94. printf ("þ ERROR.. Unable to deAllocate memory for Pseudo Buffer (This could cause a crash).\n");
  95. fflush(stdout);
  96. }
  97. }
  98. //********************************************************************************************************************************
  99. BYTE* AllocateTexturePageMemory( unsigned char NoOfTexturePages, texture_info *texture )
  100. {
  101. unsigned int size = texture->page_width*texture->page_height*NoOfTexturePages;
  102. TexturePages = (BYTE *) mallocx( size );
  103. if ( TexturePages==0 )
  104. {
  105. printf ("þ ERROR.. Unable to reserve memory for Texture Pages (This could cause a crash).\n");
  106. fflush(stdout);
  107. TexturePagesAvailable = 0;
  108. }
  109. else
  110. TexturePagesAvailable = NoOfTexturePages;
  111. if ( EUROverbose != 0 )
  112. {
  113. printf ("þ Memory allocated for Texture Pages.\n");
  114. fflush(stdout);
  115. printf ("þ Memory check: %d\n",get_mem_info() );
  116. fflush(stdout);
  117. }
  118. return ( TexturePages );
  119. }
  120. //********************************************************************************************************************************
  121. void DeAllocateTexturePages()
  122. {
  123. if ( TexturePageMemHandle != 0 )
  124. {
  125. DeAllocateMemory(TexturePageMemHandle);
  126. if ( EUROverbose != 0 )
  127. {
  128. printf ("þ Memory for Texture Pages DeAllocated.\n");
  129. fflush(stdout);
  130. printf ("þ Memory check: %d\n",get_mem_info() );
  131. fflush(stdout);
  132. }
  133. }
  134. else
  135. {
  136. printf ("þ ERROR.. Unable to deAllocate memory for Texture Pages (This could cause a crash).\n");
  137. fflush(stdout);
  138. }
  139. }
  140. //********************************************************************************************************************************
  141. BYTE* AllocateTextStringMemory()
  142. {
  143. TextStrings = (BYTE *) mallocx( TEXT_STRING_BUFFER_LEN );
  144. if ( TextStrings==0 )
  145. {
  146. printf ("þ Unable to allocate memory for Text buffer.\n");
  147. fflush(stdout);
  148. }
  149. else
  150. {
  151. printf ("þ Memory allocated for Text buffer.\n");
  152. fflush(stdout);
  153. {
  154. if ( EUROverbose != 0 )
  155. printf ("þ Memory check: %d\n",get_mem_info() );
  156. fflush(stdout);
  157. }
  158. }
  159. return ( TextStrings );
  160. }
  161. //********************************************************************************************************************************
  162. //
  163. //int DisplayFree()
  164. // {
  165. // int M8;
  166. // int buff[20];
  167. // union REGS regs;
  168. // struct SREGS sregs;
  169. //
  170. // memset(&sregs,0,sizeof(sregs)); //clr sregs
  171. // regs.x.eax=0x500; //DPMI get free mem info
  172. // sregs.es=FP_SEG(buff); //Gets SELECTOR in fact.
  173. // regs.x.edi=FP_OFF(buff); //offset from selector.
  174. // int386x(0x31,&regs,&regs,&sregs); //Get free memory info
  175. //
  176. // M8=( (buff[7]*4096) >= MEM8 );
  177. //
  178. // if (setup.verbose!=0)
  179. // {
  180. // printf("\nLargest block: %d\n",buff[0]);
  181. // printf("Total free : %d\n\n",buff[7]*4096);
  182. // if (M8)
  183. // puts("Initialising 8 meg game");
  184. // else
  185. // {
  186. // puts("Initialising 4 meg game");
  187. // printf("Need to free %d more bytes to run 8 meg version\n",MEM8-(buff[7]*4096) );
  188. // }
  189. // }
  190. // return (M8);
  191. // }
  192. //
  193. //********************************************************************************************************************************