home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix CD 2.0
/
Phoenix_CD.cdr
/
02a
/
pushpath.zip
/
PUSHPATH.ASM
< prev
next >
Wrap
Assembly Source File
|
1987-02-28
|
4KB
|
79 lines
;program pushpath. Reads the current path specification.
;Adds a carriage return the end of it. Writes the number of
;bytes including the carriage return at the beginning of it.
;Appends it to file E:\Path.dat, creating the file if necessary.
;Idea is that PopPath will read the file and reset the path.
cseg segment para public 'code'
push proc far
assume cs:cseg, ds:cseg, es:cseg, ss:cseg
org 100H ;for com file
start: push ds
mov ds, ds:002ch ;seg. address of environment
mov si,0 ;and its offset
search: mov di, offset pathflag ;look for 'PATH='
mov cx,5 ;length pathflag
repe cmpsb ;see if pathflag in env
je grab ;found pathflag
;if here, entry does not begin with pathflag. Look for
;the zero marking the end of the entry
findzero: lodsb ;look for zero
cmp al,0 ;is it zero?
je zero ;found a zero. A second?
jmp findzero ;loop till found
zero: cmp byte ptr ds:[si], 0 ;second zero?
je nofind ;path not in environment
jmp search ;keep looking
;here we found the path. Need to save it.
grab: mov cx,0 ;need counter
mov di, offset string
grabit: lodsb
cmp al,0 ;look for end of path entry
je haveit ;got to end of pathspec
inc cl ;count characters
stosb ;store the path spec
jmp grabit ;loop to get full pathspec
haveit: inc cl ;count includes final cr
mov al,cl
mov di, offset output
stosb
pop ds
push cx ;save length
;now mess around with the file
mov ah, 3DH ;function call, open file
mov dx, offset file ;address of fname
mov al, 2 ;open for read,write
int 21H ;open it
mov bx,ax ;save handle
jnc cont ;branch if successful
mov ah, 3CH ;if no file, create it
mov cx, 0 ;no attribute.
int 21H ;do it
mov bx,ax ;file handle to bx
cont: mov al,2 ;setup move to EOF
xor cx,cx ;zero cx -moving to at EOF
xor dx,dx ;zero dx-no offset
mov ah, 42H ;function call, move pointer
int 21H ;move it
;now write the path spec out, with length and cr
pop cx ;get string length back
inc cl ;outputting string + its length
mov dx, offset output ;set up right
mov ah, 40H ;function call, write string
int 21H ;do it
;now close the file. Handle should still be in bx
mov ah, 3EH ;function call, close
int 21H ;do it
jmp quit
nofind: pop ds
quit: int 20H ;return to DOS
push endp
file db 'C:\PATH.DAT'
endz db 2 dup(0)
pathflag db 'PATH='
output db 0
string db 128 dup (0dh)
cseg ends
end start