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
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
137 ======================
141 =======================
144 byte MML_SetupEMS(mminfo_t *mm)
148 boolean errorflag=false;
150 unsigned int EMSVer = 0;
152 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
153 totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
158 int EMS_INT // make sure EMS hardware is present
160 //mov [EMS_status],ah
167 mov [EMSVer],ax // set EMSVer
168 cmp al,0x32 // only work on ems 3.2 or greater
172 int EMS_INT // find the page frame address
175 mov [EMSpageframe],bx
178 int EMS_INT // find out how much EMS is there
181 mov [totalEMSpages],dx
182 mov [freeEMSpages],bx
184 jz noEMS // no EMS at all to allocate
188 cmp bx,[freeEMSpages]
190 mov bx,[freeEMSpages]
195 jle getpages // there is only 1,2,3,or 4 pages
196 mov bx,4 // we can't use more than 4 pages
199 mov [EMSpagesmapped],bx
200 mov ah,EMS_ALLOCPAGES // allocate up to 64k of EMS
215 //err = CPURegs.h.ah;
216 strcpy(str,"MM_SetupEMS: EMS error ");
218 MM_EMSerr(&str, err);
222 mm->totalEMSpages=totalEMSpages;
223 mm->freeEMSpages=freeEMSpages;
224 mm->EMSpageframe=EMSpageframe;
225 mm->EMSpagesmapped=EMSpagesmapped;
226 mm->EMShandle=EMShandle;
233 ======================
237 =======================
240 void MML_ShutdownEMS(mminfo_t *mm)
242 boolean errorflag=false;
243 unsigned EMShandle=mm->EMShandle;
257 if(errorflag==true) printf("MML_ShutdownEMS: Error freeing EMS!\n"); //++++ add something
265 = Maps the 64k of EMS used by memory manager into the page frame
266 = for general use. This only needs to be called if you are keeping
267 = other things in EMS.
272 byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi)
277 boolean errorflag=false;
279 EMShandle=mm->EMShandle;
281 for (i=0;i<4/*MAPPAGES*/;i++)
286 mov bx,[i] // logical page
287 mov al,bl // physical page
288 mov dx,[EMShandle] // handle
300 //err = CPURegs.h.ah;
301 strcpy(str,"MM_MapEMS: EMS error ");
305 //printf("FACK! %x\n", err);
309 mmi->EMSmem = (i)*0x4000lu;
313 byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
315 //SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)
317 //Maps up to 4 logical EMS pages to physical pages in the page frame, where:
318 //PhysicalStart = Physical page first logical page is mapped to
319 //LogicalStart = First logical page to map
320 //NumPages = Number of pages to map (1 to 4)
321 //Handle = EMS handle logical pages are allocated to
323 /*//Create a buffer containing the page information
324 // FOR x = 0 TO NumPages - 1
325 // MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x)
328 // Regs.ax = 0x5000 //Map the pages in the buffer
329 // Regs.cx = NumPages //to the pageframe
331 // Regs.ds = VARSEG(MapInfo$)
332 // Regs.si = SADD(MapInfo$)
333 // InterruptX 0x67, Regs, Regs
334 // EMS.Error = (Regs.ax AND 0xFF00&) \ 0x100 //Store the status code
340 boolean errorflag=false;
342 EMShandle=mm->EMShandle;
347 for (i=0;i<MAPPAGES;i++)
352 mov cx,[i] // logical page
353 mov al,bl // physical page
354 mov dx,[EMShandle] // handle
366 //err = CPURegs.h.ah;
367 //strcpy(str,"MM_MapXEMS: EMS error 0x");
368 strcpy(str,"MM_MapXEMS: EMS error ");
370 MM_EMSerr(&str, err);
372 //printf("%s%x\n",str, err);
373 //printf("FACK! %x\n", err);
377 mmi->EMSmem = (i)*0x4000lu;
381 //==========================================================================
384 ======================
388 = Check for XMM driver
390 =======================
393 boolean MML_CheckForXMS(mminfo_t *mm)
395 boolean errorflag=false;
401 int 0x2f // query status of installed diver
407 if(errorflag==true) return false;
413 ======================
417 = Try to allocate all upper memory block
419 =======================
422 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
431 mov [WORD PTR XMSaddr],bx
432 mov [WORD PTR XMSaddr+2],es // function pointer to XMS driver
435 mov dx,0xffff // try for largest block possible
436 //mov ax,dx // Set available Kbytes.
437 call [DWORD PTR XMSaddr]
441 cmp bl,0xb0 // error: smaller UMB is available
445 call [DWORD PTR XMSaddr] // DX holds largest available UMB
447 jz done // another error...
454 printf("base=%u ", base); printf("size=%u\n", size);
455 MML_UseSpace(base,size, mm);
456 mmi->XMSmem += size*16;
457 mm->UMBbase[mm->numUMBs] = base;
459 if(mm->numUMBs < MAXUMBS)
465 ======================
469 ======================
472 void MML_ShutdownXMS(mminfo_t *mm)
477 for (i=0;i<mm->numUMBs;i++)
479 base = mm->UMBbase[i];
484 call [DWORD PTR XMSaddr]
489 //==========================================================================
492 ======================
496 = Marks a range of paragraphs as usable by the memory manager
497 = This is used to mark space for the near heap, far heap, ems page frame,
498 = and upper memory blocks
500 ======================
503 void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm)
505 mmblocktype huge *scan,huge *last;
510 scan = last = mm->mmhead;
511 mm->mmrover = mm->mmhead; // reset rover to start of memory
514 // search for the block that contains the range of segments
516 while(scan->start+scan->length < segstart)
522 //find out how many blocks it spans!
523 if(seglength>0xffffu)
525 // segm=seglength/0x4000u;
526 segm=seglength/0xffffu;
531 if(segm>1/*extra>0xfffflu*/)
542 //MML_UseSpace(?segstart?, ?length?, mm);
548 //printf("MML_UseSpace: Segment spans two blocks!\n");
552 // take the given range out of the block
554 oldend = scan->start + scan->length;
555 extra = oldend - (segstart+seglength);
557 printf("segm=%u ", segm);
558 printf("ex=%lu ", extra);
559 printf("start+seglen=%lu ", segstart+seglength);
560 printf("len=%u ", scan->length);
561 printf("segsta=%x ", segstart);
562 printf("seglen=%lu\n", seglength);
565 //++++todo: linked list of segment!
566 //printf("segm=%lu\n", segm);
567 if(segstart == scan->start)
569 last->next = scan->next; // unlink block
570 MM_FreeBlock(scan, mm);
574 scan->length = segstart-scan->start; // shorten block
581 mm->mmnew->next = scan->next;
582 scan->next = mm->mmnew;
583 mm->mmnew->start = segstart+seglength;
584 mm->mmnew->length = extra;
585 mm->mmnew->attributes = LOCKBIT;
586 }//else if(segm>0) goto segu;
590 //==========================================================================
597 = We are out of blocks, so free a purgable block
602 void MML_ClearBlock(mminfo_t *mm)
604 mmblocktype huge *scan,huge *last;
606 scan = mm->mmhead->next;
610 if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS))
612 MM_FreePtr(scan->useptr, mm);
618 printf("MM_ClearBlock: No purgable blocks!\n");
622 //==========================================================================
629 = Grabs all space from turbo with malloc/farmalloc
630 = Allocates bufferseg misc buffer
635 void MM_Startup(mminfo_t *mm, mminfotype *mmi)
638 dword length,seglength;
639 //dword length; word seglength;
641 word segstart;//,endfree;
646 mm->mmstarted = true;
647 mm->bombonerror = true;
650 // set up the linked list (everything in the free list;
652 //printf(" linked list making!\n");
654 mm->mmfree = &(mm->mmblocks[0]);
655 for(i=0;i<MAXBLOCKS-1;i++)
657 mm->mmblocks[i].next = &(mm->mmblocks[i+1]);
659 mm->mmblocks[i].next = NULL;
662 // locked block of all memory until we punch out free space
664 //printf(" newblock making!\n");
666 mm->mmhead = mm->mmnew; // this will allways be the first node
667 mm->mmnew->start = 0;
668 mm->mmnew->length = 0xffff;
669 mm->mmnew->attributes = LOCKBIT;
670 mm->mmnew->next = NULL;
671 mm->mmrover = mm->mmhead;
674 // get all available near conventional memory segments
676 //---- length=coreleft();
677 printf(" nearheap making!\n");
679 length=_memmax();//(dword)GetFreeSize();
680 start = (void huge *)(mm->nearheap = malloc(length));
681 length -= 16-(FP_OFF(start)&15);
682 length -= SAVENEARHEAP;
683 seglength = length / 16; // now in paragraphs
684 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
685 MML_UseSpace(segstart,seglength, mm);
686 mmi->nearheap = length;
687 printf("start=%FP segstart=%X seglen=%lu len=%lu\n", start, segstart, seglength, length);
688 printf(" near heap ok!\n");
691 // get all available far conventional memory segments
693 //---- length=farcoreleft();
694 printf(" farheap making!\n");
696 length=(dword)GetFarFreeSize();//0xffffUL*4UL;
697 //start = mm->farheap = halloc(length, 1);
698 start = mm->farheap = _fmalloc(length);
699 length -= 16-(FP_OFF(start)&15);
700 length -= SAVEFARHEAP;
701 seglength = length / 16; // now in paragraphs
702 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
703 MML_UseSpace(segstart,seglength, mm);
704 mmi->farheap = length;
705 printf("start=%FP segstart=%X seglen=%lu len=%lu\n", start, segstart, seglength, length);
706 printf(" far heap ok!\n");
708 mmi->mainmem = mmi->nearheap + mmi->farheap;
713 // detect EMS and allocate up to 64K at page frame
716 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!
718 for(i = 1;i < __argc;i++)
720 if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
721 goto emsskip; // param NOEMS
723 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!
724 if(MML_CheckForEMS())
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!
728 MML_SetupEMS(mm); // allocate space
730 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!
731 //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
732 MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
733 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(mm->EMSVer<0x40)
736 MM_MapEMS(mm, mmi); // map in used pages
738 //MM_MapXEMS(mm, mmi); // map in used pages
742 // detect XMS and get upper memory blocks
746 for(i = 1;i < __argc;i++)
748 if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
749 goto xmsskip; // param NOXMS
751 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!
752 if(MML_CheckForXMS(mm))
754 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 MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible
760 // allocate the misc buffer
763 mm->mmrover = mm->mmhead; // start looking for space after low block
765 MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi);
768 //==========================================================================
775 = Frees all conventional, EMS, and XMS allocated
780 void MM_Shutdown(mminfo_t *mm)
785 _ffree(mm->farheap); printf(" far freed\n");
786 free(mm->nearheap); printf(" near freed\n");
787 if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); printf(" EMS freed\n"); }
788 if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); printf(" XMS freed\n"); }
791 //==========================================================================
798 = Allocates an unlocked, unpurgable block
803 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi)
805 mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
807 unsigned needed,startseg;
809 needed = (size+15)/16; // convert size from bytes to paragraphs
811 MM_GetNewBlock(mm); // fill in start and next after a spot is found
812 mm->mmnew->length = needed;
813 mm->mmnew->useptr = baseptr;
814 mm->mmnew->attributes = BASEATTRIBUTES;
816 for(search = 0; search<3; search++)
819 // first search: try to allocate right after the rover, then on up
820 // second search: search from the head pointer up to the rover
821 // third search: compress memory, then scan from start
822 if(search == 1 && mm->mmrover == mm->mmhead)
828 lastscan = mm->mmrover;
829 scan = mm->mmrover->next;
833 lastscan = mm->mmhead;
834 scan = mm->mmhead->next;
835 endscan = mm->mmrover;
839 lastscan = mm->mmhead;
840 scan = mm->mmhead->next;
845 startseg = lastscan->start + lastscan->length;
847 while(scan != endscan)
849 if(scan->start - startseg >= needed)
852 // got enough space between the end of lastscan and
853 // the start of scan, so throw out anything in the middle
854 // and allocate the new block
856 purge = lastscan->next;
857 lastscan->next = mm->mmnew;
858 mm->mmnew->start = *(unsigned *)baseptr = startseg;
859 mm->mmnew->next = scan;
861 { // free the purgable block
863 MM_FreeBlock(purge, mm);
864 purge = next; // purge another if not at scan
866 mm->mmrover = mm->mmnew;
867 return; // good allocation!
871 // if this block is purge level zero or locked, skip past it
873 if((scan->attributes & LOCKBIT)
874 || !(scan->attributes & PURGEBITS) )
877 startseg = lastscan->start + lastscan->length;
881 scan=scan->next; // look at next line
887 printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
894 //==========================================================================
901 = Allocates an unlocked, unpurgable block
906 void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
908 mmblocktype huge *scan,huge *last;
913 if(baseptr == mm->mmrover->useptr) // removed the last allocated block
914 mm->mmrover = mm->mmhead;
916 while(scan->useptr != baseptr && scan)
924 printf("MM_FreePtr: Block not found!\n");
928 last->next = scan->next;
930 MM_FreeBlock(scan, mm);
932 //==========================================================================
935 =====================
939 = Sets the purge level for a block (locked blocks cannot be made purgable)
941 =====================
944 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
946 mmblocktype huge *start;
952 if(mm->mmrover->useptr == baseptr)
955 mm->mmrover = mm->mmrover->next;
958 mm->mmrover = mm->mmhead;
959 else if(mm->mmrover == start)
961 printf("MM_SetPurge: Block not found!");
967 mm->mmrover->attributes &= ~PURGEBITS;
968 mm->mmrover->attributes |= purge;
971 //==========================================================================
974 =====================
978 = Locks / unlocks the block
980 =====================
983 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
985 mmblocktype huge *start;
991 if(mm->mmrover->useptr == baseptr)
994 mm->mmrover = mm->mmrover->next;
997 mm->mmrover = mm->mmhead;
998 else if(mm->mmrover == start)
1000 printf("MM_SetLock: Block not found!");
1006 mm->mmrover->attributes &= ~LOCKBIT;
1007 mm->mmrover->attributes |= locked*LOCKBIT;
1010 //==========================================================================
1013 =====================
1017 = Throws out all purgable stuff and compresses movable blocks
1019 =====================
1022 void MM_SortMem(mminfo_t *mm)
1024 mmblocktype huge *scan,huge *last,huge *next;
1025 unsigned start,length,source,dest,oldborder;
1029 // lock down a currently playing sound
1031 /*++++ playing = SD_SoundPlaying ();
1037 playing += STARTPCSOUNDS;
1040 playing += STARTADLIBSOUNDS;
1043 MM_SetLock(&(memptr)audiosegs[playing],true);
1048 // oldborder = bordercolor;
1049 // VW_ColorBorder (15);
1056 last = NULL; // shut up compiler warning
1060 if(scan->attributes & LOCKBIT)
1063 // block is locked, so try to pile later blocks right after it
1065 start = scan->start + scan->length;
1069 if(scan->attributes & PURGEBITS)
1072 // throw out the purgable block
1075 MM_FreeBlock(scan, mm);
1083 // push the non purgable block on top of the last moved block
1085 if(scan->start != start)
1087 length = scan->length;
1088 source = scan->start;
1090 while(length > 0xf00)
1092 movedata(source,0,dest,0,0xf00*16);
1097 movedata(source,0,dest,0,length*16);
1099 scan->start = start;
1100 *(unsigned *)scan->useptr = start;
1102 start = scan->start + scan->length;
1107 scan = scan->next; // go to next block
1110 mm->mmrover = mm->mmhead;
1115 // VW_ColorBorder (oldborder);
1118 MM_SetLock(&(memptr)audiosegs[playing],false);*/
1122 //==========================================================================
1126 =====================
1130 =====================
1133 void MM_ShowMemory(/*page_t *page, */mminfo_t *mm)
1135 mmblocktype huge *scan;
1139 byte scratch[160],str[16];
1141 //**** VW_SetDefaultColors();
1142 //**** VW_SetLineWidth(40);
1143 //++++mh temp = bufferofs;
1144 //++++mh bufferofs = 0;
1145 //**** VW_SetScreen (0,0);
1158 if(scan->attributes & PURGEBITS)
1159 color = 5; // dark purple = purgable
1161 color = 9; // medium blue = non purgable
1162 if(scan->attributes & LOCKBIT)
1163 color = 12; // red = locked
1164 if(scan->start<=end)
1167 write(debughandle,"\nMM_ShowMemory: Memory block order currupted!\n",strlen("\nMM_ShowMemory: Memory block order currupted!\n"));
1168 //modexprint(&page, chx, chy, 1, 0, 24, "\nMM_ShowMemory: Memory block order currupted!\n");
1171 end = scan->start+scan->length-1;
1172 chy = scan->start/320;
1173 chx = scan->start%320;
1174 //modexhlin(page, scan->start, (unsigned)end, chy, color);
1175 //for(chx=scan->start;chx+4>=(word)end;chx+=4)
1177 //++++ modexClearRegion(page, chx, chy, 4, 4, color);
1180 //++++ VW_Hlin(scan->start,(unsigned)end,0,color);
1182 //++++ VW_Plot(scan->start,0,15);
1183 //++++ modexClearRegion(page, chx, chy, 4, 4, 15);
1184 if(scan->next->start > end+1)
1185 //++++ VW_Hlin(end+1,scan->next->start,0,0); // black = free
1186 //for(chx=scan->next->start;chx+4>=(word)end+1;chx+=4)
1188 //++++ chx+=scan->next->start;
1189 //++++ modexClearRegion(page, chx, chy, 4, 4, 2);
1191 //modexhlin(page, end+1,scan->next->start, chy, 0);
1194 end = scan->length-1;
1195 y = scan->start/320;
1196 x = scan->start%320;
1197 VW_Hlin(x,x+end,y,color);
1199 if (scan->next && scan->next->start > end+1)
1200 VW_Hlin(x+end+1,x+(scan->next->start-scan->start),y,0); // black = free
1204 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!
1205 strcpy(scratch,"Seg:");
1206 ultoa (scan->start,str,16);
1207 strcat (scratch,str);
1208 strcat (scratch,"\tSize:");
1209 ultoa ((dword)scan->length,str,10);
1210 strcat (scratch,str);
1211 strcat (scratch,"\tOwner:0x");
1212 owner = (unsigned)scan->useptr;
1213 ultoa (owner,str,16);
1214 strcat (scratch,str);
1215 strcat (scratch,"\n");
1216 write(debughandle,scratch,strlen(scratch));
1217 //modexprint(page, chx, chy, 1, 0, 24, &scratch);
1219 //fprintf(stdout, "%s", scratch);
1228 //**** VW_SetLineWidth(64);
1229 //++++mh bufferofs = temp;
1233 //==========================================================================
1236 =====================
1240 =====================
1243 void MM_DumpData(mminfo_t *mm)
1245 mmblocktype far *scan,far *best;
1246 long lowest,oldlowest;
1252 //++++free(mm->nearheap);
1253 dumpfile = fopen ("mmdump.16","w");
1255 printf("MM_DumpData: Couldn't open MMDUMP.16!\n");
1268 owner = (word)scan->useptr;
1270 if (owner && owner<lowest && owner > oldlowest)
1279 if (lowest != 0xffff)
1281 if (best->attributes & PURGEBITS)
1285 if (best->attributes & LOCKBIT)
1289 fprintf (dumpfile,"0x%p (%c%c) = %u\n"
1290 ,(word)lowest,lock,purge,best->length);
1293 } while (lowest != 0xffff);
1296 printf("MMDUMP.16 created.\n");
1299 //==========================================================================
1303 ======================
1307 = Returns the total free space without purging
1309 ======================
1312 dword MM_UnusedMemory(mminfo_t *mm)
1315 mmblocktype huge *scan;
1322 free += scan->next->start - (scan->start + scan->length);
1330 //==========================================================================
1334 ======================
1338 = Returns the total free space with purging
1340 ======================
1343 dword MM_TotalFree(mminfo_t *mm)
1346 mmblocktype huge *scan;
1353 if((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
1354 free += scan->length;
1355 free += scan->next->start - (scan->start + scan->length);
1363 //==========================================================================
1366 =====================
1370 =====================
1373 void MM_Report(/*page_t *page, */mminfo_t *mm, mminfotype *mmi)
1375 if(MML_CheckForEMS())
1377 printf("EMM v%x.%x available\n", mm->EMSVer>>4,mm->EMSVer&0x0F);
1378 printf("totalEMSpages=%u\n", mm->totalEMSpages);
1379 printf("freeEMSpages=%u\n", mm->freeEMSpages);
1380 printf("EMSpageframe=%x\n", mm->EMSpageframe);
1382 if(MML_CheckForXMS(mm)) printf("XMSaddr=%X\n", *XMSaddr);
1383 printf("near=%lu\n", mmi->nearheap);
1384 printf("far=%lu\n", mmi->farheap);
1385 printf("EMSmem=%lu\n", mmi->EMSmem);
1386 printf("XMSmem=%lu\n", mmi->XMSmem);
1387 printf("mainmem=%lu\n", mmi->mainmem);
1388 printf("UnusedMemory=%lu\n", MM_UnusedMemory(mm));
1389 printf("TotalFree=%lu\n", MM_TotalFree(mm));
1390 //mmi->nearheap+mmi->farheap+
1391 printf("TotalUsed=%lu\n", mmi->mainmem+mmi->EMSmem+mmi->XMSmem);//+);
1393 // printf("UnusedMemory=%lu kb\n", MM_UnusedMemory()/10248);
1394 // printf("TotalFree=%lu kb\n", MM_TotalFree()/10248);
1397 //==========================================================================
1400 =====================
1404 =====================
1407 void MM_EMSerr(byte *stri, byte err)
1409 //Returns a text string describing the error code in EMS.Error.
1413 strcat(stri, "successful");
1416 strcat(stri, "internal error");
1419 strcat(stri, "hardware malfunction");
1422 strcat(stri, "busy .. retry later");
1425 strcat(stri, "invalid handle");
1428 strcat(stri, "undefined function requested by application");
1431 strcat(stri, "no more handles available");
1434 strcat(stri, "error in save or restore of mapping context");
1437 strcat(stri, "insufficient memory pages in system");
1440 strcat(stri, "insufficient memory pages available");
1443 strcat(stri, "zero pages requested");
1446 strcat(stri, "invalid logical page number encountered");
1449 strcat(stri, "invalid physical page number encountered");
1452 strcat(stri, "page-mapping hardware state save area is full");
1455 strcat(stri, "save of mapping context failed");
1458 strcat(stri, "restore of mapping context failed");
1461 strcat(stri, "undefined subfunction");
1464 strcat(stri, "undefined attribute type");
1467 strcat(stri, "feature not supported");
1470 strcat(stri, "successful, but a portion of the source region has been overwritten");
1473 strcat(stri, "length of source or destination region exceeds length of region allocated to either source or destination handle");
1476 strcat(stri, "conventional and expanded memory regions overlap");
1479 strcat(stri, "offset within logical page exceeds size of logical page");
1482 strcat(stri, "region length exceeds 1 MB");
1485 strcat(stri, "source and destination EMS regions have same handle and overlap");
1488 strcat(stri, "memory source or destination type undefined");
1491 strcat(stri, "specified alternate map register or DMA register set not supported");
1494 strcat(stri, "all alternate map register or DMA register sets currently allocated");
1497 strcat(stri, "alternate map register or DMA register sets not supported");
1500 strcat(stri, "undefined or unallocated alternate map register or DMA register set");
1503 strcat(stri, "dedicated DMA channels not supported");
1506 strcat(stri, "specified dedicated DMA channel not supported");
1509 strcat(stri, "no such handle name");
1512 strcat(stri, "a handle found had no name, or duplicate handle name");
1515 strcat(stri, "attempted to wrap around 1M conventional address space");
1518 strcat(stri, "source array corrupted");
1521 strcat(stri, "operating system denied access");
1524 strcat(stri, "undefined error");
1528 //==========================================================================
1531 =====================
1535 =====================
1538 void MM_BombOnError(boolean bomb, mminfo_t *mm)
1540 mm->bombonerror = bomb;
1543 void MM_GetNewBlock(mminfo_t *mm)
1547 mm->mmnew=mm->mmfree;
1548 mm->mmfree=mm->mmfree->next;
1549 /*if(!(mm->mmnew=mm->mmfree))
1551 printf("MM_GETNEWBLOCK: No free blocks!");
1554 mm->mmfree=mm->mmfree->next;*/
1557 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
1564 void MM_seguin(void)
1575 void MM_segude(void)
1584 pull data from far and put it into ds var