; Bitmaps to Mouse Cursors ASM, Copr. 1994 Matthias K”ppe

		LOCALS	@@
		JUMPS

	.286

CODE		SEGMENT BYTE PUBLIC

		ASSUME 	CS:CODE

		PUBLIC	DoBitmapToCursor

DoBitmapToCursor	PROC NEAR
		ARG	xormask: WORD, h: WORD, w: WORD, b: WORD, y: WORD, \
			x: WORD, dest: DWORD, source: DWORD = ArgSize
		LOCAL	msk: WORD, copy: WORD, zero: WORD = LocalSize
		enter	LocalSize, 0
		push	ds
		lds	si, source
		les	di, dest
		cld
		mov	bx, h			; source row count
		mov	dx, h
		shl	dx, 1			; dest col delta
		mov	cx, x
		and	cl, 15
		mov	ax, 0FFFFH	;!!
		jz	@@7
		shr	ax, cl
		not	ax
@@7:		mov	msk, ax			; last-word mask
		mov	cx, w
		shr	cx, 1			; dest word count
		mov	copy, cx
		dec	copy			; full copy word count
		mov	ax, x
		add	ax, 15
		shr	ax, 4			; source word count
		sub	cx, ax
		jns	@@6
		mov	cx, 0
@@6:		mov	zero, cx		; zero word count

		add	di, dx

@@2:    	sub	di, 2			; previous dest row
		push	si
		push	di
		push	bx

		mov	bx, xormask

		mov	cx, copy
		jcxz	@@3

@@1:		lodsw
		xor	ax, bx
		xchg	ah, al
		mov	es:[di], ax
		add	di, dx			; dest col delta
		loop	@@1

@@3:		lodsw
		xor	ax, bx
		xchg	ah, al
		and	ax, Msk
		mov	es:[di], ax
		add	di, dx			; dest col delta

		mov	cx, zero
		jcxz	@@4
		xor	ax, ax

@@5:		mov	es:[di], ax
		add	di, dx			; dest col delta
		loop	@@5

@@4:		pop	bx
		pop	di
		pop	si
		add	si, b			; next source row
		dec	bx
		jnz	@@2

		pop	ds
		mov	ax, w
		mul	h
		add	ax, WORD PTR dest
		mov	dx, es
		leave
		retn	ArgSize
DoBitmapToCursor	ENDP

CODE		ENDS

		END
