]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_hc.c
farcoreleft() is now flexible <3 going to code later like a few days from now later
[16.git] / src / lib / 16_hc.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 /*\r
23         heap test stuff\r
24 */\r
25 \r
26 #include "src/lib/16_hc.h"\r
27 #include <malloc.h>\r
28 \r
29 //from ftp://213.85.246.177/pub/FreeBSD/ports/archivers/arj/work/arj-3.10.22/environ.c\r
30 #if 0\r
31 //#ifdef __WATCOMC__\r
32 long HC_Newfarcoreleft()\r
33 {\r
34         void __huge *hp;                static long rc=736L;    long s_rc;\r
35 \r
36         s_rc=rc;        rc+=2L;\r
37         do\r
38                 hp=halloc(rc-=2L, 1024);\r
39         while(hp==NULL&&rc>0L);\r
40         if(hp!=NULL)\r
41                 hfree(hp);\r
42         if(rc<s_rc)\r
43                 return(rc*1024L);\r
44         do\r
45         {\r
46                 hp=halloc(rc+=16L, 1024);\r
47                 if(hp!=NULL)\r
48                         hfree(hp);\r
49         } while(hp!=NULL);\r
50         return((rc-16L)*1024L);\r
51 }\r
52 #endif\r
53 \r
54 void\r
55 #ifdef __BORLANDC__\r
56  *\r
57 #endif\r
58 #ifdef __WATCOMC__\r
59  __near*\r
60 #endif\r
61 HC_LargestFreeBlock(size_t* Size)\r
62 {\r
63         size_t s0, s1;\r
64 #ifdef __BORLANDC__\r
65         void * p;\r
66 #endif\r
67 #ifdef __WATCOMC__\r
68         void __near* p;\r
69 #endif\r
70 \r
71         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
72 #ifdef __BORLANDC__\r
73         while (s0 && (p = malloc(s0)) == NULL)\r
74 #endif\r
75 #ifdef __WATCOMC__\r
76         while (s0 && (p = _nmalloc(s0)) == NULL)\r
77 #endif\r
78                 s0 >>= 1;\r
79 \r
80         if (p)\r
81 #ifdef __BORLANDC__\r
82                 free(p);\r
83 #endif\r
84 #ifdef __WATCOMC__\r
85                 _nfree(p);\r
86 #endif\r
87 \r
88         s1 = s0 >> 1;\r
89         while (s1)\r
90         {\r
91 #ifdef __BORLANDC__\r
92                 if ((p = malloc(s0 + s1)) != NULL)\r
93 #endif\r
94 #ifdef __WATCOMC__\r
95                 if ((p = _nmalloc(s0 + s1)) != NULL)\r
96 #endif\r
97                 {\r
98                         s0 += s1;\r
99 #ifdef __BORLANDC__\r
100                         free(p);\r
101 #endif\r
102 #ifdef __WATCOMC__\r
103                         _nfree(p);\r
104 #endif\r
105                 }\r
106         s1 >>= 1;\r
107         }\r
108 #ifdef __BORLANDC__\r
109         while (s0 && (p = malloc(s0)) == NULL)\r
110 #endif\r
111 #ifdef __WATCOMC__\r
112         while (s0 && (p = _nmalloc(s0)) == NULL)\r
113 #endif\r
114                 s0 ^= s0 & -s0;\r
115 \r
116         *Size = s0;\r
117         return p;\r
118 }\r
119 \r
120 size_t HC_coreleft(void)\r
121 {\r
122         size_t total = 0;\r
123         void __near* pFirst = NULL;\r
124         void __near* pLast = NULL;\r
125         for(;;)\r
126         {\r
127                 size_t largest;\r
128                 void __near* p = (void __near *)HC_LargestFreeBlock(&largest);\r
129                 if (largest < sizeof(void __near*))\r
130                 {\r
131                         if (p != NULL)\r
132 #ifdef __BORLANDC__\r
133                         free(p);\r
134 #endif\r
135 #ifdef __WATCOMC__\r
136                         _nfree(p);\r
137 #endif\r
138                         break;\r
139                 }\r
140                 *(void __near* __near*)p = NULL;\r
141                 total += largest;\r
142                 if (pFirst == NULL)\r
143                         pFirst = p;\r
144 \r
145                 if (pLast != NULL)\r
146                         *(void __near* __near*)pLast = p;\r
147                 pLast = p;\r
148         }\r
149 \r
150         while (pFirst != NULL)\r
151         {\r
152                 void __near* p = *(void __near* __near*)pFirst;\r
153 #ifdef __BORLANDC__\r
154                 free(pFirst);\r
155 #endif\r
156 #ifdef __WATCOMC__\r
157                 _nfree(pFirst);\r
158 #endif\r
159                 pFirst = p;\r
160         }\r
161         return total;\r
162 }\r
163 \r
164 void far* HC_LargestFarFreeBlock(unsigned long* Size)\r
165 {\r
166         unsigned long s0, s1;\r
167         void far* p;\r
168 \r
169         s0 = ~(unsigned long)0 ^ (~(unsigned long)0 >> 1);\r
170         while (s0 && (p = _fmalloc(s0)) == NULL)\r
171                 s0 >>= 1;\r
172 \r
173         if (p)\r
174                 _ffree(p);\r
175 \r
176         s1 = s0 >> 1;\r
177         while (s1)\r
178         {\r
179                 if ((p = _fmalloc(s0 + s1)) != NULL)\r
180                 {\r
181                         s0 += s1;\r
182                         _ffree(p);\r
183                 }\r
184         s1 >>= 1;\r
185         }\r
186         while (s0 && (p = _fmalloc(s0)) == NULL)\r
187                 s0 ^= s0 & -s0;\r
188 \r
189         *Size = s0;\r
190         return p;\r
191 }\r
192 \r
193 unsigned long HC_farcoreleft(void)\r
194 {\r
195         unsigned long total = 0UL;\r
196         void far* pFirst = NULL;\r
197         void far* pLast = NULL;\r
198         for(;;)\r
199         {\r
200                 unsigned long largest;\r
201                 void far* p = HC_LargestFarFreeBlock(&largest);\r
202                 if (largest < sizeof(void far*))\r
203                 {\r
204                         if (p != NULL)\r
205                         _ffree(p);\r
206                         break;\r
207                 }\r
208                 *(void far* far*)p = NULL;\r
209                 total += largest;\r
210                 if (pFirst == NULL)\r
211                         pFirst = p;\r
212 \r
213                 if (pLast != NULL)\r
214                         *(void far* far*)pLast = p;\r
215                 pLast = p;\r
216         }\r
217 \r
218         while (pFirst != NULL)\r
219         {\r
220                 void far* p = *(void far* far*)pFirst;\r
221                 _ffree(pFirst);\r
222                 pFirst = p;\r
223         }\r
224         return total;\r
225 }\r
226 \r
227 #ifdef __WATCOMC__\r
228 /*void huge* LargestHugeFreeBlock(size_t* Size)\r
229 {\r
230         size_t s0, s1;\r
231         void huge* p;\r
232 \r
233         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
234         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
235                 s0 >>= 1;\r
236 \r
237         if (p)\r
238                 hfree(p);\r
239 \r
240         s1 = s0 >> 1;\r
241         while (s1)\r
242         {\r
243                 if ((p = halloc((dword)(s0 + s1), 1)) != NULL)\r
244                 {\r
245                         s0 += s1;\r
246                         hfree(p);\r
247                 }\r
248         s1 >>= 1;\r
249         }\r
250         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
251                 s0 ^= s0 & -s0;\r
252 \r
253         *Size = s0;\r
254         return p;\r
255 }\r
256 \r
257 size_t _hugecoreleft(void)\r
258 {\r
259         size_t total = 0;\r
260         void huge* pFirst = NULL;\r
261         void huge* pLast = NULL;\r
262         for(;;)\r
263         {\r
264                 size_t largest;\r
265                 void huge* p = LargestHugeFreeBlock(&largest);\r
266                 if (largest < sizeof(void huge*))\r
267                 {\r
268                         if (p != NULL)\r
269                         hfree(p);\r
270                         break;\r
271                 }\r
272                 *(void huge* huge*)p = NULL;\r
273                 total += largest;\r
274                 if (pFirst == NULL)\r
275                         pFirst = p;\r
276 \r
277                 if (pLast != NULL)\r
278                         *(void huge* huge*)pLast = p;\r
279                 pLast = p;\r
280         }\r
281 \r
282         while (pFirst != NULL)\r
283         {\r
284                 void huge* p = *(void huge* huge*)pFirst;\r
285                 hfree(pFirst);\r
286                 pFirst = p;\r
287         }\r
288         return total;\r
289 }\r
290 \r
291 void __based(__self)* LargestBasedFreeBlock(size_t* Size)\r
292 {\r
293         __segment segu;\r
294         size_t s0, s1;\r
295         void __based(__self)* p;\r
296 \r
297         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
298         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
299                 s0 >>= 1;\r
300 \r
301         if (p)\r
302                 _ffree(p);\r
303 \r
304         s1 = s0 >> 1;\r
305         while (s1)\r
306         {\r
307                 if ((p = _bmalloc(segu, s0 + s1)) != NULL)\r
308                 {\r
309                         s0 += s1;\r
310                         _ffree(p);\r
311                 }\r
312         s1 >>= 1;\r
313         }\r
314         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
315                 s0 ^= s0 & -s0;\r
316 \r
317         *Size = s0;\r
318         return p;\r
319 }\r
320 \r
321 size_t _basedcoreleft(void)\r
322 {\r
323         __segment segu;\r
324         size_t total = 0;\r
325         void __based(segu)* pFirst = NULL;\r
326         void __based(segu)* pLast = NULL;\r
327         // allocate based heap\r
328         segu = _bHC_heapseg( 1024 );\r
329         if( segu == _NULLSEG ) {\r
330                 printf( "Unable to allocate based heap\n" );\r
331                 return 0;\r
332 \r
333         }\r
334         else\r
335 \r
336         for(;;)\r
337         {\r
338                 size_t largest;\r
339                 void __based(segu)* p = LargestBasedFreeBlock(&largest);\r
340                 if (largest < sizeof(void far*))\r
341                 {\r
342                         if (p != NULL)\r
343                         _ffree(p);\r
344                         break;\r
345                 }\r
346                 *(void far* far*)p = NULL;\r
347                 total += largest;\r
348                 if (pFirst == NULL)\r
349                         pFirst = p;\r
350 \r
351                 if (pLast != NULL)\r
352                         *(void far* far*)pLast = p;\r
353                 pLast = p;\r
354         }\r
355 \r
356         while (pFirst != NULL)\r
357         {\r
358                 void far* p = *(void far* far*)pFirst;\r
359                 _ffree(pFirst);\r
360                 pFirst = p;\r
361         }\r
362         return total;\r
363 }*/\r
364 #if 0\r
365 size_t HC_GetFreeSize(void)\r
366 {\r
367         struct _heapinfo h_info;\r
368         int heap_status;\r
369         size_t h_free=0, h_total=0, h_used=0;\r
370 \r
371         h_info._pentry = NULL;\r
372         for(;;) {\r
373                 heap_status = _heapwalk( &h_info );\r
374                 if( heap_status != _HEAPOK ) break;\r
375                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
376                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
377                 h_total += h_info._size;\r
378         }\r
379         HCL_heapstat0(heap_status);\r
380         return h_free;\r
381 }\r
382 #endif\r
383 \r
384 unsigned long HC_GetFarFreeSize(void)\r
385 {\r
386         struct _heapinfo fh_info;\r
387         int heap_status;\r
388         unsigned long fh_free=0, fh_total=0, fh_used=0;\r
389 \r
390         fh_info._pentry = NULL;\r
391         for(;;) {\r
392                 heap_status = _fheapwalk( &fh_info );\r
393                 if( heap_status != _HEAPOK ) break;\r
394                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
395                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
396                 fh_total += fh_info._size;\r
397         }\r
398         HCL_heapstat0(heap_status);\r
399         return fh_free;\r
400 }\r
401 \r
402 size_t HC_GetNearFreeSize(void)\r
403 {\r
404         struct _heapinfo nh_info;\r
405         int heap_status;\r
406         size_t nh_free=0, nh_total=0, nh_used=0;\r
407 \r
408         nh_info._pentry = NULL;\r
409         for(;;) {\r
410                 heap_status = _nheapwalk( &nh_info );\r
411                 if( heap_status != _HEAPOK ) break;\r
412                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
413                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
414                 nh_total += nh_info._size;\r
415         }\r
416         HCL_heapstat0(heap_status);\r
417         return nh_free;\r
418 }\r
419 \r
420 void HC_heapdump(global_game_variables_t *gvar)\r
421 {\r
422         struct _heapinfo fh_info, nh_info;//, h_info;\r
423         int heap_status;\r
424         size_t nh_free, fh_free, nh_total, fh_total, nh_used, fh_used;//,       h_free, h_total, h_used;\r
425         byte    scratch[1024],str[16];\r
426 \r
427         HC_OpenDebug(gvar);\r
428 \r
429 #if 0\r
430         strcpy(scratch,"\n      == default ==\n\n");\r
431         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
432         h_info._pentry = NULL;\r
433         h_free=0; h_total=0; h_used=0;\r
434         for(;;) {\r
435                 heap_status = _heapwalk( &h_info );\r
436                 if( heap_status != _HEAPOK ) break;\r
437                 strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
438                 sprintf(str, "%Fp", h_info._pentry); //ultoa((dword)h_info._pentry,str,16);\r
439                         strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
440                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
441                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
442                 h_total += h_info._size;\r
443                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
444         }\r
445         HCL_heapstat(gvar, heap_status, &scratch);\r
446 #endif\r
447 \r
448         //near\r
449         strcpy(scratch,"\n      == near ==\n\n");\r
450         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
451         nh_info._pentry = NULL;\r
452         nh_free=0; nh_total=0; nh_used=0;\r
453         for(;;) {\r
454                 heap_status = _nheapwalk( &nh_info );\r
455                 if( heap_status != _HEAPOK ) break;\r
456                 strcpy(scratch,"  "); strcat(scratch,(nh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
457                 sprintf(str, "%Fp", nh_info._pentry); //ultoa((dword)nh_info._pentry,str,16);\r
458                         strcat(scratch,str); strcat(scratch," of size "); ultoa(nh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
459 /*              printf( "  %s block at %Fp of size %4.4X\n",\r
460 (nh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
461 nh_info._pentry, nh_info._size );*/\r
462                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
463                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
464                 nh_total += nh_info._size;\r
465                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
466         }\r
467         HCL_heapstat(gvar, heap_status, &scratch);\r
468 \r
469         //far\r
470         strcpy(scratch,"\n      == far ==\n\n");\r
471         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
472         fh_info._pentry = NULL;\r
473         fh_free=0; fh_total=0; fh_used=0;\r
474         for(;;) {\r
475                 heap_status = _fheapwalk( &fh_info );\r
476                 if( heap_status != _HEAPOK ) break;\r
477                 strcpy(scratch,"  "); strcat(scratch,(fh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
478                 sprintf(str, "%Fp", fh_info._pentry); //ultoa((dword)fh_info._pentry,str,16);\r
479                         strcat(scratch,str); strcat(scratch," of size "); ultoa(fh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
480                 /*printf( "  %s block at %Fp of size %4.4X\n",\r
481 (fh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
482 fh_info._pentry, fh_info._size );*/\r
483                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
484                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
485                 fh_total += fh_info._size;\r
486                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
487         }\r
488         HCL_heapstat(gvar, heap_status, &scratch);\r
489 \r
490         strcpy(scratch,"\n");\r
491         strcat(scratch,kittengets(2,0,"Memory Type         Total      Used       Free\n"));\r
492         strcat(scratch,"----------------  --------   --------   --------\n");\r
493 //      printmeminfoline(&scratch, "Default", h_total, h_used, h_free);\r
494         printmeminfoline(&scratch, "Near", nh_total, nh_used, nh_free);\r
495         printmeminfoline(&scratch, "Far", fh_total, fh_used, fh_free);\r
496         strcat(scratch,"----------------  --------   --------   --------\n");\r
497         strcat(scratch,"HC_coreleft = ");                       ultoa((dword)HC_coreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
498         strcat(scratch,"HC_farcoreleft = ");                    ultoa((dword)HC_farcoreleft(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
499 //      strcat(scratch,"HC_Newfarcoreleft = ");         ultoa((dword)HC_Newfarcoreleft(),str,10);               strcat(scratch,str);    strcat(scratch,"\n");\r
500 //      strcat(scratch,"HC_GetFreeSize = ");            ultoa((dword)HC_GetFreeSize(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
501         strcat(scratch,"HC_GetNearFreeSize = ");        ultoa((dword)HC_GetNearFreeSize(),str,10);      strcat(scratch,str);    strcat(scratch,"\n");\r
502         strcat(scratch,"HC_GetFarFreeSize = ");         ultoa((dword)HC_GetFarFreeSize(),str,10);       strcat(scratch,str);    strcat(scratch,"\n");\r
503         strcat(scratch,"coreleft = ");                          ultoa((dword)coreleft(),str,10);                                strcat(scratch,str);    strcat(scratch,"\n");\r
504         strcat(scratch,"farcoreleft = ");                       ultoa((dword)farcoreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
505         strcat(scratch,"stackavail = ");                        ultoa((dword)stackavail(),str,10);                      strcat(scratch,str);    strcat(scratch,"\n");\r
506         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
507         HC_CloseDebug(gvar);\r
508 }\r
509 \r
510 void HCL_heapstat(global_game_variables_t *gvar, int heap_status, byte *str)\r
511 {\r
512         switch( heap_status ) {\r
513                 case _HEAPEND:\r
514                         strcpy((str),"OK - end of heap\n");\r
515                 break;\r
516                 case _HEAPEMPTY:\r
517                         strcpy((str),"OK - heap is empty\n");\r
518 \r
519                 break;\r
520                 case _HEAPBADBEGIN:\r
521                         strcpy((str),"ERROR - heap is damaged\n");\r
522                 break;\r
523                 case _HEAPBADPTR:\r
524                         strcpy((str),"ERROR - bad pointer to heap\n");\r
525                 break;\r
526                 case _HEAPBADNODE:\r
527                         strcpy((str),"ERROR - bad node in heap\n");\r
528         }\r
529         write(gvar->handle.heaphandle,(str),strlen((str)));\r
530 }\r
531 \r
532 void HCL_heapstat0(int heap_status)\r
533 {\r
534         switch( heap_status ) {\r
535                 case _HEAPEND:\r
536                         //printf("OK - end of heap\n");\r
537                 break;\r
538                 case _HEAPEMPTY:\r
539                         //printf("OK - heap is empty\n");\r
540                 break;\r
541                 case _HEAPBADBEGIN:\r
542                         printf("ERROR - heap is damaged\n");\r
543                 break;\r
544                 case _HEAPBADPTR:\r
545                         printf("ERROR - bad pointer to heap\n");\r
546                 break;\r
547                 case _HEAPBADNODE:\r
548                         printf("ERROR - bad node in heap\n");\r
549         }\r
550 }\r
551 \r
552 unsigned long farcoreleft()\r
553 {\r
554 //----  _fheapgrow();\r
555         return HC_farcoreleft();\r
556 //stack overflows       return HC_GetFarFreeSize();\r
557 }\r
558 \r
559 unsigned long coreleft()\r
560 {\r
561         _nheapgrow();\r
562         return _memavl();\r
563 //      return HC_GetNearFreeSize();\r
564 }\r
565 #endif\r
566 \r
567 /*\r
568 ============================\r
569 =\r
570 = HC_OpenDebug / HC_CloseDebug\r
571 =\r
572 = Opens a binary file with the handle "heaphandle"\r
573 =\r
574 ============================\r
575 */\r
576 void HC_OpenDebug(global_game_variables_t *gvar)\r
577 {\r
578 #ifdef __BORLANDC__\r
579         unlink("heap.16b");\r
580         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
581 #endif\r
582 #ifdef __WATCOMC__\r
583         unlink("heap.16w");\r
584         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
585 #endif\r
586 }\r
587 \r
588 void HC_CloseDebug(global_game_variables_t *gvar)\r
589 {\r
590         close(gvar->handle.heaphandle);\r
591 \r
592 #ifdef __BORLANDC__\r
593         strcpy(gvar->handle.heapdumpfilename, "heap.16b");\r
594 #endif\r
595 #ifdef __WATCOMC__\r
596         strcpy(gvar->handle.heapdumpfilename, "heap.16w");\r
597 #endif\r
598 }\r