delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/05/25/17:00:47

Date: Tue, 25 May 1993 13:18:56 -0700 (PDT)
From: Andrew Tucker <a_tucker AT paul DOT spu DOT edu>
Sender: Andrew Tucker <a_tucker AT paul DOT spu DOT edu>
Reply-To: Andrew Tucker <a_tucker AT paul DOT spu DOT edu>
Subject: Re: Access to CONFIG.SYS params
To: DJGPP mailing list <djgpp AT sun DOT soe DOT clarkson DOT edu>

Aha!  I found it!  On page 194 of _Undocumented DOS_, Jim Kyle gives the
following code for finding the value of the FILES= parameter in CONFIG.SYS.

** CODE REUSE FLAG ON **

/*
	COUNTF.C - Jim Kyle
	Last Change: 13 AUG 1990
*/

#include <stdio.h>
#include <dos.h>
#include <stdlib.h>

#ifndef MK_FP
#define MK_FP (s,o)	(void far *)(((long)(s)<<16)|(unsigned)(o))
#endif

unsigned files(void) {
	
	union REGS regs;
	struct SREGS sregs;
	unsigned int far *ptr;
	int n = 0;

	if (_osmajor < 2) {
		puts("FILES not supported in this DOS version.");
		exit(0);
	}

	regs.h.ah = 0x52;
	intdosx(&regs, &regs, &sregs);
	ptr = (unsigned int far *)MK_FP(sregs.es, regs.x.bx + 4);
	ptr = (unsigned int far *)MK_FP(ptr[1], ptr[0]);
	while (FP_OFF(ptr) != 0xFFFF) {
		n += ptr[2];
		ptr = (unsigned int far *)MK_FP(ptr[1], ptr[0]);
	}

	return n;
}

#ifdef TESTING
void main(void) {
	printf("FILES=%u\n", files());
}
#endif

** CODE REUSE FLAG OFF **

This could easily be ported to a C compiler of anyone's choosing, as well
as any other language that supports pointers.  A quick and dirty assembly
routine would work best, IMO.

Anyways, I _highly_ reccomend this book to anyone interested in the down
and dirty details of how DOS does what little it does.



/* Andrew */

"As far as the laws of mathematics refer to reality, they are not certain;
 and as far as they are certain, they do not refer to reality"
				Albert Einstein





- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019