#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
\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
\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