X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_mm.c;h=f0c40f9ec4f53b210bba7444cc90f3a280c7fff5;hb=974303f5ca3975d925d08452c175e09b77e8d4b4;hp=8a64d1055e8c8a019e11a8ef6f5c523cdd88fb7d;hpb=62cbd212900e125c2f8470a5ef85fe80938e1efa;p=16.git diff --git a/src/lib/16_mm.c b/src/lib/16_mm.c index 8a64d105..f0c40f9e 100644 --- a/src/lib/16_mm.c +++ b/src/lib/16_mm.c @@ -83,10 +83,11 @@ static char *ParmStringsexmm[] = {"noems","noxms",""}; boolean MML_CheckForEMS(void) { boolean emmcfems; - char emmname[] = "EMMXXXX0"; + static char emmname[] = "EMMXXXX0"; //fix by andrius4669 // mov dx,OFFSET emmname __asm { - LEA DX, emmname //fix by andrius4669 + //LEA DX, emmname //fix by andrius4669 + mov dx,OFFSET emmname //fix by andrius4669 mov ax,0x3d00 int 0x21 // try to open EMMXXXX0 device jc error @@ -142,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; @@ -150,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 @@ -174,7 +177,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] @@ -269,7 +272,7 @@ unsigned MM_MapEMS(mminfo_t *mm) union REGS CPURegs; EMShandle=mm->EMShandle; - for (i=0;iEMSpagesmapped;i++) + for (i=0;iEMSpagesmapped*/;i++) { __asm { @@ -291,13 +294,44 @@ unsigned MM_MapEMS(mminfo_t *mm) strcpy(str,"MM_MapEMS: EMS error 0x"); itoa(err,str2,16); strcpy(str,str2); - printf("%s\n",str); + //printf("%s\n",str); + printf("FACK! %u\n", err); return err; } } return 0; } +/* +SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle) + + 'Maps up to 4 logical EMS pages to physical pages in the page frame, where: + ' + 'PhysicalStart = Physical page first logical page is mapped to + 'LogicalStart = First logical page to map + 'NumPages = Number of pages to map (1 to 4) + 'Handle = EMS handle logical pages are allocated to + + 'Create a buffer containing the page information + FOR x = 0 TO NumPages - 1 + MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x) + NEXT + + Regs.ax = &H5000 'Map the pages in the buffer + Regs.cx = NumPages 'to the pageframe + Regs.dx = Handle + Regs.ds = VARSEG(MapInfo$) + Regs.si = SADD(MapInfo$) + InterruptX &H67, Regs, Regs + EMS.Error = (Regs.ax AND &HFF00&) \ &H100 'Store the status code + +END SUB +*/ +void MM_MapXEMS(mminfo_t *mm) +{ + +} + //========================================================================== /* @@ -423,9 +457,8 @@ void MML_ShutdownXMS(mminfo_t *mm) void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm) { mmblocktype huge *scan,huge *last; + word segm; dword oldend; - ///*d*/word fat=0; - //word segm=0; dword extra; scan = last = mm->mmhead; @@ -440,13 +473,16 @@ void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm) scan = scan->next; } -// -// take the given range out of the block -// - oldend = scan->start + scan->length; - extra = oldend - (segstart+seglength); + //find out how many blocks it spans! + if(seglength>0xffffu) + { +// segm=seglength/0x4000u; + segm=seglength/0xffffu; + } + else segm=1; + //++++emsver stuff! - if(extra>0xfffflu) + if(segm>1/*extra>0xfffflu*/) { /*__asm { @@ -455,10 +491,7 @@ void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm) inc ax mov ds,ax }*/ -printf("extra=%lu ", extra); -printf("oldend=%lu ", oldend); -printf("length=%lu ", scan->length); -printf("seglength=%lu\n", seglength); + //MML_UseSpace(?segstart?, ?length?, mm); @@ -469,6 +502,19 @@ printf("seglength=%lu\n", seglength); //printf("MML_UseSpace: Segment spans two blocks!\n"); } +// +// take the given range out of the block +// + oldend = scan->start + scan->length; + extra = oldend - (segstart+seglength); + +printf("segm=%u ", segm); +printf("ex=%lu ", extra); +printf("start+seglen=%lu ", segstart+seglength); +printf("len=%u ", scan->length); +printf("segsta=%x ", segstart); +printf("seglen=%lu\n", seglength); + //segu: //++++todo: linked list of segment! //printf("segm=%lu\n", segm); @@ -543,7 +589,7 @@ void MML_ClearBlock(mminfo_t *mm) void MM_Startup(mminfo_t *mm, mminfotype *mmi) { int i; - dword length;//,farlen; + dword length; void huge *start; unsigned segstart,seglength,endfree; @@ -569,7 +615,7 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi) MM_GetNewBlock(mm); mm->mmhead = mm->mmnew; // this will allways be the first node mm->mmnew->start = 0; - mm->mmnew->length = 0xffff; //todo: mm make it fucking massive as fuck!~ + mm->mmnew->length = 0xffff; mm->mmnew->attributes = LOCKBIT; mm->mmnew->next = NULL; mm->mmrover = mm->mmhead; @@ -583,13 +629,13 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi) _nheapgrow(); length=_memavl(); start = (void huge *)(mm->nearheap = malloc(length)); - length -= 16-(FP_OFF(start)&15); length -= SAVENEARHEAP; seglength = length / 16; // now in paragraphs segstart = FP_SEG(start)+(FP_OFF(start)+15)/16; MML_UseSpace(segstart,seglength, mm); mmi->nearheap = length; + //printf("near heap ok!\n"); // // get all available far conventional memory segments @@ -597,8 +643,7 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi) //---- length=farcoreleft(); _fheapgrow(); length=_memavl(); - //length-=farlen; - start = mm->farheap = halloc(length, sizeof(dword)); + start = mm->farheap = halloc(length, sizeof(byte)); //start = mm->farheap = _fmalloc(length); length -= 16-(FP_OFF(start)&15); length -= SAVEFARHEAP; @@ -607,6 +652,7 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi) MML_UseSpace(segstart,seglength, mm); mmi->farheap = length; mmi->mainmem = mmi->nearheap + mmi->farheap; + //printf("far heap ok!\n"); // @@ -622,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; } // @@ -643,11 +690,11 @@ emsskip: if(US_CheckParm(__argv[i],ParmStringsexmm) == 0) goto xmsskip; // param NOXMS } -// 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! + 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 + //MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible } // @@ -816,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; } @@ -1025,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;//, i; + word color,temp; long end,owner; - char scratch[80],str[10]; + word chx,chy; + byte scratch[160],str[16]; //**** VW_SetDefaultColors(); //**** VW_SetLineWidth(40); @@ -1042,9 +1090,12 @@ void MM_ShowMemory(mminfo_t *mm) end = -1; -//CA_OpenDebug (); +CA_OpenDebug (); + + chx=0; + chy=0; - while (scan) + while(scan) { if(scan->attributes & PURGEBITS) color = 5; // dark purple = purgable @@ -1054,19 +1105,49 @@ void MM_ShowMemory(mminfo_t *mm) color = 12; // red = locked if(scan->start<=end) { - printf("MM_ShowMemory: Memory block order currupted!"); + //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("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,"Seg:"); +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"); @@ -1074,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); @@ -1091,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 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"); +} + +//========================================================================== + /* ====================== @@ -1163,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);