include	clib.inc
include	conio.inc
include	mouse.inc

_TEXT	SEGMENT

_FG_DEACTIVE	equ 	8

ifdef __CDECL__
	DRECT	equ 	[bp+ARG1]
	WCHAR	equ 	[bp+ARG1+4]
else
	WCHAR	equ 	[bp+ARG1]
	DRECT	equ 	[bp+ARG1+DPTRZ]
endif

SHADECOLS	equ 	word ptr [bp-2]
OFFSETBUFFER	equ 	word ptr [bp-4]
OFFSETSCREEN	equ 	word ptr [bp-6]
XCOUNT		equ	word ptr [bp-8]
WCOUNT		equ	word ptr [bp-10]

rcshade_init PROC
  ifdef __MOUSE__
	call	mousehide
  endif
	xor	ax,ax
	mov	dx,ax
	mov	cx,ax
	mov	al,_scrcol
	add	ax,ax
	mov	WCOUNT,ax
	mov	ax,dx
	mov	cl,DRECT.rc_row
	mov	al,DRECT.rc_col
	mov	XCOUNT,ax
	mov	SHADECOLS,dx
	add	al,DRECT.rc_x
	inc	al
	cmp	al,_scrcol
	ja	rcshade_init_01
	je      rcshade_init_00
	inc	SHADECOLS
    rcshade_init_00:
	inc	SHADECOLS
    rcshade_init_01:
	les	di,WCHAR
	mov	al,DRECT.rc_col
	mul	cl
	add	ax,ax
	add	di,ax
	mov	OFFSETBUFFER,di
	mov	bx,DRECT
	call	@rcsprc
	mov	ds,dx
	add	ax,WCOUNT
	add	ax,XCOUNT
	add	ax,XCOUNT
	inc	ax
	mov	dx,ax
	mov	OFFSETSCREEN,ax
	mov	ah,_FG_DEACTIVE
	ret
rcshade_init ENDP

_TEXT	ENDS

PPROC	rcsetshade, rc:dword, ws:DPTR
local	sshade[10]:byte
	push	ds
	push	si
	push	di
	call	rcshade_init
    rcsetshade_00:
	mov	si,dx
	add	dx,WCOUNT
	cmp	SHADECOLS,1
	jb	rcsetshade_01
	mov	al,[si]
	mov	es:[di],al
	mov	[si],ah
	je	rcsetshade_01
	mov	al,[si+2]
	mov	es:[di+1],al
	mov	[si+2],ah
    rcsetshade_01:
	add	di,2
	dec	cx
	jnz	rcsetshade_00
	mov	cx,XCOUNT
	dec	cx
	jz	rcsetshade_end
	dec	cx
	jz	rcsetshade_end
	mov	ah,_FG_DEACTIVE
	std
	sub	si,2
    rcsetshade_02:
	movsb
	mov	[si+1],ah
	dec	si
	add	di,2
	dec	cx
	jnz	rcsetshade_02
    rcsetshade_end:
  ifdef __MOUSE__
	call	mouseshow
  endif
	pop	di
	pop	si
	pop	ds
	ret
PEND	rcsetshade

PPROC	rcclrshade, rc2:dword, wc2:DPTR
local	sshade[10]:byte
	push	ds
	push	si
	push	di
	call	rcshade_init
    rcclrshade_00:
	mov	si,dx
	add	dx,WCOUNT
	cmp	SHADECOLS,1
	jb	rcclrshade_01
	mov	ax,es:[di]
	mov	[si],al
	je	rcclrshade_01
	mov	[si+2],ah
    rcclrshade_01:
	add	di,2
	dec	cx
	jnz	rcclrshade_00
	mov	cx,XCOUNT
	dec	cx
	jz	rcclrshade_end
	dec	cx
	jz	rcclrshade_end
    rcclrshade_02:
	sub	si,2
	mov	al,es:[di]
	mov	[si],al
	inc	di
	dec	cx
	jnz	rcclrshade_02
    rcclrshade_end:
  ifdef __MOUSE__
	call	mouseshow
  endif
	pop	di
	pop	si
	pop	ds
	ret
PEND	rcclrshade

	END
