--- /dev/null
+Seg:0 Size:109104 Owner:0xfdba\r
+Seg:1b9c Size:16 Owner:0xc31e\r
+Seg:1b9d Size:4096 Owner:0xc25c\r
+Seg:1f42 Size:789472 Owner:0xa8c\r
+\r
+MM_ShowMemory: Memory block order currupted!\r
+++ /dev/null
-Seg:0 Size:105952 Owner:0xfc46\r
-Seg:19de Size:4096 Owner:0x56f8\r
-Seg:218e Size:8080 Owner:0x46f6\r
-Seg:6385 Size:640928 Owner:0x2ef7\r
#-zk0 = kanji support~
#-zkl = current codepage
-ZFLAGS=-zk0 -zc# -zu -zm# -zdp# -zp16 -zq
+ZFLAGS=-zk0 -zu -zc# -zm# -zdp# -zp16 -zq
DFLAGS=-DTARGET_MSDOS=16 -DMSDOS=1
-CFLAGS=-wo -x -mc -wo -k32768#16384#
+CFLAGS=-ei -wo -x -mc -r -fh=16.hed -k60000#16384#
OFLAGS=-ot -ox -ob -oh -or -om -ol# -ol+
FLAGS=-0 -d2 -lr $(OFLAGS) $(CFLAGS) $(DFLAGS) $(ZFLAGS)
SRC=src$(DIRSEP)
#pragma warn -use
//file load or read definition
-//#define FILERL
-//#define FILEREAD
+#define FILERL
+#define FILEREAD
void
main(int argc, char *argv[])
mminfo_t mm; mminfotype mmi;
__segment segu;
#ifdef FILERL
- memptr bigbuffer;
- static char *bakapee;
+ memptr bigbuffer;
+ char *bakapee;
+// int bakapeehandle;
word baka;
#endif
//static page_t screen;
printf("main()=%Fp start MM\n", *argv[0]);
MM_Startup(&mm, &mmi);
+ //PM_Startup();\r
+ //PM_UnlockMainMem();\r
+ CA_Startup();
printf(" done!\n");
/*if(FP_SEG(*argv[0])==0)
{
exit(-5);
}*/
printf("&main()=%Fp\n", *argv[0]);
- printf("&segu=%p\n", (segu));
+ printf("&segu=%p\n", (segu));\r
//printf("mmi.segu=%p\n", (mmi.segu));
#ifdef FILERL
+// bakapeehandle = open(bakapee,O_RDONLY | O_BINARY, S_IREAD);
+ printf("size of big buffer~=%lu\n", _bmsize(segu, bigbuffer));
+// if(CA_FarRead(bakapeehandle,(void far *)&bigbuffer,sizeof(bigbuffer),&mm))
#ifdef FILEREAD
printf(" read\n");
if(CA_ReadFile(bakapee, &bigbuffer, &mm))
baka=1;
else
baka=0;
+// close(bakapeehandle);
//hmm functions in cache system use the buffered stuff
printf("size of big buffer~=%lu\n", _bmsize(segu, bigbuffer));
#endif
#ifdef FILERL
MM_FreePtr(&bigbuffer, &mm);
#endif
+ //PM_Shutdown();
+ CA_Shutdown();
MM_Shutdown(&mm);
printf(" done!\n");
#ifdef FILERL
*/\r
void CA_OpenDebug(void)\r
{\r
- unlink("debug.txt");\r
- debughandle = open("debug.txt", O_CREAT | O_WRONLY | O_TEXT);\r
+ unlink("debug.16");\r
+ debughandle = open("debug.16", O_CREAT | O_WRONLY | O_TEXT);\r
}\r
\r
void CA_CloseDebug(void)\r
boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm)\r
{\r
int handle;\r
- dword size;\r
+ dword size;
+ //long size;\r
\r
if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1)\r
return false;\r
boolean CA_LoadFile(char *filename, memptr *ptr, mminfo_t *mm, mminfotype *mmi)\r
{\r
int handle;\r
- long size;\r
+ dword size;
+ //long size;\r
\r
if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1)\r
return false;\r
void CA_Startup(void)\r
{\r
#ifdef PROFILE\r
- unlink("PROFILE.TXT");\r
- profilehandle = open("PROFILE.TXT", O_CREAT | O_WRONLY | O_TEXT);\r
+ unlink("profile.16");\r
+ profilehandle = open("profile.16", O_CREAT | O_WRONLY | O_TEXT);\r
#endif\r
/*++++\r
// MDM begin - (GAMERS EDGE)\r
//#define AUDIOHEADERLINKED\r
\r
//#define NUMMAPS 39\r
-//#define MAPPLANES 3\r
+//#define MAPPLANES 3
+#define PROFILE\r
\r
//===========================================================================\r
\r
#include "src/lib/16_head.h"
-/* local function */\r
-void wait(clock_t wait);
-void* AllocateLargestFreeBlock(size_t* Size);
-size_t GetFreeSize(void);
-long int filesize(FILE *fp);\r
-\r
/* Function: Wait **********************************************************\r
*\r
* Parameters: wait - time in microseconds\r
return total;
}
+void far* AllocateLargestFarFreeBlock(size_t far* 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 GetFarFreeSize(void)
+{
+ size_t total = 0;
+ void far* pFirst = NULL;
+ void far* pLast = NULL;
+ for(;;)
+ {
+ size_t largest;
+ void far* p = AllocateLargestFarFreeBlock(&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;
+}
+
long int
filesize(FILE *fp)\r
{\r
typedef union REGPACK regs_t;
typedef enum {false,true} boolean;
+/* local function */\r
void wait(clock_t wait);
void* AllocateLargestFreeBlock(size_t* Size);
size_t GetFreeSize(void);
+void far *AllocateLargestFarFreeBlock(size_t far* Size);
+size_t GetFarFreeSize(void);
long int filesize(FILE *fp);
int US_CheckParm(char *parm,char **strings);
-//void Quit(char *error, ...);
extern void CA_OpenDebug (void);\r
extern void CA_CloseDebug (void);
*/
#include "src/lib/16_mm.h"
-#pragma hdrstop\r
-\r
-#pragma warn -pro\r
+#pragma hdrstop
+
+#pragma warn -pro
#pragma warn -use
/*
//
// get all available near conventional memory segments
//
- printf(" nearheap making!\n");
//---- length=coreleft();
+ printf(" nearheap making!\n");
_heapgrow();
- length=_memmax();
+ length=_memmax();//(dword)GetFreeSize();
start = (void huge *)(mm->nearheap = malloc(length));
length -= 16-(FP_OFF(start)&15);
length -= SAVENEARHEAP;
segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
MML_UseSpace(segstart,seglength, mm);
mmi->nearheap = length;
- printf("start=%Fp segstart=%x seglen=%lu len=%lu\n", start, segstart, seglength, length);
- /*switch( _nheapchk() ) {
- case _HEAPOK:
- printf( "OK - nearheap is good\n" );
- break;
- case _HEAPEMPTY:
- printf( "OK - nearheap is empty\n" );
- break;
- case _HEAPBADBEGIN:
- printf( "ERROR - nearheap is damaged\n" );
- break;
- case _HEAPBADNODE:
- printf( "ERROR - bad node in nearheap\n" );
- break;
- }*/
+ printf("start=%FP segstart=%X seglen=%lu len=%lu\n", start, segstart, seglength, length);
printf(" near heap ok!\n");
//
//---- length=farcoreleft();
printf(" farheap making!\n");
_fheapgrow();
- length=0xffffUL*4UL;
- start = mm->farheap = halloc(length, sizeof(byte));
- //start = mm->farheap = _fmalloc(length);
+ length=(dword)GetFarFreeSize();//0xffffUL*4UL;
+ //start = mm->farheap = halloc(length, 1);
+ start = mm->farheap = _fmalloc(length);
length -= 16-(FP_OFF(start)&15);
length -= SAVEFARHEAP;
seglength = length / 16; // now in paragraphs
segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
MML_UseSpace(segstart,seglength, mm);
mmi->farheap = length;
- mmi->mainmem = mmi->nearheap + mmi->farheap;
- printf("start=%Fp segstart=%x seglen=%lu len=%lu\n", start, segstart, seglength, length);
- /*switch( _fheapchk() ) {
- case _HEAPOK:
- printf( "OK - farheap is good\n" );
- break;
- case _HEAPEMPTY:
- printf( "OK - farheap is empty\n" );
- break;
- case _HEAPBADBEGIN:
- printf( "ERROR - farheap is damaged\n" );
- break;
- case _HEAPBADNODE:
- printf( "ERROR - bad node in farheap\n" );
- break;
- }*/
+ printf("start=%FP segstart=%X seglen=%lu len=%lu\n", start, segstart, seglength, length);
printf(" far heap ok!\n");
+ mmi->mainmem = mmi->nearheap + mmi->farheap;
+
+ getch();
+
//
// detect EMS and allocate up to 64K at page frame
//
-/*printf(" EMS1\n");
+printf(" EMS1\n");
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!
mmi->EMSmem = 0;
for(i = 1;i < __argc;i++)
//
// detect XMS and get upper memory blocks
//
-emsskip:
+emsskip:/*
mmi->XMSmem = 0;
for(i = 1;i < __argc;i++)
{
//
xmsskip:*/
/*mmi->nearheap = 0;
-mmi->farheap = 0;*/
-mmi->EMSmem = 0;
+mmi->farheap = 0;
+mmi->EMSmem = 0;*/
mmi->XMSmem = 0;
mm->mmrover = mm->mmhead; // start looking for space after low block
if(!(mm->mmstarted))
return;
- _ffree(mm->farheap);
- printf(" far freed\n");
- free(mm->nearheap);
- printf(" near freed\n");
- //hfree(mm->hugeheap);
- //printf("huge freed\n");
+ _ffree(mm->farheap); printf(" far freed\n");
+ free(mm->nearheap); printf(" near freed\n");
if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); printf(" EMS freed\n"); }
if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); printf(" XMS freed\n"); }
}
}
if (mm->bombonerror)
+ {
printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
+ exit(-5);
+ }
else
mm->mmerror = true;
}
//++++free(mm->nearheap);
- dumpfile = fopen ("mmdump.txt","w");
+ dumpfile = fopen ("mmdump.16","w");
if (!dumpfile){
- printf("MM_DumpData: Couldn't open MMDUMP.TXT!\n");
+ printf("MM_DumpData: Couldn't open MMDUMP.16!\n");
return;
}
} while (lowest != 0xffff);
fclose(dumpfile);
- printf("MMDUMP.TXT created.\n");
+ printf("MMDUMP.16 created.\n");
}
//==========================================================================
scan = scan->next;
}
- return free*16l;
-// return free;
+// return free*16l;
+ return free;
}
//==========================================================================
scan = scan->next;
}
- return free*16l;
-// return free;
+// return free*16l;
+ return free;
}
//==========================================================================
#define SAVENEARHEAP 0//x200 // space to leave in data segment
-#define SAVEFARHEAP 0//x2000 // space to leave in far heap
+#define SAVEFARHEAP 0x400 // space to leave in far heap
#define BUFFERSIZE 0x1000 // miscelanious, allways available buffer
// Primary coder: Jason Blochowiak\r
//\r
\r
-#include "ID_HEADS.H"\r
+#include "src/lib/16_pm.h"\r
#pragma hdrstop\r
\r
// Main Mem specific variables\r
//\r
void\r
PML_MapEMS(word logical,word physical)\r
-{\r
- _AL = physical;\r
- _BX = logical;\r
- _DX = EMSHandle;\r
- _AH = EMS_MAPPAGE;\r
-asm int EMS_INT\r
+{
+ union REGS CPURegs;\r
+ CPURegs.h.al = physical;\r
+ CPURegs.x.bx = logical;\r
+ CPURegs.x.dx = EMSHandle;\r
+ CPURegs.h.ah = EMS_MAPPAGE;\r
+ __asm
+ {
+ int EMS_INT
+ }\r
\r
- if (_AH)\r
- Quit("PML_MapEMS: Page mapping failed");\r
+ if(CPURegs.h.ah)\r
+ printf("PML_MapEMS: Page mapping failed\n");\r
}\r
\r
//\r
asm mov dx,[EMSHandle]\r
asm int EMS_INT\r
if (_AH)\r
- Quit ("PML_ShutdownEMS: Error freeing EMS");\r
+ printf("PML_ShutdownEMS: Error freeing EMS\n");\r
}\r
}\r
\r
void\r
PML_XMSCopy(boolean toxms,byte far *addr,word xmspage,word length)\r
{\r
- longword xoffset;\r
+ dword xoffset;\r
struct\r
{\r
longword length;\r
} copy;\r
\r
if (!addr)\r
- Quit("PML_XMSCopy: zero address");\r
+ printf("PML_XMSCopy: zero address\n");\r
\r
xoffset = (longword)xmspage * PMPageSize;\r
\r
if (!noxms)\r
PML_StartupXMS();\r
\r
- if (nomain && !EMSPresent)\r
- Quit("PM_Startup: No main or EMS");\r
+ if (nomain && !EMSPresent)
+ {\r
+ printf("PM_Startup: No main or EMS\n");
+ return;
+ }\r
else\r
PML_StartupMainMem();\r
\r