home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
os2ntree.zip
/
DOSCALLS.ASM
next >
Wrap
Assembly Source File
|
1988-03-01
|
9KB
|
434 lines
NAME DOSCALLS
TITLE DOSCALLS
PAGE 60,132
;
; This is coded for Microsoft C. The small memory model
; (for both _code and _data) are assumed. This is easily changed.
; This is for DOSNTREE.C
_data SEGMENT WORD PUBLIC 'data'
dgroup GROUP _data
_data ENDS
_text SEGMENT BYTE PUBLIC 'code'
igroup GROUP _text
ASSUME CS:igroup,DS:dgroup
; +-------------------------------------------------------------------+
; | dosfindfirst(filename,attribute) |
; | find first matching file |
; +-------------------------------------------------------------------+
public _dosfindfirst
_dosfindfirst proc near
push bp
mov bp,sp
mov dx,[bp+4] ; get filename string
mov cx,[bp+6] ; get attribute
mov ah,4EH ; find first file
int 21h ; call DOS
jc error_ret1 ; error return
xor ax,ax ; return 0 if OK
error_ret1: clc
pop bp
ret
_dosfindfirst endp
; +-------------------------------------------------------------------+
; | dosfindnext() |
; | returns next matching file |
; +-------------------------------------------------------------------+
public _dosfindnext
_dosfindnext proc near
push bp
mov bp,sp
mov ah,4FH ; find next file
int 21h ; call DOS
jc error_ret2 ; return error
xor ax,ax
error_ret2: clc
pop bp
ret
_dosfindnext endp
; +-------------------------------------------------------------------+
; | dossetdta(dta) |
; | set DTA to new location |
; +-------------------------------------------------------------------+
public _dossetdta
_dossetdta proc near
push bp
mov bp,sp
mov ah,2FH ; get current DTA
int 21h
push bx ; save (we assume our DS)
mov dx,[bp+4] ; get dta loc
mov ah,1AH ; set DTA
int 21h
pop ax ; restore DTA
pop bp
ret
_dossetdta endp
; +-------------------------------------------------------------------+
; | curdrive() |
; | Returns current disk drive |
; +-------------------------------------------------------------------+
public _curdrive
_curdrive proc near
push bp
mov bp,sp
mov ah,19h
int 21h
mov ah,0
inc al
pop bp
ret
_curdrive endp
; +-------------------------------------------------------------------+
; | getdir(drive,buf) |
; | gets directory of specified drive into buffer |
; +-------------------------------------------------------------------+
public _getdir
_getdir proc near
push bp
mov bp,sp
push si
mov dx,[bp+4]
mov si,[bp+6]
add si,3
mov ah,47h
int 21h
jc getdir_err
mov ax,[bp+4]
add al,'@'
mov si,[bp+6]
mov byte ptr ds:[si],al
inc si
mov byte ptr ds:[si],':'
inc si
mov byte ptr ds:[si],'\'
xor ax,ax
getdir_err: clc
pop si
pop bp
ret
_getdir endp
; +-------------------------------------------------------------------+
; | changedir(dir) |
; | changes drive and directory |
; +-------------------------------------------------------------------+
public _changedir
_changedir proc near
push bp
mov bp,sp
mov dx,[bp+4]
mov ah,3BH
int 21h
jc chdir_err
mov bx,[bp+4]
cmp byte ptr [bx+1],':' ; drive letter there?
je drv_let ; yes. change drive too
xor ax,ax
chdir_exit: pop bp
ret
drv_let: mov dl,byte ptr [bx]
sub dl,'A'
mov ah,0EH ; select disk
int 21h
xor ax,ax
jmp short chdir_exit
chdir_err: clc
jmp chdir_exit
_changedir endp
; +-------------------------------------------------------------------+
; | docopyfile(from,to) |
; | copy file from from to to |
; | errors returned: |
; | 1: error opening source file |
; | 2: error opening dest file |
; | 3: error reading source file |
; | 4: error writing dest file |
; | 5: error allocating memory |
; +-------------------------------------------------------------------+
public _docopyfile
_docopyfile proc near
push bp
mov bp,sp
push ds
cmp cs:alloced,0
jne do_it_now ; all set to go
mov ah,48h ; request memory
mov bx,1000h ; 64K of memory
mov cs:msize,bx ; save size
int 21h ; can we get it?
mov dx,0FFFFH ; this many usable
jnc got_mem
mov cs:msize,bx ; save size
push bx ; save amt read
mov ah,48h
int 21h ; get memory
jnc alloc_mem_ok ; couldn't do it.
jmp alloc_mem_err
alloc_mem_ok: pop dx
mov cl,4
shl dx,cl ; make bytes
got_mem: mov cs:msize,dx ; save memory size
mov cs:mstart,ax ; save memory
mov cs:alloced,1 ; set flag
do_it_now:
mov dx,[bp+4] ; get name
mov ah,3dh ; open file
mov al,0 ; read mode
int 21h ; try to open
jnc open_src_ok ; error opening source
jmp open_src_err
open_src_ok: mov cs:inhandle,ax ; save handle
mov dx,[bp+6] ; get out name
mov cx,0 ; normal file
mov ah,3ch ; create file
int 21h ; do it.
jc open_dst_err ; error opening dest
mov cs:outhandle,ax ; save handle.
; copy data in file
mov ax,word ptr cs:mstart ; get segment ptr
mov ds,ax
copy_loop: mov ah,3Fh ; read file
mov bx,cs:inhandle ; this one
mov cx,cs:msize ; this much
mov dx,0
int 21h ; do it.
jc read_src_err ; if errors...
cmp ax,0 ; at end of file?
je at_eof ; yup.
push ax
mov cx,ax ; prepare to write
mov bx,cs:outhandle ; output
mov ah,40H ; write to file
mov dx,0
int 21h ; do it.
pop bx
jc write_dst_err ; couldn't write
cmp ax,bx ; wrote the same amt read?
jne write_dst_err
jmp copy_loop
at_eof:
; copy creation date
mov bx,cs:inhandle
mov ah,57h ; get/set time
mov al,0 ; get time
int 21h ; get files time
jc read_src_err
mov ah,57h ; get/set
mov al,1 ; set
mov bx,cs:outhandle ; handle
int 21h ; set time
jc write_dst_err ; errors...
; close files
mov ah,3eh ; close
mov bx,cs:inhandle
int 21h
jc read_src_err ; error reading
mov ah,3eh ; close
mov bx,cs:outhandle
int 21h
jc write_dst_err
mov ax,0
copy_exit: pop ds
clc
pop bp
ret
open_src_err: mov ax,1
jmp short copy_exit
open_dst_err: mov ax,2
jmp short copy_exit
read_src_err: mov ax,3
jmp short copy_exit
write_dst_err: mov ax,4
jmp short copy_exit
alloc_mem_err: mov ax,5
jmp short copy_exit
alloced dw 0 ; have we alloced yet?
mstart dw 0 ; starting segment
msize dw 0 ; segment size (bytes)
inhandle dw 0 ; in file handle
outhandle dw 0 ; out file handle
_docopyfile endp
; +-------------------------------------------------------------------+
; | setverify(flg) |
; | sets verify flag |
; +-------------------------------------------------------------------+
public _setverify
_setverify proc near
push bp
mov bp,sp
mov ax,[bp+4]
mov ah,2EH
int 21h
pop bp
ret
_setverify endp
; +-------------------------------------------------------------------+
; | getverify() |
; | Return verify flag |
; +-------------------------------------------------------------------+
public _getverify
_getverify proc near
push bp
mov bp,sp
mov ah,54h
int 21h
mov ah,0
pop bp
ret
_getverify endp
; +-------------------------------------------------------------------+
; | doschmod(name,attr) |
; | change file mode |
; +-------------------------------------------------------------------+
public _doschmod
_doschmod proc near
push bp
mov bp,sp
mov dx,[bp+4]
mov cx,[bp+6]
mov ah,43h
int 21h
jc dc_err
xor ax,ax
dc_err: clc
pop bp
ret
_doschmod endp
; +-------------------------------------------------------------------+
; | clussize(drive) |
; | returns size of cluster in bytes |
; +-------------------------------------------------------------------+
public _clussize
_clussize proc near
push bp
mov bp,sp
push ds
mov dx,[bp+4] ; get drive
mov ah,1ch
int 21h ; get table info
pop ds
mov bx,ax ; save sec/alloc unit
mov bh,0 ; zap hi part
mov ax,cx ; get sec size
mul bx ; dxax = alloc unit size
mov dx,0 ; will be 0 anyways...
pop bp
ret
_clussize endp
_text ENDS
END