include	clib.inc
include	conio.inc

PPROC	rcframe, rc:dword, wstr:dword, lsize:word, ftype:word
local	tmp[8]:byte
	push	si
	push	di
	push	cx		; Preserve CX,BX,DX
	push	bx
	push	dx
	cld
	mov	ax,ftype	; AL = Type [0,6,12,18]
	mov     ah,00h		; AH = Attrib
	add	ax,offset frametypes
	mov	si,ax		;------------------------
	lodsw			; [BP-2] UL 'Ú'
	mov	[bp-2],ax	; [BP-1] HL 'Ä'
	lodsw			; [BP-4] UR '¿'
	mov	[bp-4],ax	; [BP-3] VL '³'
	lodsw			; [BP-6] LL 'À'
	mov	[bp-6],ax	; [BP-5] LR 'Ù'
	mov	ax,lsize	;------------------------
	mov	cl,al		; line size - 80 on screen
	add	al,al
	mul	rc.rc_y
	mov	dl,rc.rc_x
	mov	dh,00h
	add	ax,dx
	add	ax,dx
	les	di,wstr
	add	di,ax
	mov	ah,0
	mov	al,rc.rc_col
	sub	al,2
	mov	ch,al
	add	ax,ax
	mov	[bp-8],ax
	mov	ax,ftype
	mov	dl,rc.rc_row
	mov	si,dx
	mov	dl,cl
	add	dx,dx
	mov	bx,di
	mov	cl,1
	mov	al,[bp-2]	; Upper Left 'Ú'
	call	rcstosw
	mov	al,[bp-1]	; Horizontal Line 'Ä'
	mov	cl,ch
	call	rcstosw
	inc	cl
	mov	al,[bp-4]	; Upper Right '¿'
	call	rcstosw
	cmp	si,2
	jb	rcframe_end
	je	rcframe_01
	sub	si,2
    rcframe_00:
	add	bx,dx
	mov	di,bx
	inc	cl
	mov	al,[bp-3]	; Vertical Line '³'
	call	rcstosw
	add	di,[bp-8]
	inc	cl
	call	rcstosw
	dec	si
	jnz	rcframe_00
    rcframe_01:
	add	bx,dx
	mov	di,bx
	mov	cl,1
	mov	al,[bp-6]	; Lower Left 'À'
	call	rcstosw
	mov	al,[bp-1]	; Horizontal Line 'Ä'
	mov	cl,ch
	call	rcstosw
	inc	cl
	mov	al,[bp-5]	; Lower Right 'Ù'
	call	rcstosw
    rcframe_end:
	pop	dx
	pop	bx
	pop	cx
	pop	di
	pop	si
	ret
PEND	rcframe

_TEXT	SEGMENT

rcstosw:
	test	ah,ah
	jz	rcstosw_00
	stosw
	jmp	rcstosw_01
    rcstosw_00:
	stosb
	inc	di
    rcstosw_01:
	dec	cl
	jnz	rcstosw
	ret

_TEXT	ENDS

_DATA	SEGMENT

frametypes label byte
	db	'ÚÄ¿³ÀÙ'
	db	'ÉÍ»ºÈ¼'
	db	'ÂÄÂ³ÁÁ'
	db	'ÃÄ´³Ã´'

_DATA	ENDS

	END
