]> 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 46be242fc060ea8772f162f5ac3b9b61ba965b41..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;
@@ -579,21 +582,24 @@ void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
                scan = scan->next;
        }
 
-       //find out how many blocks it spans!
-       //
-       for(;seglength>0x10000;seglength-=0xffff)
-       {
-               printf("                seglen=%lu\n", seglength);
-               segm++;
-       }
-
 //
 // take the given range out of the block
 //
        oldend = scan->start + scan->length;
-       extra = oldend - (segstart+(word)seglength);
+       extra = oldend - (segstart+seglength);
+
+       segmlen=extra;
+//
+// find out how many blocks it spans!
+//
+       for(;segmlen>0x10000;segmlen-=0x10000)
+       {
+               //printf("      seglen=%lu\n", segmlen);
+               segm++;
+       }
+
        //++++emsver stuff!
-       if(segm>1 || extra>0x10000lu)
+       if(segm>1/* || extra>=0x10000lu*/)
        //if(extra>0xfffflu)
        {
                scan->blob=segm;
@@ -638,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;
@@ -705,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;
@@ -777,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
@@ -886,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
@@ -948,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;
@@ -965,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
                }
        }
@@ -986,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);
        }
@@ -1235,11 +1233,11 @@ void MM_SortMem(mminfo_t *mm)
 void MM_ShowMemory(global_game_variables_t *gvar,/*page_t *page, */mminfo_t *mm)
 {
        mmblocktype huge *scan;
-       //byte color;
        word temp;
        sdword  end,owner;
        //word chx,chy;
        word w;
+       dword wwww;
        byte    scratch[160],scratch0[4096],str[16];
        //byte d = '#';
 //**** VW_SetDefaultColors();
@@ -1275,7 +1273,6 @@ void MM_ShowMemory(global_game_variables_t *gvar,/*page_t *page, */mminfo_t *mm)
                        //modexprint(&page, chx, chy, 1, 0, 24, "\nMM_ShowMemory: Memory block order currupted!\n");
                        break;
                }
-               //for(;scan->length>0xfffflu;scan->length-=0xfffflu);
                end = scan->start+(scan->length)-1;
 //++++         chy = scan->start/320;
 //++++         chx = scan->start%320;
@@ -1288,34 +1285,44 @@ void MM_ShowMemory(global_game_variables_t *gvar,/*page_t *page, */mminfo_t *mm)
                for(w=(scan->start)/80;w<=end/80;w++)
                {
                        //printf("+     %u      %lu\n", w, scan->length);
-                       //if(w==48) getch();
                        strcat(scratch0, "+");
                }
                strcat(scratch0, AARESET); strcat(scratch0, AAGREY); strcat(scratch0,"_");
 //++++         VW_Plot(scan->start,0,15);
 //++++                         modexClearRegion(page, chx, chy, 4, 4, 15);
 //++++                 VW_Hlin(end+1,scan->next->start,0,0);   // black = free
-               if((scan->next->start != 0xe000) > end)
+
+               wwww=(dword)(scan->next->start)-(dword)scan->start;
+               //wwww=(dword)scan->start+(dword)(scan->next->start);
+               if (scan->next && scan->next->start >= end+1)
                {
                        strcat(scratch0, AARESET);
+                       strcat(scratch0, "\n");
                        strcat(scratch0,AAGREEN);
-                       for(w=0;w<=((scan->length+1)/80);w++)
+                       for(w=(end+1)/80;w<=(wwww/80);w++)
                        {
                                //printf("0     %x      %u      %lu\n", scan->next->start, w, scan->length);
                                strcat(scratch0,"0");
                        }
-               }else{
+                       //printf("==================\n");
+                       //printf("w=%x  start=%x        next=%x end=%u  %lu\n", w, scan->start, (scan->next->start), end+1, wwww);
+                       //printf("==================\n");
+               }/*else {//if(scan->next->start <= scan->start){
+                       scan->next->start=scan->start+0x1000;
+                       wwww=(dword)(scan->next->start)-(dword)scan->start;
                        strcat(scratch0, AARESET);
+                       strcat(scratch0, "\n");
                        strcat(scratch0,AAGREEN);
-                       for(w=0;w<=((scan->length+1)/80);w++)
+                       for(w=(end+1);w<=(0x1000/80);w++)
                        {
-                               //printf("0     %x      %u      %lu\n", scan->next->start, w, scan->length);
+                               //printf("0     %x      %x      %u\n", scan->start, w);
                                strcat(scratch0,"0");
                        }
-                       printf("================\nstart=%x      length==%lu\n           next=%x end=%x\nscan->start+(scan->length)==%x\n================\n", scan->start, scan->length, scan->next->start, end, scan->start+(scan->length));
-                       printf("w=%u    (scan->length+1)/80)=%lu\n\n", w, (scan->length+1)/80);
-                       //getch();
-               }
+                       printf("================\n");
+                       printf("w=%x    start=%x        next=%x end=%u  %lu\n", w, scan->start, (scan->next->start), end+1, wwww);
+                       printf("================\n");
+//                     getch();
+               }*/
                strcat(scratch0, AARESET);
                strcat(scratch0,"\n");
                        //for(chx=scan->next->start;chx+4>=(word)end+1;chx+=4)
@@ -1673,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)
@@ -1681,10 +1687,9 @@ 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)
+/*void MM_seguin(void)
 {
        __asm {
                push    ds
@@ -1699,7 +1704,7 @@ void MM_segude(void)
        __asm {
                pop ds
        }
-}
+}*/
 
 /*
 pull data from far and put it into ds var