1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
26 =============================================================================
\r
28 ID software memory manager
\r
29 --------------------------
\r
31 Primary coder: John Carmack
\r
35 Quit (global_game_variables_t *gvar, char *error) function
\r
40 MM_SizePtr to change the size of a given pointer
\r
42 Multiple purge levels utilized
\r
44 EMS / XMS unmanaged routines
\r
46 =============================================================================
\r
50 Open Watcom port by sparky4
\r
53 #include "src/lib/16_mm.h"
\r
54 #include "src/lib/16_ca.h"
\r
62 =============================================================================
\r
66 =============================================================================
\r
69 #define LOCKBIT 0x80 // if set in attributes, block cannot be moved
\r
70 #define PURGEBITS 3 // 0-3 level, 0= unpurgable, 3= purge first
\r
71 #define PURGEMASK 0xfffc
\r
72 #define BASEATTRIBUTES 0 // unlocked, non purgable
\r
74 //#define MAXUMBS 10
\r
76 /*typedef struct mmblockstruct
\r
78 unsigned start,length;
\r
79 unsigned attributes;
\r
80 memptr *useptr; // pointer to the segment start
\r
81 struct mmblockstruct far *next;
\r
85 //#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}
\r
88 #define GETNEWBLOCK {if(!gvar->mm.mmfree)MML_ClearBlock(gvar);gvar->mm.mmnew=gvar->mm.mmfree;gvar->mm.mmfree=gvar->mm.mmfree->next;}
\r
90 #define FREEBLOCK(x) {*x->useptr=NULL;x->next=gvar->mm.mmfree;gvar->mm.mmfree=x;}
\r
93 =============================================================================
\r
97 =============================================================================
\r
100 /*mminfotype mminfo;
\r
104 void (* beforesort) (void);
\r
105 void (* aftersort) (void);
\r
108 =============================================================================
\r
112 =============================================================================
\r
115 /*boolean mmstarted;
\r
120 mmblocktype far mmblocks[MAXBLOCKS]
\r
121 ,far *mmhead,far *mmfree,far *mmrover,far *mmnew;
\r
123 boolean bombonerror;*/
\r
125 //unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
\r
127 void (* XMSaddr) (void); // far pointer to XMS driver
\r
129 /*unsigned numUMBs,UMBbase[MAXUMBS];*/
\r
131 //==========================================================================
\r
134 // local prototypes
\r
137 boolean MML_CheckForEMS (void);
\r
138 void MML_ShutdownEMS (void);
\r
139 void MM_MapEMS (void);
\r
140 boolean MML_CheckForXMS (void);
\r
141 void MML_ShutdownXMS (void);
\r
142 //void MML_UseSpace (unsigned segstart, unsigned seglength);
\r
143 //void MML_ClearBlock (void);
\r
145 //==========================================================================
\r
148 static char *ParmStringsexmm[] = {"noems","noxms",""};
\r
152 ======================
\r
156 = Routine from p36 of Extending DOS
\r
158 =======================
\r
161 boolean MML_CheckForEMS(void)
\r
163 boolean emmcfems = false;
\r
164 word EMSPageFrame = 0;
\r
165 byte err=0, str[64];
\r
166 static char emmname[] = "EMMXXXX0"; //fix by andrius4669
\r
168 mov dx,OFFSET emmname //fix by andrius4669
\r
170 int EMM_INT // try to open EMMXXXX0 device
\r
176 int EMM_INT // get device info
\r
184 int EMM_INT // get status
\r
190 int EMM_INT // close handle
\r
196 mov ah,EMS_GETFRAME
\r
197 int EMS_INT // find the page frame address
\r
200 mov [EMSPageFrame],bx
\r
207 #ifdef __BORLANDC__
\r
211 #ifdef __BORLANDC__
\r
219 #ifdef __BORLANDC__
\r
228 // Pageframe switch to determine if there is one!
\r
233 #if defined(__DEBUG_PM__) || defined(__DEBUG_MM__)
\r
234 printf("MML_CheckForEMS: EMS error No Pageframe!\nAddress detected to be %04x\n", EMSPageFrame);
\r
236 }else if(!emmcfems)// if there is an error and page frame is not 0000
\r
238 strcpy(str,"MML_CheckForEMS: EMS error ");
\r
239 MM_EMSerr(str, err);
\r
240 printf("%s\n",str);
\r
249 ======================
\r
253 =======================
\r
256 byte MML_SetupEMS(global_game_variables_t *gvar)
\r
260 boolean errorflag=false;
\r
262 unsigned int EMSVer = 0;
\r
264 unsigned totalEMSpages,freeEMSpages,EMSPageFrame,EMSpagesmapped,EMSHandle;
\r
265 totalEMSpages = freeEMSpages = EMSPageFrame = EMSpagesmapped = 0;
\r
269 int EMS_INT // make sure EMS hardware is present
\r
271 //mov [EMS_status],ah
\r
278 mov [EMSVer],ax // set EMSVer
\r
279 cmp al,0x32 // only work on ems 3.2 or greater
\r
282 mov ah,EMS_GETFRAME
\r
283 int EMS_INT // find the page frame address
\r
286 mov [EMSPageFrame],bx
\r
288 mov ah,EMS_GETPAGES
\r
289 int EMS_INT // find out how much EMS is there
\r
292 mov [totalEMSpages],dx
\r
293 mov [freeEMSpages],bx
\r
295 jz noEMS // no EMS at all to allocate
\r
299 cmp bx,[freeEMSpages]
\r
301 mov bx,[freeEMSpages]
\r
303 #ifdef __BORLANDC__
\r
307 #ifdef __BORLANDC__
\r
311 jle getpages // there is only 1,2,3,or 4 pages
\r
312 mov bx,4 // we can't use more than 4 pages
\r
313 #ifdef __BORLANDC__
\r
317 #ifdef __BORLANDC__
\r
320 mov [EMSpagesmapped],bx
\r
321 mov ah,EMS_ALLOCPAGES // allocate up to 64k of EMS
\r
327 #ifdef __BORLANDC__
\r
331 #ifdef __BORLANDC__
\r
337 #ifdef __BORLANDC__
\r
345 if(errorflag==true)
\r
347 strcpy(str,"MM_SetupEMS: EMS error ");
\r
348 MM_EMSerr(str, err);
\r
349 printf("%s\n",str);
\r
352 gvar->mm.totalEMSpages=totalEMSpages;
\r
353 gvar->mm.freeEMSpages=freeEMSpages;
\r
354 gvar->mm.EMSPageFrame=EMSPageFrame;
\r
355 gvar->mm.EMSpagesmapped=EMSpagesmapped;
\r
356 gvar->mm.EMSHandle=EMSHandle;
\r
357 gvar->mm.EMSVer=EMSVer;
\r
363 ======================
\r
367 =======================
\r
370 void MML_ShutdownEMS(global_game_variables_t *gvar)
\r
372 boolean errorflag=false;
\r
373 unsigned EMSHandle=gvar->mm.EMSHandle;
\r
378 mov ah,EMS_FREEPAGES
\r
384 #ifdef __BORLANDC__
\r
391 if(errorflag==true)
\r
392 Quit (gvar, "MML_ShutdownEMS: Error freeing EMS!\n"); //++++ add something
\r
396 ====================
\r
400 = Maps the 64k of EMS used by memory manager into the page frame
\r
401 = for general use. This only needs to be called if you are keeping
\r
402 = other things in EMS.
\r
404 ====================
\r
407 byte MM_MapEMS(global_game_variables_t *gvar)
\r
410 unsigned EMSHandle;
\r
412 boolean errorflag=false;
\r
414 EMSHandle=gvar->mm.EMSHandle;
\r
416 for (i=0;i<4/*MAPPAGES*/;i++)
\r
420 mov bx,[i] // logical page
\r
421 mov al,bl // physical page
\r
422 mov dx,[EMSHandle] // handle
\r
427 #ifdef __BORLANDC__
\r
431 #ifdef __BORLANDC__
\r
436 #ifdef __BORLANDC__
\r
443 if(errorflag==true)
\r
445 strcpy(str,"MM_MapEMS: EMS error ");
\r
446 MM_EMSerr(str, err);
\r
447 printf("%s\n",str);
\r
451 gvar->mmi.EMSmem = (i)*0x4000lu;
\r
455 byte MM_MapXEMS(global_game_variables_t *gvar)
\r
457 //SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)
\r
459 //Maps up to 4 logical EMS pages to physical pages in the page frame, where:
\r
460 //PhysicalStart = Physical page first logical page is mapped to
\r
461 //LogicalStart = First logical page to map
\r
462 //NumPages = Number of pages to map (1 to 4)
\r
463 //Handle = EMS handle logical pages are allocated to
\r
465 /*//Create a buffer containing the page information
\r
466 // FOR x = 0 TO NumPages - 1
\r
467 // MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x)
\r
470 // Regs.ax = 0x5000 //Map the pages in the buffer
\r
471 // Regs.cx = NumPages //to the pageframe
\r
472 // Regs.dx = Handle
\r
473 // Regs.ds = VARSEG(MapInfo$)
\r
474 // Regs.si = SADD(MapInfo$)
\r
475 // InterruptX 0x67, Regs, Regs
\r
476 // EMS.Error = (Regs.ax AND 0xFF00&) \ 0x100 //Store the status code
\r
482 boolean errorflag=false;
\r
484 EMSHandle=gvar->mm.EMSHandle;
\r
486 if(gvar->mm.EMSVer<0x40)
\r
489 for (i=0;i<MAPPAGES;i++)
\r
492 mov ah,EMS_MAPXPAGE
\r
493 mov cx,[i] // logical page
\r
494 mov al,bl // physical page
\r
495 mov dx,[EMSHandle] // handle
\r
500 #ifdef __BORLANDC__
\r
504 #ifdef __BORLANDC__
\r
509 #ifdef __BORLANDC__
\r
516 if(errorflag==true)
\r
518 //strcpy(str,"MM_MapXEMS: EMS error 0x");
\r
519 strcpy(str,"MM_MapXEMS: EMS error ");
\r
520 //itoa(err,str2,16);
\r
521 MM_EMSerr(str, err);
\r
522 printf("%s\n",str);
\r
523 //printf("%s%x\n",str, err);
\r
524 //printf("FACK! %x\n", err);
\r
528 gvar->mmi.EMSmem = (i)*0x4000lu;
\r
533 //==========================================================================
\r
536 ======================
\r
540 = Check for XMM driver
\r
542 =======================
\r
545 boolean MML_CheckForXMS(void)
\r
548 boolean errorflag=false;
\r
552 int 0x2f // query status of installed diver
\r
556 #ifdef __BORLANDC__
\r
563 if(errorflag==true) return false;
\r
570 ======================
\r
574 = Try to allocate all upper memory block
\r
576 =======================
\r
579 void MML_SetupXMS(global_game_variables_t *gvar)
\r
587 mov [WORD PTR XMSaddr],bx
\r
588 mov [WORD PTR XMSaddr+2],es // function pointer to XMS driver
\r
592 mov ah,XMS_ALLOCUMB
\r
593 mov dx,0xffff // try for largest block possible
\r
594 //mov ax,dx // Set available Kbytes.
\r
595 call [DWORD PTR XMSaddr]
\r
599 cmp bl,0xb0 // error: smaller UMB is available
\r
602 mov ah,XMS_ALLOCUMB
\r
603 call [DWORD PTR XMSaddr] // DX holds largest available UMB
\r
605 jz done // another error...
\r
606 #ifdef __BORLANDC__
\r
610 #ifdef __BORLANDC__
\r
615 #ifdef __BORLANDC__
\r
622 // printf("base=%u ", base); printf("size=%u\n", size);
\r
623 MML_UseSpace(base,size, gvar);
\r
624 gvar->mmi.XMSmem += size*16;
\r
625 gvar->mm.UMBbase[gvar->mm.numUMBs] = base;
\r
626 gvar->mm.numUMBs++;
\r
627 if(gvar->mm.numUMBs < MAXUMBS)
\r
633 ======================
\r
637 ======================
\r
640 void MML_ShutdownXMS(global_game_variables_t *gvar)
\r
645 for (i=0;i<gvar->mm.numUMBs;i++)
\r
647 base = gvar->mm.UMBbase[i];
\r
651 call [DWORD PTR XMSaddr]
\r
657 //==========================================================================
\r
660 ======================
\r
664 = Marks a range of paragraphs as usable by the memory manager
\r
665 = This is used to mark space for the near heap, far heap, ems page frame,
\r
666 = and upper memory blocks
\r
668 ======================
\r
672 extra = oldend - (segstart+seglength);
\r
676 //++++emsver stuff!
\r
677 if(segm>1)/// || extra>=0x10000lu)
\r
678 //if(extra>0xfffflu)
\r
682 //MML_UseSpace(segstart, seglength, gvar);
\r
684 printf("MML_UseSpace: Segment spans two blocks!\n");
\r
686 printf("segm=%u ", segm);
\r
687 printf("ex=%lu ", extra);
\r
688 printf("old=%u ", oldend);
\r
689 printf("start+seglen=%lu\n", segstart+seglength);
\r
690 printf("segsta=%x ", segstart);
\r
691 printf("len=%lu ", scan->length);
\r
692 printf("seglen=%lu ", seglength);
\r
693 printf("segmlen=%lu\n", segmlen);
\r
695 //++++todo: linked list of segment!
\r
697 void MML_UseSpace (unsigned segstart, unsigned seglength, global_game_variables_t *gvar)
\r
699 mmblocktype far *scan,far *last;
\r
704 scan = last = gvar->mm.mmhead;
\r
705 gvar->mm.mmrover = gvar->mm.mmhead; // reset rover to start of memory
\r
708 // search for the block that contains the range of segments
\r
710 while (scan->start+scan->length < segstart)
\r
717 // find out how many blocks it spans!
\r
719 /*for(;seglength>=0x10000;seglength-=0xFFFF)
\r
721 //printf(" seglen=%lu\n", segmlen);
\r
726 // take the given range out of the block
\r
728 oldend = scan->start + scan->length;
\r
729 extra = oldend - (segstart+seglength);
\r
731 #ifdef __DEBUG_MM__
\r
733 printf("========================================\n");
\r
734 printf("start=%x ", scan->start);
\r
735 printf("old=%u ", oldend);
\r
736 printf("start+seglen=%lu\n", segstart+seglength);
\r
737 printf("segsta=%x ", segstart);
\r
738 printf("len=%lu ", scan->length);
\r
739 printf("seglen=%lu ", seglength);
\r
741 printf("MML_UseSpace: Segment spans two blocks! %d\n", extra);
\r
742 printf("========================================\n");
\r
746 Quit (gvar, "MML_UseSpace: Segment spans two blocks!");
\r
749 if (segstart == scan->start)
\r
751 last->next = scan->next; // unlink block
\r
756 scan->length = segstart-scan->start; // shorten block
\r
761 gvar->mm.mmnew->useptr = NULL;
\r
763 gvar->mm.mmnew->next = scan->next;
\r
764 scan->next = gvar->mm.mmnew;
\r
765 gvar->mm.mmnew->start = segstart+seglength;
\r
766 gvar->mm.mmnew->length = extra;
\r
767 gvar->mm.mmnew->attributes = LOCKBIT;
\r
768 }//else if(segm>0) goto segu;
\r
772 //==========================================================================
\r
775 ====================
\r
779 = We are out of blocks, so free a purgable block
\r
781 ====================
\r
784 void MML_ClearBlock (global_game_variables_t *gvar)
\r
786 mmblocktype far *scan;//,far *last;
\r
788 scan = gvar->mm.mmhead->next;
\r
792 if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS) )
\r
794 MM_FreePtr (scan->useptr, gvar);
\r
800 Quit (gvar, "MM_ClearBlock: No purgable blocks!\n");
\r
804 //==========================================================================
\r
807 ===================
\r
811 ===================
\r
814 void MM_Reset (global_game_variables_t *gvar)
\r
817 // if(sizeof(mmblocktype)!=16)
\r
820 #ifdef __BORLANDC__
\r
821 strcpy(gvar->handle.datadumpfilename, "mmdump.16b");
\r
824 strcpy(gvar->handle.datadumpfilename, "mmdump.16w");
\r
827 #ifdef __BORLANDC__
\r
828 strcpy(gvar->handle.heapdumpfilename, "heap.16b");
\r
831 strcpy(gvar->handle.heapdumpfilename, "heap.16w");
\r
836 //==========================================================================
\r
839 ===================
\r
843 = Grabs all space from turbo with malloc/farmalloc
\r
844 = Allocates bufferseg misc buffer
\r
846 ===================
\r
849 void MM_Startup (global_game_variables_t *gvar)
\r
852 unsigned long length;
\r
854 unsigned segstart,seglength;//,endfree;
\r
856 if(gvar->mm.mmstarted)
\r
857 MM_Shutdown (gvar);
\r
860 gvar->mm.mmstarted = true;
\r
861 gvar->mm.bombonerror = true;
\r
863 // set up the linked list (everything in the free list;
\r
865 gvar->mm.mmhead = NULL;
\r
866 gvar->mm.mmfree = &(gvar->mm.mmblocks[0]);
\r
867 for (i=0;i<MAXBLOCKS-1;i++)
\r
868 gvar->mm.mmblocks[i].next = &(gvar->mm.mmblocks[i+1]);
\r
869 gvar->mm.mmblocks[i].next = NULL;
\r
872 // locked block of all memory until we punch out free space
\r
875 gvar->mm.mmhead = gvar->mm.mmnew; // this will allways be the first node
\r
876 gvar->mm.mmnew->start = 0;
\r
877 gvar->mm.mmnew->length = 0xffff;
\r
878 gvar->mm.mmnew->attributes = LOCKBIT;
\r
879 gvar->mm.mmnew->next = NULL;
\r
880 gvar->mm.mmrover = gvar->mm.mmhead;
\r
884 // get all available near conventional memory segments
\r
886 length=(word)coreleft();
\r
887 start = (void far *)(gvar->mm.nearheap = _nmalloc(length));
\r
889 length -= 16-(FP_OFF(start)&15);
\r
890 length -= SAVENEARHEAP;
\r
891 seglength = length / 16; // now in paragraphs
\r
892 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
\r
893 MML_UseSpace (segstart,seglength, gvar);
\r
894 gvar->mmi.nearheap = length;
\r
895 //0000printf("near: start=%Fp segstart=%x seglen=%lu len=%lu\n", start, segstart, (dword)seglength, length);
\r
897 // get all available far conventional memory segments
\r
899 length=farcoreleft();
\r
900 start = gvar->mm.farheap = farmalloc(length);
\r
901 length -= 16-(FP_OFF(start)&15);
\r
902 length -= SAVEFARHEAP;
\r
903 seglength = length / 16; // now in paragraphs
\r
904 segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
\r
905 MML_UseSpace (segstart,seglength, gvar);
\r
906 gvar->mmi.farheap = length;
\r
907 gvar->mmi.mainmem = gvar->mmi.nearheap + gvar->mmi.farheap;
\r
908 //0000printf("far: start=%Fp segstart=%x seglen=%lu len=%lu\n", start, segstart, (dword)seglength, length);
\r
909 #if !defined(__16_PM__)// && defined(__WATCOMC__)
\r
913 // detect EMS and allocate up to 64K at page frame
\r
915 gvar->mmi.EMSmem = 0;
\r
916 //goto emsskip; //0000
\r
917 for(i = 1;i < _argc;i++)
\r
919 if(US_CheckParm(_argv[i],ParmStringsexmm) == 0)
\r
920 goto emsskip; // param NOEMS
\r
922 if(MML_CheckForEMS())
\r
924 MML_SetupEMS(gvar); // allocate space
\r
925 //16_PM: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
\r
926 MML_UseSpace(gvar->mm.EMSPageFrame,(MAPPAGES)*0x4000lu, gvar);
\r
927 //if(gvar->pm.emm.EMSVer<0x40)
\r
928 MM_MapEMS(gvar); // map in used pages
\r
930 //MM_MapXEMS(gvar); // map in used pages
\r
934 // detect XMS and get upper memory blocks
\r
937 gvar->mmi.XMSmem = 0;
\r
938 goto xmsskip;//0000
\r
939 for(i = 1;i < _argc;i++)
\r
941 if(US_CheckParm( _argv[i],ParmStringsexmm) == 0)
\r
942 goto xmsskip; // param NOXMS
\r
944 if(MML_CheckForXMS())
\r
946 MML_SetupXMS(gvar); // allocate as many UMBs as possible
\r
954 // allocate the misc buffer
\r
956 gvar->mm.mmrover = gvar->mm.mmhead; // start looking for space after low block
\r
958 MM_GetPtr (&(gvar->mm.bufferseg),BUFFERSIZE, gvar);
\r
961 //==========================================================================
\r
964 ====================
\r
968 = Frees all conventional, EMS, and XMS allocated
\r
970 ====================
\r
973 void MM_Shutdown (global_game_variables_t *gvar)
\r
975 if(!(gvar->mm.mmstarted))
\r
978 _ffree(gvar->mm.farheap);// printf(" far freed\n");
\r
979 _nfree(gvar->mm.nearheap);// printf(" near freed\n");
\r
985 if(MML_CheckForEMS()){ MML_ShutdownEMS(gvar); }//printf(" EMS freed\n"); }
\r
986 if(MML_CheckForXMS()){ MML_ShutdownXMS(gvar); }//printf(" XMS freed\n"); }
\r
994 //==========================================================================
\r
997 ====================
\r
1001 = Allocates an unlocked, unpurgable block
\r
1003 ====================
\r
1006 void MM_GetPtr (memptr *baseptr,dword size, global_game_variables_t *gvar)
\r
1008 mmblocktype far *scan,far *lastscan,far *endscan
\r
1009 ,far *purge,far *next;
\r
1011 unsigned needed,startseg;
\r
1013 needed = (size+15)/16; // convert size from bytes to paragraphs
\r
1015 GETNEWBLOCK; // fill in start and next after a spot is found
\r
1016 gvar->mm.mmnew->length = needed;
\r
1017 gvar->mm.mmnew->useptr = baseptr;
\r
1018 gvar->mm.mmnew->attributes = BASEATTRIBUTES;
\r
1019 //if(gvar->mm.mmnew->useptr==NULL){
\r
1020 #ifdef __DEBUG_MM__
\r
1021 if(dbg_debugmm>0){
\r
1022 printf("===============================================================================\n");
\r
1023 printf(" MM_GetPtr\n");
\r
1024 printf("===============================================================================\n");
\r
1026 // printf(" baseptr=%Fp ", baseptr); printf("useptr=%Fp\n", gvar->mm.mmnew->useptr);
\r
1027 // //printf(" *baseptr=%Fp ", *baseptr); printf("*useptr=%Fp\n", *(gvar->mm.mmnew->useptr));
\r
1028 // printf(" &baseptr=%Fp ", &baseptr); printf("&useptr=%Fp\n", &(gvar->mm.mmnew->useptr));
\r
1030 printf(" baseptr=%04x ", baseptr); printf("useptr=%04x\n", gvar->mm.mmnew->useptr);
\r
1031 //printf(" *baseptr=%04x ", *baseptr); printf("*useptr=%04x\n", *(gvar->mm.mmnew->useptr));
\r
1032 printf(" &baseptr=%04u ", &baseptr); printf("&useptr=%04u\n", &(gvar->mm.mmnew->useptr));
\r
1034 printf(" size is %lu\n", size);
\r
1037 //Quit (gvar, "gvar->mm.mmnew->useptr==NULL"); }
\r
1040 for (search = 0; search<3; search++)
\r
1043 // first search: try to allocate right after the rover, then on up
\r
1044 // second search: search from the head pointer up to the rover
\r
1045 // third search: compress memory, then scan from start
\r
1046 if (search == 1 && gvar->mm.mmrover == gvar->mm.mmhead)
\r
1052 lastscan = gvar->mm.mmrover;
\r
1053 scan = gvar->mm.mmrover->next;
\r
1057 lastscan = gvar->mm.mmhead;
\r
1058 scan = gvar->mm.mmhead->next;
\r
1059 endscan = gvar->mm.mmrover;
\r
1062 MM_SortMem (gvar);
\r
1063 lastscan = gvar->mm.mmhead;
\r
1064 scan = gvar->mm.mmhead->next;
\r
1069 startseg = lastscan->start + lastscan->length;
\r
1071 while (scan != endscan)
\r
1073 if (scan->start - startseg >= needed)
\r
1076 // got enough space between the end of lastscan and
\r
1077 // the start of scan, so throw out anything in the middle
\r
1078 // and allocate the new block
\r
1080 purge = lastscan->next;
\r
1081 lastscan->next = gvar->mm.mmnew;
\r
1082 gvar->mm.mmnew->start = *(unsigned *)baseptr = startseg;
\r
1083 gvar->mm.mmnew->next = scan;
\r
1084 while ( purge != scan)
\r
1085 { // free the purgable block
\r
1086 next = purge->next;
\r
1088 purge = next; // purge another if not at scan
\r
1090 gvar->mm.mmrover = gvar->mm.mmnew;
\r
1091 return; // good allocation!
\r
1095 // if this block is purge level zero or locked, skip past it
\r
1097 if ( (scan->attributes & LOCKBIT)
\r
1098 || !(scan->attributes & PURGEBITS) )
\r
1101 startseg = lastscan->start + lastscan->length;
\r
1105 scan=scan->next; // look at next line
\r
1109 if (gvar->mm.bombonerror)
\r
1111 #ifdef __WATCOMC__
\r
1114 printf(OUT_OF_MEM_MSG,(size-gvar->mmi.nearheap));
\r
1115 Quit (gvar, "for stability reasons the program will shut down! wwww\n");
\r
1118 gvar->mm.mmerror = true;
\r
1121 //==========================================================================
\r
1124 ====================
\r
1128 = Deallocates an unlocked, purgable block
\r
1130 ====================
\r
1133 void MM_FreePtr (memptr *baseptr, global_game_variables_t *gvar)
\r
1135 mmblocktype far *scan,far *last;
\r
1137 last = gvar->mm.mmhead;
\r
1138 scan = last->next;
\r
1140 if (baseptr == gvar->mm.mmrover->useptr) // removed the last allocated block
\r
1141 gvar->mm.mmrover = gvar->mm.mmhead;
\r
1143 while (scan->useptr != baseptr && scan)
\r
1146 scan = scan->next;
\r
1150 Quit (gvar, "MM_FreePtr: Block not found!");
\r
1152 last->next = scan->next;
\r
1156 //==========================================================================
\r
1159 =====================
\r
1163 = Sets the purge level for a block (locked blocks cannot be made purgable)
\r
1165 =====================
\r
1168 void MM_SetPurge (memptr *baseptr, int purge, global_game_variables_t *gvar)
\r
1170 mmblocktype far *start;
\r
1172 start = gvar->mm.mmrover;
\r
1176 if (gvar->mm.mmrover->useptr == baseptr)
\r
1179 gvar->mm.mmrover = gvar->mm.mmrover->next;
\r
1181 if (!gvar->mm.mmrover)
\r
1182 gvar->mm.mmrover = gvar->mm.mmhead;
\r
1183 else if (gvar->mm.mmrover == start)
\r
1184 Quit (gvar, "MM_SetPurge: Block not found!");
\r
1188 gvar->mm.mmrover->attributes &= ~PURGEBITS;
\r
1189 gvar->mm.mmrover->attributes |= purge;
\r
1192 //==========================================================================
\r
1195 =====================
\r
1199 = Locks / unlocks the block
\r
1201 =====================
\r
1204 void MM_SetLock (memptr *baseptr, boolean locked, global_game_variables_t *gvar)
\r
1206 mmblocktype far *start;
\r
1208 start = gvar->mm.mmrover;
\r
1212 if (gvar->mm.mmrover->useptr == baseptr)
\r
1215 gvar->mm.mmrover = gvar->mm.mmrover->next;
\r
1217 if (!gvar->mm.mmrover)
\r
1218 gvar->mm.mmrover = gvar->mm.mmhead;
\r
1219 else if (gvar->mm.mmrover == start)
\r
1220 Quit (gvar, "MM_SetLock: Block not found!");
\r
1224 gvar->mm.mmrover->attributes &= ~LOCKBIT;
\r
1225 gvar->mm.mmrover->attributes |= locked*LOCKBIT;
\r
1228 //==========================================================================
\r
1231 =====================
\r
1235 = Throws out all purgable stuff and compresses movable blocks
\r
1237 =====================
\r
1240 void MM_SortMem (global_game_variables_t *gvar)
\r
1242 mmblocktype far *scan,far *last,far *next;
\r
1243 unsigned start,length,source,dest,oldborder;
\r
1244 //++++int playing;
\r
1247 // lock down a currently playing sound
\r
1249 /*++++ playing = SD_SoundPlaying ();
\r
1252 switch (SoundMode)
\r
1255 playing += STARTPCSOUNDS;
\r
1258 playing += STARTADLIBSOUNDS;
\r
1261 MM_SetLock(MEMPTRCONV audiosegs[playing],true);
\r
1266 #ifdef __WATCOMC__
\r
1267 oldborder = gvar->video.bordercolor;
\r
1268 gvar->video.bordercolor = VL_modexPalOverscan(gvar->video.palette, 4);
\r
1274 scan = gvar->mm.mmhead;
\r
1276 last = NULL; // shut up compiler warning
\r
1280 if (scan->attributes & LOCKBIT)
\r
1283 // block is locked, so try to pile later blocks right after it
\r
1285 start = scan->start + scan->length;
\r
1289 if (scan->attributes & PURGEBITS)
\r
1292 // throw out the purgable block
\r
1294 next = scan->next;
\r
1295 FREEBLOCK(scan); //MM_FreeBlock(scan, gvar);
\r
1296 last->next = next;
\r
1303 // push the non purgable block on top of the last moved block
\r
1305 if (scan->start != start)
\r
1307 length = scan->length;
\r
1308 source = scan->start;
\r
1310 while (length > 0xf00)
\r
1312 movedata(source,0,dest,0,0xf00*16);
\r
1317 movedata(source,0,dest,0,length*16);
\r
1319 scan->start = start;
\r
1320 *(unsigned *)scan->useptr = start;
\r
1322 start = scan->start + scan->length;
\r
1327 scan = scan->next; // go to next block
\r
1330 gvar->mm.mmrover = gvar->mm.mmhead;
\r
1335 VL_ColorBorder (oldborder, &gvar->video);
\r
1337 /*++++ if(playing)
\r
1338 MM_SetLock((memptr *)&audiosegs[playing],false);*/
\r
1341 //==========================================================================
\r
1343 #ifdef __BORLANDC__
\r
1344 extern char global_temp_status_text[512];
\r
1345 extern char global_temp_status_text2[512];
\r
1347 #ifdef __WATCOMC__
\r
1348 //#define MMSMPANVID
\r
1349 #define MMSMSCANINFO
\r
1353 =====================
\r
1357 =====================
\r
1361 void MM_ShowMemory (global_game_variables_t *gvar)
\r
1363 mmblocktype far *scan;
\r
1364 unsigned color,temp,x,y ,w,width;
\r
1366 byte scratch[160],scratch0[4096],str[16];
\r
1367 #ifdef MMSMSCANINFO
\r
1368 mmshowmemoryinfo_t scaninfo[MAXBLOCKS];
\r
1370 unsigned xpos,ypos, oldq,q,maxq;
\r
1371 boolean done,restarted;
\r
1372 ScanCode scancode;
\r
1375 if(!gvar->video.page[0].width) gvar->video.page[0].sw = gvar->video.page[0].width = 320; //to prevent division by 0
\r
1376 //-- VL_SetLineWidth(40, gvar);
\r
1377 //temp = gvar->video.ofs.bufferofs;
\r
1378 //gvar->video.ofs.bufferofs = gvar->video.ofs.displayofs;
\r
1379 temp = BDOFSCONV gvar->video.BOFS;
\r
1380 gvar->video.BOFS = gvar->video.DOFS;
\r
1381 #ifdef MMSMSCANINFO
\r
1382 oldq = 0; restarted = false;
\r
1386 scan = gvar->mm.mmhead;
\r
1390 width = gvar->video.page[0].width;
\r
1392 CA_OpenDebug (gvar);
\r
1395 #ifdef MMSMSCANINFO
\r
1396 scaninfo[q].scan = scan;
\r
1398 strcpy(scratch, AARESET);
\r
1399 if(scan->attributes & PURGEBITS)
\r
1401 color = 6; // dark purple = purgable
\r
1402 strcpy(scratch0, AAMAGENTA); // dark purple = purgable
\r
1404 color = 2; // medium blue = non purgable
\r
1405 strcpy(scratch0, AABLUE); // medium blue = non purgable
\r
1407 if(scan->attributes & LOCKBIT)
\r
1409 color = 1; // red = locked
\r
1410 strcpy(scratch0, AARED); // red = locked
\r
1412 if (scan->start<=end)
\r
1414 printf("\nend==%d\n\n", end);
\r
1415 strcat(scratch, "MM_ShowMemory: Memory block order currupted!\n");
\r
1416 strcat(scratch, "End's Size: ");
\r
1417 ultoa (end,str,10);
\r
1418 strcat (scratch,str);
\r
1419 strcat(scratch, "\nscan->start's Size: ");
\r
1420 ultoa (scan->start,str,10);
\r
1421 strcat (scratch,str);
\r
1422 write(gvar->handle.debughandle,scratch,strlen(scratch));
\r
1423 Quit (gvar, "MM_ShowMemory: Memory block order currupted!");
\r
1425 end = scan->length-1;
\r
1426 y = scan->start/width;
\r
1427 x = scan->start%width;
\r
1428 #ifdef MMSMSCANINFO
\r
1430 y += gvar->video.page[0].dy;
\r
1431 x += gvar->video.page[0].dx;
\r
1435 scaninfo[q].y = y;
\r
1436 scaninfo[q].x = x;
\r
1440 VW_Hlin(x,x+end,y,color,gvar);
\r
1441 VL_Plot(x,y,5,gvar);
\r
1442 //++==++==optional strcat(scratch0, AARESET); strcat(scratch0, AAGREY); strcat(scratch0,"_");
\r
1443 for(w=(scan->start)/80;w<=end/80;w++)
\r
1445 //printf("+ %u %lu\n", w, scan->length);
\r
1446 strcat(scratch0, "+");
\r
1449 if (scan->next && scan->next->start > end+1)
\r
1451 VW_Hlin(x+end+1,x+(scan->next->start-scan->start),y,3,gvar); // black = free//now green
\r
1452 strcat(scratch0, AARESET);
\r
1453 //++==++==optional strcat(scratch0, "\n");
\r
1454 strcat(scratch0,AAGREEN);
\r
1455 for(w=(end+1)/80;w<=((scan->next->start-scan->start)/80);w++)
\r
1457 //printf("0 %x %u %lu\n", scan->next->start, w, scan->length);
\r
1458 strcat(scratch0,"0");
\r
1460 //printf("==================\n");
\r
1461 //printf("w=%u start=%04x next=%04x end=%lu\n", w/80, scan->start, (scan->next->start), end+1);
\r
1462 //printf("==================\n");
\r
1463 strcat(scratch0, "\n");
\r
1466 else {//if(scan->next->start <= scan->start){
\r
1467 scan->next->start=scan->start+0x1000;
\r
1468 strcat(scratch0, AARESET);
\r
1469 strcat(scratch0, "\n");
\r
1470 strcat(scratch0,AAGREEN);
\r
1471 for(w=(end+1);w<=(0x1000/80);w++)
\r
1473 //printf("0 %x %x %u\n", scan->start, w);
\r
1474 strcat(scratch0,"0");
\r
1476 printf("================\n");
\r
1477 printf("w=%x start=%x next=%x end=%u\n", w, scan->start, (scan->next->start), end+1);
\r
1478 printf("================\n");
\r
1482 strcat(scratch0, AARESET);
\r
1483 //strcat(scratch0,"\n");
\r
1484 strcat(scratch,"Seg:");
\r
1485 ultoa (scan->start,str,16);
\r
1486 strcat (scratch,str);
\r
1487 // strcat(scratch, AABLACK); strcat(scratch,"\t"); strcat(scratch, AARESET);
\r
1488 strcat (scratch,"\tSize:");
\r
1489 ultoa ((unsigned)scan->length,str,10);
\r
1490 strcat (scratch,str);
\r
1491 // strcat(scratch, AABLACK); strcat(scratch,"\t"); strcat(scratch, AARESET);
\r
1492 strcat (scratch,"\tOwner:0x");
\r
1493 owner = (unsigned)scan->useptr;
\r
1494 ultoa (owner,str,16);
\r
1495 strcat (scratch,str);
\r
1496 strcat (scratch,"\n");
\r
1497 write(gvar->handle.debughandle,scratch,strlen(scratch));
\r
1498 write(gvar->handle.debughandle,scratch0,strlen(scratch0));
\r
1499 //0000fprintf(stdout, "\n[%s]", scratch);
\r
1500 //0000fprintf(stdout, "[\n%s\n]", scratch0);
\r
1501 //0000fprintf(stdout, "[%u]\n", q);
\r
1503 scan = scan->next;
\r
1504 #ifdef MMSMSCANINFO
\r
1507 //0000if(q==1 && gvar->video.VL_Started && color!=6) IN_Ack(gvar);
\r
1510 CA_CloseDebug (gvar);
\r
1515 int dx,dy,odx,ody;
\r
1516 odx = gvar->video.page[0].dx;
\r
1517 ody = gvar->video.page[0].dy;
\r
1519 while(!gvar->in.inst->Keyboard[sc_Escape] && !gvar->in.inst->Keyboard[sc_Space])
\r
1521 if(gvar->in.inst->Keyboard[sc_UpArrow])
\r
1526 else if(gvar->in.inst->Keyboard[sc_DownArrow])
\r
1528 if(dy<gvar->video.page[0].height-gvar->video.page[0].sh)
\r
1531 if(gvar->in.inst->Keyboard[sc_LeftArrow])
\r
1536 else if(gvar->in.inst->Keyboard[sc_RightArrow])
\r
1538 if(dx<gvar->video.page[0].width-gvar->video.page[0].sw)
\r
1542 modexPanPage(&gvar->video.page[0], dx, dy);
\r
1543 VL_ShowPage(&gvar->video.page[0], 1, 1);
\r
1546 gvar->video.page[0].dx = odx;
\r
1547 gvar->video.page[0].dy = ody;
\r
1550 #ifdef MMSMSCANINFO
\r
1551 //#define MMSMSCANINFOXYPOSNEW
\r
1554 if(restarted) q = oldq;
\r
1556 restarted = false;
\r
1559 // VL_ClearVideo (8);
\r
1560 for (done = false;!done;)
\r
1562 if(scaninfo[q].scan->attributes & PURGEBITS)
\r
1564 color = 6; // dark purple = purgable
\r
1565 strcpy(scratch1, AAMAGENTA); // dark purple = purgable
\r
1566 //printf("%s", AAMAGENTA);
\r
1568 color = 2; // medium blue = non purgable
\r
1569 strcpy(scratch1, AABLUE); // medium blue = non purgable
\r
1570 //printf("%s", AABLUE);
\r
1572 if(scaninfo[q].scan->attributes & LOCKBIT)
\r
1574 color = 1; // red = locked
\r
1575 strcpy(scratch1, AARED); // red = locked
\r
1576 //printf("%s", AARED);
\r
1578 end = scaninfo[q].scan->length-1;
\r
1579 //modexprint(page, x, y, t, tlsw, color, bgcolor, vidsw, const byte *str);
\r
1580 #define MMSMPRINTMEMINFO modexprint(&(gvar->video.page[0]), xpos, ypos, 1, 1, color, 8, gvar->video.VL_Started, global_temp_status_text); ypos+=8;
\r
1581 #ifdef __WATCOMC__
\r
1582 if(gvar->video.VL_Started)
\r
1584 VL_ShowPage(&gvar->video.page[0], 1, 0);
\r
1585 modexClearRegion(&gvar->video.page[0], 0, 0, gvar->video.page[0].width, gvar->video.page[0].height, 8);
\r
1589 sprintf(global_temp_status_text, "block #%04u", q); MMSMPRINTMEMINFO
\r
1590 // sprintf(global_temp_status_text, "%Fp", scaninfo[q].scan->useptr); MMSMPRINTMEMINFO
\r
1591 sprintf(global_temp_status_text, "start: %04x", (unsigned)scaninfo[q].scan->start); MMSMPRINTMEMINFO
\r
1592 sprintf(global_temp_status_text, "useptr: %04x", (unsigned)scaninfo[q].scan->useptr); MMSMPRINTMEMINFO
\r
1593 sprintf(global_temp_status_text, "size: %05u", (unsigned)scaninfo[q].scan->length); MMSMPRINTMEMINFO
\r
1594 if (scaninfo[q].scan->next && scaninfo[q].scan->next->start > end+1)
\r
1596 sprintf(global_temp_status_text, "free: %05u", (unsigned)(scaninfo[q].scan->next->start-scaninfo[q].scan->start)); MMSMPRINTMEMINFO
\r
1598 if(gvar->video.VL_Started)
\r
1600 y = scaninfo[q].scan->start/width;
\r
1601 x = scaninfo[q].scan->start%width;
\r
1602 #ifndef MMSMSCANINFOXYPOSNEW
\r
1606 //y = scaninfo[q].y;
\r
1607 //x = scaninfo[q].x;
\r
1608 y += gvar->video.page[0].dy;
\r
1609 x += gvar->video.page[0].dx;
\r
1611 VW_Hlin(x,x+end,y,color,gvar);
\r
1612 VL_Plot(x,y,5,gvar);
\r
1616 printf("%s", scratch1);
\r
1617 printf("%s", AAGREY); printf("_");
\r
1618 if(scaninfo[q].scan->length<64000)
\r
1619 for(w=(scaninfo[q].scan->start)/80;w<=end/80;w++)
\r
1621 //strcat(scratch1, "+");
\r
1627 if (scaninfo[q].scan->next && scaninfo[q].scan->next->start > end+1) if(!gvar->video.VL_Started)
\r
1629 //strcat(scratch1, AARESET);
\r
1630 printf("%s", AARESET);
\r
1631 //strcat(scratch1,AAGREEN);
\r
1632 printf("%s", AAGREEN);
\r
1633 for(w=(end+1)/80;w<=((scaninfo[q].scan->next->start-scaninfo[q].scan->start)/80);w++)
\r
1635 //strcat(scratch1,"0");
\r
1638 }else VW_Hlin(x+end+1,x+(scaninfo[q].scan->next->start-scaninfo[q].scan->start),y,3,gvar); // black = free//now green
\r
1641 if(gvar->video.VL_Started)
\r
1643 //if (scan->next && scan->next->start > end+1) free
\r
1644 xpos = gvar->video.page[0].dx;
\r
1645 ypos = gvar->video.page[0].dy;//(gvar->video.page[0].sh-(32));//8*4
\r
1649 //printf("%s\n", scratch1);
\r
1650 printf("%s", AARESET);
\r
1655 while (!(scancode = gvar->in.inst->LastScan)){}
\r
1657 IN_ClearKey(scancode);
\r
1660 case sc_LeftArrow:
\r
1664 case sc_RightArrow:
\r
1672 case sc_DownArrow:
\r
1673 if(q<maxq+10) q+=10;
\r
1677 // scan = gvar->mm.mmhead;
\r
1678 // x = gvar->video.page[0].dx;
\r
1679 // y = gvar->video.page[0].dy;//(gvar->video.page[0].sh-(32));//8*4
\r
1690 // MM_ShowMemoryDetail (x, y, w, q, end, &scaninfo, gvar);
\r
1694 //?? if(gvar->video.VL_Started) IN_Ack(gvar);
\r
1696 gvar->video.BOFS = (byte __far *)temp;
\r
1700 //def MMSMSCANINFO
\r
1701 void MM_ShowMemoryDetail (unsigned x, unsigned y, unsigned w, unsigned q, sdword end, mmshowmemoryinfo_t *scaninfo, global_game_variables_t *gvar)
\r
1704 unsigned maxq = q;
\r
1706 ScanCode scancode;
\r
1710 // VL_ClearVideo (8);
\r
1711 for (q = 0,done = false;!done;)
\r
1713 if(scaninfo[q].scan->attributes & PURGEBITS)
\r
1715 ccolor = 6; // dark purple = purgable
\r
1716 strcpy(scratch1, AAMAGENTA); // dark purple = purgable
\r
1717 //printf("%s", AAMAGENTA);
\r
1719 ccolor = 2; // medium blue = non purgable
\r
1720 strcpy(scratch1, AABLUE); // medium blue = non purgable
\r
1721 //printf("%s", AABLUE);
\r
1723 if(scaninfo[q].scan->attributes & LOCKBIT)
\r
1725 ccolor = 1; // red = locked
\r
1726 strcpy(scratch1, AARED); // red = locked
\r
1727 //printf("%s", AARED);
\r
1729 end = scaninfo[q].scan->length-1;
\r
1730 //modexprint(page, x, y, t, tlsw, color, bgcolor, vidsw, const byte *str);
\r
1731 #define MMSMPRINTMEMINFO modexprint(&(gvar->video.page[0]), xpos, ypos, 1, 1, ccolor, 8, gvar->video.VL_Started, global_temp_status_text); ypos+=8;
\r
1732 #ifdef __WATCOMC__
\r
1733 if(gvar->video.VL_Started)
\r
1735 VL_ShowPage(&gvar->video.page[0], 1, 0);
\r
1736 modexClearRegion(&gvar->video.page[0], 0, 0, gvar->video.page[0].width, gvar->video.page[0].height, 8);
\r
1740 sprintf(global_temp_status_text, "block #%04u", q); MMSMPRINTMEMINFO
\r
1741 // sprintf(global_temp_status_text, "%Fp", scaninfo[q].scan->useptr); MMSMPRINTMEMINFO
\r
1742 sprintf(global_temp_status_text, "start: %04x", (unsigned)scaninfo[q].scan->start); MMSMPRINTMEMINFO
\r
1743 sprintf(global_temp_status_text, "useptr: %04x", (unsigned)scaninfo[q].scan->useptr); MMSMPRINTMEMINFO
\r
1744 sprintf(global_temp_status_text, "size: %05u", (unsigned)scaninfo[q].scan->length); MMSMPRINTMEMINFO
\r
1745 if (scaninfo[q].scan->next && scaninfo[q].scan->next->start > end+1)
\r
1747 sprintf(global_temp_status_text, "free: %05u", (unsigned)(scaninfo[q].scan->next->start-scaninfo[q].scan->start)); MMSMPRINTMEMINFO
\r
1749 if(gvar->video.VL_Started)
\r
1751 y = ypos;//scaninfo[q].scan->start/width;
\r
1752 x = xpos;//scaninfo[q].scan->start%width;
\r
1753 VW_Hlin(x,x+end,y,ccolor,gvar);
\r
1754 VL_Plot(x,y,5,gvar);
\r
1758 printf("%s", scratch1);
\r
1759 printf("%s", AAGREY); printf("_");
\r
1760 if(scaninfo[q].scan->length<64000)
\r
1761 for(w=(scaninfo[q].scan->start)/80;w<=end/80;w++)
\r
1763 //strcat(scratch1, "+");
\r
1769 if (scaninfo[q].scan->next && scaninfo[q].scan->next->start > end+1) if(!gvar->video.VL_Started)
\r
1771 //strcat(scratch1, AARESET);
\r
1772 printf("%s", AARESET);
\r
1773 //strcat(scratch1,AAGREEN);
\r
1774 printf("%s", AAGREEN);
\r
1775 for(w=(end+1)/80;w<=((scaninfo[q].scan->next->start-scaninfo[q].scan->start)/80);w++)
\r
1777 //strcat(scratch1,"0");
\r
1780 }else VW_Hlin(x+end+1,x+(scaninfo[q].scan->next->start-scaninfo[q].scan->start),y,3,gvar); // black = free//now green
\r
1783 if(gvar->video.VL_Started)
\r
1785 //if (scan->next && scan->next->start > end+1) free
\r
1786 xpos = gvar->video.page[0].dx;
\r
1787 ypos = gvar->video.page[0].dy;//(gvar->video.page[0].sh-(32));//8*4
\r
1791 //printf("%s\n", scratch1);
\r
1792 printf("%s", AARESET);
\r
1795 //0000printf("%s", AABLACK); fprintf(stdout, "q=%u maxq=%u\n", q, maxq); printf("%s", AARESET);
\r
1796 //fprintf(stdout, ""); //this is a HAX to make it decrement and increment properly when it is at 0 and qmax
\r
1797 while (!(scancode = gvar->in.inst->LastScan)){}
\r
1799 IN_ClearKey(scancode);
\r
1802 case sc_LeftArrow:
\r
1806 case sc_RightArrow:
\r
1814 case sc_DownArrow:
\r
1815 if(q<maxq+10) q+=10;
\r
1826 //==========================================================================
\r
1829 =====================
\r
1833 =====================
\r
1836 void MM_DumpData (global_game_variables_t *gvar)
\r
1838 mmblocktype far *scan,far *best;
\r
1839 long lowest,oldlowest;
\r
1844 _nfree(gvar->mm.nearheap);
\r
1845 dumpfile = fopen (gvar->handle.datadumpfilename, "w");
\r
1847 Quit (gvar, "MM_DumpData: Couldn't open MMDUMP.16!\n");
\r
1852 oldlowest = lowest;
\r
1855 scan = gvar->mm.mmhead;
\r
1858 owner = (unsigned)scan->useptr;
\r
1860 if (owner && owner<lowest && owner > oldlowest)
\r
1866 scan = scan->next;
\r
1869 if (lowest != 0xffff)
\r
1871 if (best->attributes & PURGEBITS)
\r
1875 if (best->attributes & LOCKBIT)
\r
1879 fprintf (dumpfile,"0x%p (%c%c) = %u\n"
\r
1880 ,(unsigned)lowest,lock,purge,best->length);
\r
1883 } while (lowest != 0xffff);
\r
1885 fclose (dumpfile);
\r
1888 #ifdef __BORLANDC__
\r
1889 strcpy(gvar->handle.datadumpfilename, "mmdump.16b");
\r
1891 #ifdef __WATCOMC__
\r
1892 strcpy(gvar->handle.datadumpfilename, "mmdump.16w");
\r
1894 //00 printf ("MMDUMP.16 created.\n");
\r
1897 //==========================================================================
\r
1901 ======================
\r
1905 = Returns the total free space without purging
\r
1907 ======================
\r
1910 dword MM_UnusedMemory (global_game_variables_t *gvar)
\r
1913 mmblocktype far *scan;
\r
1916 scan = gvar->mm.mmhead;
\r
1920 free += scan->next->start - (scan->start + scan->length);
\r
1921 scan = scan->next;
\r
1927 //==========================================================================
\r
1931 ======================
\r
1935 = Returns the total free space with purging
\r
1937 ======================
\r
1940 dword MM_TotalFree (global_game_variables_t *gvar)
\r
1943 mmblocktype far *scan;
\r
1946 scan = gvar->mm.mmhead;
\r
1950 if((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
\r
1951 free += scan->length;
\r
1952 free += scan->next->start - (scan->start + scan->length);
\r
1953 scan = scan->next;
\r
1959 //==========================================================================
\r
1962 =====================
\r
1966 =====================
\r
1969 void MM_Report_ (global_game_variables_t *gvar)
\r
1971 printf("========================================\n");
\r
1972 printf(" MM_Report_\n");
\r
1973 printf("========================================\n");
\r
1974 if(MML_CheckForEMS())
\r
1976 printf(" %cLIMEMS %u\n", 0xC9, gvar->pm.emm.EMSPresent);
\r
1977 printf(" %c%cEMM v%x.%x available\n", 0xC7, 0xC4, gvar->pm.emm.EMSVer>>4,gvar->pm.emm.EMSVer&0x0F);
\r
1978 printf(" %c%ctotalEMSpages: %u ", 0xC7, 0xC4, gvar->pm.emm.totalEMSpages); printf("freeEMSpages: %u\n", gvar->pm.emm.freeEMSpages);
\r
1979 printf(" %c%cEMSPageFrame: %04x\n", 0xC7, 0xC4, gvar->pm.emm.EMSPageFrame);
\r
1980 printf(" %c%cEMSmem: %lu\n", 0xD3, 0xC4, gvar->mmi.EMSmem);
\r
1982 if(MML_CheckForXMS())
\r
1984 printf(" %cXMS %u\n", 0xC9, gvar->pm.xmm.XMSPresent);
\r
1985 printf(" %c%cXMS v%x.%x available\n", 0xC7, 0xC4, XMSVer>>8,XMSVer&0x0F);
\r
1986 printf(" %c%cXMSDriver: %Fp\n", 0xC7, 0xC4, XMSDriver);
\r
1987 printf(" %c%cXMSHandle: %04x\n", 0xC7, 0xC4, gvar->pm.xmm.XMSHandle);
\r
1988 printf(" %c%cXMSmem: %lu\n", 0xD3, 0xC4, gvar->mmi.XMSmem);
\r
1990 printf(" %cConv. %u\n", 0xC9, gvar->pm.mm.MainPresent); DebugMemory_(gvar, 0);
\r
1991 //printf("mainmem: %lu\n", gvar->mmi.mainmem);
\r
1992 //printf("Total convmem: %lu ", gvar->mmi.mainmem); printf("TotalFree: %lu ", MM_TotalFree(gvar)+gvar->mmi.EMSmem+gvar->mmi.XMSmem+gvar->mmi.XMSmem); printf("TotalUsed: %lu\n", gvar->mmi.mainmem);
\r
1993 //printf(" UnusedMemory: %lu\n", MM_UnusedMemory(gvar));
\r
1994 printf("nearheap: %lu ", gvar->mmi.nearheap); printf("farheap: %lu\n", gvar->mmi.farheap);
\r
1997 //==========================================================================
\r
2000 =====================
\r
2004 =====================
\r
2007 void MM_EMSerr(byte *stri, byte err)
\r
2009 //Returns a text string describing the error code in EMS.Error.
\r
2013 strcat(stri, "successful");
\r
2016 strcat(stri, "internal error");
\r
2019 strcat(stri, "hardware malfunction");
\r
2022 strcat(stri, "busy .. retry later");
\r
2025 strcat(stri, "invalid handle");
\r
2028 strcat(stri, "undefined function requested by application");
\r
2031 strcat(stri, "no more handles available");
\r
2034 strcat(stri, "error in save or restore of mapping context");
\r
2037 strcat(stri, "insufficient memory pages in system");
\r
2040 strcat(stri, "insufficient memory pages available");
\r
2043 strcat(stri, "zero pages requested");
\r
2046 strcat(stri, "invalid logical page number encountered");
\r
2049 strcat(stri, "invalid physical page number encountered");
\r
2052 strcat(stri, "page-mapping hardware state save area is full");
\r
2055 strcat(stri, "save of mapping context failed");
\r
2058 strcat(stri, "restore of mapping context failed");
\r
2061 strcat(stri, "undefined subfunction");
\r
2064 strcat(stri, "undefined attribute type");
\r
2067 strcat(stri, "feature not supported");
\r
2070 strcat(stri, "successful, but a portion of the source region has been overwritten");
\r
2073 strcat(stri, "length of source or destination region exceeds length of region allocated to either source or destination handle");
\r
2076 strcat(stri, "conventional and expanded memory regions overlap");
\r
2079 strcat(stri, "offset within logical page exceeds size of logical page");
\r
2082 strcat(stri, "region length exceeds 1 MB");
\r
2085 strcat(stri, "source and destination EMS regions have same handle and overlap");
\r
2088 strcat(stri, "memory source or destination type undefined");
\r
2091 strcat(stri, "specified alternate map register or DMA register set not supported");
\r
2094 strcat(stri, "all alternate map register or DMA register sets currently allocated");
\r
2097 strcat(stri, "alternate map register or DMA register sets not supported");
\r
2100 strcat(stri, "undefined or unallocated alternate map register or DMA register set");
\r
2103 strcat(stri, "dedicated DMA channels not supported");
\r
2106 strcat(stri, "specified dedicated DMA channel not supported");
\r
2109 strcat(stri, "no such handle name");
\r
2112 strcat(stri, "a handle found had no name, or duplicate handle name");
\r
2115 strcat(stri, "attempted to wrap around 1M conventional address space");
\r
2118 strcat(stri, "source array corrupted");
\r
2121 strcat(stri, "operating system denied access");
\r
2124 strcat(stri, "undefined error");
\r
2128 //==========================================================================
\r
2131 =====================
\r
2135 =====================
\r
2138 void MM_BombOnError (boolean bomb, global_game_variables_t *gvar)
\r
2140 gvar->mm.bombonerror = bomb;
\r
2144 void MM_GetNewBlock(global_game_variables_t *gvar)
\r
2146 if(!gvar->mm.mmfree)
\r
2147 MML_ClearBlock(gvar);
\r
2148 gvar->mm.mmnew=gvar->mm.mmfree;
\r
2149 gvar->mm.mmfree=gvar->mm.mmfree->next;
\r
2150 if(!(gvar->mm.mmnew=gvar->mm.mmfree))
\r
2152 printf("MM_GETNEWBLOCK: No free blocks!\n");
\r
2155 gvar->mm.mmfree=gvar->mm.mmfree->next;
\r
2158 void MM_FreeBlock(mmblocktype *x, global_game_variables_t *gvar)
\r
2161 x->next=gvar->mm.mmfree;
\r
2162 gvar->mm.mmfree=x;
\r
2166 void xms_call(byte v, global_game_variables_t *gvar)
\r
2168 dword XMSDriver = gvar->pm.xmm.XMSDriver;
\r
2171 call [DWORD PTR XMSDriver]
\r
2175 /*void MM_seguin(void)
\r
2185 void MM_segude(void)
\r
2193 pull data from far and put it into ds var
\r
2200 bp bottem of stack
\r