include	clib.inc
include	stdio.inc

GLOBAL	_iob:BYTE
lastiob	EQU (OFFSET _iob + (_NSTREAM_ * (SIZE S_FILE)))

PPROC	_getst
	mov	bx,OFFSET _iob
    _getst_00:
	mov	ax,[bx.iob_flag]
	and	ax,_IOREAD or _IOWRT or _IORW
	jnz	_getst_01
	mov	[bx.iob_cnt],ax
	mov	[bx.iob_flag],ax
	mov	WORD PTR [bx.iob_bp],ax
	MMOV	WORD PTR [bx.iob_bp+2],ax
	mov	WORD PTR [bx.iob_base],ax
	MMOV	WORD PTR [bx.iob_base+2],ax
	dec	ax
	mov	[bx.iob_file],ax
	mov	ax,bx
	mov	dx,ds
	jmp	_getst_02
    _getst_01:
	add	bx,SIZE S_FILE
	cmp	bx,lastiob
	jb      _getst_00
	xor	ax,ax
	cwd
    _getst_02:
	ret
PEND	_getst

	END
