home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 144.lha / mm201.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  5KB  |  198 lines

  1. /*DO:
  2.  
  3. cc mm.c
  4. list mm
  5. ln mm.o -lc
  6. list mm
  7.  
  8. */
  9.  
  10. /* MergeMem.c v2 - by  Carolyn Scheppner  CBM  02/87
  11.  *    modified:  07/87 to move printf's outside of Forbid
  12.  *               (printf eventually Waits which breaks a Forbid)
  13.  *               Now responsive from WB, linkage with TWstartup.obj
  14.  *
  15.  *
  16.  *        Modified: Khalid Aldoseri 06/88 to improve output.
  17.  *                  and to work with Aztec C3.40.
  18.  * 
  19.  *  Attempts to merge the memlists of sequentially configged ram boards
  20.  *  which have the same Attributes (for contiguous expansion ram)
  21.  *
  22.  *  Note:  This program has been tested with an Alegra plugged into
  23.  *         a Microbotics Starboard' pass-thru, and with an A2000
  24.  *         with multiple 2-meg ram boards.  This program makes
  25.  *         the assumption that sequentially configged ram boards
  26.  *         have sequential entries in the MemHeader list.
  27.  *         If ram boards are not installed largest to smallest,
  28.  *         this may not be true and this program will not be able
  29.  *         to merge them.
  30.  *
  31.  */
  32.  
  33. #include "exec/types.h"
  34. #include "exec/exec.h" 
  35. #include "exec/execbase.h" 
  36. #include "libraries/dosextens.h"
  37.  
  38. extern struct ExecBase *SysBase;
  39. extern struct FileHandle *Open();
  40.  
  41.    struct FileHandle *fh;
  42.  
  43. long    Chip = 0,Fast = 0,Static = 0,temp;
  44. char    output[128];
  45. int        Height = 0;
  46.  
  47. main(argc,argv)
  48.     int argc;
  49.     char *argv[];
  50.    {
  51.    struct MemChunk *chunk;
  52.    struct MemHeader *mem, *firstmem, *prevmem = 0;
  53.    struct ExecBase *eb = SysBase;
  54.    ULONG  memsize;
  55.  
  56.    ULONG  mems[32], ends[32], atts[32], prev[32], mrgs[32];
  57.    ULONG  k, memCnt = 0, mrgCnt = 0;
  58.  
  59.    /* Temps */
  60.    struct MemChunk *oldFirst;
  61.    APTR   oldLower, oldUpper;
  62.    ULONG  oldFree;
  63.  
  64.    Forbid();
  65.    firstmem = (struct MemHeader *)eb->MemList.lh_Head;
  66.  
  67.    /* Go to end of MemHeader list */
  68.    for (mem = firstmem;
  69.            mem->mh_Node.ln_Succ;
  70.               mem = (struct MemHeader *)mem->mh_Node.ln_Succ)
  71.       {
  72.       mems[memCnt] = (ULONG)mem;
  73.       ends[memCnt] = (ULONG)mem->mh_Upper;
  74.       atts[memCnt] = (ULONG)mem->mh_Attributes;
  75.       memCnt++;
  76.       }
  77.  
  78.    /* Back up from terminal node to point at last MemHeader */
  79.    mem = (struct MemHeader *)mem->mh_Node.ln_Pred;
  80.  
  81.    /* Backwards, for each except first */
  82.    for ( ; (ULONG)mem != (ULONG)firstmem; mem = prevmem)
  83.       {
  84.       prevmem = (struct MemHeader *)mem->mh_Node.ln_Pred;
  85.  
  86.       /* If prev MemHeader describes neighboring ram of same Attributes */
  87.       if(((ULONG)prevmem->mh_Upper == (ULONG)mem->mh_Lower - 32L)
  88.                && (prevmem->mh_Attributes == mem->mh_Attributes))
  89.          {
  90.          prev[mrgCnt] = (ULONG)prevmem;
  91.          mrgs[mrgCnt] = (ULONG)mem;
  92.          mrgCnt++;
  93.  
  94.          /* Save needed stuff from MemHeader before Remove()ing it */
  95.          oldFirst = mem->mh_First;
  96.          oldLower = mem->mh_Lower;
  97.          oldUpper = mem->mh_Upper;
  98.          oldFree  = mem->mh_Free;
  99.          Remove(mem);
  100.  
  101.          /* Adjust Upper and Free in prev MemHeader to include this mem */
  102.          memsize = (ULONG)oldUpper - (ULONG)oldLower +32L;
  103.          prevmem->mh_Upper = (APTR)((ULONG)prevmem->mh_Upper + memsize);
  104.          prevmem->mh_Free += oldFree;
  105.  
  106.          /* Link last free chunk of prevmem to first free of mem */
  107.          for (chunk = prevmem->mh_First;
  108.                   chunk->mc_Next; chunk = chunk->mc_Next);
  109.          chunk->mc_Next = oldFirst;
  110.  
  111.          /* Now FreeMem() the old MemHeader as a 32 byte chunk */
  112.          FreeMem(mem,32L);
  113.          }
  114.       }
  115.    Permit();
  116.    
  117.     if (argc != 1)
  118.         {
  119.        Height = 104 + (memCnt + mrgCnt) * 8;    
  120.                                    /* Calculate Height for window */
  121.        if (Height > 184)    Height = 184;
  122.        sprintf(output,"CON:10/12/430/%d/ MergeMem v2.01 ",Height);
  123.         if (!(fh = Open(output,MODE_NEWFILE)))
  124.             exit(20);
  125.         Print("\n");
  126.         }
  127.             
  128.       Print("\t\t  RAM Configuration\n\t\t  -----------------\n\n");
  129.       
  130.       for(k=0; k<memCnt; k++)
  131.          {
  132.          temp = (ends[k] - mems[k]);
  133.          if (atts[k] & 1)     Print("     PUBLIC ");
  134.         else
  135.             Print("            ");
  136.          if (atts[k] & 2)
  137.              {
  138.              Print(" CHIP :");
  139.             Chip = Chip + temp;
  140.             }
  141.          if (atts[k] & 4)        
  142.              {
  143.             if (mems[k] > 0xffffff)    
  144.                 {
  145.                 Static = Static + temp;
  146.                 Print("STATIC:");
  147.                 }
  148.             else
  149.                 {
  150.                 Fast = Fast + temp;
  151.                  Print(" FAST :");
  152.                 }
  153.             }
  154.          sprintf(output," $%08lx - $%08lx %5ldk\n", mems[k], (ends[k]) - 1,
  155.          (512L + temp) / 1024L);
  156.          Print(output);
  157.          }
  158.         
  159.         Chip   = (Chip   + 512L) / 1024L;
  160.         Fast   = (Fast   + 512L) / 1024L;
  161.         Static = (Static + 512L) / 1024L;
  162.         
  163.         sprintf(output,"\n\t\t     Chip : %5ldk\n\t\t     Fast : %5ldk\n\t\t    Static: %5ldk\n\n"
  164.             ,Chip,Fast,Static);
  165.          Print(output);
  166.          
  167.          if (!fh)    Print("\n");
  168.      
  169.       if(mrgCnt)
  170.           {
  171.         for(k=0; k<mrgCnt; k++)
  172.              {
  173.              sprintf(output,"\t  Merged  $%08lx with $%08lx\n",mrgs[k], prev[k]);
  174.              Print(output);
  175.              }
  176.             
  177.          if (!fh)    Print("\n\n");
  178.         }
  179.         
  180.     if (fh) 
  181.         {
  182.         Delay(750L);
  183.         Close(fh);
  184.         }
  185.    }
  186.  
  187.  
  188. Print(string)
  189.     char *string;
  190.     
  191.     {
  192.     if (fh)
  193.         Write(fh,string,(long) strlen(string));
  194.     else
  195.         printf(string);
  196.     }
  197.  
  198.