--- /dev/null
+0 Size:5194 Owner:0x0
+0 Size:5194 Owner:0x0
+144a Size:256 Owner:0x4d02
+Seg:154a Size:273 Owner:0x859a
+Seg:1bd1 Size:17 Owner:0x144d
+Seg:1bd1 Size:17 Owner:0x144d
+1dd2 Size:49710 Owner:0x11
+Seg:e000 Size:4294909951 Owner:0xc22b
--- /dev/null
+
+ == default ==
+
+ USED block at 1bd30016 of size 88
+ USED block at 1bd3009e of size 42
+ FREE block at 1bd300e0 of size 1f1e
+ USED block at 1bd31ffe of size 14
+ FREE block at 1bd32012 of size 1fea
+OK - end of heap
+
+ == near ==
+
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+OK - end of heap
+
+ == far ==
+
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+ USED block at 0 of size 0
+OK - end of heap
+
+Memory Type Total Used Free
+---------------- -------- -------- --------
+Default 16358 222 16136
+Near 31286 436 30850
+Far 16358 222 16136
+---------------- -------- -------- --------
+coreleft = 30848
+farcoreleft = 46788
+GetFreeSize = 15960
+GetNearFreeSize = 30850
+GetFarFreeSize = 15960
+memavl = 30848
+stackavail = 17135
16FLAGS=-fh=16.hed
BAKAPIFLAGS=-fh=bakapi.hed
-SFLAGS=-sg -st -of+ -k32768#51200#49152#24576
+SFLAGS=-sg -st -of+ -k32768 -zu -zdp#51200#49152#24576
DFLAGS=-DTARGET_MSDOS=16 -DMSDOS=1 $(SFLAGS)
ZFLAGS=-zk0 -zq -zu -zc -zm# -zdp# -zp16
CFLAGS=-mc -lr -l=dos -wo -x## -d2
DOSLIBEXMMOBJ = himemsys.$(OBJ) emm.$(OBJ)
DOSLIBOBJ = adlib.$(OBJ) 8254.$(OBJ) 8259.$(OBJ) dos.$(OBJ) cpu.$(OBJ)
-16LIBOBJS = bakapee.$(OBJ) 16_in.$(OBJ) 16_mm.$(OBJ) wcpu.$(OBJ) 16_head.$(OBJ) scroll16.$(OBJ) 16_ca.$(OBJ) timer.$(OBJ) kitten.$(OBJ)
+16LIBOBJS = bakapee.$(OBJ) 16_in.$(OBJ) 16_mm.$(OBJ) wcpu.$(OBJ) 16_head.$(OBJ) scroll16.$(OBJ) 16_ca.$(OBJ) timer.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ)
GFXLIBOBJS = modex16.$(OBJ) bitmap.$(OBJ) planar.$(OBJ) 16text.$(OBJ)
TESTEXEC = exmmtest.exe test.exe pcxtest.exe test2.exe palettec.exe maptest.exe fmemtest.exe fonttest.exe fontgfx.exe sountest.exe tsthimem.exe inputest.exe scroll.exe sega.exe
16_head.$(OBJ): $(SRCLIB)16_head.h $(SRCLIB)16_head.c
wcl $(FLAGS) -c $(SRCLIB)16_head.c
+16_hc.$(OBJ): $(SRCLIB)16_hc.h $(SRCLIB)16_hc.c
+ wcl $(FLAGS) -c $(SRCLIB)16_hc.c
+
jsmn.$(OBJ): $(JSMNLIB)jsmn.h $(JSMNLIB)jsmn.c
wcl $(FLAGS) -c $(JSMNLIB)jsmn.c
#include "src/lib/16_head.h"\r
#include "src/lib/16_ca.h"\r
#include "src/lib/16_mm.h"\r
+#include "src/lib/16_hc.h"\r
//#include "src/lib/modex16.h"\r
#pragma hdrstop\r
\r
printf("&bigbuffer= %Fp\n", &bigbuffer);\r
printf("bigbuffer= %04x\n", bigbuffer);\r
printf("&bigbuffer= %04x\n", &bigbuffer);\r
- getch();\r
+// getch();\r
#ifdef FILERL\r
// bakapeehandle = open(bakapee,O_RDONLY | O_BINARY, S_IREAD);\r
// printf("size of big buffer~=%u\n", _bmsize(segu, bigbuffer));\r
printf("&bigbuffer= %Fp\n", &bigbuffer);\r
printf("bigbuffer= %04x\n", bigbuffer);\r
printf("&bigbuffer= %04x\n", &bigbuffer);\r
- printf("\n\n");\r
+ /*printf("\n\n");\r
printf("Total free: %lu\n", (dword)(GetFreeSize()));\r
printf("Total near free: %lu\n", (dword)(GetNearFreeSize()));\r
printf("Total far free: %lu\n", (dword)(GetFarFreeSize()));\r
- getch();\r
+ getch();*/\r
printf("\n");\r
heapdump();\r
- printf("core left: %lu\n", (dword)_coreleft());\r
- printf("far core left: %lu\n", (dword)_farcoreleft());\r
+ //printf("core left: %lu\n", (dword)_coreleft());\r
+ //printf("far core left: %lu\n", (dword)_farcoreleft());\r
//printf("based core left: %lu\n", (dword)_basedcoreleft());\r
//printf("huge core left: %lu\n", (dword)_hugecoreleft());\r
}\r
--- /dev/null
+/* Project 16 Source Code~
+ * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
+ *
+ * This file is part of Project 16.
+ *
+ * Project 16 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Project 16 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>, or
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+/*
+ heap test stuff
+*/
+
+#include "src/lib/16_hc.h"
+
+void __near* LargestFreeBlock(size_t* Size)
+{
+ size_t s0, s1;
+ void __near* p;
+
+ s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
+ while (s0 && (p = _nmalloc(s0)) == NULL)
+ s0 >>= 1;
+
+ if (p)
+ _nfree(p);
+
+ s1 = s0 >> 1;
+ while (s1)
+ {
+ if ((p = _nmalloc(s0 + s1)) != NULL)
+ {
+ s0 += s1;
+ _nfree(p);
+ }
+ s1 >>= 1;
+ }
+ while (s0 && (p = _nmalloc(s0)) == NULL)
+ s0 ^= s0 & -s0;
+
+ *Size = s0;
+ return p;
+}
+
+size_t _coreleft(void)
+{
+ size_t total = 0;
+ void __near* pFirst = NULL;
+ void __near* pLast = NULL;
+ for(;;)
+ {
+ size_t largest;
+ void __near* p = LargestFreeBlock(&largest);
+ if (largest < sizeof(void __near*))
+ {
+ if (p != NULL)
+ _nfree(p);
+ break;
+ }
+ *(void __near* __near*)p = NULL;
+ total += largest;
+ if (pFirst == NULL)
+ pFirst = p;
+
+ if (pLast != NULL)
+ *(void __near* __near*)pLast = p;
+ pLast = p;
+ }
+
+ while (pFirst != NULL)
+ {
+ void __near* p = *(void __near* __near*)pFirst;
+ _nfree(pFirst);
+ pFirst = p;
+ }
+ return total;
+}
+
+void far* LargestFarFreeBlock(size_t* Size)
+{
+ size_t s0, s1;
+ void far* p;
+
+ s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
+ while (s0 && (p = _fmalloc(s0)) == NULL)
+ s0 >>= 1;
+
+ if (p)
+ _ffree(p);
+
+ s1 = s0 >> 1;
+ while (s1)
+ {
+ if ((p = _fmalloc(s0 + s1)) != NULL)
+ {
+ s0 += s1;
+ _ffree(p);
+ }
+ s1 >>= 1;
+ }
+ while (s0 && (p = _fmalloc(s0)) == NULL)
+ s0 ^= s0 & -s0;
+
+ *Size = s0;
+ return p;
+}
+
+size_t _farcoreleft(void)
+{
+ size_t total = 0;
+ void far* pFirst = NULL;
+ void far* pLast = NULL;
+ for(;;)
+ {
+ size_t largest;
+ void far* p = LargestFarFreeBlock(&largest);
+ if (largest < sizeof(void far*))
+ {
+ if (p != NULL)
+ _ffree(p);
+ break;
+ }
+ *(void far* far*)p = NULL;
+ total += largest;
+ if (pFirst == NULL)
+ pFirst = p;
+
+ if (pLast != NULL)
+ *(void far* far*)pLast = p;
+ pLast = p;
+ }
+
+ while (pFirst != NULL)
+ {
+ void far* p = *(void far* far*)pFirst;
+ _ffree(pFirst);
+ pFirst = p;
+ }
+ return total;
+}
+
+void huge* LargestHugeFreeBlock(size_t* Size)
+{
+ size_t s0, s1;
+ void huge* p;
+
+ s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
+ while (s0 && (p = halloc((dword)s0, 1)) == NULL)
+ s0 >>= 1;
+
+ if (p)
+ hfree(p);
+
+ s1 = s0 >> 1;
+ while (s1)
+ {
+ if ((p = halloc((dword)(s0 + s1), 1)) != NULL)
+ {
+ s0 += s1;
+ hfree(p);
+ }
+ s1 >>= 1;
+ }
+ while (s0 && (p = halloc((dword)s0, 1)) == NULL)
+ s0 ^= s0 & -s0;
+
+ *Size = s0;
+ return p;
+}
+
+size_t _hugecoreleft(void)
+{
+ size_t total = 0;
+ void huge* pFirst = NULL;
+ void huge* pLast = NULL;
+ for(;;)
+ {
+ size_t largest;
+ void huge* p = LargestHugeFreeBlock(&largest);
+ if (largest < sizeof(void huge*))
+ {
+ if (p != NULL)
+ hfree(p);
+ break;
+ }
+ *(void huge* huge*)p = NULL;
+ total += largest;
+ if (pFirst == NULL)
+ pFirst = p;
+
+ if (pLast != NULL)
+ *(void huge* huge*)pLast = p;
+ pLast = p;
+ }
+
+ while (pFirst != NULL)
+ {
+ void huge* p = *(void huge* huge*)pFirst;
+ hfree(pFirst);
+ pFirst = p;
+ }
+ return total;
+}
+
+/*void __based(__self)* LargestBasedFreeBlock(size_t* Size)
+{
+ __segment segu;
+ size_t s0, s1;
+ void __based(__self)* p;
+
+ s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
+ while (s0 && (p = _bmalloc(segu, s0)) == NULL)
+ s0 >>= 1;
+
+ if (p)
+ _ffree(p);
+
+ s1 = s0 >> 1;
+ while (s1)
+ {
+ if ((p = _bmalloc(segu, s0 + s1)) != NULL)
+ {
+ s0 += s1;
+ _ffree(p);
+ }
+ s1 >>= 1;
+ }
+ while (s0 && (p = _bmalloc(segu, s0)) == NULL)
+ s0 ^= s0 & -s0;
+
+ *Size = s0;
+ return p;
+}
+
+size_t _basedcoreleft(void)
+{
+ __segment segu;
+ size_t total = 0;
+ void __based(segu)* pFirst = NULL;
+ void __based(segu)* pLast = NULL;
+ // allocate based heap
+ segu = _bheapseg( 1024 );
+ if( segu == _NULLSEG ) {
+ printf( "Unable to allocate based heap\n" );
+ return 0;
+ //exit( 1 );
+ }
+ else
+
+ for(;;)
+ {
+ size_t largest;
+ void __based(segu)* p = LargestBasedFreeBlock(&largest);
+ if (largest < sizeof(void far*))
+ {
+ if (p != NULL)
+ _ffree(p);
+ break;
+ }
+ *(void far* far*)p = NULL;
+ total += largest;
+ if (pFirst == NULL)
+ pFirst = p;
+
+ if (pLast != NULL)
+ *(void far* far*)pLast = p;
+ pLast = p;
+ }
+
+ while (pFirst != NULL)
+ {
+ void far* p = *(void far* far*)pFirst;
+ _ffree(pFirst);
+ pFirst = p;
+ }
+ return total;
+}*/
+
+size_t GetFreeSize(void)
+{
+ struct _heapinfo h_info;
+ int heap_status;
+ size_t h_free=0, h_total=0, h_used=0;
+
+ h_info._pentry = NULL;
+ for(;;) {
+ heap_status = _heapwalk( &h_info );
+ if( heap_status != _HEAPOK ) break;
+ if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;
+ if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;
+ h_total += h_info._size;
+ }
+ heapstat0(heap_status);
+ return h_free;
+}
+
+size_t GetFarFreeSize(void)
+{
+ struct _heapinfo fh_info;
+ int heap_status;
+ size_t fh_free=0, fh_total=0, fh_used=0;
+
+ fh_info._pentry = NULL;
+ for(;;) {
+ heap_status = _fheapwalk( &fh_info );
+ if( heap_status != _HEAPOK ) break;
+ if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;
+ if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;
+ fh_total += fh_info._size;
+ }
+ heapstat0(heap_status);
+ return fh_free;
+}
+
+size_t GetNearFreeSize(void)
+{
+ struct _heapinfo nh_info;
+ int heap_status;
+ size_t nh_free=0, nh_total=0, nh_used=0;
+
+ nh_info._pentry = NULL;
+ for(;;) {
+ heap_status = _nheapwalk( &nh_info );
+ if( heap_status != _HEAPOK ) break;
+ if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;
+ if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;
+ nh_total += nh_info._size;
+ }
+ heapstat0(heap_status);
+ return nh_free;
+}
+
+void heapdump(void)
+{
+ struct _heapinfo fh_info, nh_info, h_info;
+ int heap_status;
+ size_t h_free, nh_free, fh_free, h_total, nh_total, fh_total, h_used, nh_used, fh_used;
+ byte scratch[1024],str[16];
+
+ HC_OpenDebug();
+
+ strcpy(scratch,"\n == default ==\n\n");
+ write(heaphandle,scratch,strlen(scratch));
+ h_info._pentry = NULL;
+ h_free=0; h_total=0; h_used=0;
+ for(;;) {
+ heap_status = _heapwalk( &h_info );
+ if( heap_status != _HEAPOK ) break;
+
+ strcpy(scratch," "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,16); strcat(scratch,str); strcat(scratch,"\n");
+ if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;
+ if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;
+ h_total += h_info._size;
+ write(heaphandle,scratch,strlen(scratch));
+ }
+ heapstat(heap_status, &scratch);
+
+ //near
+ strcpy(scratch,"\n == near ==\n\n");
+ write(heaphandle,scratch,strlen(scratch));
+ nh_info._pentry = NULL;
+ nh_free=0; nh_total=0; nh_used=0;
+ for(;;) {
+ heap_status = _nheapwalk( &nh_info );
+ if( heap_status != _HEAPOK ) break;
+
+ strcpy(scratch," "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,16); strcat(scratch,str); strcat(scratch,"\n");
+/* printf( " %s block at %Fp of size %4.4X\n",
+(nh_info._useflag == _USEDENTRY ? "USED" : "FREE"),
+nh_info._pentry, nh_info._size );*/
+ if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;
+ if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;
+ nh_total += nh_info._size;
+ write(heaphandle,scratch,strlen(scratch));
+ }
+ heapstat(heap_status, &scratch);
+
+ //far
+ strcpy(scratch,"\n == far ==\n\n");
+ write(heaphandle,scratch,strlen(scratch));
+ fh_info._pentry = NULL;
+ fh_free=0; fh_total=0; fh_used=0;
+ for(;;) {
+ heap_status = _fheapwalk( &fh_info );
+ if( heap_status != _HEAPOK ) break;
+
+ strcpy(scratch," "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at "); ultoa((dword)h_info._pentry,str,16); strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,16); strcat(scratch,str); strcat(scratch,"\n");
+ /*printf( " %s block at %Fp of size %4.4X\n",
+(fh_info._useflag == _USEDENTRY ? "USED" : "FREE"),
+fh_info._pentry, fh_info._size );*/
+ if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;
+ if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;
+ fh_total += fh_info._size;
+ write(heaphandle,scratch,strlen(scratch));
+ }
+ heapstat(heap_status, &scratch);
+
+ strcpy(scratch,"\n");
+ strcat(scratch,kittengets(2,0,"Memory Type Total Used Free\n"));
+ strcat(scratch,"---------------- -------- -------- --------\n");
+ printmeminfoline(&scratch, "Default", h_total, h_used, h_free);
+ printmeminfoline(&scratch, "Near", nh_total, nh_used, nh_free);
+ printmeminfoline(&scratch, "Far", fh_total, fh_used, fh_free);
+ strcat(scratch,"---------------- -------- -------- --------\n");
+ strcat(scratch,"coreleft = "); ultoa((dword)_coreleft(),str,10); strcat(scratch,str); strcat(scratch,"\n");
+ strcat(scratch,"farcoreleft = "); ultoa((dword)_farcoreleft(),str,10); strcat(scratch,str); strcat(scratch,"\n");
+ strcat(scratch,"GetFreeSize = "); ultoa((dword)GetFreeSize(),str,10); strcat(scratch,str); strcat(scratch,"\n");
+ strcat(scratch,"GetNearFreeSize = "); ultoa((dword)GetNearFreeSize(),str,10); strcat(scratch,str); strcat(scratch,"\n");
+ strcat(scratch,"GetFarFreeSize = "); ultoa((dword)GetFarFreeSize(),str,10); strcat(scratch,str); strcat(scratch,"\n");
+ strcat(scratch,"memavl = "); ultoa((dword)_memavl(),str,10); strcat(scratch,str); strcat(scratch,"\n");
+ strcat(scratch,"stackavail = "); ultoa((dword)stackavail(),str,10); strcat(scratch,str); strcat(scratch,"\n");
+ write(heaphandle,scratch,strlen(scratch));
+ HC_CloseDebug();
+}
+
+void heapstat(int heap_status, byte *str)
+{
+ switch( heap_status ) {
+ case _HEAPEND:
+ strcpy((str),"OK - end of heap\n");
+ break;
+ case _HEAPEMPTY:
+ strcpy((str),"OK - heap is empty\n");
+
+ break;
+ case _HEAPBADBEGIN:
+ strcpy((str),"ERROR - heap is damaged\n");
+ break;
+ case _HEAPBADPTR:
+ strcpy((str),"ERROR - bad pointer to heap\n");
+ break;
+ case _HEAPBADNODE:
+ strcpy((str),"ERROR - bad node in heap\n");
+ }
+ write(heaphandle,(str),strlen((str)));
+}
+
+void heapstat0(int heap_status)
+{
+ switch( heap_status ) {
+ case _HEAPEND:
+ //printf("OK - end of heap\n");
+ break;
+ case _HEAPEMPTY:
+ //printf("OK - heap is empty\n");
+
+ break;
+ case _HEAPBADBEGIN:
+ printf("ERROR - heap is damaged\n");
+ break;
+ case _HEAPBADPTR:
+ printf("ERROR - bad pointer to heap\n");
+ break;
+ case _HEAPBADNODE:
+ printf("ERROR - bad node in heap\n");
+ }
+}
+
+/*
+============================
+=
+= HC_OpenDebug / HC_CloseDebug
+=
+= Opens a binary file with the handle "heaphandle"
+=
+============================
+*/
+void HC_OpenDebug()
+{
+ unlink("heap.16");
+ heaphandle = open("heap.16", O_CREAT | O_WRONLY | O_TEXT);
+}
+
+void HC_CloseDebug()
+{
+ close(heaphandle);
+}
--- /dev/null
+/* Project 16 Source Code~
+ * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
+ *
+ * This file is part of Project 16.
+ *
+ * Project 16 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Project 16 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>, or
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+/*
+ heap test stuff
+*/
+
+#ifndef __16HC__
+#define __16HC__
+
+#include "src/lib/16_head.h"
+
+int heaphandle;
+
+void __near* LargestFreeBlock(size_t* Size);
+size_t _coreleft(void);
+void far* LargestFarFreeBlock(size_t* Size);
+size_t _farcoreleft(void);
+void huge* LargestHugeFreeBlock(size_t* Size);
+size_t _hugecoreleft(void);
+//void __based(__self)* LargestBasedFreeBlock(size_t* Size);
+//size_t _basedcoreleft(void);
+size_t GetFreeSize(void);
+size_t GetFarFreeSize(void);
+size_t GetNearFreeSize(void);
+void heapdump(void);
+void heapstat(int heap_status, byte *str);
+void heapstat0(int heap_status);
+
+void HC_OpenDebug();
+void HC_CloseDebug();
+
+#endif /* __16HC__ */
while((goal > clock()) && !kbhit()) ;\r
} /* End of wait */
-void __near* LargestFreeBlock(size_t* Size)
-{
- size_t s0, s1;
- void __near* p;
-
- s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
- while (s0 && (p = _nmalloc(s0)) == NULL)
- s0 >>= 1;
-
- if (p)
- _nfree(p);
-
- s1 = s0 >> 1;
- while (s1)
- {
- if ((p = _nmalloc(s0 + s1)) != NULL)
- {
- s0 += s1;
- _nfree(p);
- }
- s1 >>= 1;
- }
- while (s0 && (p = _nmalloc(s0)) == NULL)
- s0 ^= s0 & -s0;
-
- *Size = s0;
- return p;
-}
-
-size_t _coreleft(void)
-{
- size_t total = 0;
- void __near* pFirst = NULL;
- void __near* pLast = NULL;
- for(;;)
- {
- size_t largest;
- void __near* p = LargestFreeBlock(&largest);
- if (largest < sizeof(void __near*))
- {
- if (p != NULL)
- _nfree(p);
- break;
- }
- *(void __near* __near*)p = NULL;
- total += largest;
- if (pFirst == NULL)
- pFirst = p;
-
- if (pLast != NULL)
- *(void __near* __near*)pLast = p;
- pLast = p;
- }
-
- while (pFirst != NULL)
- {
- void __near* p = *(void __near* __near*)pFirst;
- _nfree(pFirst);
- pFirst = p;
- }
- return total;
-}
-
-void far* LargestFarFreeBlock(size_t* Size)
-{
- size_t s0, s1;
- void far* p;
-
- s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
- while (s0 && (p = _fmalloc(s0)) == NULL)
- s0 >>= 1;
-
- if (p)
- _ffree(p);
-
- s1 = s0 >> 1;
- while (s1)
- {
- if ((p = _fmalloc(s0 + s1)) != NULL)
- {
- s0 += s1;
- _ffree(p);
- }
- s1 >>= 1;
- }
- while (s0 && (p = _fmalloc(s0)) == NULL)
- s0 ^= s0 & -s0;
-
- *Size = s0;
- return p;
-}
-
-size_t _farcoreleft(void)
-{
- size_t total = 0;
- void far* pFirst = NULL;
- void far* pLast = NULL;
- for(;;)
- {
- size_t largest;
- void far* p = LargestFarFreeBlock(&largest);
- if (largest < sizeof(void far*))
- {
- if (p != NULL)
- _ffree(p);
- break;
- }
- *(void far* far*)p = NULL;
- total += largest;
- if (pFirst == NULL)
- pFirst = p;
-
- if (pLast != NULL)
- *(void far* far*)pLast = p;
- pLast = p;
- }
-
- while (pFirst != NULL)
- {
- void far* p = *(void far* far*)pFirst;
- _ffree(pFirst);
- pFirst = p;
- }
- return total;
-}
-
-void huge* LargestHugeFreeBlock(size_t* Size)
-{
- size_t s0, s1;
- void huge* p;
-
- s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
- while (s0 && (p = halloc((dword)s0, 1)) == NULL)
- s0 >>= 1;
-
- if (p)
- hfree(p);
-
- s1 = s0 >> 1;
- while (s1)
- {
- if ((p = halloc((dword)(s0 + s1), 1)) != NULL)
- {
- s0 += s1;
- hfree(p);
- }
- s1 >>= 1;
- }
- while (s0 && (p = halloc((dword)s0, 1)) == NULL)
- s0 ^= s0 & -s0;
-
- *Size = s0;
- return p;
-}
-
-size_t _hugecoreleft(void)
-{
- size_t total = 0;
- void huge* pFirst = NULL;
- void huge* pLast = NULL;
- for(;;)
- {
- size_t largest;
- void huge* p = LargestHugeFreeBlock(&largest);
- if (largest < sizeof(void huge*))
- {
- if (p != NULL)
- hfree(p);
- break;
- }
- *(void huge* huge*)p = NULL;
- total += largest;
- if (pFirst == NULL)
- pFirst = p;
-
- if (pLast != NULL)
- *(void huge* huge*)pLast = p;
- pLast = p;
- }
-
- while (pFirst != NULL)
- {
- void huge* p = *(void huge* huge*)pFirst;
- hfree(pFirst);
- pFirst = p;
- }
- return total;
-}
-
-/*void __based(__self)* LargestBasedFreeBlock(size_t* Size)
-{
- __segment segu;
- size_t s0, s1;
- void __based(__self)* p;
-
- s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
- while (s0 && (p = _bmalloc(segu, s0)) == NULL)
- s0 >>= 1;
-
- if (p)
- _ffree(p);
-
- s1 = s0 >> 1;
- while (s1)
- {
- if ((p = _bmalloc(segu, s0 + s1)) != NULL)
- {
- s0 += s1;
- _ffree(p);
- }
- s1 >>= 1;
- }
- while (s0 && (p = _bmalloc(segu, s0)) == NULL)
- s0 ^= s0 & -s0;
-
- *Size = s0;
- return p;
-}
-
-size_t _basedcoreleft(void)
-{
- __segment segu;
- size_t total = 0;
- void __based(segu)* pFirst = NULL;
- void __based(segu)* pLast = NULL;
- // allocate based heap\r
- segu = _bheapseg( 1024 );\r
- if( segu == _NULLSEG ) {\r
- printf( "Unable to allocate based heap\n" );
- return 0;\r
- //exit( 1 );\r
- }
- else
-
- for(;;)
- {
- size_t largest;
- void __based(segu)* p = LargestBasedFreeBlock(&largest);
- if (largest < sizeof(void far*))
- {
- if (p != NULL)
- _ffree(p);
- break;
- }
- *(void far* far*)p = NULL;
- total += largest;
- if (pFirst == NULL)
- pFirst = p;
-
- if (pLast != NULL)
- *(void far* far*)pLast = p;
- pLast = p;
- }
-
- while (pFirst != NULL)
- {
- void far* p = *(void far* far*)pFirst;
- _ffree(pFirst);
- pFirst = p;
- }
- return total;
-}*/
-
-size_t GetFreeSize(void)
-{
- struct _heapinfo h_info;
- int heap_status;
- size_t h_free=0, h_total=0, h_used=0;
-
- h_info._pentry = NULL;
- for(;;) {
- heap_status = _heapwalk( &h_info );
- if( heap_status != _HEAPOK ) break;
- if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;
- if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;
- h_total += h_info._size;
- }
- heapstat(heap_status);
- return h_free;
-}
-
-size_t GetFarFreeSize(void)
-{
- struct _heapinfo fh_info;
- int heap_status;
- size_t fh_free=0, fh_total=0, fh_used=0;
-
- fh_info._pentry = NULL;
- for(;;) {
- heap_status = _fheapwalk( &fh_info );
- if( heap_status != _HEAPOK ) break;
- if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;
- if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;
- fh_total += fh_info._size;
- }
- heapstat(heap_status);
- return fh_free;
-}
-
-size_t GetNearFreeSize(void)
-{
- struct _heapinfo nh_info;
- int heap_status;
- size_t nh_free=0, nh_total=0, nh_used=0;
-
- nh_info._pentry = NULL;
- for(;;) {
- heap_status = _nheapwalk( &nh_info );
- if( heap_status != _HEAPOK ) break;
- if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;
- if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;
- nh_total += nh_info._size;
- }
- heapstat(heap_status);
- return nh_free;
-}
-
long int
filesize(FILE *fp)\r
{\r
return(size_of_file);\r
}
-void print_normal_entry(char *text, dword total, dword used, dword free)
+void printmeminfoline(byte *strc, const byte *pee, size_t h_total, size_t h_used, size_t h_free)
+{
+ byte str[64];
+ strcat(strc,pee); strcat(strc," "); ultoa((dword)h_total,str,10); strcat(strc,str); strcat(strc," "); ultoa((dword)h_used,str,10); strcat(strc,str); strcat(strc," "); ultoa((dword)h_free,str,10); strcat(strc,str);
+ strcat(strc,"\n");
+}
+
+void print_normal_entry(char *text, dword total, dword used, dword free, byte *str)
{
printf("%-17s", text);
convert("%8sB ", total);
printf(format, des);
}
-void heapdump(void)
-{
- struct _heapinfo fh_info, nh_info, h_info;
- int heap_status;
- size_t h_free, nh_free, fh_free, h_total, nh_total, fh_total, h_used, nh_used, fh_used;
-
- printf("\n == default ==\n\n");
- h_info._pentry = NULL;
- h_free=0; h_total=0; h_used=0;
- for(;;) {
- heap_status = _heapwalk( &h_info );
- if( heap_status != _HEAPOK ) break;
- printf( " %s block at %Fp of size %4.4X\n",
-(h_info._useflag == _USEDENTRY ? "USED" : "FREE"),
-h_info._pentry, h_info._size );
- if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;
- if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;
- h_total += h_info._size;
- }
- heapstat(heap_status);
-
- //near
- printf("\n == near ==\n\n");
- nh_info._pentry = NULL;
- nh_free=0; nh_total=0; nh_used=0;
- for(;;) {
- heap_status = _nheapwalk( &nh_info );
- if( heap_status != _HEAPOK ) break;
- printf( " %s block at %Fp of size %4.4X\n",
-(nh_info._useflag == _USEDENTRY ? "USED" : "FREE"),
-nh_info._pentry, nh_info._size );
- if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;
- if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;
- nh_total += nh_info._size;
- }
- heapstat(heap_status);
-
- //far
- printf("\n == far ==\n\n");
- fh_info._pentry = NULL;
- fh_free=0; fh_total=0; fh_used=0;
- for(;;) {
- heap_status = _fheapwalk( &fh_info );
- if( heap_status != _HEAPOK ) break;
- printf( " %s block at %Fp of size %4.4X\n",
-(fh_info._useflag == _USEDENTRY ? "USED" : "FREE"),
-fh_info._pentry, fh_info._size );
- if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;
- if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;
- fh_total += fh_info._size;
- }
- heapstat(heap_status);
-
-printf("\n");
-printf(kittengets(2,0,"Memory Type Total Used Free\n"));
-printf( "---------------- -------- -------- --------\n");
-print_normal_entry(kittengets(2,1,"Default"), (dword)h_total, (dword)h_used, (dword)h_free);
-print_normal_entry(kittengets(2,1,"Near"), (dword)nh_total, (dword)nh_used, (dword)nh_free);
-print_normal_entry(kittengets(2,1,"Far"), (dword)fh_total, (dword)fh_used, (dword)fh_free);
-printf( "---------------- -------- -------- --------\n");
-printf("coreleft = %lu\n", (dword)_coreleft());
-printf("farcoreleft = %lu\n", (dword)_farcoreleft());
-printf("GetFreeSize = %lu\n", (dword)GetFreeSize());
-printf("GetNearFreeSize = %lu\n", (dword)GetNearFreeSize());
-printf("GetFarFreeSize = %lu\n", (dword)GetFarFreeSize());
-printf("memavl = %lu\n", (dword)_memavl());
-printf("stackavail = %u\n", stackavail());
-}
-
-void heapstat(int heap_status)
-{
- switch( heap_status ) {
- case _HEAPEND:
- //printf( "OK - end of heap\n" );
- break;
- case _HEAPEMPTY:
- //printf( "OK - heap is empty\n" );
- break;
- case _HEAPBADBEGIN:
- printf( "ERROR - heap is damaged\n" );
- break;
- case _HEAPBADPTR:
- printf( "ERROR - bad pointer to heap\n" );
- break;
- case _HEAPBADNODE:
- printf( "ERROR - bad node in heap\n" );
- }
-}
-
-
///////////////////////////////////////////////////////////////////////////\r
//\r
// US_CheckParm() - checks to see if a string matches one of a set of\r
#include "src/lib/nyan/kitten.h"\r
#include "src/lib/types.h"\r
\r
+//0000 test type def wwww\r
struct list {\r
struct list __based(__self) *next;\r
int value;\r
*/\r
\r
static dword far* clockdw= (dword far*) 0x046C; /* 18.2hz clock */\r
-//static dword clockdw=0;\r
extern int profilehandle,debughandle; //make it into game global\r
\r
#define __DEBUG__\r
\r
-//#define _SEGU(__p) ((unsigned)((unsigned long)(void __huge*)(__p) >> 16))\r
-\r
#define nil ((void *)0)\r
\r
#define peekb(segm,ofs) (*(byte far*)MK_FP((segm),(ofs)))\r
typedef enum {false,true} boolean;\r
//I hope this is correct!\r
typedef void __based(__self) * memptr;\r
-//typedef sregs.w.es * memptr\r
-//typedef __segment * memptr;\r
-//typedef fenp.op_ptr_seg * memptr;\r
typedef struct\r
{\r
int old_mode; //old video mode before game!\r
clock_t t;\r
dword tiku;\r
word far* clock;\r
+ //handles for log files of the game gose here if wwww\r
+ //int heaphandle;\r
} global_game_variables_t;\r
\r
/* local function */\r
void wait(clock_t wait);\r
-void __near* LargestFreeBlock(size_t* Size);\r
-size_t _coreleft(void);\r
-void far* LargestFarFreeBlock(size_t* Size);\r
-size_t _farcoreleft(void);\r
-void huge* LargestHugeFreeBlock(size_t* Size);\r
-size_t _hugecoreleft(void);\r
-//void __based(__self)* LargestBasedFreeBlock(size_t* Size);\r
-//size_t _basedcoreleft(void);\r
-size_t GetFreeSize(void);\r
-size_t GetFarFreeSize(void);\r
-size_t GetNearFreeSize(void);\r
+\r
long int filesize(FILE *fp);\r
-void print_normal_entry(char *text, dword total, dword used, dword free);\r
+void printmeminfoline(byte *strc, const byte *pee, size_t h_total, size_t h_used, size_t h_free);\r
+void print_normal_entry(char *text, dword total, dword used, dword free, byte *str);\r
void convert(const char *format, dword num);\r
-void heapdump(void);\r
-void heapstat(int heap_status);\r
int US_CheckParm(char *parm,char **strings);\r
\r
extern void CA_OpenDebug (void);\r
mmi->nearheap = length;
printf("start=%FP segstart=%X seglen=%lu len=%lu\n", start, segstart, seglength, length);
//heapdump();
- //getch();
//
// get all available far conventional memory segments
mmi->mainmem = mmi->nearheap + mmi->farheap;
- getch();
+// getch();
//goto xmsskip;
unsigned needed,startseg;
needed = (size+15)/16; // convert size from bytes to paragraphs
-
+printf("."); //0000
MM_GetNewBlock(mm); // fill in start and next after a spot is found
mm->mmnew->length = needed;
mm->mmnew->useptr = baseptr;
mm->mmnew->attributes = BASEATTRIBUTES;
-
+printf("."); //0000
for(search = 0; search<3; search++)
{
+printf("|[case]"); //0000
//
// first search: try to allocate right after the rover, then on up
// second search: search from the head pointer up to the rover
switch(search)
{
case 0:
+printf("0"); //0000
lastscan = mm->mmrover;
scan = mm->mmrover->next;
endscan = NULL;
break;
case 1:
+printf("1"); //0000
lastscan = mm->mmhead;
scan = mm->mmhead->next;
endscan = mm->mmrover;
break;
case 2:
+printf("2"); //0000
MM_SortMem(mm);
lastscan = mm->mmhead;
scan = mm->mmhead->next;
while(scan != endscan)
{
+printf(","); //0000
if(scan->start - startseg >= needed)
{
+printf("\\"); //0000
//
// got enough space between the end of lastscan and
// the start of scan, so throw out anything in the middle
mm->mmnew->next = scan;
while(purge != scan)
{ // free the purgable block
+printf(" freeing block~\n"); //0000
next = purge->next;
MM_FreeBlock(purge, mm);
purge = next; // purge another if not at scan
if((scan->attributes & LOCKBIT)
|| !(scan->attributes & PURGEBITS) )
{
+printf("/[lock]"); //0000
lastscan = scan;
startseg = lastscan->start + lastscan->length;
}
*/
//****#if 0
-printf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); //bug!
+//printf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); //bug!
strcpy(scratch,"Seg:");
ultoa (scan->start,str,16);
strcat (scratch,str);
#include <malloc.h>
//#include <bios.h>
#include "src/lib/16_head.h"
+#include "src/lib/16_hc.h"
#include "src/lib/modex16.h"
//#include "src/lib/16_ca.h"
//++++mh #include "src/lib/16_in.h"