Ligne sur ecran (1280x1024) avec souris

Description

Trace une ligne entre le centre de l'ecran (1280x1024) et la position de la souris

Source / Exemple :


.286
.SALL
.MODEL MEDIUM
.CODE
mondata		segment
imagea		db	1024 dup (?)
imageb		db	1024 dup (?)
imagec		db	1024 dup (?)
imaged		db	1024 dup (?)
imagee		db	1024 dup (?)
imagef		db	1024 dup (?)
imageg		db	1024 dup (?)
imageh		db	1024 dup (?)
xa		dw	0
ya		dw	0
xb		dw	0
yb		dw	0
x1		dw	0
y1		dw	0
x2		dw	0
y2		dw	0
dely		dw	0
delx		dw	0
delx_dely	dw	0
reste		dw	0
etat		dw	0
erreur		dw	0
mondata		ends
monstack	segment
		db	60 dup (0)
monstack	ends
moncode		segment
		assume		cs:moncode,ss:monstack,ds:mondata
ligne		proc near
		pusha
		mov	etat,0
		mov	ax,x1
		cmp	ax,x2
		jb	dropx
		shl	ax,1
		sub	ax,x2
		mov	x2,ax
		mov	ax,2
		or	etat,ax
dropx:		
		mov	ax,y1
		cmp	ax,y2
		jb	dropy
		shl	ax,1
		sub	ax,y2
		mov	y2,ax
		mov	ax,4
		or	etat,ax
dropy:		
		mov	ax,x2
		sub	ax,x1
		mov	delx,ax
		mov	ax,y2
		sub	ax,y1
		mov	dely,ax
		
		mov	ax,delx
		cmp	ax,dely
		jae	drg
		mov	ax,delx
		xchg	dely,ax
		mov	delx,ax
		mov	ax,y1
		xchg	x1,ax
		mov	y1,ax
		mov	ax,y2
		xchg	x2,ax
		mov	y2,ax
		mov	ax,1
		or	etat,ax
drg:		
		mov	ax,delx
		sub	ax,dely
		mov	delx_dely,ax
		mov	ax,delx
		shr	ax,1
		mov	cx,dely
		sub	cx,ax
		mov	erreur,cx
		mov	ax,x1
		mov	cx,y1
		mov	dx,x2
		mov	bx,y2
		mov	xa,ax
		mov	ya,cx
		mov	xb,dx
		mov	yb,bx
		mov	ax,delx
		inc	ax
		shr	ax,1
		mov	reste,ax
boucle:		
		mov	ax,2
		and	ax,etat
		jz	fdropx1
		mov	ax,x1
		shl	ax,1
		push	ax
		sub	ax,xa
		mov	xa,ax
		pop	ax
		sub	ax,xb
		mov	xb,ax
fdropx1:	
		mov	ax,4
		and	ax,etat
		jz	fdropy1
		mov	ax,y1
		shl	ax,1
		push	ax
		sub	ax,ya
		mov	ya,ax
		pop	ax
		sub	ax,yb
		mov	yb,ax
fdropy1:	
		mov	ax,1
		and	ax,etat
		jz	d2
		mov	dx,xa
		mov	cx,ya
		mov	ax,0ch
		call	affiche
		mov	dx,xb
		mov	cx,yb
		mov	ax,09h
		call	affiche
		jmp	d3
d2:		
		mov	cx,xa
		mov	dx,ya
		mov	ax,0ch
		call	affiche
		mov	cx,xb
		mov	dx,yb
		mov	ax,09h
		call	affiche
d3:		
		mov	ax,2
		and	ax,etat
		jz	fdropx2
		mov	ax,x1
		shl	ax,1
		push	ax
		sub	ax,xa
		mov	xa,ax
		pop	ax
		sub	ax,xb
		mov	xb,ax
fdropx2:	
		mov	ax,4
		and	ax,etat
		jz	fdropy2
		mov	ax,y1
		shl	ax,1
		push	ax
		sub	ax,ya
		mov	ya,ax
		pop	ax
		sub	ax,yb
		mov	yb,ax
fdropy2:	
		inc	xa
		dec	xb
		mov	ax,8000h
		and	ax,erreur
		cmp	ax,8000h
		je	saut
		inc	ya
		dec	yb
		mov	ax,delx_dely
		sub	erreur,ax
		jmp	suite
saut:		
		mov	ax,dely
		add	erreur,ax
suite:		
		dec	reste
		mov	ax,8000h
		and	ax,reste
		jz	boucle
		mov	ax,1
		and	ax,delx
		jz	finpro
		mov	ax,1
		and	ax,etat
		jz	d4
		mov	dx,xa
		mov	cx,ya
		mov	ax,0ah
		jmp	finpro
d4:		
		mov	cx,xa
		mov	dx,ya
		mov	ax,0ch
		call	affiche
finpro:		
		popa
		ret
ligne		endp
affiche		proc near
		pusha
		push	ds
		push	ax
		mov	ax,1280
		mov	bx,dx
		mov	dx,0
		mul	bx
		push	ax
		add	ax,cx
		pop	cx
		cmp	ax,cx
		jae	continue
		inc	dx
continue:	
		push	ax
		mov	ax,4f05h
		mov	bx,0
		int	10h
		mov	ax,0a000h
		mov	ds,ax
		pop	ax
		mov	si,ax
		pop	ax
		mov	[si],al
		pop	ds
		popa
		ret
affiche		endp
MainProc	proc far
		mov	ax,4f02h
		mov	bx,107h
		int	10h
		mov	ax,7
		mov	cx,0
		mov	dx,1279
		int	33h
		mov	ax,8
		mov	cx,0
		mov	dx,1023
		int	33h
		xor	ax,ax
		xor	cx,cx
		xor	bx,bx
		xor	dx,dx
ecrire:		
		mov	ax,3
		int	33h
		mov	al,00ah
		call	affiche
		mov	x1,640
		mov	y1,512
		mov	x2,cx
		mov	y2,dx
		call	ligne
		mov	ax,0b00h
		int	21h
		and	al,al
		je	ecrire
		mov	ax,04c00h
		int	21h
		ret
MainProc	endp
moncode		ends
		end MainProc

Conclusion :


La fonction ligne a un petit defaut pour une partie particuliere de l'ecran et n'est pas optimisee. Cependant l'algorithme qui trace la ligne est tres performant.Une mise à jour sera faite si quelqu'un me debarrasse de ce bug car je n'ais pas l'intention de le retravailler.

Pour l'utiliser:
Bouger la souris
Pour quitter:
Appuyer sur une touche

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.