getdrv  proc
	mov ah,19h
	int 21h
	mov ah,0
	ret
getdrv  endp

getfattr proc pascal filen:dword
  ifdef __LFN__
	mov al,_ifsmgr
	or al,al
  endif
	push ds
	lds dx,filen
	mov ax,4300h
  ifdef __LFN__
	jz getfattr_21
	stc
	mov ax,7143h
	mov bl,0
    getfattr_21:
  endif
	int 21h
	pop ds
	jc getfattr_err
	mov ax,cx
    getfattr_end:
	ret
    getfattr_err:
	call dosmaper
	mov ax,-1
	jmp getfattr_end
getfattr endp

filexist proc pascal filename:dword
	invoke getfattr, filename
	inc ax
	jz filexist_end
	dec ax      	; 1 = file
	and ax,_A_SUBDIR    ; 2 = subdir
	shr ax,4
	inc ax
    filexist_end:
	ret
filexist endp

lseek	proc pascal handle:word, offs:dword, pos:word
	mov ah,42h
	mov al,byte ptr pos
	mov bx,handle
	mov cx,word ptr offs+2	; CX:DX offset
	mov dx,word ptr offs
	int 21h
	jc lseek_error
	cmp dx,-1
	jne lseek_end
	cmp ax,-1
	je lseek_negseek
    lseek_end:
	ret
    lseek_negseek:
	xor cx,cx
	mov dx,cx
	mov ax,4200h
	int 21h
	mov ax,ER_NEGATIVE_SEEK
    lseek_error:
	call dosmaper
	mov ax,-1
	cwd
	jmp lseek_end
lseek	endp

remove	proc pascal filename:dword
  ifdef __LFN__
	push si
	mov al,_ifsmgr
	or al,al
  endif
	push ds
	lds dx,filename
	mov ah,41h
  ifdef __LFN__
	jz remove_int
	xor si,si
	stc
	xchg al,ah
    remove_int:
  endif
	int 21h
	pop ds
	jc remove_err
	xor ax,ax
    remove_end:
  ifdef __LFN__
	pop si
  endif
	ret
    remove_err:
	call dosmaper
	mov ax,-1
	jmp remove_end
remove	endp

dwdosdate proc
	mov ah,2Ah
	int 21h
	mov ax,cx
	sub ax,DT_BASEYEAR
	shl ax,9
	xchg ax,dx
	mov cl,al
	mov al,ah
	xor ah,ah
	shl ax,5
	xchg ax,dx
	or ax,dx
	or al,cl
	ret
dwdosdate endp

twdostime proc
	mov ah,2Ch	; CH = hour
	int 21h		; CL = minute
	xor ax,ax	; DH = second
	mov al,dh
	shr ax,1
	mov dx,ax	; second/2
	mov al,ch
	mov ch,ah
	shl cx,5
	shl ax,11
	or ax,cx
	or ax,dx	; hhhhhmmmmmmsssss
	ret
twdostime endp

osread	proc pascal handle:word, buffer:dword, bsize:word
	push ds
	mov ah,3Fh
	mov bx,handle
	mov cx,bsize
	lds dx,buffer
	int 21h
	pop ds
	jc osread_error
    osread_end:
	ret
    osread_error:
	call dosmaper
	xor ax,ax
	jmp osread_end
osread	endp
