flat assembler
Message board for the users of flat assembler.

Index > Heap > fire like effect

Author
Thread Post new topic Reply to topic
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
i have a grid of 128x128.
suppose the grid contains balls.
i also have 128 different fire shades (HBRUSHs)
i will initialize the balls at the bottom line of grid with darker fire shades.
now how do i proceed to make it look like fire balls?
any idea?

PS: writing this program for my windows examples.

_________________
Code:
 o__=-
 )
(\
 /\  
    
Post 07 Dec 2007, 11:36
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
Here's my effort so far.
I know the logic is not working properly.
But, what the hell, the GDI is sooo slow Sad
What should I do to make it faster?
I am writing the stuff in assembly already Wink
Code:

        format PE GUI 4.0
        entry start

        include 'win32a.inc'

d equ dword

GRID_SIZE = 64
BALL_SIZE = 5
WINDOW_WIDTH = BALL_SIZE*GRID_SIZE
WINDOW_HEIGHT = BALL_SIZE*GRID_SIZE


        section '.data' data readable writable
_hwnd dd 0

; Contains HBRUSHs.
_balls_array rd GRID_SIZE
; Contains indices into _balls_array.
_balls_grid rd GRID_SIZE*GRID_SIZE

_class_name db 'FireBallClass',0
_title_text db 'Fire Balls',0

        section '.code' code readable executable

start:
 wc = sizeof.WNDCLASSEX
 _ = wc

        enter _,0

        lea ebx, [ebp-wc]
        mov [ebx+WNDCLASSEX.cbSize], sizeof.WNDCLASSEX
        mov [ebx+WNDCLASSEX.style], CS_HREDRAW or CS_VREDRAW
        mov [ebx+WNDCLASSEX.lpfnWndProc], window_proc
        mov [ebx+WNDCLASSEX.cbClsExtra], 0
        mov [ebx+WNDCLASSEX.cbWndExtra], 0

        push 0
        call [GetModuleHandle]
        mov [ebx+WNDCLASSEX.hInstance], eax

        push IDI_APPLICATION
        push 0
        call [LoadIcon]
        mov [ebx+WNDCLASSEX.hIcon], eax
        mov [ebx+WNDCLASSEX.hIconSm], eax

        push IDC_ARROW
        push 0
        call [LoadCursor]
        mov [ebx+WNDCLASSEX.hCursor], eax

        push 0
        call [CreateSolidBrush]
        mov [ebx+WNDCLASSEX.hbrBackground], eax

        mov [ebx+WNDCLASSEX.lpszMenuName], 0
        mov [ebx+WNDCLASSEX.lpszClassName], _class_name

        push ebx
        call [RegisterClassEx]

        push 0
        push [ebx+WNDCLASSEX.hInstance]
        push 0
        push 0
        push WINDOW_HEIGHT
        push WINDOW_WIDTH
        push CW_USEDEFAULT
        push CW_USEDEFAULT
        push WS_OVERLAPPED;WINDOW
        push _title_text
        push _class_name
        push 0
        call [CreateWindowEx]
        mov [_hwnd], eax

; Put HBRUSHEs colored 255,127,0 to 255,255,0 in _balls_array
        mov ebx, GRID_SIZE
        mov edi, _balls_array
.init_balls:
        mov eax, 255
        mov ah, bl
        add ah, 127
        push eax
        call [CreateSolidBrush]
        stosd
        dec ebx
        jnz .init_balls

; Put indices in grid.

        mov edi, _balls_grid
        cld
        mov ebx, GRID_SIZE*GRID_SIZE
.init_grid:
        rdtsc
        xor eax, edx
        and eax, GRID_SIZE-1
        stosd
        dec ebx
        jnz .init_grid


        push SW_SHOWNORMAL
        push [_hwnd]
        call [ShowWindow]

        push 0
        push 50
        push 1
        push d[_hwnd]
        call [SetTimer]

        lea ebx, [ebp-sizeof.MSG]
        jmp .get_message

.message_loop:
        push ebx
        call [TranslateMessage]

        push ebx
        call [DispatchMessage]

.get_message:
        push 0
        push 0
        push 0
        push ebx
        call [GetMessage]
        cmp eax, 0
        jg .message_loop

        push 0
        call [ExitProcess]


window_proc:
 hwnd equ ebp+8
 umsg equ ebp+12
 wpar equ ebp+16
 lpar equ ebp+20
 ps = sizeof.PAINTSTRUCT
 _ = ps

        push ebp
        mov ebp, esp
        sub esp, _
        push ebx
        push edi

        mov eax, [umsg]

        cmp eax, WM_TIMER
        je .wm_timer

        cmp eax, WM_PAINT
        je .wm_paint

        cmp eax, WM_DESTROY
        je .wm_destroy

        push d[lpar]
        push d[wpar]
        push d[umsg]
        push d[hwnd]
        call [DefWindowProc]
        jmp .def_handled

.wm_timer:
        push d[hwnd]
        call [GetDC]
        push eax ; Save Wink
        push eax
        call draw_balls
        push d[hwnd]
        call [ReleaseDC]
        call update_balls
        jmp .handled

.wm_paint:
        lea ebx, [ebp-ps]
        push ebx
        push d[hwnd]
        call [BeginPaint]

        push eax
        call draw_balls

        push ebx
        push d[hwnd]
        call [EndPaint]

        jmp .handled

.wm_destroy:
        push 0
        call [PostQuitMessage]
        jmp .handled

.handled:
        mov eax, 0

.def_handled:

        pop edi
        pop ebx
        leave
        ret 16


draw_balls:
 hdc equ ebp+8
 xoff = 4
 yoff = 8
 _ = yoff

        push ebp
        mov ebp, esp
        sub esp, _

        push ebx
        push esi
        push edi

        push BLACK_PEN
        call [GetStockObject]
        push eax
        push d[hdc]
        call [SelectObject]

        mov esi, _balls_grid
        mov ebx, 0
        mov d[ebp-yoff], 0
        mov d[ebp-xoff], 0
.balls_loop:
        cld
        lodsd
        cmp eax, -1
        je .skip_null

        push d[_balls_array+eax*4]
        push d[hdc]
        call [SelectObject]

        mov ecx, [ebp-xoff]
        mov edx, [ebp-yoff]
        add ecx, BALL_SIZE
        add edx, BALL_SIZE

        push edx
        push ecx
        push d[ebp-yoff]
        push d[ebp-xoff]
        push d[hdc]
        call [Ellipse]

.skip_null:
        add d[ebp-xoff], BALL_SIZE

        inc ebx
        mov eax, ebx
        mov ecx, GRID_SIZE
        xor edx, edx
        div ecx
        cmp edx, 0
        jnz .balls_loop

        mov d[ebp-xoff], 0
        add d[ebp-yoff], BALL_SIZE

        cmp ebx, GRID_SIZE*GRID_SIZE
        jb .balls_loop

        pop edi
        pop esi
        pop ebx
        leave
        ret 4

update_balls:
        push esi

        mov ecx, GRID_SIZE*GRID_SIZE
        mov esi, _balls_grid
.update_loop:
        dec d[esi]
        and d[esi],GRID_SIZE-1
        add esi, 4
        dec ecx
        jnz .update_loop

        pop esi
        ret


        section '.idata' import data readable

library kernel32,'kernel32.dll',\
        user32,'user32.dll',\
        gdi32,'gdi32.dll'

include 'api/kernel32.inc'
include 'api/user32.inc'
include 'api/gdi32.inc'

    

_________________
Code:
 o__=-
 )
(\
 /\  
    
Post 07 Dec 2007, 12:56
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
0.1 wrote:
Here's my effort so far.
I know the logic is not working properly.
But, what the hell, the GDI is sooo slow Sad
What should I do to make it faster?
I am writing the stuff in assembly already Wink
Code:

        format PE GUI 4.0
        entry start

        include 'win32a.inc'

d equ dword

GRID_SIZE = 64
BALL_SIZE = 5
WINDOW_WIDTH = BALL_SIZE*GRID_SIZE
WINDOW_HEIGHT = BALL_SIZE*GRID_SIZE


        section '.data' data readable writable
_hwnd dd 0

; Contains HBRUSHs.
_balls_array rd GRID_SIZE
; Contains indices into _balls_array.
_balls_grid rd GRID_SIZE*GRID_SIZE

_class_name db 'FireBallClass',0
_title_text db 'Fire Balls',0

        section '.code' code readable executable

start:
 wc = sizeof.WNDCLASSEX
 _ = wc

        enter _,0

        lea ebx, [ebp-wc]
        mov [ebx+WNDCLASSEX.cbSize], sizeof.WNDCLASSEX
        mov [ebx+WNDCLASSEX.style], CS_HREDRAW or CS_VREDRAW
        mov [ebx+WNDCLASSEX.lpfnWndProc], window_proc
        mov [ebx+WNDCLASSEX.cbClsExtra], 0
        mov [ebx+WNDCLASSEX.cbWndExtra], 0

        push 0
        call [GetModuleHandle]
        mov [ebx+WNDCLASSEX.hInstance], eax

        push IDI_APPLICATION
        push 0
        call [LoadIcon]
        mov [ebx+WNDCLASSEX.hIcon], eax
        mov [ebx+WNDCLASSEX.hIconSm], eax

        push IDC_ARROW
        push 0
        call [LoadCursor]
        mov [ebx+WNDCLASSEX.hCursor], eax

        push 0
        call [CreateSolidBrush]
        mov [ebx+WNDCLASSEX.hbrBackground], eax

        mov [ebx+WNDCLASSEX.lpszMenuName], 0
        mov [ebx+WNDCLASSEX.lpszClassName], _class_name

        push ebx
        call [RegisterClassEx]

        push 0
        push [ebx+WNDCLASSEX.hInstance]
        push 0
        push 0
        push WINDOW_HEIGHT
        push WINDOW_WIDTH
        push CW_USEDEFAULT
        push CW_USEDEFAULT
        push WS_OVERLAPPED;WINDOW
        push _title_text
        push _class_name
        push 0
        call [CreateWindowEx]
        mov [_hwnd], eax

; Put HBRUSHEs colored 255,127,0 to 255,255,0 in _balls_array
        mov ebx, GRID_SIZE
        mov edi, _balls_array
.init_balls:
        mov eax, 255
        mov ah, bl
        add ah, 127
        push eax
        call [CreateSolidBrush]
        stosd
        dec ebx
        jnz .init_balls

; Put indices in grid.

        mov edi, _balls_grid
        cld
        mov ebx, GRID_SIZE*GRID_SIZE
.init_grid:
        rdtsc
        xor eax, edx
        and eax, GRID_SIZE-1
        stosd
        dec ebx
        jnz .init_grid


        push SW_SHOWNORMAL
        push [_hwnd]
        call [ShowWindow]

        push 0
        push 50
        push 1
        push d[_hwnd]
        call [SetTimer]

        lea ebx, [ebp-sizeof.MSG]
        jmp .get_message

.message_loop:
        push ebx
        call [TranslateMessage]

        push ebx
        call [DispatchMessage]

.get_message:
        push 0
        push 0
        push 0
        push ebx
        call [GetMessage]
        cmp eax, 0
        jg .message_loop

        push 0
        call [ExitProcess]


window_proc:
 hwnd equ ebp+8
 umsg equ ebp+12
 wpar equ ebp+16
 lpar equ ebp+20
 ps = sizeof.PAINTSTRUCT
 _ = ps

        push ebp
        mov ebp, esp
        sub esp, _
        push ebx
        push edi

        mov eax, [umsg]

        cmp eax, WM_TIMER
        je .wm_timer

        cmp eax, WM_PAINT
        je .wm_paint

        cmp eax, WM_DESTROY
        je .wm_destroy

        push d[lpar]
        push d[wpar]
        push d[umsg]
        push d[hwnd]
        call [DefWindowProc]
        jmp .def_handled

.wm_timer:
        push d[hwnd]
        call [GetDC]
        push eax ; Save Wink
        push eax
        call draw_balls
        push d[hwnd]
        call [ReleaseDC]
        call update_balls
        jmp .handled

.wm_paint:
        lea ebx, [ebp-ps]
        push ebx
        push d[hwnd]
        call [BeginPaint]

        push eax
        call draw_balls

        push ebx
        push d[hwnd]
        call [EndPaint]

        jmp .handled

.wm_destroy:
        push 0
        call [PostQuitMessage]
        jmp .handled

.handled:
        mov eax, 0

.def_handled:

        pop edi
        pop ebx
        leave
        ret 16


draw_balls:
 hdc equ ebp+8
 xoff = 4
 yoff = 8
 _ = yoff

        push ebp
        mov ebp, esp
        sub esp, _

        push ebx
        push esi
        push edi

        push BLACK_PEN
        call [GetStockObject]
        push eax
        push d[hdc]
        call [SelectObject]

        mov esi, _balls_grid
        mov ebx, 0
        mov d[ebp-yoff], 0
        mov d[ebp-xoff], 0
.balls_loop:
        cld
        lodsd
        cmp eax, -1
        je .skip_null

        push d[_balls_array+eax*4]
        push d[hdc]
        call [SelectObject]

        mov ecx, [ebp-xoff]
        mov edx, [ebp-yoff]
        add ecx, BALL_SIZE
        add edx, BALL_SIZE

        push edx
        push ecx
        push d[ebp-yoff]
        push d[ebp-xoff]
        push d[hdc]
        call [Ellipse]

.skip_null:
        add d[ebp-xoff], BALL_SIZE

        inc ebx
        mov eax, ebx
        mov ecx, GRID_SIZE
        xor edx, edx
        div ecx
        cmp edx, 0
        jnz .balls_loop

        mov d[ebp-xoff], 0
        add d[ebp-yoff], BALL_SIZE

        cmp ebx, GRID_SIZE*GRID_SIZE
        jb .balls_loop

        pop edi
        pop esi
        pop ebx
        leave
        ret 4

update_balls:
        push esi

        mov ecx, GRID_SIZE*GRID_SIZE
        mov esi, _balls_grid
.update_loop:
        dec d[esi]
        and d[esi],GRID_SIZE-1
        add esi, 4
        dec ecx
        jnz .update_loop

        pop esi
        ret


        section '.idata' import data readable

library kernel32,'kernel32.dll',\
        user32,'user32.dll',\
        gdi32,'gdi32.dll'

include 'api/kernel32.inc'
include 'api/user32.inc'
include 'api/gdi32.inc'

    


Well... DirectDraw instead of Windows GDI?
Post 07 Dec 2007, 18:43
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
something very interesting about various effects is at
256b demo galaxy fire
Post 07 Dec 2007, 19:20
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.