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=20
+T_FLAGS=-bt=dos -mh -0 -fpi87 -fo=.$(OBJ) -d1 -e=65536
CPPFLAGS=-DTARGET_MSDOS=16 -DMSDOS=1
!ifeq DEBUGSERIAL 1
# objects
#
VGMSNDOBJ = vgmSnd.$(OBJ) 16_snd.$(OBJ)
-16LIBOBJS = 16_lib.$(OBJ) 16_in.$(OBJ) 16_mm.$(OBJ) wcpu.$(OBJ) 16_head.$(OBJ) 16_ca.$(OBJ) 16_dbg.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ) 16_timer.$(OBJ)
+16LIBOBJS = 16_lib.$(OBJ) 16_in.$(OBJ) 16_mm.$(OBJ) wcpu.$(OBJ) 16_head.$(OBJ) 16_ca.$(OBJ) 16_dbg.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ) 16_timer.$(OBJ) 16_pm.$(OBJ)
GFXLIBOBJS = modex16.$(OBJ) bitmap.$(OBJ) 16text.$(OBJ) bakapee.$(OBJ) scroll16.$(OBJ) 16render.$(OBJ) 16_vrs.$(OBJ) 16_sprit.$(OBJ) #scroll16.$(OBJ)
#16planar.$(OBJ) planar.$(OBJ)
DOSLIBOBJ = adlib.$(OBJ) 8254.$(OBJ) 8259.$(OBJ) dos.$(OBJ) cpu.$(OBJ)
16/wolf3d/WOLFSRC/WOLF3D.MAP: 1912:114B _PM_Shutdown\r
16/wolf3d/WOLFSRC/WOLFHACK.C: src = PM_GetPage(0);\r
16/wolf3d/WOLFSRC/WOLFHACK.C: src = PM_GetPage(1);\r
+\r
+16/wf3d8086/id_pm.c: longword last = MAXLONG;\r
+16/wf3d8086/id_pm.c: for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < ChunksInFile;i++,page++)\r
+16/wf3d8086/id_pm.c: for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < ChunksInFile;i++,page++)\r
+16/wf3d8086/id_pm.c: if (++PMFrameCount >= MAXLONG - 4)\r
bakapee2 = "data/test.map";\r
}\r
// printf("main()=%Fp start MM\n", *argv[0]);\r
- MM_Startup(&gvar.mm, &gvar.mmi);\r
+ MM_Startup(&gvar);\r
//PM_Startup();\r
//PM_UnlockMainMem();\r
CA_Startup(&gvar);\r
printf("press any key to continue!\n");\r
getch();\r
MM_ShowMemory(&gvar);\r
- MM_DumpData(&gvar.mm);\r
+ MM_DumpData(&gvar);\r
MM_Report_(&gvar);\r
if(baka) printf("\nyay!\n");\r
else printf("\npoo!\n");\r
#ifdef FILEREAD\r
}\r
#endif\r
- MM_FreePtr(&bigbuffer, &gvar.mm);\r
+ MM_FreePtr(&bigbuffer, &gvar);\r
//PM_Shutdown();\r
CA_Shutdown(&gvar);\r
- MM_Shutdown(&gvar.mm);\r
+ MM_Shutdown(&gvar);\r
free(bakapee1); free(bakapee2);\r
printf("========================================\n");\r
printf("near= %Fp ", gvar.mm.nearheap);\r
boolean flag;\r
//dword fat=0;\r
//word segm=0;\r
- if(gvar->mm.EMSVer<0x40)\r
+ if(gvar->pm.emm.EMSVer<0x40)\r
if(length>0xfffflu)\r
{\r
printf("File is a fat bakapee\n");\r
boolean flag;\r
//dword fat=0;\r
//word segm=0;\r
- if(gvar->mm.EMSVer<0x40)\r
+ if(gvar->pm.emm.EMSVer<0x40)\r
if(length>0xfffflu)\r
{\r
printf("File is a fat bakapee\n");\r
return false;\r
\r
size = filelength(handle);\r
- MM_GetPtr(ptr,size, &(gvar->mm), &(gvar->mmi)); //TODO: gvar parameters\r
+ MM_GetPtr(ptr,size, gvar);\r
if(!CA_FarRead(handle,*ptr,size, gvar))\r
{\r
close(handle);\r
#include <sys/stat.h>\r
#include <mem.h>\r
#include <string.h>\r
+#include <limits.h>\r
#ifdef __WATCOMC__\r
#include <i86.h>\r
#include <unistd.h>\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
=======================
*/
-byte MML_SetupEMS(mminfo_t *mm)
+byte MML_SetupEMS(global_game_variables_t *gvar)
{
byte str[160];
byte err;
printf("%s\n",str);
return err;
}
- mm->totalEMSpages=totalEMSpages;
- mm->freeEMSpages=freeEMSpages;
- mm->EMSpageframe=EMSpageframe;
- mm->EMSpagesmapped=EMSpagesmapped;
- mm->EMShandle=EMShandle;
- mm->EMSVer=EMSVer;
+ gvar->mm.totalEMSpages=totalEMSpages;
+ gvar->mm.freeEMSpages=freeEMSpages;
+ gvar->mm.EMSpageframe=EMSpageframe;
+ gvar->mm.EMSpagesmapped=EMSpagesmapped;
+ gvar->mm.EMShandle=EMShandle;
+ gvar->pm.emm.EMSVer=EMSVer;
return 0;
}
=======================
*/
-void MML_ShutdownEMS(mminfo_t *mm)
+void MML_ShutdownEMS(global_game_variables_t *gvar)
{
boolean errorflag=false;
- unsigned EMShandle=mm->EMShandle;
+ unsigned EMShandle=gvar->mm.EMShandle;
if(!EMShandle)
return;
====================
*/
-byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi)
+byte MM_MapEMS(global_game_variables_t *gvar)
{
byte str[160];
unsigned EMShandle;
byte err;
boolean errorflag=false;
int i;
- EMShandle=mm->EMShandle;
+ EMShandle=gvar->mm.EMShandle;
for (i=0;i<4/*MAPPAGES*/;i++)
{
return err;
}
}
- mmi->EMSmem = (i)*0x4000lu;
- //printf(" mmi->EMSmem=%lu\n", mmi->EMSmem);
+ gvar->mmi.EMSmem = (i)*0x4000lu;
+ //printf(" gvar->mmi.EMSmem=%lu\n", gvar->mmi.EMSmem);
return 0;
}
-byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi)
+byte MM_MapXEMS(global_game_variables_t *gvar)
{
//SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)
word EMShandle;
boolean errorflag=false;
int i;
- EMShandle=mm->EMShandle;
+ EMShandle=gvar->mm.EMShandle;
- if(mm->EMSVer<0x40)
+ if(gvar->pm.emm.EMSVer<0x40)
return 5;
for (i=0;i<MAPPAGES;i++)
return err;
}
}
- mmi->EMSmem = (i)*0x4000lu;
+ gvar->mmi.EMSmem = (i)*0x4000lu;
return 0;
}
=======================
*/
-boolean MML_CheckForXMS(mminfo_t *mm)
+boolean MML_CheckForXMS(global_game_variables_t *gvar)
{
boolean errorflag=false;
- mm->numUMBs = 0;
+ gvar->mm.numUMBs = 0;
__asm {
mov ax,0x4300
=======================
*/
-void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
+void MML_SetupXMS(global_game_variables_t *gvar)
{
word base,size;
}
#endif
// printf("base=%u ", base); printf("size=%u\n", size);
- MML_UseSpace(base,size, mm);
- mmi->XMSmem += size*16;
- mm->UMBbase[mm->numUMBs] = base;
- mm->numUMBs++;
- if(mm->numUMBs < MAXUMBS)
+ MML_UseSpace(base,size, gvar);
+ gvar->mmi.XMSmem += size*16;
+ gvar->mm.UMBbase[gvar->mm.numUMBs] = base;
+ gvar->mm.numUMBs++;
+ if(gvar->mm.numUMBs < MAXUMBS)
goto getmemory;
}
======================
*/
-void MML_ShutdownXMS(mminfo_t *mm)
+void MML_ShutdownXMS(global_game_variables_t *gvar)
{
int i;
unsigned base;
- for (i=0;i<mm->numUMBs;i++)
+ for (i=0;i<gvar->mm.numUMBs;i++)
{
- base = mm->UMBbase[i];
+ base = gvar->mm.UMBbase[i];
__asm {
mov ah,XMS_FREEUMB
mov dx,[base]
======================
*/
-/*void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
+/*void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar)
{
//huge mmblocktype huge *scan,huge *last;
word segm=1;
dword segmlen;
dword extra;
- scan = last = mm->mmhead;
- mm->mmrover = mm->mmhead; // reset rover to start of memory
+ scan = last = gvar->mm.mmhead;
+ gvar->mm.mmrover = gvar->mm.mmhead; // reset rover to start of memory
//
// search for the block that contains the range of segments
{
scan->blob=segm;
- //MML_UseSpace(segstart, seglength, mm);
+ //MML_UseSpace(segstart, seglength, gvar);
printf("MML_UseSpace: Segment spans two blocks!\n");
//}
if(extra > 0)
{
GETNEWBLOCK;
- mm->mmnew->useptr = NULL;
+ gvar->mm.mmnew->useptr = NULL;
- mm->mmnew->next = scan->next;
- scan->next = mm->mmnew;
- mm->mmnew->start = segstart+seglength;
- mm->mmnew->length = extra;
- mm->mmnew->attributes = LOCKBIT;
+ gvar->mm.mmnew->next = scan->next;
+ scan->next = gvar->mm.mmnew;
+ gvar->mm.mmnew->start = segstart+seglength;
+ gvar->mm.mmnew->length = extra;
+ gvar->mm.mmnew->attributes = LOCKBIT;
}//else if(segm>0) goto segu;
}*/
-void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm)
+void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar)
{
mmblocktype far *scan,far *last;
word oldend;
sdword extra;
//word segm=1;
- scan = last = mm->mmhead;
- mm->mmrover = mm->mmhead; // reset rover to start of memory
+ scan = last = gvar->mm.mmhead;
+ gvar->mm.mmrover = gvar->mm.mmhead; // reset rover to start of memory
//
// search for the block that contains the range of segments
if (extra > 0)
{
GETNEWBLOCK;
- mm->mmnew->useptr = NULL;
+ gvar->mm.mmnew->useptr = NULL;
- mm->mmnew->next = scan->next;
- scan->next = mm->mmnew;
- mm->mmnew->start = segstart+seglength;
- mm->mmnew->length = extra;
- mm->mmnew->attributes = LOCKBIT;
+ gvar->mm.mmnew->next = scan->next;
+ scan->next = gvar->mm.mmnew;
+ gvar->mm.mmnew->start = segstart+seglength;
+ gvar->mm.mmnew->length = extra;
+ gvar->mm.mmnew->attributes = LOCKBIT;
}
}
====================
*/
-void MML_ClearBlock(mminfo_t *mm)
+void MML_ClearBlock(global_game_variables_t *gvar)
{
//huge mmblocktype huge *scan,huge *last;
mmblocktype far *scan,far *last;
- scan = mm->mmhead->next;
+ scan = gvar->mm.mmhead->next;
while(scan)
{
if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS))
{
- MM_FreePtr(scan->useptr, mm);
+ MM_FreePtr(scan->useptr, gvar);
return;
}
scan = scan->next;
===================
*/
-void MM_Startup(mminfo_t *mm, mminfotype *mmi)
+void MM_Startup(global_game_variables_t *gvar)
{
int i;
//dword length,seglength;
word segstart;//,endfree;
//memptr *peeonself;
-// if(mm->mmstarted)
-// MM_Shutdown(mm);
+ if(gvar->mm.mmstarted)
+ MM_Shutdown(gvar);
- mm->mmstarted = true;
- mm->bombonerror = true;
+ gvar->mm.mmstarted = true;
+ gvar->mm.bombonerror = true;
//
// set up the linked list (everything in the free list;
//
- mm->mmhead = NULL;
- mm->mmfree = &(mm->mmblocks[0]);
+ gvar->mm.mmhead = NULL;
+ gvar->mm.mmfree = &(gvar->mm.mmblocks[0]);
for(i=0;i<MAXBLOCKS-1;i++)
{
- mm->mmblocks[i].next = &(mm->mmblocks[i+1]);
+ gvar->mm.mmblocks[i].next = &(gvar->mm.mmblocks[i+1]);
}
- mm->mmblocks[i].next = NULL;
+ gvar->mm.mmblocks[i].next = NULL;
//
// locked block of all memory until we punch out free space
//
GETNEWBLOCK;
- mm->mmhead = mm->mmnew; // this will allways be the first node
- mm->mmnew->start = 0;
- mm->mmnew->length = 0xffff;
- mm->mmnew->attributes = LOCKBIT;
- mm->mmnew->next = NULL;
- //mm->mmnew->useptr = peeonself;
- mm->mmrover = mm->mmhead;
+ gvar->mm.mmhead = gvar->mm.mmnew; // this will allways be the first node
+ gvar->mm.mmnew->start = 0;
+ gvar->mm.mmnew->length = 0xffff;
+ gvar->mm.mmnew->attributes = LOCKBIT;
+ gvar->mm.mmnew->next = NULL;
+ //gvar->mm.mmnew->useptr = peeonself;
+ gvar->mm.mmrover = gvar->mm.mmhead;
//printf(" %x\n", peeonself);
//printf(" %x\n", *peeonself);
#ifdef __WATCOMC__
_nheapgrow();
length=(dword)_memavl();//(dword)GetFreeSize();
- //huge start = (void huge *)(mm->nearheap = _nmalloc(length));
- start = (void far *)(mm->nearheap = _nmalloc(length));
+ //huge start = (void huge *)(gvar->mm.nearheap = _nmalloc(length));
+ start = (void far *)(gvar->mm.nearheap = _nmalloc(length));
#endif
#ifdef __BORLANDC__
length=coreleft();
- //huge start = (void huge *)(mm->nearheap = malloc(length));
- start = (void far *)(mm->nearheap = malloc(length));
+ //huge start = (void huge *)(gvar->mm.nearheap = malloc(length));
+ start = (void far *)(gvar->mm.nearheap = malloc(length));
#endif
length -= 16-(FP_OFF(start)&15);
length -= SAVENEARHEAP;
seglength = length / 16; // now in paragraphs
segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
- MML_UseSpace(segstart,seglength, mm);
- mmi->nearheap = length;
+ MML_UseSpace(segstart,seglength, gvar);
+ gvar->mmi.nearheap = length;
//printf("start=%Fp segstart=%x seglen=%lu len=%lu\n", start, segstart, seglength, length);
//
printf("(farcoreleft()+32)-_FCORELEFT %d\n", (sword)((farcoreleft()+32)-_FCORELEFT));
#endif
length=_FCORELEFT;//_fcoreleft();//(dword)GetFarFreeSize();//0xffffUL*4UL;
- start = mm->farheap = _fmalloc(length);
- //start = mm->farheap = halloc(length, 1);
+ start = gvar->mm.farheap = _fmalloc(length);
+ //start = gvar->mm.farheap = halloc(length, 1);
length -= 16-(FP_OFF(start)&15);
length -= SAVEFARHEAP;
seglength = length / 16; // now in paragraphs
segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
- MML_UseSpace(segstart,seglength, mm);
- mmi->farheap = length;
+ MML_UseSpace(segstart,seglength, gvar);
+ gvar->mmi.farheap = length;
//printf("start=%Fp segstart=%x seglen=%lu len=%lu\n", start, segstart, seglength, length);
- mmi->mainmem = mmi->nearheap + mmi->farheap;
+ gvar->mmi.mainmem = gvar->mmi.nearheap + gvar->mmi.farheap;
//
// detect EMS and allocate up to 64K at page frame
//
- mmi->EMSmem = 0;
+ gvar->mmi.EMSmem = 0;
//goto emsskip; //0000
for(i = 1;i <
#ifdef __WATCOMC__
}
if(MML_CheckForEMS())
{
- MML_SetupEMS(mm); // allocate space
+ MML_SetupEMS(gvar); // allocate space
//TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
- MML_UseSpace(mm->EMSpageframe,(MAPPAGES)*0x4000lu, mm);
- //if(mm->EMSVer<0x40)
- MM_MapEMS(mm, mmi); // map in used pages
+ MML_UseSpace(gvar->mm.EMSpageframe,(MAPPAGES)*0x4000lu, gvar);
+ //if(gvar->pm.emm.EMSVer<0x40)
+ MM_MapEMS(gvar); // map in used pages
//else
- //MM_MapXEMS(mm, mmi); // map in used pages
+ //MM_MapXEMS(gvar); // map in used pages
}
//
// detect XMS and get upper memory blocks
//
emsskip:
- mmi->XMSmem = 0;
+ gvar->mmi.XMSmem = 0;
goto xmsskip;//0000
for(i = 1;i <
#ifdef __WATCOMC__
,ParmStringsexmm) == 0)
goto xmsskip; // param NOXMS
}
- if(MML_CheckForXMS(mm))
+ if(MML_CheckForXMS(gvar))
{
- MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible
+ MML_SetupXMS(gvar); // allocate as many UMBs as possible
}
//
// allocate the misc buffer
//
xmsskip:
- mm->mmrover = mm->mmhead; // start looking for space after low block
+ gvar->mm.mmrover = gvar->mm.mmhead; // start looking for space after low block
- MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi);
+ MM_GetPtr(&(gvar->mm.bufferseg),BUFFERSIZE, gvar);
}
//==========================================================================
====================
*/
-void MM_Shutdown(mminfo_t *mm)
+void MM_Shutdown(global_game_variables_t *gvar)
{
- if(!(mm->mmstarted))
+ if(!(gvar->mm.mmstarted))
return;
- _ffree(mm->farheap);// printf(" far freed\n");
+ _ffree(gvar->mm.farheap);// printf(" far freed\n");
#ifdef __WATCOMC__
- _nfree(mm->nearheap);// printf(" near freed\n");
+ _nfree(gvar->mm.nearheap);// printf(" near freed\n");
#endif
#ifdef __BORLANDC__
- free(mm->nearheap);// printf(" near freed\n");
+ free(gvar->mm.nearheap);// printf(" near freed\n");
#endif
- if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); }//printf(" EMS freed\n"); }
- if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); }//printf(" XMS freed\n"); }
+ if(MML_CheckForEMS()){ MML_ShutdownEMS(gvar); }//printf(" EMS freed\n"); }
+ if(MML_CheckForXMS(gvar)){ MML_ShutdownXMS(gvar); }//printf(" XMS freed\n"); }
}
//==========================================================================
====================
*/
-void MM_GetPtr (memptr *baseptr, dword size, mminfo_t *mm, mminfotype *mmi)
+void MM_GetPtr (memptr *baseptr, dword size, global_game_variables_t *gvar)
{
//huge mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
mmblocktype far *scan,far *lastscan,far *endscan,far *purge,far *next;
needed = (size+15)/16; // convert size from bytes to paragraphs
GETNEWBLOCK; // fill in start and next after a spot is found
- mm->mmnew->length = needed;
- mm->mmnew->useptr = baseptr;
- //if(mm->mmnew->useptr==NULL){
+ 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", mm->mmnew->useptr);
- printf("*baseptr=%04x ", *baseptr); printf("*useptr=%04x\n", *(mm->mmnew->useptr));
- printf("*baseptr=%Fp ", *baseptr); printf("*useptr=%Fp\n", *(mm->mmnew->useptr));
+ 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));
#endif
//exit(-5); }
- mm->mmnew->attributes = BASEATTRIBUTES;
+ gvar->mm.mmnew->attributes = BASEATTRIBUTES;
//tryagain:
for (search = 0; search<3; search++)
// first search: try to allocate right after the rover, then on up
// second search: search from the head pointer up to the rover
// third search: compress memory, then scan from start
- if (search == 1 && mm->mmrover == mm->mmhead)
+ if (search == 1 && gvar->mm.mmrover == gvar->mm.mmhead)
search++;
switch (search)
{
case 0:
- lastscan = mm->mmrover;
- scan = mm->mmrover->next;
+ lastscan = gvar->mm.mmrover;
+ scan = gvar->mm.mmrover->next;
endscan = NULL;
break;
case 1:
- lastscan = mm->mmhead;
- scan = mm->mmhead->next;
- endscan = mm->mmrover;
+ lastscan = gvar->mm.mmhead;
+ scan = gvar->mm.mmhead->next;
+ endscan = gvar->mm.mmrover;
break;
case 2:
- MM_SortMem (mm);
- lastscan = mm->mmhead;
- scan = mm->mmhead->next;
+ MM_SortMem (gvar);
+ lastscan = gvar->mm.mmhead;
+ scan = gvar->mm.mmhead->next;
endscan = NULL;
break;
}
// and allocate the new block
//
purge = lastscan->next;
- lastscan->next = mm->mmnew;
- mm->mmnew->start = *(unsigned *)baseptr = startseg;
- mm->mmnew->next = scan;
+ lastscan->next = gvar->mm.mmnew;
+ gvar->mm.mmnew->start = *(unsigned *)baseptr = startseg;
+ gvar->mm.mmnew->next = scan;
while ( purge != scan)
{ // free the purgable block
next = purge->next;
FREEBLOCK(purge);
purge = next; // purge another if not at scan
}
- mm->mmrover = mm->mmnew;
+ gvar->mm.mmrover = gvar->mm.mmnew;
return; // good allocation!
}
}
}
- if (mm->bombonerror)
+ if (gvar->mm.bombonerror)
{
#ifdef __WATCOMC__
//heapdump();
#endif
- printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
+ printf(OUT_OF_MEM_MSG,(size-gvar->mmi.nearheap));
printf("for stability reasons the program will shut down! wwww\n");
- MM_Shutdown(mm);
+ MM_Shutdown(gvar);
exit(-1);
}
else
- mm->mmerror = true;
+ gvar->mm.mmerror = true;
}
//==========================================================================
====================
*/
-void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
+void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar)
{
//huge mmblocktype huge *scan,huge *last;
mmblocktype far *scan,far *last;
- last = mm->mmhead;
+ last = gvar->mm.mmhead;
scan = last->next;
- if(baseptr == mm->mmrover->useptr) // removed the last allocated block
- mm->mmrover = mm->mmhead;
+ if(baseptr == gvar->mm.mmrover->useptr) // removed the last allocated block
+ gvar->mm.mmrover = gvar->mm.mmhead;
while(scan->useptr != baseptr && scan)
{
=====================
*/
-void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
+void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar)
{
//huge mmblocktype huge *start;
mmblocktype far *start;
- start = mm->mmrover;
+ start = gvar->mm.mmrover;
do
{
- if(mm->mmrover->useptr == baseptr)
+ if(gvar->mm.mmrover->useptr == baseptr)
break;
- mm->mmrover = mm->mmrover->next;
+ gvar->mm.mmrover = gvar->mm.mmrover->next;
- if(!mm->mmrover)
- mm->mmrover = mm->mmhead;
- else if(mm->mmrover == start)
+ if(!gvar->mm.mmrover)
+ gvar->mm.mmrover = gvar->mm.mmhead;
+ else if(gvar->mm.mmrover == start)
{
Quit("MM_SetPurge: Block not found!");
//return;
} while(1);
- mm->mmrover->attributes &= ~PURGEBITS;
- mm->mmrover->attributes |= purge;
+ gvar->mm.mmrover->attributes &= ~PURGEBITS;
+ gvar->mm.mmrover->attributes |= purge;
}
//==========================================================================
=====================
*/
-void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
+void MM_SetLock(memptr *baseptr, boolean locked, global_game_variables_t *gvar)
{
//huge mmblocktype huge *start;
mmblocktype far *start;
- start = mm->mmrover;
+ start = gvar->mm.mmrover;
do
{
- if(mm->mmrover->useptr == baseptr)
+ if(gvar->mm.mmrover->useptr == baseptr)
break;
- mm->mmrover = mm->mmrover->next;
+ gvar->mm.mmrover = gvar->mm.mmrover->next;
- if(!mm->mmrover)
- mm->mmrover = mm->mmhead;
- else if(mm->mmrover == start)
+ if(!gvar->mm.mmrover)
+ gvar->mm.mmrover = gvar->mm.mmhead;
+ else if(gvar->mm.mmrover == start)
{
Quit("MM_SetLock: Block not found!");
//return;
} while(1);
- mm->mmrover->attributes &= ~LOCKBIT;
- mm->mmrover->attributes |= locked*LOCKBIT;
+ gvar->mm.mmrover->attributes &= ~LOCKBIT;
+ gvar->mm.mmrover->attributes |= locked*LOCKBIT;
}
//==========================================================================
=====================
*/
-void MM_SortMem(mminfo_t *mm)
+void MM_SortMem(global_game_variables_t *gvar)
{
//huge mmblocktype huge *scan,huge *last,huge *next;
mmblocktype far *scan,far *last,far *next;
if(beforesort)
beforesort();
- scan = mm->mmhead;
+ scan = gvar->mm.mmhead;
last = NULL; // shut up compiler warning
//
next = scan->next;
FREEBLOCK(scan);
- //MM_FreeBlock(scan, mm);
+ //MM_FreeBlock(scan, gvar);
last->next = next;
scan = next;
continue;
scan = scan->next; // go to next block
}
- mm->mmrover = mm->mmhead;
+ gvar->mm.mmrover = gvar->mm.mmhead;
if(aftersort)
aftersort();
/*strcpy(scratch1, AARESET);
strcat(scratch1, "========================================\n");
strcat(scratch1, "near= ");
- ultoa (*(mm->nearheap),str,10);
+ ultoa (*(gvar->mm.nearheap),str,10);
strcat (scratch1,str);
strcat(scratch1, " far= ");
- ultoa (*(mm->farheap),str,10);
+ ultoa (*(gvar->mm.farheap),str,10);
strcat (scratch1,str);
strcat(scratch1, "\n");
- //strcat(scratch1, "&near= %Fp ", &(mm->nearheap));
- //strcat(scratch1, "&far= %Fp", &(mm->farheap));
+ //strcat(scratch1, "&near= %Fp ", &(gvar->mm.nearheap));
+ //strcat(scratch1, "&far= %Fp", &(gvar->mm.farheap));
//strcat(scratch1, "\n");
strcat(scratch1, "========================================\n");
write(gvar->handle.debughandle,scratch1,strlen(scratch1));*/
=====================
*/
-void MM_DumpData(mminfo_t *mm)
+void MM_DumpData(global_game_variables_t *gvar)
{
//huge mmblocktype huge *scan,huge *best;
mmblocktype far *scan,far *best;
byte lock,purge;
FILE *dumpfile;
- free(mm->nearheap);
+ free(gvar->mm.nearheap);
#ifdef __BORLANDC__
dumpfile = fopen ("mmdump.16b","w");
#endif
oldlowest = lowest;
lowest = 0xffff;
- scan = mm->mmhead;
+ scan = gvar->mm.mmhead;
while (scan)
{
owner = (unsigned)scan->useptr;
======================
*/
-dword MM_UnusedMemory(mminfo_t *mm)
+dword MM_UnusedMemory(global_game_variables_t *gvar)
{
dword free;
//huge mmblocktype huge *scan;
mmblocktype far *scan;
free = 0;
- scan = mm->mmhead;
+ scan = gvar->mm.mmhead;
while(scan->next)
{
======================
*/
-dword MM_TotalFree(mminfo_t *mm)
+dword MM_TotalFree(global_game_variables_t *gvar)
{
dword free;
//huge mmblocktype huge *scan;
mmblocktype far *scan;
free = 0;
- scan = mm->mmhead;
+ scan = gvar->mm.mmhead;
while(scan->next)
{
if(MML_CheckForEMS())
{
printf(" LIMEMS\n");
- printf(" EMM v%x.%x available\n", gvar->mm.EMSVer>>4,gvar->mm.EMSVer&0x0F);
+ printf(" EMM v%x.%x available\n", gvar->pm.emm.EMSVer>>4,gvar->pm.emm.EMSVer&0x0F);
printf(" totalEMSpages: %u ", gvar->mm.totalEMSpages); printf("freeEMSpages: %u\n", gvar->mm.freeEMSpages);
printf(" EMSpageframe: %x\n", gvar->mm.EMSpageframe);
}
- if(MML_CheckForXMS(&(gvar->mm)))
+ if(MML_CheckForXMS(gvar))
{
printf(" XMS\n");
printf(" XMSaddr: %X\n", *XMSaddr);
}
printf("near: %lu ", gvar->mmi.nearheap); printf("far: %lu\n", gvar->mmi.farheap); if(MML_CheckForEMS())
- printf("EMSmem: %lu ", gvar->mmi.EMSmem); if(MML_CheckForXMS(&(gvar->mm))) printf("XMSmem: %lu", gvar->mmi.XMSmem); printf("\n");
+ printf("EMSmem: %lu ", gvar->mmi.EMSmem); if(MML_CheckForXMS(gvar)) printf("XMSmem: %lu", gvar->mmi.XMSmem); printf("\n");
//printf("mainmem: %lu\n", gvar->mmi.mainmem);
- printf("Total convmem: %lu ", gvar->mmi.mainmem); printf("TotalFree: %lu ", MM_TotalFree(&(gvar->mm))); printf("TotalUsed: %lu\n", gvar->mmi.mainmem+gvar->mmi.EMSmem+gvar->mmi.XMSmem+gvar->mmi.XMSmem);
- printf(" UnusedMemory: %lu\n", MM_UnusedMemory(&(gvar->mm)));
+ printf("Total convmem: %lu ", gvar->mmi.mainmem); printf("TotalFree: %lu ", MM_TotalFree(gvar)); printf("TotalUsed: %lu\n", gvar->mmi.mainmem+gvar->mmi.EMSmem+gvar->mmi.XMSmem+gvar->mmi.XMSmem);
+ printf(" UnusedMemory: %lu\n", MM_UnusedMemory(gvar));
}
//==========================================================================
=====================
*/
-void MM_BombOnError(boolean bomb, mminfo_t *mm)
+void MM_BombOnError(boolean bomb, global_game_variables_t *gvar)
{
- mm->bombonerror = bomb;
+ gvar->mm.bombonerror = bomb;
}
-/*void MM_GetNewBlock(mminfo_t *mm)
+/*void MM_GetNewBlock(global_game_variables_t *gvar)
{
- if(!mm->mmfree)
- MML_ClearBlock(mm);
- mm->mmnew=mm->mmfree;
- mm->mmfree=mm->mmfree->next;
- if(!(mm->mmnew=mm->mmfree))
+ if(!gvar->mm.mmfree)
+ MML_ClearBlock(gvar);
+ gvar->mm.mmnew=gvar->mm.mmfree;
+ gvar->mm.mmfree=gvar->mm.mmfree->next;
+ if(!(gvar->mm.mmnew=gvar->mm.mmfree))
{
printf("MM_GETNEWBLOCK: No free blocks!\n");
return;
}
- mm->mmfree=mm->mmfree->next;
+ gvar->mm.mmfree=gvar->mm.mmfree->next;
}
-void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
+void MM_FreeBlock(mmblocktype *x, global_game_variables_t *gvar)
{
x->useptr=NULL;
- x->next=mm->mmfree;
- mm->mmfree=x;
+ x->next=gvar->mm.mmfree;
+ gvar->mm.mmfree=x;
}*/
/*void MM_seguin(void)
#endif
//#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}
-#define GETNEWBLOCK {if(!mm->mmfree)MML_ClearBlock(mm);mm->mmnew=mm->mmfree;mm->mmfree=mm->mmfree->next;}
+#define GETNEWBLOCK {if(!gvar->mm.mmfree)MML_ClearBlock(gvar);gvar->mm.mmnew=gvar->mm.mmfree;gvar->mm.mmfree=gvar->mm.mmfree->next;}
-#define FREEBLOCK(x) {*x->useptr=NULL;x->next=mm->mmfree;mm->mmfree=x;}
+#define FREEBLOCK(x) {*x->useptr=NULL;x->next=gvar->mm.mmfree;gvar->mm.mmfree=x;}
#define SAVENEARHEAP 0x200 // space to leave in data segment
#define SAVEFARHEAP 0//x400 // space to leave in far heap
//--------
#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 XMSD dword XMSDriver=gvar->pm.xmm.XMSDriver;
+inline void XMS_CALL(byte v, global_game_variables_t *gvar)
+{
+ XMSD;
+ XMSDriver=gvar->pm.xmm.XMSDriver;
+ __asm {
+ mov v,ah
+ call [WORD PTR XMSDriver]
+ }
+}
#define XMS_VERSION 0x00
//moved to typedefst
//#define MAXUMBS 12
-#define MAPPAGES 4//mm->EMSpagesmapped
+#define MAPPAGES 4//gvar->mm.EMSpagesmapped
//moved to typdefst
/*typedef struct mmblockstruct
//==========================================================================
boolean MML_CheckForEMS(void);
-byte MML_SetupEMS(mminfo_t *mm);
-void MML_ShutdownEMS(mminfo_t *mm);
-byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi);
-byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi);
-boolean MML_CheckForXMS(mminfo_t *mm);
-void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
-void MML_ShutdownXMS(mminfo_t *mm);
-void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm);
-void MML_ClearBlock(mminfo_t *mm);
-
-void MM_Startup(mminfo_t *mm, mminfotype *mmi);
-void MM_Shutdown(mminfo_t *mm);
-
-void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi);
-void MM_FreePtr(memptr *baseptr, mminfo_t *mm);
-void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm);
-void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm);
-void MM_SortMem(mminfo_t *mm);
+//byte MML_SetupEMS(mminfo_t *mm);
+//void MML_ShutdownEMS(mminfo_t *mm);
+byte MM_MapEMS(global_game_variables_t *gvar);
+byte MM_MapXEMS(global_game_variables_t *gvar);
+//boolean MML_CheckForXMS(mminfo_t *mm);
+//void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
+//void MML_ShutdownXMS(mminfo_t *mm);
+void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar);
+void MML_ClearBlock(global_game_variables_t *gvar);
+
+void MM_Startup(global_game_variables_t *gvar);
+void MM_Shutdown(global_game_variables_t *gvar);
+
+void MM_GetPtr(memptr *baseptr,dword size, global_game_variables_t *gvar);
+void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar);
+void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar);
+void MM_SetLock(memptr *baseptr, boolean locked, global_game_variables_t *gvar);
+void MM_SortMem(global_game_variables_t *gvar);
void MM_ShowMemory(global_game_variables_t *gvar);//,/*page_t *page, */mminfo_t *mm);
-void MM_DumpData(mminfo_t *mm);
-dword MM_UnusedMemory(mminfo_t *mm);
-dword MM_TotalFree(mminfo_t *mm);
+void MM_DumpData(global_game_variables_t *gvar);
+dword MM_UnusedMemory(global_game_variables_t *gvar);
+dword MM_TotalFree(global_game_variables_t *gvar);
void MM_Report_(global_game_variables_t *gvar);
static void MM_EMSerr(byte *stri, byte err);
-void MM_BombOnError(boolean bomb, mminfo_t *mm);
+void MM_BombOnError(boolean bomb, global_game_variables_t *gvar);
//void MM_GetNewBlock(mminfo_t *mm);
//void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ *\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 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\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\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
//\r
// ID_PM.C\r
// Id Engine's Page Manager v1.0\r
\r
#include "src/lib/16_pm.h"\r
#pragma hdrstop\r
+union REGS CPURegs;\r
/*\r
// Main Mem specific variables\r
boolean MainPresent;\r
memptr MainMemPages[PMMaxMainMem];\r
- PMBlockAttr MainMemUsed[PMMaxMainMem];\r
- int MainPagesAvail;\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
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
+ gvar->pm.emm.EMSListStruct gvar->pm.emm.EMSList[EMSFrameCount];\r
\r
// XMS specific variables\r
boolean gvar->pm.xmm.XMSPresent;\r
int gvar->pm.xmm.XMSProtectPage = -1;\r
\r
// File specific variables\r
- char PageFileName[13] = {"VSWAP."};\r
+ char gvar->pm.fi.PageFileName[13] = {"VSWAP."};\r
int PageFile = -1;\r
word gvar->pm.fi.ChunksInFile;\r
word PMSpriteStart,PMSoundStart;\r
\r
// General usage variables\r
boolean PMStarted,\r
- PMPanicMode,\r
- PMThrashing;\r
- word gvar->pm.xmm.XMSPagesUsed,\r
- gvar->pm.emm.EMSPagesUsed,\r
+ gvar->pm.PMPanicMode,\r
+ gvar->pm.PMThrashing;\r
+ word gvar->pm.XMSPagesUsed,\r
+ gvar->pm.EMSPagesUsed,\r
MainPagesUsed,\r
- PMNumBlocks;\r
+ gvar->pm.PMNumBlocks;\r
long PMFrameCount;\r
- PageListStruct far *PMPages,\r
- _seg *PMSegPages;\r
+ PageListStruct far *gvar->pm.PMPages,\r
+ _seg *gvar->pm.PMSegPages;\r
*/\r
static char *ParmStrings[] = {"nomain","noems","noxms",nil};\r
\r
CPURegs.x.bx = logical;\r
CPURegs.x.dx = gvar->pm.emm.EMSHandle;\r
CPURegs.h.ah = EMS_MAPPAGE;\r
- __asm\r
- {\r
+ __asm {\r
int EMS_INT\r
}\r
\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
+ XMS_CALL(XMS_QUERYFREE, gvar); // Find out how much XMS is available\r
gvar->pm.xmm.XMSAvail = CPURegs.x.ax;\r
if (!CPURegs.x.ax) // AJR: bugfix 10/8/92\r
goto error;\r
goto error;\r
\r
CPURegs.x.dx = gvar->pm.xmm.XMSAvail;\r
- XMS_CALL(XMS_ALLOC); // And do the allocation\r
+ XMS_CALL(XMS_ALLOC, gvar); // And do the allocation\r
gvar->pm.xmm.XMSHandle = CPURegs.x.dx;\r
\r
if (!CPURegs.x.ax) // AJR: bugfix 10/8/92\r
push si\r
}\r
CPURegs.x.si = (word)©\r
- XMS_CALL(XMS_MOVE);\r
+ XMS_CALL(XMS_MOVE, gvar);\r
__asm {\r
pop si\r
}\r
}\r
\r
#if 1\r
-#define PML_CopyToXMS(s,t,l) PML_XMSCopy(true,(s),(t),(l))\r
-#define PML_CopyFromXMS(t,s,l) PML_XMSCopy(false,(t),(s),(l))\r
+#define PML_CopyToXMS(s,t,l,gvar) PML_XMSCopy(true,(s),(t),(l),(gvar))\r
+#define PML_CopyFromXMS(t,s,l,gvar) PML_XMSCopy(false,(t),(s),(l),(gvar))\r
#else\r
//\r
// PML_CopyToXMS() - Copies the specified number of bytes from the real mode\r
// segment address to the specified XMS page\r
//\r
void\r
-PML_CopyToXMS(byte far *source,int targetpage,word length)\r
+PML_CopyToXMS(byte far *source,int targetpage,word length,global_game_variables_t *gvar)\r
{\r
- PML_XMSCopy(true,source,targetpage,length);\r
+ PML_XMSCopy(true,source,targetpage,length, global_game_variables_t *gvar);\r
}\r
\r
//\r
// page to the specified real mode address\r
//\r
void\r
-PML_CopyFromXMS(byte far *target,int sourcepage,word length)\r
+PML_CopyFromXMS(byte far *target,int sourcepage,word length, global_game_variables_t *gvar)\r
{\r
- PML_XMSCopy(false,target,sourcepage,length);\r
+ PML_XMSCopy(false,target,sourcepage,length, global_game_variables_t *gvar);\r
}\r
#endif\r
\r
if (gvar->pm.xmm.XMSPresent)\r
{\r
CPURegs.x.dx = gvar->pm.xmm.XMSHandle;\r
- XMS_CALL(XMS_FREE);\r
+ XMS_CALL(XMS_FREE, gvar);\r
if (CPURegs.h.bl)\r
{\r
Quit("PML_ShutdownXMS: Error freeing XMS");\r
\r
for (i = 0;i < PMMaxMainMem;i++)\r
if (gvar->pm.mm.MainMemPages[i])\r
- MM_SetPurge(&gvar->pm.mm.MainMemPages[i],level);\r
- return 0;//TODO FIX\r
+ MM_SetPurge(&gvar->pm.mm.MainMemPages[i],level, gvar);\r
}\r
\r
//\r
// program makes allocation requests of the Memory Mgr.\r
//\r
void\r
-PM_CheckMainMem(void)\r
+PM_CheckMainMem(global_game_variables_t *gvar)\r
{\r
boolean allocfailed;\r
int i,n;\r
PMBlockAttr *used;\r
PageListStruct far *page;\r
\r
- if (!MainPresent)\r
+ if (!gvar->pm.mm.MainPresent)\r
return;\r
\r
- for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+ for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
{\r
n = page->mainPage;\r
if (n != -1) // Is the page using main memory?\r
{\r
- if (!MainMemPages[n]) // Yep, was the block purged?\r
+ if (!gvar->pm.mm.MainMemPages[n]) // Yep, was the block purged?\r
{\r
page->mainPage = -1; // Yes, mark page as purged & unlocked\r
page->locked = pml_Unlocked;\r
}\r
\r
// Prevent allocation attempts from purging any of our other blocks\r
- PM_LockMainMem();\r
+ PM_LockMainMem(gvar);\r
allocfailed = false;\r
- for (i = 0,p = MainMemPages,used = MainMemUsed;i < PMMaxMainMem;i++,p++,used++)\r
+ for (i = 0,p = gvar->pm.mm.MainMemPages,used = gvar->pm.mm.MainMemUsed; i < PMMaxMainMem;i++,p++,used++)\r
{\r
if (!*p) // If the page got purged\r
{\r
if (*used & pmba_Allocated) // If it was allocated\r
{\r
*used &= ~pmba_Allocated; // Mark as unallocated\r
- MainPagesAvail--; // and decrease available count\r
+ gvar->pm.mm.MainPagesAvail--; // and decrease available count\r
}\r
\r
if (*used & pmba_Used) // If it was used\r
{\r
*used &= ~pmba_Used; // Mark as unused\r
- MainPagesUsed--; // and decrease used count\r
+ gvar->pm.MainPagesUsed--; // and decrease used count\r
}\r
\r
if (!allocfailed)\r
{\r
- MM_BombOnError(false);\r
- MM_GetPtr(p,PMPageSize); // Try to reallocate\r
- if (mmerror) // If it failed,\r
+ MM_BombOnError(false, gvar);\r
+ MM_GetPtr(p,PMPageSize, gvar); // Try to reallocate\r
+ if (gvar->mm.mmerror) // If it failed,\r
allocfailed = true; // don't try any more allocations\r
else // If it worked,\r
{\r
*used |= pmba_Allocated; // Mark as allocated\r
- MainPagesAvail++; // and increase available count\r
+ gvar->pm.mm.MainPagesAvail++; // and increase available count\r
}\r
- MM_BombOnError(true);\r
+ MM_BombOnError(true, gvar);\r
}\r
}\r
}\r
- if (mmerror)\r
- mmerror = false;\r
+ if (gvar->mm.mmerror)\r
+ gvar->mm.mmerror = false;\r
}\r
\r
//\r
// needs to be called.\r
//\r
void\r
-PML_StartupMainMem(void)\r
+PML_StartupMainMem(global_game_variables_t *gvar)\r
{\r
int i,n;\r
memptr *p;\r
\r
- MainPagesAvail = 0;\r
- MM_BombOnError(false);\r
- for (i = 0,p = MainMemPages;i < PMMaxMainMem;i++,p++)\r
+ gvar->pm.mm.MainPagesAvail = 0;\r
+ MM_BombOnError(false, gvar);\r
+ for (i = 0,p = gvar->pm.mm.MainMemPages;i < PMMaxMainMem;i++,p++)\r
{\r
- MM_GetPtr(p,PMPageSize);\r
- if (mmerror)\r
+ MM_GetPtr(p,PMPageSize, gvar);\r
+ if (gvar->mm.mmerror)\r
break;\r
\r
- MainPagesAvail++;\r
- MainMemUsed[i] = pmba_Allocated;\r
+ gvar->pm.mm.MainPagesAvail++;\r
+ gvar->pm.mm.MainMemUsed[i] = pmba_Allocated;\r
}\r
- MM_BombOnError(true);\r
- if (mmerror)\r
- mmerror = false;\r
- if (MainPagesAvail < PMMinMainMem)\r
+ MM_BombOnError(true, gvar);\r
+ if (gvar->mm.mmerror)\r
+ gvar->mm.mmerror = false;\r
+ if (gvar->pm.mm.MainPagesAvail < PMMinMainMem)\r
{\r
Quit("PM_SetupMainMem: Not enough main memory");\r
//return;\r
}\r
- MainPresent = true;\r
+ gvar->pm.mm.MainPresent = true;\r
}\r
\r
//\r
// Page Mgr.\r
//\r
void\r
-PML_ShutdownMainMem(void)\r
+PML_ShutdownMainMem(global_game_variables_t *gvar)\r
{\r
int i;\r
memptr *p;\r
\r
// DEBUG - mark pages as unallocated & decrease page count as appropriate\r
- for (i = 0,p = MainMemPages;i < PMMaxMainMem;i++,p++)\r
+ for (i = 0,p = gvar->pm.mm.MainMemPages;i < PMMaxMainMem;i++,p++)\r
if (*p)\r
- MM_FreePtr(p);\r
+ MM_FreePtr(p, gvar);\r
}\r
\r
/////////////////////////////////////////////////////////////////////////////\r
// PML_ReadFromFile() - Reads some data in from the page file\r
//\r
void\r
-PML_ReadFromFile(byte far *buf,long offset,word length)\r
+PML_ReadFromFile(byte far *buf,long offset,word length, global_game_variables_t *gvar)\r
{\r
if (!buf)\r
{\r
Quit("PML_ReadFromFile: Zero offset");\r
//return;\r
}\r
- if (lseek(PageFile,offset,SEEK_SET) != offset)\r
+ if (lseek(gvar->pm.fi.PageFile,offset,SEEK_SET) != offset)\r
{\r
Quit("PML_ReadFromFile: Seek failed");\r
//return;\r
}\r
- if (!CA_FarRead(PageFile,buf,length))\r
+ if (!CA_FarRead(gvar->pm.fi.PageFile,buf,length, gvar))\r
+ {\r
Quit("PML_ReadFromFile: Read failed");\r
//return;\r
}\r
// PML_OpenPageFile() - Opens the page file and sets up the page info\r
//\r
void\r
-PML_OpenPageFile(void)\r
+PML_OpenPageFile(global_game_variables_t *gvar)\r
{\r
int i;\r
long size;\r
- __SEGA *buf;\r
+ //__SEGA buf;\r
+ memptr buf;\r
dword far *offsetptr;\r
word far *lengthptr;\r
PageListStruct far *page;\r
\r
- PageFile = open(PageFileName,O_RDONLY + O_BINARY);\r
- if (PageFile == -1)\r
+ gvar->pm.fi.PageFile = open(gvar->pm.fi.PageFileName,O_RDONLY + O_BINARY);\r
+ if (gvar->pm.fi.PageFile == -1)\r
{\r
Quit("PML_OpenPageFile: Unable to open page file");\r
//return;\r
}\r
\r
// Read in header variables\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
+ read(gvar->pm.fi.PageFile,&gvar->pm.fi.ChunksInFile,sizeof(gvar->pm.fi.ChunksInFile));\r
+ read(gvar->pm.fi.PageFile,&gvar->pm.fi.PMSpriteStart,sizeof(gvar->pm.fi.PMSpriteStart));\r
+ read(gvar->pm.fi.PageFile,&gvar->pm.fi.PMSoundStart,sizeof(gvar->pm.fi.PMSoundStart));\r
\r
// Allocate and clear the page list\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
+ gvar->pm.PMNumBlocks = gvar->pm.fi.ChunksInFile;\r
+ MM_GetPtr((memptr *)gvar->pm.PMSegPages, sizeof(PageListStruct) * (gvar->pm.PMNumBlocks), gvar);\r
+ MM_SetLock((memptr *)gvar->pm.PMSegPages,true, gvar);\r
+ gvar->pm.PMPages = (PageListStruct far *)gvar->pm.PMSegPages;\r
+ _fmemset(gvar->pm.PMPages,0,sizeof(PageListStruct) * gvar->pm.PMNumBlocks);\r
\r
// Read in the chunk offsets\r
size = sizeof(dword) * gvar->pm.fi.ChunksInFile;\r
- MM_GetPtr(&buf,size);\r
- if (!CA_FarRead(PageFile,(byte far *)buf,size))\r
+ MM_GetPtr(&buf, size, gvar);\r
+ if (!CA_FarRead(gvar->pm.fi.PageFile,(byte far *)buf,size, gvar))\r
{\r
Quit("PML_OpenPageFile: Offset read failed");\r
//return;\r
}\r
offsetptr = (dword far *)buf;\r
- for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+ for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
page->offset = *offsetptr++;\r
- MM_FreePtr(&buf);\r
+ MM_FreePtr(&buf, gvar);\r
\r
// Read in the chunk lengths\r
size = sizeof(word) * gvar->pm.fi.ChunksInFile;\r
- MM_GetPtr(&buf,size);\r
- if (!CA_FarRead(PageFile,(byte far *)buf,size))\r
+ MM_GetPtr(&buf,size, gvar);\r
+ if (!CA_FarRead(gvar->pm.fi.PageFile,(byte far *)buf,size, gvar))\r
{\r
Quit("PML_OpenPageFile: Length read failed");\r
//return;\r
}\r
lengthptr = (word far *)buf;\r
- for (i = 0,page = PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+ for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
page->length = *lengthptr++;\r
- MM_FreePtr(&buf);\r
+ MM_FreePtr(&buf, gvar);\r
}\r
\r
//\r
// PML_ClosePageFile() - Closes the page file\r
//\r
void\r
-PML_ClosePageFile(void)\r
+PML_ClosePageFile(global_game_variables_t *gvar)\r
{\r
- if (PageFile != -1)\r
- close(PageFile);\r
- if (PMSegPages)\r
+ if (gvar->pm.fi.PageFile != -1)\r
+ close(gvar->pm.fi.PageFile);\r
+ if (gvar->pm.PMSegPages)\r
{\r
- MM_SetLock(&(memptr)PMSegPages,false);\r
- MM_FreePtr(&(__SEGA *)PMSegPages);\r
+ MM_SetLock((memptr)gvar->pm.PMSegPages,false, gvar);\r
+ MM_FreePtr((memptr)gvar->pm.PMSegPages, gvar);\r
}\r
}\r
\r
/////////////////////////////////////////////////////////////////////////////\r
\r
//\r
-// PML_Getgvar->pm.emm.EMSAddress()\r
+// PML_GetEMSAddress()\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
// use the physical page specified by the lock type\r
//\r
-#ifdef __DEBUG__\r
+#ifndef __DEBUG_2__\r
#pragma argsused // DEBUG - remove lock parameter\r
memptr\r
-PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)\r
+PML_GetEMSAddress(int page,PMLockType lock, global_game_variables_t *gvar)\r
{\r
int i,emspage;\r
word emsoff,emsbase,offset;\r
// See if this page is already mapped in\r
for (i = 0;i < EMSFrameCount;i++)\r
{\r
- if (EMSList[i].basegvar->pm.emm.EMSPage == emsbase)\r
+ if (gvar->pm.emm.EMSList[i].baseEMSPage == emsbase)\r
{\r
emspage = i; // Yep - don't do a redundant remapping\r
break;\r
// If page isn't already mapped in, find LRU EMS frame, and use it\r
if (emspage == -1)\r
{\r
- dword last = MAXLONG;\r
+ dword last = LONG_MAX;\r
for (i = 0;i < EMSFrameCount;i++)\r
{\r
- if (EMSList[i].lastHit < last)\r
+ if (gvar->pm.emm.EMSList[i].lastHit < last)\r
{\r
emspage = i;\r
- last = EMSList[i].lastHit;\r
+ last = gvar->pm.emm.EMSList[i].lastHit;\r
}\r
}\r
\r
- EMSList[emspage].basegvar->pm.emm.EMSPage = emsbase;\r
- PML_MapEMS(page / PMEMSSubPage,emspage);\r
+ gvar->pm.emm.EMSList[emspage].baseEMSPage = emsbase;\r
+ PML_MapEMS(page / PMEMSSubPage,emspage, gvar);\r
}\r
\r
if (emspage == -1)\r
- Quit("PML_Getgvar->pm.emm.EMSAddress: EMS find failed");\r
+ Quit("PML_GetEMSAddress: EMS find failed");\r
\r
- EMSList[emspage].lastHit = PMFrameCount;\r
+ gvar->pm.emm.EMSList[emspage].lastHit = gvar->pm.PMFrameCount;\r
offset = emspage * EMSPageSizeSeg;\r
offset += emsoff * PMPageSizeSeg;\r
return((memptr)(gvar->pm.emm.EMSPageFrame + offset));\r
}\r
#else\r
memptr\r
-PML_Getgvar->pm.emm.EMSAddress(int page,PMLockType lock)\r
+PML_GetEMSAddress(int page,PMLockType lock, global_game_variables_t *gvar)\r
{\r
word emspage;\r
\r
\r
PML_MapEMS(page / PMEMSSubPage,emspage);\r
\r
- return((memptr)(gvar->pm.emm.EMSPageFrame + (emspage * EMSPageSizeSeg)\r
+ return((memptr)(EMSPageFrame + (emspage * EMSPageSizeSeg)\r
+ ((page & (PMEMSSubPage - 1)) * PMPageSizeSeg)));\r
}\r
#endif\r
//\r
//\r
memptr\r
-PM_GetPageAddress(int pagenum)\r
+PM_GetPageAddress(int pagenum, global_game_variables_t *gvar)\r
{\r
PageListStruct far *page;\r
\r
- page = &PMPages[pagenum];\r
+ page = &gvar->pm.PMPages[pagenum];\r
if (page->mainPage != -1)\r
- return(MainMemPages[page->mainPage]);\r
+ return(gvar->pm.mm.MainMemPages[page->mainPage]);\r
else if (page->emsPage != -1)\r
- return(PML_Getgvar->pm.emm.EMSAddress(page->emsPage,page->locked));\r
+ return(PML_GetEMSAddress(page->emsPage,page->locked, gvar));\r
else\r
return(nil);\r
}\r
// present & unlocked main/EMS page (or main page if mainonly is true)\r
//\r
int\r
-PML_GiveLRUPage(boolean mainonly)\r
+PML_GiveLRUPage(boolean mainonly, global_game_variables_t *gvar)\r
{\r
int i,lru;\r
long last;\r
PageListStruct far *page;\r
\r
- for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+ for (i = 0,page = gvar->pm.PMPages,lru = -1,last = LONG_MAX;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
{\r
if\r
(\r
}\r
\r
//\r
-// PML_GiveLRUgvar->pm.xmm.XMSPage() - Returns the page # of the least recently used\r
+// PML_GiveLRUXMSPage() - Returns the page # of the least recently used\r
// (and present) XMS page.\r
// This routine won't return the XMS page protected (by gvar->pm.xmm.XMSProtectPage)\r
//\r
int\r
-PML_GiveLRUgvar->pm.xmm.XMSPage(void)\r
+PML_GiveLRUXMSPage(global_game_variables_t *gvar)\r
{\r
int i,lru;\r
long last;\r
PageListStruct far *page;\r
\r
- for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
+ for (i = 0,page = gvar->pm.PMPages,lru = -1,last = LONG_MAX;i < gvar->pm.fi.ChunksInFile;i++,page++)\r
{\r
if\r
(\r
// it with the main/EMS page\r
//\r
void\r
-PML_PutPageInXMS(int pagenum)\r
+PML_PutPageInXMS(int pagenum, global_game_variables_t *gvar)\r
{\r
int usexms;\r
PageListStruct far *page;\r
if (!gvar->pm.xmm.XMSPresent)\r
return;\r
\r
- page = &PMPages[pagenum];\r
+ page = &gvar->pm.PMPages[pagenum];\r
if (page->xmsPage != -1)\r
return; // Already in XMS\r
\r
- if (gvar->pm.xmm.XMSPagesUsed < gvar->pm.xmm.XMSPagesAvail)\r
- page->xmsPage = gvar->pm.xmm.XMSPagesUsed++;\r
+ if (gvar->pm.XMSPagesUsed < gvar->pm.xmm.XMSPagesAvail)\r
+ page->xmsPage = gvar->pm.XMSPagesUsed++;\r
else\r
{\r
- usexms = PML_GiveLRUgvar->pm.xmm.XMSPage();\r
+ usexms = PML_GiveLRUXMSPage(gvar);\r
if (usexms == -1)\r
Quit("PML_PutPageInXMS: No XMS LRU");\r
- page->xmsPage = PMPages[usexms].xmsPage;\r
- PMPages[usexms].xmsPage = -1;\r
+ page->xmsPage = gvar->pm.PMPages[usexms].xmsPage;\r
+ gvar->pm.PMPages[usexms].xmsPage = -1;\r
}\r
- PML_CopyToXMS(PM_GetPageAddress(pagenum),page->xmsPage,page->length);\r
+ PML_CopyToXMS(PM_GetPageAddress(pagenum, gvar),page->xmsPage,page->length, gvar);\r
}\r
\r
//\r
// the old one's address space. Returns the address of the new page.\r
//\r
memptr\r
-PML_TransferPageSpace(int orig,int new)\r
+PML_TransferPageSpace(int orig,int new, global_game_variables_t *gvar)\r
{\r
memptr addr;\r
PageListStruct far *origpage,far *newpage;\r
if (orig == new)\r
Quit("PML_TransferPageSpace: Identity replacement");\r
\r
- origpage = &PMPages[orig];\r
- newpage = &PMPages[new];\r
+ origpage = &gvar->pm.PMPages[orig];\r
+ newpage = &gvar->pm.PMPages[new];\r
\r
if (origpage->locked != pml_Unlocked)\r
Quit("PML_TransferPageSpace: Killing locked page");\r
Quit("PML_TransferPageSpace: Reusing non-existent page");\r
\r
// Copy page that's about to be purged into XMS\r
- PML_PutPageInXMS(orig);\r
+ PML_PutPageInXMS(orig, gvar);\r
\r
// Get the address, and force EMS into a physical page if necessary\r
- addr = PM_GetPageAddress(orig);\r
+ addr = PM_GetPageAddress(orig, gvar);\r
\r
// Steal the address\r
newpage->emsPage = origpage->emsPage;\r
// will be looked at by PML_GiveLRUPage().\r
//\r
byte far *\r
-PML_GetAPageBuffer(int pagenum,boolean mainonly)\r
+PML_GetAPageBuffer(int pagenum,boolean mainonly, global_game_variables_t *gvar)\r
{\r
byte far *addr = nil;\r
int i,n;\r
PMBlockAttr *used;\r
PageListStruct far *page;\r
\r
- page = &PMPages[pagenum];\r
- if ((gvar->pm.emm.EMSPagesUsed < gvar->pm.emm.EMSPagesAvail) && !mainonly)\r
+ page = &gvar->pm.PMPages[pagenum];\r
+ if ((gvar->pm.EMSPagesUsed < gvar->pm.emm.EMSPagesAvail) && !mainonly)\r
{\r
// There's remaining EMS - use it\r
- page->emsPage = gvar->pm.emm.EMSPagesUsed++;\r
- addr = PML_Getgvar->pm.emm.EMSAddress(page->emsPage,page->locked);\r
+ page->emsPage = gvar->pm.EMSPagesUsed++;\r
+ addr = PML_GetEMSAddress(page->emsPage,page->locked, gvar);\r
}\r
- else if (MainPagesUsed < MainPagesAvail)\r
+ else if (gvar->pm.MainPagesUsed < gvar->pm.mm.MainPagesAvail)\r
{\r
// There's remaining main memory - use it\r
- for (i = 0,n = -1,used = MainMemUsed;i < PMMaxMainMem;i++,used++)\r
+ for (i = 0,n = -1,used = gvar->pm.mm.MainMemUsed;i < PMMaxMainMem;i++,used++)\r
{\r
if ((*used & pmba_Allocated) && !(*used & pmba_Used))\r
{\r
}\r
if (n == -1)\r
Quit("PML_GetPageBuffer: MainPagesAvail lied");\r
- addr = MainMemPages[n];\r
+ addr = gvar->pm.mm.MainMemPages[n];\r
if (!addr)\r
Quit("PML_GetPageBuffer: Purged main block");\r
page->mainPage = n;\r
- MainPagesUsed++;\r
+ gvar->pm.MainPagesUsed++;\r
}\r
else\r
- addr = PML_TransferPageSpace(PML_GiveLRUPage(mainonly),pagenum);\r
+ addr = PML_TransferPageSpace(PML_GiveLRUPage(mainonly, gvar),pagenum, gvar);\r
\r
if (!addr)\r
Quit("PML_GetPageBuffer: Search failed");\r
// 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
-// gvar->pm.xmm.XMSProtectPage is set to the page to be retrieved from XMS, so that if\r
+// 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
//\r
memptr\r
-PML_GetPageFromXMS(int pagenum,boolean mainonly)\r
+PML_GetPageFromXMS(int pagenum,boolean mainonly, global_game_variables_t *gvar)\r
{\r
byte far *checkaddr;\r
memptr addr = nil;\r
PageListStruct far *page;\r
\r
- page = &PMPages[pagenum];\r
+ page = &gvar->pm.PMPages[pagenum];\r
if (gvar->pm.xmm.XMSPresent && (page->xmsPage != -1))\r
{\r
gvar->pm.xmm.XMSProtectPage = pagenum;\r
- checkaddr = PML_GetAPageBuffer(pagenum,mainonly);\r
+ checkaddr = PML_GetAPageBuffer(pagenum,mainonly, gvar);\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
+ PML_CopyFromXMS(addr,page->xmsPage,page->length, gvar);\r
gvar->pm.xmm.XMSProtectPage = -1;\r
}\r
\r
// only be loaded into main.\r
//\r
void\r
-PML_LoadPage(int pagenum,boolean mainonly)\r
+PML_LoadPage(int pagenum,boolean mainonly, global_game_variables_t *gvar)\r
{\r
byte far *addr;\r
PageListStruct far *page;\r
\r
- addr = PML_GetAPageBuffer(pagenum,mainonly);\r
- page = &PMPages[pagenum];\r
- PML_ReadFromFile(addr,page->offset,page->length);\r
+ addr = PML_GetAPageBuffer(pagenum,mainonly, gvar);\r
+ page = &gvar->pm.PMPages[pagenum];\r
+ PML_ReadFromFile(addr,page->offset,page->length, gvar);\r
}\r
\r
//\r
//\r
#pragma warn -pia\r
memptr\r
-PM_GetPage(int pagenum)\r
+PM_GetPage(int pagenum, global_game_variables_t *gvar)\r
{\r
memptr result;\r
\r
if (pagenum >= gvar->pm.fi.ChunksInFile)\r
Quit("PM_GetPage: Invalid page request");\r
\r
-#if __DEBUG__ // for debugging\r
+#ifdef __DEBUG_2__ // for debugging\r
__asm {\r
mov dx,STATUS_REGISTER_1\r
in al,dx\r
}\r
#endif\r
\r
- if (!(result = PM_GetPageAddress(pagenum)))\r
+ if (!(result = PM_GetPageAddress(pagenum, gvar)))\r
{\r
- boolean mainonly = (pagenum >= PMSoundStart);\r
-if (!PMPages[pagenum].offset) // JDC: sparse page\r
+ boolean mainonly = (pagenum >= gvar->pm.fi.PMSoundStart);\r
+if (!gvar->pm.PMPages[pagenum].offset) // JDC: sparse page\r
Quit ("Tried to load a sparse page!");\r
- if (!(result = PML_GetPageFromXMS(pagenum,mainonly)))\r
+ if (!(result = PML_GetPageFromXMS(pagenum,mainonly, gvar)))\r
{\r
- if (PMPages[pagenum].lastHit == PMFrameCount)\r
- PMThrashing++;\r
+ if (gvar->pm.PMPages[pagenum].lastHit == gvar->pm.PMFrameCount)\r
+ gvar->pm.PMThrashing++;\r
\r
- PML_LoadPage(pagenum,mainonly);\r
- result = PM_GetPageAddress(pagenum);\r
+ PML_LoadPage(pagenum,mainonly, gvar);\r
+ result = PM_GetPageAddress(pagenum, gvar);\r
}\r
}\r
- PMPages[pagenum].lastHit = PMFrameCount;\r
+ gvar->pm.PMPages[pagenum].lastHit = gvar->pm.PMFrameCount;\r
\r
-#if __DEBUG__ // for debugging\r
+#ifdef __DEBUG_2__ // for debugging\r
__asm{\r
mov dx,STATUS_REGISTER_1\r
in al,dx\r
// specified when returning the address. For sound stuff.\r
//\r
void\r
-PM_SetPageLock(int pagenum,PMLockType lock)\r
+PM_SetPageLock(int pagenum,PMLockType lock, global_game_variables_t *gvar)\r
{\r
- if (pagenum < PMSoundStart)\r
+ if (pagenum < gvar->pm.fi.PMSoundStart)\r
Quit("PM_SetPageLock: Locking/unlocking non-sound page");\r
\r
- PMPages[pagenum].locked = lock;\r
+ gvar->pm.PMPages[pagenum].locked = lock;\r
}\r
\r
//\r
// page, and the total pages that need to be loaded (for thermometer).\r
//\r
void\r
-PM_Preload(boolean (*update)(word current,word total))\r
+PM_Preload(boolean (*update)(word current,word total), global_game_variables_t *gvar)\r
{\r
int i,j,\r
page,oogypage;\r
memptr addr;\r
PageListStruct far *p;\r
\r
- mainfree = (MainPagesAvail - MainPagesUsed) + (gvar->pm.emm.EMSPagesAvail - gvar->pm.emm.EMSPagesUsed);\r
- xmsfree = (gvar->pm.xmm.XMSPagesAvail - gvar->pm.xmm.XMSPagesUsed);\r
+ mainfree = (gvar->pm.mm.MainPagesAvail - gvar->pm.MainPagesUsed) + (gvar->pm.emm.EMSPagesAvail - gvar->pm.EMSPagesUsed);\r
+ xmsfree = (gvar->pm.xmm.XMSPagesAvail - gvar->pm.XMSPagesUsed);\r
\r
xmstotal = maintotal = 0;\r
\r
for (i = 0;i < gvar->pm.fi.ChunksInFile;i++)\r
{\r
- if (!PMPages[i].offset)\r
+ if (!gvar->pm.PMPages[i].offset)\r
continue; // sparse\r
\r
- if ( PMPages[i].emsPage != -1 || PMPages[i].mainPage != -1 )\r
+ if ( gvar->pm.PMPages[i].emsPage != -1 || gvar->pm.PMPages[i].mainPage != -1 )\r
continue; // already in main mem\r
\r
if ( mainfree )\r
maintotal++;\r
mainfree--;\r
}\r
- else if ( xmsfree && (PMPages[i].xmsPage == -1) )\r
+ else if ( xmsfree && (gvar->pm.PMPages[i].xmsPage == -1) )\r
{\r
xmstotal++;\r
xmsfree--;\r
//\r
while (maintotal)\r
{\r
- while ( !PMPages[page].offset || PMPages[page].mainPage != -1\r
- || PMPages[page].emsPage != -1 )\r
+ while ( !gvar->pm.PMPages[page].offset || gvar->pm.PMPages[page].mainPage != -1\r
+ || gvar->pm.PMPages[page].emsPage != -1 )\r
page++;\r
\r
if (page >= gvar->pm.fi.ChunksInFile)\r
Quit ("PM_Preload: Pages>=gvar->pm.fi.ChunksInFile");\r
\r
- PM_GetPage(page);\r
+ PM_GetPage(page, gvar);\r
\r
page++;\r
current++;\r
//\r
if (xmstotal)\r
{\r
- for (oogypage = 0 ; PMPages[oogypage].mainPage == -1 ; oogypage++)\r
+ for (oogypage = 0 ; gvar->pm.PMPages[oogypage].mainPage == -1 ; oogypage++)\r
;\r
- addr = PM_GetPage(oogypage);\r
+ addr = PM_GetPage(oogypage, gvar);\r
if (!addr)\r
Quit("PM_Preload: XMS buffer failed");\r
\r
while (xmstotal)\r
{\r
- while ( !PMPages[page].offset || PMPages[page].xmsPage != -1 )\r
+ while ( !gvar->pm.PMPages[page].offset || gvar->pm.PMPages[page].xmsPage != -1 )\r
page++;\r
\r
if (page >= gvar->pm.fi.ChunksInFile)\r
Quit ("PM_Preload: Pages>=gvar->pm.fi.ChunksInFile");\r
\r
- p = &PMPages[page];\r
+ p = &gvar->pm.PMPages[page];\r
\r
- p->xmsPage = gvar->pm.xmm.XMSPagesUsed++;\r
- if (gvar->pm.xmm.XMSPagesUsed > gvar->pm.xmm.XMSPagesAvail)\r
+ p->xmsPage = gvar->pm.XMSPagesUsed++;\r
+ if (gvar->pm.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
\r
- PML_ReadFromFile((byte far *)addr,p->offset,p->length);\r
- PML_CopyToXMS((byte far *)addr,p->xmsPage,p->length);\r
+ PML_ReadFromFile((byte far *)addr,p->offset,p->length, gvar);\r
+ PML_CopyToXMS((byte far *)addr,p->xmsPage,p->length, gvar);\r
\r
page++;\r
current++;\r
update(current,total);\r
}\r
\r
- p = &PMPages[oogypage];\r
- PML_ReadFromFile((byte far *)addr,p->offset,p->length);\r
+ p = &gvar->pm.PMPages[oogypage];\r
+ PML_ReadFromFile((byte far *)addr,p->offset,p->length, gvar);\r
}\r
\r
update(total,total);\r
//\r
//\r
void\r
-PM_NextFrame(void)\r
+PM_NextFrame(global_game_variables_t *gvar)\r
{\r
int i;\r
\r
// Frame count overrun - kill the LRU hit entries & reset frame count\r
- if (++PMFrameCount >= MAXLONG - 4)\r
+ if (++gvar->pm.PMFrameCount >= LONG_MAX - 4)\r
{\r
- for (i = 0;i < PMNumBlocks;i++)\r
- PMPages[i].lastHit = 0;\r
- PMFrameCount = 0;\r
+ for (i = 0;i < gvar->pm.PMNumBlocks;i++)\r
+ gvar->pm.PMPages[i].lastHit = 0;\r
+ gvar->pm.PMFrameCount = 0;\r
}\r
\r
-#if 0\r
- for (i = 0;i < PMSoundStart;i++)\r
+//#if 0\r
+ for (i = 0;i < gvar->pm.fi.PMSoundStart;i++)\r
{\r
- if (PMPages[i].locked)\r
+ if (gvar->pm.PMPages[i].locked)\r
{\r
char buf[40];\r
sprintf(buf,"PM_NextFrame: Page %d is locked",i);\r
Quit(buf);\r
}\r
}\r
-#endif\r
+//#endif\r
\r
- if (PMPanicMode)\r
+ if (gvar->pm.PMPanicMode)\r
{\r
// DEBUG - set border color\r
- if ((!PMThrashing) && (!--PMPanicMode))\r
+ if ((!gvar->pm.PMThrashing) && (!--gvar->pm.PMPanicMode))\r
{\r
// DEBUG - reset border color\r
}\r
}\r
- if (PMThrashing >= PMThrashThreshold)\r
- PMPanicMode = PMUnThrashThreshold;\r
- PMThrashing = false;\r
+ if (gvar->pm.PMThrashing >= PMThrashThreshold)\r
+ gvar->pm.PMPanicMode = PMUnThrashThreshold;\r
+ gvar->pm.PMThrashing = false;\r
}\r
\r
//\r
// PM_Reset() - Sets up caching structures\r
//\r
void\r
-PM_Reset(void)\r
+PM_Reset(global_game_variables_t *gvar)\r
{\r
int i;\r
PageListStruct far *page;\r
gvar->pm.emm.EMSPagesAvail = gvar->pm.emm.EMSAvail * (EMSPageSizeKB / PMPageSizeKB);\r
gvar->pm.emm.EMSPhysicalPage = 0;\r
\r
- MainPagesUsed = gvar->pm.emm.EMSPagesUsed = gvar->pm.xmm.XMSPagesUsed = 0;\r
+ gvar->pm.MainPagesUsed = gvar->pm.EMSPagesUsed = gvar->pm.XMSPagesUsed = 0;\r
\r
- PMPanicMode = false;\r
+ gvar->pm.PMPanicMode = false;\r
\r
// Initialize page list\r
- for (i = 0,page = PMPages;i < PMNumBlocks;i++,page++)\r
+ for (i = 0,page = gvar->pm.PMPages;i < gvar->pm.PMNumBlocks;i++,page++)\r
{\r
page->mainPage = -1;\r
page->emsPage = -1;\r
// PM_Startup() - Start up the Page Mgr\r
//\r
void\r
-PM_Startup(void)\r
+PM_Startup(global_game_variables_t *gvar)\r
{\r
boolean nomain,noems,noxms;\r
int i;\r
\r
- if (PMStarted)\r
+ if (gvar->pm.PMStarted)\r
return;\r
\r
+ strcat(&(gvar->pm.fi.PageFileName), "VSWAP.");\r
+ gvar->pm.fi.PageFile = -1;\r
+ gvar->pm.xmm.XMSProtectPage = -1;\r
+\r
nomain = noems = noxms = false;\r
- for (i = 1;i < _argc;i++)\r
+ for (i = 1;i <\r
+#ifdef __WATCOMC__\r
+ __argc\r
+#endif\r
+#ifdef __BORLANDC__\r
+ _argc\r
+#endif\r
+ ;i++)\r
{\r
- switch (US_CheckParm(_argv[i],ParmStrings))\r
+ switch (US_CheckParm(\r
+#ifdef __WATCOMC__\r
+ __argv[i]\r
+#endif\r
+#ifdef __BORLANDC__\r
+ _argv[i]\r
+#endif\r
+ ,ParmStrings))\r
{\r
case 0:\r
nomain = true;\r
}\r
}\r
\r
- PML_OpenPageFile();\r
+ PML_OpenPageFile(gvar);\r
\r
if (!noems)\r
- PML_StartupEMS();\r
+ PML_StartupEMS(gvar);\r
if (!noxms)\r
- PML_StartupXMS();\r
+ PML_StartupXMS(gvar);\r
\r
if (nomain && !gvar->pm.emm.EMSPresent)\r
{\r
//return;\r
}\r
else\r
- PML_StartupMainMem();\r
+ PML_StartupMainMem(gvar);\r
\r
- PM_Reset();\r
+ PM_Reset(gvar);\r
\r
- PMStarted = true;\r
+ gvar->pm.PMStarted = true;\r
}\r
\r
//\r
// PM_Shutdown() - Shut down the Page Mgr\r
//\r
void\r
-PM_Shutdown(void)\r
+PM_Shutdown(global_game_variables_t *gvar)\r
{\r
- PML_ShutdownXMS();\r
- PML_ShutdownEMS();\r
+ PML_ShutdownXMS(gvar);\r
+ PML_ShutdownEMS(gvar);\r
\r
- if (!PMStarted)\r
+ if (!gvar->pm.PMStarted)\r
return;\r
\r
- PML_ClosePageFile();\r
+ PML_ClosePageFile(gvar);\r
\r
- PML_ShutdownMainMem();\r
+ PML_ShutdownMainMem(gvar);\r
}\r
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ *\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 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\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\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
+#ifndef __16_PM__\r
+#define __16_PM__\r
+\r
//\r
// ID_PM.H\r
// Header file for Id Engine's Page Manager\r
#define PM_GetSoundPage(v) PM_GetPage(PMSoundStart + (v))\r
#define PM_GetSpritePage(v) PM_GetPage(PMSpriteStart + (v))\r
\r
-#define PM_LockMainMem() PM_SetMainMemPurge(0)\r
-#define PM_UnlockMainMem() PM_SetMainMemPurge(3)\r
+#define PM_LockMainMem(gvar) PM_SetMainMemPurge(0, gvar)\r
+#define PM_UnlockMainMem(gvar) PM_SetMainMemPurge(3, gvar)\r
\r
\r
extern char PageFileName[13];\r
\r
\r
-extern void PM_Startup(void),\r
- PM_Shutdown(void),\r
- PM_Reset(void),\r
- PM_Preload(boolean (*update)(word current,word total)),\r
- PM_NextFrame(void),\r
- PM_SetPageLock(int pagenum,PMLockType lock),\r
+extern void PM_Startup(global_game_variables_t *gvar),\r
+ PM_Shutdown(global_game_variables_t *gvar),\r
+ PM_Reset(global_game_variables_t *gvar),\r
+ PM_Preload(boolean (*update)(word current,word total), global_game_variables_t *gvar),\r
+ PM_NextFrame(global_game_variables_t *gvar),\r
+ PM_SetPageLock(int pagenum,PMLockType lock, global_game_variables_t *gvar),\r
PM_SetMainPurge(int level),\r
- PM_CheckMainMem(void);\r
-extern memptr PM_GetPageAddress(int pagenum),\r
- PM_GetPage(int pagenum); // Use this one to cache page\r
+ PM_CheckMainMem(global_game_variables_t *gvar);\r
+extern memptr PM_GetPageAddress(int pagenum, global_game_variables_t *gvar),\r
+ PM_GetPage(int pagenum, global_game_variables_t *gvar); // Use this one to cache page\r
\r
-PM_SetMainMemPurge(int level, global_game_variables_t *gvar);\r
+void PM_SetMainMemPurge(int level, global_game_variables_t *gvar);\r
+#endif\r
void __near *nearheap;\r
#endif\r
//byte EMS_status;\r
- unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;\r
- unsigned int EMSVer;\r
+ unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;//TODO: PM use\r
+ //unsigned int EMSVer;\r
word numUMBs,UMBbase[MAXUMBS];\r
//dword numUMBs,UMBbase[MAXUMBS];\r
//huge mmblocktype huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;\r
{\r
boolean EMSPresent;\r
word EMSAvail,EMSPagesAvail,EMSHandle,\r
- EMSPageFrame,EMSPhysicalPage;\r
+ EMSPageFrame,EMSPhysicalPage, EMSVer;\r
EMSListStruct EMSList[EMSFrameCount];\r
} pm_emmi_t;\r
\r
{\r
boolean XMSPresent;\r
word XMSAvail,XMSPagesAvail,XMSHandle;\r
- word XMSDriver; //TODO: changed to word\r
+ dword XMSDriver; //TODO: changed to word\r
int XMSProtectPage;// = -1;\r
} pm_xmmi_t;\r
\r
//gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);
gvar.mm.mmstarted=0;
- MM_Startup(&gvar.mm, &gvar.mmi);
+ MM_Startup(&gvar);
CA_Startup(&gvar);
// What should be done by read_vrs:
//sega = (mm.bufferseg);
}
VGAmodeX(0, 1, &gvar);
MM_ShowMemory(&gvar);
- MM_DumpData(&gvar.mm);
+ MM_DumpData(&gvar);
free(spri.sprite_vrl_cont);
- MM_FreePtr(&bigbuffer, &gvar.mm);
+ MM_FreePtr(&bigbuffer, &gvar);
//MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
CA_Shutdown(&gvar);
- MM_Shutdown(&gvar.mm);
+ MM_Shutdown(&gvar);
//printf("CPU to VGA: %f\n", t1);
//printf("VGA to VGA: %f\n", t2);
heapdump(&gvar);