#pragma warn -pro\r
#pragma warn -use\r
\r
-//#define THREEBYTEGRSTARTS\r
+#define THREEBYTEGRSTARTS\r
//https://github.com/open-watcom/open-watcom-v2/issues/279#issuecomment-244587566 for _seg\r
//http://www.shikadi.net/moddingwiki/GameMaps_Format for info on the code\r
/*\r
int grhandle; // handle to EGAGRAPH\r
int maphandle; // handle to MAPTEMP / GAMEMAPS\r
int audiohandle; // handle to AUDIOT / AUDIO\r
-\r
-long c hunkcomplen,c hunkexplen;\r
-\r
+*/\r
+long chunkcomplen,chunkexplen;\r
+/*\r
SDMode oldsoundmode;\r
\r
\r
#ifdef THREEBYTEGRSTARTS\r
#define FILEPOSSIZE 3\r
//#define GRFILEPOS(c) (*(long far *)(((byte far *)grstarts)+(c)*3)&0xffffff)\r
-long GRFILEPOS(int c, global_game_variables_t *gvar)\r
+CASVT GRFILEPOS(int c, global_game_variables_t *gvar)\r
{\r
- long value;\r
+ CASVT value;\r
int offset;\r
\r
offset = c*3;\r
\r
- value = *(long far *)(((byte far *)gvar->ca.grstarts)+offset);\r
+ value = *(CASVT far *)(((byte far *)gvar->ca.grstarts)+offset);\r
\r
value &= 0x00ffffffl;\r
\r
};\r
#else\r
#define FILEPOSSIZE 4\r
-#define GRFILEPOS(c) (gvar->ca.grstarts[c])\r
+//#define GRFILEPOS(c) (gvar->ca.grstarts[c])\r
+CASVT GRFILEPOS(int c, global_game_variables_t *gvar)\r
+{\r
+ return gvar->ca.grstarts[c];\r
+}\r
#endif\r
\r
/*\r
\r
void CAL_GetGrChunkLength (int chunk,global_game_variables_t *gvar)\r
{\r
- lseek(gvar->ca.file.grhandle,GRFILEPOS(chunk),SEEK_SET);\r
+ lseek(gvar->ca.file.grhandle,GRFILEPOS(chunk,gvar),SEEK_SET);\r
read(gvar->ca.file.grhandle,&gvar->ca.chunkexplen,sizeof(gvar->ca.chunkexplen));\r
- gvar->ca.chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4;\r
+ gvar->ca.chunkcomplen = GRFILEPOS(chunk+1,gvar)-GRFILEPOS(chunk,gvar)-4;\r
}\r
\r
\r
#if NUMPICS>0\r
MM_GetPtr(MEMPTRCONV gvar->video.pictable,NUMPICS*sizeof(pictabletype),gvar);\r
CAL_GetGrChunkLength(STRUCTPIC,gvar); // position file pointer\r
- MM_GetPtr(&compseg,gvar->ca.chunkcomplen, gvar);\r
+ printf("CAL_SetupGrFile:\n");\r
+ printf(" gvar->ca.chunkcomplen size is %lu\n", gvar->ca.chunkcomplen);\r
+ MM_GetPtr(&compseg,gvar->ca.chunkcomplen,gvar);\r
+ IN_Ack(gvar);\r
CA_FarRead (gvar->ca.file.grhandle,compseg,gvar->ca.chunkcomplen,gvar);\r
CAL_HuffExpand (compseg, (byte far *)gvar->video.pictable,NUMPICS*sizeof(pictabletype),gvar->ca.grhuffman);\r
MM_FreePtr(&compseg,gvar);\r
/*#ifdef MAPHEADERLINKED\r
if ((maphandle = open("GAMEMAPS.16"ENSION,\r
O_RDONLY | O_BINARY, S_IREAD)) == -1)\r
- Quit ("Can't open GAMEMAPS.16"ENSION"!");\r
+ Quit (gvar, "Can't open GAMEMAPS.16"ENSION"!");\r
#else\r
if ((maphandle = open("MAPTEMP.16"ENSION,\r
O_RDONLY | O_BINARY, S_IREAD)) == -1)\r
- Quit ("Can't open MAPTEMP.16"ENSION"!");\r
+ Quit (gvar, "Can't open MAPTEMP.16"ENSION"!");\r
#endif*/\r
}\r
\r
// load the chunk into a buffer, either the miscbuffer if it fits, or allocate\r
// a larger buffer\r
//\r
- pos = GRFILEPOS(chunk);\r
+ pos = GRFILEPOS(chunk,gvar);\r
if (pos<0) // $FFFFFFFF start is a sparse tile\r
return;\r
\r
next = chunk +1;\r
- while (GRFILEPOS(next) == -1) // skip past any sparse tiles\r
+ while (GRFILEPOS(next,gvar) == -1) // skip past any sparse tiles\r
next++;\r
\r
- compressed = GRFILEPOS(next)-pos;\r
+ compressed = GRFILEPOS(next,gvar)-pos;\r
\r
lseek(gvar->ca.file.grhandle,pos,SEEK_SET);\r
\r
// load the chunk into a buffer, either the miscbuffer if it fits, or allocate\r
// a larger buffer\r
//\r
- pos = GRFILEPOS(chunk);\r
+ pos = GRFILEPOS(chunk,gvar);\r
if (pos<0) // $FFFFFFFF start is a sparse tile\r
return;\r
\r
while (GRFILEPOS(next) == -1) // skip past any sparse tiles\r
next++;\r
\r
- compressed = GRFILEPOS(next)-pos;\r
+ compressed = GRFILEPOS(next,gvar)-pos;\r
\r
lseek(gvar->ca.file.grhandle,pos,SEEK_SET);\r
\r
if (dialog && updatecachebox)\r
updatecachebox ();\r
\r
- pos = GRFILEPOS(i);\r
+ pos = GRFILEPOS(i,gvar);\r
if (pos<0)\r
continue;\r
\r
while (GRFILEPOS(next) == -1) // skip past any sparse tiles\r
next++;\r
\r
- compressed = GRFILEPOS(next)-pos;\r
+ compressed = GRFILEPOS(next,gvar)-pos;\r
endpos = pos+compressed;\r
\r
if (compressed<=BUFFERSIZE)\r
if (next == NUMCHUNKS)\r
continue;\r
\r
- nextpos = GRFILEPOS(next);\r
- while (GRFILEPOS(++next) == -1) // skip past any sparse tiles\r
+ nextpos = GRFILEPOS(next,gvar);\r
+ while (GRFILEPOS(++next,gvar) == -1) // skip past any sparse tiles\r
;\r
- nextendpos = GRFILEPOS(next);\r
+ nextendpos = GRFILEPOS(next,gvar);\r
if (nextpos - endpos <= MAXEMPTYREAD\r
&& nextendpos-pos <= BUFFERSIZE)\r
endpos = nextendpos;\r
-/* Catacomb Apocalypse Source Code\r
- * Copyright (C) 1993-2014 Flat Rock Software\r
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
*\r
- * This program is free software; you can redistribute it and/or modify\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 2 of the License, or\r
+ * the Free Software Foundation; either version 3 of the License, or\r
* (at your option) any later version.\r
*\r
- * This program is distributed in the hope that it will be useful,\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 along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\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
// NEWMM.C\r
\r
RELIES ON\r
---------\r
-Quit (global_game_variables_t *gvar, char *error) function\r
+Quit (gvar, global_game_variables_t *gvar, char *error) function\r
\r
\r
WORK TO DO\r
#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
=============================================================================\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
\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
}\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
// 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
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
====================\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
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
===================\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
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
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
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
//\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
====================\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
====================\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
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
//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
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
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
playing += STARTADLIBSOUNDS;\r
break;\r
}\r
- MM_SetLock((memptr *)&audiosegs[playing],true);\r
+ MM_SetLock(MEMPTRCONV audiosegs[playing],true);\r
}\r
\r
\r
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
}\r
else\r
{\r
- if(scan->attributes & PURGEBITS)\r
+ if (scan->attributes & PURGEBITS)\r
{\r
//\r
// throw out the purgable block\r
//\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
\r
gvar->mm.mmrover = gvar->mm.mmhead;\r
\r
- if(aftersort)\r
+ if (aftersort)\r
aftersort();\r
\r
VL_ColorBorder (oldborder, &gvar->video);\r
-/* Catacomb Apocalypse Source Code\r
- * Copyright (C) 1993-2014 Flat Rock Software\r
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
*\r
- * This program is free software; you can redistribute it and/or modify\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 2 of the License, or\r
+ * the Free Software Foundation; either version 3 of the License, or\r
* (at your option) any later version.\r
*\r
- * This program is distributed in the hope that it will be useful,\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 along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\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
// ID_MM.H\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
#else\r
-#define OUT_OF_MEM_MSG "\npee\n"\r
+#define OUT_OF_MEM_MSG "\n"\r
#endif\r
\r
//#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}\r
\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
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_MapEMS(global_game_variables_t *gvar);\r
//byte MM_MapXEMS(global_game_variables_t *gvar);\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_ClearBlock(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