From: sparky4 Date: Mon, 3 Aug 2015 20:52:25 +0000 (-0500) Subject: Signed-off-by: sparky4 X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=3b3f3b4bc62245426ea4dec22cbfaa7cfbf13645;p=16.git Signed-off-by: sparky4 --- diff --git a/16.exe b/16.exe index 48790e24..addb6416 100644 Binary files a/16.exe and b/16.exe differ diff --git a/DEBUG.16 b/DEBUG.16 new file mode 100644 index 00000000..13e4d4d3 --- /dev/null +++ b/DEBUG.16 @@ -0,0 +1,8 @@ +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 diff --git a/HEAP.16 b/HEAP.16 new file mode 100644 index 00000000..96185784 --- /dev/null +++ b/HEAP.16 @@ -0,0 +1,45 @@ + + == 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 diff --git a/MMDUMP.16 b/MMDUMP.16 new file mode 100644 index 00000000..b14aef4e Binary files /dev/null and b/MMDUMP.16 differ diff --git a/PROFILE.16 b/PROFILE.16 new file mode 100644 index 00000000..e69de29b diff --git a/bakapi.exe b/bakapi.exe index e1c1f69d..de36892c 100644 Binary files a/bakapi.exe and b/bakapi.exe differ diff --git a/exmmtest.exe b/exmmtest.exe index eb7ba4e9..d3de90c1 100644 Binary files a/exmmtest.exe and b/exmmtest.exe differ diff --git a/fmemtest.exe b/fmemtest.exe index d67d4458..22b19432 100644 Binary files a/fmemtest.exe and b/fmemtest.exe differ diff --git a/fontgfx.exe b/fontgfx.exe index 0b932c07..b25350a2 100644 Binary files a/fontgfx.exe and b/fontgfx.exe differ diff --git a/fonttest.exe b/fonttest.exe index 2d6c1c5b..abd57e7c 100644 Binary files a/fonttest.exe and b/fonttest.exe differ diff --git a/inputest.exe b/inputest.exe index b8e4f4f8..01fa6582 100644 Binary files a/inputest.exe and b/inputest.exe differ diff --git a/makefile b/makefile index 55ed3f26..faa97ac9 100644 --- a/makefile +++ b/makefile @@ -22,7 +22,7 @@ WCPULIB=$(SRCLIB)wcpu$(DIRSEP) 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 @@ -31,7 +31,7 @@ FLAGS=$(OFLAGS) $(CFLAGS) $(DFLAGS) $(ZFLAGS) 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 @@ -267,6 +267,9 @@ emm.$(OBJ): $(DOSLIB)emm.h $(DOSLIB)emm.c 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 diff --git a/maptest.exe b/maptest.exe index 6ad04474..a1237bb1 100644 Binary files a/maptest.exe and b/maptest.exe differ diff --git a/palettec.exe b/palettec.exe index b38c6f72..e4ad17d4 100644 Binary files a/palettec.exe and b/palettec.exe differ diff --git a/pcxtest.exe b/pcxtest.exe index 87b9f8e4..a8ebf8a9 100644 Binary files a/pcxtest.exe and b/pcxtest.exe differ diff --git a/scroll.exe b/scroll.exe index d360c998..534f03b3 100644 Binary files a/scroll.exe and b/scroll.exe differ diff --git a/sega.exe b/sega.exe index 9ed4ba36..7d1e0dda 100644 Binary files a/sega.exe and b/sega.exe differ diff --git a/sountest.exe b/sountest.exe index 6df13ea9..8c9ac9b7 100644 Binary files a/sountest.exe and b/sountest.exe differ diff --git a/src/exmmtest.c b/src/exmmtest.c index c0bbc332..bee5e1dc 100644 --- a/src/exmmtest.c +++ b/src/exmmtest.c @@ -28,6 +28,7 @@ #include "src/lib/16_head.h" #include "src/lib/16_ca.h" #include "src/lib/16_mm.h" +#include "src/lib/16_hc.h" //#include "src/lib/modex16.h" #pragma hdrstop @@ -85,7 +86,7 @@ main(int argc, char *argv[]) printf("&bigbuffer= %Fp\n", &bigbuffer); printf("bigbuffer= %04x\n", bigbuffer); printf("&bigbuffer= %04x\n", &bigbuffer); - getch(); +// getch(); #ifdef FILERL // bakapeehandle = open(bakapee,O_RDONLY | O_BINARY, S_IREAD); // printf("size of big buffer~=%u\n", _bmsize(segu, bigbuffer)); @@ -132,15 +133,15 @@ main(int argc, char *argv[]) printf("&bigbuffer= %Fp\n", &bigbuffer); printf("bigbuffer= %04x\n", bigbuffer); printf("&bigbuffer= %04x\n", &bigbuffer); - printf("\n\n"); + /*printf("\n\n"); printf("Total free: %lu\n", (dword)(GetFreeSize())); printf("Total near free: %lu\n", (dword)(GetNearFreeSize())); printf("Total far free: %lu\n", (dword)(GetFarFreeSize())); - getch(); + getch();*/ printf("\n"); heapdump(); - printf("core left: %lu\n", (dword)_coreleft()); - printf("far core left: %lu\n", (dword)_farcoreleft()); + //printf("core left: %lu\n", (dword)_coreleft()); + //printf("far core left: %lu\n", (dword)_farcoreleft()); //printf("based core left: %lu\n", (dword)_basedcoreleft()); //printf("huge core left: %lu\n", (dword)_hugecoreleft()); } diff --git a/src/lib/16_hc.c b/src/lib/16_hc.c new file mode 100644 index 00000000..af747fc4 --- /dev/null +++ b/src/lib/16_hc.c @@ -0,0 +1,489 @@ +/* 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 , 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); +} diff --git a/src/lib/16_hc.h b/src/lib/16_hc.h new file mode 100644 index 00000000..7959d295 --- /dev/null +++ b/src/lib/16_hc.h @@ -0,0 +1,51 @@ +/* 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 , 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__ */ diff --git a/src/lib/16_head.c b/src/lib/16_head.c index 95a9e688..df0b31c7 100644 --- a/src/lib/16_head.c +++ b/src/lib/16_head.c @@ -38,323 +38,6 @@ void wait(clock_t wait){ while((goal > clock()) && !kbhit()) ; } /* 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 - 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; - } - 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) { @@ -367,7 +50,14 @@ filesize(FILE *fp) return(size_of_file); } -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); @@ -415,96 +105,6 @@ void convert(const char *format, dword num) 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" ); - } -} - - /////////////////////////////////////////////////////////////////////////// // // US_CheckParm() - checks to see if a string matches one of a set of diff --git a/src/lib/16_head.h b/src/lib/16_head.h index 3589a821..84a4a9eb 100644 --- a/src/lib/16_head.h +++ b/src/lib/16_head.h @@ -46,6 +46,7 @@ #include "src/lib/nyan/kitten.h" #include "src/lib/types.h" +//0000 test type def wwww struct list { struct list __based(__self) *next; int value; @@ -144,13 +145,10 @@ struct list { */ static dword far* clockdw= (dword far*) 0x046C; /* 18.2hz clock */ -//static dword clockdw=0; extern int profilehandle,debughandle; //make it into game global #define __DEBUG__ -//#define _SEGU(__p) ((unsigned)((unsigned long)(void __huge*)(__p) >> 16)) - #define nil ((void *)0) #define peekb(segm,ofs) (*(byte far*)MK_FP((segm),(ofs))) @@ -164,9 +162,6 @@ typedef union REGPACK regs_t; typedef enum {false,true} boolean; //I hope this is correct! typedef void __based(__self) * memptr; -//typedef sregs.w.es * memptr -//typedef __segment * memptr; -//typedef fenp.op_ptr_seg * memptr; typedef struct { int old_mode; //old video mode before game! @@ -174,26 +169,17 @@ typedef struct clock_t t; dword tiku; word far* clock; + //handles for log files of the game gose here if wwww + //int heaphandle; } global_game_variables_t; /* local function */ void wait(clock_t wait); -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); + long int filesize(FILE *fp); -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); +void print_normal_entry(char *text, dword total, dword used, dword free, byte *str); void convert(const char *format, dword num); -void heapdump(void); -void heapstat(int heap_status); int US_CheckParm(char *parm,char **strings); extern void CA_OpenDebug (void); diff --git a/src/lib/16_mm.c b/src/lib/16_mm.c index 1b887284..bff43730 100644 --- a/src/lib/16_mm.c +++ b/src/lib/16_mm.c @@ -684,7 +684,6 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi) 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 @@ -706,7 +705,7 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi) mmi->mainmem = mmi->nearheap + mmi->farheap; - getch(); +// getch(); //goto xmsskip; @@ -811,14 +810,15 @@ void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi) 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 @@ -829,16 +829,19 @@ void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi) 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; @@ -850,8 +853,10 @@ void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi) 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 @@ -863,6 +868,7 @@ void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi) 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 @@ -877,6 +883,7 @@ void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi) if((scan->attributes & LOCKBIT) || !(scan->attributes & PURGEBITS) ) { +printf("/[lock]"); //0000 lastscan = scan; startseg = lastscan->start + lastscan->length; } @@ -1208,7 +1215,7 @@ CA_OpenDebug (); */ //****#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); diff --git a/src/lib/16_mm.h b/src/lib/16_mm.h index 4298adb0..010a2626 100644 --- a/src/lib/16_mm.h +++ b/src/lib/16_mm.h @@ -25,6 +25,7 @@ #include //#include #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" diff --git a/test.exe b/test.exe index c2fb85a4..cbb49da8 100644 Binary files a/test.exe and b/test.exe differ diff --git a/test2.exe b/test2.exe index 1c8b210f..bd6ee779 100644 Binary files a/test2.exe and b/test2.exe differ diff --git a/tsthimem.exe b/tsthimem.exe index 8a00b50c..ddedc3e4 100644 Binary files a/tsthimem.exe and b/tsthimem.exe differ