home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 24b / getenvr.zip / GETENVR.ASM next >
Assembly Source File  |  1984-08-22  |  10KB  |  301 lines

  1.     page 58,132
  2.     title COMMAND.COM Environment Locator Program
  3.     name getenvr
  4.  
  5. ;-----------------------------
  6. ;    This Program consists of a driver MAIN procedure will display the
  7. ;     the Segment Address of this programs copy of the Environment and
  8. ;        the Segment Address of COMMAND.COM's Environment.  The MAIN
  9. ;        procedure will also print all the strings in COMMAND.COM's
  10. ;     Environment.
  11. ;    The principal procedure of this program is GET_ENV which returns
  12. ;        the Segment Address of the active COMMAND.COM's Environment.
  13. ;    There are two possibilities: (1) the active COMMAND.COM is the one
  14. ;     which was loaded during the boot when the computer was turned on;
  15. ;     or (2) a another COMMAND.COM which was loaded as a secondary
  16. ;     command processor.
  17. ;    The basic algorithm is first to locate the PSP Segment Address of
  18. ;     the active command processor which is located at offsets 0ch, 10h
  19. ;        and 14h in this program's PSP.  (This program uses the one at offset
  20. ;        10h.)  COMMAND.COM's PSP Segment Address is loaded in to the ES
  21. ;     register and offset 2ch is read.  If there is a non-zero value
  22. ;     at this location, the active command processor is a secondary
  23. ;     command processor, and the value stored at offset 2ch is the
  24. ;     Segment Address of the active Environment.  If the value at offset
  25. ;     2ch is 0, then the active command processor is the one loaded during
  26. ;     the boot.  In this case the (offset - 1) in paragraphs is stored at
  27. ;     offset 3h in the paragraph of memory just in front of the boot
  28. ;        COMMAND.COM.  When this value is added to COMMAND.COM's PSP Segment
  29. ;     Address, the active Environment Segment Address is obtained.
  30. ;
  31. ;    Calling format for this program:
  32. ;        getenvr
  33. ;
  34. ;    System Requirements:
  35. ;        Any version of PC-DOS (It was not tested on MS-DOS)
  36. ;
  37. ;    This program may be freely used for private non-commercial use.  It
  38. ;     may be copied and distributed as long as no changes are make and no
  39. ;     profit is made in its distribution (only cost for material may be
  40. ;     charged).
  41. ;
  42. ;    21 July 1985                Raymond Moon
  43. ;
  44. ;------------------------------
  45. ;    Updated 22 Aug 85            Raymond Moon
  46. ;
  47. ;    DSEG_A alignment changed to "at 0000h"  and is use to establish
  48. ;    addresses for various variables located in GETENVR's PSP and 
  49. ;    COMMAND.COM's PSP.
  50.  
  51.     subttl    Data Segments
  52.     page                    ; Start new page for Data Segs
  53.  
  54. BASE    group    CSEG, DSEG_A            ; Define Code and Data in the
  55.                         ; - same segment
  56.  
  57. ;-----------------------------
  58. ;    This program uses two Data Segments:  DSEG_B supports only the
  59. ;     procedure GET_ENV, and DSEG_A support the MAIN and other driver
  60. ;     procedures.  This is done so the data needed to support GET_ENV
  61. ;     is easily distinguishable.
  62.  
  63. DSEG_A    segment byte
  64.  
  65. ;-----------------------------
  66. ;    Define various variables
  67.  
  68.     PRG_ENV_seg    dw    ?
  69.     ENV_offset    dw    ?
  70.     ENV_seg     dw    ?
  71.     COM_PSP     dw    ?        ; Used by GET_ENV
  72.     PRGM_ENV    dw    ?
  73.     EOL_flag    db    0
  74.  
  75. ;-----------------------------
  76. ;    Define various string constants
  77.  
  78.         HEX             db      '0123456789abcdef'      ; xlat table values
  79.         LOGO            db      13,10,'Enviroment Finder V1.1 --- '
  80.                         db      'MoonWare',13,10,10
  81.                         db      "COMMAND.COM's Environment Segment Address is "
  82.         COM_ADDR        db      4 dup(20h),' hex.',13,10
  83.                         db      "This program's Environment Segment Address is "
  84.         PRGM_ADDR       db      4 dup(20h),' hex.',13,10,10
  85.                         db      'The Environment contains the following '
  86.                         db      'strings:',13,10,10,'$'
  87.         CRLF            db      13,10,'$'
  88.                         db      '***** 22 Aug 85 ----- Ray Moon *****'
  89. DSEG_A    ends
  90.  
  91. DSEG_B    segment at 0000h            ; Define various labels to
  92.     org    0003h                ; - data in the PSP
  93.         ENV_offset_ptr  dw      ?
  94.     org    0010h
  95.     COM_PSP_ptr    dw    ?
  96.     org    002ch
  97.     ENV_seg_ptr    dw    ?
  98. DSEG_B    ends
  99.  
  100.     subttl    Code Segment
  101.     page                    ; Start new page for Code
  102.  
  103. CSEG    segment para
  104.  
  105. ;-----------------------------
  106. ;    Set file for .COM file format and start MAIN procedure
  107.  
  108.     org    100h                ; .COM file format
  109.     assume    cs:BASE,ds:BASE,es:DSEG_B,ss:BASE    ; Establish addressability
  110.  
  111. MAIN    proc    near
  112.  
  113. ;-----------------------------
  114. ;       Get the Segment Address of this program's copy of the Enviroment
  115.  
  116.     mov    ax,ENV_seg_ptr            ; Load Seg Addr ptr in AX
  117.     mov    PRGM_ENV,ax            ; Save it
  118.     xor    al,al                ; Zero low byte
  119.     xchg    al,ah                ; Load high byte in AL
  120.     push    ax                ; Load byte in STACK 
  121.     call    BIN2HEX             ; Call conversion procedure
  122.     mov    PRGM_ADDR,ah            ; Store 1st hex char
  123.     mov    PRGM_ADDR + 1,al        ; Store 2nd hex char
  124.     mov    ax,PRGM_ENV            ; Load Seg Addr for 2nd xlat
  125.     xor    ah,ah                ; Zero high byte
  126.     push    ax                ; Load byte in STACK
  127.     call    BIN2HEX             ; Call conversion procedure
  128.     mov    PRGM_ADDR + 2,ah        ; Store 3rd hex char
  129.     mov    PRGM_ADDR + 3,al        ; Store 4th hex char
  130.  
  131. ;-----------------------------
  132. ;       Get the Segment address of COMMAND.COM's Environment
  133.  
  134.     call    GET_ENV             ; Call GET_ENV procedure
  135.     mov    ENV_seg,ax            ; Save returned Seg Addr
  136.     xor    al,al                ; Zero low byte
  137.     xchg    al,ah                ; Load high byte in AL
  138.     push    ax                ; Load byte in STACK
  139.     call    BIN2HEX             ; Call conversion procedure
  140.     mov    COM_ADDR,ah            ; Store 1st hex char
  141.     mov    COM_ADDR + 1,al         ; Store 2nd hex char
  142.     mov    ax,ENV_seg            ; Load Seg Addr for 2nd xlat
  143.     xor    ah,ah                ; Zero high byte
  144.     push    ax                ; Load byte in STACK
  145.     call    BIN2HEX             ; Call conversion procedure
  146.     mov    COM_ADDR + 2,ah         ; Store 3rd hex char
  147.     mov    COM_ADDR + 3,al         ; Store 4th hex char
  148.  
  149. ;-----------------------------
  150. ;    Call the Print procedure and terminate the program
  151.  
  152.     mov    ax,ENV_seg            ; Load Env seg addr in AX
  153.     push    ax                ; Pass it to PRINT proc
  154.     call    PRINT                ; Call the Print procedure
  155.     int    20h                ; Return to DOS
  156. MAIN    endp
  157.  
  158. ;-----------------------------
  159. ;    BIN to(2) HEX conversion procedure
  160. ;    - The byte to be converted is passed in the AL register
  161. ;    - The two hex char are returned in the AX register
  162.  
  163. BIN2HEX proc    near                ; Define the start
  164.     mov    bp,sp                ; Move stack ptr to bp
  165.     mov    dx,[bp + 2]            ; Load passed byte to DX
  166.  
  167. ;-----------------------------
  168. ;    Convert the 1st byte
  169.  
  170.     mov    cl,4                ; Set the shift value
  171.     xor    ah,ah                ; Zero AH (just in case)
  172.     mov    al,dl                ; Get 1st hex digit
  173.     shr    ax,cl                ; Isolate it
  174.     lea    bx,HEX                ; Load the xlat table offset
  175.     xlat                    ; Convert it
  176.     mov    dh,al                ; Store it
  177.  
  178. ;-----------------------------
  179. ;    Convert 2nd byte
  180.  
  181.     mov    al,dl                ; Get 2nd hex digit
  182.     shl    ax,cl                ; Isolate it
  183.     shr    al,cl                ; - finish isolation
  184.     xlat                    ; Convert it
  185.  
  186. ;-----------------------------
  187. ;    Set up for return, return, and end procedure
  188.  
  189.     mov    ah,dh                ; Load high hex char
  190.     ret    2                ; Do what it says
  191. BIN2HEX endp                    ; End of BIN2HEX procedure
  192.  
  193. ;-----------------------------
  194. ;    PRINT Procedure
  195.  
  196. PRINT    proc    near
  197.  
  198. ;-----------------------------
  199. ;    Print Logo and introductory information
  200.  
  201.     mov    ah,9                ; Request DOS string print
  202.     lea    dx,LOGO             ; Load LOGO addr in DX
  203.     int    21h                ; Call PC-DOS
  204.  
  205. ;-----------------------------
  206. ;    Save DS register, get passed Seg Addr and Load in DS
  207.  
  208.     push    es                ; Save ES
  209.     mov    bp,sp                ; Move stack ptr to BP
  210.     mov    es,[bp + 4]            ; Load passed addr in ES
  211.  
  212. ;------------------------------
  213. ;       Start printing char if not a 'nul' byte
  214.  
  215.     mov    bx,-1                ; Initialize BX
  216. LINE:    mov    ah,2                ; Request DOS char print
  217. CHAR:    inc    bx                ; BX points to next char
  218.     mov    dl,es:[bx]             ; Load next char
  219.         cmp     dl,0                            ; Is it the 'nul' byte?
  220.     je    NL                ; Yes, jump to New Line
  221.     int    21h                ; No, print char
  222.     mov    EOL_flag,0            ; Clear EOL flag
  223.     jmp    CHAR                ; Process another char
  224.  
  225. ;-----------------------------
  226. ;       Check to see if it was the 2nd 'nul' byte signaling the end of the
  227. ;     Environment.  If not, just print CR,LF and return for another byte.
  228.  
  229. NL:     cmp     EOL_flag,1                      ; Is this the 2nd 'nul' byte
  230.     jne    EOL                ; No, jump to CR,LF print
  231.  
  232. ;-----------------------------
  233. ;    Here is where this procedure returns. Restore DS and return.
  234.  
  235.     pop    es
  236.     ret    2
  237.  
  238. ;-----------------------------
  239. ;    Print CR,LF, set EOL flag, and return to print new line
  240.  
  241. EOL:    mov    ah,9                ; Request DOS string print
  242.     lea    dx,CRLF             ; Load CRLF addr in DX
  243.     int    21h                ; Call PC-DOS
  244.     mov    EOL_flag,1            ; Set EOL flag
  245.     jmp    LINE                ; Go back and start a new line
  246. PRINT    endp
  247.  
  248.     page                    ; New page for major procedure
  249. ;-----------------------------
  250. ;       This procedure locates the Segment Address of the active COMMAND.COM's
  251. ;     Environment and returns it in AX
  252.  
  253. GET_ENV proc    near
  254.     push    es                ; Save ES
  255.  
  256. ;-----------------------------
  257. ;       Get COMMAND.COM's PSP addr
  258.  
  259.     mov    ax,COM_PSP_ptr            ; Load ptr to CMD.COM PSP
  260.     mov    COM_PSP,ax            ; Save it
  261.     mov    es,ax                ; ES now CMD.COM PSP
  262.  
  263. ;-----------------------------
  264. ;    Determine if COMMAND.COM is boot COMMAND.COM ([2c] = 0000h) or
  265. ;     a secondary command processor ([2c] not 0000h).
  266.  
  267.     mov    ax,ENV_seg_ptr            ; Get Envr ptr
  268.         cmp     ax,0                            ; Is it 'nul'?
  269.     je    BOOT                ; Yes, jump to BOOT
  270.  
  271. ;-----------------------------
  272. ;    Since [2c] is not zero, it is the segment address of the active
  273. ;     Environment.  Return it
  274.  
  275.     pop    es                ; Restore ES
  276.     ret
  277.  
  278. ;-----------------------------
  279. ;    Active command processor is the boot version.  Get segment address
  280. ;     to its Environment.  The offset in paragraphs is located at offset
  281. ;     [3h] in the paragraph (16 bytes) ahead of the PSP.
  282.  
  283. BOOT:    mov    ax,es                ; move PSP to AX
  284.     dec    ax                ; decriment AX
  285.     mov    es,ax                ; ES is now 1 para ahead of PSP
  286.  
  287. ;-----------------------------
  288. ;    Get Segment Address and return it
  289.  
  290.     add    ax,ENV_offset_ptr         ; Add offset to PSP - 1
  291.     add    ax,2                ; Correct it back to PSP
  292.     pop    es                ; Restore ES
  293.     ret                    ; Return to calling procedure
  294. GET_ENV endp
  295.  
  296. ;-----------------------------
  297. ;    End Code Segment and End program
  298.  
  299. CSEG    ends
  300.     end    MAIN
  301.