TITLE	env_adrs.asm
NAME	env_adrs

; $Header:   E:/mark/envircat/env_adrs.asv   1.0   27 Nov 1990 00:14:18   Mark_Gardner  $

;* environment address
;  
;  a routine to determine the address of the environment of the master
;  COMMAND.COM invocation under DOS.  Does not work with some versions,
;  typically 4.00.
;
;  this routine was taken from an article by Scott Robert Ladd in the
;  book "MS-DOS SYSTEM PROGRAMMING", edited by Robert Ward, R&D Publications,
;  260-1 Iowa Street, Lawrence, KS 66046.  My thanks to him, since I was
;  desperate for a longer path statement, and this was the key.
;
;  I hope he will forgive me for leaving out all the comments.  Even though
;  he put the program in the public domain, R&D might get a few more orders
;  this way for a very useful book.  I received the book as a 'bonus' for
;  subscribing to TechSpecialist, which, in spite of its title, is targeted
;  at specialist programmers in MS-DOS, and is at least as useful as most
;  other of my subscriptions.
;
;>


.MODEL	LARGE

.CODE

PUBLIC	_findmenv

_findmenv	PROC	FAR

	push	es
	push	bx
	push	cx

	mov	ah, 52h
	int	21h

	mov	ax, word ptr es:[bx-2]
	mov	es, ax
	mov	bx, 3

	add	ax, word ptr es:[bx]
	inc	ax
	inc	ax
	mov	es, ax
	mov	bx, 44

	mov	ax, word ptr es:[bx]
	cmp	ax, 0

	jne	fge_1

	mov	ax, es
	dec	ax
	mov	es, ax
	mov	bx, 3
	add	ax, es:[bx]
	inc	ax

fge_1:

	dec	ax
	mov	es, ax
	mov	bx, 3

	mov	dx, es:[bx]
	mov	cl, 4
	shl	dx, cl
	mov	cx, dx

	inc	ax
	mov	dx, ax
	xor	ax, ax

	pop	cx
	pop	bx
	pop	es

	ret

_findmenv	ENDP

;-

END

