masm 像素碰撞检测
256 * 240 的 directx surface
_spriteDrawAndTest proc C _pBuffer, _pSprite, _xPos, _yPos, _pStruct, _AColor
; esp + 4 +32 esp + 8 + 32 esp + 12 + 32
option prologue:none, epilogue:none
;.FPO ( 0, 6, 0, 0, 0, 0 )
pBuffer equ [esp+36]
pSprite equ [esp+40]
xPos equ [esp+44]
yPos equ [esp+48]
pStruct equ [esp+52]
AColor equ [esp+56]
movd xmm7, esp
pushad ; - N save old frame
mov ebx, yPos ; - U ebx <- yPos
mov edi, pBuffer ; - V edi <- pBuffer
shl ebx, 10 ; - U * pitch 1024
mov eax, xPos ; - V eax <- xPos
mov esi, pSprite ; - U esi <- source pointer
lea edi, [edi+eax*4] ; - V add
mov ecx, pStruct ; - U struct ;
add edi, ebx ; - V save old frame
mov ebp, [ecx+4] ; - U rect.top
mov eax, [ecx] ; - V rect.left
mov ebx, AColor ; - U BG color
mov edx, ebp ; - V save old frame
mov esp, [ecx+16] ; - U pitch
lea esi, [esi+eax*4] ; - V add esi ++ =;das
imul edx, esp ; - N
lea esi, [esi+edx*4] ; - U esi comp
sub eax, [ecx+8] ; over x
sub ebp, [ecx+12] ; over y
; esi <- tex pointer
; edi <- des pointer
; eax <- rv x
; ebp <- rv y
; ebx <- color
; esp <- rv pitch
align 16
sub edi, 4 ; - U ready to copy ... - 4
mov ecx, eax ; - V save old frame ...
sub esp, 1024 ; - U rv pitch
align 16 ; - V align is may be a jmp opd ... :)
mn_main_loop:
mov edx, [edi+esi] ; - U load source pixel
add edi, 4 ; - V add inc to addring des pixel ...
cmp edx, ebx ; - U is BG color ?
jne next_test ; - V Y ? into mnc_nesc : next_test
mnc_nesc: ; BG color
inc eax ; - U x pos addring over ?
jne mn_main_loop ; - V Y ? into starting next line
add esi, esp ; - U add pitch
mov eax, ecx ; - V recover x cnt
inc ebp ; - U y pos addring over ?
jne mn_main_loop ; - V Y ? continue : child proc ret ...
movd esp, xmm7
popad
xor eax, eax ; no clash appear
ret
align 16
next_test:; not BG color ..
mov ecx, [edi] ; - U load des buffer pixel
mov [edi], edx ; - V write buffer ...
cmp ecx, ebx ; - U test clash
je mnc_nesc ; - V N clash appear ? continue mnc_nesc ...
inc eax ; - U else into no test clash's main_loop (clash has happend ...)
jne xmn_main_loop ; - V
add esi, esp ; - U
mov eax, ecx
inc ebp ; - U
je emd_end
align 16
xmn_main_loop:
mov edx, [esi+edi] ; - U load source pixel
add edi, 4 ; - V spare
cmp edx, ebx ; - U is BG color ?
jne no_BG ; - V
inc eax
jne xmn_main_loop
add esi, esp ; - U
mov eax, ecx
inc ebp
jne xmn_main_loop
xor eax, eax
jmp emd_end
align 16
no_BG:
mov [edi], edx
lea ecx, [ecx]
inc eax
jne xmn_main_loop
add esi, esp ; - U
mov eax, ecx
inc ebp ; - V
jne xmn_main_loop
emd_end:
movd esp, xmm7
popad
mov eax, 1 ; appear clash ...
ret
_spriteDrawAndTest endp