]> 4ch.mooo.com Git - 16.git/commitdiff
16_pm portings
authorsparky4 <sparky4@cock.li>
Tue, 20 Sep 2016 16:44:27 +0000 (11:44 -0500)
committersparky4 <sparky4@cock.li>
Tue, 20 Sep 2016 16:44:27 +0000 (11:44 -0500)
makefile
src/lib/16_head.h
src/lib/16_mm.h
src/lib/16_pm.c
src/lib/16_pm.h
src/lib/typdefst.h

index ddf393d1a5e3d924b0ddedf83870482aa054a483..7c2d12c23be19d89230e41c27ee5ce4f7dabbacb 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=256
+T_FLAGS=-bt=dos -mh -0 -fpi87 -fo=.$(OBJ) -d1 -e=20
 
 CPPFLAGS=-DTARGET_MSDOS=16 -DMSDOS=1
 !ifeq DEBUGSERIAL 1
index acd1e1ec53439daaab1f0391a2a7c43a9db6a1b4..b840043d4fd149606472f7f4ae2d00d84c585642 100755 (executable)
@@ -159,7 +159,23 @@ extern     int                     profilehandle,debughandle;      //make it into game global
 #endif\r
 #ifdef __WATCOMC__\r
 #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
 #define pokeb(segm,ofs,value) (peekb((segm),(ofs)) = (byte)(value))\r
index 33e1e526cfb55f87c27e0120ec225a42f96d77a8..bdc974298938a1de8171c05e71a0271da285b063 100755 (executable)
 
 //--------
 
+#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        XMS_VERSION             0x00
 
 #define        XMS_ALLOCHMA    0x01
@@ -76,7 +82,7 @@
 #define        XMS_LDISABLEA20 0x06
 #define        XMS_QUERYA20    0x07
 
-#define        XMS_QUERYREE    0x08
+#define        XMS_QUERYFREE   0x08
 #define        XMS_ALLOC               0x09
 #define        XMS_FREE                0x0A
 #define        XMS_MOVE                0x0B
index 48bd2bf9a9c0654c838bc478e95a182076b640ce..0b04b16eee30a37f53a12a4d1334a926e8fd90f0 100755 (executable)
        int                             MainPagesAvail;\r
 \r
 //     EMS specific variables\r
-       boolean                 EMSPresent;\r
-       word                    EMSAvail,EMSPagesAvail,EMSHandle,\r
-                                       EMSPageFrame,EMSPhysicalPage;\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
 \r
 //     XMS specific variables\r
-       boolean                 XMSPresent;\r
-       word                    XMSAvail,XMSPagesAvail,XMSHandle;\r
+       boolean                 gvar->pm.xmm.XMSPresent;\r
+       word                    gvar->pm.xmm.XMSAvail,gvar->pm.xmm.XMSPagesAvail,gvar->pm.xmm.XMSHandle;\r
        dword           XMSDriver;\r
-       int                             XMSProtectPage = -1;\r
+       int                             gvar->pm.xmm.XMSProtectPage = -1;\r
 \r
 //     File specific variables\r
        char                    PageFileName[13] = {"VSWAP."};\r
        int                             PageFile = -1;\r
-       word                    ChunksInFile;\r
+       word                    gvar->pm.fi.ChunksInFile;\r
        word                    PMSpriteStart,PMSoundStart;\r
 \r
 //     General usage variables\r
        boolean                 PMStarted,\r
                                        PMPanicMode,\r
                                        PMThrashing;\r
-       word                    XMSPagesUsed,\r
-                                       EMSPagesUsed,\r
+       word                    gvar->pm.xmm.XMSPagesUsed,\r
+                                       gvar->pm.emm.EMSPagesUsed,\r
                                        MainPagesUsed,\r
                                        PMNumBlocks;\r
        long                    PMFrameCount;\r
@@ -55,12 +55,12 @@ static      char            *ParmStrings[] = {"nomain","noems","noxms",nil};
 //     PML_MapEMS() - Maps a logical page to a physical page\r
 //\r
 void\r
-PML_MapEMS(word logical,word physical)\r
+PML_MapEMS(word logical, word physical, global_game_variables_t *gvar)\r
 {\r
        union REGS CPURegs;\r
        CPURegs.h.al = physical;\r
        CPURegs.x.bx = logical;\r
-       CPURegs.x.dx = EMSHandle;\r
+       CPURegs.x.dx = gvar->pm.emm.EMSHandle;\r
        CPURegs.h.ah = EMS_MAPPAGE;\r
        __asm\r
        {\r
@@ -86,37 +86,66 @@ PML_MapEMS(word logical,word physical)
        char    EMMDriverName[9] = "EMMXXXX0";\r
 \r
 boolean\r
-PML_StartupEMS(void)\r
+PML_StartupEMS(global_game_variables_t *gvar)\r
 {\r
+       boolean emmcfems;\r
        union REGS CPURegs;\r
+\r
        int             i;\r
        long    size;\r
 \r
-       EMSPresent = false;                     // Assume that we'll fail\r
-       EMSAvail = 0;\r
-\r
-       CPURegs.x.dx = (word)EMMDriverName;\r
-       CPURegs.x.ax = 0x3d00;\r
-       geninterrupt(0x21);                     // try to open EMMXXXX0 device\r
-__asm  jnc     gothandle\r
-       goto error;\r
+       gvar->pm.emm.EMSPresent = false;                        // Assume that we'll fail\r
+       gvar->pm.emm.EMSAvail = 0;\r
+       emmcfems=0;\r
+\r
+       __asm {\r
+       //CPURegs.x.dx = (word)EMMDriverName;\r
+       //CPURegs.x.ax = 0x3d00;\r
+       //geninterrupt(0x21);                   // try to open EMMXXXX0 device\r
+               mov     dx,OFFSET EMMDriverName\r
+               mov     ax,0x3d00\r
+               int     0x21            // try to open EMMXXXX0 device\r
+               jnc     gothandle\r
+               //fail\r
+               mov     emmcfems,1\r
+               jmp             Aend\r
+#ifdef __BORLANDC__\r
+       }\r
+#endif\r
 \r
 gothandle:\r
-       CPURegs.x.bx = CPURegs.x.ax;\r
-       CPURegs.x.ax = 0x4400;\r
-       geninterrupt(0x21);                     // get device info\r
-asm    jnc     gotinfo;\r
-       goto error;\r
-\r
+#ifdef __BORLANDC__\r
+       __asm {\r
+#endif\r
+       //CPURegs.x.bx = CPURegs.x.ax;\r
+       //CPURegs.x.ax = 0x4400;\r
+       //geninterrupt(0x21);                   // get device info\r
+               mov     bx,ax\r
+               mov     ax,0x4400\r
+               int     0x21                    // get device info\r
+               jnc     gotinfo\r
+               //fail\r
+               mov     emmcfems,1\r
+               jmp             Aend\r
+#ifdef __BORLANDC__\r
+       }\r
+#endif\r
+Aend:\r
 gotinfo:\r
-asm    and     dx,0x80\r
+#ifndef __BORLANDC__\r
+       }\r
+#endif\r
+       if(emmcfems!=0) goto error;\r
+       __asm and       dx,0x80\r
        if (!CPURegs.x.dx)\r
                goto error;\r
 \r
        CPURegs.x.ax = 0x4407;\r
        geninterrupt(0x21);                     // get status\r
-asm    jc      error\r
-       if (!CPURegs.l.al)\r
+       __asm mov       emmcfems,1\r
+       if(emmcfems!=0) goto error;\r
+\r
+       if (!CPURegs.h.al)\r
                goto error;\r
 \r
        CPURegs.h.ah = 0x3e;\r
@@ -129,14 +158,14 @@ asm       jc      error
 \r
        CPURegs.h.ah = EMS_VERSION;\r
        geninterrupt(EMS_INT);\r
-       if (CPURegs.h.ah || (CPURegs.l.al < 0x32))      // only work on EMS 3.2 or greater (silly, but...)\r
+       if (CPURegs.h.ah || (CPURegs.h.al < 0x32))      // only work on EMS 3.2 or greater (silly, but...)\r
                goto error;\r
 \r
        CPURegs.h.ah = EMS_GETFRAME;\r
        geninterrupt(EMS_INT);\r
        if (CPURegs.h.ah)\r
                goto error;                             // find the page frame address\r
-       EMSPageFrame = CPURegs.x.bx;\r
+       gvar->pm.emm.EMSPageFrame = CPURegs.x.bx;\r
 \r
        CPURegs.h.ah = EMS_GETPAGES;\r
        geninterrupt(EMS_INT);\r
@@ -144,48 +173,48 @@ asm       jc      error
                goto error;\r
        if (CPURegs.x.bx < 2)\r
                goto error;             // Require at least 2 pages (32k)\r
-       EMSAvail = CPURegs.x.bx;\r
+       gvar->pm.emm.EMSAvail = CPURegs.x.bx;\r
 \r
        // Don't hog all available EMS\r
-       size = EMSAvail * (long)EMSPageSize;\r
-       if (size - (EMSPageSize * 2) > (ChunksInFile * (long)PMPageSize))\r
+       size = gvar->pm.emm.EMSAvail * (long)EMSPageSize;\r
+       if (size - (EMSPageSize * 2) > (gvar->pm.fi.ChunksInFile * (long)PMPageSize))\r
        {\r
-               size = (ChunksInFile * (long)PMPageSize) + EMSPageSize;\r
-               EMSAvail = size / EMSPageSize;\r
+               size = (gvar->pm.fi.ChunksInFile * (long)PMPageSize) + EMSPageSize;\r
+               gvar->pm.emm.EMSAvail = size / EMSPageSize;\r
        }\r
 \r
-       CPURegs.h.ah = EMSCPURegs.l.alLOCPAGES;\r
-       CPURegs.x.bx = EMSAvail;\r
+       CPURegs.h.ah = EMS_ALLOCPAGES;\r
+       CPURegs.x.bx = gvar->pm.emm.EMSAvail;\r
        geninterrupt(EMS_INT);\r
        if (CPURegs.h.ah)\r
                goto error;\r
-       EMSHandle = CPURegs.x.dx;\r
+       gvar->pm.emm.EMSHandle = CPURegs.x.dx;\r
 \r
-       mminfo.EMSmem += EMSAvail * (long)EMSPageSize;\r
+       gvar->mmi.EMSmem += gvar->pm.emm.EMSAvail * (long)EMSPageSize;\r
 \r
        // Initialize EMS mapping cache\r
        for (i = 0;i < EMSFrameCount;i++)\r
-               EMSList[i].baseEMSPage = -1;\r
+               gvar->pm.emm.EMSList[i].baseEMSPage = -1;\r
 \r
-       EMSPresent = true;                      // We have EMS\r
+       gvar->pm.emm.EMSPresent = true;                 // We have EMS\r
 \r
 error:\r
-       return(EMSPresent);\r
+       return(gvar->pm.emm.EMSPresent);\r
 }\r
 \r
 //\r
 //     PML_ShutdownEMS() - If EMS was used, deallocate it\r
 //\r
 void\r
-PML_ShutdownEMS(void)\r
+PML_ShutdownEMS(global_game_variables_t *gvar)\r
 {\r
-       if (EMSPresent)\r
+       union REGS CPURegs;\r
+\r
+       if (gvar->pm.emm.EMSPresent)\r
        {\r
-               __asm {\r
-                       mov     ah,EMS_FREEPAGES\r
-                       mov     dx,[EMSHandle]\r
-                       int     EMS_INT\r
-               }\r
+                       CPURegs.h.ah=EMS_FREEPAGES;\r
+                       CPURegs.x.ax=gvar->pm.emm.EMSHandle;\r
+                       geninterrupt(EMS_INT);\r
                if (CPURegs.h.ah)\r
                {\r
                        Quit("PML_ShutdownEMS: Error freeing EMS\n");\r
@@ -207,46 +236,51 @@ PML_ShutdownEMS(void)
 //             Allocates any remaining XMS (rounded down to the nearest page size)\r
 //\r
 boolean\r
-PML_StartupXMS(void)\r
+PML_StartupXMS(global_game_variables_t *gvar)\r
 {\r
-       XMSPresent = false;                                     // Assume failure\r
-       XMSAvail = 0;\r
+       union REGS CPURegs;\r
 \r
-asm    mov     ax,0x4300\r
-asm    int     XMS_INT                                         // Check for presence of XMS driver\r
-       if (CPURegs.l.al != 0x80)\r
+       XMSD;\r
+       gvar->pm.xmm.XMSPresent = false;                                        // Assume failure\r
+       gvar->pm.xmm.XMSAvail = 0;\r
+\r
+       CPURegs.x.ax=0x4300;\r
+       geninterrupt(XMS_INT);                                  // Check for presence of XMS driver\r
+       if (CPURegs.h.al != 0x80)\r
                goto error;\r
 \r
 \r
-asm    mov     ax,0x4310\r
-asm    int     XMS_INT                                                 // Get address of XMS driver\r
-asm    mov     [WORD PTR XMSDriver],bx\r
-asm    mov     [WORD PTR XMSDriver+2],es               // function pointer to XMS driver\r
+       __asm {\r
+               mov     ax,0x4310\r
+               int     XMS_INT                                                 // Get address of XMS driver\r
+               mov     [WORD PTR XMSDriver],bx\r
+               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
-       XMSAvail = CPURegs.x.ax;\r
+       gvar->pm.xmm.XMSAvail = CPURegs.x.ax;\r
        if (!CPURegs.x.ax)                              // AJR: bugfix 10/8/92\r
                goto error;\r
 \r
-       XMSAvail &= ~(PMPageSizeKB - 1);        // Round off to nearest page size\r
-       if (XMSAvail < (PMPageSizeKB * 2))      // Need at least 2 pages\r
+       gvar->pm.xmm.XMSAvail &= ~(PMPageSizeKB - 1);   // Round off to nearest page size\r
+       if (gvar->pm.xmm.XMSAvail < (PMPageSizeKB * 2)) // Need at least 2 pages\r
                goto error;\r
 \r
-       CPURegs.x.dx = XMSAvail;\r
-       XMS_CALL(XMSCPURegs.l.alLOC);                           // And do the allocation\r
-       XMSHandle = CPURegs.x.dx;\r
+       CPURegs.x.dx = gvar->pm.xmm.XMSAvail;\r
+       XMS_CALL(XMS_ALLOC);                            // And do the allocation\r
+       gvar->pm.xmm.XMSHandle = CPURegs.x.dx;\r
 \r
        if (!CPURegs.x.ax)                              // AJR: bugfix 10/8/92\r
        {\r
-               XMSAvail = 0;\r
+               gvar->pm.xmm.XMSAvail = 0;\r
                goto error;\r
        }\r
 \r
-       mminfo.XMSmem += XMSAvail * 1024;\r
+       gvar->mmi.XMSmem += gvar->pm.xmm.XMSAvail * 1024;\r
 \r
-       XMSPresent = true;\r
+       gvar->pm.xmm.XMSPresent = true;\r
 error:\r
-       return(XMSPresent);\r
+       return(gvar->pm.xmm.XMSPresent);\r
 }\r
 \r
 //\r
@@ -254,8 +288,9 @@ error:
 //             Will round an odd-length request up to the next even value\r
 //\r
 void\r
-PML_XMSCopy(boolean toxms,byte far *addr,word xmspage,word length)\r
+PML_XMSCopy(boolean toxms,byte far *addr,word xmspage,word length, global_game_variables_t *gvar)\r
 {\r
+       XMSD;\r
        dword   xoffset;\r
        struct\r
        {\r
@@ -275,15 +310,19 @@ PML_XMSCopy(boolean toxms,byte far *addr,word xmspage,word length)
        xoffset = (dword)xmspage * PMPageSize;\r
 \r
        copy.length = (length + 1) & ~1;\r
-       copy.source_handle = toxms? 0 : XMSHandle;\r
+       copy.source_handle = toxms? 0 : gvar->pm.xmm.XMSHandle;\r
        copy.source_offset = toxms? (long)addr : xoffset;\r
-       copy.target_handle = toxms? XMSHandle : 0;\r
+       copy.target_handle = toxms? gvar->pm.xmm.XMSHandle : 0;\r
        copy.target_offset = toxms? xoffset : (long)addr;\r
 \r
-asm    push si\r
-       CPURegs.i.si = (word)&copy;\r
+       __asm {\r
+               push si\r
+       }\r
+       CPURegs.x.si = (word)&copy;\r
        XMS_CALL(XMS_MOVE);\r
-asm    pop     si\r
+       __asm {\r
+               pop     si\r
+       }\r
        if (!CPURegs.x.ax)\r
        {\r
                Quit("PML_XMSCopy: Error on copy");\r
@@ -320,13 +359,14 @@ PML_CopyFromXMS(byte far *target,int sourcepage,word length)
 //     PML_ShutdownXMS()\r
 //\r
 void\r
-PML_ShutdownXMS(void)\r
+PML_ShutdownXMS(global_game_variables_t *gvar)\r
 {\r
-       if (XMSPresent)\r
+       XMSD;\r
+       if (gvar->pm.xmm.XMSPresent)\r
        {\r
-               CPURegs.x.dx = XMSHandle;\r
+               CPURegs.x.dx = gvar->pm.xmm.XMSHandle;\r
                XMS_CALL(XMS_FREE);\r
-               if (CPURegs.l.bl)\r
+               if (CPURegs.h.bl)\r
                {\r
                        Quit("PML_ShutdownXMS: Error freeing XMS");\r
                        //return;\r
@@ -346,13 +386,14 @@ PML_ShutdownXMS(void)
 //             PM_UnlockMainMem() macros should be used instead.\r
 //\r
 void\r
-PM_SetMainMemPurge(int level)\r
+PM_SetMainMemPurge(int level, global_game_variables_t *gvar)\r
 {\r
        int     i;\r
 \r
        for (i = 0;i < PMMaxMainMem;i++)\r
-               if (MainMemPages[i])\r
-                       MM_SetPurge(&MainMemPages[i],level);\r
+               if (gvar->pm.mm.MainMemPages[i])\r
+                       MM_SetPurge(&gvar->pm.mm.MainMemPages[i],level);\r
+       return 0;//TODO FIX\r
 }\r
 \r
 //\r
@@ -380,7 +421,7 @@ PM_CheckMainMem(void)
        if (!MainPresent)\r
                return;\r
 \r
-       for (i = 0,page = PMPages;i < ChunksInFile;i++,page++)\r
+       for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
        {\r
                n = page->mainPage;\r
                if (n != -1)                                            // Is the page using main memory?\r
@@ -535,19 +576,19 @@ PML_OpenPageFile(void)
        }\r
 \r
        // Read in header variables\r
-       read(PageFile,&ChunksInFile,sizeof(ChunksInFile));\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
 \r
        // Allocate and clear the page list\r
-       PMNumBlocks = ChunksInFile;\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
 \r
        // Read in the chunk offsets\r
-       size = sizeof(dword) * ChunksInFile;\r
+       size = sizeof(dword) * gvar->pm.fi.ChunksInFile;\r
        MM_GetPtr(&buf,size);\r
        if (!CA_FarRead(PageFile,(byte far *)buf,size))\r
        {\r
@@ -555,12 +596,12 @@ PML_OpenPageFile(void)
                //return;\r
        }\r
        offsetptr = (dword far *)buf;\r
-       for (i = 0,page = PMPages;i < ChunksInFile;i++,page++)\r
+       for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
                page->offset = *offsetptr++;\r
        MM_FreePtr(&buf);\r
 \r
        // Read in the chunk lengths\r
-       size = sizeof(word) * ChunksInFile;\r
+       size = sizeof(word) * gvar->pm.fi.ChunksInFile;\r
        MM_GetPtr(&buf,size);\r
        if (!CA_FarRead(PageFile,(byte far *)buf,size))\r
        {\r
@@ -568,7 +609,7 @@ PML_OpenPageFile(void)
                //return;\r
        }\r
        lengthptr = (word far *)buf;\r
-       for (i = 0,page = PMPages;i < ChunksInFile;i++,page++)\r
+       for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
                page->length = *lengthptr++;\r
        MM_FreePtr(&buf);\r
 }\r
@@ -595,7 +636,7 @@ PML_ClosePageFile(void)
 /////////////////////////////////////////////////////////////////////////////\r
 \r
 //\r
-//     PML_GetEMSAddress()\r
+//     PML_Getgvar->pm.emm.EMSAddress()\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
@@ -604,7 +645,7 @@ PML_ClosePageFile(void)
 #ifdef __DEBUG__\r
 #pragma argsused       // DEBUG - remove lock parameter\r
 memptr\r
-PML_GetEMSAddress(int page,PMLockType lock)\r
+PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)\r
 {\r
        int             i,emspage;\r
        word    emsoff,emsbase,offset;\r
@@ -616,7 +657,7 @@ PML_GetEMSAddress(int page,PMLockType lock)
        // See if this page is already mapped in\r
        for (i = 0;i < EMSFrameCount;i++)\r
        {\r
-               if (EMSList[i].baseEMSPage == emsbase)\r
+               if (EMSList[i].basegvar->pm.emm.EMSPage == emsbase)\r
                {\r
                        emspage = i;    // Yep - don't do a redundant remapping\r
                        break;\r
@@ -636,21 +677,21 @@ PML_GetEMSAddress(int page,PMLockType lock)
                        }\r
                }\r
 \r
-               EMSList[emspage].baseEMSPage = emsbase;\r
+               EMSList[emspage].basegvar->pm.emm.EMSPage = emsbase;\r
                PML_MapEMS(page / PMEMSSubPage,emspage);\r
        }\r
 \r
        if (emspage == -1)\r
-               Quit("PML_GetEMSAddress: EMS find failed");\r
+               Quit("PML_Getgvar->pm.emm.EMSAddress: EMS find failed");\r
 \r
        EMSList[emspage].lastHit = PMFrameCount;\r
        offset = emspage * EMSPageSizeSeg;\r
        offset += emsoff * PMPageSizeSeg;\r
-       return((memptr)(EMSPageFrame + offset));\r
+       return((memptr)(gvar->pm.emm.EMSPageFrame + offset));\r
 }\r
 #else\r
 memptr\r
-PML_GetEMSAddress(int page,PMLockType lock)\r
+PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)\r
 {\r
        word    emspage;\r
 \r
@@ -658,7 +699,7 @@ PML_GetEMSAddress(int page,PMLockType lock)
 \r
        PML_MapEMS(page / PMEMSSubPage,emspage);\r
 \r
-       return((memptr)(EMSPageFrame + (emspage * EMSPageSizeSeg)\r
+       return((memptr)(gvar->pm.emm.EMSPageFrame + (emspage * EMSPageSizeSeg)\r
                        + ((page & (PMEMSSubPage - 1)) * PMPageSizeSeg)));\r
 }\r
 #endif\r
@@ -678,7 +719,7 @@ PM_GetPageAddress(int pagenum)
        if (page->mainPage != -1)\r
                return(MainMemPages[page->mainPage]);\r
        else if (page->emsPage != -1)\r
-               return(PML_GetEMSAddress(page->emsPage,page->locked));\r
+               return(PML_Getgvar->pm.emm.EMSAddress(page->emsPage,page->locked));\r
        else\r
                return(nil);\r
 }\r
@@ -694,7 +735,7 @@ PML_GiveLRUPage(boolean mainonly)
        long                    last;\r
        PageListStruct  far *page;\r
 \r
-       for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < ChunksInFile;i++,page++)\r
+       for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
        {\r
                if\r
                (\r
@@ -715,24 +756,24 @@ PML_GiveLRUPage(boolean mainonly)
 }\r
 \r
 //\r
-//     PML_GiveLRUXMSPage() - Returns the page # of the least recently used\r
+//     PML_GiveLRUgvar->pm.xmm.XMSPage() - Returns the page # of the least recently used\r
 //             (and present) XMS page.\r
-//     This routine won't return the XMS page protected (by XMSProtectPage)\r
+//     This routine won't return the XMS page protected (by gvar->pm.xmm.XMSProtectPage)\r
 //\r
 int\r
-PML_GiveLRUXMSPage(void)\r
+PML_GiveLRUgvar->pm.xmm.XMSPage(void)\r
 {\r
        int                             i,lru;\r
        long                    last;\r
        PageListStruct  far *page;\r
 \r
-       for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < ChunksInFile;i++,page++)\r
+       for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
        {\r
                if\r
                (\r
                        (page->xmsPage != -1)\r
                &&      (page->lastHit < last)\r
-               &&      (i != XMSProtectPage)\r
+               &&      (i != gvar->pm.xmm.XMSProtectPage)\r
                )\r
                {\r
                        last = page->lastHit;\r
@@ -752,18 +793,18 @@ PML_PutPageInXMS(int pagenum)
        int                             usexms;\r
        PageListStruct  far *page;\r
 \r
-       if (!XMSPresent)\r
+       if (!gvar->pm.xmm.XMSPresent)\r
                return;\r
 \r
        page = &PMPages[pagenum];\r
        if (page->xmsPage != -1)\r
                return;                                 // Already in XMS\r
 \r
-       if (XMSPagesUsed < XMSPagesAvail)\r
-               page->xmsPage = XMSPagesUsed++;\r
+       if (gvar->pm.xmm.XMSPagesUsed < gvar->pm.xmm.XMSPagesAvail)\r
+               page->xmsPage = gvar->pm.xmm.XMSPagesUsed++;\r
        else\r
        {\r
-               usexms = PML_GiveLRUXMSPage();\r
+               usexms = PML_GiveLRUgvar->pm.xmm.XMSPage();\r
                if (usexms == -1)\r
                        Quit("PML_PutPageInXMS: No XMS LRU");\r
                page->xmsPage = PMPages[usexms].xmsPage;\r
@@ -830,11 +871,11 @@ PML_GetAPageBuffer(int pagenum,boolean mainonly)
        PageListStruct  far *page;\r
 \r
        page = &PMPages[pagenum];\r
-       if ((EMSPagesUsed < EMSPagesAvail) && !mainonly)\r
+       if ((gvar->pm.emm.EMSPagesUsed < gvar->pm.emm.EMSPagesAvail) && !mainonly)\r
        {\r
                // There's remaining EMS - use it\r
-               page->emsPage = EMSPagesUsed++;\r
-               addr = PML_GetEMSAddress(page->emsPage,page->locked);\r
+               page->emsPage = gvar->pm.emm.EMSPagesUsed++;\r
+               addr = PML_Getgvar->pm.emm.EMSAddress(page->emsPage,page->locked);\r
        }\r
        else if (MainPagesUsed < MainPagesAvail)\r
        {\r
@@ -868,7 +909,7 @@ 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
-//     XMSProtectPage is set to the page to be retrieved from XMS, so that if\r
+//     gvar->pm.xmm.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
@@ -881,15 +922,15 @@ PML_GetPageFromXMS(int pagenum,boolean mainonly)
        PageListStruct  far *page;\r
 \r
        page = &PMPages[pagenum];\r
-       if (XMSPresent && (page->xmsPage != -1))\r
+       if (gvar->pm.xmm.XMSPresent && (page->xmsPage != -1))\r
        {\r
-               XMSProtectPage = pagenum;\r
+               gvar->pm.xmm.XMSProtectPage = pagenum;\r
                checkaddr = PML_GetAPageBuffer(pagenum,mainonly);\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
-               XMSProtectPage = -1;\r
+               gvar->pm.xmm.XMSProtectPage = -1;\r
        }\r
 \r
        return(addr);\r
@@ -923,17 +964,19 @@ PM_GetPage(int pagenum)
 {\r
        memptr  result;\r
 \r
-       if (pagenum >= ChunksInFile)\r
+       if (pagenum >= gvar->pm.fi.ChunksInFile)\r
                Quit("PM_GetPage: Invalid page request");\r
 \r
-#if 0  // for debugging\r
-asm    mov     dx,STATUS_REGISTER_1\r
-asm    in      al,dx\r
-asm    mov     dx,ATR_INDEX\r
-asm    mov     al,ATR_OVERSCAN\r
-asm    out     dx,al\r
-asm    mov     al,10   // bright green\r
-asm    out     dx,al\r
+#if __DEBUG__  // for debugging\r
+       __asm {\r
+               mov     dx,STATUS_REGISTER_1\r
+               in      al,dx\r
+               mov     dx,ATR_INDEX\r
+               mov     al,ATR_OVERSCAN\r
+               out     dx,al\r
+               mov     al,10   // bright green\r
+               out     dx,al\r
+       }\r
 #endif\r
 \r
        if (!(result = PM_GetPageAddress(pagenum)))\r
@@ -952,16 +995,17 @@ if (!PMPages[pagenum].offset)     // JDC: sparse page
        }\r
        PMPages[pagenum].lastHit = PMFrameCount;\r
 \r
-#if 0  // for debugging\r
-asm    mov     dx,STATUS_REGISTER_1\r
-asm    in      al,dx\r
-asm    mov     dx,ATR_INDEX\r
-asm    mov     al,ATR_OVERSCAN\r
-asm    out     dx,al\r
-asm    mov     al,3    // blue\r
-asm    out     dx,al\r
-asm    mov     al,0x20 // normal\r
-asm    out     dx,al\r
+#if __DEBUG__  // for debugging\r
+       __asm{\r
+               mov     dx,STATUS_REGISTER_1\r
+               in      al,dx\r
+               mov     dx,ATR_INDEX\r
+               mov     al,ATR_OVERSCAN\r
+               out     dx,al\r
+               mov     al,3    // blue\r
+               out     dx,al\r
+               mov     al,0x20 // normal\r
+               out     dx,al\r
 #endif\r
 \r
        return(result);\r
@@ -1002,12 +1046,12 @@ PM_Preload(boolean (*update)(word current,word total))
        memptr                  addr;\r
        PageListStruct  far *p;\r
 \r
-       mainfree = (MainPagesAvail - MainPagesUsed) + (EMSPagesAvail - EMSPagesUsed);\r
-       xmsfree = (XMSPagesAvail - XMSPagesUsed);\r
+       mainfree = (MainPagesAvail - MainPagesUsed) + (gvar->pm.emm.EMSPagesAvail - gvar->pm.emm.EMSPagesUsed);\r
+       xmsfree = (gvar->pm.xmm.XMSPagesAvail - gvar->pm.xmm.XMSPagesUsed);\r
 \r
        xmstotal = maintotal = 0;\r
 \r
-       for (i = 0;i < ChunksInFile;i++)\r
+       for (i = 0;i < gvar->pm.fi.ChunksInFile;i++)\r
        {\r
                if (!PMPages[i].offset)\r
                        continue;                       // sparse\r
@@ -1045,8 +1089,8 @@ PM_Preload(boolean (*update)(word current,word total))
                        ||      PMPages[page].emsPage != -1 )\r
                        page++;\r
 \r
-               if (page >= ChunksInFile)\r
-                       Quit ("PM_Preload: Pages>=ChunksInFile");\r
+               if (page >= gvar->pm.fi.ChunksInFile)\r
+                       Quit ("PM_Preload: Pages>=gvar->pm.fi.ChunksInFile");\r
 \r
                PM_GetPage(page);\r
 \r
@@ -1072,13 +1116,13 @@ PM_Preload(boolean (*update)(word current,word total))
                        while ( !PMPages[page].offset || PMPages[page].xmsPage != -1 )\r
                                page++;\r
 \r
-                       if (page >= ChunksInFile)\r
-                               Quit ("PM_Preload: Pages>=ChunksInFile");\r
+                       if (page >= gvar->pm.fi.ChunksInFile)\r
+                               Quit ("PM_Preload: Pages>=gvar->pm.fi.ChunksInFile");\r
 \r
                        p = &PMPages[page];\r
 \r
-                       p->xmsPage = XMSPagesUsed++;\r
-                       if (XMSPagesUsed > XMSPagesAvail)\r
+                       p->xmsPage = gvar->pm.xmm.XMSPagesUsed++;\r
+                       if (gvar->pm.xmm.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
@@ -1161,12 +1205,12 @@ PM_Reset(void)
        int                             i;\r
        PageListStruct  far *page;\r
 \r
-       XMSPagesAvail = XMSAvail / PMPageSizeKB;\r
+       gvar->pm.xmm.XMSPagesAvail = gvar->pm.xmm.XMSAvail / PMPageSizeKB;\r
 \r
-       EMSPagesAvail = EMSAvail * (EMSPageSizeKB / PMPageSizeKB);\r
-       EMSPhysicalPage = 0;\r
+       gvar->pm.emm.EMSPagesAvail = gvar->pm.emm.EMSAvail * (EMSPageSizeKB / PMPageSizeKB);\r
+       gvar->pm.emm.EMSPhysicalPage = 0;\r
 \r
-       MainPagesUsed = EMSPagesUsed = XMSPagesUsed = 0;\r
+       MainPagesUsed = gvar->pm.emm.EMSPagesUsed = gvar->pm.xmm.XMSPagesUsed = 0;\r
 \r
        PMPanicMode = false;\r
 \r
@@ -1216,7 +1260,7 @@ PM_Startup(void)
        if (!noxms)\r
                PML_StartupXMS();\r
 \r
-       if (nomain && !EMSPresent)\r
+       if (nomain && !gvar->pm.emm.EMSPresent)\r
        {\r
                Quit("PM_Startup: No main or EMS\n");\r
                //return;\r
index f8b62c40513adec987c2cd4184db701afb94f24c..973b08b404eaa98cc7d5aa3badb60faccf3707f6 100755 (executable)
@@ -6,6 +6,7 @@
 #include "src/lib/16_head.h"\r
 #include "src/lib/16_hc.h"\r
 #include "src/lib/16_mm.h"\r
+#include <dos.h>\r
 \r
 /*//   NOTE! PMPageSize must be an even divisor of EMSPageSize, and >= 1024\r
 #define        EMSPageSize             16384\r
@@ -84,4 +85,4 @@ extern        void    PM_Startup(void),
 extern memptr  PM_GetPageAddress(int pagenum),\r
                                PM_GetPage(int pagenum);                // Use this one to cache page\r
 \r
-void PM_SetMainMemPurge(int level);\r
+PM_SetMainMemPurge(int level, global_game_variables_t *gvar);\r
index 137b00b6e2e316e1e183bb1672e9b2edda97a118..43e46906e294a1d3d69becd6b3c274e160f24fe8 100755 (executable)
@@ -256,7 +256,7 @@ typedef struct
 {\r
        boolean                 XMSPresent;\r
        word                    XMSAvail,XMSPagesAvail,XMSHandle;\r
-       dword           XMSDriver;\r
+       word                    XMSDriver;      //TODO: changed to word\r
        int                             XMSProtectPage;// = -1;\r
 } pm_xmmi_t;\r
 \r