home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast.iso
/
pcmag
/
vol10n20.zip
/
UMBFILES.ZIP
/
UMBFILES.ASM
< prev
next >
Wrap
Assembly Source File
|
1991-08-23
|
9KB
|
299 lines
;****************************************************************************
; UMBFILES extends the System File Table (SFT) that DOS uses to track
; the state of open files by creating an extension of the SFT in upper
; memory. The syntax is
;
; UMBFILES[=]nn
;
; where "nn" is the number of entries to be created in the SFT extension.
; For best results, boot your system with the statement FILES=8 in CONFIG.-
; SYS, and then allocate room for additional FILES with UMBFILES. For exam-
; ple, if you now boot with the statement FILES=40, change it to FILES=8 and
; add the statement UMBFILES=32 to your CONFIG.SYS file. The sum total of
; FILES and UMBFILES cannot exceed 255.
;
; Note: UMBFILES can only be used on 386 and 486 PCs that are running DOS
; 5.0 and are configured for loading TSRs and drivers in upper memory. To
; accomplish this, you must ensure that, at a minimum:
;
; 1) HIMEM.SYS is loaded
; 2) EMM386.EXE is loaded with a RAM or NOEMS parameter
; 3) CONFIG.SYS contains a DOS=UMB (or DOS=HIGH,UMB) statement
; 4) Your PC contains at least 384K of extended memory
;****************************************************************************
code segment
assume cs:code,ds:code
org 100h
begin: jmp main
copyright db "UMBFILES 1.0 Copyright (c) 1991 Jeff Prosise",13,10
db "First published in PC Magazine, November 26, 1991"
db 13,10,13,10
msg db "System File Table extended",13,10,"$"
helpmsg db "Builds an extension to the System File Table in "
db "upper memory.",13,10,13,10
db "UMBFILES[=]nn",13,10,13,10
db " nn Number of new SFT entries to create."
db 13,10,13,10
db "UMBFILES requires DOS 5.0 and a 386 or 486 PC "
db "configured for loading",13,10
db "programs and drivers in upper memory. The sum "
db "of FILES and UMBFILES",13,10
db "may not exceed 255.",13,10,"$"
errmsg1 db "Requires DOS 5.x",13,10,"$"
errmsg2 db "Syntax: UMBFILES[=]nn",13,10,"$"
errmsg3 db "Invalid parameter or parameter out of range",13,10
errmsg4 db "FILES plus UMBFILES cannot exceed 255",13,10,"$"
errmsg5 db "Invalid parameter (cannot be 0)",13,10,"$"
errmsg6 db "Upper Memory Area not available",13,10,"$"
errmsg7 db "Insufficient memory",13,10,"$"
umbfiles dw 0 ;Number of UMBFILES
strategy dw ? ;Memory allocation strategy
linkstat dw 0 ;Upper memory link status
last_offset dw ? ;Offset of final SFT header
last_segment dw ? ;Segment of final SFT header
sftlen dw ? ;Length of SFT extension
;****************************************************************************
; Procedure MAIN
;****************************************************************************
main proc near
cld ;Clear direction flag
mov si,81h ;Point SI to command line
call scanhelp ;Scan for "/?" switch
jnc main1 ;Branch if not found
mov ah,09h ;Display help text and exit
mov dx,offset helpmsg ; with ERRORLEVEL=0
int 21h
mov ax,4C00h
int 21h
;
; Check the DOS version and abort if it's not 5.x.
;
main1: mov ah,30h ;Get DOS version
int 21h
cmp al,5 ;Branch if the major version
mov dx,offset errmsg1 ; number is 5, abort if
je main2 ; it's not
error: mov ah,9 ;Display error message
int 21h
mov ax,4C01h ;Exit with ERRORLEVEL=1
int 21h
;
; Parse the command line to determine how many SFT entries to create.
;
main2: call findchar ;Advance to next character
mov dx,offset errmsg2 ;Error if EOL encountered
jc error
call asc2bin ;Convert ASCII to binary
mov dx,offset errmsg3 ;Error if carry is set on
jc error ; return
mov dx,offset errmsg5 ;Error if number was 0
or al,al
jz error
mov byte ptr umbfiles,al ;Save UMBFILES number
;
; Walk the chain of SFT headers to determine how many FILES already exist.
;
xor cx,cx ;Zero SFT entry count
mov ah,52h ;Get address of DOS's List
int 21h ; of Lists
mov di,es:[bx+4] ;Place address of first SFT
mov es,es:[bx+6] ; header in ES:DI
main3: mov last_offset,di ;Save the address of this
mov last_segment,es ; header
add cx,es:[di+4] ;Add number of SFT entries
; in this block
mov bx,es:[di] ;Place address of next SFT
mov es,es:[di+2] ; header in ES:DI and loop
mov di,bx ; if the offset address
cmp di,0FFFFh ; isn't equal to FFFFh
jne main3
add cx,umbfiles ;Verify that FILES plus
mov dx,offset errmsg4 ; UMBFILES is less than
cmp cx,255 ; 255 and abort if it's
ja error ; not
;
; Allocate an upper memory block to hold the SFT extension.
;
mov ax,5802h ;Get the current UMB link
int 21h ; status and save it
mov byte ptr linkstat,al
mov ax,5803h ;Set UMB link
mov bx,1
int 21h
mov dx,offset errmsg6 ;Error if carry returns set
jc error
mov ax,5800h ;Get the current memory
int 21h ; allocation strategy
mov strategy,ax ; code and save it
mov ax,5801h ;Change to high-only, best-
mov bx,41h ; fit allocation strategy
int 21h
mov dx,offset errmsg6 ;Error if carry returns set
jnc main4
error1: jmp error
main4: mov al,59 ;Compute the number of
mul byte ptr umbfiles ; paragraphs of memory
mov sftlen,ax ; required for the SFT
add ax,21 ; extension
mov cl,4
shr ax,cl
mov bx,ax
mov ah,48h ;Request the memory through
int 21h ; DOS function 48h
mov dx,offset errmsg7 ;Error if allocation request
jc error1 ; is denied
dec ax ;Point ES to MCB preceding
mov es,ax ; the memory block
mov word ptr es:[01h],08h ;Change owner ID to 08h
inc ax ;Point ES back to the block
mov es,ax ; itself
mov ax,5801h ;Restore original memory
mov bx,strategy ; allocation strategy
int 21h
mov ax,5803h ;Restore original UMB
mov bx,linkstat ; link status
xor bh,bh
int 21h
;
; Initialize the new SFT block and link it into the chain.
;
mov word ptr es:[00h],0FFFFh ;Initialize the
mov word ptr es:[02h],0000h ; SFT header
mov ax,umbfiles
mov word ptr es:[04h],ax
mov cx,sftlen ;Load CX with SFT length
xor al,al ;Fill the new SFT with
mov di,06h ; zeroes from start to
rep stosb ; finish
mov ax,es ;Place the address of the
mov di,last_offset ; new SFT header in the
mov es,last_segment ; header of the last
mov word ptr es:[di],00h ; one
mov word ptr es:[di+2],ax
;
; Display message verifying that the operation is completed, and then exit.
;
mov ah,09h ;Display message
mov dx,offset copyright
int 21h
mov ax,4C00h ;Exit with ERRORLEVEL=0
int 21h
main endp
;****************************************************************************
; SCANHELP scans the command line for a /? switch. If found, carry returns
; set and SI contains its offset. If not found, carry returns clear.
;****************************************************************************
scanhelp proc near
push si ;Save SI
scanloop: lodsb ;Get a character
cmp al,0Dh ;Exit if end of line
je scan_exit
cmp al,"?" ;Loop if not "?"
jne scanloop
cmp byte ptr [si-2],"/" ;Loop if not "/"
jne scanloop
add sp,2 ;Clear the stack
sub si,2 ;Adjust SI
stc ;Set carry and exit
ret
scan_exit: pop si ;Restore SI
clc ;Clear carry and exit
ret
scanhelp endp
;****************************************************************************
; FINDCHAR advances SI to the next non-white space character. On return,
; carry set indicates EOL was encountered; carry clear indicates it was not.
;****************************************************************************
findchar proc near
lodsb ;Get the next character
cmp al,09h ;Loop if tab
je findchar
cmp al,20h ;Loop if space
je findchar
cmp al,2Ch ;Loop if comma
je findchar
cmp al,3Dh ;Loop if equal sign
je findchar
dec si ;Point SI to the character
cmp al,0Dh ;Exit with carry set if end
je eol ; of line is reached
clc ;Clear carry and exit
ret
eol: stc ;Set carry and exit
ret
findchar endp
;****************************************************************************
; ASC2BIN converts a decimal number entered in ASCII form into a binary
; value in AL. Carry set on return indicates that an error occurred in
; the conversion.
;****************************************************************************
asc2bin proc near
sub ax,ax ;Initialize registers
sub bh,bh
mov dl,10
a2b_loop: mov bl,[si] ;Get a character
inc si
cmp bl,20h ;Exit if space
je a2b_exit
cmp bl,2Ch ;Exit if comma
je a2b_exit
cmp bl,0Dh ;Exit if carriage return
je a2b_exit
cmp bl,"0" ;Error if character is not
jb a2b_error ; a number
cmp bl,"9"
ja a2b_error
mul dl ;Multiply the value in AL by
jc a2b_error ; 10 and exit on overflow
sub bl,30h ;ASCII => binary
add ax,bx ;Add latest value to AX
cmp ax,255 ;Error if sum > 255
jna a2b_loop ;Loop back for more
a2b_error: dec si ;Set carry and exit
stc
ret
a2b_exit: dec si ;Clear carry and exit
clc
ret
asc2bin endp
code ends
end begin