⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 membase.c

📁 DOS 源代码 系列之 command 源码
💻 C
📖 第 1 页 / 共 4 页
字号:
      if (mem_table.files[i].psp_addr)  continue;

      memsize = mem_table.files[i].conv_ttl + mem_table.files[i].umb_ttl;
      sprintf (temp1, "(%ldK)", toK (mem_table.files[i].conv_ttl));
      sprintf (temp2, "(%ldK)", toK (mem_table.files[i].umb_ttl));
      sprintf (temp3, "(%ldK)", toK (memsize));

      mprintf (MainCLineMsg, "%-8m%8ld%7c%8ld%7c%8ld%7c", CFreeMsg,
	   &memsize, temp3, &mem_table.files[i].conv_ttl, temp1,
	                    &mem_table.files[i].umb_ttl,  temp2);
      }
}

/*----------------------------------------------------------------------*/
/*  AddMem_to_Table						        */
/*	Entry:	PSP_ADDR	(to which this mem. should be added)	*/
/*		ARENA_START_ADDR					*/
/*		Region of arena (0 == conv, 1 == UMB#1, 2 == UMB#2...)	*/
/*		Length_of_Arena						*/
/*	Exit:	mem_table updated.			      		*/
/*		returns 1 if more than MAX_CL_ENTRIES in mem_table	*/
/*		   else 0						*/
/*									*/
/* CAVEATS:						  		*/
/* --------								*/
/* 1. any system area (BIOS,SYSINIT,DOS ) code/data is listed as	*/
/*    to PSP 8.							        */
/*									*/
/* 2. We look at the UMB_HEAD in DOS DATA to determine whether an arena */
/*    is in UMB or not; For the Arena at the UMB boundary, we add one   */
/*    para to conv. and remaining to UMB portion of that PSP	        */
/*									*/
/* 3. Any free memory is always added as a new entry in the mem_table   */
/*    instead of just adding the sizes to an existing FREE entry        */
/*    Free memory gets added to the previous free memory if they are    */
/*    contiguous							*/
/*									*/
/* 4. The no of programs/free arenas cannot exceed a max of (100)	*/
/*    (defined by MAX_CLDATA_INDEX )       				*/
/*    If the memory is fragmented and a lot of small TSRs loaded such   */
/*    that we exceed this limit, we TERMINATE				*/
/*									*/
/* 5. Mem occupied by this MEM are also reported as FREE mem		*/
/*									*/
/*----------------------------------------------------------------------*/

/*
 * AddMem_to_Table() should be called for each given primary segment in the
 * detailed display.  By the time the detail is over, all conventional and
 * upper memory summaries of any sort will be finished (neato eh?), save the
 * sorting of programs (if you wanna do that).
 *
 */

unsigned int AddMem_to_Table (psp, addr, region, size)
unsigned int                  psp;
unsigned long                      addr, region, size;
{
   int               dd,            i;
   static long       memsize = 0L,  wasfree = 0L;
   static int        ismem   = 0;
   struct ARENA far *ArenaPtr;

   if (psp == 7)
      {
      dd = (unsigned int)GetDDriverPSP ();
      }
   else
      {
      FP_SEG(ArenaPtr) = (unsigned)addr-1; // Find the arena so we can get name
      FP_OFF(ArenaPtr) = 0;                // to compare with device drivers.

      if ((dd = IsDDriverAround (gpszDevDriver)) < 0) // If there's no DD
         dd = MAX_DDRIVER_REP;                        // with the same
      else                                            // name, it's nrml
         psp = 7;     // Otherwise, pretend we're filling in the DD list.
      }

   size += 16;  /* Header */

   if (ismem && psp == 0)
      {
      wasfree = memsize;
      memsize = 0;
      }

   ismem = 0;
   if (psp == _psp)
      {
      if (wasfree && region == 0L)
         {
	 memsize += wasfree;
	 }

      psp = 0;  /* treat MEM's arenas as FREE */
      ismem = 1;
      wasfree = 0L;
      }
   else
      wasfree = (psp == 0 && region == 0L) ? wasfree+size : 0L;

   for (i = 0; i < mem_table.noof_progs; i++)
      if (mem_table.files[i].psp_addr == psp)
         {
	 if ((psp != 7) || mem_table.files[i].driveridx == dd)
	    break;
	 }

	   /* if psp is not already listed in the table, add it */

   if (i == mem_table.noof_progs)
      {
      if (mem_table.noof_progs == MAX_CLDATA_INDEX)
	 {
	 mprintf(CMemFragMsg, "");
	 return(1);
	 }
      mem_table.files[i].psp_addr  = psp;
      mem_table.files[i].driveridx = dd;
      mem_table.noof_progs ++;
      }

		 /* add the memory to the table entry */

   if (ismem && region==0L)
      memsize += size;

   if (addr < UMB_Head)
      {
      mem_table.files[i].conv_ttl += size;
      if (psp == 0)
         mem_table.conv_free += size;
      if (psp == 0 && size > mem_table.conv_large)
         mem_table.conv_large = size;
      if (ismem && memsize > (long)mem_table.conv_large)
         mem_table.conv_large = size;
      if (wasfree > (long)mem_table.conv_large)
         mem_table.conv_large = wasfree;
      }
   else
      {
      mem_table.umb_ttl += size;
      if (psp == 0)
         mem_table.umb_free += size;

      mem_table.files[i].umb_ttl += size;
      if (psp == 0 && size > mem_table.umb_large)
	mem_table.umb_large = size;
      }

   if (region == 0L)  return 0;

   mem_table.umbs[(int)region-1].umb_ttl += size;
   if (psp == 0)
      {
      mem_table.umbs[(int)region-1].umb_free += size;
      if (size > mem_table.umbs[(int)region-1].umb_large)
	 mem_table.umbs[(int)region-1].umb_large = size;
      }
   if (mem_table.umbs[(int)region-1].umb_addr == 0L ||
       addr < mem_table.umbs[(int)region-1].umb_addr)
      {
      mem_table.umbs[(int)region-1].umb_addr = addr;
      }

  return 0;
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/* A quick bit about headers:  MEM now reports all headers, or MCBs, as      */
/* space allocated by modules; ie, a module consisting of 2 MCBs, one which  */
/* points to a 50-paragraph block, and one which points to a 25-paragraph    */
/* block, will be listed in MEM/C as using 77 paragraphs... 1 for each MCB   */
/* as well.  MEM/D will list the individual sizes as 51 and 26 paragraphs,   */
/* so that size + address gives the next address.  This is mentioned here    */
/* because things... well... have not always been this way.                  */
/*                                                                           */
/*---------------------------------------------------------------------------*/

void
DoMainLine        (Owner, Address, Name, Size, Type, Region)
int                Owner,          Name,       Type;
unsigned long int        *Address,      *Size,      *Region;
{
   char  temp[40], far *ptr, temp2[9];

   if (Owner != 7)  *Size += 16;  // For display ONLY--see end of this routine

   if (DataLevel == 2 && Owner != 7)
      {
      mainline (Address, Name, Size, Type, Region);
      }

   if (DataLevel == 3 && *Region == 0L && (Owner == 0 || Owner == _psp))
      {
      sprintf (temp, "(%ldK)", toK (*Size));
      mprintf (MainFLineMsg, "%5lx%8ld%7c", Address, Size, temp);
      modulesize += *Size;
      }
   if (DataLevel == 4)
      {
      if (Owner == 7)
         {
	 strcpy (temp2, gpszDevDriver);
	 ptr = temp2;
	 }
      else
	 {
	 InRegs.x.ax = Name;
	 InRegs.h.dh = Utility_Msg_Class;
	 sysgetmsg(&InRegs,&SegRegs,&OutRegs);
	 FP_OFF(ptr) = OutRegs.x.si;
	 FP_SEG(ptr) = SegRegs.ds;
         }

      estrip (ptr);
      if (stricmp (ModName, (char *)ptr))  return;

      if (! modulesize)
         {
	 mprintf (NewLineMsg,   "");
	 mprintf (ModUseMsg,    "%-c", ModName);
	 mprintf (NewLineMsg,   "");
	 mprintf (ModTitleMsg,  "");
	 mprintf (ModUScoreMsg, "");
	 }
      sprintf (temp, "(%ldK)", toK (*Size));
      if (*Region == 0L)
         {
	 if (Owner != 7)
	    {
	    mprintf (MainMLineMsg, "%5lx%8ld%7c%-m", Address,Size,temp,Type);
	    }
	 else
	    {
	    mprintf (MainMDLineMsg, "%5lx%8ld%7c%-m%-c", Address, Size,
	                            temp, Type, ptr);
	    }
         }
      else
         {
	 if (Owner != 7)
	    {
	    mprintf (MainMXLineMsg, "%5lx%3ld%8ld%7c%-m", Address, Region,
		     Size, temp, Type);
	    }
	 else
	    {
	    mprintf (MainMDXLineMsg, "%5lx%3ld%8ld%7c%-m%-c", Address, Region,
		     Size, temp, Type, ptr);
	    }
         }
      modulesize += *Size;
      }

   if (Owner != 7)  *Size -= 16;  // For display ONLY--see top of this routine
}

void
DoMainLine_a      (Owner, Address, Name, Size, Type, Region)
int                Owner;
char                              *Name,      *Type;
unsigned long int        *Address,      *Size,      *Region;
{
   char  temp[40];
   *Size += 16;
   if (DataLevel == 2)  mainline_a (Address, Name, Size, Type, Region);
   if (DataLevel == 3 && *Region == 0L && (Owner == 0 || Owner == _psp))
      {
      sprintf (temp, "(%ldK)", toK (*Size));
      mprintf (MainFLineMsg, "%5lx%8ld%7c", Address, Size, temp);
      modulesize += *Size;
      }
   if (DataLevel == 4)
      {
      estrip ((char far *)Name);
      if (stricmp (Name, ModName))
      if (stricmp (Name, ModName))  return;

      if (! modulesize)
         {
	 mprintf (NewLineMsg,   "");
	 mprintf (ModUseMsg,    "%-c", ModName);
	 mprintf (NewLineMsg,   "");
	 mprintf (ModTitleMsg,  "");
	 mprintf (ModUScoreMsg, "");
	 }
      sprintf (temp, "(%ldK)", toK (*Size));
      if (*Region == 0L)
         mprintf (MainMLineMsg, "%5lx%8ld%7c%-c", Address,
		  Size, temp, Type);
      else
         mprintf (MainMXLineMsg, "%5lx%3ld%8ld%7c%-c", Address, Region,
		  Size, temp, Type);
      modulesize += *Size;
      }
   *Size -= 16;
}

void
estrip   (str)
char far *str;
{
   char far *p;
   if ((p = strchr ((char *)str, ' ')) != NULL)  *p = 0;
}

/*
 * DriverData() returns a character string containing:
 *
 *    Driver == 'F' : Number of files from "FILES=XXX" statement
 *    Driver == 'X' : Number of FCBS from "FCBS=XXX" statement
 *    Driver == 'B' : Number of buffers from "BUFFERS=XXX" statment
 *    Driver == 'L' : Letter of last drive from "LASTDRIVE=?" statement
 *    Driver == 'S' : Proper format from "STACKS=XXX,XXX" statement
 *
 * Thanks go to EricAr for his work here.
 *
 */

char *
DriverData       (ptr)
struct ARENA far *ptr;
{

#define buffer_m (int) (SysVarsPtr->BufferValues & 0x00FF)
#define buffer_n (int)((SysVarsPtr->BufferValues & 0xFF00) >> 8)

   void    far *tmp, far *tmp2;
   static char  buf[40];

   strcpy (buf, "?");

   tmp  = ptr;  FP_SEG(tmp)++;
   tmp2 = ptr;  FP_SEG(tmp2)++;
   FP_OFF(tmp)  = 4L;
   FP_OFF(tmp2) = 6L;
   switch (ptr->Signature)
      {
      case 'F':  sprintf (buf, "%d", *(short far *)tmp +5);
		break;
      case 'X':  sprintf (buf, "%d", *(short far *)tmp);
		break;
      case 'B':  if (! buffer_n)  sprintf (buf, "%d", buffer_m);
                 else             sprintf (buf, "%d,%d", buffer_m, buffer_n);
		break;
      case 'L':  sprintf (buf, "%c", ('A'-1) +SysVarsPtr->CdsCount);
		break;
      case 'S':  FP_OFF(tmp) = 2L;
                 sprintf (buf, "%d,%d", *(short far *)tmp, *(short far *)tmp2);
		break;
      }
   return buf;
}

unsigned int GetDDriverPSP ()
{
   register int  i;

   for (i = 0; i < ddriveridx; i++)
      {
      if (! strcmp (ddrivername[i], gpszDevDriver))
	 break;
      }
   if (i >= MAX_DDRIVER_REP)
      {
      return MAX_DDRIVER_REP;  // Too many?
      }
   if (i == ddriveridx)
      {
      strcpy (ddrivername[i], gpszDevDriver);
      ddriveridx++;
      }
   return i;
}

unsigned int IsDDriverAround (char *name) // Returns -1 if not, else its #.
{
   register int  i;

   for (i = 0; i < ddriveridx; i++)
     {
     if (! strcmp (ddrivername[i], name))
        break;
     }
   return (i < ddriveridx) ? i : -1;
}

/* M003 END */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -