include	clib.inc
include	io.inc

	public	_nfile
	public	_osfile

FH_TEXT	  = 80h
FH_OPEN	  = 01h
FH_DEVICE = 40h

_DATA	SEGMENT

_nfile	DW	_NFILE_
_osfile	DB	FH_OPEN or FH_DEVICE or FH_TEXT
	DB	FH_OPEN or FH_DEVICE or FH_TEXT
	DB	FH_OPEN or FH_DEVICE or FH_TEXT
	DB	FH_OPEN or FH_DEVICE
	DB	FH_OPEN or FH_DEVICE
	DB	_NFILE_ - 5 dup(0)

_DATA	ENDS

_TEXT	SEGMENT

_ioinit	PROC
	push	di
	push	si
	cmp	_nfile,5
	jbe	ioinit_03
	mov	es,_psp
	mov	di,29
	mov	si,OFFSET _osfile
	mov	cx,5
	add	si,cx
    ioinit_00:
	mov	al,es:[di]
	cmp	al,0FFh
	je	ioinit_01
	or	BYTE PTR [si],(FH_TEXT or FH_OPEN)
	mov	ax,4400h
	mov	bx,cx
	int	21h
	and	dx,128
	jz	ioinit_02
	or	BYTE PTR [si],FH_DEVICE
	jmp	ioinit_02
    ioinit_01:
	mov	BYTE PTR [si],0
    ioinit_02:
	inc	si
	inc	di
	inc	cx
	cmp	cx,_nfile
	jb	ioinit_00
    ioinit_03:
	pop	si
	pop	di
	ret
_ioinit	ENDP

_TEXT	ENDS

_INIT_	SEGMENT
	dw	_ioinit
_INIT_	ENDS

	END
