]> 4ch.mooo.com Git - 16.git/commitdiff
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww massive work there is issue with...
authorsparky4 <sparky4@cock.li>
Mon, 26 Sep 2016 18:04:11 +0000 (13:04 -0500)
committersparky4 <sparky4@cock.li>
Mon, 26 Sep 2016 18:04:11 +0000 (13:04 -0500)
14 files changed:
DEBUG.16B
DEBUG.16W
HEAP.16W
MMDUMP.16B
MMDUMP.16W
bcexmm.exe
bcexmm.prj
src/exmmtest.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

index f5605e8569417be970e53cea18f527efe53b7816..d6ad70e76ef9ab0113476c9d10946ff100e7f400 100755 (executable)
--- a/DEBUG.16B
+++ b/DEBUG.16B
@@ -1,9 +1,7 @@
-\e[0mSeg:0      Size:3547       Owner:0x696c\r
+\e[0mSeg:0      Size:3552       Owner:0x6974\r
 \e[41;31m+++++++++++++++++++++++++++++++++++++++++++++\e[0m\e[42;32m0\r
-\e[0m\e[0mSeg:ddb        Size:256        Owner:0xcf85\r
-\e[44;34m++++\e[0m\e[42;32m\r
-\e[0m\e[0mSeg:edb        Size:273        Owner:0xfde\r
-\e[44;34m++++\e[0m\e[42;32m0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r
+\e[0m\e[0mSeg:de0        Size:256        Owner:0xcf79\r
+\e[44;34m++++\e[0m\e[42;32m0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r
 \e[0m\e[0mSeg:9fde       Size:28706      Owner:0x0\r
 \e[41;31m\e[0m\e[42;32m\r
 \e[0m\e[0mSeg:9ffe       Size:24577      Owner:0x0\r
index d8f8cf89f43a5aa6a238abf3e6b5a9ec0282ce42..b3ed514bf3eaf5171b9ef596fc8080fb074755ec 100755 (executable)
--- a/DEBUG.16W
+++ b/DEBUG.16W
@@ -1,12 +1,12 @@
-\e[0mSeg:0      Size:8575       Owner:0x0\r
-\e[41;31m++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m\e[42;32m0\r
-\e[0m\e[0mSeg:217f       Size:256        Owner:0x5438\r
+\e[0mSeg:0      Size:8558       Owner:0x1\r
+\e[41;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m\e[42;32m0\r
+\e[0m\e[0mSeg:216e       Size:256        Owner:0x5448\r
+\e[44;34m+++++\e[0m\e[42;32m\r
+\e[0m\e[0mSeg:226e       Size:273        Owner:0x94a0\r
 \e[44;34m++++\e[0m\e[42;32m\r
-\e[0m\e[0mSeg:227f       Size:273        Owner:0x9490\r
-\e[44;34m++++\e[0m\e[42;32m\r
-\e[0m\e[0mSeg:27f2       Size:44 Owner:0x0\r
+\e[0m\e[0mSeg:27e0       Size:44 Owner:0x0\r
 \e[41;31m++\e[0m\e[42;32m0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r
-\e[0m\e[0mSeg:b81e       Size:10210      Owner:0x0\r
-\e[41;31m++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m\e[42;32m\r
+\e[0m\e[0mSeg:b80c       Size:10228      Owner:0x0\r
+\e[41;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m\e[42;32m\r
 \e[0m\e[0mSeg:e000       Size:8191       Owner:0x0\r
 \e[41;31m++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m
\ No newline at end of file
index ac2b7f9d07130dfe864bf625fc4e83c1e03a3bcf..2b94206e8c61d86672aff49a51be5d9b6f84cdc8 100755 (executable)
--- a/HEAP.16W
+++ b/HEAP.16W
@@ -1,47 +1,47 @@
 \r
        == default ==\r
 \r
-  USED block at 28140016 of size 66\r
-  USED block at 28140058 of size 66\r
-  FREE block at 2814009a of size 18\r
-  USED block at 281400ac of size 136\r
-  USED block at 28140134 of size 20\r
-  FREE block at 28140148 of size 7860\r
+  USED block at 28020016 of size 66\r
+  USED block at 28020058 of size 66\r
+  FREE block at 2802009a of size 18\r
+  USED block at 280200ac of size 136\r
+  USED block at 28020134 of size 20\r
+  FREE block at 28020148 of size 7860\r
 OK - end of heap\r
 \r
        == near ==\r
 \r
-  USED block at 181394c6 of size 12\r
-  USED block at 181394d2 of size 332\r
-  USED block at 1813961e of size 52\r
-  USED block at 18139652 of size 20\r
-  USED block at 18139666 of size 20\r
-  USED block at 1813967a of size 20\r
-  USED block at 1813968e of size 20\r
-  USED block at 181396a2 of size 20\r
-  USED block at 181396b6 of size 26950\r
+  USED block at 180194d6 of size 12\r
+  USED block at 180194e2 of size 332\r
+  USED block at 1801962e of size 52\r
+  USED block at 18019662 of size 20\r
+  USED block at 18019676 of size 20\r
+  USED block at 1801968a of size 20\r
+  USED block at 1801969e of size 20\r
+  USED block at 180196b2 of size 20\r
+  USED block at 180196c6 of size 26934\r
 OK - end of heap\r
 \r
        == far ==\r
 \r
-  USED block at 28140016 of size 66\r
-  USED block at 28140058 of size 66\r
-  USED block at 2814009a of size 18\r
-  USED block at 281400ac of size 136\r
-  USED block at 28140134 of size 20\r
-  USED block at 28140148 of size 7860\r
+  USED block at 28020016 of size 66\r
+  USED block at 28020058 of size 66\r
+  USED block at 2802009a of size 18\r
+  USED block at 280200ac of size 136\r
+  USED block at 28020134 of size 20\r
+  USED block at 28020148 of size 7860\r
 OK - end of heap\r
 \r
 Memory Type         Total      Used       Free\r
 ----------------  --------   --------   --------\r
 Default                   8166         288       7878\r
-Near              27446        496       26950\r
+Near              27430        496       26934\r
 Far               8166         288       7878\r
 ----------------  --------   --------   --------\r
-coreleft = 26948\r
-farcoreleft = 51056\r
+coreleft = 26932\r
+farcoreleft = 51040\r
 GetFreeSize = 24128\r
-GetNearFreeSize = 26950\r
+GetNearFreeSize = 26934\r
 GetFarFreeSize = 24128\r
-memavl = 26948\r
+memavl = 26932\r
 stackavail = 11268\r
index b9dba4098a7462b56b9604a128c8017cdd85933e..253c86cf555207e1bebcea2a92837095340d24d0 100755 (executable)
Binary files a/MMDUMP.16B and b/MMDUMP.16B differ
index 8420fa4cd09c2471e1733221766255fa2167ea53..2f5e7ecfa7fabedb4836a18f552f166b815237f7 100755 (executable)
Binary files a/MMDUMP.16W and b/MMDUMP.16W differ
index ebfd740ed727432e13bf8452aa20e4eceeb46292..bbfb5560579b7f9ade0b1b6a9e11dfb83c72a2c7 100755 (executable)
Binary files a/bcexmm.exe and b/bcexmm.exe differ
index 5778f27af5ee70778d5bcd6bce271860e0f6e144..2610441e4baa1739fd5034b7aa653470f1edff5b 100755 (executable)
Binary files a/bcexmm.prj and b/bcexmm.prj differ
index f958283223b07ceac26763fded533a298c70ad0c..da100d8ef1ade9ef7ab6537a1775643fe087c70a 100755 (executable)
@@ -86,7 +86,7 @@ main(int argc, char *argv[])
        //file name //\r
 \r
        gvar.mm.mmstarted=0;\r
-       pmdebug=0;\r
+       debugpm=0;\r
 \r
        //PRINTBB\r
        if(argv[1]){ bakapee1 = argv[1];\r
@@ -98,10 +98,10 @@ main(int argc, char *argv[])
        }\r
        //printf("main()=%Fp    start MM\n", *argv[0]);\r
        MM_Startup(&gvar);\r
-       if(pmdebug>0)\r
+       if(debugpm>0)\r
        {\r
                PM_Startup(&gvar);\r
-               PM_CheckMainMem(&gvar);\r
+               //PM_CheckMainMem(&gvar);\r
                PM_UnlockMainMem(&gvar);\r
        }\r
        CA_Startup(&gvar);\r
@@ -151,7 +151,7 @@ for(w=0;w<2;w++)
        printf("bakapee1=%s\n", bakapee1);\r
        printf("bakapee2=%s\n", bakapee2);\r
        MM_FreePtr(&bigbuffer, &gvar);\r
-       if(pmdebug>0)\r
+       if(debugpm>0)\r
                PM_Shutdown(&gvar);\r
        CA_Shutdown(&gvar);\r
        MM_Shutdown(&gvar);\r
index ec7db9f84c18b82da424b35d36004e125940e3b6..2d080d520a501aa07803c37c4baf746cc10729f6 100755 (executable)
@@ -152,7 +152,8 @@ static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */
 extern int                     profilehandle,debughandle;      //make it into game global\r
 \r
 #define __DEBUG__\r
-//0000#define __DEBUG_PM__\r
+#define __DEBUG_PM__\r
+//#define __DEBUG_MM__\r
 \r
 #define        nil     ((void *)0)\r
 #ifdef __BORLANDC__\r
index db338fa12df5e9d4c93f386e48d0384403ae5b24..859a5b4aed31ee74fde4a5dcfeb534e7778857ba 100755 (executable)
@@ -157,8 +157,8 @@ byte MML_SetupEMS(global_game_variables_t *gvar)
 
        unsigned int EMSVer = 0;
        //byte  EMS_status;
-       unsigned        totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
-       totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
+       unsigned        totalEMSpages,freeEMSpages,EMSPageFrame,EMSpagesmapped,EMSHandle;
+       totalEMSpages = freeEMSpages = EMSPageFrame = EMSpagesmapped = 0;
 
        __asm {
                mov     ah,EMS_STATUS
@@ -179,7 +179,7 @@ byte MML_SetupEMS(global_game_variables_t *gvar)
                int     EMS_INT                                         // find the page frame address
                or      ah,ah
                jnz     error
-               mov     [EMSpageframe],bx
+               mov     [EMSPageFrame],bx
 
                mov     ah,EMS_GETPAGES
                int     EMS_INT                                         // find out how much EMS is there
@@ -218,7 +218,7 @@ byte MML_SetupEMS(global_game_variables_t *gvar)
                int     EMS_INT
                or      ah,ah
                jnz     error
-               mov     [EMShandle],dx
+               mov     [EMSHandle],dx
                jmp End
 #ifdef __BORLANDC__
        }
@@ -247,9 +247,9 @@ End:
        }
        gvar->mm.totalEMSpages=totalEMSpages;
        gvar->mm.freeEMSpages=freeEMSpages;
-       gvar->mm.EMSpageframe=EMSpageframe;
+       gvar->mm.EMSPageFrame=EMSPageFrame;
        gvar->mm.EMSpagesmapped=EMSpagesmapped;
-       gvar->mm.EMShandle=EMShandle;
+       gvar->mm.EMSHandle=EMSHandle;
        gvar->mm.EMSVer=EMSVer;
        return 0;
 }
@@ -266,13 +266,13 @@ End:
 void MML_ShutdownEMS(global_game_variables_t *gvar)
 {
        boolean errorflag=false;
-       unsigned EMShandle=gvar->mm.EMShandle;
+       unsigned EMSHandle=gvar->mm.EMSHandle;
 
-       if(!EMShandle)
+       if(!EMSHandle)
                return;
        __asm {
                mov     ah,EMS_FREEPAGES
-               mov     dx,[EMShandle]
+               mov     dx,[EMSHandle]
                int     EMS_INT
                or      ah,ah
                jz      ok
@@ -303,11 +303,11 @@ void MML_ShutdownEMS(global_game_variables_t *gvar)
 byte MM_MapEMS(global_game_variables_t *gvar)
 {
        byte    str[160];
-       unsigned        EMShandle;
+       unsigned        EMSHandle;
        byte err;
        boolean errorflag=false;
        int     i;
-       EMShandle=gvar->mm.EMShandle;
+       EMSHandle=gvar->mm.EMSHandle;
 
        for (i=0;i<4/*MAPPAGES*/;i++)
        {
@@ -315,7 +315,7 @@ byte MM_MapEMS(global_game_variables_t *gvar)
                        mov     ah,EMS_MAPPAGE
                        mov     bx,[i]                  // logical page
                        mov     al,bl                   // physical page
-                       mov     dx,[EMShandle]  // handle
+                       mov     dx,[EMSHandle]  // handle
                        int     EMS_INT
                        or      ah,ah
                        jnz     error
@@ -375,10 +375,10 @@ byte MM_MapXEMS(global_game_variables_t *gvar)
 //END SUB
        byte    str[160];
        byte err;
-       word    EMShandle;
+       word    EMSHandle;
        boolean errorflag=false;
        int     i;
-       EMShandle=gvar->mm.EMShandle;
+       EMSHandle=gvar->mm.EMSHandle;
 
        if(gvar->mm.EMSVer<0x40)
                return 5;
@@ -389,7 +389,7 @@ byte MM_MapXEMS(global_game_variables_t *gvar)
                        mov     ah,EMS_MAPXPAGE
                        mov     cx,[i]                  // logical page
                        mov     al,bl                   // physical page
-                       mov     dx,[EMShandle]  // handle
+                       mov     dx,[EMSHandle]  // handle
                        int     EMS_INT
                        or      ah,ah
                        jnz     error
@@ -836,7 +836,9 @@ void MM_Startup(global_game_variables_t *gvar)
 
        gvar->mmi.mainmem = gvar->mmi.nearheap + gvar->mmi.farheap;
 
-       if(!pmdebug) {
+#ifdef __DEBUG__
+       if(!debugpm) {
+#endif
 //
 // detect EMS and allocate up to 64K at page frame
 //
@@ -865,7 +867,7 @@ void MM_Startup(global_game_variables_t *gvar)
        {
                MML_SetupEMS(gvar);                                     // allocate space
                //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
-               MML_UseSpace(gvar->mm.EMSpageframe,(MAPPAGES)*0x4000lu, gvar);
+               MML_UseSpace(gvar->mm.EMSPageFrame,(MAPPAGES)*0x4000lu, gvar);
                //if(gvar->pm.emm.EMSVer<0x40)
                        MM_MapEMS(gvar);                                        // map in used pages
                //else
@@ -901,7 +903,9 @@ goto xmsskip;//0000
        {
                MML_SetupXMS(gvar);                                     // allocate as many UMBs as possible
        }
+#ifdef __DEBUG__
        }
+#endif
 //
 // allocate the misc buffer
 //
@@ -935,10 +939,14 @@ void MM_Shutdown(global_game_variables_t *gvar)
 #ifdef __BORLANDC__
        free(gvar->mm.nearheap);//      printf("                near freed\n");
 #endif
-       if(!pmdebug) {
+#ifdef __DEBUG__
+       if(!debugpm) {
+#endif
        if(MML_CheckForEMS()){ MML_ShutdownEMS(gvar); }//printf("               EMS freed\n"); }
        if(MML_CheckForXMS(gvar)){ MML_ShutdownXMS(gvar); }//printf("           XMS freed\n"); }
+#ifdef __DEBUG__
        }
+#endif
 }
 
 //==========================================================================
@@ -966,10 +974,12 @@ void MM_GetPtr (memptr *baseptr, dword size, global_game_variables_t *gvar)
        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", 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));
+#ifdef __DEBUG_MM__
+               printf("MM_GetPtr\n");
+               //%04x
+               printf("        baseptr=%Fp     ", baseptr); printf("useptr=%Fp\n", gvar->mm.mmnew->useptr);
+               printf("        *baseptr=%Fp    ", *baseptr); printf("*useptr=%Fp\n", *(gvar->mm.mmnew->useptr));
+               printf("        &baseptr=%Fp    ", &baseptr); printf("&useptr=%Fp\n", &(gvar->mm.mmnew->useptr));
 #endif
        //exit(-5); }
        gvar->mm.mmnew->attributes = BASEATTRIBUTES;
@@ -1109,6 +1119,7 @@ void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar)
 =====================
 */
 
+
 void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar)
 {
        //huge mmblocktype huge *start;
@@ -1610,7 +1621,7 @@ void MM_Report_(global_game_variables_t *gvar)
                printf("        LIMEMS\n");
                printf("                EMM v%x.%x available\n", gvar->mm.EMSVer>>4,gvar->mm.EMSVer&0x0F);
                printf("                totalEMSpages:  %u      ", gvar->mm.totalEMSpages); printf("freeEMSpages:       %u\n", gvar->mm.freeEMSpages);
-               printf("                EMSpageframe:   %x\n", gvar->mm.EMSpageframe);
+               printf("                EMSPageFrame:   %x\n", gvar->mm.EMSPageFrame);
        }
        if(MML_CheckForXMS(gvar))
        {
index b04c56ab58c77f1e9c43cac1b79c1f49ead1c21e..d858c0f1b69908beddec362184e5db27ba97f3ac 100755 (executable)
 #include "src/lib/16_hc.h"\r
 #include "src/lib/16_lib.h"\r
 //++++mh       #include "src/lib/16_in.h"\r
-extern boolean pmdebug;\r
-\r
 \r
 #ifdef __DEBUG__               // 1 == Debug/Dev  ;  0 == Production/final\r
 #define OUT_OF_MEM_MSG "MM_GetPtr: Out of memory!\nYou were short :%lu bytes\n"\r
+extern boolean debugpm;\r
 #else\r
 #define OUT_OF_MEM_MSG "\npee\n"\r
 #endif\r
@@ -106,7 +105,7 @@ extern boolean pmdebug;
 \r
 extern void            (* beforesort) (void);\r
 extern void            (* aftersort) (void);\r
-extern void            (* XMSaddr) (void);             // far pointer to XMS driver\r
+extern void            (* XMSaddr) (void);             // far pointer to XMS driver\r
 \r
 //==========================================================================\r
 \r
index b472e58b2c3f124c8d3935bb4b49320c52e5947f..030a47b62d3f6093b17ffe167b286a910d55528d 100755 (executable)
 #include "src/lib/16_pm.h"\r
 #pragma hdrstop\r
 \r
-boolean pmdebug=0;\r
+#ifdef __DEBUG__\r
+boolean debugpm=0;\r
+#endif\r
 \r
-/*\r
 //     Main Mem specific variables\r
-       boolean                 MainPresent;\r
+/*     boolean                 MainPresent;\r
        memptr                  MainMemPages[PMMaxMainMem];\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
+       boolean                 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
        gvar->pm.emm.EMSListStruct      gvar->pm.emm.EMSList[EMSFrameCount];\r
 \r
 //     XMS specific variables\r
-       boolean                 gvar->pm.xmm.XMSPresent;\r
+       boolean                 XMSPresent;\r
        word                    gvar->pm.xmm.XMSAvail,gvar->pm.xmm.XMSPagesAvail,gvar->pm.xmm.XMSHandle;*/\r
        word            XMSDriver;\r
 /*     int                             gvar->pm.xmm.XMSProtectPage = -1;\r
@@ -68,6 +69,7 @@ boolean pmdebug=0;
        PageListStruct  far *gvar->pm.PMPages,\r
                                        _seg *gvar->pm.PMSegPages;\r
 */\r
+boolean                PMStarted, MainPresent, EMSPresent, XMSPresent;\r
 static char            *ParmStrings[] = {"nomain","noems","noxms",nil};\r
 \r
 /////////////////////////////////////////////////////////////////////////////\r
@@ -134,126 +136,157 @@ PML_MapEMS(word logical, byte physical, global_game_variables_t *gvar)
 //                     to the maximum we need)\r
 //\r
 \r
-       char    EMMDriverName[9] = "EMMXXXX0";\r
-\r
 boolean\r
 PML_StartupEMS(global_game_variables_t *gvar)\r
 {\r
        int             i;\r
        long    size;\r
-       boolean errorflag;\r
+       byte    str[160];\r
+       byte err;\r
 \r
-       gvar->pm.emm.EMSPresent = false;                        // Assume that we'll fail\r
+       boolean errorflag=0;\r
+       static char     emmname[] = "EMMXXXX0"; //fix by andrius4669\r
+       unsigned int EMSVer = 0;\r
+       unsigned        totalEMSpages,freeEMSpages,EMSPageFrame,EMSHandle,EMSAvail;\r
+       totalEMSpages = freeEMSpages = EMSPageFrame = 0;\r
+       EMSPresent = false;                     // Assume that we'll fail\r
        gvar->pm.emm.EMSAvail = 0;\r
-       errorflag=0;\r
 \r
-       _DX = (word)EMMDriverName;\r
-       _AX = 0x3d00;\r
-       geninterrupt(0x21);                     // try to open EMMXXXX0 device\r
        __asm {\r
-               jnc     gothandle\r
-               mov     errorflag,1\r
+               mov     dx,OFFSET emmname       //fix by andrius4669\r
+               mov     ax,0x3d00\r
+               int     EMS_INT         // try to open EMMXXXX0 device\r
+               jc      error1\r
+\r
+               mov     bx,ax\r
+               mov     ax,0x4400\r
+\r
+               int     EMS_INT         // get device info\r
+               jc      error1\r
+\r
+               and     dx,0x80\r
+               jz      error1\r
+\r
+               mov     ax,0x4407\r
+\r
+               int     EMS_INT         // get status\r
+               jc      error1\r
+               or      al,al\r
+               jz      error1\r
+\r
+               mov     ah,0x3e\r
+               int     EMS_INT         // close handle\r
+               jc      error1\r
+\r
+               mov     ah,EMS_STATUS\r
+               int     EMS_INT\r
+               jc      error1                  // make sure EMS hardware is present\r
+\r
+               mov     ah,EMS_VERSION\r
+               int     EMS_INT                 // only work on EMS 3.2 or greater (silly, but...)\r
+               or      ah,ah\r
+               jnz     error1\r
+               mov     [EMSVer],ax             //      set EMSVer\r
+               cmp     al,0x32                 // only work on ems 3.2 or greater\r
+               jb      error1\r
+\r
+               mov     ah,EMS_GETFRAME\r
+               int     EMS_INT                 // find the page frame address\r
+               or      ah,ah\r
+               jnz     error1\r
+               mov     [EMSPageFrame],bx\r
+\r
+               mov     ah,EMS_GETPAGES\r
+               int     EMS_INT                 // find out how much EMS is there\r
+               or      ah,ah\r
+               jnz     error1\r
+               or      bx,bx\r
+               jz      noEMS                   // no EMS at all to allocate\r
+               cmp     bx,2\r
+               jl      noEMS                   // Require at least 2 pages (32k)\r
+               mov     [totalEMSpages],dx\r
+               mov     [freeEMSpages],bx\r
+               mov     [EMSAvail],bx\r
+               jmp End1\r
 #ifdef __BORLANDC__\r
        }\r
 #endif\r
-               gothandle:\r
-#ifdef __WATCOMC__\r
-       }\r
-#endif\r
-       if(errorflag)\r
-               goto error;\r
-\r
-//gothandle:\r
-       _BX = _AX;\r
-       _AX = 0x4400;\r
-       geninterrupt(0x21);                     // get device info\r
+       error1:\r
+#ifdef __BORLANDC__\r
        __asm {\r
-               jnc     gotinfo\r
+#endif\r
+               mov     err,ah\r
                mov     errorflag,1\r
+               jmp End1\r
 #ifdef __BORLANDC__\r
        }\r
 #endif\r
-               gotinfo:\r
+noEMS:\r
+End1:\r
 #ifdef __WATCOMC__\r
        }\r
 #endif\r
-       if(errorflag)\r
-               goto error;\r
-\r
-//gotinfo:\r
-__asm  and     dx,0x80\r
-       if (!_DX)\r
-               goto error;\r
+       if(errorflag==false)\r
+       {\r
+               // Don't hog all available EMS\r
+               size = gvar->pm.emm.EMSAvail * (long)EMSPageSize;\r
+               if (size - (EMSPageSize * 2) > (gvar->pm.fi.ChunksInFile * (long)PMPageSize))\r
+               {\r
+                       size = (gvar->pm.fi.ChunksInFile * (long)PMPageSize) + EMSPageSize;\r
+                       gvar->pm.emm.EMSAvail = size / EMSPageSize;\r
+               }\r
+       }\r
 \r
-       _AX = 0x4407;\r
-       geninterrupt(0x21);                     // get status\r
        __asm {\r
-               jc      error\r
-               jmp     end\r
-               error:\r
+               mov     ah,EMS_ALLOCPAGES\r
+               mov     bx,[EMSAvail];\r
+               int     EMS_INT\r
+               or      ah,ah\r
+               jnz     error2\r
+               mov     [EMSHandle],dx\r
+               jmp     End2\r
+#ifdef __BORLANDC__\r
+       }\r
+#endif\r
+       error2:\r
+#ifdef __BORLANDC__\r
+       __asm {\r
+#endif\r
+               mov     err,ah\r
                mov     errorflag,1\r
+               jmp End2\r
 #ifdef __BORLANDC__\r
        }\r
 #endif\r
-               end:\r
+End2:\r
 #ifdef __WATCOMC__\r
        }\r
 #endif\r
-       if (!_AL)\r
-               goto error;\r
 \r
-       _AH = 0x3e;\r
-       geninterrupt(0x21);                     // close handle\r
-\r
-       _AH = EMS_STATUS;\r
-       geninterrupt(EMS_INT);\r
-       if (_AH)\r
-               goto error;                             // make sure EMS hardware is present\r
-\r
-       _AH = EMS_VERSION;\r
-       geninterrupt(EMS_INT);\r
-       if (_AH || (_AL < 0x32))        // only work on EMS 3.2 or greater (silly, but...)\r
-               goto error;\r
-\r
-       _AH = EMS_GETFRAME;\r
-       geninterrupt(EMS_INT);\r
-       if (_AH)\r
-               goto error;                             // find the page frame address\r
-       gvar->pm.emm.EMSPageFrame = _BX;\r
-\r
-       _AH = EMS_GETPAGES;\r
-       geninterrupt(EMS_INT);\r
-       if (_AH)\r
-               goto error;\r
-       if (_BX < 2)\r
-               goto error;             // Require at least 2 pages (32k)\r
-       gvar->pm.emm.EMSAvail = _BX;\r
-\r
-       // Don't hog all available EMS\r
-       size = gvar->pm.emm.EMSAvail * (long)EMSPageSize;\r
-       if (size - (EMSPageSize * 2) > (gvar->pm.fi.ChunksInFile * (long)PMPageSize))\r
+       if(errorflag==false)\r
        {\r
-               size = (gvar->pm.fi.ChunksInFile * (long)PMPageSize) + EMSPageSize;\r
-               gvar->pm.emm.EMSAvail = size / EMSPageSize;\r
-       }\r
-\r
-       _AH = EMS_ALLOCPAGES;\r
-       _BX = gvar->pm.emm.EMSAvail;\r
-       geninterrupt(EMS_INT);\r
-       if (_AH)\r
-               goto error;\r
-       gvar->pm.emm.EMSHandle = _DX;\r
-\r
        gvar->mmi.EMSmem += gvar->pm.emm.EMSAvail * (long)EMSPageSize;\r
 \r
        // Initialize EMS mapping cache\r
        for (i = 0;i < EMSFrameCount;i++)\r
                gvar->pm.emm.EMSList[i].baseEMSPage = -1;\r
 \r
-       gvar->pm.emm.EMSPresent = true;                 // We have EMS\r
+       }\r
+       else\r
+       {\r
+               strcpy(str,"PML_StartupEMS: EMS error ");\r
+               MM_EMSerr(str, err);\r
+               printf("%s\n",str);\r
+               return(EMSPresent);\r
+       }\r
 \r
-error:\r
-       return(gvar->pm.emm.EMSPresent);\r
+       EMSPresent = true;                      // We have EMS\r
+       gvar->pm.emm.EMSPageFrame = EMSPageFrame;\r
+       gvar->pm.emm.EMSAvail = EMSAvail;\r
+       gvar->pm.emm.EMSVer = EMSVer;\r
+       gvar->pm.emm.EMSHandle = EMSHandle;\r
+\r
+       return(EMSPresent);\r
 }\r
 \r
 //\r
@@ -265,7 +298,7 @@ PML_ShutdownEMS(global_game_variables_t *gvar)
        word EMSHandle;\r
        EMSHandle=gvar->pm.emm.EMSHandle;\r
 \r
-       if (gvar->pm.emm.EMSPresent)\r
+       if (EMSPresent)\r
        {\r
                __asm {\r
                        mov     ah,EMS_FREEPAGES\r
@@ -295,7 +328,7 @@ PML_ShutdownEMS(global_game_variables_t *gvar)
 boolean\r
 PML_StartupXMS(global_game_variables_t *gvar)\r
 {\r
-       gvar->pm.xmm.XMSPresent = false;                                        // Assume failure\r
+       XMSPresent = false;                                     // Assume failure\r
        gvar->pm.xmm.XMSAvail = 0;\r
 \r
        _AX=0x4300;\r
@@ -332,9 +365,9 @@ PML_StartupXMS(global_game_variables_t *gvar)
 \r
        gvar->mmi.XMSmem += gvar->pm.xmm.XMSAvail * 1024;\r
 \r
-       gvar->pm.xmm.XMSPresent = true;\r
+       XMSPresent = true;\r
 error:\r
-       return(gvar->pm.xmm.XMSPresent);\r
+       return(XMSPresent);\r
 }\r
 \r
 //\r
@@ -414,7 +447,7 @@ PML_CopyFromXMS(byte far *target,int sourcepage,word length, global_game_variabl
 void\r
 PML_ShutdownXMS(global_game_variables_t *gvar)\r
 {\r
-       if (gvar->pm.xmm.XMSPresent)\r
+       if (XMSPresent)\r
        {\r
                _DX = gvar->pm.xmm.XMSHandle;\r
                XMS_CALL(XMS_FREE);\r
@@ -442,15 +475,26 @@ PM_SetMainMemPurge(int level, global_game_variables_t *gvar)
 {\r
        int     i;\r
 \r
+       if(MainPresent)\r
        for (i = 0;i < PMMaxMainMem;i++)\r
        {\r
 #ifdef __DEBUG_PM__\r
                printf("PM_SetMainMemPurge()    info of gvar->pm.mm.MainMemPages[i]\n");\r
-               printf("        %Fp,    %Fp\n", gvar->pm.mm.MainMemPages[i],            (gvar->pm.mm.MainMemPages[i]));\r
+               //printf("      %Fp,    %Fp\n", gvar->pm.mm.MainMemPages[i],            (gvar->pm.mm.MainMemPages[i]));\r
                printf("&       %Fp,    %Fp\n", &gvar->pm.mm.MainMemPages[i],   &(gvar->pm.mm.MainMemPages[i]));\r
+               //MM_ShowMemory(gvar);\r
+               //MM_DumpData(gvar);\r
+               //MM_Report_(gvar);\r
 #endif\r
                if (gvar->pm.mm.MainMemPages[i])\r
-                       MM_SetPurge((gvar->pm.mm.MainMemPages[i]),level, gvar);\r
+                       MM_SetPurge(&(gvar->pm.mm.MainMemPages[i]),level, gvar);\r
+       }\r
+\r
+       else\r
+       {\r
+               printf("MainPresent IS NULL\n");\r
+               printf("%x      ", MainPresent);\r
+               exit(-4);\r
        }\r
 }\r
 \r
@@ -476,7 +520,7 @@ PM_CheckMainMem(global_game_variables_t *gvar)
        PMBlockAttr             *used;\r
        PageListStruct  far *page;\r
 \r
-       if (!gvar->pm.mm.MainPresent)\r
+       if (!MainPresent)\r
                return;\r
 \r
        for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
@@ -543,7 +587,11 @@ PML_StartupMainMem(global_game_variables_t *gvar)
        memptr  *p;\r
 \r
        gvar->pm.mm.MainPagesAvail = 0;\r
+       MainPresent = false;\r
        MM_BombOnError(false, gvar);\r
+       printf("PML_StartupMainMem()\n");\r
+       printf("        p=%04x  MainMemPages=%04x\n", p, gvar->pm.mm.MainMemPages);\r
+       printf("        p=%Fp   MainMemPages=%Fp\n", p, gvar->pm.mm.MainMemPages);\r
        for (i = 0,p = gvar->pm.mm.MainMemPages;i < PMMaxMainMem;i++,p++)\r
        {\r
                MM_GetPtr(p,PMPageSize, gvar);\r
@@ -561,7 +609,7 @@ PML_StartupMainMem(global_game_variables_t *gvar)
                Quit("PM_SetupMainMem: Not enough main memory");\r
                //return;\r
        }\r
-       gvar->pm.mm.MainPresent = true;\r
+       MainPresent = true;\r
 }\r
 \r
 //\r
@@ -853,7 +901,7 @@ PML_PutPageInXMS(int pagenum, global_game_variables_t *gvar)
        int                             usexms;\r
        PageListStruct  far *page;\r
 \r
-       if (!gvar->pm.xmm.XMSPresent)\r
+       if (!XMSPresent)\r
                return;\r
 \r
        page = &gvar->pm.PMPages[pagenum];\r
@@ -982,7 +1030,7 @@ PML_GetPageFromXMS(int pagenum,boolean mainonly, global_game_variables_t *gvar)
        PageListStruct  far *page;\r
 \r
        page = &gvar->pm.PMPages[pagenum];\r
-       if (gvar->pm.xmm.XMSPresent && (page->xmsPage != -1))\r
+       if (XMSPresent && (page->xmsPage != -1))\r
        {\r
                gvar->pm.xmm.XMSProtectPage = pagenum;\r
                checkaddr = PML_GetAPageBuffer(pagenum,mainonly, gvar);\r
@@ -1296,8 +1344,11 @@ PM_Startup(global_game_variables_t *gvar)
        boolean nomain,noems,noxms;\r
        int             i;\r
 \r
-       if (gvar->pm.PMStarted)\r
+       if (PMStarted)\r
+       {\r
+               printf("pee\n");\r
                return;\r
+       }\r
 \r
        strcat(&(gvar->pm.fi.PageFileName), "VSWAP.");\r
 \r
@@ -1339,17 +1390,17 @@ PM_Startup(global_game_variables_t *gvar)
        if (!noxms)\r
                PML_StartupXMS(gvar);\r
 \r
-       if (nomain && !gvar->pm.emm.EMSPresent)\r
+       if (nomain && !EMSPresent)\r
        {\r
                Quit("PM_Startup: No main or EMS\n");\r
                //return;\r
        }\r
-       else\r
-               PML_StartupMainMem(gvar);\r
+       printf("PML_StartupMainMem\n");\r
+       PML_StartupMainMem(gvar);\r
 \r
        PM_Reset(gvar);\r
 \r
-       gvar->pm.PMStarted = true;\r
+       PMStarted = true;\r
 }\r
 \r
 //\r
@@ -1361,7 +1412,7 @@ PM_Shutdown(global_game_variables_t *gvar)
        PML_ShutdownXMS(gvar);\r
        PML_ShutdownEMS(gvar);\r
 \r
-       if (!gvar->pm.PMStarted)\r
+       if (!PMStarted)\r
                return;\r
 \r
        PML_ClosePageFile(gvar);\r
index a8510f1762abc7581fc7c51d25c452ea3faf13c5..2a9c368f6b83a73786f1916967435b3bdf7a263a 100755 (executable)
@@ -33,7 +33,9 @@
 #include "src/lib/16_mm.h"\r
 #include <dos.h>\r
 \r
-extern boolean pmdebug;\r
+#ifdef __DEBUG__\r
+extern boolean debugpm;\r
+#endif\r
 \r
 /*//   NOTE! PMPageSize must be an even divisor of EMSPageSize, and >= 1024\r
 #define        EMSPageSize             16384\r
@@ -113,4 +115,5 @@ extern      memptr  PM_GetPageAddress(int pagenum, global_game_variables_t *gvar),
                                PM_GetPage(int pagenum, global_game_variables_t *gvar);         // Use this one to cache page\r
 \r
 void PM_SetMainMemPurge(int level, global_game_variables_t *gvar);\r
+void PML_StartupMainMem(global_game_variables_t *gvar);\r
 #endif\r
index d069b92fad770b2aac84c7352da3beacc62a3474..b34d133d86cf884c991be036cb1a8ea6204e4327 100755 (executable)
@@ -155,6 +155,7 @@ typedef struct mmblockstruct
 typedef struct\r
 {\r
        dword   nearheap,farheap,EMSmem,XMSmem,mainmem;\r
+//     boolean         PMStarted, MainPresent, EMSPresent, XMSPresent;\r
 } mminfotype;\r
 \r
 typedef struct\r
@@ -169,9 +170,9 @@ typedef struct
 #ifdef __WATCOMC__\r
        void __near     *nearheap;\r
 #endif\r
-       //byte          EMS_status;\r
+       unsigned int            EMSVer;\r
        word numUMBs,UMBbase[MAXUMBS];\r
-       word                    totalEMSpages, freeEMSpages, EMSpagesmapped, EMShandle, EMSpageframe,EMSVer;\r
+       word                    totalEMSpages, freeEMSpages, EMSpagesmapped, EMSHandle, EMSPageFrame;\r
        //dword numUMBs,UMBbase[MAXUMBS];\r
        //huge mmblocktype      huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;\r
        mmblocktype     far mmblocks[MAXBLOCKS],far *mmhead,far *mmfree,far *mmrover,far *mmnew;\r
@@ -235,7 +236,7 @@ typedef     struct
 //     Main Mem specific variables\r
 typedef struct\r
 {\r
-       boolean                 MainPresent;\r
+//     boolean                 MainPresent;\r
        memptr                  MainMemPages[PMMaxMainMem];\r
        PMBlockAttr             MainMemUsed[PMMaxMainMem];\r
        int                             MainPagesAvail;\r
@@ -244,9 +245,10 @@ typedef struct
 //     EMS specific variables\r
 typedef struct\r
 {\r
-       boolean                 EMSPresent;\r
+//     boolean                 EMSPresent;\r
+       unsigned int                    EMSVer;\r
        word                    EMSAvail,EMSPagesAvail,EMSHandle,\r
-                                       EMSPageFrame,EMSPhysicalPage, EMSVer;\r
+                                       EMSPageFrame,EMSPhysicalPage;\r
        word                    totalEMSpages, freeEMSpages, EMSpagesmapped;\r
        EMSListStruct   EMSList[EMSFrameCount];\r
 } pm_emmi_t;\r
@@ -254,7 +256,7 @@ typedef struct
 //     XMS specific variables\r
 typedef struct\r
 {\r
-       boolean                 XMSPresent;\r
+//     boolean                 XMSPresent;\r
        word                    XMSAvail,XMSPagesAvail,XMSHandle;\r
        dword                   XMSDriver;      //TODO: changed to word\r
        int                             XMSProtectPage;// = -1;\r