Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > MSDOS Programmer > Re: List of lis...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 6 Topic 493 of 495
Post > Topic >>

Re: List of lists code example

by NoEmailAds@[EMAIL PROTECTED] (Chris Giese) May 6, 2008 at 12:21 AM

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, &regs, &regs, &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;
}
 




 6 Posts in Topic:
List of lists code example
gerotica <pgerotica@[E  2008-05-03 11:34:20 
Re: List of lists code example
"Rick" <rich  2008-05-04 20:32:35 
Re: List of lists code example
Sjouke Burry <burrynul  2008-05-05 00:37:29 
Re: List of lists code example
gerotica <pgerotica@[E  2008-05-04 15:58:19 
Re: List of lists code example
NoEmailAds@[EMAIL PROTECT  2008-05-06 00:21:44 
Re: List of lists code example
Robert Riebisch <Rober  2008-05-05 23:10:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 15:54:18 CDT 2008.