-/* Catacomb Armageddon Source Code
+/* Catacomb Apocalypse Source Code
* Copyright (C) 1993-2014 Flat Rock Software
*
* This program is free software; you can redistribute it and/or modify
=============================================================================
*/
-
-#include "src/lib/16_mm.h"
-
/*
-=============================================================================
- LOCAL INFO
+Open Watcom port by sparky4
-=============================================================================
*/
-
-#define LOCKBIT 0x80 // if set in attributes, block cannot be moved
-#define PURGEBITS 3 // 0-3 level, 0= unpurgable, 3= purge first
-#define PURGEMASK 0xfffc
-#define BASEATTRIBUTES 0 // unlocked, non purgable
-
-#define MAXUMBS 10
-
-typedef struct mmblockstruct
-{
- unsigned start,length;
- unsigned attributes;
- memptr *useptr; // pointer to the segment start
- struct mmblockstruct far *next;
-} mmblocktype;
-
-
-//#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!");mmfree=mmfree->next;}
-#define GETNEWBLOCK {if(!mmfree)MML_ClearBlock();mmnew=mmfree;mmfree=mmfree->next;}
-#define FREEBLOCK(x) {*x->useptr=NULL;x->next=mmfree;mmfree=x;}
+#include "src/lib/16_mm.h"
/*
=============================================================================
=============================================================================
*/
-mminfotype mminfo;
-memptr bufferseg;
-boolean mmerror;
-
void (* beforesort) (void);
void (* aftersort) (void);
+void (* XMSaddr) (void); // far pointer to XMS driver
/*
=============================================================================
=============================================================================
*/
-boolean mmstarted;
-
-void huge *hugeheap;
-void far *farheap;
-void *nearheap;
-
-mmblocktype far mmblocks[MAXBLOCKS]
- ,far *mmhead,far *mmfree,far *mmrover,far *mmnew;
-
-boolean bombonerror;
-
-unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
-
-void (* XMSaddr) (void); // far pointer to XMS driver
-
-unsigned numUMBs,UMBbase[MAXUMBS];
-
+static char *ParmStringsexmm[] = {"noems","noxms",""};
/*
======================
=======================
*/
-boolean MML_CheckForEMS (void)
+boolean MML_CheckForEMS(void)
{
boolean emmcfems;
- char emmname[] = "EMMXXXX0";
+ static char emmname[] = "EMMXXXX0"; //fix by andrius4669
// mov dx,OFFSET emmname
__asm {
- LEA DX, emmname //fix by andrius4669
+ //LEA DX, emmname //fix by andrius4669
+ mov dx,OFFSET emmname //fix by andrius4669
mov ax,0x3d00
int 0x21 // try to open EMMXXXX0 device
jc error
=======================
*/
-void MML_SetupEMS (void)
+unsigned MML_SetupEMS(mminfo_t *mm)
{
char str[80],str2[10];
unsigned err;
boolean errorflag=false;
union REGS CPURegs;
+ unsigned int EMSVer = 0;
+ unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
totalEMSpages = freeEMSpages = EMSpageframe = EMSpagesmapped = 0;
__asm
int EMS_INT
or ah,ah
jnz error
+ mov [EMSVer],ax // set EMSVer
cmp al,0x32 // only work on ems 3.2 or greater
jb error
mov [freeEMSpages],bx
or bx,bx
jz noEMS // no EMS at all to allocate
-
+ //EXPAND DONG!!!!
+ cmp [EMSVer],0x40
+ jb low
+ cmp bx,[freeEMSpages]
+ jle getpages
+ mov bx,[freeEMSpages]
+ jmp getpages
+
+low:
cmp bx,4
jle getpages // there is only 1,2,3,or 4 pages
mov bx,4 // we can't use more than 4 pages
itoa(err,str2,16);
strcpy(str,str2);
printf("%s\n",str);
+ return err;
}
+ mm->totalEMSpages=totalEMSpages;
+ mm->freeEMSpages=freeEMSpages;
+ mm->EMSpageframe=EMSpageframe;
+ mm->EMSpagesmapped=EMSpagesmapped;
+ mm->EMShandle=EMShandle;
+ mm->EMSVer=EMSVer;
+ return 0;
}
=======================
*/
-void MML_ShutdownEMS (void)
+void MML_ShutdownEMS(mminfo_t *mm)
{
boolean errorflag=false;
- if (!EMShandle)
+ unsigned EMShandle=mm->EMShandle;
+
+ if(!EMShandle)
return;
__asm
{
====================
*/
-void MM_MapEMS (void)
+unsigned MM_MapEMS(mminfo_t *mm)
{
char str[80],str2[10];
- unsigned err;
+ unsigned err, EMShandle;
boolean errorflag=false;
int i;
union REGS CPURegs;
+ EMShandle=mm->EMShandle;
- for (i=0;i<EMSpagesmapped;i++)
+ for (i=0;i<4/*mm->EMSpagesmapped*/;i++)
{
__asm
{
strcpy(str,"MM_MapEMS: EMS error 0x");
itoa(err,str2,16);
strcpy(str,str2);
- printf("%s\n",str);
+ //printf("%s\n",str);
+ printf("FACK! %u\n", err);
+ return err;
}
}
- return;
+ return 0;
+}
+
+/*
+SUB EMS.MapXPages (PhysicalStart, LogicalStart, NumPages, Handle)\r
+\r
+ 'Maps up to 4 logical EMS pages to physical pages in the page frame, where:\r
+ '\r
+ 'PhysicalStart = Physical page first logical page is mapped to\r
+ 'LogicalStart = First logical page to map\r
+ 'NumPages = Number of pages to map (1 to 4)\r
+ 'Handle = EMS handle logical pages are allocated to\r
+\r
+ 'Create a buffer containing the page information\r
+ FOR x = 0 TO NumPages - 1\r
+ MapInfo$ = MapInfo$ + MKI$(LogicalStart + x) + MKI$(PhysicalStart + x)\r
+ NEXT\r
+\r
+ Regs.ax = &H5000 'Map the pages in the buffer\r
+ Regs.cx = NumPages 'to the pageframe\r
+ Regs.dx = Handle\r
+ Regs.ds = VARSEG(MapInfo$)\r
+ Regs.si = SADD(MapInfo$)\r
+ InterruptX &H67, Regs, Regs\r
+ EMS.Error = (Regs.ax AND &HFF00&) \ &H100 'Store the status code\r
+\r
+END SUB
+*/
+void MM_MapXEMS(mminfo_t *mm)
+{
+
}
//==========================================================================
=======================
*/
-boolean MML_CheckForXMS (void)
+boolean MML_CheckForXMS(mminfo_t *mm)
{
boolean errorflag=false;
- numUMBs = 0;
+ mm->numUMBs = 0;
__asm
{
=======================
*/
-void MML_SetupXMS (void)
+void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi)
{
unsigned base,size;
+getmemory:
__asm
{
mov ax,0x4310
int 0x2f
mov [WORD PTR XMSaddr],bx
mov [WORD PTR XMSaddr+2],es // function pointer to XMS driver
- }
-getmemory:
- __asm
- {
+
mov ah,XMS_ALLOCUMB
mov dx,0xffff // try for largest block possible
+ //mov ax,dx // Set available Kbytes.
call [DWORD PTR XMSaddr]
or ax,ax
jnz gotone
mov [size],dx
done:
}
- MML_UseSpace (base,size);
- mminfo.XMSmem += size*16;
- UMBbase[numUMBs] = base;
- numUMBs++;
- if (numUMBs < MAXUMBS)
+ 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)
goto getmemory;
}
======================
*/
-void MML_ShutdownXMS (void)
+void MML_ShutdownXMS(mminfo_t *mm)
{
int i;
unsigned base;
- for (i=0;i<numUMBs;i++)
+ for (i=0;i<mm->numUMBs;i++)
{
- base = UMBbase[i];
+ base = mm->UMBbase[i];
__asm
{
mov ah,XMS_FREEUMB
======================
*/
-void MML_UseSpace (unsigned segstart, unsigned seglength)
+void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm)
{
- mmblocktype far *scan,far *last;
- unsigned oldend;
- long extra;
+ mmblocktype huge *scan,huge *last;
+ word segm;
+ dword oldend;
+ dword extra;
- scan = last = mmhead;
- mmrover = mmhead; // reset rover to start of memory
+ scan = last = mm->mmhead;
+ mm->mmrover = mm->mmhead; // reset rover to start of memory
//
// search for the block that contains the range of segments
//
- while (scan->start+scan->length < segstart)
+ while(scan->start+scan->length < segstart)
{
last = scan;
scan = scan->next;
}
+ //find out how many blocks it spans!
+ if(seglength>0xffffu)
+ {
+// segm=seglength/0x4000u;
+ segm=seglength/0xffffu;
+ }
+ else segm=1;
+
+ //++++emsver stuff!
+ if(segm>1/*extra>0xfffflu*/)
+ {
+ /*__asm
+ {
+ push ds
+ mov ax,ds
+ inc ax
+ mov ds,ax
+ }*/
+
+
+//MML_UseSpace(?segstart?, ?length?, mm);
+
+ /*__asm
+ {
+ pop ds
+ }*/
+ //printf("MML_UseSpace: Segment spans two blocks!\n");
+ }
+
//
// take the given range out of the block
//
oldend = scan->start + scan->length;
extra = oldend - (segstart+seglength);
- if (extra < 0)
- {
- printf("MML_UseSpace: Segment spans two blocks!");
- return;
- }
-
- if (segstart == scan->start)
+printf("segm=%u ", segm);
+printf("ex=%lu ", extra);
+printf("start+seglen=%lu ", segstart+seglength);
+printf("len=%u ", scan->length);
+printf("segsta=%x ", segstart);
+printf("seglen=%lu\n", seglength);
+
+//segu:
+//++++todo: linked list of segment!
+//printf("segm=%lu\n", segm);
+ if(segstart == scan->start)
{
last->next = scan->next; // unlink block
- FREEBLOCK(scan);
+ MM_FreeBlock(scan, mm);
scan = last;
}
else
scan->length = segstart-scan->start; // shorten block
- if (extra > 0)
+// segm--;
+
+ if(extra > 0)
{
- GETNEWBLOCK;
- mmnew->next = scan->next;
- scan->next = mmnew;
- mmnew->start = segstart+seglength;
- mmnew->length = extra;
- mmnew->attributes = LOCKBIT;
- }
+ MM_GetNewBlock(mm);
+ mm->mmnew->next = scan->next;
+ scan->next = mm->mmnew;
+ mm->mmnew->start = segstart+seglength;
+ mm->mmnew->length = extra;
+ mm->mmnew->attributes = LOCKBIT;
+ }//else if(segm>0) goto segu;
}
====================
*/
-void MML_ClearBlock (void)
+void MML_ClearBlock(mminfo_t *mm)
{
- mmblocktype far *scan,far *last;
+ mmblocktype huge *scan,huge *last;
- scan = mmhead->next;
+ scan = mm->mmhead->next;
- while (scan)
+ while(scan)
{
- if (!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS) )
+ if(!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS))
{
- MM_FreePtr(scan->useptr);
+ MM_FreePtr(scan->useptr, mm);
return;
}
scan = scan->next;
}
- printf("MM_ClearBlock: No purgable blocks!");
+ printf("MM_ClearBlock: No purgable blocks!\n");
}
===================
*/
-static char *ParmStringsexmm[] = {"noems","noxms",""};
-
-void MM_Startup (void)
+void MM_Startup(mminfo_t *mm, mminfotype *mmi)
{
int i;
dword length;
- void far *start;
- unsigned segstart,seglength,endfree;
+ void huge *start;
+ unsigned segstart,seglength,endfree;
- if (mmstarted)
- MM_Shutdown ();
+ if(mm->mmstarted)
+ MM_Shutdown(mm);
-
- mmstarted = true;
- bombonerror = true;
+ mm->mmstarted = true;
+ mm->bombonerror = true;
//
// set up the linked list (everything in the free list;
//
- mmhead = NULL;
- mmfree = &mmblocks[0];
- for (i=0;i<MAXBLOCKS-1;i++)
- mmblocks[i].next = &mmblocks[i+1];
- mmblocks[i].next = NULL;
+ mm->mmhead = NULL;
+ mm->mmfree = &(mm->mmblocks[0]);
+ for(i=0;i<MAXBLOCKS-1;i++)
+ {
+ mm->mmblocks[i].next = &(mm->mmblocks[i+1]);
+ }
+ mm->mmblocks[i].next = NULL;
//
// locked block of all memory until we punch out free space
//
- GETNEWBLOCK;
- mmhead = mmnew; // this will allways be the first node
- mmnew->start = 0;
- mmnew->length = 0xffff;
- mmnew->attributes = LOCKBIT;
- mmnew->next = NULL;
- mmrover = mmhead;
+ MM_GetNewBlock(mm);
+ 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->mmrover = mm->mmhead;
+// farlen=_bios_memsize()*1024;
//
// get all available near conventional memory segments
//
//---- length=coreleft();
+ _nheapgrow();
length=_memavl();
- start = (void far *)(nearheap = malloc(length));
-
+ start = (void huge *)(mm->nearheap = malloc(length));
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);
- mminfo.nearheap = length;
+ MML_UseSpace(segstart,seglength, mm);
+ mmi->nearheap = length;
+ //printf("near heap ok!\n");
//
// get all available far conventional memory segments
//
//---- length=farcoreleft();
- length=_memmax();
- start = farheap = _fmalloc(length);
+ _fheapgrow();
+ length=_memavl();
+ start = mm->farheap = halloc(length, sizeof(byte));
+ //start = mm->farheap = _fmalloc(length);
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);
- mminfo.farheap = length;
- mminfo.mainmem = mminfo.nearheap + mminfo.farheap;
+ MML_UseSpace(segstart,seglength, mm);
+ mmi->farheap = length;
+ mmi->mainmem = mmi->nearheap + mmi->farheap;
+ //printf("far heap ok!\n");
//
// detect EMS and allocate up to 64K at page frame
//
- mminfo.EMSmem = 0;
- for (i = 1;i < __argc;i++)
+ printf("EMS!\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); //bug!
+ mmi->EMSmem = 0;
+ for(i = 1;i < __argc;i++)
{
- if ( US_CheckParm(__argv[i],ParmStringsexmm) == 0)
+ if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
goto emsskip; // param NOEMS
}
-
- if (MML_CheckForEMS())
+ printf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); //bug!
+ if(MML_CheckForEMS())
{
- MML_SetupEMS(); // allocate space
- MML_UseSpace (EMSpageframe,EMSpagesmapped*0x400);
- MM_MapEMS(); // map in used pages
- mminfo.EMSmem = EMSpagesmapped*0x4000l;
+//printf("EMS1\n");
+ MML_SetupEMS(mm); // allocate space
+ printf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); //bug!
+ //TODO: EMS4! AND EMS 3.2 MASSIVE DATA HANDLMENT!
+ MML_UseSpace(mm->EMSpageframe,(mm->EMSpagesmapped)*0x4000lu, mm);
+//printf("EMS3\n");
+ MM_MapEMS(mm); // map in used pages
+//printf("EMS4\n");
+ mmi->EMSmem = (mm->EMSpagesmapped)*0x4000lu;
}
//
// detect XMS and get upper memory blocks
//
emsskip:
- mminfo.XMSmem = 0;
- for (i = 1;i < __argc;i++)
+ mmi->XMSmem = 0;
+ for(i = 1;i < __argc;i++)
{
- if ( US_CheckParm(__argv[i],ParmStringsexmm) == 0)
+ if(US_CheckParm(__argv[i],ParmStringsexmm) == 0)
goto xmsskip; // param NOXMS
}
-
- if (MML_CheckForXMS())
- MML_SetupXMS(); // allocate as many UMBs as possible
+ printf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); //bug!
+ if(MML_CheckForXMS(mm))
+ {
+ printf("XMS!\n");
+ //MML_SetupXMS(mm, mmi); // allocate as many UMBs as possible
+ }
//
// allocate the misc buffer
//
xmsskip:
- mmrover = mmhead; // start looking for space after low block
+ mm->mmrover = mm->mmhead; // start looking for space after low block
- MM_GetPtr (&bufferseg,BUFFERSIZE);
+ MM_GetPtr(&(mm->bufferseg),BUFFERSIZE, mm, mmi);
}
//==========================================================================
====================
*/
-void MM_Shutdown (void)
+void MM_Shutdown(mminfo_t *mm)
{
- if (!mmstarted)
- return;
-
- _ffree (farheap);
- free (nearheap);
- hfree(hugeheap);
- MML_ShutdownEMS ();
- MML_ShutdownXMS ();
+ if(!(mm->mmstarted))
+ return;
+
+ _ffree(mm->farheap);
+ printf("far freed\n");
+ free(mm->nearheap);
+ printf("near freed\n");
+ //hfree(mm->hugeheap);
+ //printf("huge freed\n");
+ if(MML_CheckForEMS()){ MML_ShutdownEMS(mm); printf("EMS freed\n"); }
+ if(MML_CheckForXMS(mm)){ MML_ShutdownXMS(mm); printf("XMS freed\n"); }
}
//==========================================================================
====================
*/
-void MM_GetPtr (memptr *baseptr,dword size)
+void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi)
{
- mmblocktype far *scan,far *lastscan,far *endscan
- ,far *purge,far *next;
+ mmblocktype huge *scan,huge *lastscan,huge *endscan,huge *purge,huge *next;
int search;
unsigned needed,startseg;
needed = (size+15)/16; // convert size from bytes to paragraphs
- GETNEWBLOCK; // fill in start and next after a spot is found
- mmnew->length = needed;
- mmnew->useptr = baseptr;
- mmnew->attributes = BASEATTRIBUTES;
+ MM_GetNewBlock(mm); // fill in start and next after a spot is found
+ mm->mmnew->length = needed;
+ mm->mmnew->useptr = baseptr;
+ mm->mmnew->attributes = BASEATTRIBUTES;
- for (search = 0; search<3; search++)
+ 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 && mmrover == mmhead)
+ if(search == 1 && mm->mmrover == mm->mmhead)
search++;
- switch (search)
+ switch(search)
{
case 0:
- lastscan = mmrover;
- scan = mmrover->next;
+ lastscan = mm->mmrover;
+ scan = mm->mmrover->next;
endscan = NULL;
break;
case 1:
- lastscan = mmhead;
- scan = mmhead->next;
- endscan = mmrover;
+ lastscan = mm->mmhead;
+ scan = mm->mmhead->next;
+ endscan = mm->mmrover;
break;
case 2:
- MM_SortMem ();
- lastscan = mmhead;
- scan = mmhead->next;
+ MM_SortMem(mm);
+ lastscan = mm->mmhead;
+ scan = mm->mmhead->next;
endscan = NULL;
break;
}
startseg = lastscan->start + lastscan->length;
- while (scan != endscan)
+ while(scan != endscan)
{
- if (scan->start - startseg >= needed)
+ if(scan->start - startseg >= needed)
{
//
// got enough space between the end of lastscan and
// and allocate the new block
//
purge = lastscan->next;
- lastscan->next = mmnew;
- mmnew->start = *(unsigned *)baseptr = startseg;
- mmnew->next = scan;
- while ( purge != scan)
+ lastscan->next = mm->mmnew;
+ mm->mmnew->start = *(unsigned *)baseptr = startseg;
+ mm->mmnew->next = scan;
+ while(purge != scan)
{ // free the purgable block
next = purge->next;
- FREEBLOCK(purge);
+ MM_FreeBlock(purge, mm);
purge = next; // purge another if not at scan
}
- mmrover = mmnew;
+ mm->mmrover = mm->mmnew;
return; // good allocation!
}
//
// if this block is purge level zero or locked, skip past it
//
- if ( (scan->attributes & LOCKBIT)
+ if((scan->attributes & LOCKBIT)
|| !(scan->attributes & PURGEBITS) )
{
lastscan = scan;
}
}
- if (bombonerror)
- printf(OUT_OF_MEM_MSG,(size-mminfo.nearheap));
+ if (mm->bombonerror)
+ printf(OUT_OF_MEM_MSG,(size-mmi->nearheap));
else
- mmerror = true;
+ mm->mmerror = true;
}
//==========================================================================
====================
*/
-void MM_FreePtr (memptr *baseptr)
+void MM_FreePtr(memptr *baseptr, mminfo_t *mm)
{
- mmblocktype far *scan,far *last;
+ mmblocktype huge *scan,huge *last;
- last = mmhead;
+ last = mm->mmhead;
scan = last->next;
- if (baseptr == mmrover->useptr) // removed the last allocated block
- mmrover = mmhead;
+ if(baseptr == mm->mmrover->useptr) // removed the last allocated block
+ mm->mmrover = mm->mmhead;
- while (scan->useptr != baseptr && scan)
+ while(scan->useptr != baseptr && scan)
{
last = scan;
scan = scan->next;
}
- if (!scan)
+ if(!scan)
{
printf("MM_FreePtr: Block not found!");
return;
last->next = scan->next;
- FREEBLOCK(scan);
+ MM_FreeBlock(scan, mm);
}
//==========================================================================
=====================
*/
-void MM_SetPurge (memptr *baseptr, int purge)
+void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm)
{
- mmblocktype far *start;
+ mmblocktype huge *start;
- start = mmrover;
+ start = mm->mmrover;
do
{
- if (mmrover->useptr == baseptr)
+ if(mm->mmrover->useptr == baseptr)
break;
- mmrover = mmrover->next;
+ mm->mmrover = mm->mmrover->next;
- if (!mmrover)
- mmrover = mmhead;
- else if (mmrover == start)
+ if(!mm->mmrover)
+ mm->mmrover = mm->mmhead;
+ else if(mm->mmrover == start)
{
printf("MM_SetPurge: Block not found!");
return;
}
- } while (1);
+ } while(1);
- mmrover->attributes &= ~PURGEBITS;
- mmrover->attributes |= purge;
+ mm->mmrover->attributes &= ~PURGEBITS;
+ mm->mmrover->attributes |= purge;
}
//==========================================================================
=====================
*/
-void MM_SetLock (memptr *baseptr, boolean locked)
+void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm)
{
- mmblocktype far *start;
+ mmblocktype huge *start;
- start = mmrover;
+ start = mm->mmrover;
do
{
- if (mmrover->useptr == baseptr)
+ if(mm->mmrover->useptr == baseptr)
break;
- mmrover = mmrover->next;
+ mm->mmrover = mm->mmrover->next;
- if (!mmrover)
- mmrover = mmhead;
- else if (mmrover == start)
+ if(!mm->mmrover)
+ mm->mmrover = mm->mmhead;
+ else if(mm->mmrover == start)
{
printf("MM_SetLock: Block not found!");
return;
}
- } while (1);
+ } while(1);
- mmrover->attributes &= ~LOCKBIT;
- mmrover->attributes |= locked*LOCKBIT;
+ mm->mmrover->attributes &= ~LOCKBIT;
+ mm->mmrover->attributes |= locked*LOCKBIT;
}
//==========================================================================
=====================
*/
-void MM_SortMem (void)
+void MM_SortMem(mminfo_t *mm)
{
- mmblocktype far *scan,far *last,far *next;
+ mmblocktype huge *scan,huge *last,huge *next;
unsigned start,length,source,dest,oldborder;
int playing;
// lock down a currently playing sound
//
/*++++ playing = SD_SoundPlaying ();
- if (playing)
+ if(playing)
{
switch (SoundMode)
{
// oldborder = bordercolor;
// VW_ColorBorder (15);
- if (beforesort)
+ if(beforesort)
beforesort();
- scan = mmhead;
+ scan = mm->mmhead;
last = NULL; // shut up compiler warning
- while (scan)
+ while(scan)
{
- if (scan->attributes & LOCKBIT)
+ if(scan->attributes & LOCKBIT)
{
//
// block is locked, so try to pile later blocks right after it
}
else
{
- if (scan->attributes & PURGEBITS)
+ if(scan->attributes & PURGEBITS)
{
//
// throw out the purgable block
//
next = scan->next;
- FREEBLOCK(scan);
+ MM_FreeBlock(scan, mm);
last->next = next;
scan = next;
continue;
//
// push the non purgable block on top of the last moved block
//
- if (scan->start != start)
+ if(scan->start != start)
{
length = scan->length;
source = scan->start;
dest = start;
- while (length > 0xf00)
+ while(length > 0xf00)
{
movedata(source,0,dest,0,0xf00*16);
length -= 0xf00;
scan = scan->next; // go to next block
}
- mmrover = mmhead;
+ mm->mmrover = mm->mmhead;
- if (aftersort)
+ if(aftersort)
aftersort();
// VW_ColorBorder (oldborder);
-/*++++ if (playing)
+/*++++ if(playing)
MM_SetLock(&(memptr)audiosegs[playing],false);*/
}
=====================
*/
-void MM_ShowMemory (void)
+void MM_ShowMemory(mminfo_t *mm)
{
- mmblocktype far *scan;
+ mmblocktype huge *scan;
unsigned color,temp;
long end,owner;
- char scratch[80],str[10];
+ char scratch[160],str[16];
//**** VW_SetDefaultColors();
//**** VW_SetLineWidth(40);
//++++mh bufferofs = 0;
//**** VW_SetScreen (0,0);
- scan = mmhead;
+ scan = mm->mmhead;
end = -1;
//CA_OpenDebug ();
- while (scan)
+ while(scan)
{
- if (scan->attributes & PURGEBITS)
+ if(scan->attributes & PURGEBITS)
color = 5; // dark purple = purgable
else
color = 9; // medium blue = non purgable
- if (scan->attributes & LOCKBIT)
+ if(scan->attributes & LOCKBIT)
color = 12; // red = locked
- if (scan->start<=end)
+ if(scan->start<=end)
{
- printf("MM_ShowMemory: Memory block order currupted!");
+ printf("\nMM_ShowMemory: Memory block order currupted!\n");
return;
}
end = scan->start+scan->length-1;
-//**** VW_Hlin(scan->start,(unsigned)end,0,color);
-//**** VW_Plot(scan->start,0,15);
-//**** if (scan->next->start > end+1)
-//**** VW_Hlin(end+1,scan->next->start,0,0); // black = free
+//++++ VW_Hlin(scan->start,(unsigned)end,0,color);
+//++++ VW_Plot(scan->start,0,15);
+ if(scan->next->start > end+1)
+//++++ VW_Hlin(end+1,scan->next->start,0,0); // black = free
//****#if 0
-strcpy (scratch,"Size:");
-ltoa ((long)scan->length*16,str,10);
+printf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); //bug!
+strcpy(scratch,"Location:");
+ultoa (scan->start,str,16);
+strcat (scratch,str);
+strcat (scratch,"\tSize:");
+ltoa ((dword)scan->length*16,str,10);
strcat (scratch,str);
strcat (scratch,"\tOwner:0x");
owner = (unsigned)scan->useptr;
strcat (scratch,str);
strcat (scratch,"\n");
//++++write (debughandle,scratch,strlen(scratch));
-printf("%s\n", scratch);
+fprintf(stdout, "%s", scratch);
//****#endif
scan = scan->next;
======================
*/
-long MM_UnusedMemory (void)
+dword MM_UnusedMemory(mminfo_t *mm)
{
- unsigned free;
- mmblocktype far *scan;
+ dword free;
+ mmblocktype huge *scan;
free = 0;
- scan = mmhead;
+ scan = mm->mmhead;
- while (scan->next)
+ while(scan->next)
{
free += scan->next->start - (scan->start + scan->length);
scan = scan->next;
}
return free*16l;
+// return free;
}
//==========================================================================
======================
*/
-long MM_TotalFree (void)
+dword MM_TotalFree(mminfo_t *mm)
{
- unsigned free;
- mmblocktype far *scan;
+ dword free;
+ mmblocktype huge *scan;
free = 0;
- scan = mmhead;
+ scan = mm->mmhead;
- while (scan->next)
+ while(scan->next)
{
- if ((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
+ if((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
free += scan->length;
free += scan->next->start - (scan->start + scan->length);
scan = scan->next;
}
return free*16l;
+// return free;
+}
+
+//==========================================================================
+
+/*
+=====================
+=
+= MM_Report
+=
+=====================
+*/
+
+void MM_Report(mminfo_t *mm, mminfotype *mmi)
+{
+ if(MML_CheckForEMS())
+ {
+ printf("EMM %x available\n", mm->EMSVer);
+ printf("totalEMSpages=%u\n", mm->totalEMSpages);
+ printf("freeEMSpages=%u\n", mm->freeEMSpages);
+ printf("EMSpageframe=%x\n", mm->EMSpageframe);
+ }
+ if(MML_CheckForXMS(mm)) printf("XMSaddr=%Fp\n", *XMSaddr);
+ printf("near=%lu\n", mmi->nearheap);
+ printf("far=%lu\n", mmi->farheap);
+ printf("EMSmem=%lu\n", mmi->EMSmem);
+ printf("XMSmem=%lu\n", mmi->XMSmem);
+ printf("mainmem=%lu\n", mmi->mainmem);
+ printf("UnusedMemory=%lu\n", MM_UnusedMemory(mm));
+ printf("TotalFree=%lu\n", MM_TotalFree(mm));
+// printf("\n");
+// printf("UnusedMemory=%lu kb\n", MM_UnusedMemory()/10248);
+// printf("TotalFree=%lu kb\n", MM_TotalFree()/10248);
}
//==========================================================================
+/*
+=====================
+=
+= MM_EMSVer
+=
+=====================
+
+
+int MM_EMSVer(void)
+{
+ int EMSver;
+ __asm
+ {
+ mov ah,EMS_VERSION
+ int EMS_INT
+ mov EMSver,ax
+ }
+ return(EMSver);
+}*/
+
+//==========================================================================
+
/*
=====================
=
=====================
*/
-void MM_BombOnError (boolean bomb)
+void MM_BombOnError(boolean bomb, mminfo_t *mm)
{
- bombonerror = bomb;
+ mm->bombonerror = bomb;
}
-///////////////////////////////////////////////////////////////////////////
-//
-// US_CheckParm() - checks to see if a string matches one of a set of
-// strings. The check is case insensitive. The routine returns the
-// index of the string that matched, or -1 if no matches were found
-//
-///////////////////////////////////////////////////////////////////////////
-int
-US_CheckParm(char *parm,char **strings)
+void MM_GetNewBlock(mminfo_t *mm)
{
- char cp,cs,
- *p,*s;
- int i;
+ if(!mm->mmfree)
+ MML_ClearBlock(mm);
+ mm->mmnew=mm->mmfree;
+ mm->mmfree=mm->mmfree->next;
+ /*if(!(mm->mmnew=mm->mmfree))
+ {
+ printf("MM_GETNEWBLOCK: No free blocks!");
+ return;
+ }
+ mm->mmfree=mm->mmfree->next;*/
+}
- while (!isalpha(*parm)) // Skip non-alphas
- parm++;
+void MM_FreeBlock(mmblocktype *x, mminfo_t *mm)
+{
+ x->useptr=NULL;
+ x->next=mm->mmfree;
+ mm->mmfree=x;
+}
- for (i = 0;*strings && **strings;i++)
+void MM_seguin(void)
+{
+ __asm
{
- for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)
- {
- cs = *s++;
- if (!cs)
- return(i);
- cp = *p++;
-
- if (isupper(cs))
- cs = tolower(cs);
- if (isupper(cp))
- cp = tolower(cp);
- }
+ push ds
+ mov ax,ds
+ inc ax
+ mov ds,ax
+ }
+}
+
+void MM_segude(void)
+{
+ __asm
+ {
+ pop ds
}
- return(-1);
}
+/*
+pull data from far and put it into ds var
+mov ax,es:si
+mov x,ax
+*/
+/*
+ss stack segment
+sp top of stack
+bp bottem of stack
+*/