X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_mm.c;h=dd754efdd6fe2369c36c01cd6bad27caff633c24;hb=8243a7d2a157ab520384f5019a63fd29c5c1383c;hp=acb71982b50508d4dbb000f446acfce52d0cc72b;hpb=6ca6ac83797249d4f46c245d12aa974427779573;p=16.git diff --git a/src/lib/16_mm.c b/src/lib/16_mm.c index acb71982..dd754efd 100644 --- a/src/lib/16_mm.c +++ b/src/lib/16_mm.c @@ -1,4 +1,4 @@ -/* Catacomb Armageddon Source Code +/* Catacomb Apocalypse Source Code * Copyright (C) 1993-2014 Flat Rock Software * * This program is free software; you can redistribute it and/or modify @@ -41,9 +41,35 @@ EMS / XMS unmanaged routines ============================================================================= */ +/* + +Open Watcom port by sparky4 +*/ #include "src/lib/16_mm.h" +/* +============================================================================= + + GLOBAL VARIABLES + +============================================================================= +*/ + +void (* beforesort) (void); +void (* aftersort) (void); +void (* XMSaddr) (void); // far pointer to XMS driver + +/* +============================================================================= + + LOCAL VARIABLES + +============================================================================= +*/ + +static char *ParmStringsexmm[] = {"noems","noxms",""}; + /* ====================== = @@ -54,13 +80,14 @@ EMS / XMS unmanaged routines ======================= */ -boolean MML_CheckForEMS (void) +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 @@ -108,14 +135,16 @@ boolean MML_CheckForEMS (void) ======================= */ -void MML_SetupEMS (void) +unsigned MML_SetupEMS(mminfo_t *mm) { char str[80],str2[10]; unsigned err; boolean errorflag=false; union REGS CPURegs; - EMSVer = 0; + unsigned int EMSVer = 0; + byte EMS_status; + unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle; totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0; __asm @@ -123,6 +152,7 @@ void MML_SetupEMS (void) 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 @@ -147,7 +177,15 @@ void MML_SetupEMS (void) mov [freeEMSpages],bx or bx,bx jz noEMS // no EMS at all to allocate - + //EXPAND DONG!!!! + cmp [EMSVer],0x40 + jb low + cmp bx,[freeEMSpages] + jle getpages + mov bx,[freeEMSpages] + jmp getpages + +low: cmp bx,4 jle getpages // there is only 1,2,3,or 4 pages mov bx,4 // we can't use more than 4 pages @@ -173,7 +211,15 @@ End: itoa(err,str2,16); strcpy(str,str2); printf("%s\n",str); + return err; } + mm->totalEMSpages=totalEMSpages; + mm->freeEMSpages=freeEMSpages; + mm->EMSpageframe=EMSpageframe; + mm->EMSpagesmapped=EMSpagesmapped; + mm->EMShandle=EMShandle; + mm->EMSVer=EMSVer; + return 0; } @@ -185,10 +231,12 @@ End: ======================= */ -void MML_ShutdownEMS (void) +void MML_ShutdownEMS(mminfo_t *mm) { boolean errorflag=false; - if (!EMShandle) + unsigned EMShandle=mm->EMShandle; + + if(!EMShandle) return; __asm { @@ -215,15 +263,16 @@ void MML_ShutdownEMS (void) ==================== */ -void MM_MapEMS (void) +unsigned MM_MapEMS(mminfo_t *mm) { char str[80],str2[10]; - unsigned err; + unsigned err, EMShandle; boolean errorflag=false; int i; union REGS CPURegs; + EMShandle=mm->EMShandle; - for (i=0;iEMSpagesmapped*/;i++) { __asm { @@ -245,10 +294,42 @@ void MM_MapEMS (void) 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; + 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) +{ + } //========================================================================== @@ -263,10 +344,10 @@ void MM_MapEMS (void) ======================= */ -boolean MML_CheckForXMS (void) +boolean MML_CheckForXMS(mminfo_t *mm) { boolean errorflag=false; - numUMBs = 0; + mm->numUMBs = 0; __asm { @@ -292,22 +373,21 @@ boolean MML_CheckForXMS (void) ======================= */ -void MML_SetupXMS (void) +void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi) { unsigned 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. call [DWORD PTR XMSaddr] or ax,ax jnz gotone @@ -325,11 +405,12 @@ gotone: mov [size],dx done: } - MML_UseSpace (base,size); - mminfo.XMSmem += size*16; - UMBbase[numUMBs] = base; - numUMBs++; - if (numUMBs < MAXUMBS) + printf("base=%u ", base); printf("size=%u\n", size); + MML_UseSpace(base,size, mm); + mmi->XMSmem += size*16; + mm->UMBbase[mm->numUMBs] = base; + mm->numUMBs++; + if(mm->numUMBs < MAXUMBS) goto getmemory; } @@ -342,14 +423,14 @@ done: ====================== */ -void MML_ShutdownXMS (void) +void MML_ShutdownXMS(mminfo_t *mm) { int i; unsigned base; - for (i=0;inumUMBs;i++) { - base = UMBbase[i]; + base = mm->UMBbase[i]; __asm { mov ah,XMS_FREEUMB @@ -373,54 +454,90 @@ void MML_ShutdownXMS (void) ====================== */ -void MML_UseSpace (unsigned segstart, unsigned seglength) +void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm) { - mmblocktype far *scan,far *last; - unsigned oldend; - long extra; + mmblocktype huge *scan,huge *last; + word segm; + dword oldend; + dword extra; - scan = last = mmhead; - mmrover = mmhead; // reset rover to start of memory + scan = last = mm->mmhead; + mm->mmrover = mm->mmhead; // reset rover to start of memory // // search for the block that contains the range of segments // - while (scan->start+scan->length < segstart) + while(scan->start+scan->length < segstart) { last = scan; scan = scan->next; } + //find out how many blocks it spans! + if(seglength>0xffffu) + { +// segm=seglength/0x4000u; + segm=seglength/0xffffu; + } + else segm=1; + + //++++emsver stuff! + if(segm>1/*extra>0xfffflu*/) + { + /*__asm + { + push ds + mov ax,ds + inc ax + mov ds,ax + }*/ + + +//MML_UseSpace(?segstart?, ?length?, mm); + + /*__asm + { + pop ds + }*/ + //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); - if (extra < 0) - { - printf("MML_UseSpace: Segment spans two blocks!"); - return; - } - - if (segstart == scan->start) +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); + if(segstart == scan->start) { last->next = scan->next; // unlink block - FREEBLOCK(scan); + MM_FreeBlock(scan, mm); scan = last; } else scan->length = segstart-scan->start; // shorten block - if (extra > 0) +// segm--; + + if(extra > 0) { - GETNEWBLOCK; - mmnew->next = scan->next; - scan->next = mmnew; - mmnew->start = segstart+seglength; - mmnew->length = extra; - mmnew->attributes = LOCKBIT; - } + MM_GetNewBlock(mm); + mm->mmnew->next = scan->next; + scan->next = mm->mmnew; + mm->mmnew->start = segstart+seglength; + mm->mmnew->length = extra; + mm->mmnew->attributes = LOCKBIT; + }//else if(segm>0) goto segu; } @@ -436,23 +553,23 @@ void MML_UseSpace (unsigned segstart, unsigned seglength) ==================== */ -void MML_ClearBlock (void) +void MML_ClearBlock(mminfo_t *mm) { - mmblocktype far *scan,far *last; + mmblocktype huge *scan,huge *last; - scan = mmhead->next; + scan = mm->mmhead->next; - while (scan) + while(scan) { - if (!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS) ) + if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS)) { - MM_FreePtr(scan->useptr); + MM_FreePtr(scan->useptr, mm); return; } scan = scan->next; } - printf("MM_ClearBlock: No purgable blocks!"); + printf("MM_ClearBlock: No purgable blocks!\n"); } @@ -469,115 +586,124 @@ void MML_ClearBlock (void) =================== */ -void MM_Startup (void) +void MM_Startup(mminfo_t *mm, mminfotype *mmi) { int i; dword length; - void far *start; - unsigned segstart,seglength,endfree; + void huge *start; + unsigned segstart,seglength,endfree; - if (mmstarted) - MM_Shutdown (); + if(mm->mmstarted) + MM_Shutdown(mm); - - mmstarted = true; - bombonerror = true; + mm->mmstarted = true; + mm->bombonerror = true; // // set up the linked list (everything in the free list; // - mmhead = NULL; - mmfree = &mmblocks[0]; - for (i=0;immhead = NULL; + mm->mmfree = &(mm->mmblocks[0]); + for(i=0;immblocks[i].next = &(mm->mmblocks[i+1]); + } + mm->mmblocks[i].next = NULL; // // locked block of all memory until we punch out free space // - GETNEWBLOCK; - mmhead = mmnew; // this will allways be the first node - mmnew->start = 0; - mmnew->length = 0xffff; - mmnew->attributes = LOCKBIT; - mmnew->next = NULL; - mmrover = mmhead; + MM_GetNewBlock(mm); + mm->mmhead = mm->mmnew; // this will allways be the first node + mm->mmnew->start = 0; + mm->mmnew->length = 0xffff; + mm->mmnew->attributes = LOCKBIT; + mm->mmnew->next = NULL; + mm->mmrover = mm->mmhead; +// farlen=_bios_memsize()*1024; // // get all available near conventional memory segments // //---- length=coreleft(); + _nheapgrow(); length=_memavl(); - start = (void far *)(nearheap = malloc(length)); - + 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); - mminfo.nearheap = length; + MML_UseSpace(segstart,seglength, mm); + mmi->nearheap = length; + //printf("near heap ok!\n"); // // get all available far conventional memory segments // //---- length=farcoreleft(); - length=_memmax(); - start = farheap = _fmalloc(length); + _fheapgrow(); + length=_memavl(); + start = mm->farheap = halloc(length, sizeof(byte)); + //start = mm->farheap = _fmalloc(length); length -= 16-(FP_OFF(start)&15); length -= SAVEFARHEAP; seglength = length / 16; // now in paragraphs segstart = FP_SEG(start)+(FP_OFF(start)+15)/16; - MML_UseSpace (segstart,seglength); - mminfo.farheap = length; - mminfo.mainmem = mminfo.nearheap + mminfo.farheap; + MML_UseSpace(segstart,seglength, mm); + mmi->farheap = length; + mmi->mainmem = mmi->nearheap + mmi->farheap; + //printf("far heap ok!\n"); // // detect EMS and allocate up to 64K at page frame // - mminfo.EMSmem = 0; - for (i = 1;i < __argc;i++) + 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++) { - if ( US_CheckParm(__argv[i],ParmStringsexmm) == 0) + if(US_CheckParm(__argv[i],ParmStringsexmm) == 0) goto emsskip; // param NOEMS } - - if (MML_CheckForEMS()) + 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"); - MML_SetupEMS(); // allocate space - //printf("EMS2\n"); - MML_UseSpace (EMSpageframe,EMSpagesmapped*0x400); - //printf("EMS3\n"); - MM_MapEMS(); // map in used pages - //printf("EMS4\n"); - mminfo.EMSmem = EMSpagesmapped*0x4000l; +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,(MAPPAGES)*0x4000lu, mm); +printf("EMS3\n"); + MM_MapEMS(mm); // map in used pages +printf("EMS4\n"); + mmi->EMSmem = (MAPPAGES)*0x4000lu; } // // detect XMS and get upper memory blocks // emsskip: - mminfo.XMSmem = 0; - for (i = 1;i < __argc;i++) + mmi->XMSmem = 0; + for(i = 1;i < __argc;i++) { - if ( US_CheckParm(__argv[i],ParmStringsexmm) == 0) + if(US_CheckParm(__argv[i],ParmStringsexmm) == 0) goto xmsskip; // param NOXMS } - - if (MML_CheckForXMS()) + 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(); // allocate as many UMBs as possible + printf("XMS!\n"); + //MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible } // // allocate the misc buffer // xmsskip: - mmrover = mmhead; // start looking for space after low block + mm->mmrover = mm->mmhead; // start looking for space after low block - MM_GetPtr (&bufferseg,BUFFERSIZE); + MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi); } //========================================================================== @@ -592,16 +718,19 @@ xmsskip: ==================== */ -void MM_Shutdown (void) +void MM_Shutdown(mminfo_t *mm) { - if (!mmstarted) - return; - - _ffree (farheap); - free (nearheap); - hfree(hugeheap); - MML_ShutdownEMS (); - MML_ShutdownXMS (); + if(!(mm->mmstarted)) + return; + + _ffree(mm->farheap); + printf("far freed\n"); + free(mm->nearheap); + printf("near freed\n"); + //hfree(mm->hugeheap); + //printf("huge freed\n"); + if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); printf("EMS freed\n"); } + if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); printf("XMS freed\n"); } } //========================================================================== @@ -616,54 +745,53 @@ void MM_Shutdown (void) ==================== */ -void MM_GetPtr (memptr *baseptr,dword size) +void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi) { - mmblocktype far *scan,far *lastscan,far *endscan - ,far *purge,far *next; + mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next; int search; unsigned needed,startseg; needed = (size+15)/16; // convert size from bytes to paragraphs - GETNEWBLOCK; // fill in start and next after a spot is found - mmnew->length = needed; - mmnew->useptr = baseptr; - mmnew->attributes = BASEATTRIBUTES; + MM_GetNewBlock(mm); // fill in start and next after a spot is found + mm->mmnew->length = needed; + mm->mmnew->useptr = baseptr; + mm->mmnew->attributes = BASEATTRIBUTES; - for (search = 0; search<3; search++) + for(search = 0; search<3; search++) { // // 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 && mmrover == mmhead) + if(search == 1 && mm->mmrover == mm->mmhead) search++; - switch (search) + switch(search) { case 0: - lastscan = mmrover; - scan = mmrover->next; + lastscan = mm->mmrover; + scan = mm->mmrover->next; endscan = NULL; break; case 1: - lastscan = mmhead; - scan = mmhead->next; - endscan = mmrover; + lastscan = mm->mmhead; + scan = mm->mmhead->next; + endscan = mm->mmrover; break; case 2: - MM_SortMem (); - lastscan = mmhead; - scan = mmhead->next; + MM_SortMem(mm); + lastscan = mm->mmhead; + scan = mm->mmhead->next; endscan = NULL; break; } startseg = lastscan->start + lastscan->length; - while (scan != endscan) + while(scan != endscan) { - if (scan->start - startseg >= needed) + if(scan->start - startseg >= needed) { // // got enough space between the end of lastscan and @@ -671,23 +799,23 @@ void MM_GetPtr (memptr *baseptr,dword size) // and allocate the new block // purge = lastscan->next; - lastscan->next = mmnew; - mmnew->start = *(unsigned *)baseptr = startseg; - mmnew->next = scan; - while ( purge != scan) + lastscan->next = mm->mmnew; + mm->mmnew->start = *(unsigned *)baseptr = startseg; + mm->mmnew->next = scan; + while(purge != scan) { // free the purgable block next = purge->next; - FREEBLOCK(purge); + MM_FreeBlock(purge, mm); purge = next; // purge another if not at scan } - mmrover = mmnew; + mm->mmrover = mm->mmnew; return; // good allocation! } // // if this block is purge level zero or locked, skip past it // - if ( (scan->attributes & LOCKBIT) + if((scan->attributes & LOCKBIT) || !(scan->attributes & PURGEBITS) ) { lastscan = scan; @@ -699,10 +827,10 @@ void MM_GetPtr (memptr *baseptr,dword size) } } - if (bombonerror) - printf(OUT_OF_MEM_MSG,(size-mminfo.nearheap)); + if (mm->bombonerror) + printf(OUT_OF_MEM_MSG,(size-mmi->nearheap)); else - mmerror = true; + mm->mmerror = true; } //========================================================================== @@ -717,23 +845,23 @@ void MM_GetPtr (memptr *baseptr,dword size) ==================== */ -void MM_FreePtr (memptr *baseptr) +void MM_FreePtr(memptr *baseptr, mminfo_t *mm) { - mmblocktype far *scan,far *last; + mmblocktype huge *scan,huge *last; - last = mmhead; + last = mm->mmhead; scan = last->next; - if (baseptr == mmrover->useptr) // removed the last allocated block - mmrover = mmhead; + if(baseptr == mm->mmrover->useptr) // removed the last allocated block + mm->mmrover = mm->mmhead; - while (scan->useptr != baseptr && scan) + while(scan->useptr != baseptr && scan) { last = scan; scan = scan->next; } - if (!scan) + if(!scan) { printf("MM_FreePtr: Block not found!"); return; @@ -741,7 +869,7 @@ void MM_FreePtr (memptr *baseptr) last->next = scan->next; - FREEBLOCK(scan); + MM_FreeBlock(scan, mm); } //========================================================================== @@ -755,31 +883,31 @@ void MM_FreePtr (memptr *baseptr) ===================== */ -void MM_SetPurge (memptr *baseptr, int purge) +void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm) { - mmblocktype far *start; + mmblocktype huge *start; - start = mmrover; + start = mm->mmrover; do { - if (mmrover->useptr == baseptr) + if(mm->mmrover->useptr == baseptr) break; - mmrover = mmrover->next; + mm->mmrover = mm->mmrover->next; - if (!mmrover) - mmrover = mmhead; - else if (mmrover == start) + if(!mm->mmrover) + mm->mmrover = mm->mmhead; + else if(mm->mmrover == start) { printf("MM_SetPurge: Block not found!"); return; } - } while (1); + } while(1); - mmrover->attributes &= ~PURGEBITS; - mmrover->attributes |= purge; + mm->mmrover->attributes &= ~PURGEBITS; + mm->mmrover->attributes |= purge; } //========================================================================== @@ -794,31 +922,31 @@ void MM_SetPurge (memptr *baseptr, int purge) ===================== */ -void MM_SetLock (memptr *baseptr, boolean locked) +void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm) { - mmblocktype far *start; + mmblocktype huge *start; - start = mmrover; + start = mm->mmrover; do { - if (mmrover->useptr == baseptr) + if(mm->mmrover->useptr == baseptr) break; - mmrover = mmrover->next; + mm->mmrover = mm->mmrover->next; - if (!mmrover) - mmrover = mmhead; - else if (mmrover == start) + if(!mm->mmrover) + mm->mmrover = mm->mmhead; + else if(mm->mmrover == start) { printf("MM_SetLock: Block not found!"); return; } - } while (1); + } while(1); - mmrover->attributes &= ~LOCKBIT; - mmrover->attributes |= locked*LOCKBIT; + mm->mmrover->attributes &= ~LOCKBIT; + mm->mmrover->attributes |= locked*LOCKBIT; } //========================================================================== @@ -833,9 +961,9 @@ void MM_SetLock (memptr *baseptr, boolean locked) ===================== */ -void MM_SortMem (void) +void MM_SortMem(mminfo_t *mm) { - mmblocktype far *scan,far *last,far *next; + mmblocktype huge *scan,huge *last,huge *next; unsigned start,length,source,dest,oldborder; int playing; @@ -843,7 +971,7 @@ void MM_SortMem (void) // lock down a currently playing sound // /*++++ playing = SD_SoundPlaying (); - if (playing) + if(playing) { switch (SoundMode) { @@ -862,16 +990,16 @@ void MM_SortMem (void) // oldborder = bordercolor; // VW_ColorBorder (15); - if (beforesort) + if(beforesort) beforesort(); - scan = mmhead; + scan = mm->mmhead; last = NULL; // shut up compiler warning - while (scan) + while(scan) { - if (scan->attributes & LOCKBIT) + if(scan->attributes & LOCKBIT) { // // block is locked, so try to pile later blocks right after it @@ -880,13 +1008,13 @@ void MM_SortMem (void) } else { - if (scan->attributes & PURGEBITS) + if(scan->attributes & PURGEBITS) { // // throw out the purgable block // next = scan->next; - FREEBLOCK(scan); + MM_FreeBlock(scan, mm); last->next = next; scan = next; continue; @@ -896,12 +1024,12 @@ void MM_SortMem (void) // // push the non purgable block on top of the last moved block // - if (scan->start != start) + if(scan->start != start) { length = scan->length; source = scan->start; dest = start; - while (length > 0xf00) + while(length > 0xf00) { movedata(source,0,dest,0,0xf00*16); length -= 0xf00; @@ -921,14 +1049,14 @@ void MM_SortMem (void) scan = scan->next; // go to next block } - mmrover = mmhead; + mm->mmrover = mm->mmhead; - if (aftersort) + if(aftersort) aftersort(); // VW_ColorBorder (oldborder); -/*++++ if (playing) +/*++++ if(playing) MM_SetLock(&(memptr)audiosegs[playing],false);*/ } @@ -944,12 +1072,13 @@ void MM_SortMem (void) ===================== */ -void MM_ShowMemory (void) +void MM_ShowMemory(page_t *page, mminfo_t *mm) { - mmblocktype far *scan; - unsigned color,temp;//, i; + mmblocktype huge *scan; + unsigned color,temp; long end,owner; - char scratch[80],str[10]; + word chx,chy; + char scratch[160],str[16]; //**** VW_SetDefaultColors(); //**** VW_SetLineWidth(40); @@ -957,50 +1086,63 @@ void MM_ShowMemory (void) //++++mh bufferofs = 0; //**** VW_SetScreen (0,0); - scan = mmhead; + scan = mm->mmhead; end = -1; -//CA_OpenDebug (); +CA_OpenDebug (); - while (scan) + chx=0; + chy=0; + + while(scan) { - if (scan->attributes & PURGEBITS) + if(scan->attributes & PURGEBITS) color = 5; // dark purple = purgable else color = 9; // medium blue = non purgable - if (scan->attributes & LOCKBIT) + if(scan->attributes & LOCKBIT) color = 12; // red = locked - if (scan->start<=end) + 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; + modexhlin(page, scan->start, (unsigned)end, chy, color); //++++ VW_Hlin(scan->start,(unsigned)end,0,color); + //++++ VW_Plot(scan->start,0,15); - if (scan->next->start > end+1) + modexClearRegion(page, scan->start, chy, 4, 4, 15); + if(scan->next->start > end+1) //++++ VW_Hlin(end+1,scan->next->start,0,0); // black = free + modexhlin(page, end+1,scan->next->start, chy, 9); //****#if 0 -printf("Location:"); -printf("%Fp\t", scan->start); -strcpy (scratch,"Size:"); -ltoa ((long)scan->length*16,str,10); +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"); 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); @@ -1008,6 +1150,72 @@ fprintf(stdout, "%s", scratch); } //****#endif +//========================================================================== + +/* +===================== += += MM_DumpData += +===================== +*/ + +void MM_DumpData(mminfo_t *mm) +{ + mmblocktype far *scan,far *best; + long lowest,oldlowest; + unsigned owner; + char lock,purge; + FILE *dumpfile; + + + free (mm->nearheap); + dumpfile = fopen ("mmdump.txt","w"); + if (!dumpfile){ + printf("MM_DumpData: Couldn't open MMDUMP.TXT!"); + return; + } + + lowest = -1; + do + { + oldlowest = lowest; + lowest = 0xffff; + + scan = mm->mmhead; + while (scan) + { + owner = (unsigned)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" + ,(unsigned)lowest,lock,purge,best->length); + } + + } while (lowest != 0xffff); + + fclose (dumpfile); + printf("MMDUMP.TXT created."); +} + //========================================================================== @@ -1021,21 +1229,22 @@ fprintf(stdout, "%s", scratch); ====================== */ -dword MM_UnusedMemory (void) +dword MM_UnusedMemory(mminfo_t *mm) { - unsigned free; - mmblocktype far *scan; + dword free; + mmblocktype huge *scan; free = 0; - scan = mmhead; + scan = mm->mmhead; - while (scan->next) + while(scan->next) { free += scan->next->start - (scan->start + scan->length); scan = scan->next; } return free*16l; +// return free; } //========================================================================== @@ -1051,23 +1260,24 @@ dword MM_UnusedMemory (void) ====================== */ -dword MM_TotalFree (void) +dword MM_TotalFree(mminfo_t *mm) { - unsigned free; - mmblocktype far *scan; + dword free; + mmblocktype huge *scan; free = 0; - scan = mmhead; + scan = mm->mmhead; - while (scan->next) + while(scan->next) { - if ((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT)) + if((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT)) free += scan->length; free += scan->next->start - (scan->start + scan->length); scan = scan->next; } return free*16l; +// return free; } //========================================================================== @@ -1080,14 +1290,26 @@ dword MM_TotalFree (void) ===================== */ -void MM_Report(void) +void MM_Report(page_t *page, mminfo_t *mm, mminfotype *mmi) { - printf("EMM %x available\n", EMSVer); - printf("totalEMSpages=%u\n", totalEMSpages); - printf("freeEMSpages=%u\n", freeEMSpages); - printf("EMSpageframe=%Fp\n", EMSpageframe); - printf("UnusedMemory=%lu\n", MM_UnusedMemory()); - printf("TotalFree=%lu\n", MM_TotalFree()); + if(MML_CheckForEMS()) + { + 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); + } + 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); + printf("XMSmem=%lu\n", mmi->XMSmem); + printf("mainmem=%lu\n", mmi->mainmem); + printf("UnusedMemory=%lu\n", MM_UnusedMemory(mm)); + printf("TotalFree=%lu\n", MM_TotalFree(mm)); +// printf("\n"); +// printf("UnusedMemory=%lu kb\n", MM_UnusedMemory()/10248); +// printf("TotalFree=%lu kb\n", MM_TotalFree()/10248); } //========================================================================== @@ -1100,16 +1322,16 @@ void MM_Report(void) ===================== -int MM_EMSVer(void) +int MM_EMSVer(void) { - int EMSver; + int EMSver; __asm { - mov ah,EMS_VERSION + mov ah,EMS_VERSION int EMS_INT - mov EMSver,ax + mov EMSver,ax } - return(EMSver); + return(EMSver); }*/ //========================================================================== @@ -1122,45 +1344,58 @@ int MM_EMSVer(void) ===================== */ -void MM_BombOnError (boolean bomb) +void MM_BombOnError(boolean bomb, mminfo_t *mm) { - bombonerror = bomb; + mm->bombonerror = bomb; } -//========================================================================== +void MM_GetNewBlock(mminfo_t *mm) +{ + if(!mm->mmfree) + MML_ClearBlock(mm); + mm->mmnew=mm->mmfree; + mm->mmfree=mm->mmfree->next; + /*if(!(mm->mmnew=mm->mmfree)) + { + printf("MM_GETNEWBLOCK: No free blocks!"); + return; + } + mm->mmfree=mm->mmfree->next;*/ +} -/////////////////////////////////////////////////////////////////////////// -// -// US_CheckParm() - checks to see if a string matches one of a set of -// strings. The check is case insensitive. The routine returns the -// index of the string that matched, or -1 if no matches were found -// -/////////////////////////////////////////////////////////////////////////// -int -US_CheckParm(char *parm,char **strings) +void MM_FreeBlock(mmblocktype *x, mminfo_t *mm) { - char cp,cs, - *p,*s; - int i; + x->useptr=NULL; + x->next=mm->mmfree; + mm->mmfree=x; +} - while (!isalpha(*parm)) // Skip non-alphas - parm++; +void MM_seguin(void) +{ + __asm + { + push ds + mov ax,ds + inc ax + mov ds,ax + } +} - for (i = 0;*strings && **strings;i++) +void MM_segude(void) +{ + __asm { - for (s = *strings++,p = parm,cs = cp = 0;cs == cp;) - { - cs = *s++; - if (!cs) - return(i); - cp = *p++; - - if (isupper(cs)) - cs = tolower(cs); - if (isupper(cp)) - cp = tolower(cp); - } + pop ds } - return(-1); } +/* +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 +*/