include	clib.inc
include	io.inc
include	iost.inc
include	errno.inc
include	conio.inc
ifdef __TE__
include	clip.inc
endif
	public	oflush

_TEXT	SEGMENT

oflush	PROC	DIST
	push	si
	mov	si,OSTDO
	mov	ax,[si.ios_i]
	test	ax,ax
	jz	oflush_01
	mov	dx,[si.ios_flag]
	test	dx,IO_USECRC
	jnz	oflush_crc
  ifdef __TE__
	test	dx,IO_CLIPBOARD
	jnz	oflush_clipcopy
  endif
    oflush_write:
	push	[si.ios_file]
	pushm	[si.ios_bp]
	push	[si.ios_i]
	call	oswrite
    oflush_clip:
	cmp	ax,[si.ios_i]
	jne	oflush_error
	add	word ptr [si.ios_total],ax
	adc	word ptr [si.ios_total+2],0
	xor	ax,ax
	mov	[si.ios_c],ax
	mov	[si.ios_i],ax
	test	[si.ios_flag],IO_USEUPD
	jnz	oflush_update
    oflush_01:
	inc	ax
    oflush_end:
	pop	si
	ret
    oflush_update:
	inc	ax
	push	ax
	call	oupdate
	dec	ax
	jmp	oflush_01
    oflush_error:
	or	[si.ios_flag],IO_ERROR
	xor	ax,ax
	jmp	oflush_end
    oflush_crc:
	xor	dx,dx
	call	oupdcrc
	jmp	oflush_write
  ifdef __TE__
    oflush_clipcopy:
	pushm	[si.ios_bp]
	push	ax
	call	ClipboardCopy
	xor	ax,ax
	jmp	oflush_end
  endif
oflush	ENDP

_TEXT	ENDS

	END
