From 69f68d1bb20a1e5817bade94128ced396a7ab8cf Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Tue, 5 Dec 2017 06:29:38 +0000 Subject: [PATCH] Firework: add AVX, AVX2 and AVX512 code (default is SSE as before). git-svn-id: svn://kolibrios.org@7125 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/demos/firework/trunk/aspapi.inc | 139 ---- programs/demos/firework/trunk/firework.asm | 698 ++++++++++++--------- programs/demos/firework/trunk/proc32.inc | 268 -------- 3 files changed, 384 insertions(+), 721 deletions(-) delete mode 100644 programs/demos/firework/trunk/aspapi.inc delete mode 100644 programs/demos/firework/trunk/proc32.inc diff --git a/programs/demos/firework/trunk/aspapi.inc b/programs/demos/firework/trunk/aspapi.inc deleted file mode 100644 index f6f7de0dd4..0000000000 --- a/programs/demos/firework/trunk/aspapi.inc +++ /dev/null @@ -1,139 +0,0 @@ -include 'proc32.inc' - -macro start_draw_window x,y,xsize,ysize,areacolor,caption;,capsize -{ - ;pusha - mov eax, 12 ; function 12:tell os about windowdraw - mov ebx, 1 ; 1, start of draw - int 0x40 - ; DRAW WINDOW - mov eax, 0 ; function 0 : define and draw window - mov ebx, x*65536+xsize ; [x start] *65536 + [x size] - mov ecx, y*65536+ysize ; [y start] *65536 + [y size] - mov edx, areacolor ; color of work area RRGGBB - mov esi, 0x00334455 ; color of grab bar RRGGBB - mov edi, 0x00ddeeff ; color of frames RRGGBB - int 0x40 - ; WINDOW LABEL - ;mov eax, 4 ; function 4 : write text to window - ;mov ebx, 8*65536+8 ; [x start] *65536 + [y start] - ;mov ecx, 0x00ffffff ; color of text RRGGBB - ;mov edx, caption ; pointer to text beginning - ;mov esi, capsize ; text length - mov eax, 71 ; function 71.1 - mov ebx, 1 ; set window caption - mov ecx, caption ; pointer to text - int 0x40 - ;popa -} - -macro end_draw_window -{ - mov eax, 12 ; end of redraw - mov ebx, 2 - int 0x40 -} - -proc draw_button stdcall, x:dword, y:dword, xsize:dword, ysize:dword, \ - id:dword, butcolor:dword, text:dword, textlen:byte, textcolor:dword - - ;pusha - mov ebx, dword [x] - shl ebx, 16 - add ebx, dword [xsize] ; [x start] *65536 + [x size] - - mov ecx, dword [y] - shl ecx, 16 - add ecx, dword [ysize] ; [y start] *65536 + [y size] - - mov edx, dword [id] ; button id - mov esi, dword [butcolor] ; button color RRGGBB - mov eax, 8 ; function 8 : define and draw button - int 0x40 - - mov ebx, dword [x] - add ebx, 5 - shl ebx, 16 - mov eax, dword [ysize] - sub eax, 5 - shr eax, 1 - add ebx, eax - add ebx, dword [y] ;mov ebx, (x+5)*65536+y+(ysize-5)/2 ; Draw button text - - mov ecx, dword [textcolor] - mov edx, dword [text] - xor eax, eax - mov al, byte [textlen] - mov esi, eax - mov eax, 4 - int 0x40 - ;popa -ret -endp - -macro outtextxy x,y,prompt,prompt_len,color -{ - pusha - mov ebx, x*65536+y ; draw info text with function 4 - mov ecx, color - mov edx, prompt - xor eax, eax - mov al, prompt_len - mov esi, eax - mov eax, 4 - int 0x40 - popa -} - -;proc bar x:dword, y:dword, xsize:dword, ysize:dword, color:dword -macro bar x, y, xsize, ysize, color -{ - pusha - mov eax, 13 - ;mov ebx, [x] - ;shl ebx, 16 - ;add ebx, [xsize] - ;mov ecx, [y] - ;shl ecx, 16 - ;add ecx, [ysize] - ;mov edx, [color] - mov ebx, x*65536+xsize - mov ecx, y*65536+ysize - mov edx, color - - int 0x40 - popa -;ret -;endp -} - -macro line x1,y1,x2,y2,color -{ - pusha - mov eax, 38 - mov ebx, x1*65536+x2 - mov ecx, y1*65536+y2 - mov edx, color - int 0x40 - popa -} - -macro rectangle x,y,xsize,ysize,color -{ - x2=x+xsize - y2=y+ysize - line x,y,x2,y,color - line x,y,x,y2,color - line x,y2,x2,y2,color - line x2,y,x2,y2,color -} - -macro putpixel x,y,color -{ - mov eax, 1 - mov ebx, x - mov ecx, y - mov edx, color - int 0x40 -} - diff --git a/programs/demos/firework/trunk/firework.asm b/programs/demos/firework/trunk/firework.asm index 9a94ab63dd..35244be70a 100644 --- a/programs/demos/firework/trunk/firework.asm +++ b/programs/demos/firework/trunk/firework.asm @@ -1,375 +1,445 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; A firework demo -; Programmed by Yaniv LEVIATHAN -; http://yaniv.leviathanonline.com -; Converted to DexOS, By Dex +; A firework demo +; Programmed by Yaniv LEVIATHAN +; http://yaniv.leviathanonline.com +; Converted to DexOS, By Dex ; Converted to KolibriOS, By Asper ; Optimized for KolibriOS, By Diamond ; Assemble with ; c:fasm firework.asm firework.kex -; NOTE: Needs MMX & SSE -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -use32 - org 0x0 +; NOTE: Needs MMX & SSE, optionally AVX +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +use32 + org 0x0 - db 'MENUET00' ; 8 byte id - dd 38 ; required os - dd STARTAPP ; program start - dd I_END ; program image size - dd 0x100000 ; required amount of memory - dd 0x00000000 ; reserved=no extended header + db 'MENUET01' ; 8 byte id + dd 0x01 ; version + dd STARTAPP ; program start + dd I_END ; program image size + dd E_END ; required amount of memory + dd stacktop ; reserved=no extended header + dd 0, 0 include '../../../macros.inc' -include "aspapi.inc" -SCREEN_WIDTH equ 320 -SCREEN_HEIGHT equ 200 +SCREEN_WIDTH = 320 +SCREEN_HEIGHT = 200 +SIMD equ SSE +SIMD_BYTES = 8 +assert SCREEN_WIDTH mod SIMD_BYTES = 0 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Global defines ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; Global defines -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - NUM_PARTS = 150 - X_OFFSET = 0 - Y_OFFSET = 4 - X_SPEED_OFFSET = 8 - Y_SPEED_OFFSET = 12 - COLOR_OFFSET = 16 - PART_SIZE = 20 +NUM_PARTS = 150 +X_OFFSET = 0 +Y_OFFSET = 4 +X_SPEED_OFFSET = 8 +Y_SPEED_OFFSET = 12 +COLOR_OFFSET = 16 +PART_SIZE = 20 -macro draw_window -{ -local x, xsize, y, ysize, areacolor, caption -x = 100 -y = 70 -xsize = SCREEN_WIDTH+9 -ysize = SCREEN_HEIGHT+4 -areacolor = 0x54224466 -caption = labelt - mov eax, 12 ; function 12:tell os about windowdraw - mov ebx, 1 ; 1, start of draw - int 0x40 - ; DRAW WINDOW - mov eax, 48 - mov ebx, 4 - int 0x40 - lea ecx, [y*65536+ysize+eax] - xor eax, eax ; function 0 : define and draw window - mov ebx, x*65536+xsize ; [x start] *65536 + [x size] - mov edx, areacolor ; color of work area RRGGBB - mov edi, caption - int 0x40 -; start_draw_window 100,70,SCREEN_WIDTH+9,SCREEN_HEIGHT+29,0x04224466,labelt;, 14;labellen-labelt - end_draw_window -} - -macro mmx_shade -{ - mov ecx, SCREEN_WIDTH*SCREEN_HEIGHT/8 - mov edi,buffer - movq mm1, [sub_mask] -.lop: - movq mm0, [edi] - psubusb mm0, mm1 - movq [edi], mm0 - add edi, 8 - loop .lop -} - -macro mmx_blur_prepare -{ - mov ecx, (SCREEN_WIDTH*SCREEN_HEIGHT-330*2)/8 - mov edi,buffer + 328 -} - -macro mmx_blur +macro shade { local .lop -.lop: - movq mm0, [edi] - movq mm1, [edi+1] - movq mm2, [edi-1] - movq mm3, mm0 - movq mm4, [edi-SCREEN_WIDTH] - movq mm5, [edi+SCREEN_WIDTH] - - pavgb mm0, mm1 ; mm0 = avg(cur,cur+1) - pavgb mm3, mm2 ; mm3 = avg(cur,cur-1) - pavgb mm4, mm5 ; mm4 = avg(cur+320,cur-320) - pavgb mm3, mm4 ; mm3 = avg(avg(cur,cur-1),avg(cur+320,cur-320)) - pavgb mm0, mm3 ; mm0 = avg(avg(cur,cur+1), - - movq [edi], mm0 - add edi, 8 - loop .lop +if SIMD eq SSE + mov ecx, SCREEN_WIDTH * SCREEN_HEIGHT / SIMD_BYTES + mov edi, buffer + movq mm1, qword [sub_mask] + .lop: + movq mm0, [edi] + psubusb mm0, mm1 + movq [edi], mm0 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX + mov ecx, SCREEN_WIDTH * SCREEN_HEIGHT / SIMD_BYTES + mov edi, buffer + vmovdqa xmm1, xword [sub_mask] + .lop: + vmovdqa xmm0, [edi] + vpsubusb xmm0, xmm0, xmm1 + vmovdqa [edi], xmm0 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX2 + mov ecx, SCREEN_WIDTH * SCREEN_HEIGHT / SIMD_BYTES + mov edi, buffer + vmovdqa ymm1, yword [sub_mask] + .lop: + vmovdqa ymm0, [edi] + vpsubusb ymm0, ymm0, ymm1 + vmovdqa [edi], ymm0 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX512 + mov ecx, SCREEN_WIDTH * SCREEN_HEIGHT / SIMD_BYTES + mov edi, buffer + vmovdqa64 zmm1, zword [sub_mask] + .lop: + vmovdqa64 zmm0, [edi] + vpsubusb zmm0, zmm0, zmm1 + vmovdqa64 [edi], zmm0 + add edi, SIMD_BYTES + loop .lop +end if } +macro blur_prepare +{ + mov ecx, (SCREEN_WIDTH * SCREEN_HEIGHT - SCREEN_WIDTH * 2 - SIMD_BYTES*2) / SIMD_BYTES + mov edi, buffer + SCREEN_WIDTH + SIMD_BYTES +} -macro mmx_blur_right +macro blur { local .lop -.lop: - movq mm0, [edi] - movq mm1, [edi+1] - movq mm2, [edi+SCREEN_WIDTH] - movq mm3, [edi+SCREEN_WIDTH+1] - pavgb mm0, mm1 - pavgb mm3, mm2 - pavgb mm0, mm3 - movq [edi], mm0 - add edi, 8 - loop .lop +if SIMD eq SSE +.lop: + movq mm0, [edi] + movq mm1, [edi + 1] + movq mm2, [edi - 1] + movq mm3, mm0 + movq mm4, [edi - SCREEN_WIDTH] + movq mm5, [edi + SCREEN_WIDTH] + + pavgb mm0, mm1 ; mm0 = avg(cur,cur+1) + pavgb mm3, mm2 ; mm3 = avg(cur,cur-1) + pavgb mm4, mm5 ; mm4 = avg(cur+width,cur-width) + pavgb mm3, mm4 ; mm3 = avg(avg(cur,cur-1),avg(cur+width,cur-width)) + pavgb mm0, mm3 ; mm0 = avg(avg(cur,cur+1), + + movq [edi], mm0 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX +.lop: + vmovdqa xmm0, [edi] + vmovdqa xmm1, xmm0 + vmovdqa xmm2, [edi - SCREEN_WIDTH] + + vpavgb xmm0, xmm0, [edi + 1] + vpavgb xmm1, xmm1, [edi - 1] + vpavgb xmm2, xmm2, [edi + SCREEN_WIDTH] + vpavgb xmm1, xmm1, xmm2 + vpavgb xmm0, xmm0, xmm1 + + vmovdqa [edi], xmm0 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX2 +.lop: + vmovdqa ymm0, [edi] + vmovdqa ymm1, ymm0 + vmovdqa ymm2, [edi - SCREEN_WIDTH] + + vpavgb ymm0, ymm0, [edi + 1] + vpavgb ymm1, ymm1, [edi - 1] + vpavgb ymm2, ymm2, [edi + SCREEN_WIDTH] + vpavgb ymm1, ymm1, ymm2 + vpavgb ymm0, ymm0, ymm1 + + vmovdqa [edi], ymm0 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX512 +.lop: + vmovdqa64 zmm0, [edi] + vmovdqa64 zmm1, zmm0 + vmovdqa64 zmm2, [edi - SCREEN_WIDTH] + + vpavgb zmm0, zmm0, [edi + 1] + vpavgb zmm1, zmm1, [edi - 1] + vpavgb zmm2, zmm2, [edi + SCREEN_WIDTH] + vpavgb zmm1, zmm1, zmm2 + vpavgb zmm0, zmm0, zmm1 + + vmovdqa64 [edi], zmm0 + add edi, SIMD_BYTES + loop .lop +end if +} + +macro blur_right +{ +local .lop +if SIMD eq SSE + .lop: + movq mm0, [edi] + movq mm1, [edi + 1] + movq mm2, [edi + SCREEN_WIDTH] + movq mm3, [edi + SCREEN_WIDTH + 1] + pavgb mm0, mm1 + pavgb mm3, mm2 + pavgb mm0, mm3 + movq [edi], mm0 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX + .lop: + vmovdqa xmm0, [edi] + vmovdqu xmm1, [edi + SCREEN_WIDTH + 1] + vpavgb xmm2, xmm0, [edi + 1] + vpavgb xmm3, xmm1, [edi + SCREEN_WIDTH] + vpavgb xmm4, xmm2, xmm3 + vmovdqa [edi], xmm4 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX2 + .lop: + vmovdqa ymm0, [edi] + vmovdqu ymm1, [edi + SCREEN_WIDTH + 1] + vpavgb ymm2, ymm0, [edi + 1] + vpavgb ymm3, ymm1, [edi + SCREEN_WIDTH] + vpavgb ymm4, ymm2, ymm3 + vmovdqa [edi], ymm4 + add edi, SIMD_BYTES + loop .lop +else if SIMD eq AVX512 + .lop: + vmovdqa64 zmm0, [edi] + vmovdqu64 zmm1, [edi + SCREEN_WIDTH + 1] + vpavgb zmm2, zmm0, [edi + 1] + vpavgb zmm3, zmm1, [edi + SCREEN_WIDTH] + vpavgb zmm4, zmm2, zmm3 + vmovdqa64 [edi], zmm4 + add edi, SIMD_BYTES + loop .lop +end if } STARTAPP: init_palette: - mov edi, pal - xor eax, eax + mov edi, pal + xor eax, eax red_loop: - stosd - stosd - add eax, 0x040000 - and eax, 0xFFFFFF - jnz red_loop + stosd + stosd + add eax, 0x040000 + and eax, 0xFFFFFF + jnz red_loop - mov eax, 63*4*65536 + mov eax, 63*4 SHL 16 @@: - stosd - stosd - add ax, 0x0404 - jnc @b - -;zero_buffer: - mov ecx, SCREEN_WIDTH*SCREEN_HEIGHT/4 -; mov edi,buffer - xor eax, eax - rep stosd -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; Main Functions -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + stosd + stosd + add ax, 0x0404 + jnc @b + +;zero_buffer: + mov ecx, SCREEN_WIDTH * SCREEN_HEIGHT / 4 +; mov edi, buffer + xor eax, eax + rep stosd + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Main Functions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; virtual at esp -global_x dd ? -global_y dd ? -seed dd ? + global_x dd ? + global_y dd ? + seed dd ? end virtual - db 0x0f, 0x31 - push eax ; seed - push 100*64 ; global_y - push 160*64 ; global_x + rdtsc + push eax ; seed + push 100 * 64 ; global_y + push 160 * 64 ; global_x - jmp MAIN + jmp MAIN red: - mcall 9,proc_info,-1 - draw_window + mcall 9, proc_info, -1 +x = 100 +y = 70 +xsize = SCREEN_WIDTH+9 +ysize = SCREEN_HEIGHT+4 +areacolor = 0x54224466 + mov eax, 12 ; function 12:tell os about windowdraw + mov ebx, 1 ; 1, start of draw + int 0x40 + mov eax, 48 + mov ebx, 4 + int 0x40 + lea ecx, [(y SHL 16) + ysize + eax] + xor eax, eax ; function 0 : define and draw window + mov ebx, (x SHL 16) + xsize ; [x start] *65536 + [x size] + mov edx, areacolor ; color of work area RRGGBB + mov edi, window_title + int 0x40 + mov eax, 12 ; end of redraw + mov ebx, 2 + int 0x40 + MAIN: - test [proc_info.wnd_state], 0x04 - jnz still - mov ecx, NUM_PARTS - mov ebp, particles - .advance_particles: - mov eax, [ebp+X_OFFSET] - mov ebx, [ebp+Y_OFFSET] + test [proc_info.wnd_state], 0x04 + jnz still + mov ecx, NUM_PARTS + mov ebp, particles + .advance_particles: + mov eax, [ebp + X_OFFSET] + mov ebx, [ebp + Y_OFFSET] - sar eax, 6 - sar ebx, 6 + sar eax, 6 + sar ebx, 6 - cmp eax, 5 - jb .new_particle - cmp eax, SCREEN_WIDTH-5;315 - jge .new_particle - cmp ebx, 5 - jb .new_particle - cmp ebx, SCREEN_HEIGHT-5;195 - jl .part_ok + cmp eax, 5 + jb .new_particle + cmp eax, SCREEN_WIDTH - 5 + jge .new_particle + cmp ebx, 5 + jb .new_particle + cmp ebx, SCREEN_HEIGHT - 5 + jl .part_ok - .new_particle: - call init_particle - jmp .advance_particles + .new_particle: + call init_particle + jmp .advance_particles - .part_ok: -; mov edi, eax - ; add edi,buffer -; mov eax, SCREEN_WIDTH -; mul ebx - imul edi, ebx, SCREEN_WIDTH - mov dl, [ebp+COLOR_OFFSET] - mov [buffer+eax+edi], dl + .part_ok: + imul edi, ebx, SCREEN_WIDTH + mov dl, [ebp+COLOR_OFFSET] + mov [buffer+eax+edi], dl -; mov eax, [ebp+X_OFFSET] -; mov ebx, [ebp+Y_OFFSET] -; add eax, [ebp+X_SPEED_OFFSET] -; add ebx, [ebp+Y_SPEED_OFFSET] -; mov [ebp+X_OFFSET], eax -; mov [ebp+Y_OFFSET], ebx - mov eax, [ebp+X_SPEED_OFFSET] - add [ebp+X_OFFSET], eax - mov eax, [ebp+Y_SPEED_OFFSET] - add [ebp+Y_OFFSET], eax + mov eax, [ebp+X_SPEED_OFFSET] + add [ebp+X_OFFSET], eax + mov eax, [ebp+Y_SPEED_OFFSET] + add [ebp+Y_OFFSET], eax - db 0x0f, 0x31 - and al, 0x7F - jnz .dont_inc_y_speed - inc dword [ebp+Y_SPEED_OFFSET] - .dont_inc_y_speed: - - add ebp, PART_SIZE - loop .advance_particles + rdtsc + and al, 0x7F + jnz .dont_inc_y_speed + inc dword [ebp+Y_SPEED_OFFSET] + .dont_inc_y_speed: - mmx_shade -; jmp .copy_buffer_to_video - mmx_blur_prepare - test dword [blur_right_flag] , 0x800000 - jnz .do_blur_right - mmx_blur - db 0x0f, 0x31 - and al, 1 - jz .blur_ok - jmp .dont_blur - .do_blur_right: - mmx_blur_right - .blur_ok: - add dword [blur_right_flag], 0x1000 - .dont_blur: + add ebp, PART_SIZE + loop .advance_particles - .copy_buffer_to_video: - ; mov eax, 18 ;@WAITVSYNC(); - ; mov ebx, 14 - ; int 0x40 + shade +; jmp .copy_buffer_to_video + blur_prepare + test dword [blur_right_flag] , 0x800000 + jnz .do_blur_right + blur + rdtsc + and al, 1 + jz .blur_ok + jmp .dont_blur + .do_blur_right: + blur_right + .blur_ok: + add dword [blur_right_flag], 0x1000 + .dont_blur: - mov eax, 48 - mov ebx, 4 - int 0x40 - lea edx, [5*65536+eax] + .copy_buffer_to_video: - mov eax, 65 ;copyfard(0xA000,0,screen,0,16000); - mov ebx, buffer;dword [screen] - mov ecx, SCREEN_WIDTH*65536+SCREEN_HEIGHT ;ecx = w*65536+h -; mov edx, 5*65536+25 ;edx = x*65536+y - push 8 - pop esi - ;mov esi, 8 - mov edi, pal - xor ebp, ebp - int 0x40 + mcall 48, 4 + lea edx, [(5 SHL 16) + eax] + + mov eax, 65 + mov ebx, buffer + mov ecx, (SCREEN_WIDTH SHL 16) + SCREEN_HEIGHT + push 8 + pop esi + mov edi, pal + xor ebp, ebp + int 0x40 still: - mov eax, 11 ; Test if there is an event in the queue. - int 0x40 + mov eax, 11 ; Test if there is an event in the queue. + int 0x40 - dec eax ; redraw request ? - jz red - dec eax ; key in buffer ? - jz key - dec eax ; button in buffer ? - jz button + dec eax ; redraw request ? + jz red + dec eax ; key in buffer ? + jz key + dec eax ; button in buffer ? + jz button - jmp MAIN + jmp MAIN key: - mov eax, 2 - int 0x40 -; cmp ah, 1 ; Test Esc in Scan -; je close_app - cmp ah, 27 ; Test Esc in ASCII - je close_app - jmp MAIN + mov eax, 2 + int 0x40 +; cmp ah, 1 ; Test Esc in Scan +; je close_app + cmp ah, 27 ; Test Esc in ASCII + je close_app + jmp MAIN button: ; we have only one button, close -; mov eax, 17 ; Get pressed button code -; int 0x40 -; cmp ah, 1 ; Test x button -; je close_app -; jmp MAIN -; fall through to close_app - -fail: - ; Type something here. close_app: - mov eax,-1 ; close this program - int 0x40 + mov eax, -1 ; close this program + int 0x40 -init_particle: - db 0x0f, 0x31 - and al, 0x1F -jnz .dont_re_init_globals - ; init x - call rand - cdq - ;xor dx, dx - mov ebx, SCREEN_WIDTH - div ebx - shl edx, 6 - mov [4+global_x], edx - ; init y - call rand - cdq - ;xor dx, dx - mov ebx, SCREEN_HEIGHT - div ebx - shl edx, 6 - mov [4+global_y], edx -.dont_re_init_globals: - ; init x - mov eax, [4+global_x] - mov [ebp+X_OFFSET], eax - ; init y - mov eax, [4+global_y] - mov [ebp+Y_OFFSET], eax - ; init x speed - call rand - and eax, 31 - sub eax, 15 - ;shl ax, 6 - mov [ebp+X_SPEED_OFFSET], eax - ; init y speed - call rand - and eax, 31 - sub eax, 15 - ;shl ax, 6 - mov [ebp+Y_SPEED_OFFSET], eax - ; init color -; mov ax, 255 - ;call rand - ;and ax, 0xFF - mov [ebp+COLOR_OFFSET], dword 255;ax - ret +init_particle: + rdtsc + and al, 0x1F + jnz .dont_re_init_globals + ; init x + call rand + cdq + ;xor dx, dx + mov ebx, SCREEN_WIDTH + div ebx + shl edx, 6 + mov [4 + global_x], edx + ; init y + call rand + cdq + ;xor dx, dx + mov ebx, SCREEN_HEIGHT + div ebx + shl edx, 6 + mov [4 + global_y], edx + .dont_re_init_globals: + ; init x + mov eax, [4 + global_x] + mov [ebp + X_OFFSET], eax + ; init y + mov eax, [4 + global_y] + mov [ebp + Y_OFFSET], eax + ; init x speed + call rand + and eax, 31 + sub eax, 15 + ;shl ax, 6 + mov [ebp + X_SPEED_OFFSET], eax + ; init y speed + call rand + and eax, 31 + sub eax, 15 + ;shl ax, 6 + mov [ebp + Y_SPEED_OFFSET], eax + ; init color + mov [ebp + COLOR_OFFSET], dword 255 + ret -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; Misc. Functions -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - -rand: - mov eax, [8+seed] - imul eax, 214013 - add eax, 2531011 - mov [8+seed], eax - shr eax, 16 - ret +rand: + mov eax, [8 + seed] + imul eax, 214013 + add eax, 2531011 + mov [8 + seed], eax + shr eax, 16 + ret ; DATA AREA - -; Application Title -labelt db 'Firework demo',0 -;labelt db 'Matrix demo',0 - -;seed: dd 0 -;global_x: dd 160*64 -;global_y: dd 100*64 -sub_mask: dd 0x01010101, 0x01010101 -; x, y, x_speed, y_speed, color -particles: times NUM_PARTS dd 0, 0, 0, 0, 0 -blur_right_flag: dd 0 -;include 'Dex.inc' +window_title db 'Firework demo',0 +align SIMD_BYTES +sub_mask db SIMD_BYTES dup 0x01 +; x, y, x_speed, y_speed, color +particles: times NUM_PARTS dd 0, 0, 0, 0, 0 +blur_right_flag dd 0 I_END: -proc_info process_information -pal rb 256*4 ;dup(0) -;pal dd 256 dup(0) -;buffer rb 1024*64 -buffer rb SCREEN_WIDTH*SCREEN_HEIGHT - +proc_info process_information +align 16 +pal rb 256 * 4 +align SIMD_BYTES +buffer rb SCREEN_WIDTH * SCREEN_HEIGHT +E_END: +rd 0x200 +stacktop: diff --git a/programs/demos/firework/trunk/proc32.inc b/programs/demos/firework/trunk/proc32.inc deleted file mode 100644 index da6c04cda3..0000000000 --- a/programs/demos/firework/trunk/proc32.inc +++ /dev/null @@ -1,268 +0,0 @@ - -; Macroinstructions for defining and calling procedures - -macro stdcall proc,[arg] ; directly call STDCALL procedure - { common - if ~ arg eq - reverse - pushd arg - common - end if - call proc } - -macro invoke proc,[arg] ; indirectly call STDCALL procedure - { common - if ~ arg eq - reverse - pushd arg - common - end if - call [proc] } - -macro ccall proc,[arg] ; directly call CDECL procedure - { common - size@ccall = 0 - if ~ arg eq - reverse - pushd arg - size@ccall = size@ccall+4 - common - end if - call proc - if size@ccall - add esp,size@ccall - end if } - -macro cinvoke proc,[arg] ; indirectly call CDECL procedure - { common - size@ccall = 0 - if ~ arg eq - reverse - pushd arg - size@ccall = size@ccall+4 - common - end if - call [proc] - if size@ccall - add esp,size@ccall - end if } - -macro proc [args] ; define procedure - { common - match name params, args> - \{ define@proc name, \{ prologue name,flag,parmbytes,localbytes,reglist \} - macro locals - \{ virtual at ebp-localbytes+current - macro label . \\{ deflocal@proc .,:, \\} - struc db [val] \\{ \common deflocal@proc .,db,val \\} - struc dw [val] \\{ \common deflocal@proc .,dw,val \\} - struc dp [val] \\{ \common deflocal@proc .,dp,val \\} - struc dd [val] \\{ \common deflocal@proc .,dd,val \\} - struc dt [val] \\{ \common deflocal@proc .,dt,val \\} - struc dq [val] \\{ \common deflocal@proc .,dq,val \\} - struc rb cnt \\{ deflocal@proc .,rb cnt, \\} - struc rw cnt \\{ deflocal@proc .,rw cnt, \\} - struc rp cnt \\{ deflocal@proc .,rp cnt, \\} - struc rd cnt \\{ deflocal@proc .,rd cnt, \\} - struc rt cnt \\{ deflocal@proc .,rt cnt, \\} - struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} - macro endl - \{ purge label - restruc db,dw,dp,dd,dt,dq - restruc rb,rw,rp,rd,rt,rq - restruc byte,word,dword,pword,tword,qword - current = $-(ebp-localbytes) - end virtual \} - macro ret operand - \{ match any, operand \\{ retn operand \\} - match , operand \\{ match epilogue:reglist, epilogue@proc: - \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} - macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 - end if \} } - -macro defargs@proc [arg] - { common - if ~ arg eq - forward - local ..arg,current@arg - match argname:type, arg - \{ current@arg equ argname - label ..arg type - argname equ ..arg - if dqword eq type - dd ?,?,?,? - else if tbyte eq type - dd ?,?,? - else if qword eq type | pword eq type - dd ?,? - else - dd ? - end if \} - match =current@arg,current@arg - \{ current@arg equ arg - arg equ ..arg - ..arg dd ? \} - common - args@proc equ current@arg - forward - restore current@arg - common - end if } - -macro deflocal@proc name,def,[val] - { common - match vars, all@vars \{ all@vars equ all@vars, \} - all@vars equ all@vars name - forward - local ..var,..tmp - ..var def val - match =?, val \{ ..tmp equ \} - match any =dup (=?), val \{ ..tmp equ \} - match tmp : value, ..tmp : val - \{ tmp: end virtual - initlocal@proc ..var,def value - virtual at tmp\} - common - match first rest, ..var, \{ name equ first \} } - -macro initlocal@proc name,def - { virtual at name - def - size@initlocal = $ - name - end virtual - position@initlocal = 0 - while size@initlocal > position@initlocal - virtual at name - def - if size@initlocal - position@initlocal < 2 - current@initlocal = 1 - load byte@initlocal byte from name+position@initlocal - else if size@initlocal - position@initlocal < 4 - current@initlocal = 2 - load word@initlocal word from name+position@initlocal - else - current@initlocal = 4 - load dword@initlocal dword from name+position@initlocal - end if - end virtual - if current@initlocal = 1 - mov byte [name+position@initlocal],byte@initlocal - else if current@initlocal = 2 - mov word [name+position@initlocal],word@initlocal - else - mov dword [name+position@initlocal],dword@initlocal - end if - position@initlocal = position@initlocal + current@initlocal - end while } - -macro endp - { purge ret,locals,endl - finish@proc - purge finish@proc - restore regs@proc - match all,args@proc \{ restore all \} - restore args@proc - match all,all@vars \{ restore all \} } - -macro local [var] - { common - locals - forward done@local equ - match varname[count]:vartype, var - \{ match =BYTE, vartype \\{ varname rb count - restore done@local \\} - match =WORD, vartype \\{ varname rw count - restore done@local \\} - match =DWORD, vartype \\{ varname rd count - restore done@local \\} - match =PWORD, vartype \\{ varname rp count - restore done@local \\} - match =QWORD, vartype \\{ varname rq count - restore done@local \\} - match =TBYTE, vartype \\{ varname rt count - restore done@local \\} - match =DQWORD, vartype \\{ label varname dqword - rq count+count - restore done@local \\} - match , done@local \\{ virtual - varname vartype - end virtual - rb count*sizeof.\#vartype - restore done@local \\} \} - match :varname:vartype, done@local:var - \{ match =BYTE, vartype \\{ varname db ? - restore done@local \\} - match =WORD, vartype \\{ varname dw ? - restore done@local \\} - match =DWORD, vartype \\{ varname dd ? - restore done@local \\} - match =PWORD, vartype \\{ varname dp ? - restore done@local \\} - match =QWORD, vartype \\{ varname dq ? - restore done@local \\} - match =TBYTE, vartype \\{ varname dt ? - restore done@local \\} - match =DQWORD, vartype \\{ label varname dqword - dq ?,? - restore done@local \\} - match , done@local \\{ varname vartype - restore done@local \\} \} - match ,done@local - \{ var - restore done@local \} - common - endl }