Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; external functions from X11 library
  2. extern XOpenDisplay
  3. extern XDisplayName
  4. extern XCloseDisplay
  5. extern XCreateSimpleWindow
  6. extern XMapWindow
  7. extern XRootWindow
  8. extern XSelectInput
  9. extern XFlush
  10. extern XCreateGC
  11. extern XSetForeground
  12. extern XDrawLine
  13. extern XNextEvent
  14.  
  15. ; external functions from stdio library (ld-linux-x86-64.so.2)    
  16. extern printf
  17. extern exit
  18.  
  19. %define StructureNotifyMask 131072
  20. %define KeyPressMask        1
  21. %define ButtonPressMask     4
  22. %define MapNotify       19
  23. %define KeyPress        2
  24. %define ButtonPress     4
  25. %define Expose          12
  26. %define ConfigureNotify     22
  27. %define CreateNotify 16
  28. %define QWORD   8
  29. %define DWORD   4
  30. %define WORD    2
  31. %define BYTE    1
  32.  
  33. global main
  34.  
  35. section .bss
  36. display_name:   resq    1
  37. screen:         resd    1
  38. depth:          resd    1
  39. connection:     resd    1
  40. width:          resd    1
  41. height:         resd    1
  42. window:     resq    1
  43. gc:     resq    1
  44.  
  45.  
  46.  
  47. section .data
  48.  
  49. event:      times   24 dq 0
  50.  
  51. x1: dd  0
  52. x2: dd  0
  53. y1: dd  0
  54. y2: dd  0
  55.  
  56. x_neg:  dd 0
  57. y_neg:  dd 0
  58. z_neg:  dd 0
  59.  
  60. dist:   dd 50
  61. Xoff:   dd 200
  62. Yoff:   dd 200
  63. Zoff:   dd 30
  64.  
  65. finalX: dd 0
  66. finalY: dd 0
  67.  
  68. section .text
  69.    
  70. ;##################################################
  71. ;########### PROGRAMME PRINCIPAL ##################
  72. ;##################################################
  73.  
  74. main:
  75. xor     rdi,rdi
  76. call    XOpenDisplay    ; Création de display
  77. mov     qword[display_name],rax ; rax=nom du display
  78.  
  79. ; display_name structure
  80. ; screen = DefaultScreen(display_name);
  81. mov     rax,qword[display_name]
  82. mov     eax,dword[rax+0xe0]
  83. mov     dword[screen],eax
  84.  
  85. mov rdi,qword[display_name]
  86. mov esi,dword[screen]
  87. call XRootWindow
  88. mov rbx,rax
  89.  
  90. mov rdi,qword[display_name]
  91. mov rsi,rbx
  92. mov rdx,10
  93. mov rcx,10
  94. mov r8,400  ; largeur
  95. mov r9,400  ; hauteur
  96. push 0xFFFFFF   ; background  0xRRGGBB
  97. push 0x00FF00
  98. push 1
  99. call XCreateSimpleWindow
  100. mov qword[window],rax
  101.  
  102. mov rdi,qword[display_name]
  103. mov rsi,qword[window]
  104. mov rdx,131077 ;131072
  105. call XSelectInput
  106.  
  107. mov rdi,qword[display_name]
  108. mov rsi,qword[window]
  109. call XMapWindow
  110.  
  111. mov rsi,qword[window]
  112. mov rdx,0
  113. mov rcx,0
  114. call XCreateGC
  115. mov qword[gc],rax
  116.  
  117. mov rdi,qword[display_name]
  118. mov rsi,qword[gc]
  119. mov rdx,0x000000    ; Couleur du crayon
  120. call XSetForeground
  121.  
  122. boucle: ; boucle de gestion des évènements
  123. mov rdi,qword[display_name]
  124. mov rsi,event
  125. call XNextEvent
  126.  
  127. cmp dword[event],ConfigureNotify    ; à l'apparition de la fenêtre
  128. je dessin                           ; on saute au label 'dessin'
  129.  
  130. cmp dword[event],KeyPress           ; Si on appuie sur une touche
  131. je closeDisplay                     ; on saute au label 'closeDisplay' qui ferme la fenêtre
  132. jmp boucle
  133.  
  134.  
  135. global checkNeg
  136. checkNeg:
  137.     ;edi position x
  138.     ;esi position y
  139.    
  140.     cmp edi,0 ; compare la position x avec 0
  141.     jl x_negat
  142.     mov byte[x_neg],0
  143.     jmp y_check
  144.    
  145.    
  146.     x_negat:
  147.     neg edi ; passe la valeur en positif
  148.     mov byte[x_neg],1
  149.    
  150.     y_check:
  151.     cmp esi,0
  152.     jl y_negat
  153.     jmp end
  154.    
  155.     y_negat:
  156.     neg esi
  157.     mov byte[y_neg],1
  158.    
  159.     end:
  160.        
  161. ret
  162.  
  163.  
  164. global projectX
  165. projectX:
  166.     ; edi = pos x
  167.     ; esi = pos z
  168.    
  169.     ;X = (df*x)/(z+Zoff) + Xoff
  170.    
  171.     mov ebx,edi
  172.     mov eax,[dist]      ; dist = df
  173.     imul word[ebx]      ; eax = (df * x)
  174.     add esi,Zoff       ; z + zOff
  175.     mov edx,0          ; division
  176.     idiv esi           ; eax / posZ
  177.    
  178.     cmp byte[x_neg],1  ; x == 1
  179.     je x_negativ       ; true : inverse eax et ajoute Xoff
  180.     add eax,Xoff       ; false : ajoute Xoff
  181.     jmp end_x
  182.    
  183.     x_negativ:
  184.     neg eax
  185.     add eax,Xoff
  186.    
  187.     end_x:
  188.      ;envoyer le resultat eax dans un registre
  189.  
  190. ret
  191.  
  192.  
  193. global projectY
  194. projectY:
  195.     ; edi = pos y
  196.     ; esi = pos z
  197.    
  198.     ;Y = (df*y)/(z+Zoff) + Yoff
  199.    
  200.     mov ebx,edi
  201.     mov eax,[dist]
  202.     imul word[ebx]
  203.     add esi,Zoff
  204.     mov edx,0
  205.     idiv esi
  206.    
  207.     cmp byte[y_neg],1
  208.     je y_negativ
  209.     add eax,Xoff
  210.     jmp end_y
  211.    
  212.    
  213.     y_negativ:
  214.     neg eax
  215.     add eax,Yoff
  216.  
  217.     end_y:
  218.     ;envoyer le resultat eax dans un registre
  219.  
  220. ret
  221.  
  222.  
  223. ;#########################################
  224. ;#      DEBUT DE LA ZONE DE DESSIN       #
  225. ;#########################################
  226.  
  227.  
  228. dessin:
  229.  
  230. ; Calcule d'un point X: -100, Y: -100, Z: -100
  231. mov edi,-100    ; x = -100
  232. mov esi,-100    ; y = -100
  233. call checkNeg
  234. mov edi,-100    ; x = -100
  235. mov esi,-100    ; z = -100
  236. call projectX
  237. mov [x1],eax
  238. mov edi,-100    ; y = -100
  239. mov esi,-100    ; z = -100
  240. call projectY
  241. mov [y1],eax
  242.  
  243.  
  244.  
  245.  
  246. mov dword[x1],50
  247. mov dword[y1],50
  248. mov dword[x2],200
  249. mov dword[y2],350
  250. ; dessin de ligne
  251.  
  252. mov rdi,qword[display_name]
  253. mov rsi,qword[window]
  254. mov rdx,qword[gc]
  255. mov ecx,dword[x1]   ; coordonnée source en x
  256. mov r8d,dword[y1]   ; coordonnée source en y
  257. mov r9d,dword[x2]   ; coordonnée destination en x
  258. push qword[y2]      ; coordonnée destination en y
  259. call XDrawLine
  260.  
  261. mov dword[x1],50
  262. mov dword[y1],350
  263. mov dword[x2],200
  264. mov dword[y2],50
  265. ; dessin de ligne
  266.  
  267. mov rdi,qword[display_name]
  268. mov rsi,qword[window]
  269. mov rdx,qword[gc]
  270. mov ecx,dword[x1]   ; coordonnée source en x
  271. mov r8d,dword[y1]   ; coordonnée source en y
  272. mov r9d,dword[x2]   ; coordonnée destination en x
  273. push qword[y2]      ; coordonnée destination en y
  274. call XDrawLine
  275.    
  276. mov dword[x1],275
  277. mov dword[y1],50
  278. mov dword[x2],275
  279. mov dword[y2],350
  280. ; dessin de ligne
  281.  
  282. mov rdi,qword[display_name]
  283. mov rsi,qword[window]
  284. mov rdx,qword[gc]
  285. mov ecx,dword[x1]   ; coordonnée source en x
  286. mov r8d,dword[y1]   ; coordonnée source en y
  287. mov r9d,dword[x2]   ; coordonnée destination en x
  288. push qword[y2]      ; coordonnée destination en y
  289. call XDrawLine
  290.  
  291. mov dword[x1],350
  292. mov dword[y1],50
  293. mov dword[x2],350
  294. mov dword[y2],350
  295. ; dessin de ligne
  296.  
  297. mov rdi,qword[display_name]
  298. mov rsi,qword[window]
  299. mov rdx,qword[gc]
  300. mov ecx,dword[x1]   ; coordonnée source en x
  301. mov r8d,dword[y1]   ; coordonnée source en y
  302. mov r9d,dword[x2]   ; coordonnée destination en x
  303. push qword[y2]      ; coordonnée destination en y
  304. call XDrawLine
  305.  
  306. ; ############################
  307. ; # FIN DE LA ZONE DE DESSIN #
  308. ; ############################
  309. jmp flush
  310.  
  311. flush:
  312. mov rdi,qword[display_name]
  313. call XFlush
  314. jmp boucle
  315. mov rax,34
  316. syscall
  317.  
  318. closeDisplay:
  319.     mov     rax,qword[display_name]
  320.     mov     rdi,rax
  321.     call    XCloseDisplay
  322.     xor     rdi,rdi
  323.     call    exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement