]> 4ch.mooo.com Git - 16.git/commitdiff
16_ca needs huge amounts of work and I should remember what needs to be done soon...
authorsparky4 <sparky4@cock.li>
Mon, 24 Apr 2017 13:55:05 +0000 (08:55 -0500)
committersparky4 <sparky4@cock.li>
Mon, 24 Apr 2017 13:55:05 +0000 (08:55 -0500)
src/lib/16_mm.c
src/lib/16_mm.h
src/lib/16_pm.c
src/lib/16_tdef.h
src/sountest.c
src/xcroll.c

index 7fe1110df998e96ff457d5f9151c402236623881..4aa8b746d54932754e491008d28462c2bb6d96b7 100755 (executable)
@@ -58,6 +58,37 @@ Open Watcom port by sparky4
 #pragma warn -pro\r
 #pragma warn -use\r
 \r
+/*\r
+=============================================================================\r
+\r
+                                                       LOCAL INFO\r
+\r
+=============================================================================\r
+*/\r
+\r
+#define LOCKBIT                0x80    // if set in attributes, block cannot be moved\r
+#define PURGEBITS      3               // 0-3 level, 0= unpurgable, 3= purge first\r
+#define PURGEMASK      0xfffc\r
+#define BASEATTRIBUTES 0       // unlocked, non purgable\r
+\r
+//#define MAXUMBS              10\r
+\r
+/*typedef struct mmblockstruct\r
+{\r
+       unsigned        start,length;\r
+       unsigned        attributes;\r
+       memptr          *useptr;        // pointer to the segment start\r
+       struct mmblockstruct far *next;\r
+} mmblocktype;*/\r
+\r
+\r
+//#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}\r
+//\r
+\r
+#define GETNEWBLOCK {if(!gvar->mm.mmfree)MML_ClearBlock(gvar);gvar->mm.mmnew=gvar->mm.mmfree;gvar->mm.mmfree=gvar->mm.mmfree->next;}\r
+\r
+#define FREEBLOCK(x) {*x->useptr=NULL;x->next=gvar->mm.mmfree;gvar->mm.mmfree=x;}\r
+\r
 /*\r
 =============================================================================\r
 \r
@@ -66,9 +97,12 @@ Open Watcom port by sparky4
 =============================================================================\r
 */\r
 \r
+/*mminfotype   mminfo;\r
+memptr         bufferseg;\r
+boolean                mmerror;*/\r
+\r
 void           (* beforesort) (void);\r
 void           (* aftersort) (void);\r
-void           (* XMSaddr) (void);             // far pointer to XMS driver\r
 \r
 /*\r
 =============================================================================\r
@@ -77,6 +111,38 @@ void                (* XMSaddr) (void);             // far pointer to XMS driver
 \r
 =============================================================================\r
 */\r
+\r
+/*boolean              mmstarted;\r
+\r
+void far       *farheap;\r
+void           *nearheap;\r
+\r
+mmblocktype    far mmblocks[MAXBLOCKS]\r
+                       ,far *mmhead,far *mmfree,far *mmrover,far *mmnew;\r
+\r
+boolean                bombonerror;*/\r
+\r
+//unsigned     totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;\r
+\r
+void           (* XMSaddr) (void);             // far pointer to XMS driver\r
+\r
+/*unsigned     numUMBs,UMBbase[MAXUMBS];*/\r
+\r
+//==========================================================================\r
+\r
+//\r
+// local prototypes\r
+//\r
+\r
+boolean                MML_CheckForEMS (void);\r
+void           MML_ShutdownEMS (void);\r
+void           MM_MapEMS (void);\r
+boolean        MML_CheckForXMS (void);\r
+void           MML_ShutdownXMS (void);\r
+//void         MML_UseSpace (unsigned segstart, unsigned seglength);\r
+//void                 MML_ClearBlock (void);\r
+\r
+//==========================================================================\r
 #ifndef __16_PM__\r
 #if 0\r
 static char *ParmStringsexmm[] = {"noems","noxms",""};\r
@@ -628,10 +694,10 @@ void MML_ShutdownXMS(global_game_variables_t *gvar)
        }\r
 //++++todo: linked list of segment!\r
 */\r
-void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar)\r
+void MML_UseSpace (unsigned segstart, unsigned seglength, global_game_variables_t *gvar)\r
 {\r
        mmblocktype far *scan,far *last;\r
-       word    oldend;\r
+       unsigned        oldend;\r
        sdword          extra;\r
        //word segm=1;\r
 \r
@@ -660,8 +726,9 @@ void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar)
 // take the given range out of the block\r
 //\r
        oldend = scan->start + scan->length;\r
-       extra = oldend - (segstart+((unsigned)seglength));\r
+       extra = oldend - (segstart+seglength);\r
        if (extra < 0)\r
+#ifdef __DEBUG_MM__\r
        {\r
                printf("========================================\n");\r
                printf("start=%x        ", scan->start);\r
@@ -675,6 +742,9 @@ void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar)
                printf("========================================\n");\r
                //return;\r
        }\r
+#else\r
+               Quit (gvar, "MML_UseSpace: Segment spans two blocks!");\r
+#endif\r
 \r
        if (segstart == scan->start)\r
        {\r
@@ -711,7 +781,7 @@ void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar)
 ====================\r
 */\r
 \r
-void MML_ClearBlock(global_game_variables_t *gvar)\r
+void MML_ClearBlock (global_game_variables_t *gvar)\r
 {\r
        mmblocktype far *scan;//,far *last;\r
 \r
@@ -727,7 +797,7 @@ void MML_ClearBlock(global_game_variables_t *gvar)
                scan = scan->next;\r
        }\r
 \r
-       printf("MM_ClearBlock: No purgable blocks!\n");\r
+       Quit (gvar, "MM_ClearBlock: No purgable blocks!\n");\r
 }\r
 \r
 \r
@@ -744,26 +814,24 @@ void MML_ClearBlock(global_game_variables_t *gvar)
 ===================\r
 */\r
 \r
-void MM_Startup(global_game_variables_t *gvar)\r
+void MM_Startup (global_game_variables_t *gvar)\r
 {\r
        int i;\r
-       //dword length,seglength;\r
-       dword length; word seglength;\r
+       dword length;\r
        void far        *start;\r
-       word    segstart;//,endfree;\r
+       unsigned        segstart,seglength;//,endfree;\r
 \r
        if(gvar->mm.mmstarted)\r
-               MM_Shutdown(gvar);\r
+               MM_Shutdown (gvar);\r
 \r
        gvar->mm.mmstarted = true;\r
        gvar->mm.bombonerror = true;\r
-\r
 //\r
 // set up the linked list (everything in the free list;\r
 //\r
        gvar->mm.mmhead = NULL;\r
        gvar->mm.mmfree = &(gvar->mm.mmblocks[0]);\r
-       for(i=0;i<MAXBLOCKS-1;i++)\r
+       for (i=0;i<MAXBLOCKS-1;i++)\r
                gvar->mm.mmblocks[i].next = &(gvar->mm.mmblocks[i+1]);\r
        gvar->mm.mmblocks[i].next = NULL;\r
 \r
@@ -778,6 +846,7 @@ void MM_Startup(global_game_variables_t *gvar)
        gvar->mm.mmnew->next = NULL;\r
        gvar->mm.mmrover = gvar->mm.mmhead;\r
 \r
+\r
 //\r
 // get all available near conventional memory segments\r
 //\r
@@ -797,7 +866,7 @@ void MM_Startup(global_game_variables_t *gvar)
        length -= SAVENEARHEAP;\r
        seglength = length / 16;                        // now in paragraphs\r
        segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;\r
-       MML_UseSpace(segstart,seglength, gvar);\r
+       MML_UseSpace (segstart,seglength, gvar);\r
        gvar->mmi.nearheap = length;\r
        //0000printf("near:     start=%Fp       segstart=%x     seglen=%lu      len=%lu\n", start, segstart, (dword)seglength, length);\r
 \r
@@ -818,7 +887,7 @@ void MM_Startup(global_game_variables_t *gvar)
        length -= SAVEFARHEAP;\r
        seglength = length / 16;                        // now in paragraphs\r
        segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;\r
-       MML_UseSpace(segstart,seglength, gvar);\r
+       MML_UseSpace (segstart,seglength, gvar);\r
        gvar->mmi.farheap = length;\r
        //0000printf("far:      start=%Fp       segstart=%x     seglen=%lu      len=%lu\n", start, segstart, (dword)seglength, length);\r
 \r
@@ -873,7 +942,7 @@ xmsskip:
 //\r
        gvar->mm.mmrover = gvar->mm.mmhead;             // start looking for space after low block\r
 \r
-       MM_GetPtr(&(gvar->mm.bufferseg),BUFFERSIZE, gvar);\r
+       MM_GetPtr (&(gvar->mm.bufferseg),BUFFERSIZE, gvar);\r
 }\r
 \r
 //==========================================================================\r
@@ -888,7 +957,7 @@ xmsskip:
 ====================\r
 */\r
 \r
-void MM_Shutdown(global_game_variables_t *gvar)\r
+void MM_Shutdown (global_game_variables_t *gvar)\r
 {\r
        if(!(gvar->mm.mmstarted))\r
                return;\r
@@ -926,10 +995,10 @@ void MM_Shutdown(global_game_variables_t *gvar)
 ====================\r
 */\r
 \r
-void MM_GetPtr (memptr *baseptr, dword size, global_game_variables_t *gvar)\r
+void MM_GetPtr (memptr *baseptr,dword size, global_game_variables_t *gvar)\r
 {\r
        mmblocktype far *scan,far *lastscan,far *endscan\r
-                                               ,far *purge,far *next;\r
+                               ,far *purge,far *next;\r
        int                     search;\r
        unsigned        needed,startseg;\r
 \r
@@ -938,18 +1007,19 @@ void MM_GetPtr (memptr *baseptr, dword size, global_game_variables_t *gvar)
        GETNEWBLOCK;                            // fill in start and next after a spot is found\r
        gvar->mm.mmnew->length = needed;\r
        gvar->mm.mmnew->useptr = baseptr;\r
+       gvar->mm.mmnew->attributes = BASEATTRIBUTES;\r
        //if(gvar->mm.mmnew->useptr==NULL){\r
 #ifdef __DEBUG_MM__\r
+       printf("MM_GetPtr\n");\r
        if(dbg_debugmm>0){\r
-               printf("MM_GetPtr\n");\r
                //%04x\r
                printf("        baseptr=%Fp     ", baseptr); printf("useptr=%Fp\n", gvar->mm.mmnew->useptr);\r
                printf("        *baseptr=%Fp    ", *baseptr); printf("*useptr=%Fp\n", *(gvar->mm.mmnew->useptr));\r
                printf("        &baseptr=%Fp    ", &baseptr); printf("&useptr=%Fp\n", &(gvar->mm.mmnew->useptr));\r
        }\r
+       printf("        size is %lu\n", size);\r
 #endif\r
-       //Quit(gvar, "gvar->mm.mmnew->useptr==NULL"); }\r
-       gvar->mm.mmnew->attributes = BASEATTRIBUTES;\r
+       //Quit (gvar, "gvar->mm.mmnew->useptr==NULL"); }\r
 \r
 //tryagain:\r
        for (search = 0; search<3; search++)\r
@@ -1027,7 +1097,7 @@ void MM_GetPtr (memptr *baseptr, dword size, global_game_variables_t *gvar)
                //heapdump();\r
 #endif\r
                printf(OUT_OF_MEM_MSG,(size-gvar->mmi.nearheap));\r
-               Quit(gvar, "for stability reasons the program will shut down! wwww\n");\r
+               Quit (gvar, "for stability reasons the program will shut down! wwww\n");\r
        }\r
        else\r
                gvar->mm.mmerror = true;\r
@@ -1055,13 +1125,13 @@ void MM_FreePtr (memptr *baseptr, global_game_variables_t *gvar)
        if (baseptr == gvar->mm.mmrover->useptr)        // removed the last allocated block\r
                gvar->mm.mmrover = gvar->mm.mmhead;\r
 \r
-       while(scan->useptr != baseptr && scan)\r
+       while (scan->useptr != baseptr && scan)\r
        {\r
                last = scan;\r
                scan = scan->next;\r
        }\r
 \r
-       if(!scan)\r
+       if (!scan)\r
                Quit (gvar, "MM_FreePtr: Block not found!");\r
 \r
        last->next = scan->next;\r
@@ -1098,7 +1168,7 @@ void MM_SetPurge (memptr *baseptr, int purge, global_game_variables_t *gvar)
                else if (gvar->mm.mmrover == start)\r
                        Quit (gvar, "MM_SetPurge: Block not found!");\r
 \r
-       } while(1);\r
+       } while (1);\r
 \r
        gvar->mm.mmrover->attributes &= ~PURGEBITS;\r
        gvar->mm.mmrover->attributes |= purge;\r
@@ -1173,7 +1243,7 @@ void MM_SortMem (global_game_variables_t *gvar)
                        playing += STARTADLIBSOUNDS;\r
                        break;\r
                }\r
-               MM_SetLock((memptr *)&audiosegs[playing],true);\r
+               MM_SetLock(MEMPTRCONV audiosegs[playing],true);\r
        }\r
 \r
 \r
@@ -1181,16 +1251,16 @@ void MM_SortMem (global_game_variables_t *gvar)
        oldborder = gvar->video.bordercolor;\r
        gvar->video.bordercolor = modexPalOverscan(15);\r
 \r
-       if(beforesort)\r
+       if (beforesort)\r
                beforesort();\r
 \r
        scan = gvar->mm.mmhead;\r
 \r
        last = NULL;            // shut up compiler warning\r
 \r
-       while(scan)\r
+       while (scan)\r
        {\r
-               if(scan->attributes & LOCKBIT)\r
+               if (scan->attributes & LOCKBIT)\r
                {\r
                //\r
                // block is locked, so try to pile later blocks right after it\r
@@ -1199,7 +1269,7 @@ void MM_SortMem (global_game_variables_t *gvar)
                }\r
                else\r
                {\r
-                       if(scan->attributes & PURGEBITS)\r
+                       if (scan->attributes & PURGEBITS)\r
                        {\r
                        //\r
                        // throw out the purgable block\r
@@ -1215,12 +1285,12 @@ void MM_SortMem (global_game_variables_t *gvar)
                        //\r
                        // push the non purgable block on top of the last moved block\r
                        //\r
-                               if(scan->start != start)\r
+                               if (scan->start != start)\r
                                {\r
                                        length = scan->length;\r
                                        source = scan->start;\r
                                        dest = start;\r
-                                       while(length > 0xf00)\r
+                                       while (length > 0xf00)\r
                                        {\r
                                                movedata(source,0,dest,0,0xf00*16);\r
                                                length -= 0xf00;\r
@@ -1242,7 +1312,7 @@ void MM_SortMem (global_game_variables_t *gvar)
 \r
        gvar->mm.mmrover = gvar->mm.mmhead;\r
 \r
-       if(aftersort)\r
+       if (aftersort)\r
                aftersort();\r
 \r
        VL_ColorBorder (oldborder, &gvar->video);\r
index 86bcdd575ef1b923134890136422873d5e7a3e70..c003b54b8429603e3abe2e158e0088fd03f5b4ce 100755 (executable)
@@ -41,8 +41,8 @@
 \r
 #define FREEBLOCK(x) {*x->useptr=NULL;x->next=gvar->mm.mmfree;gvar->mm.mmfree=x;}\r
 \r
-#define SAVENEARHEAP   0x200           // space to leave in data segment\r
-#define SAVEFARHEAP    0x400                   // space to leave in far heap\r
+#define SAVENEARHEAP   0x400           // space to leave in data segment\r
+#define SAVEFARHEAP    0                       // space to leave in far heap\r
 \r
 #define        BUFFERSIZE              0x1000          // miscelanious, allways available buffer\r
 \r
 \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
 extern dword   XMSDriver;\r
 extern word            XMSVer;\r
 \r
@@ -179,35 +179,35 @@ typedef struct
 \r
 //==========================================================================\r
 \r
-boolean MML_CheckForEMS(void);\r
+boolean MML_CheckForEMS (void);\r
 //byte MML_SetupEMS(mminfo_t *mm);\r
 //void MML_ShutdownEMS(mminfo_t *mm);\r
 //byte MM_MapEMS(global_game_variables_t *gvar);\r
 //byte MM_MapXEMS(global_game_variables_t *gvar);\r
-boolean MML_CheckForXMS(void);\r
+boolean MML_CheckForXMS (void);\r
 //void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);\r
 //void MML_ShutdownXMS(mminfo_t *mm);\r
-void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar);\r
+void MML_UseSpace (unsigned segstart, unsigned seglength, global_game_variables_t *gvar);\r
 void MML_ClearBlock (global_game_variables_t *gvar);\r
 \r
-void MM_Startup(global_game_variables_t *gvar);\r
-void MM_Shutdown(global_game_variables_t *gvar);\r
-\r
-void MM_GetPtr(memptr *baseptr,dword size, global_game_variables_t *gvar);\r
-void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar);\r
-void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar);\r
-void MM_SetLock(memptr *baseptr, boolean locked, global_game_variables_t *gvar);\r
-void MM_SortMem(global_game_variables_t *gvar);\r
-void MM_ShowMemory(global_game_variables_t *gvar);\r
-void MM_DumpData(global_game_variables_t *gvar);\r
-dword MM_UnusedMemory(global_game_variables_t *gvar);\r
-dword MM_TotalFree(global_game_variables_t *gvar);\r
-void MM_Report_(global_game_variables_t *gvar);\r
-/*static */void MM_EMSerr(byte *stri, byte err);\r
-void MM_BombOnError(boolean bomb, global_game_variables_t *gvar);\r
+void MM_Startup (global_game_variables_t *gvar);\r
+void MM_Shutdown (global_game_variables_t *gvar);\r
+\r
+void MM_GetPtr (memptr *baseptr,dword size, global_game_variables_t *gvar);\r
+void MM_FreePtr (memptr *baseptr, global_game_variables_t *gvar);\r
+void MM_SetPurge (memptr *baseptr, int purge, global_game_variables_t *gvar);\r
+void MM_SetLock (memptr *baseptr, boolean locked, global_game_variables_t *gvar);\r
+void MM_SortMem (global_game_variables_t *gvar);\r
+void MM_ShowMemory (global_game_variables_t *gvar);\r
+void MM_DumpData (global_game_variables_t *gvar);\r
+dword MM_UnusedMemory (global_game_variables_t *gvar);\r
+dword MM_TotalFree (global_game_variables_t *gvar);\r
+void MM_Report_ (global_game_variables_t *gvar);\r
+/*static */void MM_EMSerr (byte *stri, byte err);\r
+void MM_BombOnError (boolean bomb, global_game_variables_t *gvar);\r
 //void MM_GetNewBlock(mminfo_t *mm);\r
 //void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);\r
-void xms_call(byte v, global_game_variables_t *gvar);\r
+void xms_call (byte v, global_game_variables_t *gvar);\r
 \r
 //==========================================================================\r
 \r
index 858bd4b9fe121208edf5393ae64f714c4596978a..ce81eb4a4798071259f92d91737361bf955b7321 100755 (executable)
@@ -1420,7 +1420,7 @@ PM_NextFrame(global_game_variables_t *gvar)
                {\r
                        char buf[40];\r
                        sprintf(buf,"PM_NextFrame: Page %d is locked",i);\r
-                       Quit(gvar, buf);\r
+                       Quit (gvar, buf);\r
                }\r
        }\r
 //#endif\r
index f45195d698b9a93d9336987d3ed69157b18a4a1e..3fa1feb335ced492a655faf2c2195e411e338469 100755 (executable)
@@ -468,14 +468,11 @@ typedef struct
 //from 16_mm\r
 //==========================================================================\r
 \r
-#define MAXBLOCKS              1024//kd=1300 wolf3d=700 cata=600\r
-//----#define MAXUMBS          12\r
+#define MAXBLOCKS              800//kd=1300 wolf3d=700 cata=600\r
 \r
 typedef struct mmblockstruct\r
 {\r
-       word    start,length;\r
-       //word  start;  dword length;\r
-//++++ word    blob;   //for data larger than 64k\r
+       unsigned        start,length;\r
        unsigned        attributes;\r
        memptr          *useptr;        // pointer to the segment start\r
        struct mmblockstruct far *next;\r
@@ -660,9 +657,10 @@ typedef struct
 \r
 #define NUMMAPS                4//39\r
 #define NUMSNDCHUNKS           4//3\r
-//#define NUMPICS              132//wolf3d wl6\r
+//#define NUMPICS              4//132//wolf3d wl6\r
 \r
 #define STRUCTPIC      0\r
+#define CASVT          dword   //*start var type\r
 \r
 \r
 #define DATADIR                "data/"\r
@@ -718,8 +716,8 @@ typedef struct      //TODO: USE THIS!!!!
        byte            far             grneeded[NUMCHUNKS];\r
        word            _seg *audiosegs[NUMSNDCHUNKS];//long\r
 \r
-       word            _seg    *grstarts;      // array of offsets in egagraph, -1 for sparse//long\r
-       word            _seg    *audiostarts;   // array of offsets in audio / audiot//long\r
+       CASVT           _seg    *grstarts;      // array of offsets in egagraph, -1 for sparse//long\r
+       CASVT           _seg    *audiostarts;   // array of offsets in audio / audiot//long\r
 \r
 #ifdef GRHEADERLINKED\r
        huffnode        *grhuffman;\r
@@ -733,7 +731,7 @@ typedef struct      //TODO: USE THIS!!!!
        huffnode        audiohuffman[255];\r
 #endif\r
 \r
-       long            chunkcomplen,chunkexplen;\r
+       CASVT           chunkcomplen,chunkexplen;//long\r
 \r
        sd_t            sd;\r
        //TODO: extend! and learn from keen/wolf/catacomb's code wwww\r
index d15a5462fbab440514c02917f1c15c269628e0d5..3ef0114f687af66617a2ec41b657bc69271c0b63 100755 (executable)
@@ -65,13 +65,14 @@ void main(int argc, char near *argv[])
 //0x36,                                /* feedback algorithm and strength 0xC0 */\r
 //};\r
 \r
-       IN_Startup(&gvar);\r
        //FMReset();\r
        //FMSetVoice(0, &testInst);\r
        if(!init_adlib())\r
        {\r
-               Quit(&gvar, "Cannot init library");\r
+               printf("Cannot init library\n");\r
+               exit(-1);\r
        }\r
+       IN_Startup(&gvar);\r
 \r
        if (adlib_fm_voices > 9)\r
                printf("OPL3!\n");\r
index ed02457e7c28ab78389fae4c56f4e2d421813d37..d06850cbb3d6e29006c29d3185a0c161946a759c 100755 (executable)
@@ -121,9 +121,7 @@ void main(int argc, char *argv[])
        modexFadeOn(4, &gvar.video.palette);\r
 #endif\r
 \r
-       IN_StartAck (&gvar);\r
-       MM_ShowMemory(&gvar);\r
-       while (!IN_CheckAck (&gvar)){}\r
+       IN_StartAck (&gvar);    MM_ShowMemory(&gvar);   while (!IN_CheckAck (&gvar)){}\r
 #ifdef FADE\r
        modexPalBlack();        //so player will not see loadings~\r
 #endif\r