Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!cica!ctrsol!ginosko!uunet!cs.dal.ca!lane
From: lane@cs.dal.ca (John Wright/Dr. Pat Lane)
Newsgroups: comp.sys.ibm.pc
Subject: Patches to COMMAND.COM for DOS3.3x (LONG)
Summary: My old set of patches updated for several vers of DOS 3.3
Keywords: DOS COMMAND.COM patch environment size echo
Message-ID: <1989Aug14.044111.26470@cs.dal.ca>
Date: 14 Aug 89 04:41:11 GMT
Organization: Math, Stats & CS, Dalhousie University, Halifax, NS, Canada
Lines: 325


Some time ago I posted a set of patches for COMMAND.COM to do some nice
things like increase the default environment size and make ECHO OFF the
default for all batch files.  All these patches had been posted on Usenet
before but usually for a single version of DOS.  I presented the patches
for several DOS versions 3.10 to 3.30, from IBM, Microsoft and Compaq.
In this posting I present the patches for versions: IBM PCDOS 3.30,
Microsoft MSDOS 3.30 and Compaq MSDOS 3.31.  In a companion posting to
this one, I present patches for IBM PCDOS 4.00, Microsoft MSDOS 4.00
and Microsoft MSDOS 4.01.


Of course many of these patches are no longer as useful since DOS now
provides other means of accomplishing the same things.  But some, myself
included, may still find these patches to be preferable.

Since DOS 3.10, you can set the size of the environment space by using
the /E parameter of COMMAND.COM (lest we forget, it's /E:xxxx where
xxxx is in 16 byte paragraphs for DOS 3.10 or bytes for 3.20 and up).
This is usually done by using SHELL= in the CONFIG.SYS file to specify
the string DOS uses to call COMMAND for the initial invocation.  The
drawback to this is that it only applies to the first, bottom level
shell.  If you run COMMAND again (without a /E) it will just use the
default size of 160 bytes (unless the environment is already bigger
than 160 bytes in which case it will use the environment size rounded
up to the next 16 bytes).  If you go into another program and "drop
down" into DOS or if you use a shell program to run DOS commands you
you are actually re-running COMMAND with the default environment size
and it won't be long before you get that "Out of environment space"
message.  It's amazing that DOS has gone so far without anybody doing
something about it (like making the default bigger or providing some
mechanism whereby the size specified in CONFIG.SYS would carry though
to all subsequent invocations of COMMAND).

Since DOS 3.30, you can prevent batch file lines from being displayed
by putting a '@' before them.  An '@echo off' as the first line will
prevent all lines in the file (including the 'echo off') from being
echoed.  This solution, while upwardly compatible, is just plain ugly.
Also it causes problems if you take you batch files to a system running
a lower version of DOS.

To produce a blank line, you can use 'echo' followed by an unprintable
character (such as DEL), which makes creating or editing the file more
difficult, but seems to work in any version of DOS.  Since some version
of DOS (not sure which), 'echo.' works, though I've never seen it
documented.  I include the 'echo-space' patch mainly for upward
compatibility.


Users please note that these patches have been tested rather perfunctorily
and should be used with some caution.  Definitely keep an unpatched copy
of COMMAND.COM on a bootable disk.  If you mess up your regular copy of
COMMAND.COM, you won't be able to boot with it;  you'll have to boot from
the floppy and copy the original COMMAND.COM over the messed up one before
you can reboot normally.

Following the presentation of the patches for the various DOS versions,
I list a couple of batch files I use for effecting the patches.  Following
that I list the dis-assembled code around the patched areas so that those
with DOS versions other than those shown will be able to find the proper
offsets.

Remember to add 100h to offsets when patching with DEBUG.


OFFSETS for patches to COMMAND.COM for IBM PCDOS 3.30 or COMPAQ PCDOS 3.31

Default environment size of 512 bytes
     [0DB8] = 0A 00 -> 20 00
(any size environment from 160 to 32768 bytes (000A to 0800 hex) can be
 made the default by coding the amount, divided by 16, in hexadecimal
 digits, at the address shown with the low order byte first)
ECHO OFF for AUTOEXEC.BAT
     [1204] = 03 -> 02
Echo off for batch files except AUTOEXEC.BAT
     [1C68] = 01 -> 00
ECHO produces blank line
     [3E29] = E8 20 00 74 -> 83 F9 01 72


COMMAND.COMs in IBM 3.30 and COMPAQ 3.31 appear to be identical except
for version no., identification and copyright strings.


OFFSETS for patch to COMMAND.COM for Microsoft MSDOS 3.30

Default environment size of 512 bytes
     [0DB8] = 0A 00 -> 20 00
ECHO OFF for AUTOEXEC.BAT
     [1205] = 03 -> 02
Echo off for batch files except AUTOEXEC.BAT
     [1C68] = 01 -> 00
ECHO produces blank line
     [3E29] = E8 20 00 74 -> 83 F9 01 72


Microsoft MSDOS 3.30 COMMAND.COM has some minor differences with IBM
PCDOS 3.30 (besides identification and copyright strings) and there is
one offset which is changed ([1205] instead of [1204]).


Following are two batch files PATCH.BAT and UNPATCH.BAT for installing
and un-installing the patches for IBM PC-DOS 3.30.  It should be easy
enough to modify this for other DOS 3 versions.

--------------------- PATCH.BAT for IBM PCDOS 3.30 --------------------
echo off
echo INSTALL COMMAND.COM PATCHS FOR IBM PC-DOS 3.30 OR COMPAQ PC-DOS 3.31
rem usage PATCH [filespec]
rem Patch 1. Default environment size is 512 bytes
rem Patch 2. ECHO OFF default for AUTOEXEC.BAT
rem Patch 3. ECHO OFF default for batch files except AUTOEXEC.BAT
rem Patch 4. ECHO-space produces blank line
if "%1"=="" goto :default
set $s=%1
echo About to modify %$s%
goto pause
:default
set $s=COMMAND.COM
echo About to modify %$s% in the default drive and directory
:pause
pause
if not exist %$s% goto error
echo Creating PATCH.TMP...
echo e0EB8 >patch.tmp
echo 20 00 >>patch.tmp
echo e1304 >>patch.tmp
echo 02 >>patch.tmp
echo e1D68 >>patch.tmp
echo 00 >>patch.tmp
echo e3F29 >>patch.tmp
echo 83 F9 01 72 >>patch.tmp
echo w >>patch.tmp
echo q >>patch.tmp
debug %$s% patch.tmp
echo 0A 00 >>patch.tmp
echo e1304 >>patch.tmp
echo 03 >>patch.tmp
echo e1D68 >>patch.tmp
echo 01 >>patch.tmp
echo e3F29 >>patch.tmp
echo E8 20 00 74 >>patch.tmp
echo w >>patch.tmp
echo q >>patch.tmp
debug %$s%    83F901     CMP  CX,+01
3576:3F2C 7409          JZ    3F37                 ->   7209       JB   3A26
3576:3F2E BA8200        MOV   DX,0082
3576:3F31 E810F1        CALL  3044
3576:3F34 E9AFF0        JMP   2FE6

Look for 'BA 82 00 E8'.


Good luck and let me know if you have problems with these patches.
-- 
John Wright      //////////////////     Phone:  902-424-3805  or  902-424-6527
Post: c/o Dr Pat Lane, Biology Dept, Dalhousie U, Halifax N.S., CANADA B3H-4H8 
Cdn/Eannet:lane@cs.dal.cdn  Uucp:lane@dalcs.uucp or {uunet watmath}!dalcs!lane
Arpa:lane%dalcs.uucp@uunet.uu.net  Internet:lane@cs.dal.ca

-- 
John Wright      //////////////////     Phone:  902-424-3805  or  902-424-6527
Post: c/o Dr Pat Lane, Biology Dept, Dalhousie U, Halifax N.S., CANADA B3H-4H8 
Cdn/Eannet:lane@cs.dal.cdn  Uucp:lane@dalcs.uucp or {uunet watmath}!dalcs!lane
Arpa:lane%dalcs.uucp@uunet.uu.net  Internet:lane@cs.dal.ca