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 mov dx,OFFSET emmname //fix by andrius4669
95 int 0x21 // try to open EMMXXXX0 device
101 int 0x21 // get device info
109 int 0x21 // get status
115 int 0x21 // close handle
145 ======================
149 =======================
152 byte MML_SetupEMS(mminfo_t *mm)
156 boolean errorflag=false;
158 unsigned int EMSVer = 0;
160 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
161 totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
165 int EMS_INT // make sure EMS hardware is present
167 //mov [EMS_status],ah
174 mov [EMSVer],ax // set EMSVer
175 cmp al,0x32 // only work on ems 3.2 or greater
179 int EMS_INT // find the page frame address
182 mov [EMSpageframe],bx
185 int EMS_INT // find out how much EMS is there
188 mov [totalEMSpages],dx
189 mov [freeEMSpages],bx
191 jz noEMS // no EMS at all to allocate
195 cmp bx,[freeEMSpages]
197 mov bx,[freeEMSpages]
207 jle getpages // there is only 1,2,3,or 4 pages
208 mov bx,4 // we can't use more than 4 pages
216 mov [EMSpagesmapped],bx
217 mov ah,EMS_ALLOCPAGES // allocate up to 64k of EMS
243 strcpy(str,"MM_SetupEMS: EMS error ");
248 mm->totalEMSpages=totalEMSpages;
249 mm->freeEMSpages=freeEMSpages;
250 mm->EMSpageframe=EMSpageframe;
251 mm->EMSpagesmapped=EMSpagesmapped;
252 mm->EMShandle=EMShandle;
259 ======================
263 =======================
266 void MML_ShutdownEMS(mminfo_t *mm)
268 boolean errorflag=false;
269 unsigned EMShandle=mm->EMShandle;
287 if(errorflag==true) printf("MML_ShutdownEMS: Error freeing EMS!\n"); //++++ add something
295 = Maps the 64k of EMS used by memory manager into the page frame
296 = for general use. This only needs to be called if you are keeping
297 = other things in EMS.
302 byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi)
307 boolean errorflag=false;
309 EMShandle=mm->EMShandle;
311 for (i=0;i<4/*MAPPAGES*/;i++)
315 mov bx,[i] // logical page
316 mov al,bl // physical page
317 mov dx,[EMShandle] // handle
340 strcpy(str,"MM_MapEMS: EMS error ");
346 mmi->EMSmem = (i)*0x4000lu;
347 //printf(" mmi->EMSmem=%lu\n", mmi->EMSmem);
351 byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
353 //SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)
355 //Maps up to 4 logical EMS pages to physical pages in the page frame, where:
356 //PhysicalStart = Physical page first logical page is mapped to
357 //LogicalStart = First logical page to map
358 //NumPages = Number of pages to map (1 to 4)
359 //Handle = EMS handle logical pages are allocated to
361 /*//Create a buffer containing the page information
362 // FOR x = 0 TO NumPages - 1
363 // MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x)
366 // Regs.ax = 0x5000 //Map the pages in the buffer
367 // Regs.cx = NumPages //to the pageframe
369 // Regs.ds = VARSEG(MapInfo$)
370 // Regs.si = SADD(MapInfo$)
371 // InterruptX 0x67, Regs, Regs
372 // EMS.Error = (Regs.ax AND 0xFF00&) \ 0x100 //Store the status code
378 boolean errorflag=false;
380 EMShandle=mm->EMShandle;
385 for (i=0;i<MAPPAGES;i++)
389 mov cx,[i] // logical page
390 mov al,bl // physical page
391 mov dx,[EMShandle] // handle
414 //strcpy(str,"MM_MapXEMS: EMS error 0x");
415 strcpy(str,"MM_MapXEMS: EMS error ");
419 //printf("%s%x\n",str, err);
420 //printf("FACK! %x\n", err);
424 mmi->EMSmem = (i)*0x4000lu;
428 //==========================================================================
431 ======================
435 = Check for XMM driver
437 =======================
440 boolean MML_CheckForXMS(mminfo_t *mm)
442 boolean errorflag=false;
447 int 0x2f // query status of installed diver
458 if(errorflag==true) return false;
464 ======================
468 = Try to allocate all upper memory block
470 =======================
473 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
481 mov [WORD PTR XMSaddr],bx
482 mov [WORD PTR XMSaddr+2],es // function pointer to XMS driver
485 mov dx,0xffff // try for largest block possible
486 //mov ax,dx // Set available Kbytes.
487 call [DWORD PTR XMSaddr]
491 cmp bl,0xb0 // error: smaller UMB is available
495 call [DWORD PTR XMSaddr] // DX holds largest available UMB
497 jz done // another error...
514 // printf("base=%u ", base); printf("size=%u\n", size);
515 MML_UseSpace(base,size, mm);
516 mmi->XMSmem += size*16;
517 mm->UMBbase[mm->numUMBs] = base;
519 if(mm->numUMBs < MAXUMBS)
525 ======================
529 ======================
532 void MML_ShutdownXMS(mminfo_t *mm)
537 for (i=0;i<mm->numUMBs;i++)
539 base = mm->UMBbase[i];
543 call [DWORD PTR XMSaddr]
548 //==========================================================================
551 ======================
555 = Marks a range of paragraphs as usable by the memory manager
556 = This is used to mark space for the near heap, far heap, ems page frame,
557 = and upper memory blocks
559 ======================
562 void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
564 mmblocktype huge *scan,huge *last;
567 dword segmlen=seglength;
570 scan = last = mm->mmhead;
571 mm->mmrover = mm->mmhead; // reset rover to start of memory
574 // search for the block that contains the range of segments
576 while(scan->start+scan->length < segstart)
580 //printf(" start=%x",scan->start);
581 //printf(" seglen=%lu\n", scan->length);
584 //find out how many blocks it spans!
586 for(;segmlen>0x10000;segmlen-=0x10000)
588 //printf(" seglen=%lu\n", segmlen);
593 // take the given range out of the block
595 oldend = scan->start + scan->length;
596 extra = oldend - (segstart+(word)seglength);
598 if(segm>1 || extra>=0x10000lu)
611 //MML_UseSpace(segstart, seglength, mm);
617 printf("MML_UseSpace: Segment spans two blocks!\n");
619 printf("========================================\n");
620 printf("segm=%u ", segm);
621 printf("ex=%lu ", extra);
622 printf("old=%u ", oldend);
623 printf("start+seglen=%lu\n", segstart+seglength);
624 printf("segsta=%x ", segstart);
625 printf("len=%lu ", scan->length);
626 printf("seglen=%lu ", seglength);
627 printf("segmlen=%lu\n", segmlen);
628 printf("========================================\n");
630 //++++todo: linked list of segment!
631 if(segstart == scan->start)
633 last->next = scan->next; // unlink block
638 scan->length = segstart-scan->start; // shorten block
643 mm->mmnew->next = scan->next;
644 scan->next = mm->mmnew;
645 mm->mmnew->start = segstart+seglength;
646 mm->mmnew->length = extra;
647 mm->mmnew->attributes = LOCKBIT;
648 }//else if(segm>0) goto segu;
652 //==========================================================================
659 = We are out of blocks, so free a purgable block
664 void MML_ClearBlock(mminfo_t *mm)
666 mmblocktype huge *scan,huge *last;
668 scan = mm->mmhead->next;
672 if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS))
674 MM_FreePtr(scan->useptr, mm);
680 printf("MM_ClearBlock: No purgable blocks!\n");
684 //==========================================================================
691 = Grabs all space from turbo with malloc/farmalloc
692 = Allocates bufferseg misc buffer
697 void MM_Startup(mminfo_t *mm, mminfotype *mmi)
700 dword length,seglength;
701 //dword length; word seglength;
703 word segstart;//,endfree;
708 mm->mmstarted = true;
709 mm->bombonerror = true;
713 // set up the linked list (everything in the free list;
716 mm->mmfree = &(mm->mmblocks[0]);
717 for(i=0;i<MAXBLOCKS-1;i++)
719 mm->mmblocks[i].next = &(mm->mmblocks[i+1]);
721 mm->mmblocks[i].next = NULL;
724 // locked block of all memory until we punch out free space
727 mm->mmhead = mm->mmnew; // this will allways be the first node
728 mm->mmnew->start = 0;
729 mm->mmnew->length = 0xffff;
730 mm->mmnew->attributes = LOCKBIT;
731 mm->mmnew->next = NULL;
732 mm->mmrover = mm->mmhead;
735 // get all available near conventional memory segments
739 length=(dword)_memavl();//(dword)GetFreeSize();
740 start = (void huge *)(mm->nearheap = _nmalloc(length));
744 start = (void huge *)(mm->nearheap = malloc(length));
746 length -= 16-(FP_OFF(start)&15);
747 length -= SAVENEARHEAP;
748 seglength = length / 16; // now in paragraphs
749 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
750 MML_UseSpace(segstart,seglength, mm);
751 mmi->nearheap = length;
752 //printf("start=%Fp segstart=%x seglen=%lu len=%lu\n", start, segstart, seglength, length);
755 // get all available far conventional memory segments
757 //printf("_FARCORELEFT %lu\n", _FCORELEFT);
762 printf("farcoreleft() %lu\n", farcoreleft());
763 printf("(farcoreleft()+32)-_FCORELEFT %d\n", (sword)((farcoreleft()+32)-_FCORELEFT));
765 length=_FCORELEFT;//_fcoreleft();//(dword)GetFarFreeSize();//0xffffUL*4UL;
766 start = mm->farheap = _fmalloc(length);
767 //start = mm->farheap = halloc(length, 1);
768 length -= 16-(FP_OFF(start)&15);
769 length -= SAVEFARHEAP;
770 seglength = length / 16; // now in paragraphs
771 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
772 MML_UseSpace(segstart,seglength, mm);
773 mmi->farheap = length;
774 //printf("start=%Fp segstart=%x seglen=%lu len=%lu\n", start, segstart, seglength, length);
776 mmi->mainmem = mmi->nearheap + mmi->farheap;
779 // detect EMS and allocate up to 64K at page frame
798 ,ParmStringsexmm) == 0)
799 goto emsskip; // param NOEMS
801 if(MML_CheckForEMS())
803 MML_SetupEMS(mm); // allocate space
804 //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
805 MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
806 //if(mm->EMSVer<0x40)
807 MM_MapEMS(mm, mmi); // map in used pages
809 //MM_MapXEMS(mm, mmi); // map in used pages
813 // detect XMS and get upper memory blocks
834 ,ParmStringsexmm) == 0)
835 goto xmsskip; // param NOXMS
837 if(MML_CheckForXMS(mm))
839 MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible
843 // allocate the misc buffer
846 mm->mmrover = mm->mmhead; // start looking for space after low block
848 MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi);
851 //==========================================================================
858 = Frees all conventional, EMS, and XMS allocated
863 void MM_Shutdown(mminfo_t *mm)
868 _ffree(mm->farheap);// printf(" far freed\n");
870 _nfree(mm->nearheap);// printf(" near freed\n");
873 free(mm->nearheap);// printf(" near freed\n");
875 if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); }//printf(" EMS freed\n"); }
876 if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); }//printf(" XMS freed\n"); }
879 //==========================================================================
886 = Allocates an unlocked, unpurgable block
891 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi)
893 mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
898 needed = (size+15)/16; // convert size from bytes to paragraphs
900 GETNEWBLOCK; // fill in start and next after a spot is found
901 mm->mmnew->length = needed;
902 mm->mmnew->useptr = baseptr;
903 mm->mmnew->attributes = BASEATTRIBUTES;
905 for(search = 0; search<mm->endid; search++)
907 printf(" [case]"); //0000
909 // first search: try to allocate right after the rover, then on up
910 // second search: search from the head pointer up to the rover
911 // third search: compress memory, then scan from start
912 if(search == 1 && mm->mmrover == mm->mmhead)
919 lastscan = mm->mmrover;
920 scan = mm->mmrover->next;
925 lastscan = mm->mmhead;
926 scan = mm->mmhead->next;
927 endscan = mm->mmrover;
932 lastscan = mm->mmhead;
933 scan = mm->mmhead->next;
938 startseg = lastscan->start + (word)lastscan->length;
940 while(scan != endscan)
942 //printf(","); //0000
943 if(scan->start - startseg >= needed)
947 // got enough space between the end of lastscan and
948 // the start of scan, so throw out anything in the middle
949 // and allocate the new block
951 purge = lastscan->next;
952 lastscan->next = mm->mmnew;
953 mm->mmnew->start = *(word *)baseptr = startseg;
954 mm->mmnew->next = scan;
956 { // free the purgable block
957 printf(" freeing block~\n"); //0000
960 //MM_FreeBlock(purge, mm);
961 purge = next; // purge another if not at scan
963 mm->mmrover = mm->mmnew;
964 return; // good allocation!
968 // if this block is purge level zero or locked, skip past it
970 if((scan->attributes & LOCKBIT)
971 || !(scan->attributes & PURGEBITS) )
973 printf(" [lock] "); //0000
974 printf("len=%lu ", scan->length);
976 startseg = lastscan->start + (word)lastscan->length;
980 scan=scan->next; // look at next line
989 printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
990 printf("for stability reasons the program will shut down! wwww\n");
991 printf(" endid=%u\n",(mm->endid));
999 //==========================================================================
1002 ====================
1006 = Allocates an unlocked, unpurgable block
1008 ====================
1011 void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
1013 mmblocktype huge *scan,huge *last;
1018 if(baseptr == mm->mmrover->useptr) // removed the last allocated block
1019 mm->mmrover = mm->mmhead;
1021 while(scan->useptr != baseptr && scan)
1029 printf("MM_FreePtr: Block not found!\n");
1033 last->next = scan->next;
1037 //==========================================================================
1040 =====================
1044 = Sets the purge level for a block (locked blocks cannot be made purgable)
1046 =====================
1049 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
1051 mmblocktype huge *start;
1053 start = mm->mmrover;
1057 if(mm->mmrover->useptr == baseptr)
1060 mm->mmrover = mm->mmrover->next;
1063 mm->mmrover = mm->mmhead;
1064 else if(mm->mmrover == start)
1066 printf("MM_SetPurge: Block not found!");
1072 mm->mmrover->attributes &= ~PURGEBITS;
1073 mm->mmrover->attributes |= purge;
1076 //==========================================================================
1079 =====================
1083 = Locks / unlocks the block
1085 =====================
1088 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
1090 mmblocktype huge *start;
1092 start = mm->mmrover;
1096 if(mm->mmrover->useptr == baseptr)
1099 mm->mmrover = mm->mmrover->next;
1102 mm->mmrover = mm->mmhead;
1103 else if(mm->mmrover == start)
1105 printf("MM_SetLock: Block not found!");
1111 mm->mmrover->attributes &= ~LOCKBIT;
1112 mm->mmrover->attributes |= locked*LOCKBIT;
1115 //==========================================================================
1118 =====================
1122 = Throws out all purgable stuff and compresses movable blocks
1124 =====================
1127 void MM_SortMem(mminfo_t *mm)
1129 mmblocktype huge *scan,huge *last,huge *next;
1130 unsigned start,length,source,dest,oldborder;
1134 // lock down a currently playing sound
1136 /*++++ playing = SD_SoundPlaying ();
1142 playing += STARTPCSOUNDS;
1145 playing += STARTADLIBSOUNDS;
1148 MM_SetLock(&(memptr)audiosegs[playing],true);
1153 // oldborder = bordercolor;
1154 // VW_ColorBorder (15);
1161 last = NULL; // shut up compiler warning
1165 if(scan->attributes & LOCKBIT)
1168 // block is locked, so try to pile later blocks right after it
1170 start = scan->start + scan->length;
1174 if(scan->attributes & PURGEBITS)
1177 // throw out the purgable block
1181 //MM_FreeBlock(scan, mm);
1189 // push the non purgable block on top of the last moved block
1191 if(scan->start != start)
1193 length = scan->length;
1194 source = scan->start;
1196 while(length > 0xf00)
1198 movedata(source,0,dest,0,0xf00*16);
1203 movedata(source,0,dest,0,length*16);
1205 scan->start = start;
1206 *(unsigned *)scan->useptr = start;
1208 start = scan->start + scan->length;
1213 scan = scan->next; // go to next block
1216 mm->mmrover = mm->mmhead;
1221 // VW_ColorBorder (oldborder);
1224 MM_SetLock(&(memptr)audiosegs[playing],false);*/
1227 //==========================================================================
1230 =====================
1234 =====================
1237 void MM_ShowMemory(global_game_variables_t *gvar,/*page_t *page, */mminfo_t *mm)
1239 mmblocktype huge *scan;
1245 byte scratch[160],scratch0[4096],str[16];
1247 //**** VW_SetDefaultColors();
1248 //**** VW_SetLineWidth(40);
1249 //++++mh temp = bufferofs;
1250 //++++mh bufferofs = 0;
1251 //**** VW_SetScreen (0,0);
1255 CA_OpenDebug (gvar);
1259 strcpy(scratch, AARESET);
1260 if(scan->attributes & PURGEBITS)
1261 strcpy(scratch0, AAMAGENTA); // dark purple = purgable
1263 strcpy(scratch0, AABLUE); // medium blue = non purgable
1264 if(scan->attributes & LOCKBIT)
1265 strcpy(scratch0, AARED); // red = locked
1266 if(scan->start<=end)
1268 printf("\nend==%d\n\n", end);
1269 strcat(scratch, "MM_ShowMemory: Memory block order currupted!\n");
1270 strcat(scratch, "End's Size: ");
1272 strcat (scratch,str);
1273 strcat(scratch, "\nscan->start's Size: ");
1274 ultoa (scan->start,str,10);
1275 strcat (scratch,str);
1276 write(gvar->handle.debughandle,scratch,strlen(scratch));
1277 //modexprint(&page, chx, chy, 1, 0, 24, "\nMM_ShowMemory: Memory block order currupted!\n");
1280 end = scan->start+(scan->length)-1;
1281 //++++ chy = scan->start/320;
1282 //++++ chx = scan->start%320;
1283 //modexhlin(page, scan->start, (unsigned)end, chy, color);
1284 //for(chx=scan->start;chx+4>=(word)end;chx+=4)
1286 //++++ modexClearRegion(page, chx, chy, 4, 4, color);
1288 //++++ VW_Hlin(scan->start,(unsigned)end,0,color);
1289 for(w=(scan->start)/80;w<=end/80;w++)
1291 //printf("+ %u %lu\n", w, scan->length);
1292 strcat(scratch0, "+");
1294 strcat(scratch0, AARESET); strcat(scratch0, AAGREY); strcat(scratch0,"_");
1295 //++++ VW_Plot(scan->start,0,15);
1296 //++++ modexClearRegion(page, chx, chy, 4, 4, 15);
1297 //++++ VW_Hlin(end+1,scan->next->start,0,0); // black = free
1299 wwww=(dword)(scan->next->start)-(dword)scan->start;
1300 //wwww=(dword)scan->start+(dword)(scan->next->start);
1301 if (scan->next && scan->next->start >= end+1)
1303 strcat(scratch0, AARESET);
1304 strcat(scratch0, "\n");
1305 strcat(scratch0,AAGREEN);
1306 for(w=(end+1)/80;w<=(wwww/80);w++)
1308 //printf("0 %x %u %lu\n", scan->next->start, w, scan->length);
1309 strcat(scratch0,"0");
1311 //printf("==================\n");
1312 //printf("w=%x start=%x next=%x end=%u %lu\n", w, scan->start, (scan->next->start), end+1, wwww);
1313 //printf("==================\n");
1314 }/*else {//if(scan->next->start <= scan->start){
1315 scan->next->start=scan->start+0x1000;
1316 wwww=(dword)(scan->next->start)-(dword)scan->start;
1317 strcat(scratch0, AARESET);
1318 strcat(scratch0, "\n");
1319 strcat(scratch0,AAGREEN);
1320 for(w=(end+1);w<=(0x1000/80);w++)
1322 //printf("0 %x %x %u\n", scan->start, w);
1323 strcat(scratch0,"0");
1325 printf("================\n");
1326 printf("w=%x start=%x next=%x end=%u %lu\n", w, scan->start, (scan->next->start), end+1, wwww);
1327 printf("================\n");
1330 strcat(scratch0, AARESET);
1331 strcat(scratch0,"\n");
1332 //for(chx=scan->next->start;chx+4>=(word)end+1;chx+=4)
1334 // chx+=scan->next->start;
1335 // modexClearRegion(page, chx, chy, 4, 4, 2);
1337 //modexhlin(page, end+1,scan->next->start, chy, 0);
1338 /* y = scan->start/320;
1339 x = scan->start%320;
1340 VW_Hlin(x,x+end,y,color);
1342 //++++ VW_Hlin(x+end+1,x+(scan->next->start-scan->start),y,0); // black = free
1343 strcat(scratch,"Seg:");
1344 ultoa (scan->start,str,16);
1345 strcat (scratch,str);
1346 strcat (scratch,"\tSize:");
1347 ultoa ((word)scan->length,str,10);
1348 strcat (scratch,str);
1349 strcat (scratch,"\tOwner:0x");
1350 owner = (unsigned)scan->useptr;
1351 ultoa (owner,str,16);
1352 strcat (scratch,str);
1353 strcat (scratch,"\n");
1354 write(gvar->handle.debughandle,scratch,strlen(scratch));
1355 write(gvar->handle.debughandle,scratch0,strlen(scratch0));
1356 //modexprint(page, chx, chy, 1, 0, 24, &scratch);
1358 //fprintf(stdout, "%s", scratch);
1363 CA_CloseDebug (gvar);
1366 //**** VW_SetLineWidth(64);
1367 //++++mh bufferofs = temp;
1370 //==========================================================================
1373 =====================
1377 =====================
1380 void MM_DumpData(mminfo_t *mm)
1382 mmblocktype huge *scan,huge *best;
1383 long lowest,oldlowest;
1389 dumpfile = fopen ("mmdump.16","w");
1391 printf("MM_DumpData: Couldn't open MMDUMP.16!\n");
1404 owner = (word)scan->useptr;
1406 if (owner && owner<lowest && owner > oldlowest)
1415 if (lowest != 0xffff)
1417 if (best->attributes & PURGEBITS)
1421 if (best->attributes & LOCKBIT)
1425 fprintf (dumpfile,"0x%p (%c%c) = %u\n"
1426 ,(word)lowest,lock,purge,best->length);
1429 } while (lowest != 0xffff);
1432 printf("MMDUMP.16 created.\n");
1435 //==========================================================================
1439 ======================
1443 = Returns the total free space without purging
1445 ======================
1448 dword MM_UnusedMemory(mminfo_t *mm)
1451 mmblocktype huge *scan;
1458 free += scan->next->start - (scan->start + scan->length);
1466 //==========================================================================
1470 ======================
1474 = Returns the total free space with purging
1476 ======================
1479 dword MM_TotalFree(mminfo_t *mm)
1482 mmblocktype huge *scan;
1489 if((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
1490 free += scan->length;
1491 free += scan->next->start - (scan->start + scan->length);
1499 //==========================================================================
1502 =====================
1506 =====================
1509 void MM_Report(/*page_t *page, */mminfo_t *mm, mminfotype *mmi)
1511 if(MML_CheckForEMS())
1513 printf("EMM v%x.%x available\n", mm->EMSVer>>4,mm->EMSVer&0x0F);
1514 printf("totalEMSpages=%u\n", mm->totalEMSpages);
1515 printf("freeEMSpages=%u\n", mm->freeEMSpages);
1516 printf("EMSpageframe=%x\n", mm->EMSpageframe);
1518 if(MML_CheckForXMS(mm)) printf("XMSaddr=%X\n", *XMSaddr);
1519 printf("near=%lu\n", mmi->nearheap);
1520 printf("far=%lu\n", mmi->farheap);
1521 printf("EMSmem=%lu\n", mmi->EMSmem);
1522 printf("XMSmem=%lu\n", mmi->XMSmem);
1523 printf("mainmem=%lu\n", mmi->mainmem);
1524 printf("UnusedMemory=%lu\n", MM_UnusedMemory(mm));
1525 printf("TotalFree=%lu\n", MM_TotalFree(mm));
1526 printf("TotalUsed=%lu\n", mmi->mainmem+mmi->EMSmem+mmi->XMSmem+mmi->XMSmem);
1529 //==========================================================================
1532 =====================
1536 =====================
1539 void MM_EMSerr(byte *stri, byte err)
1541 //Returns a text string describing the error code in EMS.Error.
1545 strcat(stri, "successful");
1548 strcat(stri, "internal error");
1551 strcat(stri, "hardware malfunction");
1554 strcat(stri, "busy .. retry later");
1557 strcat(stri, "invalid handle");
1560 strcat(stri, "undefined function requested by application");
1563 strcat(stri, "no more handles available");
1566 strcat(stri, "error in save or restore of mapping context");
1569 strcat(stri, "insufficient memory pages in system");
1572 strcat(stri, "insufficient memory pages available");
1575 strcat(stri, "zero pages requested");
1578 strcat(stri, "invalid logical page number encountered");
1581 strcat(stri, "invalid physical page number encountered");
1584 strcat(stri, "page-mapping hardware state save area is full");
1587 strcat(stri, "save of mapping context failed");
1590 strcat(stri, "restore of mapping context failed");
1593 strcat(stri, "undefined subfunction");
1596 strcat(stri, "undefined attribute type");
1599 strcat(stri, "feature not supported");
1602 strcat(stri, "successful, but a portion of the source region has been overwritten");
1605 strcat(stri, "length of source or destination region exceeds length of region allocated to either source or destination handle");
1608 strcat(stri, "conventional and expanded memory regions overlap");
1611 strcat(stri, "offset within logical page exceeds size of logical page");
1614 strcat(stri, "region length exceeds 1 MB");
1617 strcat(stri, "source and destination EMS regions have same handle and overlap");
1620 strcat(stri, "memory source or destination type undefined");
1623 strcat(stri, "specified alternate map register or DMA register set not supported");
1626 strcat(stri, "all alternate map register or DMA register sets currently allocated");
1629 strcat(stri, "alternate map register or DMA register sets not supported");
1632 strcat(stri, "undefined or unallocated alternate map register or DMA register set");
1635 strcat(stri, "dedicated DMA channels not supported");
1638 strcat(stri, "specified dedicated DMA channel not supported");
1641 strcat(stri, "no such handle name");
1644 strcat(stri, "a handle found had no name, or duplicate handle name");
1647 strcat(stri, "attempted to wrap around 1M conventional address space");
1650 strcat(stri, "source array corrupted");
1653 strcat(stri, "operating system denied access");
1656 strcat(stri, "undefined error");
1660 //==========================================================================
1663 =====================
1667 =====================
1670 void MM_BombOnError(boolean bomb, mminfo_t *mm)
1672 mm->bombonerror = bomb;
1675 /*void MM_GetNewBlock(mminfo_t *mm)
1679 mm->mmnew=mm->mmfree;
1680 mm->mmfree=mm->mmfree->next;
1681 if(!(mm->mmnew=mm->mmfree))
1683 printf("MM_GETNEWBLOCK: No free blocks!\n");
1686 mm->mmfree=mm->mmfree->next;
1687 mm->endid++; //end of list
1690 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
1695 mm->endid--; //end of list
1698 /*void MM_seguin(void)
1708 void MM_segude(void)
1716 pull data from far and put it into ds var