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"
52 =============================================================================
56 =============================================================================
59 void (* beforesort) (void);
60 void (* aftersort) (void);
61 void (* XMSaddr) (void); // far pointer to XMS driver
64 =============================================================================
68 =============================================================================
71 static char *ParmStringsexmm[] = {"noems","noxms",""};
74 ======================
78 = Routine from p36 of Extending DOS
80 =======================
83 boolean MML_CheckForEMS(void)
86 static char emmname[] = "EMMXXXX0"; //fix by andrius4669
87 // mov dx,OFFSET emmname
89 //LEA DX, emmname //fix by andrius4669
90 mov dx,OFFSET emmname //fix by andrius4669
92 int 0x21 // try to open EMMXXXX0 device
98 int 0x21 // get device info
106 int 0x21 // get status
112 int 0x21 // close handle
131 ======================
135 =======================
138 byte MML_SetupEMS(mminfo_t *mm)
142 boolean errorflag=false;
144 unsigned int EMSVer = 0;
146 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
147 totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
152 int EMS_INT // make sure EMS hardware is present
154 //mov [EMS_status],ah
161 mov [EMSVer],ax // set EMSVer
162 cmp al,0x32 // only work on ems 3.2 or greater
166 int EMS_INT // find the page frame address
169 mov [EMSpageframe],bx
172 int EMS_INT // find out how much EMS is there
175 mov [totalEMSpages],dx
176 mov [freeEMSpages],bx
178 jz noEMS // no EMS at all to allocate
182 cmp bx,[freeEMSpages]
184 mov bx,[freeEMSpages]
189 jle getpages // there is only 1,2,3,or 4 pages
190 mov bx,4 // we can't use more than 4 pages
193 mov [EMSpagesmapped],bx
194 mov ah,EMS_ALLOCPAGES // allocate up to 64k of EMS
209 //err = CPURegs.h.ah;
210 strcpy(str,"MM_SetupEMS: EMS error ");
212 MM_EMSerr(&str, err);
216 mm->totalEMSpages=totalEMSpages;
217 mm->freeEMSpages=freeEMSpages;
218 mm->EMSpageframe=EMSpageframe;
219 mm->EMSpagesmapped=EMSpagesmapped;
220 mm->EMShandle=EMShandle;
227 ======================
231 =======================
234 void MML_ShutdownEMS(mminfo_t *mm)
236 boolean errorflag=false;
237 unsigned EMShandle=mm->EMShandle;
251 if(errorflag==true) printf("MML_ShutdownEMS: Error freeing EMS!\n"); //++++ add something
259 = Maps the 64k of EMS used by memory manager into the page frame
260 = for general use. This only needs to be called if you are keeping
261 = other things in EMS.
266 byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi)
271 boolean errorflag=false;
273 EMShandle=mm->EMShandle;
275 for (i=0;i<4/*MAPPAGES*/;i++)
280 mov bx,[i] // logical page
281 mov al,bl // physical page
282 mov dx,[EMShandle] // handle
294 //err = CPURegs.h.ah;
295 strcpy(str,"MM_MapEMS: EMS error ");
299 //printf("FACK! %x\n", err);
303 mmi->EMSmem = (i)*0x4000lu;
307 byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
310 //SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)
312 //Maps up to 4 logical EMS pages to physical pages in the page frame, where:
313 //PhysicalStart = Physical page first logical page is mapped to
314 //LogicalStart = First logical page to map
315 //NumPages = Number of pages to map (1 to 4)
316 //Handle = EMS handle logical pages are allocated to
318 /*//Create a buffer containing the page information
319 // FOR x = 0 TO NumPages - 1
320 // MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x)
323 // Regs.ax = 0x5000 //Map the pages in the buffer
324 // Regs.cx = NumPages //to the pageframe
326 // Regs.ds = VARSEG(MapInfo$)
327 // Regs.si = SADD(MapInfo$)
328 // InterruptX 0x67, Regs, Regs
329 // EMS.Error = (Regs.ax AND 0xFF00&) \ 0x100 //Store the status code
335 boolean errorflag=false;
337 EMShandle=mm->EMShandle;
342 for (i=0;i<MAPPAGES;i++)
347 mov cx,[i] // logical page
348 mov al,bl // physical page
349 mov dx,[EMShandle] // handle
361 //err = CPURegs.h.ah;
362 //strcpy(str,"MM_MapXEMS: EMS error 0x");
363 strcpy(str,"MM_MapXEMS: EMS error ");
365 MM_EMSerr(&str, err);
367 //printf("%s%x\n",str, err);
368 //printf("FACK! %x\n", err);
372 mmi->EMSmem = (i)*0x4000lu;
376 //==========================================================================
379 ======================
383 = Check for XMM driver
385 =======================
388 boolean MML_CheckForXMS(mminfo_t *mm)
390 boolean errorflag=false;
396 int 0x2f // query status of installed diver
402 if(errorflag==true) return false;
408 ======================
412 = Try to allocate all upper memory block
414 =======================
417 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
426 mov [WORD PTR XMSaddr],bx
427 mov [WORD PTR XMSaddr+2],es // function pointer to XMS driver
430 mov dx,0xffff // try for largest block possible
431 //mov ax,dx // Set available Kbytes.
432 call [DWORD PTR XMSaddr]
436 cmp bl,0xb0 // error: smaller UMB is available
440 call [DWORD PTR XMSaddr] // DX holds largest available UMB
442 jz done // another error...
449 printf("base=%u ", base); printf("size=%u\n", size);
450 MML_UseSpace(base,size, mm);
451 mmi->XMSmem += size*16;
452 mm->UMBbase[mm->numUMBs] = base;
454 if(mm->numUMBs < MAXUMBS)
460 ======================
464 ======================
467 void MML_ShutdownXMS(mminfo_t *mm)
472 for (i=0;i<mm->numUMBs;i++)
474 base = mm->UMBbase[i];
479 call [DWORD PTR XMSaddr]
484 //==========================================================================
487 ======================
491 = Marks a range of paragraphs as usable by the memory manager
492 = This is used to mark space for the near heap, far heap, ems page frame,
493 = and upper memory blocks
495 ======================
498 void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm)
500 mmblocktype huge *scan,huge *last;
505 scan = last = mm->mmhead;
506 mm->mmrover = mm->mmhead; // reset rover to start of memory
509 // search for the block that contains the range of segments
511 while(scan->start+scan->length < segstart)
517 //find out how many blocks it spans!
518 if(seglength>0xffffu)
520 // segm=seglength/0x4000u;
521 segm=seglength/0xffffu;
526 if(segm>1/*extra>0xfffflu*/)
537 //MML_UseSpace(?segstart?, ?length?, mm);
543 //printf("MML_UseSpace: Segment spans two blocks!\n");
547 // take the given range out of the block
549 oldend = scan->start + scan->length;
550 extra = oldend - (segstart+seglength);
552 printf("segm=%u ", segm);
553 printf("ex=%lu ", extra);
554 printf("start+seglen=%lu ", segstart+seglength);
555 printf("len=%u ", scan->length);
556 printf("segsta=%x ", segstart);
557 printf("seglen=%lu\n", seglength);
560 //++++todo: linked list of segment!
561 //printf("segm=%lu\n", segm);
562 if(segstart == scan->start)
564 last->next = scan->next; // unlink block
565 MM_FreeBlock(scan, mm);
569 scan->length = segstart-scan->start; // shorten block
576 mm->mmnew->next = scan->next;
577 scan->next = mm->mmnew;
578 mm->mmnew->start = segstart+seglength;
579 mm->mmnew->length = extra;
580 mm->mmnew->attributes = LOCKBIT;
581 }//else if(segm>0) goto segu;
585 //==========================================================================
592 = We are out of blocks, so free a purgable block
597 void MML_ClearBlock(mminfo_t *mm)
599 mmblocktype huge *scan,huge *last;
601 scan = mm->mmhead->next;
605 if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS))
607 MM_FreePtr(scan->useptr, mm);
613 printf("MM_ClearBlock: No purgable blocks!\n");
617 //==========================================================================
624 = Grabs all space from turbo with malloc/farmalloc
625 = Allocates bufferseg misc buffer
630 void MM_Startup(mminfo_t *mm, mminfotype *mmi)
635 unsigned segstart,seglength,endfree;
640 mm->mmstarted = true;
641 mm->bombonerror = true;
643 // set up the linked list (everything in the free list;
645 printf(" linked list making!\n");
647 mm->mmfree = &(mm->mmblocks[0]);
648 for(i=0;i<MAXBLOCKS-1;i++)
650 mm->mmblocks[i].next = &(mm->mmblocks[i+1]);
652 mm->mmblocks[i].next = NULL;
655 // locked block of all memory until we punch out free space
657 printf(" newblock making!\n");
659 mm->mmhead = mm->mmnew; // this will allways be the first node
660 mm->mmnew->start = 0;
661 mm->mmnew->length = 0xffff;
662 mm->mmnew->attributes = LOCKBIT;
663 mm->mmnew->next = NULL;
664 mm->mmrover = mm->mmhead;
666 // farlen=_bios_memsize()*1024;
669 // get all available near conventional memory segments
671 printf(" nearheap making!\n");
672 //---- length=coreleft();
675 start = (void huge *)(mm->nearheap = malloc(length));
676 length -= 16-(FP_OFF(start)&15);
677 length -= SAVENEARHEAP;
678 seglength = length / 16; // now in paragraphs
679 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
680 MML_UseSpace(segstart,seglength, mm);
681 mmi->nearheap = length;
682 printf(" near heap ok!\n");
685 // get all available far conventional memory segments
687 //---- length=farcoreleft();
688 printf(" farheap making!\n");
691 start = mm->farheap = halloc(length, sizeof(byte));
692 //start = mm->farheap = _fmalloc(length);
693 length -= 16-(FP_OFF(start)&15);
694 length -= SAVEFARHEAP;
695 seglength = length / 16; // now in paragraphs
696 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
697 MML_UseSpace(segstart,seglength, mm);
698 mmi->farheap = length;
699 mmi->mainmem = mmi->nearheap + mmi->farheap;
700 printf(" far heap ok!\n");
704 // detect EMS and allocate up to 64K at page frame
706 printf(" EMS1\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!
708 for(i = 1;i < __argc;i++)
710 if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
711 goto emsskip; // param NOEMS
713 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!
714 if(MML_CheckForEMS())
717 MML_SetupEMS(mm); // allocate space
719 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!
720 //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
721 MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
724 MM_MapEMS(mm, mmi); // map in used pages
726 MM_MapXEMS(mm, mmi); // map in used pages
730 // detect XMS and get upper memory blocks
734 for(i = 1;i < __argc;i++)
736 if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
737 goto xmsskip; // param NOXMS
739 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!
740 if(MML_CheckForXMS(mm))
743 //MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible
747 // allocate the misc buffer
750 mm->mmrover = mm->mmhead; // start looking for space after low block
752 MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi);
755 //==========================================================================
762 = Frees all conventional, EMS, and XMS allocated
767 void MM_Shutdown(mminfo_t *mm)
773 printf(" far freed\n");
775 printf(" near freed\n");
776 //hfree(mm->hugeheap);
777 //printf("huge freed\n");
778 if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); printf(" EMS freed\n"); }
779 if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); printf(" XMS freed\n"); }
782 //==========================================================================
789 = Allocates an unlocked, unpurgable block
794 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi)
796 mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
798 unsigned needed,startseg;
800 needed = (size+15)/16; // convert size from bytes to paragraphs
802 MM_GetNewBlock(mm); // fill in start and next after a spot is found
803 mm->mmnew->length = needed;
804 mm->mmnew->useptr = baseptr;
805 mm->mmnew->attributes = BASEATTRIBUTES;
807 for(search = 0; search<3; search++)
810 // first search: try to allocate right after the rover, then on up
811 // second search: search from the head pointer up to the rover
812 // third search: compress memory, then scan from start
813 if(search == 1 && mm->mmrover == mm->mmhead)
819 lastscan = mm->mmrover;
820 scan = mm->mmrover->next;
824 lastscan = mm->mmhead;
825 scan = mm->mmhead->next;
826 endscan = mm->mmrover;
830 lastscan = mm->mmhead;
831 scan = mm->mmhead->next;
836 startseg = lastscan->start + lastscan->length;
838 while(scan != endscan)
840 if(scan->start - startseg >= needed)
843 // got enough space between the end of lastscan and
844 // the start of scan, so throw out anything in the middle
845 // and allocate the new block
847 purge = lastscan->next;
848 lastscan->next = mm->mmnew;
849 mm->mmnew->start = *(unsigned *)baseptr = startseg;
850 mm->mmnew->next = scan;
852 { // free the purgable block
854 MM_FreeBlock(purge, mm);
855 purge = next; // purge another if not at scan
857 mm->mmrover = mm->mmnew;
858 return; // good allocation!
862 // if this block is purge level zero or locked, skip past it
864 if((scan->attributes & LOCKBIT)
865 || !(scan->attributes & PURGEBITS) )
868 startseg = lastscan->start + lastscan->length;
872 scan=scan->next; // look at next line
877 printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
882 //==========================================================================
889 = Allocates an unlocked, unpurgable block
894 void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
896 mmblocktype huge *scan,huge *last;
901 if(baseptr == mm->mmrover->useptr) // removed the last allocated block
902 mm->mmrover = mm->mmhead;
904 while(scan->useptr != baseptr && scan)
912 printf("MM_FreePtr: Block not found!\n");
916 last->next = scan->next;
918 MM_FreeBlock(scan, mm);
920 //==========================================================================
923 =====================
927 = Sets the purge level for a block (locked blocks cannot be made purgable)
929 =====================
932 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
934 mmblocktype huge *start;
940 if(mm->mmrover->useptr == baseptr)
943 mm->mmrover = mm->mmrover->next;
946 mm->mmrover = mm->mmhead;
947 else if(mm->mmrover == start)
949 printf("MM_SetPurge: Block not found!");
955 mm->mmrover->attributes &= ~PURGEBITS;
956 mm->mmrover->attributes |= purge;
959 //==========================================================================
962 =====================
966 = Locks / unlocks the block
968 =====================
971 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
973 mmblocktype huge *start;
979 if(mm->mmrover->useptr == baseptr)
982 mm->mmrover = mm->mmrover->next;
985 mm->mmrover = mm->mmhead;
986 else if(mm->mmrover == start)
988 printf("MM_SetLock: Block not found!");
994 mm->mmrover->attributes &= ~LOCKBIT;
995 mm->mmrover->attributes |= locked*LOCKBIT;
998 //==========================================================================
1001 =====================
1005 = Throws out all purgable stuff and compresses movable blocks
1007 =====================
1010 void MM_SortMem(mminfo_t *mm)
1012 mmblocktype huge *scan,huge *last,huge *next;
1013 unsigned start,length,source,dest,oldborder;
1017 // lock down a currently playing sound
1019 /*++++ playing = SD_SoundPlaying ();
1025 playing += STARTPCSOUNDS;
1028 playing += STARTADLIBSOUNDS;
1031 MM_SetLock(&(memptr)audiosegs[playing],true);
1036 // oldborder = bordercolor;
1037 // VW_ColorBorder (15);
1044 last = NULL; // shut up compiler warning
1048 if(scan->attributes & LOCKBIT)
1051 // block is locked, so try to pile later blocks right after it
1053 start = scan->start + scan->length;
1057 if(scan->attributes & PURGEBITS)
1060 // throw out the purgable block
1063 MM_FreeBlock(scan, mm);
1071 // push the non purgable block on top of the last moved block
1073 if(scan->start != start)
1075 length = scan->length;
1076 source = scan->start;
1078 while(length > 0xf00)
1080 movedata(source,0,dest,0,0xf00*16);
1085 movedata(source,0,dest,0,length*16);
1087 scan->start = start;
1088 *(unsigned *)scan->useptr = start;
1090 start = scan->start + scan->length;
1095 scan = scan->next; // go to next block
1098 mm->mmrover = mm->mmhead;
1103 // VW_ColorBorder (oldborder);
1106 MM_SetLock(&(memptr)audiosegs[playing],false);*/
1110 //==========================================================================
1114 =====================
1118 =====================
1121 void MM_ShowMemory(page_t *page, mminfo_t *mm)
1123 mmblocktype huge *scan;
1127 byte scratch[160],str[16];
1129 //**** VW_SetDefaultColors();
1130 //**** VW_SetLineWidth(40);
1131 //++++mh temp = bufferofs;
1132 //++++mh bufferofs = 0;
1133 //**** VW_SetScreen (0,0);
1146 if(scan->attributes & PURGEBITS)
1147 color = 5; // dark purple = purgable
1149 color = 9; // medium blue = non purgable
1150 if(scan->attributes & LOCKBIT)
1151 color = 12; // red = locked
1152 if(scan->start<=end)
1155 write(debughandle,"\nMM_ShowMemory: Memory block order currupted!\n",strlen("\nMM_ShowMemory: Memory block order currupted!\n"));
1156 //modexprint(&page, chx, chy, 1, 0, 24, "\nMM_ShowMemory: Memory block order currupted!\n");
1159 end = scan->start+scan->length-1;
1160 chy = scan->start/320;
1161 chx = scan->start%320;
1162 //modexhlin(page, scan->start, (unsigned)end, chy, color);
1163 //for(chx=scan->start;chx+4>=(word)end;chx+=4)
1165 modexClearRegion(page, chx, chy, 4, 4, color);
1168 //++++ VW_Hlin(scan->start,(unsigned)end,0,color);
1170 //++++ VW_Plot(scan->start,0,15);
1171 modexClearRegion(page, chx, chy, 4, 4, 15);
1172 if(scan->next->start > end+1)
1173 //++++ VW_Hlin(end+1,scan->next->start,0,0); // black = free
1174 //for(chx=scan->next->start;chx+4>=(word)end+1;chx+=4)
1176 chx+=scan->next->start;
1177 modexClearRegion(page, chx, chy, 4, 4, 2);
1179 //modexhlin(page, end+1,scan->next->start, chy, 0);
1182 end = scan->length-1;
1183 y = scan->start/320;
1184 x = scan->start%320;
1185 VW_Hlin(x,x+end,y,color);
1187 if (scan->next && scan->next->start > end+1)
1188 VW_Hlin(x+end+1,x+(scan->next->start-scan->start),y,0); // black = free
1192 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!
1193 strcpy(scratch,"Seg:");
1194 ultoa (scan->start,str,16);
1195 strcat (scratch,str);
1196 strcat (scratch,"\tSize:");
1197 ltoa ((dword)scan->length*16,str,10);
1198 strcat (scratch,str);
1199 strcat (scratch,"\tOwner:0x");
1200 owner = (unsigned)scan->useptr;
1201 ultoa (owner,str,16);
1202 strcat (scratch,str);
1203 strcat (scratch,"\n");
1204 write(debughandle,scratch,strlen(scratch));
1205 //modexprint(page, chx, chy, 1, 0, 24, &scratch);
1207 //fprintf(stdout, "%s", scratch);
1216 //**** VW_SetLineWidth(64);
1217 //++++mh bufferofs = temp;
1221 //==========================================================================
1224 =====================
1228 =====================
1231 void MM_DumpData(mminfo_t *mm)
1233 mmblocktype far *scan,far *best;
1234 long lowest,oldlowest;
1240 free (mm->nearheap);
1241 dumpfile = fopen ("mmdump.txt","w");
1243 printf("MM_DumpData: Couldn't open MMDUMP.TXT!\n");
1256 owner = (word)scan->useptr;
1258 if (owner && owner<lowest && owner > oldlowest)
1267 if (lowest != 0xffff)
1269 if (best->attributes & PURGEBITS)
1273 if (best->attributes & LOCKBIT)
1277 fprintf (dumpfile,"0x%p (%c%c) = %u\n"
1278 ,(word)lowest,lock,purge,best->length);
1281 } while (lowest != 0xffff);
1284 printf("MMDUMP.TXT created.\n");
1287 //==========================================================================
1291 ======================
1295 = Returns the total free space without purging
1297 ======================
1300 dword MM_UnusedMemory(mminfo_t *mm)
1303 mmblocktype huge *scan;
1310 free += scan->next->start - (scan->start + scan->length);
1318 //==========================================================================
1322 ======================
1326 = Returns the total free space with purging
1328 ======================
1331 dword MM_TotalFree(mminfo_t *mm)
1334 mmblocktype huge *scan;
1341 if((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
1342 free += scan->length;
1343 free += scan->next->start - (scan->start + scan->length);
1351 //==========================================================================
1354 =====================
1358 =====================
1361 void MM_Report(page_t *page, mminfo_t *mm, mminfotype *mmi)
1363 if(MML_CheckForEMS())
1365 printf("EMM v%x.%x available\n", mm->EMSVer>>4,mm->EMSVer&0x0F);
1366 printf("totalEMSpages=%u\n", mm->totalEMSpages);
1367 printf("freeEMSpages=%u\n", mm->freeEMSpages);
1368 printf("EMSpageframe=%x\n", mm->EMSpageframe);
1370 if(MML_CheckForXMS(mm)) printf("XMSaddr=%Fp\n", *XMSaddr);
1371 printf("near=%lu\n", mmi->nearheap);
1372 printf("far=%lu\n", mmi->farheap);
1373 printf("EMSmem=%lu\n", mmi->EMSmem);
1374 printf("XMSmem=%lu\n", mmi->XMSmem);
1375 printf("mainmem=%lu\n", mmi->mainmem);
1376 printf("UnusedMemory=%lu\n", MM_UnusedMemory(mm));
1377 printf("TotalFree=%lu\n", MM_TotalFree(mm));
1379 // printf("UnusedMemory=%lu kb\n", MM_UnusedMemory()/10248);
1380 // printf("TotalFree=%lu kb\n", MM_TotalFree()/10248);
1383 //==========================================================================
1386 =====================
1390 =====================
1393 void MM_EMSerr(byte *stri, byte err)
1395 //Returns a text string describing the error code in EMS.Error.
1396 fprintf(stderr, "\n%x\n\n", err);
1397 fprintf(stderr, "\n%u\n\n", err);
1401 strcat(stri, "successful");
1403 strcat(stri, "internal error");
1405 strcat(stri, "hardware malfunction");
1407 strcat(stri, "busy .. retry later");
1409 strcat(stri, "invalid handle");
1411 strcat(stri, "undefined function requested by application");
1413 strcat(stri, "no more handles available");
1415 strcat(stri, "error in save or restore of mapping context");
1417 strcat(stri, "insufficient memory pages in system");
1419 strcat(stri, "insufficient memory pages available");
1421 strcat(stri, "zero pages requested");
1423 strcat(stri, "invalid logical page number encountered");
1425 strcat(stri, "invalid physical page number encountered");
1427 strcat(stri, "page-mapping hardware state save area is full");
1429 strcat(stri, "save of mapping context failed");
1431 strcat(stri, "restore of mapping context failed");
1433 strcat(stri, "undefined subfunction");
1435 strcat(stri, "undefined attribute type");
1437 strcat(stri, "feature not supported");
1439 strcat(stri, "successful, but a portion of the source region has been overwritten");
1441 strcat(stri, "length of source or destination region exceeds length of region allocated to either source or destination handle");
1443 strcat(stri, "conventional and expanded memory regions overlap");
1445 strcat(stri, "offset within logical page exceeds size of logical page");
1447 strcat(stri, "region length exceeds 1 MB");
1449 strcat(stri, "source and destination EMS regions have same handle and overlap");
1451 strcat(stri, "memory source or destination type undefined");
1453 strcat(stri, "specified alternate map register or DMA register set not supported");
1455 strcat(stri, "all alternate map register or DMA register sets currently allocated");
1457 strcat(stri, "alternate map register or DMA register sets not supported");
1459 strcat(stri, "undefined or unallocated alternate map register or DMA register set");
1461 strcat(stri, "dedicated DMA channels not supported");
1463 strcat(stri, "specified dedicated DMA channel not supported");
1465 strcat(stri, "no such handle name");
1467 strcat(stri, "a handle found had no name, or duplicate handle name");
1469 strcat(stri, "attempted to wrap around 1M conventional address space");
1471 strcat(stri, "source array corrupted");
1473 strcat(stri, "operating system denied access");
1475 strcat(stri, "undefined error");
1479 //==========================================================================
1482 =====================
1486 =====================
1489 void MM_BombOnError(boolean bomb, mminfo_t *mm)
1491 mm->bombonerror = bomb;
1494 void MM_GetNewBlock(mminfo_t *mm)
1498 mm->mmnew=mm->mmfree;
1499 mm->mmfree=mm->mmfree->next;
1500 /*if(!(mm->mmnew=mm->mmfree))
1502 printf("MM_GETNEWBLOCK: No free blocks!");
1505 mm->mmfree=mm->mmfree->next;*/
1508 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
1515 void MM_seguin(void)
1526 void MM_segude(void)
1535 pull data from far and put it into ds var