prototype de la fonction
drawLine PROTO near C, ddsd:DWORD, x1:DWORD, y1:DWORD, x2:DWORD, y2:DWORD, color:DWORD
code de la fonction
drawLine PROC near C, ddsd:DWORD, x1:DWORD, y1:DWORD, x2:DWORD, y2:DWORD, color:DWORD
LOCAL boucle:WORD,w:WORD,h:WORD
; if dY>dX inverser axes
; if x1>x2 inverser (x1,y1),(x2,y2)
; err = 2dY-dX
; boucle = dX+1
; debut:
; dessiner (x,y)
; inc x
; if err>=0
; add err,dY-dX
; inc y
; else
; add err,dY
; endif
; dec boucle
; jnz debut
pushad
; if(!ddsd) return
mov esi,ddsd
and esi,esi
jz fin
; bx=y1 cx=y2
mov cx,word ptr y2
mov bx,word ptr y1
; dx = dY
mov dx,cx
sub dx,bx
jns @F
neg dx
@@:
shl edx,16
shl ecx,16
shl ebx,16
; bx=x1 cx=x2
mov cx,word ptr x2
mov bx,word ptr x1
; dx = dX
mov dx,cx
sub dx,bx
jns @F
neg dx
@@:
;- ebx = y1|x1
;- ecx = y2|x2
;- edx = dY|dX
; h=height w=width
mov eax,(drawDesc ptr [esi]).dwHeight
mov h,ax
mov eax,(drawDesc ptr [esi]).dwWidth
mov w,ax
; edi = inc_y|inc_x
mov di,ax
shl edi,18
inc di
shl di,2
; if(dX<=dY) inverser axes
mov eax,edx
shr eax,16
cmp ax,dx
jl @F
rol ebx,16
rol ecx,16
rol edx,16
rol edi,16
mov ax,w
xchg ax,h
mov w,ax
@@:
; if(x1>=x2) inverser (x1,y1),(x2,y2)
cmp bx,cx
jl @F
xchg ebx,ecx
@@:
; esi = dst = lpSurface+y1*inc_y+x1*inc_x
mov esi,(drawDesc ptr [esi]).lpSurface
push edx
mov eax,ebx
mov edx,edi
sar eax,16
sar edx,16
imul edx
add esi,eax
mov ax,bx
mov dx,di
shl eax,16
shl edx,16
sar eax,16
sar edx,16
imul edx
add esi,eax
pop edx
; if(y1>=y2) neg inc_y
rol ebx,16
rol ecx,16
cmp bx,cx
jl @F
rol edi,16
neg di
rol edi,16
@@:
rol ebx,16
rol ecx,16
; boucle = dX
mov ax,dx
inc ax
mov boucle,ax
;- ebx = y1|x1
;- edx = dY|dX
;- edi = inc_y|inc_x
;- esi = dst
; ecx = dY-dX|dY
mov ax,dx
rol edx,16
sub ax,dx
neg ax
mov cx,ax
shl ecx,16
mov cx,dx
rol edx,16
; dx = err = 2dY-dX
rol edx,16
mov ax,dx
shl ax,1
rol edx,16
sub ax,dx
mov dx,ax
;- ebx = y1|x1
;- ecx = dY-dX|dY
;- dx = err
;- edi = inc_y|inc_x
;- esi = dst
;- boucle
;- w
;- h
;- color
debut:
; if(x<0) continue
and bx,bx
js @F
; if(x>=w) continue
cmp bx,w
jge @F
; if(y<0) continue
mov eax,ebx
shr eax,16
and ax,ax
js @F
; if(y>=h) continue
cmp ax,h
jge @F
; dessiner (x,y)
mov eax,color
mov [esi],eax
@@:
; inc x
inc bx
mov ax,di
shl eax,16
sar eax,16
add esi,eax
; if(err>=0)
and dx,dx
js ben
bep:
; add err,dY-dX
mov eax,ecx
shr eax,16
add dx,ax
; inc y
mov eax,edi
sar eax,16
add esi,eax
rol edi,16
mov eax,10000h
and di,di
jns @F
neg eax
@@:
rol edi,16
add ebx,eax
jmp bes
ben:
; else
; add err,dY
add dx,cx
bes:
; endif
; boucle
dec boucle
jnz debut
fin:
popad
ret
drawLine ENDP