home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / XP.ZIP / FINDENV.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-12-20  |  2.5 KB  |  73 lines

  1. ; Function to get the master command.com environment
  2. ; address and it's size.
  3. ;       char far *findEnv(unsigned int *size);
  4. ; For Turbo C 2.0, small/tiny model.
  5. ; Written and tested with Turbo Assembler 1.0
  6. ; By Goh King Hwa, 20 Dec 1989.
  7.  
  8. _TEXT segment byte public 'CODE'
  9.         assume cs:_TEXT
  10.  
  11. PID             EQU     1       ;offset of PID in MCB
  12. PSIZE           EQU     3       ;offset of block size in MCB
  13. PARENTID        EQU     22      ;offset of parent ID in PSP
  14.  
  15. _findEnv         proc near
  16.         push    bp
  17.         mov     bp,sp
  18.  
  19.         push    di
  20.         push    si
  21.         push    es
  22.         push    ds
  23.  
  24.         mov     ah,52h          ;DOS get list of lists
  25.         int     21h             ;ES:BX points to start of list
  26.         sub     bx,2
  27.         mov     ax,es:[bx]      ;load AX with first MCB segment address
  28.         mov     si,ax           ;si is used to keep track of the MCB
  29.         mov     ds,ax           ;get ready for BX
  30.  
  31.         xor     bx,bx           ;zero BX
  32.         mov     di,PARENTID     ;DI offsets to the parentid in the PSP
  33.         mov     cx,2            ;count
  34.  
  35. search:
  36.         mov     ax,[bx+PID]     ;PSP segment for process owning the MCB
  37.         mov     dx,si           ;note down the address of this MCB
  38.         mov     es,ax
  39. nextMCB:
  40.         add     si,[bx+PSIZE]   ;add the size of this MCB to last
  41.         inc     si              ;add one to point to next MCB
  42.         mov     ds,si           ;point to next MCB
  43. checkCom:
  44.         cmp     ax,es:[di]      ;for command.com parentid = pid of MCB
  45.         jne     search          ;continue search if not found
  46.         loop    search          ;the second time the 2 pid match,
  47.                                 ;we've found the master environment
  48. getSize:
  49.         mov     ds,dx           ;restore the last MCB segment
  50.         mov     ax,[bx+PSIZE]   ;get the size
  51.         shl     ax,1            ;ax = size in paragraph of
  52.         shl     ax,1            ;     master environment
  53.         shl     ax,1
  54.         shl     ax,1            ;ax * 16 = actual size in bytes
  55.         pop     ds              ;restore our C old data segment
  56.         mov     di,[bp+4]       ;get pointer to unsigned int
  57.         mov     [di],ax         ;save the size
  58.  
  59.         xor     ax,ax           ;zero AX
  60.         inc     dx              ;the paragraph following is the environment
  61.  
  62.         pop     es
  63.         pop     si
  64.         pop     di
  65.         pop     bp
  66.         ret
  67. _findEnv         endp
  68.  
  69. _TEXT ends
  70.  
  71. public  _findEnv
  72.         end
  73.