g*****ca <pg*****ca@[EMAIL PROTECTED]
> wrote:
>Everytime I try to search for "how mem.exe works" or something like
>that I end up with "you need to use int21h/52h to get list-of-lists
>and walk through the MCB chain"... Well, I tried this:
This works for me:
/*----------------------------------------------------------------------------
Displays DOS MCB chain
Compile with Turbo C, Borland C, or Watcom C
----------------------------------------------------------------------------*/
#include <stdio.h>
#include <dos.h>
typedef unsigned short uint16_t;
/* mcb_t must be a packed struct: */
#pragma pack(1)
/* That doesn't work for Turbo C++ 1.0, so do this: */
#if defined(__TURBOC__)
#if __TURBOC__==0x296
#pragma option -a-
#endif
#endif
typedef struct
{
char type;
uint16_t owner_psp;
uint16_t size; /* in paragraphs */
char unused[3];
char owner_name[8];
} mcb_t;
/*****************************************************************************
*****************************************************************************/
static void wrstr(char far *s)
{
int i;
for(i = 0; i < 8; i++)
{
putchar(*s < ' ' ? '.' : *s);
s++;
}
}
/*****************************************************************************
debug function
*****************************************************************************/
#define BPERL 16 /* byte/line for dump */
void dump(void far *data_p, unsigned count)
{
unsigned char far *data = (unsigned char far *)data_p;
unsigned byte1, byte2;
while(count != 0)
{
for(byte1 = 0; byte1 < BPERL; byte1++)
{
if(count == 0)
break;
printf("%02X ", data[byte1]);
count--;
}
printf("\t");
for(byte2 = 0; byte2 < byte1; byte2++)
{
if(data[byte2] < ' ')
printf(".");
else
printf("%c", data[byte2]);
}
printf("\n");
data += BPERL;
}
}
/*****************************************************************************
*****************************************************************************/
int main(void)
{
struct SREGS sregs;
union REGS regs;
mcb_t far *mcb;
unsigned s;
regs.x.ax = 0x5200;
int86x(0x21, ®s, ®s, &sregs);
/* segment of MCB list entry
Watcom C has no 'peek'
s = peek(sregs.es - 1, regs.x.bx + 14); */
s = *(uint16_t far *)MK_FP(sregs.es - 1, regs.x.bx + 14);
while(1)
{
mcb = (mcb_t far *)MK_FP(s, 0);
/*dump(mem, sizeof(mcb_t));*/
printf("adr=%04X, owner_psp=%04X, size=%6lu, owner=",
FP_SEG(mcb), mcb->owner_psp, mcb->size * 16uL);
wrstr(mcb->owner_name);
printf(", contents=");
wrstr(&((char far *)mcb)[16]);
printf("\n");
if(mcb->type == 0x5A)
break;
s += (1 + mcb->size);
}
printf("adr=%04X\n", FP_SEG(mcb));
return 0;
}


|