//
mov emmcfems,1
jmp End
+#ifdef __BORLANDC__
+ }
+#endif
error:
+#ifdef __BORLANDC__
+ __asm {
+#endif
//
// EMS is bad
//
mov emmcfems,0
+#ifdef __BORLANDC__
+ }
+#endif
End:
+#ifdef __WATCOMC__
}
+#endif
return(emmcfems);
}
unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
- __asm
- {
+ __asm {
mov ah,EMS_STATUS
int EMS_INT // make sure EMS hardware is present
or ah,ah
jle getpages
mov bx,[freeEMSpages]
jmp getpages
-
-low:
+#ifdef __BORLANDC__
+ }
+#endif
+ low:
+#ifdef __BORLANDC__
+ __asm {
+#endif
cmp bx,4
jle getpages // there is only 1,2,3,or 4 pages
mov bx,4 // we can't use more than 4 pages
-
-getpages:
+#ifdef __BORLANDC__
+ }
+#endif
+ getpages:
+#ifdef __BORLANDC__
+ __asm {
+#endif
mov [EMSpagesmapped],bx
mov ah,EMS_ALLOCPAGES // allocate up to 64k of EMS
int EMS_INT
jnz error
mov [EMShandle],dx
jmp End
-error:
+#ifdef __BORLANDC__
+ }
+#endif
+ error:
+#ifdef __BORLANDC__
+ __asm {
+#endif
mov err,ah
mov errorflag,1
jmp End
+#ifdef __BORLANDC__
+ }
+#endif
noEMS:
End:
+#ifdef __WATCOMC__
}
+#endif
if(errorflag==true)
{
//err = CPURegs.h.ah;
strcpy(str,"MM_SetupEMS: EMS error ");
//itoa(err,str2,16);
- MM_EMSerr(&str, err);
+ MM_EMSerr(str, err);
printf("%s\n",str);
return err;
}
if(!EMShandle)
return;
- __asm
- {
+ __asm {
mov ah,EMS_FREEPAGES
mov dx,[EMShandle]
int EMS_INT
or ah,ah
jz ok
mov errorflag,1
+#ifdef __BORLANDC__
+ }
+#endif
ok:
+#ifdef __WATCOMC__
}
+#endif
if(errorflag==true) printf("MML_ShutdownEMS: Error freeing EMS!\n"); //++++ add something
}
for (i=0;i<4/*MAPPAGES*/;i++)
{
- __asm
- {
+ __asm {
mov ah,EMS_MAPPAGE
mov bx,[i] // logical page
mov al,bl // physical page
or ah,ah
jnz error
jmp End
+#ifdef __BORLANDC__
+ }
+#endif
error:
+#ifdef __BORLANDC__
+ __asm {
+#endif
mov err,ah
mov errorflag,1
+#ifdef __BORLANDC__
+ }
+#endif
End:
+#ifdef __WATCOMC__
}
+#endif
if(errorflag==true)
{
//err = CPURegs.h.ah;
for (i=0;i<MAPPAGES;i++)
{
- __asm
- {
+ __asm {
mov ah,EMS_MAPXPAGE
mov cx,[i] // logical page
mov al,bl // physical page
or ah,ah
jnz error
jmp End
+#ifdef __BORLANDC__
+ }
+#endif
error:
+#ifdef __BORLANDC__
+ __asm {
+#endif
mov err,ah
mov errorflag,1
+#ifdef __BORLANDC__
+ }
+#endif
End:
+#ifdef __WATCOMC__
}
+#endif
if(errorflag==true)
{
//err = CPURegs.h.ah;
//strcpy(str,"MM_MapXEMS: EMS error 0x");
strcpy(str,"MM_MapXEMS: EMS error ");
//itoa(err,str2,16);
- MM_EMSerr(&str, err);
+ MM_EMSerr(str, err);
printf("%s\n",str);
//printf("%s%x\n",str, err);
//printf("FACK! %x\n", err);
boolean errorflag=false;
mm->numUMBs = 0;
- __asm
- {
+ __asm {
mov ax,0x4300
int 0x2f // query status of installed diver
cmp al,0x80
je good
mov errorflag,1
+#ifdef __BORLANDC__
+ }
+#endif
good:
+#ifdef __WATCOMC__
}
+#endif
if(errorflag==true) return false;
else return true;
}
unsigned base,size;
getmemory:
- __asm
- {
+ __asm {
mov ax,0x4310
int 0x2f
mov [WORD PTR XMSaddr],bx
call [DWORD PTR XMSaddr] // DX holds largest available UMB
or ax,ax
jz done // another error...
-
-gotone:
+#ifdef __BORLANDC__
+ }
+#endif
+ gotone:
+#ifdef __BORLANDC__
+ __asm {
+#endif
mov [base],bx
mov [size],dx
-done:
+#ifdef __BORLANDC__
+ }
+#endif
+ done:
+#ifdef __WATCOMC__
}
+#endif
printf("base=%u ", base); printf("size=%u\n", size);
MML_UseSpace(base,size, mm);
mmi->XMSmem += size*16;
for (i=0;i<mm->numUMBs;i++)
{
base = mm->UMBbase[i];
- __asm
- {
+ __asm {
mov ah,XMS_FREEUMB
mov dx,[base]
call [DWORD PTR XMSaddr]
if(seglength>0xffffu)
{
// segm=seglength/0x4000u;
- segm=seglength/0xffffu;
+ segm=(word)seglength/0xffffu;
}
else segm=1;
mm->mmstarted = true;
mm->bombonerror = true;
+ mm->endid=0;
//
// set up the linked list (everything in the free list;
//
// get all available near conventional memory segments
//
-//---- length=coreleft();
- printf(" nearheap making!\n");
- _heapgrow();
- length=_memmax();//(dword)GetFreeSize();
+// printf(" nearheap making!\n");
+#ifdef __WATCOMC__
+ _nheapgrow();
+ length=(dword)_memmax();//(dword)GetFreeSize();
+ start = (void huge *)(mm->nearheap = _nmalloc(length));
+#endif
+#ifdef __BORLANDC__
+ length=coreleft();
start = (void huge *)(mm->nearheap = malloc(length));
+#endif
length -= 16-(FP_OFF(start)&15);
length -= SAVENEARHEAP;
seglength = length / 16; // now in paragraphs
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);
- printf(" near heap ok!\n");
+ printf("start=%Fp segstart=%x seglen=%l len=%l\n", start, segstart, seglength, length);
+ //heapdump();
//
// get all available far conventional memory segments
//
-//---- length=farcoreleft();
- printf(" farheap making!\n");
+// printf(" farheap making!\n");
+#ifdef __WATCOMC__
_fheapgrow();
length=(dword)GetFarFreeSize();//0xffffUL*4UL;
+#endif
+#ifdef __BORLANDC__
+ length=farcoreleft();
+#endif
//start = mm->farheap = halloc(length, 1);
start = mm->farheap = _fmalloc(length);
length -= 16-(FP_OFF(start)&15);
segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
MML_UseSpace(segstart,seglength, mm);
mmi->farheap = length;
- printf("start=%FP segstart=%X seglen=%lu len=%lu\n", start, segstart, seglength, length);
- printf(" far heap ok!\n");
+ printf("start=%Fp segstart=%x seglen=%l len=%l\n", start, segstart, seglength, length);
+ //heapdump();
mmi->mainmem = mmi->nearheap + mmi->farheap;
- getch();
+// getch();
+
+//goto xmsskip;
//
// detect EMS and allocate up to 64K at page frame
//
-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!
+//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++)
+ for(i = 1;i <
+#ifdef __WATCOMC__
+ __argc
+#endif
+#ifdef __BORLANDC__
+ _argc
+#endif
+ ;i++)
{
- if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
+ if(US_CheckParm(
+#ifdef __WATCOMC__
+ __argv[i]
+#endif
+#ifdef __BORLANDC__
+ _argv[i]
+#endif
+ ,ParmStringsexmm) == 0)
goto emsskip; // param NOEMS
}
-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!
if(MML_CheckForEMS())
{
-printf(" EMS2\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!
+//printf(" EMS2\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!
MML_SetupEMS(mm); // allocate space
-printf(" EMS3\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!
+//printf(" EMS3\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!
//TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
-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(" EMS4\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!
+//printf(" EMS4\n");
//if(mm->EMSVer<0x40)
MM_MapEMS(mm, mmi); // map in used pages
//else
//MM_MapXEMS(mm, mmi); // map in used pages
}
+mmi->XMSmem=0;
+goto xmsskip;
+
//
// detect XMS and get upper memory blocks
//
emsskip:
mmi->XMSmem = 0;
- for(i = 1;i < __argc;i++)
+ for(i = 1;i <
+#ifdef __WATCOMC__
+ __argc
+#endif
+#ifdef __BORLANDC__
+ _argc
+#endif
+ ;i++)
{
- if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
+ if(US_CheckParm(
+#ifdef __WATCOMC__
+ __argv[i]
+#endif
+#ifdef __BORLANDC__
+ _argv[i]
+#endif
+ ,ParmStringsexmm) == 0)
goto xmsskip; // param NOXMS
}
-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!
if(MML_CheckForXMS(mm))
{
-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(" XMS!\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!
+//printf(" XMS!\n");
MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible
}
return;
_ffree(mm->farheap); printf(" far freed\n");
+#ifdef __WATCOMC__
+ _nfree(mm->nearheap); printf(" near freed\n");
+#endif
+#ifdef __BORLANDC__
free(mm->nearheap); printf(" near freed\n");
+#endif
if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); printf(" EMS freed\n"); }
if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); printf(" XMS freed\n"); }
}
{
mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
int search;
- unsigned needed,startseg;
+ dword needed;
+ word 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;
-
- for(search = 0; search<3; search++)
+printf("."); //0000
+ for(search = 0; search<mm->endid; 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;
break;
}
- startseg = lastscan->start + lastscan->length;
+ startseg = lastscan->start + (word)lastscan->length;
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
//
purge = lastscan->next;
lastscan->next = mm->mmnew;
- mm->mmnew->start = *(unsigned *)baseptr = startseg;
+ mm->mmnew->start = *(word *)baseptr = startseg;
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
+printf("len=%lu ", scan->length);
lastscan = scan;
- startseg = lastscan->start + lastscan->length;
+ startseg = lastscan->start + (word)lastscan->length;
}
-
+printf("\n");
scan=scan->next; // look at next line
}
}
if (mm->bombonerror)
{
+#ifdef __WATCOMC__
+ heapdump();
+#endif
printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
- exit(-5);
+ printf("for stability reasons the program will shut down! wwww\n");
+ printf(" endid=%u\n",(mm->endid));
+ MM_Shutdown(mm);
+ exit(-1);
}
else
mm->mmerror = true;
void MM_ShowMemory(/*page_t *page, */mminfo_t *mm)
{
mmblocktype huge *scan;
- word color,temp;
+//++++ word color;
+ word temp;
long end,owner;
- word chx,chy;
+//++++ word chx,chy;
byte scratch[160],str[16];
//**** VW_SetDefaultColors();
CA_OpenDebug ();
- chx=0;
- chy=0;
+//++++ chx=0;
+//++++ chy=0;
while(scan)
{
- if(scan->attributes & PURGEBITS)
+/*++++ if(scan->attributes & PURGEBITS)
color = 5; // dark purple = purgable
else
color = 9; // medium blue = non purgable
if(scan->attributes & LOCKBIT)
- color = 12; // red = locked
+ color = 12; // red = locked*/
if(scan->start<=end)
{
//printf(");
return;
}
end = scan->start+scan->length-1;
- chy = scan->start/320;
- chx = scan->start%320;
+//++++ chy = scan->start/320;
+//++++ chx = scan->start%320;
//modexhlin(page, scan->start, (unsigned)end, chy, color);
//for(chx=scan->start;chx+4>=(word)end;chx+=4)
//{
*/
//****#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);
MML_ClearBlock(mm);
mm->mmnew=mm->mmfree;
mm->mmfree=mm->mmfree->next;
- /*if(!(mm->mmnew=mm->mmfree))
+ if(!(mm->mmnew=mm->mmfree))
{
- printf("MM_GETNEWBLOCK: No free blocks!");
+ printf("MM_GETNEWBLOCK: No free blocks!\n");
return;
}
- mm->mmfree=mm->mmfree->next;*/
+ mm->mmfree=mm->mmfree->next;
+ mm->endid++; //end of list
}
void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
x->useptr=NULL;
x->next=mm->mmfree;
mm->mmfree=x;
+ mm->endid--; //end of list
}
void MM_seguin(void)