]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_mm.c
ok
[16.git] / src / lib / 16_mm.c
index 7b8dfec921cb94ad430771410c71477c641a4fa5..f0c40f9ec4f53b210bba7444cc90f3a280c7fff5 100644 (file)
@@ -143,6 +143,7 @@ unsigned MML_SetupEMS(mminfo_t *mm)
        union REGS CPURegs;
 
        unsigned int EMSVer = 0;
+       //byte  EMS_status;
        unsigned        totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
        totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
 
@@ -151,6 +152,7 @@ unsigned MML_SetupEMS(mminfo_t *mm)
                mov     ah,EMS_STATUS
                int     EMS_INT                                         // make sure EMS hardware is present
                or      ah,ah
+               //mov   [EMS_status],ah
                jnz     error
 
                mov     ah,EMS_VERSION
@@ -270,7 +272,7 @@ unsigned MM_MapEMS(mminfo_t *mm)
        union REGS CPURegs;
        EMShandle=mm->EMShandle;
 
-       for (i=0;i<4/*mm->EMSpagesmapped*/;i++)
+       for (i=0;i<MAPPAGES/*4mm->EMSpagesmapped*/;i++)
        {
                __asm
                {
@@ -300,6 +302,36 @@ unsigned MM_MapEMS(mminfo_t *mm)
        return 0;
 }
 
+/*
+SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)\r
+\r
+  'Maps up to 4 logical EMS pages to physical pages in the page frame, where:\r
+  '\r
+  'PhysicalStart = Physical page first logical page is mapped to\r
+  'LogicalStart  = First logical page to map\r
+  'NumPages      = Number of pages to map (1 to 4)\r
+  'Handle        = EMS handle logical pages are allocated to\r
+\r
+  'Create a buffer containing the page information\r
+  FOR x = 0 TO NumPages - 1\r
+    MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x)\r
+  NEXT\r
+\r
+  Regs.ax = &H5000                           'Map the pages in the buffer\r
+  Regs.cx = NumPages                         'to the pageframe\r
+  Regs.dx = Handle\r
+  Regs.ds = VARSEG(MapInfo$)\r
+  Regs.si = SADD(MapInfo$)\r
+  InterruptX &H67, Regs, Regs\r
+  EMS.Error = (Regs.ax AND &HFF00&) \ &H100  'Store the status code\r
+\r
+END SUB
+*/
+void MM_MapXEMS(mminfo_t *mm)
+{
+
+}
+
 //==========================================================================
 
 /*
@@ -636,15 +668,16 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
        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("EMS1\n");
+printf("EMS1\n");
                MML_SetupEMS(mm);                                       // allocate space
+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!
                //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
-               MML_UseSpace(mm->EMSpageframe,(mm->EMSpagesmapped)*0x4000lu, mm);
-//printf("EMS3\n");
+               MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
+printf("EMS3\n");
                MM_MapEMS(mm);                                  // map in used pages
-//printf("EMS4\n");
-               mmi->EMSmem = (mm->EMSpagesmapped)*0x4000lu;
+printf("EMS4\n");
+               mmi->EMSmem = (MAPPAGES)*0x4000lu;
        }
 
 //
@@ -830,7 +863,7 @@ void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
 
        if(!scan)
        {
-               printf("MM_FreePtr: Block not found!");
+               printf("MM_FreePtr: Block not found!\n");
                return;
        }
 
@@ -1039,12 +1072,13 @@ void MM_SortMem(mminfo_t *mm)
 =====================
 */
 
-void MM_ShowMemory(mminfo_t *mm)
+void MM_ShowMemory(page_t *page, mminfo_t *mm)
 {
        mmblocktype huge *scan;
-       unsigned color,temp;
+       word color,temp;
        long    end,owner;
-       char    scratch[160],str[16];
+       word chx,chy;
+       byte    scratch[160],str[16];
 
 //**** VW_SetDefaultColors();
 //**** VW_SetLineWidth(40);
@@ -1056,7 +1090,10 @@ void MM_ShowMemory(mminfo_t *mm)
 
        end = -1;
 
-//CA_OpenDebug ();
+CA_OpenDebug ();
+
+       chx=0;
+       chy=0;
 
        while(scan)
        {
@@ -1068,18 +1105,46 @@ void MM_ShowMemory(mminfo_t *mm)
                        color = 12;             // red = locked
                if(scan->start<=end)
                {
-                       printf("\nMM_ShowMemory: Memory block order currupted!\n");
+                       //printf(");
+                       write(debughandle,"\nMM_ShowMemory: Memory block order currupted!\n",strlen("\nMM_ShowMemory: Memory block order currupted!\n"));
+                       //modexprint(&page, chx, chy, 1, 0, 24, "\nMM_ShowMemory: Memory block order currupted!\n");
                        return;
                }
                end = scan->start+scan->length-1;
+               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)
+                               //{
+                                       modexClearRegion(page, chx, chy, 4, 4, color);
+                               //}
+
 //++++         VW_Hlin(scan->start,(unsigned)end,0,color);
+
 //++++         VW_Plot(scan->start,0,15);
+                               modexClearRegion(page, chx, chy, 4, 4, 15);
                if(scan->next->start > end+1)
 //++++                 VW_Hlin(end+1,scan->next->start,0,0);   // black = free
+                       //for(chx=scan->next->start;chx+4>=(word)end+1;chx+=4)
+                       //{
+                               chx+=scan->next->start;
+                               modexClearRegion(page, chx, chy, 4, 4, 2);
+                       //}
+                                       //modexhlin(page, end+1,scan->next->start, chy, 0);
+
+/*
+               end = scan->length-1;
+               y = scan->start/320;
+               x = scan->start%320;
+               VW_Hlin(x,x+end,y,color);
+               VW_Plot(x,y,15);
+               if (scan->next && scan->next->start > end+1)
+                       VW_Hlin(x+end+1,x+(scan->next->start-scan->start),y,0); // black = free
+*/
 
 //****#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!
-strcpy(scratch,"Location:");
+strcpy(scratch,"Seg:");
 ultoa (scan->start,str,16);
 strcat (scratch,str);
 strcat (scratch,"\tSize:");
@@ -1090,14 +1155,16 @@ owner = (unsigned)scan->useptr;
 ultoa (owner,str,16);
 strcat (scratch,str);
 strcat (scratch,"\n");
-//++++write (debughandle,scratch,strlen(scratch));
-fprintf(stdout, "%s", scratch);
+write(debughandle,scratch,strlen(scratch));
+//modexprint(page, chx, chy, 1, 0, 24, &scratch);
+chy+=4;
+//fprintf(stdout, "%s", scratch);
 //****#endif
 
                scan = scan->next;
        }
 
-//CA_CloseDebug ();
+CA_CloseDebug ();
 
 //++++mh       IN_Ack();
 //**** VW_SetLineWidth(64);
@@ -1107,6 +1174,72 @@ fprintf(stdout, "%s", scratch);
 
 //==========================================================================
 
+/*
+=====================
+=
+= MM_DumpData
+=
+=====================
+*/
+
+void MM_DumpData(mminfo_t *mm)
+{
+       mmblocktype far *scan,far *best;
+       long    lowest,oldlowest;
+       word    owner;
+       byte    lock,purge;
+       FILE    *dumpfile;
+
+
+       free (mm->nearheap);
+       dumpfile = fopen ("mmdump.txt","w");
+       if (!dumpfile){
+               printf("MM_DumpData: Couldn't open MMDUMP.TXT!\n");
+               return;
+       }
+
+       lowest = -1;
+       do
+       {
+               oldlowest = lowest;
+               lowest = 0xffff;
+
+               scan = mm->mmhead;
+               while (scan)
+               {
+                       owner = (word)scan->useptr;
+
+                       if (owner && owner<lowest && owner > oldlowest)
+                       {
+                               best = scan;
+                               lowest = owner;
+                       }
+
+                       scan = scan->next;
+               }
+
+               if (lowest != 0xffff)
+               {
+                       if (best->attributes & PURGEBITS)
+                               purge = 'P';
+                       else
+                               purge = '-';
+                       if (best->attributes & LOCKBIT)
+                               lock = 'L';
+                       else
+                               lock = '-';
+                       fprintf (dumpfile,"0x%p (%c%c) = %u\n"
+                       ,(word)lowest,lock,purge,best->length);
+               }
+
+       } while (lowest != 0xffff);
+
+       fclose (dumpfile);
+       printf("MMDUMP.TXT created.\n");
+}
+
+//==========================================================================
+
 
 /*
 ======================
@@ -1179,11 +1312,11 @@ dword MM_TotalFree(mminfo_t *mm)
 =====================
 */
 
-void MM_Report(mminfo_t *mm, mminfotype *mmi)
+void MM_Report(page_t *page, mminfo_t *mm, mminfotype *mmi)
 {
        if(MML_CheckForEMS())
        {
-               printf("EMM %x available\n", mm->EMSVer);
+               printf("EMM v%x.%x available\n", mm->EMSVer>>4,mm->EMSVer&0x0F);
                printf("totalEMSpages=%u\n", mm->totalEMSpages);
                printf("freeEMSpages=%u\n", mm->freeEMSpages);
                printf("EMSpageframe=%x\n", mm->EMSpageframe);