64 bit assembler > Mikl__'s ml64 examples

Fractals

(1/12) > >>

Mikl__:
asm-file
--- Code: ---include win64a.inc
include msvcrt.inc
includelib gdi32.lib
includelib msvcrt.lib
IMAGE_BASE equ 400000h
cdXPos          equ 131
cdYPos          equ 217
cdYSize         equ 430
cdXSize         equ 640

movr macro x,y
mov x,0
org $-4
dd y
endm

.code


WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD

local ps:PAINTSTRUCT
local hdc:qword
local hOldBmp:qword
local hGDITmp:qword
local hOldDIB:qword
local hBackDC:qword
local hMainDIB:qword
local bufBMP:qword
local i:dword
local x:dword
local y:dword
local a:dword
local b:dword
local c:dword
local d:dword
local f:dword
local NewX:qword
local NewY:qword
local XCC:qword
local YCC:qword

push rbp
mov ebp, esp
sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16)

mov hWnd,rcx
cmp edx, WM_DESTROY
jz wmDESTROY
        cmp edx, WM_PAINT
jz wmPAINT
        cmp edx, WM_CREATE
jz wmCREATE
leave
        jmp DefWindowProc
; ---------------------------------------------------------------------------
wmDESTROY::mov rdx,hOldBmp
mov rcx,hBackDC
call SelectObject
mov hGDITmp,rax
mov rcx,bufBMP
call DeleteObject
mov rcx,hBackDC
call DeleteDC
mov rdx,hOldDIB
mov rcx,bufDIBDC
call SelectObject
mov hGDITmp,rax
mov rcx,bufDIBDC
call DeleteDC
mov rcx,hMainDIB
call DeleteObject
mov rcx,hWnd
call DestroyWindow
xor ecx,ecx ; nExitCode
call ExitProcess
; ---------------------------------------------------------------------------
wmPAINT:lea edx,ps
call BeginPaint
mov hdc,rax
mov qword ptr [rsp+40h],SRCCOPY; rop
        xor edx,edx ; x
mov [rsp+38h],rdx ; y1
mov [rsp+30h],rdx ; x1
mov rax,bufDIBDC ; hdcSrc
        mov [rsp+28h],rax
mov rax,cdYSize
mov [rsp+20h],rax
mov r9,cdXSize ; cx
xor r8d,r8d ; cy
mov rcx,hdc ; hdc
call BitBlt
lea edx,ps
mov rcx,hWnd
call EndPaint
jmp wmBYE
; ---------------------------------------------------------------------------
wmCREATE:mov rcx,hWnd
call GetDC
mov hdc,rax
        mov rcx,rax ; HDC
call CreateCompatibleDC
mov bufDIBDC,rax

mov [rsp+28h],rbx
mov [rsp+20h],rbx
mov r9d,offset pMainDIB
mov r8d,DIB_RGB_COLORS
mov edx,offset bi
mov rcx,hdc
        call CreateDIBSection
mov hMainDIB,rax
mov rdx,rax; hMainDIB
mov rcx,bufDIBDC
call SelectObject
        mov rax,hOldDIB
mov rdx,hdc
mov rcx,hWnd         
        call ReleaseDC;   // Libera device context         
;Init--------------------------------------------------------
; a       b       c       d      e   f   p
; 0.1000  0.0000  0.0000  0.1600 0.0 0.0 0.01*10000= 100
; 0.8500  0.0000  0.0000  0.8500 0.0 1.6 0.85*10000=8500
;-0.1667 -0.2887  0.2887 -0.1667 0.0 1.6 0.07*10000= 700
;-0.1667  0.2887 -0.2887 -0.1667 0.0 1.6 0.07*10000= 700
mov XCC,rbx
mov YCC,rbx
mov i,60000
bucle:  call rand
mov ecx,10000
xor edx,edx
div ecx
cmp edx, 100  ;p1
ja @f
movr a,0.1;a = 0.1
mov b,ebx; b = 0
        mov c,ebx; c = 0
movr d,0.16
mov f,ebx; f = 0
jmp fin
@@: cmp edx, 800  ;p1+p4=100+700=800
ja @f
movr a,-0.1667 
movr b, 0.2887
movr c,-0.2887
movr d,-0.1667
movr f, 1.6
jmp fin
@@: cmp edx,1500  ;p1+p4+p3=800+700=1500
ja @f
movr a,-0.1667
movr b,-0.2887 
movr c,0.2887
movr d,-0.1667
movr f,1.6
jmp fin
@@: movr a,0.8500 
mov b,ebx
mov c,ebx
movr d, 0.85
movr f, 1.60 ; f = 1.60
fin: fld a       ;st(0) = a
fmul XCC     ;st(0) = a * XCC
fld b       ;st(0) = b
fmul YCC     ;st(0) = b * YCC
faddp         ;st(0) = a * XCC + b * YCC
fst NewX    ;NewX = a * XCC + b * YCC
fmul const40 ;st(0) = NewX * 40
fld c           ;st(0) = c
fmul XCC     ;st(0) = c * XCC
fld d       ;st(0) = d
fmul YCC     ;st(0) = d * YCC
faddp         ;st(0) = c * XCC + d * YCC
fadd f       ;st(0) = c * XCC + d * YCC + f
fst NewY    ;NewY = c * XCC + d * YCC + f
fstp YCC     ;YCC = NewY
fadd const320;st(0) = NewX * 40 + cdXSize/2
fistp x       ;x = (int) (NewX*40+cdXSize/2)
mov ecx, x
cmp ecx,cdXSize
jae @f
fld1         ;st(0) = 1
fsub NewY    ;st(0) = 1 - NewY
fmul const40 ;st(0) = (1 - NewY)*40
fadd const365;st(0) = (1 - NewY)*40 + cdYSize - 35
fistp y       ; y = (int) ((1-NewY)*40+cdYSize-35)
cmp y,cdYSize
jae @f
imul eax,y,2560
add rax,pMainDIB
mov dword ptr [rax+rcx*4],0FF00h ;*(pMainDIB + (y<<9)+(y<<7)+x) = 0xFF00;
@@: fld NewX  ;XCC = NewX
fstp XCC
dec i
jnz  bucle
wmBYE: leave
retn
WndProc endp

WinMain proc
local msg:MSG

push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov esi,IMAGE_BASE
mov edi,offset ClassName
push rbx ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOWTEXT; hbrBackground
push rbx ;hCursor
push rbx        ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
db 68h
dd WndProc      ;lpfnWndProc
push sizeof WNDCLASSEX ;cbSize & style
mov ecx,esp ;addr WNDCLASSEX
call RegisterClassEx
push rbx
push rsi ;rsi=400000h
push rbx
push rbx
push cdYSize
push cdXSize
push cdYPos
push cdXPos
mov r9d,WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h ; dwExStyle
call CreateWindowEx
@@:     lea ecx,msg
xor edx,edx
xor r8d,r8d
xor r9d,r9d
call GetMessage
cmp msg.wParam,VK_ESCAPE;user press 'Esc'?
je wmDESTROY
lea ecx,msg
call DispatchMessage
jmp @b
WinMain endp

.data
ClassName db 'Fir Tree Fractal',0
bi BITMAPINFO <<28h,640,-430,1,32,0,0,0,0,0,0>>
bufDIBDC dq ?
pMainDIB dq ?
const40 dq 40.0
const320 dq 320.0
const365 dq 365.0
end
--- End code ---

Mikl__:

--- Code: ---include win64a.inc
include msvcrt.inc
includelib gdi32.lib
includelib msvcrt.lib
IMAGE_BASE equ 400000h
cdXPos          equ 131
cdYPos          equ 217
cdYSize         equ 430
cdXSize         equ 640

movr macro x,y
mov x,0
org $-4
dd y
endm

.code


WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD

local ps:PAINTSTRUCT
local hdc:qword
local hOldBmp:qword
local hGDITmp:qword
local hOldDIB:qword
local hBackDC:qword
local hMainDIB:qword
local bufBMP:qword
local i:dword
local x:dword
local y:dword
local a:dword
local b:dword
local c:dword
local d:dword
local e:dword
local f:dword
local NewX:qword
local NewY:qword
local XCC:qword
local YCC:qword

push rbp
mov ebp, esp
sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16)

mov hWnd,rcx
cmp edx, WM_DESTROY
jz wmDESTROY
        cmp edx, WM_PAINT
jz wmPAINT
        cmp edx, WM_CREATE
jz wmCREATE
leave
        jmp DefWindowProc
; ---------------------------------------------------------------------------
wmDESTROY::mov rdx,hOldBmp
mov rcx,hBackDC
call SelectObject
mov hGDITmp,rax
mov rcx,bufBMP
call DeleteObject
mov rcx,hBackDC
call DeleteDC
mov rdx,hOldDIB
mov rcx,bufDIBDC
call SelectObject
mov hGDITmp,rax
mov rcx,bufDIBDC
call DeleteDC
mov rcx,hMainDIB
call DeleteObject
mov rcx,hWnd
call DestroyWindow
xor ecx,ecx ; nExitCode
call ExitProcess
; ---------------------------------------------------------------------------
wmPAINT:lea edx,ps
call BeginPaint
mov hdc,rax
mov qword ptr [rsp+40h],SRCCOPY; rop
        xor edx,edx ; x
mov [rsp+38h],rdx ; y1
mov [rsp+30h],rdx ; x1
mov rax,bufDIBDC ; hdcSrc
        mov [rsp+28h],rax
mov rax,cdYSize
mov [rsp+20h],rax
mov r9,cdXSize ; cx
xor r8d,r8d ; cy
mov rcx,hdc ; hdc
call BitBlt
lea edx,ps
mov rcx,hWnd
call EndPaint
jmp wmBYE
; ---------------------------------------------------------------------------
wmCREATE:mov rcx,hWnd
call GetDC
mov hdc,rax
        mov rcx,rax ; HDC
call CreateCompatibleDC
mov bufDIBDC,rax

mov [rsp+28h],rbx
mov [rsp+20h],rbx
mov r9d,offset pMainDIB
mov r8d,DIB_RGB_COLORS
mov edx,offset bi
mov rcx,hdc
        call CreateDIBSection
mov hMainDIB,rax
mov rdx,rax; hMainDIB
mov rcx,bufDIBDC
call SelectObject
        mov rax,hOldDIB
mov rdx,hdc
mov rcx,hWnd         
        call ReleaseDC;   // Libera device context         
;Init--------------------------------------------------------
; a     b     c   d    e     f    p
; 0.49 -0.01  0   0.62 0.25  0.02 0.316*10000=3160;
; 0.27 -0.52  0.4 0.36 0    -0.56 0.316*10000=3160;6320
; 0.18  0.73 -0.5 0.26 0.88 -0.08 0.316*10000=3160;9480
; 0.04  0.01 -0.5 0    0.52 -0.32 0.052*10000= 520
mov XCC,rbx
mov YCC,rbx
mov i,48000
bucle:  call rand
mov ecx,10000
xor edx,edx
div ecx
cmp edx,3160
jg @f
movr a,0.49
movr b,-0.01     
mov c,ebx
movr d,0.62
movr e,0.25 
movr f,0.02
jmp fin
@@: cmp edx,6320
jg @f
movr a,0.27
movr b,-0.52 
movr c,0.4
movr d,0.36     
mov e,ebx
movr f,-0.56
jmp fin
@@: cmp edx,9480
jg @f
movr a,0.18 
movr b,0.73
movr c,-0.5
movr d,0.26
movr e,0.88
movr f,-0.08
jmp fin
@@: movr a,0.04 
movr b,0.01
movr c,-0.5     
mov d,ebx
movr e,0.52
movr f,-0.32

fin: fld a       ;st(0) = a
fmul XCC     ;st(0) = a * XCC
fld b       ;st(0) = b
fmul YCC     ;st(0) = b * YCC
faddp         ;st(0) = a * XCC + b * YCC
        fadd e       ;st(0) = a * XCC + b * YCC + e
fst NewX    ;NewX  = a * XCC + b * YCC + e
fmul const470;st(0) = NewX * 470
        fadd const82 ;st(0) = NewX * 470 + 82
fistp x       ;x = (int) (NewX * 470 + 82)
        mov eax,x
cmp eax,cdXSize
jae @f
fld c       ;st(0) = c
fmul XCC     ;st(0) = c * XCC
fld d       ;st(0) = d
fmul YCC     ;st(0) = d * YCC
faddp         ;st(0) = c * XCC + d * YCC
fadd f       ;st(0) = c * XCC + d * YCC + f
fst NewY    ;NewY  = c * XCC + d * YCC + f
fst YCC     ;YCC = NewY
fchs            ;st(0)  = -NewY
fmul const470;st(0) = -NewY * 470
fadd const42;st(0)  = -NewY * 470 + 42
fistp y       ; y = (int) (-NewY * 470 + 42)
mov ecx, y
cmp ecx,cdYSize
jae @f
imul ecx,y,cdXSize*4
add rcx,pMainDIB
mov dword ptr [rcx+rax*4],0FF8000h ;*(pMainDIB + y*cdXSize*4 + x*4) = orange color
@@: fld NewX  ;XCC = NewX
fstp XCC
dec i
jnz  bucle
wmBYE: leave
retn
WndProc endp

WinMain proc
local msg:MSG

push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov esi,IMAGE_BASE
mov edi,offset ClassName
push rbx ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOWTEXT; hbrBackground
push rbx ;hCursor
push rbx        ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
db 68h
dd WndProc      ;lpfnWndProc
push sizeof WNDCLASSEX ;cbSize & style
mov ecx,esp ;addr WNDCLASSEX
call RegisterClassEx
push rbx
push rsi ;rsi=400000h
push rbx
push rbx
push cdYSize
push cdXSize
push cdYPos
push cdXPos
mov r9d,WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h ; dwExStyle
call CreateWindowEx
@@:     lea ecx,msg
xor edx,edx
xor r8d,r8d
xor r9d,r9d
call GetMessage
cmp msg.wParam,VK_ESCAPE;user press 'Esc'?
je wmDESTROY
lea ecx,msg
call DispatchMessage
jmp @b
WinMain endp

.data
ClassName db 'Maple Fractal',0
bi BITMAPINFO <<28h,640,-430,1,32,0,0,0,0,0,0>>
bufDIBDC dq ?
pMainDIB dq ?
const470 dd 470.0
const82 dd 82.0
const42 dd 42.0
end
--- End code ---

jj2007:
Fantastic, thanks for sharing this :t

Mikl__:

--- Code: ---include win64a.inc
include msvcrt.inc
includelib gdi32.lib
includelib msvcrt.lib
IMAGE_BASE equ 400000h
cdXPos          equ 131
cdYPos          equ 217
cdYSize         equ 430
cdXSize         equ 640

movr macro x,y
mov x,0
org $-4
dd y
endm

.code


WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD

local ps:PAINTSTRUCT
local hdc:qword
local hOldBmp:qword
local hGDITmp:qword
local hOldDIB:qword
local hBackDC:qword
local hMainDIB:qword
local bufBMP:qword
local i:dword
local x:dword
local y:dword
local a:dword
local b:dword
local c:dword
local d:dword
local e:dword
local f:dword
local NewX:qword
local NewY:qword
local XCC:qword
local YCC:qword

push rbp
mov ebp, esp
sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16)

mov hWnd,rcx
cmp edx, WM_DESTROY
jz wmDESTROY
        cmp edx, WM_PAINT
jz wmPAINT
        cmp edx, WM_CREATE
jz wmCREATE
leave
        jmp DefWindowProc
; ---------------------------------------------------------------------------
wmDESTROY::mov rdx,hOldBmp
mov rcx,hBackDC
call SelectObject
mov hGDITmp,rax
mov rcx,bufBMP
call DeleteObject
mov rcx,hBackDC
call DeleteDC
mov rdx,hOldDIB
mov rcx,bufDIBDC
call SelectObject
mov hGDITmp,rax
mov rcx,bufDIBDC
call DeleteDC
mov rcx,hMainDIB
call DeleteObject
mov rcx,hWnd
call DestroyWindow
xor ecx,ecx ; nExitCode
call ExitProcess
; ---------------------------------------------------------------------------
wmPAINT:lea edx,ps
call BeginPaint
mov hdc,rax
mov qword ptr [rsp+40h],SRCCOPY; rop
        xor edx,edx ; x
mov [rsp+38h],rdx ; y1
mov [rsp+30h],rdx ; x1
mov rax,bufDIBDC ; hdcSrc
        mov [rsp+28h],rax
mov rax,cdYSize
mov [rsp+20h],rax
mov r9,cdXSize ; cx
xor r8d,r8d ; cy
mov rcx,hdc ; hdc
call BitBlt
lea edx,ps
mov rcx,hWnd
call EndPaint
jmp wmBYE
; ---------------------------------------------------------------------------
wmCREATE:mov rcx,hWnd
call GetDC
mov hdc,rax
        mov rcx,rax ; HDC
call CreateCompatibleDC
mov bufDIBDC,rax

mov [rsp+28h],rbx
mov [rsp+20h],rbx
mov r9d,offset pMainDIB
mov r8d,DIB_RGB_COLORS
mov edx,offset bi
mov rcx,hdc
        call CreateDIBSection
mov hMainDIB,rax
mov rdx,rax; hMainDIB
mov rcx,bufDIBDC
call SelectObject
        mov rax,hOldDIB
mov rdx,hdc
mov rcx,hWnd         
        call ReleaseDC;   // Libera device context         
;Init--------------------------------------------------------
; a     b      c     d    e       f    p
; 0.7  0.2 -0.2 0.7 0.0  0.0 0.5
; 0.0 -0.6  0.6 0.0 1.0 -0.6 0.5
mov XCC,rbx
mov YCC,rbx
mov i,60000
bucle:  call rand
mov ecx,1000
xor edx,edx
div ecx
cmp edx,499
jg @f
movr a,0.7 
movr b,0.2
movr c,-0.2
movr d,0.7
mov e,ebx
mov f,ebx
jmp fin
@@: mov a,ebx
movr b,-0.6 
movr c,0.6
mov d,ebx
movr e,1.0
movr f,-0.6
fin: fld a       ;st(0) = a
fmul XCC     ;st(0) = a * XCC
fld b       ;st(0) = b
fmul YCC     ;st(0) = b * YCC
faddp         ;st(0) = a * XCC + b * YCC
        fadd e       ;st(0) = a * XCC + b * YCC + e
fst NewX    ;NewX  = a * XCC + b * YCC + e
fmul const340;st(0) = NewX * 340
        fadd const120;st(0) = NewX * 340 + 120
fistp x       ;x = (int) (NewX * 470 + 120)
        mov eax,x
cmp eax,cdXSize
jae @f
fld c       ;st(0) = c
fmul XCC     ;st(0) = c * XCC
fld d       ;st(0) = d
fmul YCC     ;st(0) = d * YCC
faddp         ;st(0) = c * XCC + d * YCC
fadd f       ;st(0) = c * XCC + d * YCC + f
fst NewY    ;NewY  = c * XCC + d * YCC + f
fst YCC     ;YCC = NewY
fchs            ;st(0)  = -NewY
fmul const340;st(0) = -NewY * 340
fadd const160;st(0)  = -NewY * 340 + 160
fistp y       ; y = (int) (-NewY * 340 + 160)
mov ecx, y
cmp ecx,cdYSize
jae @f
imul ecx,cdXSize*4
add rcx,pMainDIB
mov dword ptr [rcx+rax*4],0FFFFFFh ;*(pMainDIB + y*cdXSize*4 + x*4) = white color
@@: fld NewX  ;XCC = NewX
fstp XCC
dec i
jnz  bucle
wmBYE: leave
retn
WndProc endp

WinMain proc
local msg:MSG

push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov esi,IMAGE_BASE
mov edi,offset ClassName
push rbx ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_APPWORKSPACE ;hbrBackground
push rbx ;hCursor
push rbx        ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
db 68h
dd WndProc      ;lpfnWndProc
push sizeof WNDCLASSEX ;cbSize & style
mov ecx,esp ;addr WNDCLASSEX
call RegisterClassEx
push rbx
push rsi ;rsi=400000h
push rbx
push rbx
push cdYSize
push cdXSize
push cdYPos
push cdXPos
mov r9d,WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h ; dwExStyle
call CreateWindowEx
@@:     lea ecx,msg
xor edx,edx
xor r8d,r8d
xor r9d,r9d
call GetMessage
cmp msg.wParam,VK_ESCAPE;user press 'Esc'?
je wmDESTROY
lea ecx,msg
call DispatchMessage
jmp @b
WinMain endp
.data
ClassName db 'Talon Fractal',0
bi BITMAPINFO <<28h,640,-430,1,32,0,0,0,0,0,0>>
bufDIBDC dq ?
pMainDIB dq ?
const340 dd 340.0
const120 dd 120.0
const160 dd 160.0
end
--- End code ---

Mikl__:

--- Code: ---include win64a.inc
include msvcrt.inc
includelib gdi32.lib
includelib msvcrt.lib
IMAGE_BASE equ 400000h
cdXPos          equ 131
cdYPos          equ 217
cdYSize         equ 430
cdXSize         equ 640

movr macro x,y
mov x,0
org $-4
dd y
endm

.code


WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD

local ps:PAINTSTRUCT
local hdc:qword
local hOldBmp:qword
local hGDITmp:qword
local hOldDIB:qword
local hBackDC:qword
local hMainDIB:qword
local bufBMP:qword
local i:dword
local x:dword
local y:dword
local a:dword
local b:dword
local c:dword
local d:dword
local e:dword
local f:dword
local NewX:qword
local NewY:qword
local XCC:qword
local YCC:qword

push rbp
mov ebp, esp
sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16)

mov hWnd,rcx
cmp edx, WM_DESTROY
jz wmDESTROY
        cmp edx, WM_PAINT
jz wmPAINT
        cmp edx, WM_CREATE
jz wmCREATE
leave
        jmp DefWindowProc
; ---------------------------------------------------------------------------
wmDESTROY::mov rdx,hOldBmp
mov rcx,hBackDC
call SelectObject
mov hGDITmp,rax
mov rcx,bufBMP
call DeleteObject
mov rcx,hBackDC
call DeleteDC
mov rdx,hOldDIB
mov rcx,bufDIBDC
call SelectObject
mov hGDITmp,rax
mov rcx,bufDIBDC
call DeleteDC
mov rcx,hMainDIB
call DeleteObject
mov rcx,hWnd
call DestroyWindow
xor ecx,ecx ; nExitCode
call ExitProcess
; ---------------------------------------------------------------------------
wmPAINT:lea edx,ps
call BeginPaint
mov hdc,rax
mov qword ptr [rsp+40h],SRCCOPY; rop
        xor edx,edx ; x
mov [rsp+38h],rdx ; y1
mov [rsp+30h],rdx ; x1
mov rax,bufDIBDC ; hdcSrc
        mov [rsp+28h],rax
mov rax,cdYSize
mov [rsp+20h],rax
mov r9,cdXSize ; cx
xor r8d,r8d ; cy
mov rcx,hdc ; hdc
call BitBlt
lea edx,ps
mov rcx,hWnd
call EndPaint
jmp wmBYE
; ---------------------------------------------------------------------------
wmCREATE:mov rcx,hWnd
call GetDC
mov hdc,rax
        mov rcx,rax ; HDC
call CreateCompatibleDC
mov bufDIBDC,rax

mov [rsp+28h],rbx
mov [rsp+20h],rbx
mov r9d,offset pMainDIB
mov r8d,DIB_RGB_COLORS
mov edx,offset bi
mov rcx,hdc
        call CreateDIBSection
mov hMainDIB,rax
mov rdx,rax; hMainDIB
mov rcx,bufDIBDC
call SelectObject
        mov rax,hOldDIB
mov rdx,hdc
mov rcx,hWnd         
        call ReleaseDC;   // Libera device context         
;Init--------------------------------------------------------
; a     b     c   d    e     f    p
; 0.45881 -0.22565  0.07268 0.60187 -0.00177  0.31948 0.31*10000=3100
; 0.34268  0.37561 -0.20337 0.54642 -0.02210  0.32976 0.20*10000=2000;5100
; 0.13582  0.50273 -0.31347 0.13846 -0.02004  0.21706 0.16*10000=1600;6700
; 0.25326 -0.48975  0.30798 0.34989 -0.00740  0.19810 0.23*10000=2300;9000
; 0.06641  0        0       0.47942 -0.01492 -0.02422 0.10*10000=1000;
mov XCC,rbx
mov YCC,rbx
mov i,45000
bucle:  call rand
mov ecx,10000
xor edx,edx
div ecx
cmp edx,3160
jg @f
cmp edx,3100
jg @f
movr a,0.45881
movr b,-0.22565 
movr c,0.07268
movr d,0.60187     
movr e,-0.00177   
movr f,0.31948
jmp fin
@@: cmp edx,5100
jg @f
movr a,0.34268 
movr b,0.37561
movr c,-0.20337
movr d,0.54642
movr e,-0.02210 
movr f,0.32976
jmp fin
@@: cmp edx,6700
jg @f
movr a,0.13582 
movr b,0.50273
movr c,-0.31347
movr d,0.13846
movr e,-0.02004 
movr f,0.21706
jmp fin
@@: cmp edx,9000
jg @f
movr a,0.25326
movr b,-0.48975 
movr c,0.30798
movr d,0.34989
movr e,-0.00740 
movr f,0.19810
jmp fin
@@: movr a,0.06641                 
mov b,ebx
mov c,ebx
movr d,0.47942
movr e,-0.01492
movr f,-0.02422

fin: fld a       ;st(0) = a
fmul XCC     ;st(0) = a * XCC
fld b       ;st(0) = b
fmul YCC     ;st(0) = b * YCC
faddp         ;st(0) = a * XCC + b * YCC
        fadd e       ;st(0) = a * XCC + b * YCC + e
fst NewX    ;NewX  = a * XCC + b * YCC + e
fmul const470;st(0) = NewX * 470
        fadd const320 ;st(0) = NewX * 470 + 320
fistp x       ;x = (int) (NewX * 470 + 320)
        mov eax,x
cmp eax,cdXSize
jae @f
fld c       ;st(0) = c
fmul XCC     ;st(0) = c * XCC
fld d       ;st(0) = d
fmul YCC     ;st(0) = d * YCC
faddp         ;st(0) = c * XCC + d * YCC
fadd f       ;st(0) = c * XCC + d * YCC + f
fst NewY    ;NewY  = c * XCC + d * YCC + f
fst YCC     ;YCC = NewY
fmul const470;st(0) = NewY * 470
fsubr const420;st(0)  = -NewY * 470 + 420
fistp y       ; y = (int) (-NewY * 470 + 420)
mov ecx, y
cmp ecx,cdYSize
jae @f
imul ecx,cdXSize*4
add rcx,pMainDIB
mov dword ptr [rcx+rax*4],0FF00h ;*(pMainDIB + y*cdXSize*4 + x*4) = orange color
@@: fld NewX  ;XCC = NewX
fstp XCC
dec i
jnz  bucle
wmBYE: leave
retn
WndProc endp

WinMain proc
local msg:MSG

push rbp
mov ebp,esp
sub esp,sizeof MSG

xor ebx,ebx
mov esi,IMAGE_BASE
mov edi,offset ClassName
push rbx ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOWTEXT; hbrBackground
push rbx ;hCursor
push rbx        ;hIcon
push rsi ;hInstance
push rbx        ;cbClsExtra & cbWndExtra
db 68h
dd WndProc      ;lpfnWndProc
push sizeof WNDCLASSEX ;cbSize & style
mov ecx,esp ;addr WNDCLASSEX
call RegisterClassEx
push rbx
push rsi ;rsi=400000h
push rbx
push rbx
push cdYSize
push cdXSize
push cdYPos
push cdXPos
mov r9d,WS_VISIBLE
mov r8,rdi ;offset ClassName
mov edx,edi ;offset ClassName
xor ecx,ecx
sub esp,20h ; dwExStyle
call CreateWindowEx
@@:     lea ecx,msg
xor edx,edx
xor r8d,r8d
xor r9d,r9d
call GetMessage
cmp msg.wParam,VK_ESCAPE;user press 'Esc'?
je wmDESTROY
lea ecx,msg
call DispatchMessage
jmp @b
WinMain endp

.data
ClassName db 'Tree #5 Fractal',0
bi BITMAPINFO <<28h,cdXSize,-cdXSize,1,32,0,0,0,0,0,0>>
bufDIBDC dq ?
pMainDIB dq ?
const470 dd 470.0
const320 dd 320.0
const420 dd 420.0
end
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version