1 /* Catacomb Apocalypse Source Code
2 * Copyright (C) 1993-2014 Flat Rock Software
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 =============================================================================
24 ID software memory manager
25 --------------------------
27 Primary coder: John Carmack
31 Quit (char *error) function
36 MM_SizePtr to change the size of a given pointer
38 Multiple purge levels utilized
40 EMS / XMS unmanaged routines
42 =============================================================================
46 Open Watcom port by sparky4
49 #include "src/lib/16_mm.h"
56 =============================================================================
60 =============================================================================
63 void (* beforesort) (void);
64 void (* aftersort) (void);
65 void (* XMSaddr) (void); // far pointer to XMS driver
68 =============================================================================
72 =============================================================================
75 static char *ParmStringsexmm[] = {"noems","noxms",""};
78 ======================
82 = Routine from p36 of Extending DOS
84 =======================
87 boolean MML_CheckForEMS(void)
90 static char emmname[] = "EMMXXXX0"; //fix by andrius4669
91 // mov dx,OFFSET emmname
93 //LEA DX, emmname //fix by andrius4669
94 mov dx,OFFSET emmname //fix by andrius4669
96 int 0x21 // try to open EMMXXXX0 device
102 int 0x21 // get device info
110 int 0x21 // get status
116 int 0x21 // close handle
135 ======================
139 =======================
142 byte MML_SetupEMS(mminfo_t *mm)
146 boolean errorflag=false;
148 unsigned int EMSVer = 0;
150 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
151 totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
156 int EMS_INT // make sure EMS hardware is present
158 //mov [EMS_status],ah
165 mov [EMSVer],ax // set EMSVer
166 cmp al,0x32 // only work on ems 3.2 or greater
170 int EMS_INT // find the page frame address
173 mov [EMSpageframe],bx
176 int EMS_INT // find out how much EMS is there
179 mov [totalEMSpages],dx
180 mov [freeEMSpages],bx
182 jz noEMS // no EMS at all to allocate
186 cmp bx,[freeEMSpages]
188 mov bx,[freeEMSpages]
193 jle getpages // there is only 1,2,3,or 4 pages
194 mov bx,4 // we can't use more than 4 pages
197 mov [EMSpagesmapped],bx
198 mov ah,EMS_ALLOCPAGES // allocate up to 64k of EMS
213 //err = CPURegs.h.ah;
214 strcpy(str,"MM_SetupEMS: EMS error ");
216 MM_EMSerr(&str, err);
220 mm->totalEMSpages=totalEMSpages;
221 mm->freeEMSpages=freeEMSpages;
222 mm->EMSpageframe=EMSpageframe;
223 mm->EMSpagesmapped=EMSpagesmapped;
224 mm->EMShandle=EMShandle;
231 ======================
235 =======================
238 void MML_ShutdownEMS(mminfo_t *mm)
240 boolean errorflag=false;
241 unsigned EMShandle=mm->EMShandle;
255 if(errorflag==true) printf("MML_ShutdownEMS: Error freeing EMS!\n"); //++++ add something
263 = Maps the 64k of EMS used by memory manager into the page frame
264 = for general use. This only needs to be called if you are keeping
265 = other things in EMS.
270 byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi)
275 boolean errorflag=false;
277 EMShandle=mm->EMShandle;
279 for (i=0;i<4/*MAPPAGES*/;i++)
284 mov bx,[i] // logical page
285 mov al,bl // physical page
286 mov dx,[EMShandle] // handle
298 //err = CPURegs.h.ah;
299 strcpy(str,"MM_MapEMS: EMS error ");
303 //printf("FACK! %x\n", err);
307 mmi->EMSmem = (i)*0x4000lu;
311 byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
313 //SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)
315 //Maps up to 4 logical EMS pages to physical pages in the page frame, where:
316 //PhysicalStart = Physical page first logical page is mapped to
317 //LogicalStart = First logical page to map
318 //NumPages = Number of pages to map (1 to 4)
319 //Handle = EMS handle logical pages are allocated to
321 /*//Create a buffer containing the page information
322 // FOR x = 0 TO NumPages - 1
323 // MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x)
326 // Regs.ax = 0x5000 //Map the pages in the buffer
327 // Regs.cx = NumPages //to the pageframe
329 // Regs.ds = VARSEG(MapInfo$)
330 // Regs.si = SADD(MapInfo$)
331 // InterruptX 0x67, Regs, Regs
332 // EMS.Error = (Regs.ax AND 0xFF00&) \ 0x100 //Store the status code
338 boolean errorflag=false;
340 EMShandle=mm->EMShandle;
345 for (i=0;i<MAPPAGES;i++)
350 mov cx,[i] // logical page
351 mov al,bl // physical page
352 mov dx,[EMShandle] // handle
364 //err = CPURegs.h.ah;
365 //strcpy(str,"MM_MapXEMS: EMS error 0x");
366 strcpy(str,"MM_MapXEMS: EMS error ");
368 MM_EMSerr(&str, err);
370 //printf("%s%x\n",str, err);
371 //printf("FACK! %x\n", err);
375 mmi->EMSmem = (i)*0x4000lu;
379 //==========================================================================
382 ======================
386 = Check for XMM driver
388 =======================
391 boolean MML_CheckForXMS(mminfo_t *mm)
393 boolean errorflag=false;
399 int 0x2f // query status of installed diver
405 if(errorflag==true) return false;
411 ======================
415 = Try to allocate all upper memory block
417 =======================
420 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
429 mov [WORD PTR XMSaddr],bx
430 mov [WORD PTR XMSaddr+2],es // function pointer to XMS driver
433 mov dx,0xffff // try for largest block possible
434 //mov ax,dx // Set available Kbytes.
435 call [DWORD PTR XMSaddr]
439 cmp bl,0xb0 // error: smaller UMB is available
443 call [DWORD PTR XMSaddr] // DX holds largest available UMB
445 jz done // another error...
452 printf("base=%u ", base); printf("size=%u\n", size);
453 MML_UseSpace(base,size, mm);
454 mmi->XMSmem += size*16;
455 mm->UMBbase[mm->numUMBs] = base;
457 if(mm->numUMBs < MAXUMBS)
463 ======================
467 ======================
470 void MML_ShutdownXMS(mminfo_t *mm)
475 for (i=0;i<mm->numUMBs;i++)
477 base = mm->UMBbase[i];
482 call [DWORD PTR XMSaddr]
487 //==========================================================================
490 ======================
494 = Marks a range of paragraphs as usable by the memory manager
495 = This is used to mark space for the near heap, far heap, ems page frame,
496 = and upper memory blocks
498 ======================
501 void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm)
503 mmblocktype huge *scan,huge *last;
508 scan = last = mm->mmhead;
509 mm->mmrover = mm->mmhead; // reset rover to start of memory
512 // search for the block that contains the range of segments
514 while(scan->start+scan->length < segstart)
520 //find out how many blocks it spans!
521 if(seglength>0xffffu)
523 // segm=seglength/0x4000u;
524 segm=(word)seglength/0xffffu;
529 if(segm>1/*extra>0xfffflu*/)
540 //MML_UseSpace(?segstart?, ?length?, mm);
546 //printf("MML_UseSpace: Segment spans two blocks!\n");
550 // take the given range out of the block
552 oldend = scan->start + scan->length;
553 extra = oldend - (segstart+seglength);
555 printf("segm=%u ", segm);
556 printf("ex=%lu ", extra);
557 printf("start+seglen=%lu ", segstart+seglength);
558 printf("len=%u ", scan->length);
559 printf("segsta=%x ", segstart);
560 printf("seglen=%lu\n", seglength);
563 //++++todo: linked list of segment!
564 //printf("segm=%lu\n", segm);
565 if(segstart == scan->start)
567 last->next = scan->next; // unlink block
568 MM_FreeBlock(scan, mm);
572 scan->length = segstart-scan->start; // shorten block
579 mm->mmnew->next = scan->next;
580 scan->next = mm->mmnew;
581 mm->mmnew->start = segstart+seglength;
582 mm->mmnew->length = extra;
583 mm->mmnew->attributes = LOCKBIT;
584 }//else if(segm>0) goto segu;
588 //==========================================================================
595 = We are out of blocks, so free a purgable block
600 void MML_ClearBlock(mminfo_t *mm)
602 mmblocktype huge *scan,huge *last;
604 scan = mm->mmhead->next;
608 if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS))
610 MM_FreePtr(scan->useptr, mm);
616 printf("MM_ClearBlock: No purgable blocks!\n");
620 //==========================================================================
627 = Grabs all space from turbo with malloc/farmalloc
628 = Allocates bufferseg misc buffer
633 void MM_Startup(mminfo_t *mm, mminfotype *mmi)
636 dword length,seglength;
637 //dword length; word seglength;
639 word segstart;//,endfree;
644 mm->mmstarted = true;
645 mm->bombonerror = true;
649 // set up the linked list (everything in the free list;
651 //printf(" linked list making!\n");
653 mm->mmfree = &(mm->mmblocks[0]);
654 for(i=0;i<MAXBLOCKS-1;i++)
656 mm->mmblocks[i].next = &(mm->mmblocks[i+1]);
658 mm->mmblocks[i].next = NULL;
661 // locked block of all memory until we punch out free space
663 //printf(" newblock making!\n");
665 mm->mmhead = mm->mmnew; // this will allways be the first node
666 mm->mmnew->start = 0;
667 mm->mmnew->length = 0xffff;
668 mm->mmnew->attributes = LOCKBIT;
669 mm->mmnew->next = NULL;
670 mm->mmrover = mm->mmhead;
673 // get all available near conventional memory segments
675 //---- length=coreleft();
676 printf(" nearheap making!\n");
678 length=(dword)_memmax();//(dword)GetFreeSize();
679 start = (void huge *)(mm->nearheap = _nmalloc(length));
680 length -= 16-(FP_OFF(start)&15);
681 length -= SAVENEARHEAP;
682 seglength = length / 16; // now in paragraphs
683 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
684 MML_UseSpace(segstart,seglength, mm);
685 mmi->nearheap = length;
686 printf("start=%FP segstart=%X seglen=%lu len=%lu\n", start, segstart, seglength, length);
690 // get all available far conventional memory segments
692 //---- length=farcoreleft();
693 printf(" farheap making!\n");
695 length=(dword)GetFarFreeSize();//0xffffUL*4UL;
696 //start = mm->farheap = halloc(length, 1);
697 start = mm->farheap = _fmalloc(length);
698 length -= 16-(FP_OFF(start)&15);
699 length -= SAVEFARHEAP;
700 seglength = length / 16; // now in paragraphs
701 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
702 MML_UseSpace(segstart,seglength, mm);
703 mmi->farheap = length;
704 printf("start=%FP segstart=%X seglen=%lu len=%lu\n", start, segstart, seglength, length);
707 mmi->mainmem = mmi->nearheap + mmi->farheap;
714 // detect EMS and allocate up to 64K at page frame
717 //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!
719 for(i = 1;i < __argc;i++)
721 if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
722 goto emsskip; // param NOEMS
724 //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!
725 if(MML_CheckForEMS())
728 //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!
729 MML_SetupEMS(mm); // allocate space
731 //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!
732 //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
733 MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
734 //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!
736 //if(mm->EMSVer<0x40)
737 MM_MapEMS(mm, mmi); // map in used pages
739 //MM_MapXEMS(mm, mmi); // map in used pages
746 // detect XMS and get upper memory blocks
750 for(i = 1;i < __argc;i++)
752 if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
753 goto xmsskip; // param NOXMS
755 //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!
756 if(MML_CheckForXMS(mm))
758 //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!
760 MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible
764 // allocate the misc buffer
767 mm->mmrover = mm->mmhead; // start looking for space after low block
769 MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi);
772 //==========================================================================
779 = Frees all conventional, EMS, and XMS allocated
784 void MM_Shutdown(mminfo_t *mm)
789 _ffree(mm->farheap); printf(" far freed\n");
790 _nfree(mm->nearheap); printf(" near freed\n");
791 if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); printf(" EMS freed\n"); }
792 if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); printf(" XMS freed\n"); }
795 //==========================================================================
802 = Allocates an unlocked, unpurgable block
807 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi)
809 mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
814 needed = (size+15)/16; // convert size from bytes to paragraphs
816 MM_GetNewBlock(mm); // fill in start and next after a spot is found
817 mm->mmnew->length = needed;
818 mm->mmnew->useptr = baseptr;
819 mm->mmnew->attributes = BASEATTRIBUTES;
821 for(search = 0; search<mm->endid; search++)
823 printf(" [case]"); //0000
825 // first search: try to allocate right after the rover, then on up
826 // second search: search from the head pointer up to the rover
827 // third search: compress memory, then scan from start
828 if(search == 1 && mm->mmrover == mm->mmhead)
835 lastscan = mm->mmrover;
836 scan = mm->mmrover->next;
841 lastscan = mm->mmhead;
842 scan = mm->mmhead->next;
843 endscan = mm->mmrover;
848 lastscan = mm->mmhead;
849 scan = mm->mmhead->next;
854 startseg = lastscan->start + (word)lastscan->length;
856 while(scan != endscan)
858 //printf(","); //0000
859 if(scan->start - startseg >= needed)
863 // got enough space between the end of lastscan and
864 // the start of scan, so throw out anything in the middle
865 // and allocate the new block
867 purge = lastscan->next;
868 lastscan->next = mm->mmnew;
869 mm->mmnew->start = *(word *)baseptr = startseg;
870 mm->mmnew->next = scan;
872 { // free the purgable block
873 printf(" freeing block~\n"); //0000
875 MM_FreeBlock(purge, mm);
876 purge = next; // purge another if not at scan
878 mm->mmrover = mm->mmnew;
879 return; // good allocation!
883 // if this block is purge level zero or locked, skip past it
885 if((scan->attributes & LOCKBIT)
886 || !(scan->attributes & PURGEBITS) )
888 printf(" [lock] "); //0000
889 printf("len=%lu ", scan->length);
891 startseg = lastscan->start + (word)lastscan->length;
895 scan=scan->next; // look at next line
902 printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
903 printf("for stability reasons the program will shut down! wwww\n");
904 printf(" endid=%u\n",(mm->endid));
912 //==========================================================================
919 = Allocates an unlocked, unpurgable block
924 void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
926 mmblocktype huge *scan,huge *last;
931 if(baseptr == mm->mmrover->useptr) // removed the last allocated block
932 mm->mmrover = mm->mmhead;
934 while(scan->useptr != baseptr && scan)
942 printf("MM_FreePtr: Block not found!\n");
946 last->next = scan->next;
948 MM_FreeBlock(scan, mm);
950 //==========================================================================
953 =====================
957 = Sets the purge level for a block (locked blocks cannot be made purgable)
959 =====================
962 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
964 mmblocktype huge *start;
970 if(mm->mmrover->useptr == baseptr)
973 mm->mmrover = mm->mmrover->next;
976 mm->mmrover = mm->mmhead;
977 else if(mm->mmrover == start)
979 printf("MM_SetPurge: Block not found!");
985 mm->mmrover->attributes &= ~PURGEBITS;
986 mm->mmrover->attributes |= purge;
989 //==========================================================================
992 =====================
996 = Locks / unlocks the block
998 =====================
1001 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
1003 mmblocktype huge *start;
1005 start = mm->mmrover;
1009 if(mm->mmrover->useptr == baseptr)
1012 mm->mmrover = mm->mmrover->next;
1015 mm->mmrover = mm->mmhead;
1016 else if(mm->mmrover == start)
1018 printf("MM_SetLock: Block not found!");
1024 mm->mmrover->attributes &= ~LOCKBIT;
1025 mm->mmrover->attributes |= locked*LOCKBIT;
1028 //==========================================================================
1031 =====================
1035 = Throws out all purgable stuff and compresses movable blocks
1037 =====================
1040 void MM_SortMem(mminfo_t *mm)
1042 mmblocktype huge *scan,huge *last,huge *next;
1043 unsigned start,length,source,dest,oldborder;
1047 // lock down a currently playing sound
1049 /*++++ playing = SD_SoundPlaying ();
1055 playing += STARTPCSOUNDS;
1058 playing += STARTADLIBSOUNDS;
1061 MM_SetLock(&(memptr)audiosegs[playing],true);
1066 // oldborder = bordercolor;
1067 // VW_ColorBorder (15);
1074 last = NULL; // shut up compiler warning
1078 if(scan->attributes & LOCKBIT)
1081 // block is locked, so try to pile later blocks right after it
1083 start = scan->start + scan->length;
1087 if(scan->attributes & PURGEBITS)
1090 // throw out the purgable block
1093 MM_FreeBlock(scan, mm);
1101 // push the non purgable block on top of the last moved block
1103 if(scan->start != start)
1105 length = scan->length;
1106 source = scan->start;
1108 while(length > 0xf00)
1110 movedata(source,0,dest,0,0xf00*16);
1115 movedata(source,0,dest,0,length*16);
1117 scan->start = start;
1118 *(unsigned *)scan->useptr = start;
1120 start = scan->start + scan->length;
1125 scan = scan->next; // go to next block
1128 mm->mmrover = mm->mmhead;
1133 // VW_ColorBorder (oldborder);
1136 MM_SetLock(&(memptr)audiosegs[playing],false);*/
1140 //==========================================================================
1144 =====================
1148 =====================
1151 void MM_ShowMemory(/*page_t *page, */mminfo_t *mm)
1153 mmblocktype huge *scan;
1157 byte scratch[160],str[16];
1159 //**** VW_SetDefaultColors();
1160 //**** VW_SetLineWidth(40);
1161 //++++mh temp = bufferofs;
1162 //++++mh bufferofs = 0;
1163 //**** VW_SetScreen (0,0);
1176 if(scan->attributes & PURGEBITS)
1177 color = 5; // dark purple = purgable
1179 color = 9; // medium blue = non purgable
1180 if(scan->attributes & LOCKBIT)
1181 color = 12; // red = locked
1182 if(scan->start<=end)
1185 write(debughandle,"\nMM_ShowMemory: Memory block order currupted!\n",strlen("\nMM_ShowMemory: Memory block order currupted!\n"));
1186 //modexprint(&page, chx, chy, 1, 0, 24, "\nMM_ShowMemory: Memory block order currupted!\n");
1189 end = scan->start+scan->length-1;
1190 chy = scan->start/320;
1191 chx = scan->start%320;
1192 //modexhlin(page, scan->start, (unsigned)end, chy, color);
1193 //for(chx=scan->start;chx+4>=(word)end;chx+=4)
1195 //++++ modexClearRegion(page, chx, chy, 4, 4, color);
1198 //++++ VW_Hlin(scan->start,(unsigned)end,0,color);
1200 //++++ VW_Plot(scan->start,0,15);
1201 //++++ modexClearRegion(page, chx, chy, 4, 4, 15);
1202 if(scan->next->start > end+1)
1203 //++++ VW_Hlin(end+1,scan->next->start,0,0); // black = free
1204 //for(chx=scan->next->start;chx+4>=(word)end+1;chx+=4)
1206 //++++ chx+=scan->next->start;
1207 //++++ modexClearRegion(page, chx, chy, 4, 4, 2);
1209 //modexhlin(page, end+1,scan->next->start, chy, 0);
1212 end = scan->length-1;
1213 y = scan->start/320;
1214 x = scan->start%320;
1215 VW_Hlin(x,x+end,y,color);
1217 if (scan->next && scan->next->start > end+1)
1218 VW_Hlin(x+end+1,x+(scan->next->start-scan->start),y,0); // black = free
1222 //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!
1223 strcpy(scratch,"Seg:");
1224 ultoa (scan->start,str,16);
1225 strcat (scratch,str);
1226 strcat (scratch,"\tSize:");
1227 ultoa ((dword)scan->length,str,10);
1228 strcat (scratch,str);
1229 strcat (scratch,"\tOwner:0x");
1230 owner = (unsigned)scan->useptr;
1231 ultoa (owner,str,16);
1232 strcat (scratch,str);
1233 strcat (scratch,"\n");
1234 write(debughandle,scratch,strlen(scratch));
1235 //modexprint(page, chx, chy, 1, 0, 24, &scratch);
1237 //fprintf(stdout, "%s", scratch);
1246 //**** VW_SetLineWidth(64);
1247 //++++mh bufferofs = temp;
1251 //==========================================================================
1254 =====================
1258 =====================
1261 void MM_DumpData(mminfo_t *mm)
1263 mmblocktype far *scan,far *best;
1264 long lowest,oldlowest;
1270 //++++free(mm->nearheap);
1271 dumpfile = fopen ("mmdump.16","w");
1273 printf("MM_DumpData: Couldn't open MMDUMP.16!\n");
1286 owner = (word)scan->useptr;
1288 if (owner && owner<lowest && owner > oldlowest)
1297 if (lowest != 0xffff)
1299 if (best->attributes & PURGEBITS)
1303 if (best->attributes & LOCKBIT)
1307 fprintf (dumpfile,"0x%p (%c%c) = %u\n"
1308 ,(word)lowest,lock,purge,best->length);
1311 } while (lowest != 0xffff);
1314 printf("MMDUMP.16 created.\n");
1317 //==========================================================================
1321 ======================
1325 = Returns the total free space without purging
1327 ======================
1330 dword MM_UnusedMemory(mminfo_t *mm)
1333 mmblocktype huge *scan;
1340 free += scan->next->start - (scan->start + scan->length);
1348 //==========================================================================
1352 ======================
1356 = Returns the total free space with purging
1358 ======================
1361 dword MM_TotalFree(mminfo_t *mm)
1364 mmblocktype huge *scan;
1371 if((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
1372 free += scan->length;
1373 free += scan->next->start - (scan->start + scan->length);
1381 //==========================================================================
1384 =====================
1388 =====================
1391 void MM_Report(/*page_t *page, */mminfo_t *mm, mminfotype *mmi)
1393 if(MML_CheckForEMS())
1395 printf("EMM v%x.%x available\n", mm->EMSVer>>4,mm->EMSVer&0x0F);
1396 printf("totalEMSpages=%u\n", mm->totalEMSpages);
1397 printf("freeEMSpages=%u\n", mm->freeEMSpages);
1398 printf("EMSpageframe=%x\n", mm->EMSpageframe);
1400 if(MML_CheckForXMS(mm)) printf("XMSaddr=%X\n", *XMSaddr);
1401 printf("near=%lu\n", mmi->nearheap);
1402 printf("far=%lu\n", mmi->farheap);
1403 printf("EMSmem=%lu\n", mmi->EMSmem);
1404 printf("XMSmem=%lu\n", mmi->XMSmem);
1405 printf("mainmem=%lu\n", mmi->mainmem);
1406 printf("UnusedMemory=%lu\n", MM_UnusedMemory(mm));
1407 printf("TotalFree=%lu\n", MM_TotalFree(mm));
1408 //mmi->nearheap+mmi->farheap+
1409 printf("TotalUsed=%lu\n", mmi->mainmem+mmi->EMSmem+mmi->XMSmem);//+);
1411 // printf("UnusedMemory=%lu kb\n", MM_UnusedMemory()/10248);
1412 // printf("TotalFree=%lu kb\n", MM_TotalFree()/10248);
1415 //==========================================================================
1418 =====================
1422 =====================
1425 void MM_EMSerr(byte *stri, byte err)
1427 //Returns a text string describing the error code in EMS.Error.
1431 strcat(stri, "successful");
1434 strcat(stri, "internal error");
1437 strcat(stri, "hardware malfunction");
1440 strcat(stri, "busy .. retry later");
1443 strcat(stri, "invalid handle");
1446 strcat(stri, "undefined function requested by application");
1449 strcat(stri, "no more handles available");
1452 strcat(stri, "error in save or restore of mapping context");
1455 strcat(stri, "insufficient memory pages in system");
1458 strcat(stri, "insufficient memory pages available");
1461 strcat(stri, "zero pages requested");
1464 strcat(stri, "invalid logical page number encountered");
1467 strcat(stri, "invalid physical page number encountered");
1470 strcat(stri, "page-mapping hardware state save area is full");
1473 strcat(stri, "save of mapping context failed");
1476 strcat(stri, "restore of mapping context failed");
1479 strcat(stri, "undefined subfunction");
1482 strcat(stri, "undefined attribute type");
1485 strcat(stri, "feature not supported");
1488 strcat(stri, "successful, but a portion of the source region has been overwritten");
1491 strcat(stri, "length of source or destination region exceeds length of region allocated to either source or destination handle");
1494 strcat(stri, "conventional and expanded memory regions overlap");
1497 strcat(stri, "offset within logical page exceeds size of logical page");
1500 strcat(stri, "region length exceeds 1 MB");
1503 strcat(stri, "source and destination EMS regions have same handle and overlap");
1506 strcat(stri, "memory source or destination type undefined");
1509 strcat(stri, "specified alternate map register or DMA register set not supported");
1512 strcat(stri, "all alternate map register or DMA register sets currently allocated");
1515 strcat(stri, "alternate map register or DMA register sets not supported");
1518 strcat(stri, "undefined or unallocated alternate map register or DMA register set");
1521 strcat(stri, "dedicated DMA channels not supported");
1524 strcat(stri, "specified dedicated DMA channel not supported");
1527 strcat(stri, "no such handle name");
1530 strcat(stri, "a handle found had no name, or duplicate handle name");
1533 strcat(stri, "attempted to wrap around 1M conventional address space");
1536 strcat(stri, "source array corrupted");
1539 strcat(stri, "operating system denied access");
1542 strcat(stri, "undefined error");
1546 //==========================================================================
1549 =====================
1553 =====================
1556 void MM_BombOnError(boolean bomb, mminfo_t *mm)
1558 mm->bombonerror = bomb;
1561 void MM_GetNewBlock(mminfo_t *mm)
1565 mm->mmnew=mm->mmfree;
1566 mm->mmfree=mm->mmfree->next;
1567 if(!(mm->mmnew=mm->mmfree))
1569 printf("MM_GETNEWBLOCK: No free blocks!\n");
1572 mm->mmfree=mm->mmfree->next;
1573 mm->endid++; //end of list
1576 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
1581 mm->endid--; //end of list
1584 void MM_seguin(void)
1594 void MM_segude(void)
1602 pull data from far and put it into ds var