*/
#include "src/lib/16_mm.h"
+#include "src/lib/16_ca.h"
#pragma hdrstop
#pragma warn -pro
{
word base,size;
-getmemory:
+
__asm {
mov ax,0x4310
int 0x2f
mov [WORD PTR XMSaddr],bx
mov [WORD PTR XMSaddr+2],es // function pointer to XMS driver
-
+ }
+getmemory:
+ __asm {
mov ah,XMS_ALLOCUMB
mov dx,0xffff // try for largest block possible
//mov ax,dx // Set available Kbytes.
mmblocktype huge *scan,huge *last;
word segm=1;
word oldend;
- dword segmlen=seglength;
+ dword segmlen;
dword extra;
scan = last = mm->mmhead;
{
last = scan;
scan = scan->next;
- //printf(" start=%x",scan->start);
- //printf(" seglen=%lu\n", scan->length);
}
- //find out how many blocks it spans!
- //
+//
+// take the given range out of the block
+//
+ oldend = scan->start + scan->length;
+ extra = oldend - (segstart+seglength);
+
+ segmlen=extra;
+//
+// find out how many blocks it spans!
+//
for(;segmlen>0x10000;segmlen-=0x10000)
{
//printf(" seglen=%lu\n", segmlen);
segm++;
}
-//
-// take the given range out of the block
-//
- oldend = scan->start + scan->length;
- extra = oldend - (segstart+(word)seglength);
//++++emsver stuff!
- if(segm>1 || extra>=0x10000lu)
+ if(segm>1/* || extra>=0x10000lu*/)
//if(extra>0xfffflu)
{
scan->blob=segm;
if(extra > 0)
{
GETNEWBLOCK;
+ mm->mmnew->useptr = NULL;
+
mm->mmnew->next = scan->next;
scan->next = mm->mmnew;
mm->mmnew->start = segstart+seglength;
mm->mmstarted = true;
mm->bombonerror = true;
- mm->endid=0;
//
// set up the linked list (everything in the free list;
// detect EMS and allocate up to 64K at page frame
//
mmi->EMSmem = 0;
+//goto emsskip; //0000
for(i = 1;i <
#ifdef __WATCOMC__
__argc
====================
*/
-void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi)
+void MM_GetPtr (memptr *baseptr, dword size, mminfo_t *mm, mminfotype *mmi)
{
- mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
+ mmblocktype huge *scan,huge *lastscan,huge *endscan
+ ,huge *purge,huge *next;
int search;
- dword needed;
- word startseg;
+ unsigned needed,startseg;
needed = (size+15)/16; // convert size from bytes to paragraphs
-printf("."); //0000
+
GETNEWBLOCK; // 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<mm->endid; search++)
+
+//tryagain:
+ 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
// third search: compress memory, then scan from start
- if(search == 1 && mm->mmrover == mm->mmhead)
+ if (search == 1 && mm->mmrover == mm->mmhead)
search++;
- switch(search)
+ 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);
+ MM_SortMem (mm);
lastscan = mm->mmhead;
scan = mm->mmhead->next;
endscan = NULL;
break;
}
- startseg = lastscan->start + (word)lastscan->length;
+ startseg = lastscan->start + lastscan->length;
- while(scan != endscan)
+ while (scan != endscan)
{
-//printf(","); //0000
- if(scan->start - startseg >= needed)
+ 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 = *(word *)baseptr = startseg;
+ mm->mmnew->start = *(unsigned *)baseptr = startseg;
mm->mmnew->next = scan;
- while(purge != scan)
+ while ( purge != scan)
{ // free the purgable block
-printf(" freeing block~\n"); //0000
next = purge->next;
FREEBLOCK(purge);
- //MM_FreeBlock(purge, mm);
purge = next; // purge another if not at scan
}
mm->mmrover = mm->mmnew;
//
// if this block is purge level zero or locked, skip past it
//
- if((scan->attributes & LOCKBIT)
+ if ( (scan->attributes & LOCKBIT)
|| !(scan->attributes & PURGEBITS) )
{
-printf(" [lock] "); //0000
-printf("len=%lu ", scan->length);
lastscan = scan;
- startseg = lastscan->start + (word)lastscan->length;
+ startseg = lastscan->start + lastscan->length;
}
-printf("\n");
+
scan=scan->next; // look at next line
}
}
#endif
printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
printf("for stability reasons the program will shut down! wwww\n");
- printf(" endid=%u\n",(mm->endid));
MM_Shutdown(mm);
exit(-1);
}
return;
}
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)