]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_mm.c
wsomething is not working.... i think it is use space! wwww
[16.git] / src / lib / 16_mm.c
index 63eafca6a7701932d1fb7993d073a268ec45d8df..31655c923a4c014d3a26c51113586f20499f0c33 100644 (file)
@@ -47,6 +47,7 @@ Open Watcom port by sparky4
 
 */
 #include "src/lib/16_mm.h"
+#include "src/lib/16_ca.h"
 #pragma hdrstop
 
 #pragma warn -pro
@@ -474,13 +475,15 @@ void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
 {
        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.
@@ -564,7 +567,7 @@ void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
        mmblocktype huge *scan,huge *last;
        word            segm=1;
        word    oldend;
-       dword           segmlen=seglength;
+       dword           segmlen;
        dword           extra;
 
        scan = last = mm->mmhead;
@@ -577,25 +580,26 @@ void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
        {
                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;
@@ -640,6 +644,8 @@ void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
        if(extra > 0)
        {
                GETNEWBLOCK;
+               mm->mmnew->useptr = NULL;
+
                mm->mmnew->next = scan->next;
                scan->next = mm->mmnew;
                mm->mmnew->start = segstart+seglength;
@@ -707,7 +713,6 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
 
        mm->mmstarted = true;
        mm->bombonerror = true;
-       mm->endid=0;
 
 //
 // set up the linked list (everything in the free list;
@@ -779,6 +784,7 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
 // detect EMS and allocate up to 64K at page frame
 //
        mmi->EMSmem = 0;
+//goto emsskip;        //0000
        for(i = 1;i <
 #ifdef __WATCOMC__
        __argc
@@ -888,61 +894,56 @@ void MM_Shutdown(mminfo_t *mm)
 ====================
 */
 
-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
@@ -950,14 +951,12 @@ printf(".");      //0000
                        //
                                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;
@@ -967,16 +966,14 @@ printf("          freeing block~\n");     //0000
                        //
                        // 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
                }
        }
@@ -988,7 +985,6 @@ printf("\n");
 #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);
        }
@@ -1684,7 +1680,6 @@ void MM_BombOnError(boolean bomb, mminfo_t *mm)
                return;
        }
        mm->mmfree=mm->mmfree->next;
-       mm->endid++;    //end of list
 }
 
 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
@@ -1692,7 +1687,6 @@ 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)