home *** CD-ROM | disk | FTP | other *** search
- ; Function to get the master command.com environment
- ; address and it's size.
- ; char far *findEnv(unsigned int *size);
- ; For Turbo C 2.0, small/tiny model.
- ; Written and tested with Turbo Assembler 1.0
- ; By Goh King Hwa, 20 Dec 1989.
-
- _TEXT segment byte public 'CODE'
- assume cs:_TEXT
-
- PID EQU 1 ;offset of PID in MCB
- PSIZE EQU 3 ;offset of block size in MCB
- PARENTID EQU 22 ;offset of parent ID in PSP
-
- _findEnv proc near
- push bp
- mov bp,sp
-
- push di
- push si
- push es
- push ds
-
- mov ah,52h ;DOS get list of lists
- int 21h ;ES:BX points to start of list
- sub bx,2
- mov ax,es:[bx] ;load AX with first MCB segment address
- mov si,ax ;si is used to keep track of the MCB
- mov ds,ax ;get ready for BX
-
- xor bx,bx ;zero BX
- mov di,PARENTID ;DI offsets to the parentid in the PSP
- mov cx,2 ;count
-
- search:
- mov ax,[bx+PID] ;PSP segment for process owning the MCB
- mov dx,si ;note down the address of this MCB
- mov es,ax
- nextMCB:
- add si,[bx+PSIZE] ;add the size of this MCB to last
- inc si ;add one to point to next MCB
- mov ds,si ;point to next MCB
- checkCom:
- cmp ax,es:[di] ;for command.com parentid = pid of MCB
- jne search ;continue search if not found
- loop search ;the second time the 2 pid match,
- ;we've found the master environment
- getSize:
- mov ds,dx ;restore the last MCB segment
- mov ax,[bx+PSIZE] ;get the size
- shl ax,1 ;ax = size in paragraph of
- shl ax,1 ; master environment
- shl ax,1
- shl ax,1 ;ax * 16 = actual size in bytes
- pop ds ;restore our C old data segment
- mov di,[bp+4] ;get pointer to unsigned int
- mov [di],ax ;save the size
-
- xor ax,ax ;zero AX
- inc dx ;the paragraph following is the environment
-
- pop es
- pop si
- pop di
- pop bp
- ret
- _findEnv endp
-
- _TEXT ends
-
- public _findEnv
- end
-