Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BITS 32
- EXTERN SDL_SetVideoMode
- EXTERN SDL_ShowCursor
- EXTERN SDL_PollEvent
- EXTERN SDL_Flip
- EXTERN SDL_GetTicks
- EXTERN SDL_Quit
- section .data
- W: dd 640.0
- H: dd 480.0
- msg: db "%i",10,0
- message_int: db "I-X:%i Y:%i",10,0
- message_float: db "F-X:%f Y:%f",10,0
- message_color: db "C-%i",10,0
- SECTION .bss
- ; for easy scaling
- WIDTH equ 640
- HEIGHT equ 480
- X: resq 1
- Y: resq 1
- R: resw 1
- G: resw 1 ; NEED ?!
- B: resw 1
- SCREEN: RESD 1
- PIXELS: RESD 1
- EVENTS: RESD 20 ; sizeof(SDL_Event);
- COUNT: RESD 1
- SECTION .text
- GLOBAL _start
- _start:
- push 0x20 ; push SDL_FULLSCREEN for fulSCREEN window, or SDL_NOFRAME for a borderless normal window
- push 32 ; BPP ( bits per pixel)
- push HEIGHT ; height
- push WIDTH ; width
- call SDL_SetVideoMode ; display window with those attributes
- mov [SCREEN], eax ; SDL_Surface pointer from screen
- ; Or use add eax, 20
- mov eax, [eax+20] ; surface->PIXELS
- mov [PIXELS], eax
- push 0x0 ; hide cursor
- call SDL_ShowCursor
- mainloop:
- ;call SDL_GetTicks ; get current time
- ;shr eax, 4 ; make it slower
- mov DWORD [COUNT], HEIGHT*WIDTH ; number of PIXELS to fill
- mov edi, [PIXELS] ; adress of pixels
- drawloop:
- push DWORD [COUNT] ; push location
- call calc_position
- add esp, 4
- call calc_color
- mov eax, [B] ; SDL COlor in SDl_Pixels.c SDL_MapRGB
- shl eax, 8
- or eax, [G]
- shl eax, 8
- or eax, [R]
- shl eax, 8
- mov DWORD [edi] , eax
- add edi, 4
- dec dword [COUNT]
- cmp dword [COUNT],0
- jnl drawloop
- push DWORD [SCREEN] ; push address of sdl screen surface
- call SDL_Flip ; flip the SCREEN
- add esp, 4 ; clean up stack
- push EVENTS ; push the events variable onto the stack
- call SDL_PollEvent ; get EVENTS and put them into the events variable
- add esp, 4 ; clean up stack
- cmp BYTE [EVENTS], 0x2 ; if event != SDL_KEYUP jump to mainloop
- jne mainloop ; if event = SDL_KEYUP continue execution(exit).
- exit: ; exit routine
- call SDL_Quit
- mov eax, 0x01
- xor ebx, ebx
- int 0x80
- calc_color:
- fld QWORD [X]
- mov DWORD [R], 255
- fild DWORD [R]
- fmulp st1, st0
- fistp WORD [R]
- fld QWORD [Y]
- mov DWORD [G], 255
- fild DWORD [G]
- fmulp st1, st0
- fistp WORD [G]
- ret
- calc_position:
- xor edx, edx ; init edx ,so we get no SIGFPE
- mov eax, [esp+4] ; get memory_location
- mov ebx, WIDTH ; prepare div
- div ebx ; eax = quotient | edx = remainder
- ; X+Y*W 400+300*800
- ; XPOS = (400+300*800) % 800 = 400
- ; YPOS = (400+300*800) / 800 = 300
- mov DWORD [X], edx ; load x position from register
- fild DWORD [X] ; load and convert x position to fpu stack
- fdiv DWORD [W] ; divide by WIDTH
- fstp QWORD [X] ; store result
- mov DWORD [Y], eax ; load y position from reg
- fild DWORD [Y]
- fdiv DWORD [H]
- fstp QWORD [Y]
- ret
Add Comment
Please, Sign In to add comment