home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix CD 2.0
/
Phoenix_CD.cdr
/
24b
/
getenvr.zip
/
GETENVR.ASM
next >
Wrap
Assembly Source File
|
1984-08-22
|
10KB
|
301 lines
page 58,132
title COMMAND.COM Environment Locator Program
name getenvr
;-----------------------------
; This Program consists of a driver MAIN procedure will display the
; the Segment Address of this programs copy of the Environment and
; the Segment Address of COMMAND.COM's Environment. The MAIN
; procedure will also print all the strings in COMMAND.COM's
; Environment.
; The principal procedure of this program is GET_ENV which returns
; the Segment Address of the active COMMAND.COM's Environment.
; There are two possibilities: (1) the active COMMAND.COM is the one
; which was loaded during the boot when the computer was turned on;
; or (2) a another COMMAND.COM which was loaded as a secondary
; command processor.
; The basic algorithm is first to locate the PSP Segment Address of
; the active command processor which is located at offsets 0ch, 10h
; and 14h in this program's PSP. (This program uses the one at offset
; 10h.) COMMAND.COM's PSP Segment Address is loaded in to the ES
; register and offset 2ch is read. If there is a non-zero value
; at this location, the active command processor is a secondary
; command processor, and the value stored at offset 2ch is the
; Segment Address of the active Environment. If the value at offset
; 2ch is 0, then the active command processor is the one loaded during
; the boot. In this case the (offset - 1) in paragraphs is stored at
; offset 3h in the paragraph of memory just in front of the boot
; COMMAND.COM. When this value is added to COMMAND.COM's PSP Segment
; Address, the active Environment Segment Address is obtained.
;
; Calling format for this program:
; getenvr
;
; System Requirements:
; Any version of PC-DOS (It was not tested on MS-DOS)
;
; This program may be freely used for private non-commercial use. It
; may be copied and distributed as long as no changes are make and no
; profit is made in its distribution (only cost for material may be
; charged).
;
; 21 July 1985 Raymond Moon
;
;------------------------------
; Updated 22 Aug 85 Raymond Moon
;
; DSEG_A alignment changed to "at 0000h" and is use to establish
; addresses for various variables located in GETENVR's PSP and
; COMMAND.COM's PSP.
subttl Data Segments
page ; Start new page for Data Segs
BASE group CSEG, DSEG_A ; Define Code and Data in the
; - same segment
;-----------------------------
; This program uses two Data Segments: DSEG_B supports only the
; procedure GET_ENV, and DSEG_A support the MAIN and other driver
; procedures. This is done so the data needed to support GET_ENV
; is easily distinguishable.
DSEG_A segment byte
;-----------------------------
; Define various variables
PRG_ENV_seg dw ?
ENV_offset dw ?
ENV_seg dw ?
COM_PSP dw ? ; Used by GET_ENV
PRGM_ENV dw ?
EOL_flag db 0
;-----------------------------
; Define various string constants
HEX db '0123456789abcdef' ; xlat table values
LOGO db 13,10,'Enviroment Finder V1.1 --- '
db 'MoonWare',13,10,10
db "COMMAND.COM's Environment Segment Address is "
COM_ADDR db 4 dup(20h),' hex.',13,10
db "This program's Environment Segment Address is "
PRGM_ADDR db 4 dup(20h),' hex.',13,10,10
db 'The Environment contains the following '
db 'strings:',13,10,10,'$'
CRLF db 13,10,'$'
db '***** 22 Aug 85 ----- Ray Moon *****'
DSEG_A ends
DSEG_B segment at 0000h ; Define various labels to
org 0003h ; - data in the PSP
ENV_offset_ptr dw ?
org 0010h
COM_PSP_ptr dw ?
org 002ch
ENV_seg_ptr dw ?
DSEG_B ends
subttl Code Segment
page ; Start new page for Code
CSEG segment para
;-----------------------------
; Set file for .COM file format and start MAIN procedure
org 100h ; .COM file format
assume cs:BASE,ds:BASE,es:DSEG_B,ss:BASE ; Establish addressability
MAIN proc near
;-----------------------------
; Get the Segment Address of this program's copy of the Enviroment
mov ax,ENV_seg_ptr ; Load Seg Addr ptr in AX
mov PRGM_ENV,ax ; Save it
xor al,al ; Zero low byte
xchg al,ah ; Load high byte in AL
push ax ; Load byte in STACK
call BIN2HEX ; Call conversion procedure
mov PRGM_ADDR,ah ; Store 1st hex char
mov PRGM_ADDR + 1,al ; Store 2nd hex char
mov ax,PRGM_ENV ; Load Seg Addr for 2nd xlat
xor ah,ah ; Zero high byte
push ax ; Load byte in STACK
call BIN2HEX ; Call conversion procedure
mov PRGM_ADDR + 2,ah ; Store 3rd hex char
mov PRGM_ADDR + 3,al ; Store 4th hex char
;-----------------------------
; Get the Segment address of COMMAND.COM's Environment
call GET_ENV ; Call GET_ENV procedure
mov ENV_seg,ax ; Save returned Seg Addr
xor al,al ; Zero low byte
xchg al,ah ; Load high byte in AL
push ax ; Load byte in STACK
call BIN2HEX ; Call conversion procedure
mov COM_ADDR,ah ; Store 1st hex char
mov COM_ADDR + 1,al ; Store 2nd hex char
mov ax,ENV_seg ; Load Seg Addr for 2nd xlat
xor ah,ah ; Zero high byte
push ax ; Load byte in STACK
call BIN2HEX ; Call conversion procedure
mov COM_ADDR + 2,ah ; Store 3rd hex char
mov COM_ADDR + 3,al ; Store 4th hex char
;-----------------------------
; Call the Print procedure and terminate the program
mov ax,ENV_seg ; Load Env seg addr in AX
push ax ; Pass it to PRINT proc
call PRINT ; Call the Print procedure
int 20h ; Return to DOS
MAIN endp
;-----------------------------
; BIN to(2) HEX conversion procedure
; - The byte to be converted is passed in the AL register
; - The two hex char are returned in the AX register
BIN2HEX proc near ; Define the start
mov bp,sp ; Move stack ptr to bp
mov dx,[bp + 2] ; Load passed byte to DX
;-----------------------------
; Convert the 1st byte
mov cl,4 ; Set the shift value
xor ah,ah ; Zero AH (just in case)
mov al,dl ; Get 1st hex digit
shr ax,cl ; Isolate it
lea bx,HEX ; Load the xlat table offset
xlat ; Convert it
mov dh,al ; Store it
;-----------------------------
; Convert 2nd byte
mov al,dl ; Get 2nd hex digit
shl ax,cl ; Isolate it
shr al,cl ; - finish isolation
xlat ; Convert it
;-----------------------------
; Set up for return, return, and end procedure
mov ah,dh ; Load high hex char
ret 2 ; Do what it says
BIN2HEX endp ; End of BIN2HEX procedure
;-----------------------------
; PRINT Procedure
PRINT proc near
;-----------------------------
; Print Logo and introductory information
mov ah,9 ; Request DOS string print
lea dx,LOGO ; Load LOGO addr in DX
int 21h ; Call PC-DOS
;-----------------------------
; Save DS register, get passed Seg Addr and Load in DS
push es ; Save ES
mov bp,sp ; Move stack ptr to BP
mov es,[bp + 4] ; Load passed addr in ES
;------------------------------
; Start printing char if not a 'nul' byte
mov bx,-1 ; Initialize BX
LINE: mov ah,2 ; Request DOS char print
CHAR: inc bx ; BX points to next char
mov dl,es:[bx] ; Load next char
cmp dl,0 ; Is it the 'nul' byte?
je NL ; Yes, jump to New Line
int 21h ; No, print char
mov EOL_flag,0 ; Clear EOL flag
jmp CHAR ; Process another char
;-----------------------------
; Check to see if it was the 2nd 'nul' byte signaling the end of the
; Environment. If not, just print CR,LF and return for another byte.
NL: cmp EOL_flag,1 ; Is this the 2nd 'nul' byte
jne EOL ; No, jump to CR,LF print
;-----------------------------
; Here is where this procedure returns. Restore DS and return.
pop es
ret 2
;-----------------------------
; Print CR,LF, set EOL flag, and return to print new line
EOL: mov ah,9 ; Request DOS string print
lea dx,CRLF ; Load CRLF addr in DX
int 21h ; Call PC-DOS
mov EOL_flag,1 ; Set EOL flag
jmp LINE ; Go back and start a new line
PRINT endp
page ; New page for major procedure
;-----------------------------
; This procedure locates the Segment Address of the active COMMAND.COM's
; Environment and returns it in AX
GET_ENV proc near
push es ; Save ES
;-----------------------------
; Get COMMAND.COM's PSP addr
mov ax,COM_PSP_ptr ; Load ptr to CMD.COM PSP
mov COM_PSP,ax ; Save it
mov es,ax ; ES now CMD.COM PSP
;-----------------------------
; Determine if COMMAND.COM is boot COMMAND.COM ([2c] = 0000h) or
; a secondary command processor ([2c] not 0000h).
mov ax,ENV_seg_ptr ; Get Envr ptr
cmp ax,0 ; Is it 'nul'?
je BOOT ; Yes, jump to BOOT
;-----------------------------
; Since [2c] is not zero, it is the segment address of the active
; Environment. Return it
pop es ; Restore ES
ret
;-----------------------------
; Active command processor is the boot version. Get segment address
; to its Environment. The offset in paragraphs is located at offset
; [3h] in the paragraph (16 bytes) ahead of the PSP.
BOOT: mov ax,es ; move PSP to AX
dec ax ; decriment AX
mov es,ax ; ES is now 1 para ahead of PSP
;-----------------------------
; Get Segment Address and return it
add ax,ENV_offset_ptr ; Add offset to PSP - 1
add ax,2 ; Correct it back to PSP
pop es ; Restore ES
ret ; Return to calling procedure
GET_ENV endp
;-----------------------------
; End Code Segment and End program
CSEG ends
end MAIN