;---------------------------------------------------------------
;BLIT - Copy a rectangle to (x,y)
;	( w h x y -- )
code 'blit', blit

section .text

	push edx
	push edi
	call clip	;current position in ESI (temporarily in EDX)
	mov edx,edi
	call $at	;new position in EDI
	call clip
	upop ecx	;width in EAX, height in ECX

	call store_and_lock

	xchg esi,edx
.1	  push ecx
	  mov ecx,eax
	  rep movsb
	  mov ecx,dword [hp]
	  sub ecx,eax
	  add esi,ecx
	  add edi,ecx
	  pop ecx
	  loop .1
	xchg esi,edx
	pop edi
	pop edx
	drop

	call unlock_and_flip
next
