]> 4ch.mooo.com Git - 16.git/commitdiff
==== UNTESTED major tweaking has been done to the core memory module stuff 16_mm...
authorsparky4 <sparky4@cock.li>
Tue, 20 Sep 2016 21:07:25 +0000 (16:07 -0500)
committersparky4 <sparky4@cock.li>
Tue, 20 Sep 2016 21:07:25 +0000 (16:07 -0500)
makefile
pm.use
src/exmmtest.c
src/lib/16_ca.c
src/lib/16_head.h
src/lib/16_mm.c
src/lib/16_mm.h
src/lib/16_pm.c
src/lib/16_pm.h
src/lib/typdefst.h
src/vrstest.c

index 7c2d12c23be19d89230e41c27ee5ce4f7dabbacb..e150bce8a6228be29a1c238a025285e62a6d576f 100755 (executable)
--- a/makefile
+++ b/makefile
@@ -91,7 +91,7 @@ UPXQ=-qqq
 S_FLAGS=-sg -st -of+ -zu -zdf -zff -zgf -k32768#54096#60000
 Z_FLAGS=-zk0 -zc -zp8 -zm
 O_FLAGS=-obmilr -oe=24 -out -oh -ei -onac -ol+ -ok##x
-T_FLAGS=-bt=dos -mh -0 -fpi87 -fo=.$(OBJ) -d1 -e=20
+T_FLAGS=-bt=dos -mh -0 -fpi87 -fo=.$(OBJ) -d1 -e=65536
 
 CPPFLAGS=-DTARGET_MSDOS=16 -DMSDOS=1
 !ifeq DEBUGSERIAL 1
@@ -106,7 +106,7 @@ LIBFLAGS=$(WLIBQ) -b -n
 # objects
 #
 VGMSNDOBJ = vgmSnd.$(OBJ) 16_snd.$(OBJ)
-16LIBOBJS = 16_lib.$(OBJ) 16_in.$(OBJ) 16_mm.$(OBJ) wcpu.$(OBJ) 16_head.$(OBJ) 16_ca.$(OBJ) 16_dbg.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ) 16_timer.$(OBJ)
+16LIBOBJS = 16_lib.$(OBJ) 16_in.$(OBJ) 16_mm.$(OBJ) wcpu.$(OBJ) 16_head.$(OBJ) 16_ca.$(OBJ) 16_dbg.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ) 16_timer.$(OBJ) 16_pm.$(OBJ)
 GFXLIBOBJS = modex16.$(OBJ) bitmap.$(OBJ) 16text.$(OBJ) bakapee.$(OBJ) scroll16.$(OBJ) 16render.$(OBJ) 16_vrs.$(OBJ) 16_sprit.$(OBJ) #scroll16.$(OBJ)
 #16planar.$(OBJ) planar.$(OBJ)
 DOSLIBOBJ = adlib.$(OBJ) 8254.$(OBJ) 8259.$(OBJ) dos.$(OBJ) cpu.$(OBJ)
diff --git a/pm.use b/pm.use
index a255a3a3a60237ca64ebd8f8e9d667576c466bb0..fbd7a2c7333e0bbccd830cfba456f3c9c3fe02fa 100755 (executable)
--- a/pm.use
+++ b/pm.use
@@ -270,3 +270,8 @@ Binary file 16/wolf3d/WOLFSRC/WOLF3D.EXE matches
 16/wolf3d/WOLFSRC/WOLF3D.MAP: 1912:114B       _PM_Shutdown\r
 16/wolf3d/WOLFSRC/WOLFHACK.C:  src = PM_GetPage(0);\r
 16/wolf3d/WOLFSRC/WOLFHACK.C:  src = PM_GetPage(1);\r
+\r
+16/wf3d8086/id_pm.c:           longword last = MAXLONG;\r
+16/wf3d8086/id_pm.c:   for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < ChunksInFile;i++,page++)\r
+16/wf3d8086/id_pm.c:   for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < ChunksInFile;i++,page++)\r
+16/wf3d8086/id_pm.c:   if (++PMFrameCount >= MAXLONG - 4)\r
index 1bd9671f2ffe15017ac32c68bc5fddfa42d1f0b0..ff8be1df8f353cf10c58bf09442eefdde2c39b1d 100755 (executable)
@@ -95,7 +95,7 @@ main(int argc, char *argv[])
                bakapee2 = "data/test.map";\r
        }\r
 //     printf("main()=%Fp      start MM\n", *argv[0]);\r
-       MM_Startup(&gvar.mm, &gvar.mmi);\r
+       MM_Startup(&gvar);\r
        //PM_Startup();\r
        //PM_UnlockMainMem();\r
        CA_Startup(&gvar);\r
@@ -133,7 +133,7 @@ for(w=0;w<2;w++)
        printf("press any key to continue!\n");\r
        getch();\r
        MM_ShowMemory(&gvar);\r
-       MM_DumpData(&gvar.mm);\r
+       MM_DumpData(&gvar);\r
        MM_Report_(&gvar);\r
        if(baka) printf("\nyay!\n");\r
        else printf("\npoo!\n");\r
@@ -142,10 +142,10 @@ for(w=0;w<2;w++)
 #ifdef FILEREAD\r
 }\r
 #endif\r
-       MM_FreePtr(&bigbuffer, &gvar.mm);\r
+       MM_FreePtr(&bigbuffer, &gvar);\r
        //PM_Shutdown();\r
        CA_Shutdown(&gvar);\r
-       MM_Shutdown(&gvar.mm);\r
+       MM_Shutdown(&gvar);\r
        free(bakapee1); free(bakapee2);\r
        printf("========================================\n");\r
        printf("near=   %Fp ", gvar.mm.nearheap);\r
index 27e2d7ee366c94c49a3e3187fbded08af6625ae6..e2803808a47389d6202f2f870c3dfbea4fb445d6 100755 (executable)
@@ -226,7 +226,7 @@ boolean CA_FarRead(int handle, byte huge *dest, dword length, global_game_variab
        boolean flag;\r
        //dword fat=0;\r
        //word segm=0;\r
-       if(gvar->mm.EMSVer<0x40)\r
+       if(gvar->pm.emm.EMSVer<0x40)\r
        if(length>0xfffflu)\r
        {\r
                printf("File is a fat bakapee\n");\r
@@ -298,7 +298,7 @@ boolean CA_FarWrite(int handle, byte huge *source, dword length, global_game_var
        boolean flag;\r
        //dword fat=0;\r
        //word segm=0;\r
-       if(gvar->mm.EMSVer<0x40)\r
+       if(gvar->pm.emm.EMSVer<0x40)\r
        if(length>0xfffflu)\r
        {\r
                printf("File is a fat bakapee\n");\r
@@ -438,7 +438,7 @@ boolean CA_LoadFile(char *filename, memptr *ptr, global_game_variables_t *gvar)
                return false;\r
 \r
        size = filelength(handle);\r
-       MM_GetPtr(ptr,size, &(gvar->mm), &(gvar->mmi)); //TODO: gvar parameters\r
+       MM_GetPtr(ptr,size, gvar);\r
        if(!CA_FarRead(handle,*ptr,size, gvar))\r
        {\r
                close(handle);\r
index b840043d4fd149606472f7f4ae2d00d84c585642..baa983e8e9a1c23324cd0fcaf648816b312affe6 100755 (executable)
@@ -42,6 +42,7 @@
 #include <sys/stat.h>\r
 #include <mem.h>\r
 #include <string.h>\r
+#include <limits.h>\r
 #ifdef __WATCOMC__\r
 #include <i86.h>\r
 #include <unistd.h>\r
@@ -161,20 +162,6 @@ extern     int                     profilehandle,debughandle;      //make it into game global
 #define _FCORELEFT 0x90000UL+16UL\r
 extern union REGS CPURegs;\r
 \r
-#define _AX CPURegs.x.ax\r
-#define _BX CPURegs.x.bx\r
-#define _CX CPURegs.x.cx\r
-#define _DX CPURegs.x.dx\r
-\r
-#define _AH CPURegs.h.ah\r
-#define _AL CPURegs.h.al\r
-#define _BH CPURegs.h.bh\r
-#define _BL CPURegs.h.bl\r
-#define _CH CPURegs.h.ch\r
-#define _CL CPURegs.h.cl\r
-#define _DH CPURegs.h.dh\r
-#define _DL CPURegs.h.dl\r
-\r
 #define geninterrupt(n) int86(n,&CPURegs,&CPURegs);\r
 #define peekb(segm,ofs) (*(byte far*)MK_FP((segm),(ofs)))\r
 #define peekw(segm,ofs) (*(word far*)MK_FP((segm),(ofs)))\r
index d14479d5e1b2075efe44aa738813cdb74ea7f8bb..f253768500d8c97e293b62f182444332295fcb1e 100755 (executable)
@@ -149,7 +149,7 @@ boolean MML_CheckForEMS(void)
 =======================
 */
 
-byte MML_SetupEMS(mminfo_t *mm)
+byte MML_SetupEMS(global_game_variables_t *gvar)
 {
        byte    str[160];
        byte    err;
@@ -245,12 +245,12 @@ End:
                printf("%s\n",str);
                return err;
        }
-       mm->totalEMSpages=totalEMSpages;
-       mm->freeEMSpages=freeEMSpages;
-       mm->EMSpageframe=EMSpageframe;
-       mm->EMSpagesmapped=EMSpagesmapped;
-       mm->EMShandle=EMShandle;
-       mm->EMSVer=EMSVer;
+       gvar->mm.totalEMSpages=totalEMSpages;
+       gvar->mm.freeEMSpages=freeEMSpages;
+       gvar->mm.EMSpageframe=EMSpageframe;
+       gvar->mm.EMSpagesmapped=EMSpagesmapped;
+       gvar->mm.EMShandle=EMShandle;
+       gvar->pm.emm.EMSVer=EMSVer;
        return 0;
 }
 
@@ -263,10 +263,10 @@ End:
 =======================
 */
 
-void MML_ShutdownEMS(mminfo_t *mm)
+void MML_ShutdownEMS(global_game_variables_t *gvar)
 {
        boolean errorflag=false;
-       unsigned EMShandle=mm->EMShandle;
+       unsigned EMShandle=gvar->mm.EMShandle;
 
        if(!EMShandle)
                return;
@@ -300,14 +300,14 @@ void MML_ShutdownEMS(mminfo_t *mm)
 ====================
 */
 
-byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi)
+byte MM_MapEMS(global_game_variables_t *gvar)
 {
        byte    str[160];
        unsigned        EMShandle;
        byte err;
        boolean errorflag=false;
        int     i;
-       EMShandle=mm->EMShandle;
+       EMShandle=gvar->mm.EMShandle;
 
        for (i=0;i<4/*MAPPAGES*/;i++)
        {
@@ -344,12 +344,12 @@ byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi)
                        return err;
                }
        }
-       mmi->EMSmem = (i)*0x4000lu;
-       //printf("              mmi->EMSmem=%lu\n", mmi->EMSmem);
+       gvar->mmi.EMSmem = (i)*0x4000lu;
+       //printf("              gvar->mmi.EMSmem=%lu\n", gvar->mmi.EMSmem);
        return 0;
 }
 
-byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
+byte MM_MapXEMS(global_game_variables_t *gvar)
 {
 //SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)
 
@@ -378,9 +378,9 @@ byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
        word    EMShandle;
        boolean errorflag=false;
        int     i;
-       EMShandle=mm->EMShandle;
+       EMShandle=gvar->mm.EMShandle;
 
-       if(mm->EMSVer<0x40)
+       if(gvar->pm.emm.EMSVer<0x40)
                return 5;
 
        for (i=0;i<MAPPAGES;i++)
@@ -422,7 +422,7 @@ byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
                        return err;
                }
        }
-       mmi->EMSmem = (i)*0x4000lu;
+       gvar->mmi.EMSmem = (i)*0x4000lu;
        return 0;
 }
 
@@ -438,10 +438,10 @@ byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
 =======================
 */
 
-boolean MML_CheckForXMS(mminfo_t *mm)
+boolean MML_CheckForXMS(global_game_variables_t *gvar)
 {
        boolean errorflag=false;
-       mm->numUMBs = 0;
+       gvar->mm.numUMBs = 0;
 
        __asm {
                mov     ax,0x4300
@@ -471,7 +471,7 @@ boolean MML_CheckForXMS(mminfo_t *mm)
 =======================
 */
 
-void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
+void MML_SetupXMS(global_game_variables_t *gvar)
 {
        word    base,size;
 
@@ -515,11 +515,11 @@ getmemory:
        }
 #endif
 //     printf("base=%u ", base); printf("size=%u\n", size);
-       MML_UseSpace(base,size, mm);
-       mmi->XMSmem += size*16;
-       mm->UMBbase[mm->numUMBs] = base;
-       mm->numUMBs++;
-       if(mm->numUMBs < MAXUMBS)
+       MML_UseSpace(base,size, gvar);
+       gvar->mmi.XMSmem += size*16;
+       gvar->mm.UMBbase[gvar->mm.numUMBs] = base;
+       gvar->mm.numUMBs++;
+       if(gvar->mm.numUMBs < MAXUMBS)
                goto getmemory;
 }
 
@@ -532,14 +532,14 @@ getmemory:
 ======================
 */
 
-void MML_ShutdownXMS(mminfo_t *mm)
+void MML_ShutdownXMS(global_game_variables_t *gvar)
 {
        int     i;
        unsigned        base;
 
-       for (i=0;i<mm->numUMBs;i++)
+       for (i=0;i<gvar->mm.numUMBs;i++)
        {
-               base = mm->UMBbase[i];
+               base = gvar->mm.UMBbase[i];
                __asm {
                        mov     ah,XMS_FREEUMB
                        mov     dx,[base]
@@ -562,7 +562,7 @@ void MML_ShutdownXMS(mminfo_t *mm)
 ======================
 */
 
-/*void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
+/*void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *scan,huge *last;
        word            segm=1;
@@ -570,8 +570,8 @@ void MML_ShutdownXMS(mminfo_t *mm)
        dword           segmlen;
        dword           extra;
 
-       scan = last = mm->mmhead;
-       mm->mmrover = mm->mmhead;               // reset rover to start of memory
+       scan = last = gvar->mm.mmhead;
+       gvar->mm.mmrover = gvar->mm.mmhead;             // reset rover to start of memory
 
 //
 // search for the block that contains the range of segments
@@ -596,7 +596,7 @@ void MML_ShutdownXMS(mminfo_t *mm)
        {
                scan->blob=segm;
 
-               //MML_UseSpace(segstart, seglength, mm);
+               //MML_UseSpace(segstart, seglength, gvar);
 
                printf("MML_UseSpace: Segment spans two blocks!\n");
        //}
@@ -622,25 +622,25 @@ void MML_ShutdownXMS(mminfo_t *mm)
        if(extra > 0)
        {
                GETNEWBLOCK;
-               mm->mmnew->useptr = NULL;
+               gvar->mm.mmnew->useptr = NULL;
 
-               mm->mmnew->next = scan->next;
-               scan->next = mm->mmnew;
-               mm->mmnew->start = segstart+seglength;
-               mm->mmnew->length = extra;
-               mm->mmnew->attributes = LOCKBIT;
+               gvar->mm.mmnew->next = scan->next;
+               scan->next = gvar->mm.mmnew;
+               gvar->mm.mmnew->start = segstart+seglength;
+               gvar->mm.mmnew->length = extra;
+               gvar->mm.mmnew->attributes = LOCKBIT;
        }//else if(segm>0) goto segu;
 
 }*/
-void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
+void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar)
 {
        mmblocktype far *scan,far *last;
        word    oldend;
        sdword          extra;
        //word segm=1;
 
-       scan = last = mm->mmhead;
-       mm->mmrover = mm->mmhead;               // reset rover to start of memory
+       scan = last = gvar->mm.mmhead;
+       gvar->mm.mmrover = gvar->mm.mmhead;             // reset rover to start of memory
 
 //
 // search for the block that contains the range of segments
@@ -692,13 +692,13 @@ void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
        if (extra > 0)
        {
                GETNEWBLOCK;
-               mm->mmnew->useptr = NULL;
+               gvar->mm.mmnew->useptr = NULL;
 
-               mm->mmnew->next = scan->next;
-               scan->next = mm->mmnew;
-               mm->mmnew->start = segstart+seglength;
-               mm->mmnew->length = extra;
-               mm->mmnew->attributes = LOCKBIT;
+               gvar->mm.mmnew->next = scan->next;
+               scan->next = gvar->mm.mmnew;
+               gvar->mm.mmnew->start = segstart+seglength;
+               gvar->mm.mmnew->length = extra;
+               gvar->mm.mmnew->attributes = LOCKBIT;
        }
 
 }
@@ -715,18 +715,18 @@ void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
 ====================
 */
 
-void MML_ClearBlock(mminfo_t *mm)
+void MML_ClearBlock(global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *scan,huge *last;
        mmblocktype far *scan,far *last;
 
-       scan = mm->mmhead->next;
+       scan = gvar->mm.mmhead->next;
 
        while(scan)
        {
                if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS))
                {
-                       MM_FreePtr(scan->useptr, mm);
+                       MM_FreePtr(scan->useptr, gvar);
                        return;
                }
                scan = scan->next;
@@ -749,7 +749,7 @@ void MML_ClearBlock(mminfo_t *mm)
 ===================
 */
 
-void MM_Startup(mminfo_t *mm, mminfotype *mmi)
+void MM_Startup(global_game_variables_t *gvar)
 {
        int i;
        //dword length,seglength;
@@ -759,34 +759,34 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
        word    segstart;//,endfree;
        //memptr *peeonself;
 
-//     if(mm->mmstarted)
-//             MM_Shutdown(mm);
+       if(gvar->mm.mmstarted)
+               MM_Shutdown(gvar);
 
-       mm->mmstarted = true;
-       mm->bombonerror = true;
+       gvar->mm.mmstarted = true;
+       gvar->mm.bombonerror = true;
 
 //
 // set up the linked list (everything in the free list;
 //
-       mm->mmhead = NULL;
-       mm->mmfree = &(mm->mmblocks[0]);
+       gvar->mm.mmhead = NULL;
+       gvar->mm.mmfree = &(gvar->mm.mmblocks[0]);
        for(i=0;i<MAXBLOCKS-1;i++)
        {
-               mm->mmblocks[i].next = &(mm->mmblocks[i+1]);
+               gvar->mm.mmblocks[i].next = &(gvar->mm.mmblocks[i+1]);
        }
-       mm->mmblocks[i].next = NULL;
+       gvar->mm.mmblocks[i].next = NULL;
 
 //
 // locked block of all memory until we punch out free space
 //
        GETNEWBLOCK;
-       mm->mmhead = mm->mmnew;                         // this will allways be the first node
-       mm->mmnew->start = 0;
-       mm->mmnew->length = 0xffff;
-       mm->mmnew->attributes = LOCKBIT;
-       mm->mmnew->next = NULL;
-       //mm->mmnew->useptr = peeonself;
-       mm->mmrover = mm->mmhead;
+       gvar->mm.mmhead = gvar->mm.mmnew;                               // this will allways be the first node
+       gvar->mm.mmnew->start = 0;
+       gvar->mm.mmnew->length = 0xffff;
+       gvar->mm.mmnew->attributes = LOCKBIT;
+       gvar->mm.mmnew->next = NULL;
+       //gvar->mm.mmnew->useptr = peeonself;
+       gvar->mm.mmrover = gvar->mm.mmhead;
 
        //printf("              %x\n", peeonself);
        //printf("              %x\n", *peeonself);
@@ -796,20 +796,20 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
 #ifdef __WATCOMC__
        _nheapgrow();
        length=(dword)_memavl();//(dword)GetFreeSize();
-       //huge start = (void huge *)(mm->nearheap = _nmalloc(length));
-       start = (void far *)(mm->nearheap = _nmalloc(length));
+       //huge start = (void huge *)(gvar->mm.nearheap = _nmalloc(length));
+       start = (void far *)(gvar->mm.nearheap = _nmalloc(length));
 #endif
 #ifdef __BORLANDC__
        length=coreleft();
-       //huge start = (void huge *)(mm->nearheap = malloc(length));
-       start = (void far *)(mm->nearheap = malloc(length));
+       //huge start = (void huge *)(gvar->mm.nearheap = malloc(length));
+       start = (void far *)(gvar->mm.nearheap = malloc(length));
 #endif
        length -= 16-(FP_OFF(start)&15);
        length -= SAVENEARHEAP;
        seglength = length / 16;                        // now in paragraphs
        segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
-       MML_UseSpace(segstart,seglength, mm);
-       mmi->nearheap = length;
+       MML_UseSpace(segstart,seglength, gvar);
+       gvar->mmi.nearheap = length;
        //printf("start=%Fp     segstart=%x     seglen=%lu      len=%lu\n", start, segstart, seglength, length);
 
 //
@@ -824,22 +824,22 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
        printf("(farcoreleft()+32)-_FCORELEFT   %d\n", (sword)((farcoreleft()+32)-_FCORELEFT));
 #endif
        length=_FCORELEFT;//_fcoreleft();//(dword)GetFarFreeSize();//0xffffUL*4UL;
-       start = mm->farheap = _fmalloc(length);
-       //start = mm->farheap = halloc(length, 1);
+       start = gvar->mm.farheap = _fmalloc(length);
+       //start = gvar->mm.farheap = halloc(length, 1);
        length -= 16-(FP_OFF(start)&15);
        length -= SAVEFARHEAP;
        seglength = length / 16;                        // now in paragraphs
        segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
-       MML_UseSpace(segstart,seglength, mm);
-       mmi->farheap = length;
+       MML_UseSpace(segstart,seglength, gvar);
+       gvar->mmi.farheap = length;
        //printf("start=%Fp     segstart=%x     seglen=%lu      len=%lu\n", start, segstart, seglength, length);
 
-       mmi->mainmem = mmi->nearheap + mmi->farheap;
+       gvar->mmi.mainmem = gvar->mmi.nearheap + gvar->mmi.farheap;
 
 //
 // detect EMS and allocate up to 64K at page frame
 //
-       mmi->EMSmem = 0;
+       gvar->mmi.EMSmem = 0;
 //goto emsskip;        //0000
        for(i = 1;i <
 #ifdef __WATCOMC__
@@ -862,20 +862,20 @@ void MM_Startup(mminfo_t *mm, mminfotype *mmi)
        }
        if(MML_CheckForEMS())
        {
-               MML_SetupEMS(mm);                                       // allocate space
+               MML_SetupEMS(gvar);                                     // allocate space
                //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
-               MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
-               //if(mm->EMSVer<0x40)
-                       MM_MapEMS(mm, mmi);                                     // map in used pages
+               MML_UseSpace(gvar->mm.EMSpageframe,(MAPPAGES)*0x4000lu, gvar);
+               //if(gvar->pm.emm.EMSVer<0x40)
+                       MM_MapEMS(gvar);                                        // map in used pages
                //else
-                       //MM_MapXEMS(mm, mmi);                                  // map in used pages
+                       //MM_MapXEMS(gvar);                                     // map in used pages
        }
 
 //
 // detect XMS and get upper memory blocks
 //
 emsskip:
-       mmi->XMSmem = 0;
+       gvar->mmi.XMSmem = 0;
 goto xmsskip;//0000
        for(i = 1;i <
 #ifdef __WATCOMC__
@@ -896,18 +896,18 @@ goto xmsskip;//0000
                        ,ParmStringsexmm) == 0)
                        goto xmsskip;                           // param NOXMS
        }
-       if(MML_CheckForXMS(mm))
+       if(MML_CheckForXMS(gvar))
        {
-               MML_SetupXMS(mm, mmi);                                  // allocate as many UMBs as possible
+               MML_SetupXMS(gvar);                                     // allocate as many UMBs as possible
        }
 
 //
 // allocate the misc buffer
 //
 xmsskip:
-       mm->mmrover = mm->mmhead;               // start looking for space after low block
+       gvar->mm.mmrover = gvar->mm.mmhead;             // start looking for space after low block
 
-       MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi);
+       MM_GetPtr(&(gvar->mm.bufferseg),BUFFERSIZE, gvar);
 }
 
 //==========================================================================
@@ -922,20 +922,20 @@ xmsskip:
 ====================
 */
 
-void MM_Shutdown(mminfo_t *mm)
+void MM_Shutdown(global_game_variables_t *gvar)
 {
-       if(!(mm->mmstarted))
+       if(!(gvar->mm.mmstarted))
                return;
 
-       _ffree(mm->farheap);//  printf("                far freed\n");
+       _ffree(gvar->mm.farheap);//     printf("                far freed\n");
 #ifdef __WATCOMC__
-       _nfree(mm->nearheap);// printf("                near freed\n");
+       _nfree(gvar->mm.nearheap);//    printf("                near freed\n");
 #endif
 #ifdef __BORLANDC__
-       free(mm->nearheap);//   printf("                near freed\n");
+       free(gvar->mm.nearheap);//      printf("                near freed\n");
 #endif
-       if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); }//printf("         EMS freed\n"); }
-       if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); }//printf("               XMS freed\n"); }
+       if(MML_CheckForEMS()){ MML_ShutdownEMS(gvar); }//printf("               EMS freed\n"); }
+       if(MML_CheckForXMS(gvar)){ MML_ShutdownXMS(gvar); }//printf("           XMS freed\n"); }
 }
 
 //==========================================================================
@@ -950,7 +950,7 @@ void MM_Shutdown(mminfo_t *mm)
 ====================
 */
 
-void MM_GetPtr (memptr *baseptr, dword size, mminfo_t *mm, mminfotype *mmi)
+void MM_GetPtr (memptr *baseptr, dword size, global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
        mmblocktype far *scan,far *lastscan,far *endscan,far *purge,far *next;
@@ -960,16 +960,16 @@ void MM_GetPtr (memptr *baseptr, dword size, mminfo_t *mm, mminfotype *mmi)
        needed = (size+15)/16;          // convert size from bytes to paragraphs
 
        GETNEWBLOCK;                            // fill in start and next after a spot is found
-       mm->mmnew->length = needed;
-       mm->mmnew->useptr = baseptr;
-       //if(mm->mmnew->useptr==NULL){
+       gvar->mm.mmnew->length = needed;
+       gvar->mm.mmnew->useptr = baseptr;
+       //if(gvar->mm.mmnew->useptr==NULL){
 #ifdef __DEBUG__
-               printf("baseptr=%04x    ", baseptr); printf("useptr=%04x\n", mm->mmnew->useptr);
-               printf("*baseptr=%04x   ", *baseptr); printf("*useptr=%04x\n", *(mm->mmnew->useptr));
-               printf("*baseptr=%Fp    ", *baseptr); printf("*useptr=%Fp\n", *(mm->mmnew->useptr));
+               printf("baseptr=%04x    ", baseptr); printf("useptr=%04x\n", gvar->mm.mmnew->useptr);
+               printf("*baseptr=%04x   ", *baseptr); printf("*useptr=%04x\n", *(gvar->mm.mmnew->useptr));
+               printf("*baseptr=%Fp    ", *baseptr); printf("*useptr=%Fp\n", *(gvar->mm.mmnew->useptr));
 #endif
        //exit(-5); }
-       mm->mmnew->attributes = BASEATTRIBUTES;
+       gvar->mm.mmnew->attributes = BASEATTRIBUTES;
 
 //tryagain:
        for (search = 0; search<3; search++)
@@ -978,25 +978,25 @@ void MM_GetPtr (memptr *baseptr, dword size, mminfo_t *mm, mminfotype *mmi)
        // first search:        try to allocate right after the rover, then on up
        // second search:       search from the head pointer up to the rover
        // third search:        compress memory, then scan from start
-               if (search == 1 && mm->mmrover == mm->mmhead)
+               if (search == 1 && gvar->mm.mmrover == gvar->mm.mmhead)
                        search++;
 
                switch (search)
                {
                case 0:
-                       lastscan = mm->mmrover;
-                       scan = mm->mmrover->next;
+                       lastscan = gvar->mm.mmrover;
+                       scan = gvar->mm.mmrover->next;
                        endscan = NULL;
                        break;
                case 1:
-                       lastscan = mm->mmhead;
-                       scan = mm->mmhead->next;
-                       endscan = mm->mmrover;
+                       lastscan = gvar->mm.mmhead;
+                       scan = gvar->mm.mmhead->next;
+                       endscan = gvar->mm.mmrover;
                        break;
                case 2:
-                       MM_SortMem (mm);
-                       lastscan = mm->mmhead;
-                       scan = mm->mmhead->next;
+                       MM_SortMem (gvar);
+                       lastscan = gvar->mm.mmhead;
+                       scan = gvar->mm.mmhead->next;
                        endscan = NULL;
                        break;
                }
@@ -1013,16 +1013,16 @@ void MM_GetPtr (memptr *baseptr, dword size, mminfo_t *mm, mminfotype *mmi)
                        // and allocate the new block
                        //
                                purge = lastscan->next;
-                               lastscan->next = mm->mmnew;
-                               mm->mmnew->start = *(unsigned *)baseptr = startseg;
-                               mm->mmnew->next = scan;
+                               lastscan->next = gvar->mm.mmnew;
+                               gvar->mm.mmnew->start = *(unsigned *)baseptr = startseg;
+                               gvar->mm.mmnew->next = scan;
                                while ( purge != scan)
                                {       // free the purgable block
                                        next = purge->next;
                                        FREEBLOCK(purge);
                                        purge = next;           // purge another if not at scan
                                }
-                               mm->mmrover = mm->mmnew;
+                               gvar->mm.mmrover = gvar->mm.mmnew;
                                return; // good allocation!
                        }
 
@@ -1041,18 +1041,18 @@ void MM_GetPtr (memptr *baseptr, dword size, mminfo_t *mm, mminfotype *mmi)
                }
        }
 
-       if (mm->bombonerror)
+       if (gvar->mm.bombonerror)
        {
 #ifdef __WATCOMC__
                //heapdump();
 #endif
-               printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
+               printf(OUT_OF_MEM_MSG,(size-gvar->mmi.nearheap));
                printf("for stability reasons the program will shut down! wwww\n");
-               MM_Shutdown(mm);
+               MM_Shutdown(gvar);
                exit(-1);
        }
        else
-               mm->mmerror = true;
+               gvar->mm.mmerror = true;
 }
 
 //==========================================================================
@@ -1067,16 +1067,16 @@ void MM_GetPtr (memptr *baseptr, dword size, mminfo_t *mm, mminfotype *mmi)
 ====================
 */
 
-void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
+void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *scan,huge *last;
        mmblocktype far *scan,far *last;
 
-       last = mm->mmhead;
+       last = gvar->mm.mmhead;
        scan = last->next;
 
-       if(baseptr == mm->mmrover->useptr)      // removed the last allocated block
-               mm->mmrover = mm->mmhead;
+       if(baseptr == gvar->mm.mmrover->useptr) // removed the last allocated block
+               gvar->mm.mmrover = gvar->mm.mmhead;
 
        while(scan->useptr != baseptr && scan)
        {
@@ -1106,23 +1106,23 @@ void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
 =====================
 */
 
-void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
+void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *start;
        mmblocktype far *start;
 
-       start = mm->mmrover;
+       start = gvar->mm.mmrover;
 
        do
        {
-               if(mm->mmrover->useptr == baseptr)
+               if(gvar->mm.mmrover->useptr == baseptr)
                        break;
 
-               mm->mmrover = mm->mmrover->next;
+               gvar->mm.mmrover = gvar->mm.mmrover->next;
 
-               if(!mm->mmrover)
-                       mm->mmrover = mm->mmhead;
-               else if(mm->mmrover == start)
+               if(!gvar->mm.mmrover)
+                       gvar->mm.mmrover = gvar->mm.mmhead;
+               else if(gvar->mm.mmrover == start)
                {
                        Quit("MM_SetPurge: Block not found!");
                        //return;
@@ -1130,8 +1130,8 @@ void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
 
        } while(1);
 
-       mm->mmrover->attributes &= ~PURGEBITS;
-       mm->mmrover->attributes |= purge;
+       gvar->mm.mmrover->attributes &= ~PURGEBITS;
+       gvar->mm.mmrover->attributes |= purge;
 }
 
 //==========================================================================
@@ -1146,23 +1146,23 @@ void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
 =====================
 */
 
-void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
+void MM_SetLock(memptr *baseptr, boolean locked, global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *start;
        mmblocktype far *start;
 
-       start = mm->mmrover;
+       start = gvar->mm.mmrover;
 
        do
        {
-               if(mm->mmrover->useptr == baseptr)
+               if(gvar->mm.mmrover->useptr == baseptr)
                        break;
 
-               mm->mmrover = mm->mmrover->next;
+               gvar->mm.mmrover = gvar->mm.mmrover->next;
 
-               if(!mm->mmrover)
-                       mm->mmrover = mm->mmhead;
-               else if(mm->mmrover == start)
+               if(!gvar->mm.mmrover)
+                       gvar->mm.mmrover = gvar->mm.mmhead;
+               else if(gvar->mm.mmrover == start)
                {
                        Quit("MM_SetLock: Block not found!");
                        //return;
@@ -1170,8 +1170,8 @@ void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
 
        } while(1);
 
-       mm->mmrover->attributes &= ~LOCKBIT;
-       mm->mmrover->attributes |= locked*LOCKBIT;
+       gvar->mm.mmrover->attributes &= ~LOCKBIT;
+       gvar->mm.mmrover->attributes |= locked*LOCKBIT;
 }
 
 //==========================================================================
@@ -1186,7 +1186,7 @@ void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
 =====================
 */
 
-void MM_SortMem(mminfo_t *mm)
+void MM_SortMem(global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *scan,huge *last,huge *next;
        mmblocktype far *scan,far *last,far *next;
@@ -1219,7 +1219,7 @@ void MM_SortMem(mminfo_t *mm)
        if(beforesort)
                beforesort();
 
-       scan = mm->mmhead;
+       scan = gvar->mm.mmhead;
 
        last = NULL;            // shut up compiler warning
 
@@ -1241,7 +1241,7 @@ void MM_SortMem(mminfo_t *mm)
                        //
                                next = scan->next;
                                FREEBLOCK(scan);
-                               //MM_FreeBlock(scan, mm);
+                               //MM_FreeBlock(scan, gvar);
                                last->next = next;
                                scan = next;
                                continue;
@@ -1276,7 +1276,7 @@ void MM_SortMem(mminfo_t *mm)
                scan = scan->next;              // go to next block
        }
 
-       mm->mmrover = mm->mmhead;
+       gvar->mm.mmrover = gvar->mm.mmhead;
 
        if(aftersort)
                aftersort();
@@ -1430,14 +1430,14 @@ void MM_ShowMemory(global_game_variables_t *gvar)
        /*strcpy(scratch1, AARESET);
        strcat(scratch1, "========================================\n");
        strcat(scratch1, "near=  ");
-       ultoa (*(mm->nearheap),str,10);
+       ultoa (*(gvar->mm.nearheap),str,10);
        strcat (scratch1,str);
        strcat(scratch1, "      far= ");
-       ultoa (*(mm->farheap),str,10);
+       ultoa (*(gvar->mm.farheap),str,10);
        strcat (scratch1,str);
        strcat(scratch1, "\n");
-       //strcat(scratch1, "&near=      %Fp ", &(mm->nearheap));
-       //strcat(scratch1, "&far=       %Fp", &(mm->farheap));
+       //strcat(scratch1, "&near=      %Fp ", &(gvar->mm.nearheap));
+       //strcat(scratch1, "&far=       %Fp", &(gvar->mm.farheap));
        //strcat(scratch1, "\n");
        strcat(scratch1, "========================================\n");
        write(gvar->handle.debughandle,scratch1,strlen(scratch1));*/
@@ -1460,7 +1460,7 @@ void MM_ShowMemory(global_game_variables_t *gvar)
 =====================
 */
 
-void MM_DumpData(mminfo_t *mm)
+void MM_DumpData(global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *scan,huge *best;
        mmblocktype far *scan,far *best;
@@ -1469,7 +1469,7 @@ void MM_DumpData(mminfo_t *mm)
        byte    lock,purge;
        FILE    *dumpfile;
 
-       free(mm->nearheap);
+       free(gvar->mm.nearheap);
 #ifdef __BORLANDC__
                dumpfile = fopen ("mmdump.16b","w");
 #endif
@@ -1487,7 +1487,7 @@ void MM_DumpData(mminfo_t *mm)
                oldlowest = lowest;
                lowest = 0xffff;
 
-               scan = mm->mmhead;
+               scan = gvar->mm.mmhead;
                while (scan)
                {
                        owner = (unsigned)scan->useptr;
@@ -1534,14 +1534,14 @@ void MM_DumpData(mminfo_t *mm)
 ======================
 */
 
-dword MM_UnusedMemory(mminfo_t *mm)
+dword MM_UnusedMemory(global_game_variables_t *gvar)
 {
        dword free;
        //huge mmblocktype huge *scan;
        mmblocktype far *scan;
 
        free = 0;
-       scan = mm->mmhead;
+       scan = gvar->mm.mmhead;
 
        while(scan->next)
        {
@@ -1566,14 +1566,14 @@ dword MM_UnusedMemory(mminfo_t *mm)
 ======================
 */
 
-dword MM_TotalFree(mminfo_t *mm)
+dword MM_TotalFree(global_game_variables_t *gvar)
 {
        dword free;
        //huge mmblocktype huge *scan;
        mmblocktype far *scan;
 
        free = 0;
-       scan = mm->mmhead;
+       scan = gvar->mm.mmhead;
 
        while(scan->next)
        {
@@ -1605,20 +1605,20 @@ void MM_Report_(global_game_variables_t *gvar)
        if(MML_CheckForEMS())
        {
                printf("        LIMEMS\n");
-               printf("                EMM v%x.%x available\n", gvar->mm.EMSVer>>4,gvar->mm.EMSVer&0x0F);
+               printf("                EMM v%x.%x available\n", gvar->pm.emm.EMSVer>>4,gvar->pm.emm.EMSVer&0x0F);
                printf("                totalEMSpages:  %u      ", gvar->mm.totalEMSpages); printf("freeEMSpages:       %u\n", gvar->mm.freeEMSpages);
                printf("                EMSpageframe:   %x\n", gvar->mm.EMSpageframe);
        }
-       if(MML_CheckForXMS(&(gvar->mm)))
+       if(MML_CheckForXMS(gvar))
        {
                printf("        XMS\n");
                printf("                XMSaddr:        %X\n", *XMSaddr);
        }
        printf("near:   %lu     ", gvar->mmi.nearheap); printf("far:    %lu\n", gvar->mmi.farheap); if(MML_CheckForEMS())
-       printf("EMSmem: %lu     ", gvar->mmi.EMSmem); if(MML_CheckForXMS(&(gvar->mm))) printf("XMSmem:  %lu", gvar->mmi.XMSmem); printf("\n");
+       printf("EMSmem: %lu     ", gvar->mmi.EMSmem); if(MML_CheckForXMS(gvar)) printf("XMSmem: %lu", gvar->mmi.XMSmem); printf("\n");
        //printf("mainmem:      %lu\n", gvar->mmi.mainmem);
-       printf("Total convmem:  %lu     ", gvar->mmi.mainmem); printf("TotalFree:       %lu     ", MM_TotalFree(&(gvar->mm))); printf("TotalUsed:       %lu\n", gvar->mmi.mainmem+gvar->mmi.EMSmem+gvar->mmi.XMSmem+gvar->mmi.XMSmem);
-       printf("                        UnusedMemory:   %lu\n", MM_UnusedMemory(&(gvar->mm)));
+       printf("Total convmem:  %lu     ", gvar->mmi.mainmem); printf("TotalFree:       %lu     ", MM_TotalFree(gvar)); printf("TotalUsed:      %lu\n", gvar->mmi.mainmem+gvar->mmi.EMSmem+gvar->mmi.XMSmem+gvar->mmi.XMSmem);
+       printf("                        UnusedMemory:   %lu\n", MM_UnusedMemory(gvar));
 }
 
 //==========================================================================
@@ -1762,30 +1762,30 @@ void MM_EMSerr(byte *stri, byte err)
 =====================
 */
 
-void MM_BombOnError(boolean bomb, mminfo_t *mm)
+void MM_BombOnError(boolean bomb, global_game_variables_t *gvar)
 {
-       mm->bombonerror = bomb;
+       gvar->mm.bombonerror = bomb;
 }
 
-/*void MM_GetNewBlock(mminfo_t *mm)
+/*void MM_GetNewBlock(global_game_variables_t *gvar)
 {
-       if(!mm->mmfree)
-               MML_ClearBlock(mm);
-       mm->mmnew=mm->mmfree;
-       mm->mmfree=mm->mmfree->next;
-       if(!(mm->mmnew=mm->mmfree))
+       if(!gvar->mm.mmfree)
+               MML_ClearBlock(gvar);
+       gvar->mm.mmnew=gvar->mm.mmfree;
+       gvar->mm.mmfree=gvar->mm.mmfree->next;
+       if(!(gvar->mm.mmnew=gvar->mm.mmfree))
        {
                printf("MM_GETNEWBLOCK: No free blocks!\n");
                return;
        }
-       mm->mmfree=mm->mmfree->next;
+       gvar->mm.mmfree=gvar->mm.mmfree->next;
 }
 
-void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
+void MM_FreeBlock(mmblocktype *x, global_game_variables_t *gvar)
 {
        x->useptr=NULL;
-       x->next=mm->mmfree;
-       mm->mmfree=x;
+       x->next=gvar->mm.mmfree;
+       gvar->mm.mmfree=x;
 }*/
 
 /*void MM_seguin(void)
index bdc974298938a1de8171c05e71a0271da285b063..7995bf23dbb5ee19a3a0cb38e37e88c453e9c23a 100755 (executable)
@@ -36,9 +36,9 @@
 #endif
 
 //#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}
-#define GETNEWBLOCK {if(!mm->mmfree)MML_ClearBlock(mm);mm->mmnew=mm->mmfree;mm->mmfree=mm->mmfree->next;}
+#define GETNEWBLOCK {if(!gvar->mm.mmfree)MML_ClearBlock(gvar);gvar->mm.mmnew=gvar->mm.mmfree;gvar->mm.mmfree=gvar->mm.mmfree->next;}
 
-#define FREEBLOCK(x) {*x->useptr=NULL;x->next=mm->mmfree;mm->mmfree=x;}
+#define FREEBLOCK(x) {*x->useptr=NULL;x->next=gvar->mm.mmfree;gvar->mm.mmfree=x;}
 
 #define SAVENEARHEAP   0x200           // space to leave in data segment
 #define SAVEFARHEAP    0//x400                 // space to leave in far heap
 //--------
 
 #define        XMS_INT                 0x2f
-#define        XMSD                    word XMSDriver=gvar->pm.xmm.XMSDriver;
-#define        XMS_CALL(v)             CPURegs.h.ah = (v);\
-                                               XMSDriver=gvar->pm.xmm.XMSDriver;\
-                                               __asm call [WORD PTR XMSDriver]
+#define        XMSD                    dword XMSDriver=gvar->pm.xmm.XMSDriver;
+inline void    XMS_CALL(byte v, global_game_variables_t *gvar)
+{
+       XMSD;
+       XMSDriver=gvar->pm.xmm.XMSDriver;
+       __asm {
+               mov v,ah
+               call [WORD PTR XMSDriver]
+       }
+}
 
 #define        XMS_VERSION             0x00
 
@@ -125,7 +131,7 @@ extern void         (* XMSaddr) (void);             // far pointer to XMS driver
 
 //moved to typedefst
 //#define MAXUMBS              12
-#define MAPPAGES               4//mm->EMSpagesmapped
+#define MAPPAGES               4//gvar->mm.EMSpagesmapped
 
 //moved to typdefst
 /*typedef struct mmblockstruct
@@ -181,31 +187,31 @@ typedef struct
 //==========================================================================
 
 boolean MML_CheckForEMS(void);
-byte MML_SetupEMS(mminfo_t *mm);
-void MML_ShutdownEMS(mminfo_t *mm);
-byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi);
-byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi);
-boolean MML_CheckForXMS(mminfo_t *mm);
-void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
-void MML_ShutdownXMS(mminfo_t *mm);
-void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm);
-void MML_ClearBlock(mminfo_t *mm);
-
-void MM_Startup(mminfo_t *mm, mminfotype *mmi);
-void MM_Shutdown(mminfo_t *mm);
-
-void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi);
-void MM_FreePtr(memptr *baseptr, mminfo_t *mm);
-void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm);
-void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm);
-void MM_SortMem(mminfo_t *mm);
+//byte MML_SetupEMS(mminfo_t *mm);
+//void MML_ShutdownEMS(mminfo_t *mm);
+byte MM_MapEMS(global_game_variables_t *gvar);
+byte MM_MapXEMS(global_game_variables_t *gvar);
+//boolean MML_CheckForXMS(mminfo_t *mm);
+//void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
+//void MML_ShutdownXMS(mminfo_t *mm);
+void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar);
+void MML_ClearBlock(global_game_variables_t *gvar);
+
+void MM_Startup(global_game_variables_t *gvar);
+void MM_Shutdown(global_game_variables_t *gvar);
+
+void MM_GetPtr(memptr *baseptr,dword size, global_game_variables_t *gvar);
+void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar);
+void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar);
+void MM_SetLock(memptr *baseptr, boolean locked, global_game_variables_t *gvar);
+void MM_SortMem(global_game_variables_t *gvar);
 void MM_ShowMemory(global_game_variables_t *gvar);//,/*page_t *page, */mminfo_t *mm);
-void MM_DumpData(mminfo_t *mm);
-dword MM_UnusedMemory(mminfo_t *mm);
-dword MM_TotalFree(mminfo_t *mm);
+void MM_DumpData(global_game_variables_t *gvar);
+dword MM_UnusedMemory(global_game_variables_t *gvar);
+dword MM_TotalFree(global_game_variables_t *gvar);
 void MM_Report_(global_game_variables_t *gvar);
 static void MM_EMSerr(byte *stri, byte err);
-void MM_BombOnError(boolean bomb, mminfo_t *mm);
+void MM_BombOnError(boolean bomb, global_game_variables_t *gvar);
 //void MM_GetNewBlock(mminfo_t *mm);
 //void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);
 
index 0b04b16eee30a37f53a12a4d1334a926e8fd90f0..9740195156dc584e7a15d26a248dbe76289c2028 100755 (executable)
@@ -1,3 +1,25 @@
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ *\r
+ * This file is part of Project 16.\r
+ *\r
+ * Project 16 is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Project 16 is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
+ * Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ */\r
+\r
 //\r
 //     ID_PM.C\r
 //     Id Engine's Page Manager v1.0\r
 \r
 #include "src/lib/16_pm.h"\r
 #pragma hdrstop\r
+union REGS CPURegs;\r
 /*\r
 //     Main Mem specific variables\r
        boolean                 MainPresent;\r
        memptr                  MainMemPages[PMMaxMainMem];\r
-       PMBlockAttr             MainMemUsed[PMMaxMainMem];\r
-       int                             MainPagesAvail;\r
+       PMBlockAttr             gvar->pm.mm.MainMemUsed[PMMaxMainMem];\r
+       int                             gvar->pm.mm.MainPagesAvail;\r
 \r
 //     EMS specific variables\r
        boolean                 gvar->pm.emm.EMSPresent;\r
        word                    gvar->pm.emm.EMSAvail,gvar->pm.emm.EMSPagesAvail,gvar->pm.emm.EMSHandle,\r
                                        gvar->pm.emm.EMSPageFrame,gvar->pm.emm.EMSPhysicalPage;\r
-       EMSListStruct   EMSList[EMSFrameCount];\r
+       gvar->pm.emm.EMSListStruct      gvar->pm.emm.EMSList[EMSFrameCount];\r
 \r
 //     XMS specific variables\r
        boolean                 gvar->pm.xmm.XMSPresent;\r
        int                             gvar->pm.xmm.XMSProtectPage = -1;\r
 \r
 //     File specific variables\r
-       char                    PageFileName[13] = {"VSWAP."};\r
+       char                    gvar->pm.fi.PageFileName[13] = {"VSWAP."};\r
        int                             PageFile = -1;\r
        word                    gvar->pm.fi.ChunksInFile;\r
        word                    PMSpriteStart,PMSoundStart;\r
 \r
 //     General usage variables\r
        boolean                 PMStarted,\r
-                                       PMPanicMode,\r
-                                       PMThrashing;\r
-       word                    gvar->pm.xmm.XMSPagesUsed,\r
-                                       gvar->pm.emm.EMSPagesUsed,\r
+                                       gvar->pm.PMPanicMode,\r
+                                       gvar->pm.PMThrashing;\r
+       word                    gvar->pm.XMSPagesUsed,\r
+                                       gvar->pm.EMSPagesUsed,\r
                                        MainPagesUsed,\r
-                                       PMNumBlocks;\r
+                                       gvar->pm.PMNumBlocks;\r
        long                    PMFrameCount;\r
-       PageListStruct  far *PMPages,\r
-                                       _seg *PMSegPages;\r
+       PageListStruct  far *gvar->pm.PMPages,\r
+                                       _seg *gvar->pm.PMSegPages;\r
 */\r
 static char            *ParmStrings[] = {"nomain","noems","noxms",nil};\r
 \r
@@ -62,8 +85,7 @@ PML_MapEMS(word logical, word physical, global_game_variables_t *gvar)
        CPURegs.x.bx = logical;\r
        CPURegs.x.dx = gvar->pm.emm.EMSHandle;\r
        CPURegs.h.ah = EMS_MAPPAGE;\r
-       __asm\r
-       {\r
+       __asm {\r
                int     EMS_INT\r
        }\r
 \r
@@ -257,7 +279,7 @@ PML_StartupXMS(global_game_variables_t *gvar)
                mov     [WORD PTR XMSDriver+2],es               // function pointer to XMS driver\r
        }\r
 \r
-       XMS_CALL(XMS_QUERYFREE);                        // Find out how much XMS is available\r
+       XMS_CALL(XMS_QUERYFREE, gvar);                  // Find out how much XMS is available\r
        gvar->pm.xmm.XMSAvail = CPURegs.x.ax;\r
        if (!CPURegs.x.ax)                              // AJR: bugfix 10/8/92\r
                goto error;\r
@@ -267,7 +289,7 @@ PML_StartupXMS(global_game_variables_t *gvar)
                goto error;\r
 \r
        CPURegs.x.dx = gvar->pm.xmm.XMSAvail;\r
-       XMS_CALL(XMS_ALLOC);                            // And do the allocation\r
+       XMS_CALL(XMS_ALLOC, gvar);                              // And do the allocation\r
        gvar->pm.xmm.XMSHandle = CPURegs.x.dx;\r
 \r
        if (!CPURegs.x.ax)                              // AJR: bugfix 10/8/92\r
@@ -319,7 +341,7 @@ PML_XMSCopy(boolean toxms,byte far *addr,word xmspage,word length, global_game_v
                push si\r
        }\r
        CPURegs.x.si = (word)&copy;\r
-       XMS_CALL(XMS_MOVE);\r
+       XMS_CALL(XMS_MOVE, gvar);\r
        __asm {\r
                pop     si\r
        }\r
@@ -331,17 +353,17 @@ PML_XMSCopy(boolean toxms,byte far *addr,word xmspage,word length, global_game_v
 }\r
 \r
 #if 1\r
-#define        PML_CopyToXMS(s,t,l)    PML_XMSCopy(true,(s),(t),(l))\r
-#define        PML_CopyFromXMS(t,s,l)  PML_XMSCopy(false,(t),(s),(l))\r
+#define        PML_CopyToXMS(s,t,l,gvar)       PML_XMSCopy(true,(s),(t),(l),(gvar))\r
+#define        PML_CopyFromXMS(t,s,l,gvar)     PML_XMSCopy(false,(t),(s),(l),(gvar))\r
 #else\r
 //\r
 //     PML_CopyToXMS() - Copies the specified number of bytes from the real mode\r
 //             segment address to the specified XMS page\r
 //\r
 void\r
-PML_CopyToXMS(byte far *source,int targetpage,word length)\r
+PML_CopyToXMS(byte far *source,int targetpage,word length,global_game_variables_t *gvar)\r
 {\r
-       PML_XMSCopy(true,source,targetpage,length);\r
+       PML_XMSCopy(true,source,targetpage,length, global_game_variables_t *gvar);\r
 }\r
 \r
 //\r
@@ -349,9 +371,9 @@ PML_CopyToXMS(byte far *source,int targetpage,word length)
 //             page to the specified real mode address\r
 //\r
 void\r
-PML_CopyFromXMS(byte far *target,int sourcepage,word length)\r
+PML_CopyFromXMS(byte far *target,int sourcepage,word length, global_game_variables_t *gvar)\r
 {\r
-       PML_XMSCopy(false,target,sourcepage,length);\r
+       PML_XMSCopy(false,target,sourcepage,length, global_game_variables_t *gvar);\r
 }\r
 #endif\r
 \r
@@ -365,7 +387,7 @@ PML_ShutdownXMS(global_game_variables_t *gvar)
        if (gvar->pm.xmm.XMSPresent)\r
        {\r
                CPURegs.x.dx = gvar->pm.xmm.XMSHandle;\r
-               XMS_CALL(XMS_FREE);\r
+               XMS_CALL(XMS_FREE, gvar);\r
                if (CPURegs.h.bl)\r
                {\r
                        Quit("PML_ShutdownXMS: Error freeing XMS");\r
@@ -392,8 +414,7 @@ PM_SetMainMemPurge(int level, global_game_variables_t *gvar)
 \r
        for (i = 0;i < PMMaxMainMem;i++)\r
                if (gvar->pm.mm.MainMemPages[i])\r
-                       MM_SetPurge(&gvar->pm.mm.MainMemPages[i],level);\r
-       return 0;//TODO FIX\r
+                       MM_SetPurge(&gvar->pm.mm.MainMemPages[i],level, gvar);\r
 }\r
 \r
 //\r
@@ -410,7 +431,7 @@ PM_SetMainMemPurge(int level, global_game_variables_t *gvar)
 //             program makes allocation requests of the Memory Mgr.\r
 //\r
 void\r
-PM_CheckMainMem(void)\r
+PM_CheckMainMem(global_game_variables_t *gvar)\r
 {\r
        boolean                 allocfailed;\r
        int                             i,n;\r
@@ -418,15 +439,15 @@ PM_CheckMainMem(void)
        PMBlockAttr             *used;\r
        PageListStruct  far *page;\r
 \r
-       if (!MainPresent)\r
+       if (!gvar->pm.mm.MainPresent)\r
                return;\r
 \r
-       for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+       for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
        {\r
                n = page->mainPage;\r
                if (n != -1)                                            // Is the page using main memory?\r
                {\r
-                       if (!MainMemPages[n])                   // Yep, was the block purged?\r
+                       if (!gvar->pm.mm.MainMemPages[n])                       // Yep, was the block purged?\r
                        {\r
                                page->mainPage = -1;            // Yes, mark page as purged & unlocked\r
                                page->locked = pml_Unlocked;\r
@@ -435,41 +456,41 @@ PM_CheckMainMem(void)
        }\r
 \r
        // Prevent allocation attempts from purging any of our other blocks\r
-       PM_LockMainMem();\r
+       PM_LockMainMem(gvar);\r
        allocfailed = false;\r
-       for (i = 0,p = MainMemPages,used = MainMemUsed;i < PMMaxMainMem;i++,p++,used++)\r
+       for (i = 0,p = gvar->pm.mm.MainMemPages,used = gvar->pm.mm.MainMemUsed; i < PMMaxMainMem;i++,p++,used++)\r
        {\r
                if (!*p)                                                        // If the page got purged\r
                {\r
                        if (*used & pmba_Allocated)             // If it was allocated\r
                        {\r
                                *used &= ~pmba_Allocated;       // Mark as unallocated\r
-                               MainPagesAvail--;                       // and decrease available count\r
+                               gvar->pm.mm.MainPagesAvail--;                   // and decrease available count\r
                        }\r
 \r
                        if (*used & pmba_Used)                  // If it was used\r
                        {\r
                                *used &= ~pmba_Used;            // Mark as unused\r
-                               MainPagesUsed--;                        // and decrease used count\r
+                               gvar->pm.MainPagesUsed--;                       // and decrease used count\r
                        }\r
 \r
                        if (!allocfailed)\r
                        {\r
-                               MM_BombOnError(false);\r
-                               MM_GetPtr(p,PMPageSize);                // Try to reallocate\r
-                               if (mmerror)                                    // If it failed,\r
+                               MM_BombOnError(false, gvar);\r
+                               MM_GetPtr(p,PMPageSize, gvar);          // Try to reallocate\r
+                               if (gvar->mm.mmerror)                                   // If it failed,\r
                                        allocfailed = true;                     //  don't try any more allocations\r
                                else                                                    // If it worked,\r
                                {\r
                                        *used |= pmba_Allocated;        // Mark as allocated\r
-                                       MainPagesAvail++;                       // and increase available count\r
+                                       gvar->pm.mm.MainPagesAvail++;                   // and increase available count\r
                                }\r
-                               MM_BombOnError(true);\r
+                               MM_BombOnError(true, gvar);\r
                        }\r
                }\r
        }\r
-       if (mmerror)\r
-               mmerror = false;\r
+       if (gvar->mm.mmerror)\r
+               gvar->mm.mmerror = false;\r
 }\r
 \r
 //\r
@@ -479,31 +500,31 @@ PM_CheckMainMem(void)
 //             needs to be called.\r
 //\r
 void\r
-PML_StartupMainMem(void)\r
+PML_StartupMainMem(global_game_variables_t *gvar)\r
 {\r
        int             i,n;\r
        memptr  *p;\r
 \r
-       MainPagesAvail = 0;\r
-       MM_BombOnError(false);\r
-       for (i = 0,p = MainMemPages;i < PMMaxMainMem;i++,p++)\r
+       gvar->pm.mm.MainPagesAvail = 0;\r
+       MM_BombOnError(false, gvar);\r
+       for (i = 0,p = gvar->pm.mm.MainMemPages;i < PMMaxMainMem;i++,p++)\r
        {\r
-               MM_GetPtr(p,PMPageSize);\r
-               if (mmerror)\r
+               MM_GetPtr(p,PMPageSize, gvar);\r
+               if (gvar->mm.mmerror)\r
                        break;\r
 \r
-               MainPagesAvail++;\r
-               MainMemUsed[i] = pmba_Allocated;\r
+               gvar->pm.mm.MainPagesAvail++;\r
+               gvar->pm.mm.MainMemUsed[i] = pmba_Allocated;\r
        }\r
-       MM_BombOnError(true);\r
-       if (mmerror)\r
-               mmerror = false;\r
-       if (MainPagesAvail < PMMinMainMem)\r
+       MM_BombOnError(true, gvar);\r
+       if (gvar->mm.mmerror)\r
+               gvar->mm.mmerror = false;\r
+       if (gvar->pm.mm.MainPagesAvail < PMMinMainMem)\r
        {\r
                Quit("PM_SetupMainMem: Not enough main memory");\r
                //return;\r
        }\r
-       MainPresent = true;\r
+       gvar->pm.mm.MainPresent = true;\r
 }\r
 \r
 //\r
@@ -511,15 +532,15 @@ PML_StartupMainMem(void)
 //             Page Mgr.\r
 //\r
 void\r
-PML_ShutdownMainMem(void)\r
+PML_ShutdownMainMem(global_game_variables_t *gvar)\r
 {\r
        int             i;\r
        memptr  *p;\r
 \r
        // DEBUG - mark pages as unallocated & decrease page count as appropriate\r
-       for (i = 0,p = MainMemPages;i < PMMaxMainMem;i++,p++)\r
+       for (i = 0,p = gvar->pm.mm.MainMemPages;i < PMMaxMainMem;i++,p++)\r
                if (*p)\r
-                       MM_FreePtr(p);\r
+                       MM_FreePtr(p, gvar);\r
 }\r
 \r
 /////////////////////////////////////////////////////////////////////////////\r
@@ -532,7 +553,7 @@ PML_ShutdownMainMem(void)
 //     PML_ReadFromFile() - Reads some data in from the page file\r
 //\r
 void\r
-PML_ReadFromFile(byte far *buf,long offset,word length)\r
+PML_ReadFromFile(byte far *buf,long offset,word length, global_game_variables_t *gvar)\r
 {\r
        if (!buf)\r
        {\r
@@ -544,12 +565,13 @@ PML_ReadFromFile(byte far *buf,long offset,word length)
                Quit("PML_ReadFromFile: Zero offset");\r
                //return;\r
        }\r
-       if (lseek(PageFile,offset,SEEK_SET) != offset)\r
+       if (lseek(gvar->pm.fi.PageFile,offset,SEEK_SET) != offset)\r
        {\r
                Quit("PML_ReadFromFile: Seek failed");\r
                //return;\r
        }\r
-       if (!CA_FarRead(PageFile,buf,length))\r
+       if (!CA_FarRead(gvar->pm.fi.PageFile,buf,length, gvar))\r
+       {\r
                Quit("PML_ReadFromFile: Read failed");\r
                //return;\r
        }\r
@@ -559,73 +581,74 @@ PML_ReadFromFile(byte far *buf,long offset,word length)
 //     PML_OpenPageFile() - Opens the page file and sets up the page info\r
 //\r
 void\r
-PML_OpenPageFile(void)\r
+PML_OpenPageFile(global_game_variables_t *gvar)\r
 {\r
        int                             i;\r
        long                    size;\r
-                               __SEGA *buf;\r
+                               //__SEGA buf;\r
+       memptr          buf;\r
        dword           far *offsetptr;\r
        word                    far *lengthptr;\r
        PageListStruct  far *page;\r
 \r
-       PageFile = open(PageFileName,O_RDONLY + O_BINARY);\r
-       if (PageFile == -1)\r
+       gvar->pm.fi.PageFile = open(gvar->pm.fi.PageFileName,O_RDONLY + O_BINARY);\r
+       if (gvar->pm.fi.PageFile == -1)\r
        {\r
                Quit("PML_OpenPageFile: Unable to open page file");\r
                //return;\r
        }\r
 \r
        // Read in header variables\r
-       read(PageFile,&gvar->pm.fi.ChunksInFile,sizeof(gvar->pm.fi.ChunksInFile));\r
-       read(PageFile,&PMSpriteStart,sizeof(PMSpriteStart));\r
-       read(PageFile,&PMSoundStart,sizeof(PMSoundStart));\r
+       read(gvar->pm.fi.PageFile,&gvar->pm.fi.ChunksInFile,sizeof(gvar->pm.fi.ChunksInFile));\r
+       read(gvar->pm.fi.PageFile,&gvar->pm.fi.PMSpriteStart,sizeof(gvar->pm.fi.PMSpriteStart));\r
+       read(gvar->pm.fi.PageFile,&gvar->pm.fi.PMSoundStart,sizeof(gvar->pm.fi.PMSoundStart));\r
 \r
        // Allocate and clear the page list\r
-       PMNumBlocks = gvar->pm.fi.ChunksInFile;\r
-       MM_GetPtr(&(memptr)PMSegPages,sizeof(PageListStruct) * PMNumBlocks);\r
-       MM_SetLock(&(memptr)PMSegPages,true);\r
-       PMPages = (PageListStruct far *)PMSegPages;\r
-       _fmemset(PMPages,0,sizeof(PageListStruct) * PMNumBlocks);\r
+       gvar->pm.PMNumBlocks = gvar->pm.fi.ChunksInFile;\r
+       MM_GetPtr((memptr *)gvar->pm.PMSegPages, sizeof(PageListStruct) * (gvar->pm.PMNumBlocks), gvar);\r
+       MM_SetLock((memptr *)gvar->pm.PMSegPages,true, gvar);\r
+       gvar->pm.PMPages = (PageListStruct far *)gvar->pm.PMSegPages;\r
+       _fmemset(gvar->pm.PMPages,0,sizeof(PageListStruct) * gvar->pm.PMNumBlocks);\r
 \r
        // Read in the chunk offsets\r
        size = sizeof(dword) * gvar->pm.fi.ChunksInFile;\r
-       MM_GetPtr(&buf,size);\r
-       if (!CA_FarRead(PageFile,(byte far *)buf,size))\r
+       MM_GetPtr(&buf, size, gvar);\r
+       if (!CA_FarRead(gvar->pm.fi.PageFile,(byte far *)buf,size, gvar))\r
        {\r
                Quit("PML_OpenPageFile: Offset read failed");\r
                //return;\r
        }\r
        offsetptr = (dword far *)buf;\r
-       for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+       for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
                page->offset = *offsetptr++;\r
-       MM_FreePtr(&buf);\r
+       MM_FreePtr(&buf, gvar);\r
 \r
        // Read in the chunk lengths\r
        size = sizeof(word) * gvar->pm.fi.ChunksInFile;\r
-       MM_GetPtr(&buf,size);\r
-       if (!CA_FarRead(PageFile,(byte far *)buf,size))\r
+       MM_GetPtr(&buf,size, gvar);\r
+       if (!CA_FarRead(gvar->pm.fi.PageFile,(byte far *)buf,size, gvar))\r
        {\r
                Quit("PML_OpenPageFile: Length read failed");\r
                //return;\r
        }\r
        lengthptr = (word far *)buf;\r
-       for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+       for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
                page->length = *lengthptr++;\r
-       MM_FreePtr(&buf);\r
+       MM_FreePtr(&buf, gvar);\r
 }\r
 \r
 //\r
 //  PML_ClosePageFile() - Closes the page file\r
 //\r
 void\r
-PML_ClosePageFile(void)\r
+PML_ClosePageFile(global_game_variables_t *gvar)\r
 {\r
-       if (PageFile != -1)\r
-               close(PageFile);\r
-       if (PMSegPages)\r
+       if (gvar->pm.fi.PageFile != -1)\r
+               close(gvar->pm.fi.PageFile);\r
+       if (gvar->pm.PMSegPages)\r
        {\r
-               MM_SetLock(&(memptr)PMSegPages,false);\r
-               MM_FreePtr(&(__SEGA *)PMSegPages);\r
+               MM_SetLock((memptr)gvar->pm.PMSegPages,false, gvar);\r
+               MM_FreePtr((memptr)gvar->pm.PMSegPages, gvar);\r
        }\r
 }\r
 \r
@@ -636,16 +659,16 @@ PML_ClosePageFile(void)
 /////////////////////////////////////////////////////////////////////////////\r
 \r
 //\r
-//     PML_Getgvar->pm.emm.EMSAddress()\r
+//     PML_GetEMSAddress()\r
 //\r
 //             Page is in EMS, so figure out which EMS physical page should be used\r
 //             to map our page in. If normal page, use EMS physical page 3, else\r
 //             use the physical page specified by the lock type\r
 //\r
-#ifdef __DEBUG__\r
+#ifndef __DEBUG_2__\r
 #pragma argsused       // DEBUG - remove lock parameter\r
 memptr\r
-PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)\r
+PML_GetEMSAddress(int page,PMLockType lock, global_game_variables_t *gvar)\r
 {\r
        int             i,emspage;\r
        word    emsoff,emsbase,offset;\r
@@ -657,7 +680,7 @@ PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)
        // See if this page is already mapped in\r
        for (i = 0;i < EMSFrameCount;i++)\r
        {\r
-               if (EMSList[i].basegvar->pm.emm.EMSPage == emsbase)\r
+               if (gvar->pm.emm.EMSList[i].baseEMSPage == emsbase)\r
                {\r
                        emspage = i;    // Yep - don't do a redundant remapping\r
                        break;\r
@@ -667,31 +690,31 @@ PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)
        // If page isn't already mapped in, find LRU EMS frame, and use it\r
        if (emspage == -1)\r
        {\r
-               dword last = MAXLONG;\r
+               dword last = LONG_MAX;\r
                for (i = 0;i < EMSFrameCount;i++)\r
                {\r
-                       if (EMSList[i].lastHit < last)\r
+                       if (gvar->pm.emm.EMSList[i].lastHit < last)\r
                        {\r
                                emspage = i;\r
-                               last = EMSList[i].lastHit;\r
+                               last = gvar->pm.emm.EMSList[i].lastHit;\r
                        }\r
                }\r
 \r
-               EMSList[emspage].basegvar->pm.emm.EMSPage = emsbase;\r
-               PML_MapEMS(page / PMEMSSubPage,emspage);\r
+               gvar->pm.emm.EMSList[emspage].baseEMSPage = emsbase;\r
+               PML_MapEMS(page / PMEMSSubPage,emspage, gvar);\r
        }\r
 \r
        if (emspage == -1)\r
-               Quit("PML_Getgvar->pm.emm.EMSAddress: EMS find failed");\r
+               Quit("PML_GetEMSAddress: EMS find failed");\r
 \r
-       EMSList[emspage].lastHit = PMFrameCount;\r
+       gvar->pm.emm.EMSList[emspage].lastHit = gvar->pm.PMFrameCount;\r
        offset = emspage * EMSPageSizeSeg;\r
        offset += emsoff * PMPageSizeSeg;\r
        return((memptr)(gvar->pm.emm.EMSPageFrame + offset));\r
 }\r
 #else\r
 memptr\r
-PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)\r
+PML_GetEMSAddress(int page,PMLockType lock, global_game_variables_t *gvar)\r
 {\r
        word    emspage;\r
 \r
@@ -699,7 +722,7 @@ PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)
 \r
        PML_MapEMS(page / PMEMSSubPage,emspage);\r
 \r
-       return((memptr)(gvar->pm.emm.EMSPageFrame + (emspage * EMSPageSizeSeg)\r
+       return((memptr)(EMSPageFrame + (emspage * EMSPageSizeSeg)\r
                        + ((page & (PMEMSSubPage - 1)) * PMPageSizeSeg)));\r
 }\r
 #endif\r
@@ -711,15 +734,15 @@ PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)
 //\r
 //\r
 memptr\r
-PM_GetPageAddress(int pagenum)\r
+PM_GetPageAddress(int pagenum, global_game_variables_t *gvar)\r
 {\r
        PageListStruct  far *page;\r
 \r
-       page = &PMPages[pagenum];\r
+       page = &gvar->pm.PMPages[pagenum];\r
        if (page->mainPage != -1)\r
-               return(MainMemPages[page->mainPage]);\r
+               return(gvar->pm.mm.MainMemPages[page->mainPage]);\r
        else if (page->emsPage != -1)\r
-               return(PML_Getgvar->pm.emm.EMSAddress(page->emsPage,page->locked));\r
+               return(PML_GetEMSAddress(page->emsPage,page->locked, gvar));\r
        else\r
                return(nil);\r
 }\r
@@ -729,13 +752,13 @@ PM_GetPageAddress(int pagenum)
 //             present & unlocked main/EMS page (or main page if mainonly is true)\r
 //\r
 int\r
-PML_GiveLRUPage(boolean mainonly)\r
+PML_GiveLRUPage(boolean mainonly, global_game_variables_t *gvar)\r
 {\r
        int                             i,lru;\r
        long                    last;\r
        PageListStruct  far *page;\r
 \r
-       for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+       for (i = 0,page = gvar->pm.PMPages,lru = -1,last = LONG_MAX;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
        {\r
                if\r
                (\r
@@ -756,18 +779,18 @@ PML_GiveLRUPage(boolean mainonly)
 }\r
 \r
 //\r
-//     PML_GiveLRUgvar->pm.xmm.XMSPage() - Returns the page # of the least recently used\r
+//     PML_GiveLRUXMSPage() - Returns the page # of the least recently used\r
 //             (and present) XMS page.\r
 //     This routine won't return the XMS page protected (by gvar->pm.xmm.XMSProtectPage)\r
 //\r
 int\r
-PML_GiveLRUgvar->pm.xmm.XMSPage(void)\r
+PML_GiveLRUXMSPage(global_game_variables_t *gvar)\r
 {\r
        int                             i,lru;\r
        long                    last;\r
        PageListStruct  far *page;\r
 \r
-       for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+       for (i = 0,page = gvar->pm.PMPages,lru = -1,last = LONG_MAX;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
        {\r
                if\r
                (\r
@@ -788,7 +811,7 @@ PML_GiveLRUgvar->pm.xmm.XMSPage(void)
 //             it with the main/EMS page\r
 //\r
 void\r
-PML_PutPageInXMS(int pagenum)\r
+PML_PutPageInXMS(int pagenum, global_game_variables_t *gvar)\r
 {\r
        int                             usexms;\r
        PageListStruct  far *page;\r
@@ -796,21 +819,21 @@ PML_PutPageInXMS(int pagenum)
        if (!gvar->pm.xmm.XMSPresent)\r
                return;\r
 \r
-       page = &PMPages[pagenum];\r
+       page = &gvar->pm.PMPages[pagenum];\r
        if (page->xmsPage != -1)\r
                return;                                 // Already in XMS\r
 \r
-       if (gvar->pm.xmm.XMSPagesUsed < gvar->pm.xmm.XMSPagesAvail)\r
-               page->xmsPage = gvar->pm.xmm.XMSPagesUsed++;\r
+       if (gvar->pm.XMSPagesUsed < gvar->pm.xmm.XMSPagesAvail)\r
+               page->xmsPage = gvar->pm.XMSPagesUsed++;\r
        else\r
        {\r
-               usexms = PML_GiveLRUgvar->pm.xmm.XMSPage();\r
+               usexms = PML_GiveLRUXMSPage(gvar);\r
                if (usexms == -1)\r
                        Quit("PML_PutPageInXMS: No XMS LRU");\r
-               page->xmsPage = PMPages[usexms].xmsPage;\r
-               PMPages[usexms].xmsPage = -1;\r
+               page->xmsPage = gvar->pm.PMPages[usexms].xmsPage;\r
+               gvar->pm.PMPages[usexms].xmsPage = -1;\r
        }\r
-       PML_CopyToXMS(PM_GetPageAddress(pagenum),page->xmsPage,page->length);\r
+       PML_CopyToXMS(PM_GetPageAddress(pagenum, gvar),page->xmsPage,page->length, gvar);\r
 }\r
 \r
 //\r
@@ -818,7 +841,7 @@ PML_PutPageInXMS(int pagenum)
 //             the old one's address space. Returns the address of the new page.\r
 //\r
 memptr\r
-PML_TransferPageSpace(int orig,int new)\r
+PML_TransferPageSpace(int orig,int new, global_game_variables_t *gvar)\r
 {\r
        memptr                  addr;\r
        PageListStruct  far *origpage,far *newpage;\r
@@ -826,8 +849,8 @@ PML_TransferPageSpace(int orig,int new)
        if (orig == new)\r
                Quit("PML_TransferPageSpace: Identity replacement");\r
 \r
-       origpage = &PMPages[orig];\r
-       newpage = &PMPages[new];\r
+       origpage = &gvar->pm.PMPages[orig];\r
+       newpage = &gvar->pm.PMPages[new];\r
 \r
        if (origpage->locked != pml_Unlocked)\r
                Quit("PML_TransferPageSpace: Killing locked page");\r
@@ -836,10 +859,10 @@ PML_TransferPageSpace(int orig,int new)
                Quit("PML_TransferPageSpace: Reusing non-existent page");\r
 \r
        // Copy page that's about to be purged into XMS\r
-       PML_PutPageInXMS(orig);\r
+       PML_PutPageInXMS(orig, gvar);\r
 \r
        // Get the address, and force EMS into a physical page if necessary\r
-       addr = PM_GetPageAddress(orig);\r
+       addr = PM_GetPageAddress(orig, gvar);\r
 \r
        // Steal the address\r
        newpage->emsPage = origpage->emsPage;\r
@@ -863,24 +886,24 @@ PML_TransferPageSpace(int orig,int new)
 //             will be looked at by PML_GiveLRUPage().\r
 //\r
 byte far *\r
-PML_GetAPageBuffer(int pagenum,boolean mainonly)\r
+PML_GetAPageBuffer(int pagenum,boolean mainonly, global_game_variables_t *gvar)\r
 {\r
        byte                    far *addr = nil;\r
        int                             i,n;\r
        PMBlockAttr             *used;\r
        PageListStruct  far *page;\r
 \r
-       page = &PMPages[pagenum];\r
-       if ((gvar->pm.emm.EMSPagesUsed < gvar->pm.emm.EMSPagesAvail) && !mainonly)\r
+       page = &gvar->pm.PMPages[pagenum];\r
+       if ((gvar->pm.EMSPagesUsed < gvar->pm.emm.EMSPagesAvail) && !mainonly)\r
        {\r
                // There's remaining EMS - use it\r
-               page->emsPage = gvar->pm.emm.EMSPagesUsed++;\r
-               addr = PML_Getgvar->pm.emm.EMSAddress(page->emsPage,page->locked);\r
+               page->emsPage = gvar->pm.EMSPagesUsed++;\r
+               addr = PML_GetEMSAddress(page->emsPage,page->locked, gvar);\r
        }\r
-       else if (MainPagesUsed < MainPagesAvail)\r
+       else if (gvar->pm.MainPagesUsed < gvar->pm.mm.MainPagesAvail)\r
        {\r
                // There's remaining main memory - use it\r
-               for (i = 0,n = -1,used = MainMemUsed;i < PMMaxMainMem;i++,used++)\r
+               for (i = 0,n = -1,used = gvar->pm.mm.MainMemUsed;i < PMMaxMainMem;i++,used++)\r
                {\r
                        if ((*used & pmba_Allocated) && !(*used & pmba_Used))\r
                        {\r
@@ -891,14 +914,14 @@ PML_GetAPageBuffer(int pagenum,boolean mainonly)
                }\r
                if (n == -1)\r
                        Quit("PML_GetPageBuffer: MainPagesAvail lied");\r
-               addr = MainMemPages[n];\r
+               addr = gvar->pm.mm.MainMemPages[n];\r
                if (!addr)\r
                        Quit("PML_GetPageBuffer: Purged main block");\r
                page->mainPage = n;\r
-               MainPagesUsed++;\r
+               gvar->pm.MainPagesUsed++;\r
        }\r
        else\r
-               addr = PML_TransferPageSpace(PML_GiveLRUPage(mainonly),pagenum);\r
+               addr = PML_TransferPageSpace(PML_GiveLRUPage(mainonly, gvar),pagenum, gvar);\r
 \r
        if (!addr)\r
                Quit("PML_GetPageBuffer: Search failed");\r
@@ -909,27 +932,27 @@ PML_GetAPageBuffer(int pagenum,boolean mainonly)
 //     PML_GetPageFromXMS() - If page is in XMS, find LRU main/EMS page and\r
 //             replace it with the page from XMS. If mainonly is true, will only\r
 //             search for LRU main page.\r
-//     gvar->pm.xmm.XMSProtectPage is set to the page to be retrieved from XMS, so that if\r
+//     XMSProtectPage is set to the page to be retrieved from XMS, so that if\r
 //             the page from which we're stealing the main/EMS from isn't in XMS,\r
 //             it won't copy over the page that we're trying to get from XMS.\r
 //             (pages that are being purged are copied into XMS, if possible)\r
 //\r
 memptr\r
-PML_GetPageFromXMS(int pagenum,boolean mainonly)\r
+PML_GetPageFromXMS(int pagenum,boolean mainonly, global_game_variables_t *gvar)\r
 {\r
        byte                    far *checkaddr;\r
        memptr                  addr = nil;\r
        PageListStruct  far *page;\r
 \r
-       page = &PMPages[pagenum];\r
+       page = &gvar->pm.PMPages[pagenum];\r
        if (gvar->pm.xmm.XMSPresent && (page->xmsPage != -1))\r
        {\r
                gvar->pm.xmm.XMSProtectPage = pagenum;\r
-               checkaddr = PML_GetAPageBuffer(pagenum,mainonly);\r
+               checkaddr = PML_GetAPageBuffer(pagenum,mainonly, gvar);\r
                if (FP_OFF(checkaddr))\r
                        Quit("PML_GetPageFromXMS: Non segment pointer");\r
                addr = (memptr)FP_SEG(checkaddr);\r
-               PML_CopyFromXMS(addr,page->xmsPage,page->length);\r
+               PML_CopyFromXMS(addr,page->xmsPage,page->length, gvar);\r
                gvar->pm.xmm.XMSProtectPage = -1;\r
        }\r
 \r
@@ -942,14 +965,14 @@ PML_GetPageFromXMS(int pagenum,boolean mainonly)
 //             only be loaded into main.\r
 //\r
 void\r
-PML_LoadPage(int pagenum,boolean mainonly)\r
+PML_LoadPage(int pagenum,boolean mainonly, global_game_variables_t *gvar)\r
 {\r
        byte                    far *addr;\r
        PageListStruct  far *page;\r
 \r
-       addr = PML_GetAPageBuffer(pagenum,mainonly);\r
-       page = &PMPages[pagenum];\r
-       PML_ReadFromFile(addr,page->offset,page->length);\r
+       addr = PML_GetAPageBuffer(pagenum,mainonly, gvar);\r
+       page = &gvar->pm.PMPages[pagenum];\r
+       PML_ReadFromFile(addr,page->offset,page->length, gvar);\r
 }\r
 \r
 //\r
@@ -960,14 +983,14 @@ PML_LoadPage(int pagenum,boolean mainonly)
 //\r
 #pragma warn -pia\r
 memptr\r
-PM_GetPage(int pagenum)\r
+PM_GetPage(int pagenum, global_game_variables_t *gvar)\r
 {\r
        memptr  result;\r
 \r
        if (pagenum >= gvar->pm.fi.ChunksInFile)\r
                Quit("PM_GetPage: Invalid page request");\r
 \r
-#if __DEBUG__  // for debugging\r
+#ifdef __DEBUG_2__     // for debugging\r
        __asm {\r
                mov     dx,STATUS_REGISTER_1\r
                in      al,dx\r
@@ -979,23 +1002,23 @@ PM_GetPage(int pagenum)
        }\r
 #endif\r
 \r
-       if (!(result = PM_GetPageAddress(pagenum)))\r
+       if (!(result = PM_GetPageAddress(pagenum, gvar)))\r
        {\r
-               boolean mainonly = (pagenum >= PMSoundStart);\r
-if (!PMPages[pagenum].offset)  // JDC: sparse page\r
+               boolean mainonly = (pagenum >= gvar->pm.fi.PMSoundStart);\r
+if (!gvar->pm.PMPages[pagenum].offset) // JDC: sparse page\r
        Quit ("Tried to load a sparse page!");\r
-               if (!(result = PML_GetPageFromXMS(pagenum,mainonly)))\r
+               if (!(result = PML_GetPageFromXMS(pagenum,mainonly, gvar)))\r
                {\r
-                       if (PMPages[pagenum].lastHit == PMFrameCount)\r
-                               PMThrashing++;\r
+                       if (gvar->pm.PMPages[pagenum].lastHit ==  gvar->pm.PMFrameCount)\r
+                               gvar->pm.PMThrashing++;\r
 \r
-                       PML_LoadPage(pagenum,mainonly);\r
-                       result = PM_GetPageAddress(pagenum);\r
+                       PML_LoadPage(pagenum,mainonly, gvar);\r
+                       result = PM_GetPageAddress(pagenum, gvar);\r
                }\r
        }\r
-       PMPages[pagenum].lastHit = PMFrameCount;\r
+       gvar->pm.PMPages[pagenum].lastHit =  gvar->pm.PMFrameCount;\r
 \r
-#if __DEBUG__  // for debugging\r
+#ifdef __DEBUG_2__     // for debugging\r
        __asm{\r
                mov     dx,STATUS_REGISTER_1\r
                in      al,dx\r
@@ -1020,12 +1043,12 @@ if (!PMPages[pagenum].offset)   // JDC: sparse page
 //                                     specified when returning the address. For sound stuff.\r
 //\r
 void\r
-PM_SetPageLock(int pagenum,PMLockType lock)\r
+PM_SetPageLock(int pagenum,PMLockType lock, global_game_variables_t *gvar)\r
 {\r
-       if (pagenum < PMSoundStart)\r
+       if (pagenum < gvar->pm.fi.PMSoundStart)\r
                Quit("PM_SetPageLock: Locking/unlocking non-sound page");\r
 \r
-       PMPages[pagenum].locked = lock;\r
+       gvar->pm.PMPages[pagenum].locked = lock;\r
 }\r
 \r
 //\r
@@ -1034,7 +1057,7 @@ PM_SetPageLock(int pagenum,PMLockType lock)
 //             page, and the total pages that need to be loaded (for thermometer).\r
 //\r
 void\r
-PM_Preload(boolean (*update)(word current,word total))\r
+PM_Preload(boolean (*update)(word current,word total), global_game_variables_t *gvar)\r
 {\r
        int                             i,j,\r
                                        page,oogypage;\r
@@ -1046,17 +1069,17 @@ PM_Preload(boolean (*update)(word current,word total))
        memptr                  addr;\r
        PageListStruct  far *p;\r
 \r
-       mainfree = (MainPagesAvail - MainPagesUsed) + (gvar->pm.emm.EMSPagesAvail - gvar->pm.emm.EMSPagesUsed);\r
-       xmsfree = (gvar->pm.xmm.XMSPagesAvail - gvar->pm.xmm.XMSPagesUsed);\r
+       mainfree = (gvar->pm.mm.MainPagesAvail - gvar->pm.MainPagesUsed) + (gvar->pm.emm.EMSPagesAvail - gvar->pm.EMSPagesUsed);\r
+       xmsfree = (gvar->pm.xmm.XMSPagesAvail - gvar->pm.XMSPagesUsed);\r
 \r
        xmstotal = maintotal = 0;\r
 \r
        for (i = 0;i < gvar->pm.fi.ChunksInFile;i++)\r
        {\r
-               if (!PMPages[i].offset)\r
+               if (!gvar->pm.PMPages[i].offset)\r
                        continue;                       // sparse\r
 \r
-               if ( PMPages[i].emsPage != -1 || PMPages[i].mainPage != -1 )\r
+               if ( gvar->pm.PMPages[i].emsPage != -1 || gvar->pm.PMPages[i].mainPage != -1 )\r
                        continue;                       // already in main mem\r
 \r
                if ( mainfree )\r
@@ -1064,7 +1087,7 @@ PM_Preload(boolean (*update)(word current,word total))
                        maintotal++;\r
                        mainfree--;\r
                }\r
-               else if ( xmsfree && (PMPages[i].xmsPage == -1) )\r
+               else if ( xmsfree && (gvar->pm.PMPages[i].xmsPage == -1) )\r
                {\r
                        xmstotal++;\r
                        xmsfree--;\r
@@ -1085,14 +1108,14 @@ PM_Preload(boolean (*update)(word current,word total))
 //\r
        while (maintotal)\r
        {\r
-               while ( !PMPages[page].offset || PMPages[page].mainPage != -1\r
-                       ||      PMPages[page].emsPage != -1 )\r
+               while ( !gvar->pm.PMPages[page].offset || gvar->pm.PMPages[page].mainPage != -1\r
+                       ||      gvar->pm.PMPages[page].emsPage != -1 )\r
                        page++;\r
 \r
                if (page >= gvar->pm.fi.ChunksInFile)\r
                        Quit ("PM_Preload: Pages>=gvar->pm.fi.ChunksInFile");\r
 \r
-               PM_GetPage(page);\r
+               PM_GetPage(page, gvar);\r
 \r
                page++;\r
                current++;\r
@@ -1105,30 +1128,30 @@ PM_Preload(boolean (*update)(word current,word total))
 //\r
        if (xmstotal)\r
        {\r
-               for (oogypage = 0 ; PMPages[oogypage].mainPage == -1 ; oogypage++)\r
+               for (oogypage = 0 ; gvar->pm.PMPages[oogypage].mainPage == -1 ; oogypage++)\r
                ;\r
-               addr = PM_GetPage(oogypage);\r
+               addr = PM_GetPage(oogypage, gvar);\r
                if (!addr)\r
                        Quit("PM_Preload: XMS buffer failed");\r
 \r
                while (xmstotal)\r
                {\r
-                       while ( !PMPages[page].offset || PMPages[page].xmsPage != -1 )\r
+                       while ( !gvar->pm.PMPages[page].offset || gvar->pm.PMPages[page].xmsPage != -1 )\r
                                page++;\r
 \r
                        if (page >= gvar->pm.fi.ChunksInFile)\r
                                Quit ("PM_Preload: Pages>=gvar->pm.fi.ChunksInFile");\r
 \r
-                       p = &PMPages[page];\r
+                       p = &gvar->pm.PMPages[page];\r
 \r
-                       p->xmsPage = gvar->pm.xmm.XMSPagesUsed++;\r
-                       if (gvar->pm.xmm.XMSPagesUsed > gvar->pm.xmm.XMSPagesAvail)\r
+                       p->xmsPage = gvar->pm.XMSPagesUsed++;\r
+                       if (gvar->pm.XMSPagesUsed > gvar->pm.xmm.XMSPagesAvail)\r
                                Quit("PM_Preload: Exceeded XMS pages");\r
                        if (p->length > PMPageSize)\r
                                Quit("PM_Preload: Page too long");\r
 \r
-                       PML_ReadFromFile((byte far *)addr,p->offset,p->length);\r
-                       PML_CopyToXMS((byte far *)addr,p->xmsPage,p->length);\r
+                       PML_ReadFromFile((byte far *)addr,p->offset,p->length, gvar);\r
+                       PML_CopyToXMS((byte far *)addr,p->xmsPage,p->length, gvar);\r
 \r
                        page++;\r
                        current++;\r
@@ -1136,8 +1159,8 @@ PM_Preload(boolean (*update)(word current,word total))
                        update(current,total);\r
                }\r
 \r
-               p = &PMPages[oogypage];\r
-               PML_ReadFromFile((byte far *)addr,p->offset,p->length);\r
+               p = &gvar->pm.PMPages[oogypage];\r
+               PML_ReadFromFile((byte far *)addr,p->offset,p->length, gvar);\r
        }\r
 \r
        update(total,total);\r
@@ -1159,48 +1182,48 @@ PM_Preload(boolean (*update)(word current,word total))
 //\r
 //\r
 void\r
-PM_NextFrame(void)\r
+PM_NextFrame(global_game_variables_t *gvar)\r
 {\r
        int     i;\r
 \r
        // Frame count overrun - kill the LRU hit entries & reset frame count\r
-       if (++PMFrameCount >= MAXLONG - 4)\r
+       if (++gvar->pm.PMFrameCount >= LONG_MAX - 4)\r
        {\r
-               for (i = 0;i < PMNumBlocks;i++)\r
-                       PMPages[i].lastHit = 0;\r
-               PMFrameCount = 0;\r
+               for (i = 0;i < gvar->pm.PMNumBlocks;i++)\r
+                       gvar->pm.PMPages[i].lastHit = 0;\r
+               gvar->pm.PMFrameCount = 0;\r
        }\r
 \r
-#if 0\r
-       for (i = 0;i < PMSoundStart;i++)\r
+//#if 0\r
+       for (i = 0;i < gvar->pm.fi.PMSoundStart;i++)\r
        {\r
-               if (PMPages[i].locked)\r
+               if (gvar->pm.PMPages[i].locked)\r
                {\r
                        char buf[40];\r
                        sprintf(buf,"PM_NextFrame: Page %d is locked",i);\r
                        Quit(buf);\r
                }\r
        }\r
-#endif\r
+//#endif\r
 \r
-       if (PMPanicMode)\r
+       if (gvar->pm.PMPanicMode)\r
        {\r
                // DEBUG - set border color\r
-               if ((!PMThrashing) && (!--PMPanicMode))\r
+               if ((!gvar->pm.PMThrashing) && (!--gvar->pm.PMPanicMode))\r
                {\r
                        // DEBUG - reset border color\r
                }\r
        }\r
-       if (PMThrashing >= PMThrashThreshold)\r
-               PMPanicMode = PMUnThrashThreshold;\r
-       PMThrashing = false;\r
+       if (gvar->pm.PMThrashing >= PMThrashThreshold)\r
+               gvar->pm.PMPanicMode = PMUnThrashThreshold;\r
+       gvar->pm.PMThrashing = false;\r
 }\r
 \r
 //\r
 //     PM_Reset() - Sets up caching structures\r
 //\r
 void\r
-PM_Reset(void)\r
+PM_Reset(global_game_variables_t *gvar)\r
 {\r
        int                             i;\r
        PageListStruct  far *page;\r
@@ -1210,12 +1233,12 @@ PM_Reset(void)
        gvar->pm.emm.EMSPagesAvail = gvar->pm.emm.EMSAvail * (EMSPageSizeKB / PMPageSizeKB);\r
        gvar->pm.emm.EMSPhysicalPage = 0;\r
 \r
-       MainPagesUsed = gvar->pm.emm.EMSPagesUsed = gvar->pm.xmm.XMSPagesUsed = 0;\r
+       gvar->pm.MainPagesUsed = gvar->pm.EMSPagesUsed = gvar->pm.XMSPagesUsed = 0;\r
 \r
-       PMPanicMode = false;\r
+       gvar->pm.PMPanicMode = false;\r
 \r
        // Initialize page list\r
-       for (i = 0,page = PMPages;i < PMNumBlocks;i++,page++)\r
+       for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.PMNumBlocks;i++,page++)\r
        {\r
                page->mainPage = -1;\r
                page->emsPage = -1;\r
@@ -1228,18 +1251,36 @@ PM_Reset(void)
 //     PM_Startup() - Start up the Page Mgr\r
 //\r
 void\r
-PM_Startup(void)\r
+PM_Startup(global_game_variables_t *gvar)\r
 {\r
        boolean nomain,noems,noxms;\r
        int             i;\r
 \r
-       if (PMStarted)\r
+       if (gvar->pm.PMStarted)\r
                return;\r
 \r
+       strcat(&(gvar->pm.fi.PageFileName), "VSWAP.");\r
+       gvar->pm.fi.PageFile = -1;\r
+       gvar->pm.xmm.XMSProtectPage = -1;\r
+\r
        nomain = noems = noxms = false;\r
-       for (i = 1;i < _argc;i++)\r
+       for (i = 1;i <\r
+#ifdef __WATCOMC__\r
+       __argc\r
+#endif\r
+#ifdef __BORLANDC__\r
+       _argc\r
+#endif\r
+       ;i++)\r
        {\r
-               switch (US_CheckParm(_argv[i],ParmStrings))\r
+               switch (US_CheckParm(\r
+#ifdef __WATCOMC__\r
+       __argv[i]\r
+#endif\r
+#ifdef __BORLANDC__\r
+       _argv[i]\r
+#endif\r
+               ,ParmStrings))\r
                {\r
                case 0:\r
                        nomain = true;\r
@@ -1253,12 +1294,12 @@ PM_Startup(void)
                }\r
        }\r
 \r
-       PML_OpenPageFile();\r
+       PML_OpenPageFile(gvar);\r
 \r
        if (!noems)\r
-               PML_StartupEMS();\r
+               PML_StartupEMS(gvar);\r
        if (!noxms)\r
-               PML_StartupXMS();\r
+               PML_StartupXMS(gvar);\r
 \r
        if (nomain && !gvar->pm.emm.EMSPresent)\r
        {\r
@@ -1266,26 +1307,26 @@ PM_Startup(void)
                //return;\r
        }\r
        else\r
-               PML_StartupMainMem();\r
+               PML_StartupMainMem(gvar);\r
 \r
-       PM_Reset();\r
+       PM_Reset(gvar);\r
 \r
-       PMStarted = true;\r
+       gvar->pm.PMStarted = true;\r
 }\r
 \r
 //\r
 //     PM_Shutdown() - Shut down the Page Mgr\r
 //\r
 void\r
-PM_Shutdown(void)\r
+PM_Shutdown(global_game_variables_t *gvar)\r
 {\r
-       PML_ShutdownXMS();\r
-       PML_ShutdownEMS();\r
+       PML_ShutdownXMS(gvar);\r
+       PML_ShutdownEMS(gvar);\r
 \r
-       if (!PMStarted)\r
+       if (!gvar->pm.PMStarted)\r
                return;\r
 \r
-       PML_ClosePageFile();\r
+       PML_ClosePageFile(gvar);\r
 \r
-       PML_ShutdownMainMem();\r
+       PML_ShutdownMainMem(gvar);\r
 }\r
index 973b08b404eaa98cc7d5aa3badb60faccf3707f6..85135d91b4b2a28074be8469f8d8ce17ee6d639b 100755 (executable)
@@ -1,3 +1,28 @@
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ *\r
+ * This file is part of Project 16.\r
+ *\r
+ * Project 16 is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Project 16 is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
+ * Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ */\r
+\r
+#ifndef __16_PM__\r
+#define __16_PM__\r
+\r
 //\r
 //     ID_PM.H\r
 //     Header file for Id Engine's Page Manager\r
@@ -67,22 +92,23 @@ extern      PageListStruct  far *PMPages;*///moved to src/lib/typdefst.h
 #define        PM_GetSoundPage(v)      PM_GetPage(PMSoundStart + (v))\r
 #define        PM_GetSpritePage(v)     PM_GetPage(PMSpriteStart + (v))\r
 \r
-#define        PM_LockMainMem()        PM_SetMainMemPurge(0)\r
-#define        PM_UnlockMainMem()      PM_SetMainMemPurge(3)\r
+#define        PM_LockMainMem(gvar)    PM_SetMainMemPurge(0, gvar)\r
+#define        PM_UnlockMainMem(gvar)  PM_SetMainMemPurge(3, gvar)\r
 \r
 \r
 extern char    PageFileName[13];\r
 \r
 \r
-extern void    PM_Startup(void),\r
-                               PM_Shutdown(void),\r
-                               PM_Reset(void),\r
-                               PM_Preload(boolean (*update)(word current,word total)),\r
-                               PM_NextFrame(void),\r
-                               PM_SetPageLock(int pagenum,PMLockType lock),\r
+extern void    PM_Startup(global_game_variables_t *gvar),\r
+                               PM_Shutdown(global_game_variables_t *gvar),\r
+                               PM_Reset(global_game_variables_t *gvar),\r
+                               PM_Preload(boolean (*update)(word current,word total), global_game_variables_t *gvar),\r
+                               PM_NextFrame(global_game_variables_t *gvar),\r
+                               PM_SetPageLock(int pagenum,PMLockType lock, global_game_variables_t *gvar),\r
                                PM_SetMainPurge(int level),\r
-                               PM_CheckMainMem(void);\r
-extern memptr  PM_GetPageAddress(int pagenum),\r
-                               PM_GetPage(int pagenum);                // Use this one to cache page\r
+                               PM_CheckMainMem(global_game_variables_t *gvar);\r
+extern memptr  PM_GetPageAddress(int pagenum, global_game_variables_t *gvar),\r
+                               PM_GetPage(int pagenum, global_game_variables_t *gvar);         // Use this one to cache page\r
 \r
-PM_SetMainMemPurge(int level, global_game_variables_t *gvar);\r
+void PM_SetMainMemPurge(int level, global_game_variables_t *gvar);\r
+#endif\r
index 43e46906e294a1d3d69becd6b3c274e160f24fe8..a0203ca74a8bb57fe91629029f78b2995b5d6d55 100755 (executable)
@@ -170,8 +170,8 @@ typedef struct
        void __near     *nearheap;\r
 #endif\r
        //byte          EMS_status;\r
-       unsigned        totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;\r
-       unsigned int EMSVer;\r
+       unsigned        totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;//TODO: PM use\r
+       //unsigned int EMSVer;\r
        word numUMBs,UMBbase[MAXUMBS];\r
        //dword numUMBs,UMBbase[MAXUMBS];\r
        //huge mmblocktype      huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;\r
@@ -247,7 +247,7 @@ typedef struct
 {\r
        boolean                 EMSPresent;\r
        word                    EMSAvail,EMSPagesAvail,EMSHandle,\r
-                                       EMSPageFrame,EMSPhysicalPage;\r
+                                       EMSPageFrame,EMSPhysicalPage, EMSVer;\r
        EMSListStruct   EMSList[EMSFrameCount];\r
 } pm_emmi_t;\r
 \r
@@ -256,7 +256,7 @@ typedef struct
 {\r
        boolean                 XMSPresent;\r
        word                    XMSAvail,XMSPagesAvail,XMSHandle;\r
-       word                    XMSDriver;      //TODO: changed to word\r
+       dword                   XMSDriver;      //TODO: changed to word\r
        int                             XMSProtectPage;// = -1;\r
 } pm_xmmi_t;\r
 \r
index 1c8a15aa96201e1a6bdb038cef52905e67c6fe72..8ed436206a06a204883da280ee7c26435092ac08 100755 (executable)
@@ -72,7 +72,7 @@ void main() {
        //gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);
 
        gvar.mm.mmstarted=0;
-       MM_Startup(&gvar.mm, &gvar.mmi);
+       MM_Startup(&gvar);
        CA_Startup(&gvar);
        // What should be done by read_vrs:
        //sega = (mm.bufferseg);
@@ -153,12 +153,12 @@ void main() {
        }
        VGAmodeX(0, 1, &gvar);
        MM_ShowMemory(&gvar);
-       MM_DumpData(&gvar.mm);
+       MM_DumpData(&gvar);
        free(spri.sprite_vrl_cont);
-       MM_FreePtr(&bigbuffer, &gvar.mm);
+       MM_FreePtr(&bigbuffer, &gvar);
        //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
        CA_Shutdown(&gvar);
-       MM_Shutdown(&gvar.mm);
+       MM_Shutdown(&gvar);
        //printf("CPU to VGA: %f\n", t1);
        //printf("VGA to VGA: %f\n", t2);
        heapdump(&gvar);