Guest User

Untitled

a guest
Jun 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. BITS 32
  2.  
  3. EXTERN SDL_SetVideoMode
  4. EXTERN SDL_ShowCursor
  5. EXTERN SDL_PollEvent
  6. EXTERN SDL_Flip
  7. EXTERN SDL_GetTicks
  8. EXTERN SDL_Quit
  9.  
  10. section .data
  11.  
  12. W: dd 640.0
  13. H: dd 480.0
  14.  
  15. msg: db "%i",10,0
  16.  
  17. message_int: db "I-X:%i Y:%i",10,0
  18. message_float: db "F-X:%f Y:%f",10,0
  19. message_color: db "C-%i",10,0
  20.  
  21.  
  22.  
  23. SECTION .bss
  24.  
  25. ; for easy scaling
  26. WIDTH equ 640
  27. HEIGHT equ 480
  28.  
  29.  
  30. X: resq 1
  31. Y: resq 1
  32.  
  33. R: resw 1
  34. G: resw 1 ; NEED ?!
  35. B: resw 1
  36.  
  37. SCREEN: RESD 1
  38. PIXELS: RESD 1
  39. EVENTS: RESD 20 ; sizeof(SDL_Event);
  40. COUNT: RESD 1
  41.  
  42. SECTION .text
  43. GLOBAL _start
  44.  
  45.  
  46. _start:
  47. push 0x20 ; push SDL_FULLSCREEN for fulSCREEN window, or SDL_NOFRAME for a borderless normal window
  48. push 32 ; BPP ( bits per pixel)
  49. push HEIGHT ; height
  50. push WIDTH ; width
  51. call SDL_SetVideoMode ; display window with those attributes
  52. mov [SCREEN], eax ; SDL_Surface pointer from screen
  53. ; Or use add eax, 20
  54. mov eax, [eax+20] ; surface->PIXELS
  55. mov [PIXELS], eax
  56.  
  57. push 0x0 ; hide cursor
  58. call SDL_ShowCursor
  59.  
  60. mainloop:
  61.  
  62. ;call SDL_GetTicks ; get current time
  63. ;shr eax, 4 ; make it slower
  64.  
  65. mov DWORD [COUNT], HEIGHT*WIDTH ; number of PIXELS to fill
  66. mov edi, [PIXELS] ; adress of pixels
  67.  
  68. drawloop:
  69.  
  70.  
  71. push DWORD [COUNT] ; push location
  72. call calc_position
  73. add esp, 4
  74.  
  75. call calc_color
  76.  
  77.  
  78. mov eax, [B] ; SDL COlor in SDl_Pixels.c SDL_MapRGB
  79. shl eax, 8
  80. or eax, [G]
  81. shl eax, 8
  82. or eax, [R]
  83. shl eax, 8
  84.  
  85.  
  86.  
  87. mov DWORD [edi] , eax
  88. add edi, 4
  89.  
  90. dec dword [COUNT]
  91. cmp dword [COUNT],0
  92. jnl drawloop
  93.  
  94.  
  95.  
  96. push DWORD [SCREEN] ; push address of sdl screen surface
  97. call SDL_Flip ; flip the SCREEN
  98. add esp, 4 ; clean up stack
  99.  
  100. push EVENTS ; push the events variable onto the stack
  101. call SDL_PollEvent ; get EVENTS and put them into the events variable
  102. add esp, 4 ; clean up stack
  103.  
  104. cmp BYTE [EVENTS], 0x2 ; if event != SDL_KEYUP jump to mainloop
  105. jne mainloop ; if event = SDL_KEYUP continue execution(exit).
  106.  
  107. exit: ; exit routine
  108. call SDL_Quit
  109. mov eax, 0x01
  110. xor ebx, ebx
  111. int 0x80
  112.  
  113.  
  114. calc_color:
  115.  
  116. fld QWORD [X]
  117. mov DWORD [R], 255
  118. fild DWORD [R]
  119. fmulp st1, st0
  120. fistp WORD [R]
  121.  
  122. fld QWORD [Y]
  123. mov DWORD [G], 255
  124. fild DWORD [G]
  125. fmulp st1, st0
  126. fistp WORD [G]
  127.  
  128. ret
  129.  
  130.  
  131. calc_position:
  132.  
  133. xor edx, edx ; init edx ,so we get no SIGFPE
  134. mov eax, [esp+4] ; get memory_location
  135. mov ebx, WIDTH ; prepare div
  136. div ebx ; eax = quotient | edx = remainder
  137. ; X+Y*W 400+300*800
  138. ; XPOS = (400+300*800) % 800 = 400
  139. ; YPOS = (400+300*800) / 800 = 300
  140.  
  141. mov DWORD [X], edx ; load x position from register
  142.  
  143. fild DWORD [X] ; load and convert x position to fpu stack
  144. fdiv DWORD [W] ; divide by WIDTH
  145. fstp QWORD [X] ; store result
  146.  
  147. mov DWORD [Y], eax ; load y position from reg
  148. fild DWORD [Y]
  149. fdiv DWORD [H]
  150. fstp QWORD [Y]
  151.  
  152. ret
Add Comment
Please, Sign In to add comment