Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

save & restore environment (Developers)

posted by bencollver Homepage, 08.03.2026, 00:45

I reduced it to a test case.
COMMAND.COM is from EDR DOS 20250427
CMD701.COM is from Caldera OpenDOS 7.01

C:\>type test.bat
SET D=-dTCC_TARGET_PE -dTCC_TARGET_I386
SET D=-DTCC_TARGET_PE -DTCC_TARGET_I386
SET

C:\>command.com /c test.bat
OS=DRDOS
VER=7
COMSPEC=C:\COMMAND.COM
TEMP=C:\TEMP
NLSPATH=C:\SVARDOS\NLS
WATTCP.CFG=C:\SVARDOS
PATH=C:\SVARDOS;C:\CWSDPMI;C:\UNZIP32;C:\V8POWER;C:\WHICH
PROMPT=$P$G
LANG=EN
DOS32A=/QUIET
D=-dTCC_TARGET_PE -dTCC_TARGET_I386
D=-DTCC_TARGET_PE -DTCC_TARGET_I386

C:\>cmd701.com /c test.bat
OS=DRDOS
VER=7
COMSPEC=C:\COMMAND.COM
TEMP=C:\TEMP
NLSPATH=C:\SVARDOS\NLS
WATTCP.CFG=C:\SVARDOS
PATH=C:\SVARDOS;C:\CWSDPMI;C:\UNZIP32;C:\V8POWER;C:\WHICH
PROMPT=$P$G
LANG=EN
DOS32A=/QUIET
D=-DTCC_TARGET_PE -DTCC_TARGET_I386


If i run the script in DEBUG.COM, it gives a 3rd version of the output:

C:\>debug command.com /c test.bat
- g
OS=DRDOS
VER=7
COMSPEC=C:\COMMAND.COM
TEMP=C:\TEMP
NLSPATH=C:\SVARDOS\NLS
WATTCP.CFG=C:\SVARDOS
PATH=C:\SVARDOS;C:\CWSDPMI;C:\UNZIP32;C:\V8POWER;C:\WHICH
PROMPT=$P$G
LANG=EN
DOS32A=/QUIET
D=-dTCC_TARGET_PE -dTCC_TARGET_I386

Program terminated normally (0000)
-


This discouraged me because i was hoping to use DEBUG.COM to trace what was happening within COMMAND.COM.

Oddly, if i edit test.bat and change the variable name, then i can no longer reproduce the problem even on EDR DOS COMMAND.COM. It creates a duplicate environment variable named D, but will not produce one named A, B, C, E, or even DD.

p.s.

I compared OpenDOS 7.01 COMMAND.COM with EDR DOS 20250427.

command\csup.asm get_key has only one difference.
So far as i can tell, it should work the same.

--- old-getkey.asm      2026-03-07 14:40:31.343231149 -0800
+++ new-getkey.asm      2026-03-07 14:40:54.172230574 -0800
@@ -8,7 +8,7 @@
        push ds
        pop es                          ; Calculate the length of the
        mov     di,04[bp]               ; key by scaning the string for
-       mov     al,0                    ; a zero byte.
+       xor     al,al                   ; a zero byte.
        mov     cx,-1
        repnz   scasb
        neg     cx                      ; CX is the length of the sting + 2


command\csup.asm env_del has only one difference.
So far as i can tell, it should work the same.

--- old-envdel.txt      2026-03-07 14:10:03.196277219 -0800
+++ new-envdel.txt      2026-03-07 14:10:24.636276679 -0800
@@ -28,7 +28,7 @@
 env_d15:
        lodsb
        stosb                           ; Copy through AL checking for the end
-       or      al,al
+       test    al,al
        jnz     env_d15                 ; of the environment after each
        jmps    env_d10                 ; end of string.
 env_d20:



After converting the spacing
command\comint.c cmd_set has a couple of differences,
after converting to ANSI C and fixing the indentation.

--- old-cmdset.txt      2026-03-07 14:01:29.396290167 -0800
+++ new-cmdset.txt      2026-03-07 13:42:03.099319559 -0800
@@ -46,8 +46,6 @@
       syntax();             /* or the '=' is missing return */
       return;
    } /* a syntax error.                */
-       
-   s++;
 
 #if 0
        /* msdos doesn't do this */
@@ -67,7 +65,9 @@
       crlfflg = YES;
       return;
    }
-   if ( (*s-- = c) != 0 ) {     /* Add the definition to the end*/
+   *s++ = c;
+
+   if ( *s != 0 ) { /* Add the definition to the end*/
       /* of the environment if the new*/
       if ( env_ins( key ) ) {   /* definition is not NULL      */
          printf( MSG_ENVFULL ); /* check for an error.         */



The asm PROC get_key begins with:

1E push ds
07 pop es
?? mov di,04[bp]
?? xor al,al


COMMAND.COM is 63601 bytes large (F871)

    C:\>debug command.com /c test.bat
    -s 100 l F871 1E 07
    1954:20D2
    1954:22B3
    1954:242D
    1954:2440
    1954:3D2A
    1954:2E26
    1954:408B
    1954:40A1
    1954:40E3
    1954:4109
    1954:4140
    1954:4156
    1954:42A9
    1954:446A
    1954:B262


Unassembling these offsets, only one matches the PROC get_key signature.

    -u 1954:3D2A
    1954:3D2A 1E                PUSH    DS
    1954:3D2B 07                POP     ES
    1954:3D2C 8B7E04            MOV     DI,[BP+04]
    1954:3D2F 32C0              XOR     AL,AL
    1954:3D31 B9FFFF            MOV     CX,FFFF
    1954:3D34 F2AE              REPNE   SCASB
    1954:3D36 F7D9              NEG     CX
    1954:3D38 83E902            SUB     CX,+02
    1954:3D3B 8BD1              MOV     DX,CX
    1954:3D3D 33C0              XOR     AX,AX
    1954:3D3F 8EC3              MOV     ES,BX
    1954:3D41 33FF              XOR     DI,DI
    1954:3D43 57                PUSH    DI
    1954:3D44 8BCA              MOV     CS,DX
    1954:3D46 8B7604            MOV     SI,[BP+04]
    1954:3D49 F3A6              REPE    CMPSB

 

Complete thread:

Back to the forum
Board view  Mix view
23247 Postings in 2191 Threads, 405 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum