home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
144.lha
/
mm201.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-20
|
5KB
|
198 lines
/*DO:
cc mm.c
list mm
ln mm.o -lc
list mm
*/
/* MergeMem.c v2 - by Carolyn Scheppner CBM 02/87
* modified: 07/87 to move printf's outside of Forbid
* (printf eventually Waits which breaks a Forbid)
* Now responsive from WB, linkage with TWstartup.obj
*
*
* Modified: Khalid Aldoseri 06/88 to improve output.
* and to work with Aztec C3.40.
*
* Attempts to merge the memlists of sequentially configged ram boards
* which have the same Attributes (for contiguous expansion ram)
*
* Note: This program has been tested with an Alegra plugged into
* a Microbotics Starboard' pass-thru, and with an A2000
* with multiple 2-meg ram boards. This program makes
* the assumption that sequentially configged ram boards
* have sequential entries in the MemHeader list.
* If ram boards are not installed largest to smallest,
* this may not be true and this program will not be able
* to merge them.
*
*/
#include "exec/types.h"
#include "exec/exec.h"
#include "exec/execbase.h"
#include "libraries/dosextens.h"
extern struct ExecBase *SysBase;
extern struct FileHandle *Open();
struct FileHandle *fh;
long Chip = 0,Fast = 0,Static = 0,temp;
char output[128];
int Height = 0;
main(argc,argv)
int argc;
char *argv[];
{
struct MemChunk *chunk;
struct MemHeader *mem, *firstmem, *prevmem = 0;
struct ExecBase *eb = SysBase;
ULONG memsize;
ULONG mems[32], ends[32], atts[32], prev[32], mrgs[32];
ULONG k, memCnt = 0, mrgCnt = 0;
/* Temps */
struct MemChunk *oldFirst;
APTR oldLower, oldUpper;
ULONG oldFree;
Forbid();
firstmem = (struct MemHeader *)eb->MemList.lh_Head;
/* Go to end of MemHeader list */
for (mem = firstmem;
mem->mh_Node.ln_Succ;
mem = (struct MemHeader *)mem->mh_Node.ln_Succ)
{
mems[memCnt] = (ULONG)mem;
ends[memCnt] = (ULONG)mem->mh_Upper;
atts[memCnt] = (ULONG)mem->mh_Attributes;
memCnt++;
}
/* Back up from terminal node to point at last MemHeader */
mem = (struct MemHeader *)mem->mh_Node.ln_Pred;
/* Backwards, for each except first */
for ( ; (ULONG)mem != (ULONG)firstmem; mem = prevmem)
{
prevmem = (struct MemHeader *)mem->mh_Node.ln_Pred;
/* If prev MemHeader describes neighboring ram of same Attributes */
if(((ULONG)prevmem->mh_Upper == (ULONG)mem->mh_Lower - 32L)
&& (prevmem->mh_Attributes == mem->mh_Attributes))
{
prev[mrgCnt] = (ULONG)prevmem;
mrgs[mrgCnt] = (ULONG)mem;
mrgCnt++;
/* Save needed stuff from MemHeader before Remove()ing it */
oldFirst = mem->mh_First;
oldLower = mem->mh_Lower;
oldUpper = mem->mh_Upper;
oldFree = mem->mh_Free;
Remove(mem);
/* Adjust Upper and Free in prev MemHeader to include this mem */
memsize = (ULONG)oldUpper - (ULONG)oldLower +32L;
prevmem->mh_Upper = (APTR)((ULONG)prevmem->mh_Upper + memsize);
prevmem->mh_Free += oldFree;
/* Link last free chunk of prevmem to first free of mem */
for (chunk = prevmem->mh_First;
chunk->mc_Next; chunk = chunk->mc_Next);
chunk->mc_Next = oldFirst;
/* Now FreeMem() the old MemHeader as a 32 byte chunk */
FreeMem(mem,32L);
}
}
Permit();
if (argc != 1)
{
Height = 104 + (memCnt + mrgCnt) * 8;
/* Calculate Height for window */
if (Height > 184) Height = 184;
sprintf(output,"CON:10/12/430/%d/ MergeMem v2.01 ",Height);
if (!(fh = Open(output,MODE_NEWFILE)))
exit(20);
Print("\n");
}
Print("\t\t RAM Configuration\n\t\t -----------------\n\n");
for(k=0; k<memCnt; k++)
{
temp = (ends[k] - mems[k]);
if (atts[k] & 1) Print(" PUBLIC ");
else
Print(" ");
if (atts[k] & 2)
{
Print(" CHIP :");
Chip = Chip + temp;
}
if (atts[k] & 4)
{
if (mems[k] > 0xffffff)
{
Static = Static + temp;
Print("STATIC:");
}
else
{
Fast = Fast + temp;
Print(" FAST :");
}
}
sprintf(output," $%08lx - $%08lx %5ldk\n", mems[k], (ends[k]) - 1,
(512L + temp) / 1024L);
Print(output);
}
Chip = (Chip + 512L) / 1024L;
Fast = (Fast + 512L) / 1024L;
Static = (Static + 512L) / 1024L;
sprintf(output,"\n\t\t Chip : %5ldk\n\t\t Fast : %5ldk\n\t\t Static: %5ldk\n\n"
,Chip,Fast,Static);
Print(output);
if (!fh) Print("\n");
if(mrgCnt)
{
for(k=0; k<mrgCnt; k++)
{
sprintf(output,"\t Merged $%08lx with $%08lx\n",mrgs[k], prev[k]);
Print(output);
}
if (!fh) Print("\n\n");
}
if (fh)
{
Delay(750L);
Close(fh);
}
}
Print(string)
char *string;
{
if (fh)
Write(fh,string,(long) strlen(string));
else
printf(string);
}