-
-
Save xoryouyou/1846195 to your computer and use it in GitHub Desktop.
Plasma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=/tmp/a;tail -n+2 $0|zcat>$a;chmod +x $a;$a;rm $a;exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plasma.final: plasma.stripped.gz loader | |
cat loader plasma.stripped.gz > plasma.final | |
chmod +x plasma.final | |
wc -c plasma.final | |
plasma.stripped.gz: plasma.stripped | |
gzip -n -c --best < plasma.stripped > plasma.stripped.gz | |
advdef -z -4 plasma.stripped.gz | |
plasma.stripped: plasma | |
cp plasma plasma.stripped | |
strip -s plasma.stripped | |
sstrip plasma.stripped | |
wc -c plasma.stripped | |
plasma: plasma.o | |
gold -x -s -dynamic-linker /lib/ld-linux.so.2 /usr/lib32/libSDL-1.2.so plasma.o -o plasma | |
plasma.o: plasma.asm | |
nasm -f elf32 plasma.asm | |
clean: | |
rm -f plasma.o plasma plasma.stripped plasma.stripped.gz plasma.final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BITS 32 | |
EXTERN SDL_SetVideoMode | |
EXTERN SDL_ShowCursor | |
EXTERN SDL_PollEvent | |
EXTERN SDL_Flip | |
EXTERN SDL_GetTicks | |
EXTERN SDL_Quit | |
SDL_FULLSCREEN equ 0x80000000 | |
SDL_NOFRAME equ 0x00000020 | |
; for easy scaling | |
WIDTH equ 640 | |
HEIGHT equ 480 | |
section .data | |
W: dd 640.0 | |
H: dd 480.0 | |
SECTION .bss | |
TIME: resd 1 | |
X: resq 1 | |
Y: resq 1 | |
R: resd 1 | |
G: resd 1 | |
B: resd 1 | |
SCREEN: RESD 1 | |
PIXELS: RESD 1 | |
EVENTS: RESD 20 ; sizeof(SDL_Event); | |
SECTION .text | |
GLOBAL _start | |
demostuff: | |
xor edx, edx | |
mov eax, ecx ; 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] | |
fild DWORD [TIME] | |
mov DWORD [R], 250 | |
fild DWORD [R] | |
fdivp | |
fld QWORD [X] | |
mov DWORD [R], 23 | |
fild DWORD [R] | |
fmulp | |
faddp | |
fsin | |
mov DWORD [R], 1 | |
fild DWORD [R] | |
faddp | |
mov DWORD [R], 127 | |
fild DWORD [R] | |
fmulp | |
fistp DWORD [R] | |
fild DWORD [TIME] | |
mov DWORD [G], 270 | |
fild DWORD [G] | |
fdivp | |
fld QWORD [Y] | |
mov DWORD [G], 7 | |
fild DWORD [G] | |
fmulp | |
faddp | |
fsin | |
mov DWORD [G], 1 | |
fild DWORD [G] | |
faddp | |
mov DWORD [G], 127 | |
fild DWORD [G] | |
fmulp | |
fistp DWORD [G] | |
fild DWORD [TIME] | |
mov DWORD [B], 280 | |
fild DWORD [B] | |
fdivp | |
fld QWORD [Y] | |
mov DWORD [B], -5 | |
fild DWORD [B] | |
fmulp | |
faddp | |
fld QWORD [X] | |
mov DWORD [B], -8 | |
fild DWORD [B] | |
fmulp | |
faddp | |
fsin | |
mov DWORD [B], 1 | |
fild DWORD [B] | |
faddp | |
mov DWORD [B], 127 | |
fild DWORD [B] | |
fmulp | |
fistp DWORD [B] | |
ret | |
_start: | |
push SDL_NOFRAME ; 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 | |
mov eax, [eax+20] ; surface->PIXELS | |
mov [PIXELS], eax | |
push 0x0 ; hide cursor | |
call SDL_ShowCursor | |
mainloop: | |
call SDL_GetTicks ; get current time | |
mov [TIME], eax | |
mov ecx, HEIGHT*WIDTH ; number of PIXELS to fill | |
mov edi, [PIXELS] ; adress of pixels | |
drawloop: | |
call demostuff | |
mov eax, [R] | |
shl eax, 8 | |
or eax, [G] | |
shl eax, 8 | |
or eax, [B] | |
stosd | |
loop 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment