]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_mm.c
fixed the show memory output well~
[16.git] / src / lib / 16_mm.c
index 530bc45b2ad9d7f2c982e94b675a993030b4a6b4..f03d56a1ae306b95c0f91a333d4af7830f07ec1c 100644 (file)
@@ -174,7 +174,7 @@ unsigned MML_SetupEMS(mminfo_t *mm)
                mov     [freeEMSpages],bx
                or      bx,bx
                jz      noEMS                                           // no EMS at all to allocate
-//++++EXPAND DONG!!!!
+                                                                                       //EXPAND DONG!!!!
                cmp     [EMSVer],0x40
                jb      low
                cmp     bx,[freeEMSpages]
@@ -353,6 +353,7 @@ getmemory:
 
                mov     ah,XMS_ALLOCUMB
                mov     dx,0xffff                                       // try for largest block possible
+               //mov     ax,dx                                         // Set available Kbytes.
                call    [DWORD PTR XMSaddr]
                or      ax,ax
                jnz     gotone
@@ -370,6 +371,7 @@ gotone:
                mov     [size],dx
 done:
        }
+       printf("base=%u ", base); printf("size=%u\n", size);
        MML_UseSpace(base,size, mm);
        mmi->XMSmem += size*16;
        mm->UMBbase[mm->numUMBs] = base;
@@ -418,16 +420,17 @@ void MML_ShutdownXMS(mminfo_t *mm)
 ======================
 */
 
-void MML_UseSpace(unsigned segstart, dword seglength, mminfo_t *mm)
+void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm)
 {
        mmblocktype huge *scan,huge *last;
        dword   oldend;
-       dword fat=0;
-       word segm=0;
+       ///*d*/word fat=0;
        dword           extra;
 
        scan = last = mm->mmhead;
        mm->mmrover = mm->mmhead;               // reset rover to start of memory
+       scan->segm=1;
+       scan->segmlen=seglength;
 
 //
 // search for the block that contains the range of segments
@@ -438,6 +441,12 @@ void MML_UseSpace(unsigned segstart, dword seglength, mminfo_t *mm)
                scan = scan->next;
        }
 
+       //find out how many blocks it span!
+       if(seglength>0xfffflu)
+       {
+               scan->segm=seglength/0xfffflu;
+       }
+
 //
 // take the given range out of the block
 //
@@ -446,12 +455,26 @@ void MML_UseSpace(unsigned segstart, dword seglength, mminfo_t *mm)
        //++++emsver stuff!
        if(extra>0xfffflu)
        {
-               segm=(extra%(0xfffflu))-1;
-               fat=segm*(0xfffflu);
-               extra-=fat;
-//printf("extra=%lu    ", extra);
-//printf("segm=%lu\n", segm);
-               printf("MML_UseSpace: Segment spans two blocks!\n");\r
+               /*__asm
+               {
+                       push    ds
+                       mov     ax,ds
+                       inc             ax
+                       mov     ds,ax
+               }*/
+printf("segm=%u        ", scan->segm);
+printf("ex=%lu ", extra);
+printf("len=%u ", scan->length);
+printf("segsta=%u      ", segstart);
+printf("seglen=%lu\n", seglength);
+
+//MML_UseSpace(?segstart?, ?length?, mm);
+
+               /*__asm
+               {
+                       pop ds
+               }*/
+               //printf("MML_UseSpace: Segment spans two blocks!\n");
        }
 
 //segu:
@@ -468,7 +491,7 @@ void MML_UseSpace(unsigned segstart, dword seglength, mminfo_t *mm)
 
 //     segm--;
 
-       if(0xfffflu > extra > 0)
+       if(extra > 0)
        {
                MM_GetNewBlock(mm);
                mm->mmnew->next = scan->next;
@@ -508,7 +531,7 @@ void MML_ClearBlock(mminfo_t *mm)
                scan = scan->next;
        }
 
-       printf("MM_ClearBlock: No purgable blocks!");
+       printf("MM_ClearBlock: No purgable blocks!\n");
 }
 
 
@@ -583,7 +606,7 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
        _fheapgrow();
        length=_memavl();
        //length-=farlen;
-       start = mm->farheap = halloc(length, sizeof(length));
+       start = mm->farheap = halloc(length, sizeof(dword));
        //start = mm->farheap = _fmalloc(length);
        length -= 16-(FP_OFF(start)&15);
        length -= SAVEFARHEAP;
@@ -597,6 +620,7 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
 //
 // detect EMS and allocate up to 64K at page frame
 //
+       printf("EMS!\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\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++)
        {
@@ -610,13 +634,11 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
                MML_SetupEMS(mm);                                       // allocate space
                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!
-               if(mm->EMSVer>=0x40) MML_UseSpace(mm->EMSpageframe,((dword)mm->EMSpagesmapped)*0x4000lu, mm);
-               else MML_UseSpace(mm->EMSpageframe,mm->EMSpagesmapped*0x4000lu, mm);
+               MML_UseSpace(mm->EMSpageframe,(/*++++mm->EMSpagesmapped++++*/4)*0x4000lu, mm);
 //printf("EMS3\n");
                MM_MapEMS(mm);                                  // map in used pages
 //printf("EMS4\n");
-               if(mm->EMSVer>=0x40) mmi->EMSmem = ((dword)mm->EMSpagesmapped)*0x4000lu;
-               else mmi->EMSmem = mm->EMSpagesmapped*0x4000lu;
+               mmi->EMSmem = (/*++++mm->EMSpagesmapped++++*/4)*0x4000lu;
        }
 
 //
@@ -632,8 +654,8 @@ emsskip:
 //     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("XMS!\n");
-               MML_SetupXMS(mm, mmi);                                  // allocate as many UMBs as possible
+               printf("XMS!\n");
+               //++++++++MML_SetupXMS(mm, mmi);                                        // allocate as many UMBs as possible
        }
 
 //
@@ -1016,7 +1038,7 @@ void MM_ShowMemory(mminfo_t *mm)
        mmblocktype huge *scan;
        unsigned color,temp;//, i;
        long    end,owner;
-       char    scratch[80],str[10];
+       char    scratch[160],str[16];
 
 //**** VW_SetDefaultColors();
 //**** VW_SetLineWidth(40);
@@ -1030,7 +1052,7 @@ void MM_ShowMemory(mminfo_t *mm)
 
 //CA_OpenDebug ();
 
-       while (scan)
+       while(scan)
        {
                if(scan->attributes & PURGEBITS)
                        color = 5;              // dark purple = purgable
@@ -1040,7 +1062,7 @@ void MM_ShowMemory(mminfo_t *mm)
                        color = 12;             // red = locked
                if(scan->start<=end)
                {
-                       printf("MM_ShowMemory: Memory block order currupted!");
+                       printf("\nMM_ShowMemory: Memory block order currupted!\n");
                        return;
                }
                end = scan->start+scan->length-1;
@@ -1050,9 +1072,11 @@ void MM_ShowMemory(mminfo_t *mm)
 //++++                 VW_Hlin(end+1,scan->next->start,0,0);   // black = free
 
 //****#if 0
-printf("Location:");
-printf("%x\t", scan->start);
-strcpy (scratch,"Size:");
+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,"Location:");
+ultoa (scan->start,str,16);
+strcat (scratch,str);
+strcat (scratch,"\tSize:");
 ltoa ((dword)scan->length*16,str,10);
 strcat (scratch,str);
 strcat (scratch,"\tOwner:0x");
@@ -1090,7 +1114,7 @@ fprintf(stdout, "%s", scratch);
 
 dword MM_UnusedMemory(mminfo_t *mm)
 {
-       unsigned free;
+       dword free;
        mmblocktype huge *scan;
 
        free = 0;
@@ -1121,7 +1145,7 @@ dword MM_UnusedMemory(mminfo_t *mm)
 
 dword MM_TotalFree(mminfo_t *mm)
 {
-       unsigned free;
+       dword free;
        mmblocktype huge *scan;
 
        free = 0;
@@ -1158,7 +1182,7 @@ void MM_Report(mminfo_t *mm, mminfotype *mmi)
                printf("freeEMSpages=%u\n", mm->freeEMSpages);
                printf("EMSpageframe=%x\n", mm->EMSpageframe);
        }
-       if(MML_CheckForXMS(mm)) printf("XMSaddr=%x\n", *XMSaddr);
+       if(MML_CheckForXMS(mm)) printf("XMSaddr=%Fp\n", *XMSaddr);
        printf("near=%lu\n", mmi->nearheap);
        printf("far=%lu\n", mmi->farheap);
        printf("EMSmem=%lu\n", mmi->EMSmem);
@@ -1228,3 +1252,33 @@ void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
        x->next=mm->mmfree;
        mm->mmfree=x;
 }
+
+void MM_seguin(void)
+{
+       __asm
+       {
+               push    ds
+               mov     ax,ds
+               inc             ax
+               mov     ds,ax
+       }
+}
+
+void MM_segude(void)
+{
+       __asm
+       {
+               pop ds
+       }
+}
+
+/*
+pull data from far and put it into ds var
+mov ax,es:si
+mov x,ax
+*/
+/*
+ss stack segment
+sp top of stack
+bp bottem of stack
+*/