include	clib.inc
include	conio.inc

PPROC	rcopen, rect:dword, fl:word, at:word, ttl:dword, wp:dword
	test	fl,_D_MYBUF
	jnz	rcopen_00
	invoke	rcalloc,rect,fl
	stom	wp
	jz	rcopen_end
    rcopen_00:
	invoke	rcread,rect,wp
	mov	dx,fl
	and	dx,_D_CLEAR or _D_BACKG or _D_FOREG
	jz	rcopen_end
	les	bx,wp
	mov	al,rect.rc_row
	mul	rect.rc_col
	mov	cx,ax
	mov	al,byte ptr at
	cmp	dx,_D_CLEAR
	je	rcopen_clear
	cmp	dx,_D_COLOR
	je	rcopen_color
	cmp	dx,_D_BACKG
	je	rcopen_background
	cmp	dx,_D_FOREG
	je	rcopen_foreground
	mov	ah,al
	mov	al,' '
	call	@wcputw
	jmp	rcopen_title
    rcopen_clear:
	mov	ax,' '
	call	@wcputw
	jmp	rcopen_title
    rcopen_color:
	call	@wcputa
	jmp	rcopen_title
    rcopen_background:
	call	@wcputbg
	jmp	rcopen_title
    rcopen_foreground:
	call	@wcputfg
    rcopen_title:
	xor	cx,cx
	cmp	word ptr ttl,cx
	jz	rcopen_end
	mov	cl,rect.rc_col
	mov	ax,word ptr ttl
	mov	dx,word ptr ttl+2
	call	@wctitle
    rcopen_end:
	lodm	wp
	test	ax,ax
	ret
PEND	rcopen

	END
