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
55 /*#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!")\
\r
56 ;mmfree=mmfree->next;}
\r
58 //#define GETNEWBLOCK {if(!mmfree)MML_ClearBlock();mmnew=mmfree;mmfree=mmfree->next;}
\r
60 #define FREEBLOCK(x) {*x->useptr=NULL;x->next=mmfree;mmfree=x;}*/
63 =============================================================================
67 =============================================================================
70 void (* beforesort) (void);
71 void (* aftersort) (void);
72 void (* XMSaddr) (void); // far pointer to XMS driver
75 =============================================================================
79 =============================================================================
82 static char *ParmStringsexmm[] = {"noems","noxms",""};
85 ======================
89 = Routine from p36 of Extending DOS
91 =======================
94 boolean MML_CheckForEMS(void)
97 static char emmname[] = "EMMXXXX0"; //fix by andrius4669
98 // mov dx,OFFSET emmname
100 //LEA DX, emmname //fix by andrius4669
101 mov dx,OFFSET emmname //fix by andrius4669
103 int 0x21 // try to open EMMXXXX0 device
109 int 0x21 // get device info
117 int 0x21 // get status
123 int 0x21 // close handle
144 ======================
148 =======================
151 byte MML_SetupEMS(mminfo_t *mm)
155 boolean errorflag=false;
157 unsigned int EMSVer = 0;
159 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
160 totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
164 int EMS_INT // make sure EMS hardware is present
166 //mov [EMS_status],ah
173 mov [EMSVer],ax // set EMSVer
174 cmp al,0x32 // only work on ems 3.2 or greater
178 int EMS_INT // find the page frame address
181 mov [EMSpageframe],bx
184 int EMS_INT // find out how much EMS is there
187 mov [totalEMSpages],dx
188 mov [freeEMSpages],bx
190 jz noEMS // no EMS at all to allocate
194 cmp bx,[freeEMSpages]
196 mov bx,[freeEMSpages]
203 jle getpages // there is only 1,2,3,or 4 pages
204 mov bx,4 // we can't use more than 4 pages
209 mov [EMSpagesmapped],bx
210 mov ah,EMS_ALLOCPAGES // allocate up to 64k of EMS
227 //err = CPURegs.h.ah;
228 strcpy(str,"MM_SetupEMS: EMS error ");
234 mm->totalEMSpages=totalEMSpages;
235 mm->freeEMSpages=freeEMSpages;
236 mm->EMSpageframe=EMSpageframe;
237 mm->EMSpagesmapped=EMSpagesmapped;
238 mm->EMShandle=EMShandle;
245 ======================
249 =======================
252 void MML_ShutdownEMS(mminfo_t *mm)
254 boolean errorflag=false;
255 unsigned EMShandle=mm->EMShandle;
268 if(errorflag==true) printf("MML_ShutdownEMS: Error freeing EMS!\n"); //++++ add something
276 = Maps the 64k of EMS used by memory manager into the page frame
277 = for general use. This only needs to be called if you are keeping
278 = other things in EMS.
283 byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi)
288 boolean errorflag=false;
290 EMShandle=mm->EMShandle;
292 for (i=0;i<4/*MAPPAGES*/;i++)
296 mov bx,[i] // logical page
297 mov al,bl // physical page
298 mov dx,[EMShandle] // handle
312 //err = CPURegs.h.ah;
313 strcpy(str,"MM_MapEMS: EMS error ");
317 //printf("FACK! %x\n", err);
321 mmi->EMSmem = (i)*0x4000lu;
325 byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
327 //SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)
329 //Maps up to 4 logical EMS pages to physical pages in the page frame, where:
330 //PhysicalStart = Physical page first logical page is mapped to
331 //LogicalStart = First logical page to map
332 //NumPages = Number of pages to map (1 to 4)
333 //Handle = EMS handle logical pages are allocated to
335 /*//Create a buffer containing the page information
336 // FOR x = 0 TO NumPages - 1
337 // MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x)
340 // Regs.ax = 0x5000 //Map the pages in the buffer
341 // Regs.cx = NumPages //to the pageframe
343 // Regs.ds = VARSEG(MapInfo$)
344 // Regs.si = SADD(MapInfo$)
345 // InterruptX 0x67, Regs, Regs
346 // EMS.Error = (Regs.ax AND 0xFF00&) \ 0x100 //Store the status code
352 boolean errorflag=false;
354 EMShandle=mm->EMShandle;
359 for (i=0;i<MAPPAGES;i++)
363 mov cx,[i] // logical page
364 mov al,bl // physical page
365 mov dx,[EMShandle] // handle
379 //err = CPURegs.h.ah;
380 //strcpy(str,"MM_MapXEMS: EMS error 0x");
381 strcpy(str,"MM_MapXEMS: EMS error ");
385 //printf("%s%x\n",str, err);
386 //printf("FACK! %x\n", err);
390 mmi->EMSmem = (i)*0x4000lu;
394 //==========================================================================
397 ======================
401 = Check for XMM driver
403 =======================
406 boolean MML_CheckForXMS(mminfo_t *mm)
408 boolean errorflag=false;
413 int 0x2f // query status of installed diver
419 if(errorflag==true) return false;
425 ======================
429 = Try to allocate all upper memory block
431 =======================
434 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
442 mov [WORD PTR XMSaddr],bx
443 mov [WORD PTR XMSaddr+2],es // function pointer to XMS driver
446 mov dx,0xffff // try for largest block possible
447 //mov ax,dx // Set available Kbytes.
448 call [DWORD PTR XMSaddr]
452 cmp bl,0xb0 // error: smaller UMB is available
456 call [DWORD PTR XMSaddr] // DX holds largest available UMB
458 jz done // another error...
466 printf("base=%u ", base); printf("size=%u\n", size);
467 MML_UseSpace(base,size, mm);
468 mmi->XMSmem += size*16;
469 mm->UMBbase[mm->numUMBs] = base;
471 if(mm->numUMBs < MAXUMBS)
477 ======================
481 ======================
484 void MML_ShutdownXMS(mminfo_t *mm)
489 for (i=0;i<mm->numUMBs;i++)
491 base = mm->UMBbase[i];
495 call [DWORD PTR XMSaddr]
500 //==========================================================================
503 ======================
507 = Marks a range of paragraphs as usable by the memory manager
508 = This is used to mark space for the near heap, far heap, ems page frame,
509 = and upper memory blocks
511 ======================
514 void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm)
516 mmblocktype huge *scan,huge *last;
521 scan = last = mm->mmhead;
522 mm->mmrover = mm->mmhead; // reset rover to start of memory
525 // search for the block that contains the range of segments
527 while(scan->start+scan->length < segstart)
533 //find out how many blocks it spans!
534 if(seglength>0xffffu)
536 // segm=seglength/0x4000u;
537 segm=seglength/0xffffu;
542 if(segm>1/*extra>0xfffflu*/)
553 //MML_UseSpace(?segstart?, ?length?, mm);
559 //printf("MML_UseSpace: Segment spans two blocks!\n");
563 // take the given range out of the block
565 oldend = scan->start + scan->length;
566 extra = oldend - (segstart+seglength);
568 printf("segm=%u ", segm);
569 printf("ex=%lu ", extra);
570 printf("start+seglen=%lu ", segstart+seglength);
571 printf("len=%u ", scan->length);
572 printf("segsta=%x ", segstart);
573 printf("seglen=%lu\n", seglength);
576 //++++todo: linked list of segment!
577 //printf("segm=%lu\n", segm);
578 if(segstart == scan->start)
580 last->next = scan->next; // unlink block
581 MM_FreeBlock(scan, mm);
585 scan->length = segstart-scan->start; // shorten block
592 mm->mmnew->next = scan->next;
593 scan->next = mm->mmnew;
594 mm->mmnew->start = segstart+seglength;
595 mm->mmnew->length = extra;
596 mm->mmnew->attributes = LOCKBIT;
597 }//else if(segm>0) goto segu;
601 //==========================================================================
608 = We are out of blocks, so free a purgable block
613 void MML_ClearBlock(mminfo_t *mm)
615 mmblocktype huge *scan,huge *last;
617 scan = mm->mmhead->next;
621 if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS))
623 MM_FreePtr(scan->useptr, mm);
629 printf("MM_ClearBlock: No purgable blocks!\n");
633 //==========================================================================
640 = Grabs all space from turbo with malloc/farmalloc
641 = Allocates bufferseg misc buffer
646 void MM_Startup(mminfo_t *mm, mminfotype *mmi)
649 dword length,seglength;
650 //dword length; word seglength;
652 word segstart;//,endfree;
657 mm->mmstarted = true;
658 mm->bombonerror = true;
661 // set up the linked list (everything in the free list;
663 //printf(" linked list making!\n");
665 mm->mmfree = &(mm->mmblocks[0]);
666 for(i=0;i<MAXBLOCKS-1;i++)
668 mm->mmblocks[i].next = &(mm->mmblocks[i+1]);
670 mm->mmblocks[i].next = NULL;
673 // locked block of all memory until we punch out free space
675 //printf(" newblock making!\n");
677 mm->mmhead = mm->mmnew; // this will allways be the first node
678 mm->mmnew->start = 0;
679 mm->mmnew->length = 0xffff;
680 mm->mmnew->attributes = LOCKBIT;
681 mm->mmnew->next = NULL;
682 mm->mmrover = mm->mmhead;
685 // get all available near conventional memory segments
688 printf(" nearheap making!\n");
690 //length=_memmax();//(dword)GetFreeSize();
691 start = (void huge *)(mm->nearheap = malloc(length));
692 length -= 16-(FP_OFF(start)&15);
693 length -= SAVENEARHEAP;
694 seglength = length / 16; // now in paragraphs
695 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
696 MML_UseSpace(segstart,seglength, mm);
697 mmi->nearheap = length;
698 printf("start=%Fp segstart=%x seglen=%l len=%l\n", start, segstart, seglength, length);
699 printf(" near heap ok!\n");
702 // get all available far conventional memory segments
704 length=farcoreleft();
705 //printf(" farheap making!\n");
707 //length=(dword)GetFarFreeSize();//0xffffUL*4UL;
708 //start = mm->farheap = halloc(length, 1);
709 start = mm->farheap = _fmalloc(length);
710 length -= 16-(FP_OFF(start)&15);
711 length -= SAVEFARHEAP;
712 seglength = length / 16; // now in paragraphs
713 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
714 MML_UseSpace(segstart,seglength, mm);
715 mmi->farheap = length;
716 printf("start=%Fp segstart=%x seglen=%l len=%l\n", start, segstart, seglength, length);
717 printf(" far heap ok!\n");
719 mmi->mainmem = mmi->nearheap + mmi->farheap;
724 // detect EMS and allocate up to 64K at page frame
727 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 for(i = 1;i < _argc;i++)
731 if(US_CheckParm(_argv[i],ParmStringsexmm) == 0)
732 goto emsskip; // param NOEMS
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!
735 if(MML_CheckForEMS())
738 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!
739 MML_SetupEMS(mm); // allocate space
741 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!
742 //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
743 MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
744 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!
746 //if(mm->EMSVer<0x40)
747 MM_MapEMS(mm, mmi); // map in used pages
749 //MM_MapXEMS(mm, mmi); // map in used pages
753 // detect XMS and get upper memory blocks
757 for(i = 1;i < _argc;i++)
759 if(US_CheckParm(_argv[i],ParmStringsexmm) == 0)
760 goto xmsskip; // param NOXMS
762 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!
763 if(MML_CheckForXMS(mm))
765 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!
767 MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible
771 // allocate the misc buffer
774 mm->mmrover = mm->mmhead; // start looking for space after low block
776 MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi);
779 //==========================================================================
786 = Frees all conventional, EMS, and XMS allocated
791 void MM_Shutdown(mminfo_t *mm)
796 _ffree(mm->farheap); printf(" far freed\n");
797 free(mm->nearheap); printf(" near freed\n");
798 if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); printf(" EMS freed\n"); }
799 if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); printf(" XMS freed\n"); }
802 //==========================================================================
809 = Allocates an unlocked, unpurgable block
814 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi)
816 mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
818 unsigned needed,startseg;
820 needed = (size+15)/16; // convert size from bytes to paragraphs
822 MM_GetNewBlock(mm); // fill in start and next after a spot is found
823 mm->mmnew->length = needed;
824 mm->mmnew->useptr = baseptr;
825 mm->mmnew->attributes = BASEATTRIBUTES;
827 for(search = 0; search<3; search++)
830 // first search: try to allocate right after the rover, then on up
831 // second search: search from the head pointer up to the rover
832 // third search: compress memory, then scan from start
833 if(search == 1 && mm->mmrover == mm->mmhead)
839 lastscan = mm->mmrover;
840 scan = mm->mmrover->next;
844 lastscan = mm->mmhead;
845 scan = mm->mmhead->next;
846 endscan = mm->mmrover;
850 lastscan = mm->mmhead;
851 scan = mm->mmhead->next;
856 startseg = lastscan->start + lastscan->length;
858 while(scan != endscan)
860 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 = *(unsigned *)baseptr = startseg;
870 mm->mmnew->next = scan;
872 { // free the purgable block
874 MM_FreeBlock(purge, mm);
875 purge = next; // purge another if not at scan
877 mm->mmrover = mm->mmnew;
878 return; // good allocation!
882 // if this block is purge level zero or locked, skip past it
884 if((scan->attributes & LOCKBIT)
885 || !(scan->attributes & PURGEBITS) )
888 startseg = lastscan->start + lastscan->length;
892 scan=scan->next; // look at next line
898 printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
905 //==========================================================================
912 = Allocates an unlocked, unpurgable block
917 void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
919 mmblocktype huge *scan,huge *last;
924 if(baseptr == mm->mmrover->useptr) // removed the last allocated block
925 mm->mmrover = mm->mmhead;
927 while(scan->useptr != baseptr && scan)
935 printf("MM_FreePtr: Block not found!\n");
939 last->next = scan->next;
941 MM_FreeBlock(scan, mm);
943 //==========================================================================
946 =====================
950 = Sets the purge level for a block (locked blocks cannot be made purgable)
952 =====================
955 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
957 mmblocktype huge *start;
963 if(mm->mmrover->useptr == baseptr)
966 mm->mmrover = mm->mmrover->next;
969 mm->mmrover = mm->mmhead;
970 else if(mm->mmrover == start)
972 printf("MM_SetPurge: Block not found!");
978 mm->mmrover->attributes &= ~PURGEBITS;
979 mm->mmrover->attributes |= purge;
982 //==========================================================================
985 =====================
989 = Locks / unlocks the block
991 =====================
994 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
996 mmblocktype huge *start;
1002 if(mm->mmrover->useptr == baseptr)
1005 mm->mmrover = mm->mmrover->next;
1008 mm->mmrover = mm->mmhead;
1009 else if(mm->mmrover == start)
1011 printf("MM_SetLock: Block not found!");
1017 mm->mmrover->attributes &= ~LOCKBIT;
1018 mm->mmrover->attributes |= locked*LOCKBIT;
1021 //==========================================================================
1024 =====================
1028 = Throws out all purgable stuff and compresses movable blocks
1030 =====================
1033 void MM_SortMem(mminfo_t *mm)
1035 mmblocktype huge *scan,huge *last,huge *next;
1036 unsigned start,length,source,dest,oldborder;
1040 // lock down a currently playing sound
1042 /*++++ playing = SD_SoundPlaying ();
1048 playing += STARTPCSOUNDS;
1051 playing += STARTADLIBSOUNDS;
1054 MM_SetLock(&(memptr)audiosegs[playing],true);
1059 // oldborder = bordercolor;
1060 // VW_ColorBorder (15);
1067 last = NULL; // shut up compiler warning
1071 if(scan->attributes & LOCKBIT)
1074 // block is locked, so try to pile later blocks right after it
1076 start = scan->start + scan->length;
1080 if(scan->attributes & PURGEBITS)
1083 // throw out the purgable block
1086 MM_FreeBlock(scan, mm);
1094 // push the non purgable block on top of the last moved block
1096 if(scan->start != start)
1098 length = scan->length;
1099 source = scan->start;
1101 while(length > 0xf00)
1103 movedata(source,0,dest,0,0xf00*16);
1108 movedata(source,0,dest,0,length*16);
1110 scan->start = start;
1111 *(unsigned *)scan->useptr = start;
1113 start = scan->start + scan->length;
1118 scan = scan->next; // go to next block
1121 mm->mmrover = mm->mmhead;
1126 // VW_ColorBorder (oldborder);
1129 MM_SetLock(&(memptr)audiosegs[playing],false);*/
1133 //==========================================================================
1137 =====================
1141 =====================
1144 void MM_ShowMemory(/*page_t *page, */mminfo_t *mm)
1146 mmblocktype huge *scan;
1150 byte scratch[160],str[16];
1152 //**** VW_SetDefaultColors();
1153 //**** VW_SetLineWidth(40);
1154 //++++mh temp = bufferofs;
1155 //++++mh bufferofs = 0;
1156 //**** VW_SetScreen (0,0);
1169 if(scan->attributes & PURGEBITS)
1170 color = 5; // dark purple = purgable
1172 color = 9; // medium blue = non purgable
1173 if(scan->attributes & LOCKBIT)
1174 color = 12; // red = locked
1175 if(scan->start<=end)
1178 write(debughandle,"\nMM_ShowMemory: Memory block order currupted!\n",strlen("\nMM_ShowMemory: Memory block order currupted!\n"));
1179 //modexprint(&page, chx, chy, 1, 0, 24, "\nMM_ShowMemory: Memory block order currupted!\n");
1182 end = scan->start+scan->length-1;
1183 chy = scan->start/320;
1184 chx = scan->start%320;
1185 //modexhlin(page, scan->start, (unsigned)end, chy, color);
1186 //for(chx=scan->start;chx+4>=(word)end;chx+=4)
1188 //++++ modexClearRegion(page, chx, chy, 4, 4, color);
1191 //++++ VW_Hlin(scan->start,(unsigned)end,0,color);
1193 //++++ VW_Plot(scan->start,0,15);
1194 //++++ modexClearRegion(page, chx, chy, 4, 4, 15);
1195 if(scan->next->start > end+1)
1196 //++++ VW_Hlin(end+1,scan->next->start,0,0); // black = free
1197 //for(chx=scan->next->start;chx+4>=(word)end+1;chx+=4)
1199 //++++ chx+=scan->next->start;
1200 //++++ modexClearRegion(page, chx, chy, 4, 4, 2);
1202 //modexhlin(page, end+1,scan->next->start, chy, 0);
1205 end = scan->length-1;
1206 y = scan->start/320;
1207 x = scan->start%320;
1208 VW_Hlin(x,x+end,y,color);
1210 if (scan->next && scan->next->start > end+1)
1211 VW_Hlin(x+end+1,x+(scan->next->start-scan->start),y,0); // black = free
1215 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!
1216 strcpy(scratch,"Seg:");
1217 ultoa (scan->start,str,16);
1218 strcat (scratch,str);
1219 strcat (scratch,"\tSize:");
1220 ultoa ((dword)scan->length,str,10);
1221 strcat (scratch,str);
1222 strcat (scratch,"\tOwner:0x");
1223 owner = (unsigned)scan->useptr;
1224 ultoa (owner,str,16);
1225 strcat (scratch,str);
1226 strcat (scratch,"\n");
1227 write(debughandle,scratch,strlen(scratch));
1228 //modexprint(page, chx, chy, 1, 0, 24, &scratch);
1230 //fprintf(stdout, "%s", scratch);
1239 //**** VW_SetLineWidth(64);
1240 //++++mh bufferofs = temp;
1244 //==========================================================================
1247 =====================
1251 =====================
1254 void MM_DumpData(mminfo_t *mm)
1256 mmblocktype far *scan,far *best;
1257 long lowest,oldlowest;
1263 //++++free(mm->nearheap);
1264 dumpfile = fopen ("mmdump.16","w");
1266 printf("MM_DumpData: Couldn't open MMDUMP.16!\n");
1279 owner = (word)scan->useptr;
1281 if (owner && owner<lowest && owner > oldlowest)
1290 if (lowest != 0xffff)
1292 if (best->attributes & PURGEBITS)
1296 if (best->attributes & LOCKBIT)
1300 fprintf (dumpfile,"0x%p (%c%c) = %u\n"
1301 ,(word)lowest,lock,purge,best->length);
1304 } while (lowest != 0xffff);
1307 printf("MMDUMP.16 created.\n");
1310 //==========================================================================
1314 ======================
1318 = Returns the total free space without purging
1320 ======================
1323 dword MM_UnusedMemory(mminfo_t *mm)
1326 mmblocktype huge *scan;
1333 free += scan->next->start - (scan->start + scan->length);
1341 //==========================================================================
1345 ======================
1349 = Returns the total free space with purging
1351 ======================
1354 dword MM_TotalFree(mminfo_t *mm)
1357 mmblocktype huge *scan;
1364 if((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
1365 free += scan->length;
1366 free += scan->next->start - (scan->start + scan->length);
1374 //==========================================================================
1377 =====================
1381 =====================
1384 void MM_Report(/*page_t *page, */mminfo_t *mm, mminfotype *mmi)
1386 if(MML_CheckForEMS())
1388 printf("EMM v%x.%x available\n", mm->EMSVer>>4,mm->EMSVer&0x0F);
1389 printf("totalEMSpages=%u\n", mm->totalEMSpages);
1390 printf("freeEMSpages=%u\n", mm->freeEMSpages);
1391 printf("EMSpageframe=%x\n", mm->EMSpageframe);
1393 if(MML_CheckForXMS(mm)) printf("XMSaddr=%X\n", *XMSaddr);
1394 printf("near=%lu\n", mmi->nearheap);
1395 printf("far=%lu\n", mmi->farheap);
1396 printf("EMSmem=%lu\n", mmi->EMSmem);
1397 printf("XMSmem=%lu\n", mmi->XMSmem);
1398 printf("mainmem=%lu\n", mmi->mainmem);
1399 printf("UnusedMemory=%lu\n", MM_UnusedMemory(mm));
1400 printf("TotalFree=%lu\n", MM_TotalFree(mm));
1401 //mmi->nearheap+mmi->farheap+
1402 printf("TotalUsed=%lu\n", mmi->mainmem+mmi->EMSmem+mmi->XMSmem);//+);
1404 // printf("UnusedMemory=%lu kb\n", MM_UnusedMemory()/10248);
1405 // printf("TotalFree=%lu kb\n", MM_TotalFree()/10248);
1408 //==========================================================================
1411 =====================
1415 =====================
1418 void MM_EMSerr(byte *stri, byte err)
1420 //Returns a text string describing the error code in EMS.Error.
1424 strcat(stri, "successful");
1427 strcat(stri, "internal error");
1430 strcat(stri, "hardware malfunction");
1433 strcat(stri, "busy .. retry later");
1436 strcat(stri, "invalid handle");
1439 strcat(stri, "undefined function requested by application");
1442 strcat(stri, "no more handles available");
1445 strcat(stri, "error in save or restore of mapping context");
1448 strcat(stri, "insufficient memory pages in system");
1451 strcat(stri, "insufficient memory pages available");
1454 strcat(stri, "zero pages requested");
1457 strcat(stri, "invalid logical page number encountered");
1460 strcat(stri, "invalid physical page number encountered");
1463 strcat(stri, "page-mapping hardware state save area is full");
1466 strcat(stri, "save of mapping context failed");
1469 strcat(stri, "restore of mapping context failed");
1472 strcat(stri, "undefined subfunction");
1475 strcat(stri, "undefined attribute type");
1478 strcat(stri, "feature not supported");
1481 strcat(stri, "successful, but a portion of the source region has been overwritten");
1484 strcat(stri, "length of source or destination region exceeds length of region allocated to either source or destination handle");
1487 strcat(stri, "conventional and expanded memory regions overlap");
1490 strcat(stri, "offset within logical page exceeds size of logical page");
1493 strcat(stri, "region length exceeds 1 MB");
1496 strcat(stri, "source and destination EMS regions have same handle and overlap");
1499 strcat(stri, "memory source or destination type undefined");
1502 strcat(stri, "specified alternate map register or DMA register set not supported");
1505 strcat(stri, "all alternate map register or DMA register sets currently allocated");
1508 strcat(stri, "alternate map register or DMA register sets not supported");
1511 strcat(stri, "undefined or unallocated alternate map register or DMA register set");
1514 strcat(stri, "dedicated DMA channels not supported");
1517 strcat(stri, "specified dedicated DMA channel not supported");
1520 strcat(stri, "no such handle name");
1523 strcat(stri, "a handle found had no name, or duplicate handle name");
1526 strcat(stri, "attempted to wrap around 1M conventional address space");
1529 strcat(stri, "source array corrupted");
1532 strcat(stri, "operating system denied access");
1535 strcat(stri, "undefined error");
1539 //==========================================================================
1542 =====================
1546 =====================
1549 void MM_BombOnError(boolean bomb, mminfo_t *mm)
1551 mm->bombonerror = bomb;
1554 void MM_GetNewBlock(mminfo_t *mm)
1558 mm->mmnew=mm->mmfree;
1559 mm->mmfree=mm->mmfree->next;
1560 //if(!(mm->mmnew=mm->mmfree))
1562 //printf("MM_GETNEWBLOCK: No free blocks!");
1565 //mm->mmfree=mm->mmfree->next;
1568 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
1575 /*void MM_seguin(void)
1586 void MM_segude(void)
1595 pull data from far and put it into ds var