]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_hc.c
i feel horrendous! i should stop! i fixed up showmemorydetail function ^^. and initia...
[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 //from: https://stackoverflow.com/questions/14386856/c-check-available-ram\r
55 void\r
56 #ifdef __BORLANDC__\r
57  *\r
58 #endif\r
59 #ifdef __WATCOMC__\r
60  __near*\r
61 #endif\r
62 HC_LargestFreeBlock(size_t* Size)\r
63 {\r
64         size_t s0, s1;\r
65 #ifdef __BORLANDC__\r
66         void * p;\r
67 #endif\r
68 #ifdef __WATCOMC__\r
69         void __near* p;\r
70 #endif\r
71 \r
72         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
73         while (s0 && (p = _nmalloc(s0)) == NULL)\r
74                 s0 >>= 1;\r
75 \r
76         if (p)\r
77                 _nfree(p);\r
78 \r
79         s1 = s0 >> 1;\r
80         while (s1)\r
81         {\r
82                 if ((p = _nmalloc(s0 + s1)) != NULL)\r
83                 {\r
84                         s0 += s1;\r
85                         _nfree(p);\r
86                 }\r
87         s1 >>= 1;\r
88         }\r
89         while (s0 && (p = _nmalloc(s0)) == NULL)\r
90                 s0 ^= s0 & -s0;\r
91 \r
92         *Size = s0;\r
93         return p;\r
94 }\r
95 \r
96 //from: https://stackoverflow.com/questions/14386856/c-check-available-ram\r
97 size_t HC_coreleft(void)\r
98 {\r
99         size_t total = 0;\r
100         void __near* pFirst = NULL;\r
101         void __near* pLast = NULL;\r
102         for(;;)\r
103         {\r
104                 size_t largest;\r
105                 void __near* p = (void __near *)HC_LargestFreeBlock(&largest);\r
106                 if (largest < sizeof(void __near*))\r
107                 {\r
108                         if (p != NULL)\r
109                         _nfree(p);\r
110                         break;\r
111                 }\r
112                 *(void __near* __near*)p = NULL;\r
113                 total += largest;\r
114                 if (pFirst == NULL)\r
115                         pFirst = p;\r
116 \r
117                 if (pLast != NULL)\r
118                         *(void __near* __near*)pLast = p;\r
119                 pLast = p;\r
120         }\r
121 \r
122         while (pFirst != NULL)\r
123         {\r
124                 void __near* p = *(void __near* __near*)pFirst;\r
125                 _nfree(pFirst);\r
126                 pFirst = p;\r
127         }\r
128         return total;\r
129 }\r
130 \r
131 //far version of above\r
132 void far* HC_LargestFarFreeBlock(unsigned long* Size)\r
133 {\r
134         unsigned long s0, s1;\r
135         void far* p;\r
136 \r
137         s0 = ~(unsigned long)0 ^ (~(unsigned long)0 >> 1);\r
138         while (s0 && (p = _fmalloc(s0)) == NULL)\r
139                 s0 >>= 1;\r
140 \r
141         if (p)\r
142                 _ffree(p);\r
143 \r
144         s1 = s0 >> 1;\r
145         while (s1)\r
146         {\r
147                 if ((p = _fmalloc(s0 + s1)) != NULL)\r
148                 {\r
149                         s0 += s1;\r
150                         _ffree(p);\r
151                 }\r
152         s1 >>= 1;\r
153         }\r
154         while (s0 && (p = _fmalloc(s0)) == NULL)\r
155                 s0 ^= s0 & -s0;\r
156 \r
157         *Size = s0;\r
158         return p;\r
159 }\r
160 \r
161 //far version of above\r
162 unsigned long HC_farcoreleft(void)\r
163 {\r
164         unsigned long total = 0UL;\r
165         void far* pFirst = NULL;\r
166         void far* pLast = NULL;\r
167         for(;;)\r
168         {\r
169                 unsigned long largest;\r
170                 void far* p = HC_LargestFarFreeBlock(&largest);\r
171                 if (largest < sizeof(void far*))\r
172                 {\r
173                         if (p != NULL)\r
174                         _ffree(p);\r
175                         break;\r
176                 }\r
177                 *(void far* far*)p = NULL;\r
178                 total += largest;\r
179                 if (pFirst == NULL)\r
180                         pFirst = p;\r
181 \r
182                 if (pLast != NULL)\r
183                         *(void far* far*)pLast = p;\r
184                 pLast = p;\r
185         }\r
186 \r
187         while (pFirst != NULL)\r
188         {\r
189                 void far* p = *(void far* far*)pFirst;\r
190                 _ffree(pFirst);\r
191                 pFirst = p;\r
192         }\r
193         return total;\r
194 }\r
195 \r
196 //==#ifdef __WATCOMC__\r
197 /*void huge* LargestHugeFreeBlock(size_t* Size)\r
198 {\r
199         size_t s0, s1;\r
200         void huge* p;\r
201 \r
202         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
203         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
204                 s0 >>= 1;\r
205 \r
206         if (p)\r
207                 hfree(p);\r
208 \r
209         s1 = s0 >> 1;\r
210         while (s1)\r
211         {\r
212                 if ((p = halloc((dword)(s0 + s1), 1)) != NULL)\r
213                 {\r
214                         s0 += s1;\r
215                         hfree(p);\r
216                 }\r
217         s1 >>= 1;\r
218         }\r
219         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
220                 s0 ^= s0 & -s0;\r
221 \r
222         *Size = s0;\r
223         return p;\r
224 }\r
225 \r
226 size_t _hugecoreleft(void)\r
227 {\r
228         size_t total = 0;\r
229         void huge* pFirst = NULL;\r
230         void huge* pLast = NULL;\r
231         for(;;)\r
232         {\r
233                 size_t largest;\r
234                 void huge* p = LargestHugeFreeBlock(&largest);\r
235                 if (largest < sizeof(void huge*))\r
236                 {\r
237                         if (p != NULL)\r
238                         hfree(p);\r
239                         break;\r
240                 }\r
241                 *(void huge* huge*)p = NULL;\r
242                 total += largest;\r
243                 if (pFirst == NULL)\r
244                         pFirst = p;\r
245 \r
246                 if (pLast != NULL)\r
247                         *(void huge* huge*)pLast = p;\r
248                 pLast = p;\r
249         }\r
250 \r
251         while (pFirst != NULL)\r
252         {\r
253                 void huge* p = *(void huge* huge*)pFirst;\r
254                 hfree(pFirst);\r
255                 pFirst = p;\r
256         }\r
257         return total;\r
258 }\r
259 \r
260 void __based(__self)* LargestBasedFreeBlock(size_t* Size)\r
261 {\r
262         __segment segu;\r
263         size_t s0, s1;\r
264         void __based(__self)* p;\r
265 \r
266         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
267         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
268                 s0 >>= 1;\r
269 \r
270         if (p)\r
271                 _ffree(p);\r
272 \r
273         s1 = s0 >> 1;\r
274         while (s1)\r
275         {\r
276                 if ((p = _bmalloc(segu, s0 + s1)) != NULL)\r
277                 {\r
278                         s0 += s1;\r
279                         _ffree(p);\r
280                 }\r
281         s1 >>= 1;\r
282         }\r
283         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
284                 s0 ^= s0 & -s0;\r
285 \r
286         *Size = s0;\r
287         return p;\r
288 }\r
289 \r
290 size_t _basedcoreleft(void)\r
291 {\r
292         __segment segu;\r
293         size_t total = 0;\r
294         void __based(segu)* pFirst = NULL;\r
295         void __based(segu)* pLast = NULL;\r
296         // allocate based heap\r
297         segu = _bHC_heapseg( 1024 );\r
298         if( segu == _NULLSEG ) {\r
299                 printf( "Unable to allocate based heap\n" );\r
300                 return 0;\r
301 \r
302         }\r
303         else\r
304 \r
305         for(;;)\r
306         {\r
307                 size_t largest;\r
308                 void __based(segu)* p = LargestBasedFreeBlock(&largest);\r
309                 if (largest < sizeof(void far*))\r
310                 {\r
311                         if (p != NULL)\r
312                         _ffree(p);\r
313                         break;\r
314                 }\r
315                 *(void far* far*)p = NULL;\r
316                 total += largest;\r
317                 if (pFirst == NULL)\r
318                         pFirst = p;\r
319 \r
320                 if (pLast != NULL)\r
321                         *(void far* far*)pLast = p;\r
322                 pLast = p;\r
323         }\r
324 \r
325         while (pFirst != NULL)\r
326         {\r
327                 void far* p = *(void far* far*)pFirst;\r
328                 _ffree(pFirst);\r
329                 pFirst = p;\r
330         }\r
331         return total;\r
332 }\r
333 \r
334 size_t HC_GetFreeSize(void)\r
335 {\r
336         struct _heapinfo h_info;\r
337         int heap_status;\r
338         size_t h_free=0, h_total=0, h_used=0;\r
339 \r
340         h_info._pentry = NULL;\r
341         for(;;) {\r
342                 heap_status = _heapwalk( &h_info );\r
343                 if( heap_status != _HEAPOK ) break;\r
344                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
345                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
346                 h_total += h_info._size;\r
347         }\r
348         HCL_heapstat(heap_status);\r
349         return h_free;\r
350 }\r
351 */\r
352 \r
353 void HCL_HeapWalking (struct _heapinfo *h_info, hc_use_t *hu, unsigned nearfarswitch)\r
354 {\r
355         hu->h_free=0; hu->h_total=0; hu->h_used=0;\r
356 \r
357         h_info->_pentry = NULL;\r
358         for(;;) {\r
359                 if(nearfarswitch==0) hu->heap_status = _nheapwalk( h_info );\r
360                 else if(nearfarswitch==1) hu->heap_status = _fheapwalk( h_info );\r
361                 if( hu->heap_status != _HEAPOK ) break;\r
362                 if((h_info->_useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") hu->h_free += h_info->_size;\r
363                 if((h_info->_useflag == _USEDENTRY ? "USED" : "FREE")=="USED") hu->h_used += h_info->_size;\r
364                 hu->h_total += h_info->_size;\r
365         }\r
366         HCL_heapstat(hu->heap_status);\r
367 }\r
368 \r
369 unsigned long HC_GetFarFreeSize(void)\r
370 {\r
371         struct _heapinfo h_info;\r
372         hc_use_t hu;\r
373         HCL_HeapWalking (&h_info, &hu, 1);\r
374         return hu.h_free;\r
375 #if 0\r
376         struct _heapinfo fh_info;\r
377         int heap_status;\r
378         unsigned long fh_free=0, fh_total=0, fh_used=0;\r
379 \r
380         fh_info._pentry = NULL;\r
381         for(;;) {\r
382                 heap_status = _fheapwalk( &fh_info );\r
383                 if( heap_status != _HEAPOK ) break;\r
384                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
385                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
386                 fh_total += fh_info._size;\r
387         }\r
388         HCL_heapstat(heap_status);\r
389         return fh_free;\r
390 #endif\r
391 }\r
392 \r
393 size_t HC_GetNearFreeSize(void)\r
394 {\r
395         struct _heapinfo h_info;\r
396         hc_use_t hu;\r
397         HCL_HeapWalking (&h_info, &hu, 0);\r
398         return hu.h_free;\r
399 #if 0\r
400         struct _heapinfo nh_info;\r
401         int heap_status;\r
402         size_t nh_free=0, nh_total=0, nh_used=0;\r
403 \r
404         nh_info._pentry = NULL;\r
405         for(;;) {\r
406                 heap_status = _nheapwalk( &nh_info );\r
407                 if( heap_status != _HEAPOK ) break;\r
408                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
409                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
410                 nh_total += nh_info._size;\r
411         }\r
412         HCL_heapstat(heap_status);\r
413         return nh_free;\r
414 #endif\r
415 }\r
416 \r
417 void HC_heapdump(global_game_variables_t *gvar)\r
418 {\r
419         struct _heapinfo fh_info, nh_info;//, h_info;\r
420         int heap_status;\r
421         size_t nh_free, fh_free, nh_total, fh_total, nh_used, fh_used;//,       h_free, h_total, h_used;\r
422         byte    scratch[1024],str[16];\r
423 \r
424         HC_OpenDebug(gvar);\r
425 \r
426 #if 0\r
427         strcpy(scratch,"\n      == default ==\n\n");\r
428         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
429         h_info._pentry = NULL;\r
430         h_free=0; h_total=0; h_used=0;\r
431         for(;;) {\r
432                 heap_status = _heapwalk( &h_info );\r
433                 if( heap_status != _HEAPOK ) break;\r
434                 strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
435                 sprintf(str, "%Fp", h_info._pentry); //ultoa((dword)h_info._pentry,str,16);\r
436                         strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
437                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
438                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
439                 h_total += h_info._size;\r
440                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
441         }\r
442         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
443 #endif\r
444 \r
445         //near\r
446         strcpy(scratch,"\n      == near ==\n\n");\r
447         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
448         nh_info._pentry = NULL;\r
449         nh_free=0; nh_total=0; nh_used=0;\r
450         for(;;) {\r
451                 heap_status = _nheapwalk( &nh_info );\r
452                 if( heap_status != _HEAPOK ) break;\r
453                 strcpy(scratch,"  "); strcat(scratch,(nh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
454                 sprintf(str, "%Fp", nh_info._pentry); //ultoa((dword)nh_info._pentry,str,16);\r
455                         strcat(scratch,str); strcat(scratch," of size "); ultoa(nh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
456 /*              printf( "  %s block at %Fp of size %4.4X\n",\r
457 (nh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
458 nh_info._pentry, nh_info._size );*/\r
459                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
460                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
461                 nh_total += nh_info._size;\r
462                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
463         }\r
464         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
465 \r
466         //far\r
467         strcpy(scratch,"\n      == far ==\n\n");\r
468         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
469         fh_info._pentry = NULL;\r
470         fh_free=0; fh_total=0; fh_used=0;\r
471         for(;;) {\r
472                 heap_status = _fheapwalk( &fh_info );\r
473                 if( heap_status != _HEAPOK ) break;\r
474                 strcpy(scratch,"  "); strcat(scratch,(fh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
475                 sprintf(str, "%Fp", fh_info._pentry); //ultoa((dword)fh_info._pentry,str,16);\r
476                         strcat(scratch,str); strcat(scratch," of size "); ultoa(fh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
477                 /*printf( "  %s block at %Fp of size %4.4X\n",\r
478 (fh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
479 fh_info._pentry, fh_info._size );*/\r
480                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
481                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
482                 fh_total += fh_info._size;\r
483                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
484         }\r
485         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
486 \r
487         strcpy(scratch,"\n");\r
488 #ifdef __WATCOMC__\r
489         strcat(scratch,kittengets(2,0,"Memory Type         Total      Used       Free\n"));\r
490 #endif\r
491         strcat(scratch,"----------------  --------   --------   --------\n");\r
492 //      printmeminfoline(&scratch, "Default", h_total, h_used, h_free);\r
493         printmeminfoline(scratch, "Near", nh_total, nh_used, nh_free);\r
494         printmeminfoline(scratch, "Far", fh_total, fh_used, fh_free);\r
495         strcat(scratch,"----------------  --------   --------   --------\n");\r
496         strcat(scratch,"HC_coreleft = ");                       ultoa((dword)HC_coreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
497         strcat(scratch,"HC_farcoreleft = ");                    ultoa((dword)HC_farcoreleft(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
498 //      strcat(scratch,"HC_Newfarcoreleft = ");         ultoa((dword)HC_Newfarcoreleft(),str,10);               strcat(scratch,str);    strcat(scratch,"\n");\r
499 //      strcat(scratch,"HC_GetFreeSize = ");            ultoa((dword)HC_GetFreeSize(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
500         strcat(scratch,"HC_GetNearFreeSize = ");        ultoa((dword)HC_GetNearFreeSize(),str,10);      strcat(scratch,str);    strcat(scratch,"\n");\r
501         strcat(scratch,"HC_GetFarFreeSize = ");         ultoa((dword)HC_GetFarFreeSize(),str,10);       strcat(scratch,str);    strcat(scratch,"\n");\r
502         strcat(scratch,"coreleft = ");                          ultoa((dword)coreleft(),str,10);                                strcat(scratch,str);    strcat(scratch,"\n");\r
503         strcat(scratch,"farcoreleft = ");                       ultoa((dword)farcoreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
504         strcat(scratch,"stackavail = ");                        ultoa((dword)stackavail(),str,10);                      strcat(scratch,str);    strcat(scratch,"\n");\r
505         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
506         HC_CloseDebug(gvar);\r
507 }\r
508 \r
509 void HCL_heapstatLogWrite(global_game_variables_t *gvar, int heap_status, byte *str)\r
510 {\r
511         switch( heap_status ) {\r
512                 case _HEAPEND:\r
513                         strcpy((str),"OK - end of heap\n");\r
514                 break;\r
515                 case _HEAPEMPTY:\r
516                         strcpy((str),"OK - heap is empty\n");\r
517 \r
518                 break;\r
519                 case _HEAPBADBEGIN:\r
520                         strcpy((str),"ERROR - heap is damaged\n");\r
521                 break;\r
522 #ifdef __WATCOMC__\r
523                 case _HEAPBADPTR:\r
524                         strcpy((str),"ERROR - bad pointer to heap\n");\r
525                 break;\r
526 #endif\r
527                 case _HEAPBADNODE:\r
528                         strcpy((str),"ERROR - bad node in heap\n");\r
529         }\r
530         write(gvar->handle.heaphandle,(str),strlen((str)));\r
531 }\r
532 \r
533 void HCL_heapstat(int heap_status)\r
534 {\r
535         switch( heap_status ) {\r
536                 case _HEAPEND:\r
537                         //printf("OK - end of heap\n");\r
538                 break;\r
539                 case _HEAPEMPTY:\r
540                         //printf("OK - heap is empty\n");\r
541                 break;\r
542                 case _HEAPBADBEGIN:\r
543                         printf("ERROR - heap is damaged\n");\r
544                 break;\r
545 #ifdef __WATCOMC__\r
546                 case _HEAPBADPTR:\r
547                         printf("ERROR - bad pointer to heap\n");\r
548                 break;\r
549 #endif\r
550                 case _HEAPBADNODE:\r
551                         printf("ERROR - bad node in heap\n");\r
552         }\r
553 }\r
554 \r
555 //++\r
556 #ifdef __WATCOMC__\r
557 unsigned long farcoreleft()\r
558 {\r
559 //----  _fheapgrow();\r
560         return HC_farcoreleft();\r
561 //stack overflows       return HC_GetFarFreeSize();\r
562 }\r
563 \r
564 unsigned long coreleft()\r
565 {\r
566         _nheapgrow();\r
567         return _memavl();\r
568 //      return HC_GetNearFreeSize();\r
569 }\r
570 #endif\r
571 \r
572 /*\r
573 ============================\r
574 =\r
575 = HC_OpenDebug / HC_CloseDebug\r
576 =\r
577 = Opens a binary file with the handle "heaphandle"\r
578 =\r
579 ============================\r
580 */\r
581 void HC_OpenDebug(global_game_variables_t *gvar)\r
582 {\r
583 #ifdef __BORLANDC__\r
584         unlink("heap.16b");\r
585         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
586 #endif\r
587 #ifdef __WATCOMC__\r
588         unlink("heap.16w");\r
589         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
590 #endif\r
591 }\r
592 \r
593 void HC_CloseDebug(global_game_variables_t *gvar)\r
594 {\r
595         close(gvar->handle.heaphandle);\r
596 \r
597 #ifdef __BORLANDC__\r
598         strcpy(gvar->handle.heapdumpfilename, "heap.16b");\r
599 #endif\r
600 #ifdef __WATCOMC__\r
601         strcpy(gvar->handle.heapdumpfilename, "heap.16w");\r
602 #endif\r
603 }\r