home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
info
/
dostips5.arc
/
DOSENVN
< prev
next >
Wrap
Text File
|
1986-11-25
|
8KB
|
132 lines
DOS's Dynamic Environment
(PC World September 1986 The Help Screen)
The DOS environment area is one place where parameters can be
passed from one program or batch file to another. For example, to
indicate the presence of a mouse, the AUTOEXEC.BAT file might issue
the command SET MOUSE=1. The another batch file could include the
conditional line IF "%MOUSE%"=="1" COPY mouse.drv PDIO.EXE before
loading TopView. The % signs tell DOS to search the environment
area for a line starting with MOUSE; if MOUSE=1, the condition is
true and the mouse driver file is copied to PDIO.EXT for use by
TopView.
This approach can also be used within programs to access the DOS
environment to determine what parameters have been SET. When you
enter an external command -- for example, to load BASIC or APL -- or
call a program via the EXEC function call, DOS puts the program 256
bytes above the lowest block of memory that can hold the program
being started. The first 256 bytes constitutes the Program Segment
Prefix (PSP), a control block that includes the segment address of a
copy of the DOS environment area. That segment address is kept in the
PSP at offsets 2C and 2D.
When an .EXE program starts, the DS and ES registers are set to
point to the beginning of the PSP. When a .COM program is started,
all four segment registers are set to point there. You should
remember, especially if yours is a TSR application, that the copy of
the environment area is static; it is the invoking process's current
environment. Subsequently issued SET, PATH, and PROMPT commands will
not change the environment area copy.
The PSP contains other information that your programs may find
useful. In particular, a copy of the parameters following the
invoking command (including leading blanks) can be found in the PSP
at offset 81 hex; offset 80 notes the number of characters. Using
this information, a program could bypass its opening menu and proceed
directly to some function that the user specifies on the DOS command
line when the program is called. You can find more information on
DOS program and file control blocks in the DOS Technical Reference
manual.
-----------------------------------------------------------------
Environment Expansion
(PC Tech Journal November 1986 by Jim Vallino)
DOS 2.0 marked the first appearance of the environment feature --
a block of memory reserved by the operating system to hold several
system environment variables and equated ASCII strings. Whenever a
program is run, the operating system makes a copy of the environment
and then passes to the program the segment address of this copy at
offset 2Ch in the program segment prefix (PSP). Many applications
search this environment for variables that specify user preferences
for information such as the directories in which auxiliary files are
placed.
The user manages the environment variables using the SET command.
Variables may be added, deleted, changed, or displayed with this
command. Memory space for the environment is allocated during the
booting of COMMAND.COM using the Allocate Memory (48h) function of
DOS. This block of memory is placed just above the resident portion
of the operating system with a default initial size of 10 paragraphs
(160 bytes). As variables are added, the environment is increased up
to a maximum of 32KB provided that contiguous memory space is
available for the increase in size.
Unfortunately, expansion of the environment is often prevented.
Just beyond DOS's environment memory block is the free memory used for
loading application programs. When a program is loaded into this area
it limits the size of the environment to its current memory allocation.
If this program is one of the many utilities that remains resident,
then the size limitation is permanent. Even if no terminate-and-stay-
resident programs are run, defining many environment strings from the
command line can be tedious.
What most users would like to do is place all of the SET commands
into a batch file such as AUTOEXEC.BAT. However, the operating system
will load information for the running of this batch file just above
the environment, effectively freezing its current size. The solution
is to increase the number of paragraphs requested for the default
environment memory block. This is done in DOS 2.x and 3.0 by patching
COMMAND.COM, whereas in versions 3.1 and 3.2 a feature of the SHELL
command makes a patch unnecessary.
Whenever attempting to patch the operating system the user should
perform the work on a backup copy of the DOS diskette in case something
goes wrong. The new copy should be placed in drive A: and
DEBUG A:COMMAND.COM run. The relevant assembly code is:
Assembly Code Machine Code
------------- ------------
MOV BX,0A BB 0A 00 ;Load BX with number of paragraphs
MOV AH,48 B4 48 ;Specify Allocate Memory function
INT 21 CD 21 ;Execute DOS function
Use the DEBUG command S 100 L 4500 BB 0A 00 B4 48 CD 21 to find the
location of this piece of code. Unassembling the program at this
location should display the first three instructions shown above.
If the instructions do not correspond, the operation steps should be
checked again. (This code does not appear in DOS 3.1 and 3.2; if
these versions are being used, see the section below for the correct
procedure to follow.) At the address displayed, assemble a new
instruciton, which loads the BX register with the size desired.
Remember that the number loaded into BX is understood as a hexadecimal
value specifying the number of paragraphs (times 16 for bytes) in the
default environment. Check the modification by then unassembling
again.
Once the change is satisfactory, write it back to the diskette
and exit DEBUG. Then reboot from this diskette and perform a simple
operation (such as DIR) to see if the operating system still functions.
If it still functions correctly, copy the patched COMMAND.COM to the
root directory of the disk from which the computer is normally booted.
Be sure that a backup of the patched version of the operating system
is made to be restored to the boot disk if ever needed.
To verify that the environment is enlarged, create a batch file
with several SET commands, which define strings with a total of more
that 160 bytes but less than the new size of the environment. Typing
SET without any parameters lists the entire contents of the modified
environment.
Beginning with DOS 3.1, a feature of COMMAND.COM and the SHELL
statement used in CONFIG.SYS allows a user to specify the size of the
default environment. This feature was not documented in the IBM
literature until DOS 3.2, although it is available in a slightly
different form in DOS 3.1. The IBM DOS 3.1 documentation does not
mention that the SHELL command includes an option that defines the
size of the default environment.
Put a SHELL statement in the CONFIG.SYS file using the following
command format:
SHELL<command-file> /P /E:xx
where <command-file> is the full path name for COMMAND.COM, and xx is
the size of the default environment. This size is given as a decimal
value representing in version 3.1 the number of paragraphs in the
environment and in version 3.2 the number of bytes. The P option
instructions COMMAND.COM to execute the AUTOEXEC.BAT file, or date
and time if no AUTOEXEC.BAT is present when the command processor is
loaded.