Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; external functions from X11 library
- extern XOpenDisplay
- extern XDisplayName
- extern XCloseDisplay
- extern XCreateSimpleWindow
- extern XMapWindow
- extern XRootWindow
- extern XSelectInput
- extern XFlush
- extern XCreateGC
- extern XSetForeground
- extern XDrawLine
- extern XNextEvent
- ; external functions from stdio library (ld-linux-x86-64.so.2)
- extern printf
- extern exit
- %define StructureNotifyMask 131072
- %define KeyPressMask 1
- %define ButtonPressMask 4
- %define MapNotify 19
- %define KeyPress 2
- %define ButtonPress 4
- %define Expose 12
- %define ConfigureNotify 22
- %define CreateNotify 16
- %define QWORD 8
- %define DWORD 4
- %define WORD 2
- %define BYTE 1
- global main
- section .bss
- display_name: resq 1
- screen: resd 1
- depth: resd 1
- connection: resd 1
- width: resd 1
- height: resd 1
- window: resq 1
- gc: resq 1
- section .data
- event: times 24 dq 0
- x1: dd 0
- x2: dd 0
- y1: dd 0
- y2: dd 0
- x_neg: dd 0
- y_neg: dd 0
- z_neg: dd 0
- dist: dd 50
- Xoff: dd 200
- Yoff: dd 200
- Zoff: dd 30
- finalX: dd 0
- finalY: dd 0
- section .text
- ;##################################################
- ;########### PROGRAMME PRINCIPAL ##################
- ;##################################################
- main:
- xor rdi,rdi
- call XOpenDisplay ; Création de display
- mov qword[display_name],rax ; rax=nom du display
- ; display_name structure
- ; screen = DefaultScreen(display_name);
- mov rax,qword[display_name]
- mov eax,dword[rax+0xe0]
- mov dword[screen],eax
- mov rdi,qword[display_name]
- mov esi,dword[screen]
- call XRootWindow
- mov rbx,rax
- mov rdi,qword[display_name]
- mov rsi,rbx
- mov rdx,10
- mov rcx,10
- mov r8,400 ; largeur
- mov r9,400 ; hauteur
- push 0xFFFFFF ; background 0xRRGGBB
- push 0x00FF00
- push 1
- call XCreateSimpleWindow
- mov qword[window],rax
- mov rdi,qword[display_name]
- mov rsi,qword[window]
- mov rdx,131077 ;131072
- call XSelectInput
- mov rdi,qword[display_name]
- mov rsi,qword[window]
- call XMapWindow
- mov rsi,qword[window]
- mov rdx,0
- mov rcx,0
- call XCreateGC
- mov qword[gc],rax
- mov rdi,qword[display_name]
- mov rsi,qword[gc]
- mov rdx,0x000000 ; Couleur du crayon
- call XSetForeground
- boucle: ; boucle de gestion des évènements
- mov rdi,qword[display_name]
- mov rsi,event
- call XNextEvent
- cmp dword[event],ConfigureNotify ; à l'apparition de la fenêtre
- je dessin ; on saute au label 'dessin'
- cmp dword[event],KeyPress ; Si on appuie sur une touche
- je closeDisplay ; on saute au label 'closeDisplay' qui ferme la fenêtre
- jmp boucle
- global checkNeg
- checkNeg:
- ;edi position x
- ;esi position y
- cmp edi,0 ; compare la position x avec 0
- jl x_negat
- mov byte[x_neg],0
- jmp y_check
- x_negat:
- neg edi ; passe la valeur en positif
- mov byte[x_neg],1
- y_check:
- cmp esi,0
- jl y_negat
- jmp end
- y_negat:
- neg esi
- mov byte[y_neg],1
- end:
- ret
- global projectX
- projectX:
- ; edi = pos x
- ; esi = pos z
- ;X = (df*x)/(z+Zoff) + Xoff
- mov ebx,edi
- mov eax,[dist] ; dist = df
- imul word[ebx] ; eax = (df * x)
- add esi,Zoff ; z + zOff
- mov edx,0 ; division
- idiv esi ; eax / posZ
- cmp byte[x_neg],1 ; x == 1
- je x_negativ ; true : inverse eax et ajoute Xoff
- add eax,Xoff ; false : ajoute Xoff
- jmp end_x
- x_negativ:
- neg eax
- add eax,Xoff
- end_x:
- ;envoyer le resultat eax dans un registre
- ret
- global projectY
- projectY:
- ; edi = pos y
- ; esi = pos z
- ;Y = (df*y)/(z+Zoff) + Yoff
- mov ebx,edi
- mov eax,[dist]
- imul word[ebx]
- add esi,Zoff
- mov edx,0
- idiv esi
- cmp byte[y_neg],1
- je y_negativ
- add eax,Xoff
- jmp end_y
- y_negativ:
- neg eax
- add eax,Yoff
- end_y:
- ;envoyer le resultat eax dans un registre
- ret
- ;#########################################
- ;# DEBUT DE LA ZONE DE DESSIN #
- ;#########################################
- dessin:
- ; Calcule d'un point X: -100, Y: -100, Z: -100
- mov edi,-100 ; x = -100
- mov esi,-100 ; y = -100
- call checkNeg
- mov edi,-100 ; x = -100
- mov esi,-100 ; z = -100
- call projectX
- mov [x1],eax
- mov edi,-100 ; y = -100
- mov esi,-100 ; z = -100
- call projectY
- mov [y1],eax
- mov dword[x1],50
- mov dword[y1],50
- mov dword[x2],200
- mov dword[y2],350
- ; dessin de ligne
- mov rdi,qword[display_name]
- mov rsi,qword[window]
- mov rdx,qword[gc]
- mov ecx,dword[x1] ; coordonnée source en x
- mov r8d,dword[y1] ; coordonnée source en y
- mov r9d,dword[x2] ; coordonnée destination en x
- push qword[y2] ; coordonnée destination en y
- call XDrawLine
- mov dword[x1],50
- mov dword[y1],350
- mov dword[x2],200
- mov dword[y2],50
- ; dessin de ligne
- mov rdi,qword[display_name]
- mov rsi,qword[window]
- mov rdx,qword[gc]
- mov ecx,dword[x1] ; coordonnée source en x
- mov r8d,dword[y1] ; coordonnée source en y
- mov r9d,dword[x2] ; coordonnée destination en x
- push qword[y2] ; coordonnée destination en y
- call XDrawLine
- mov dword[x1],275
- mov dword[y1],50
- mov dword[x2],275
- mov dword[y2],350
- ; dessin de ligne
- mov rdi,qword[display_name]
- mov rsi,qword[window]
- mov rdx,qword[gc]
- mov ecx,dword[x1] ; coordonnée source en x
- mov r8d,dword[y1] ; coordonnée source en y
- mov r9d,dword[x2] ; coordonnée destination en x
- push qword[y2] ; coordonnée destination en y
- call XDrawLine
- mov dword[x1],350
- mov dword[y1],50
- mov dword[x2],350
- mov dword[y2],350
- ; dessin de ligne
- mov rdi,qword[display_name]
- mov rsi,qword[window]
- mov rdx,qword[gc]
- mov ecx,dword[x1] ; coordonnée source en x
- mov r8d,dword[y1] ; coordonnée source en y
- mov r9d,dword[x2] ; coordonnée destination en x
- push qword[y2] ; coordonnée destination en y
- call XDrawLine
- ; ############################
- ; # FIN DE LA ZONE DE DESSIN #
- ; ############################
- jmp flush
- flush:
- mov rdi,qword[display_name]
- call XFlush
- jmp boucle
- mov rax,34
- syscall
- closeDisplay:
- mov rax,qword[display_name]
- mov rdi,rax
- call XCloseDisplay
- xor rdi,rdi
- call exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement