News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Fractals

Started by Mikl__, December 02, 2015, 08:27:27 PM

Previous topic - Next topic

learn64bit

I guess it should look like this, but not sure.

Mikl__

learn64bit
Yes, it should look like this

learn64bit

I can't find the "BITMAPINFO struct" in "opengl32.inc", I think I also need another file.

Mikl__

There are structures BITMAPFILEHEADER and BITMAPINFOHEADER in opengl32.inc
There is structure BITMAPINFO in masm32/include/wininc.inc and windows.inc

learn64bit

Is "RGBQUAD struct" also should use the one in "masm32\include\Windows.inc"?

Mikl__

in masm32/include/wininc.inc and windows.inc
RGBQUAD structure did not change

learn64bit

Compiling is ok, but Running is a Crashing...

Mikl__

#67
; GUI #
include win64a.inc

RGBQUAD STRUCT
       rgbBlue BYTE ?
       rgbGreen BYTE ?
       rgbRed BYTE ?
       rgbReserved BYTE ?
RGBQUAD ENDS

BITMAPINFO STRUCT
       bmiHeader BITMAPINFOHEADER <>
       bmiColors RGBQUAD   <>
BITMAPINFO ENDS

cdXPos          equ 131
cdYPos          equ 217
cdYSize         equ 430
cdXSize         equ 640

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

.code
WinMain proc
local msg: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
pushaddr WndProc      ;lpfnWndProc
push sizeof WNDCLASSEX ;cbSize & style
invoke RegisterClassExA,esp
push rbx
push rsi ;rsi=400000h
push rbx
push rbx
push cdYSize
push cdXSize
push cdYPos
push cdXPos
sub esp,20h
invoke CreateWindowExA,0,edi,edi,WS_VISIBLE
lea edi,msg
@@: invoke GetMessageA,edi,0,0,0
cmp [rdi].MSG.wParam,VK_ESCAPE;user press 'Esc'?
je wmDESTROY
invoke DispatchMessageA,edi
jmp @b
WinMain endp

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 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

mov hWnd,rcx

cmp edx, WM_DESTROY
jz wmDESTROY
        cmp edx, WM_PAINT
jz wmPAINT
        cmp edx, WM_CREATE
jz wmCREATE
leave
jmp NtdllDefWindowProc_
; ---------------------------------------------------------------------------
wmDESTROY::invoke SelectObject,hBackDC,hOldBmp
mov hGDITmp,rax
invoke DeleteObject,bufBMP
invoke DeleteDC,hBackDC
invoke SelectObject,bufDIBDC,hOldDIB
mov hGDITmp,rax
invoke DeleteDC,bufDIBDC
invoke DeleteObject,hMainDIB
invoke DestroyWindow,hWnd
invoke RtlExitUserProcess,NULL
; ---------------------------------------------------------------------------
wmPAINT:lea edx,ps
invoke 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 qword ptr[rsp+20h],cdYSize
invoke BitBlt,hdc,,0,cdXSize
lea edx,ps
invoke EndPaint,hWnd
jmp wmBYE
; ---------------------------------------------------------------------------
wmCREATE:invoke GetDC
mov hdc,rax
        invoke CreateCompatibleDC,eax
mov bufDIBDC,rax

mov [rsp+28h],rbx
mov [rsp+20h],rbx
mov r9d,offset pMainDIB
mov edx,offset bi
invoke CreateDIBSection,hdc,,DIB_RGB_COLORS
mov hMainDIB,rax
invoke SelectObject,bufDIBDC,eax
        mov rax,hOldDIB
invoke ReleaseDC,hWnd,hdc
;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:  invoke rand
mov ecx,10000
cdq
idiv 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: cvtss2sd xmm0,a       ;xmm0 = a
mulsd xmm0,XCC     ;xmm0 = a * XCC
cvtss2sd xmm1,b       ;xmm1 = b
mulsd xmm1,YCC     ;xmm1 = b * YCC
addsd xmm0,xmm1        ;xmm0 = a * XCC + b * YCC
movq NewX,xmm0    ;NewX = a * XCC + b * YCC
mulsd xmm0,const40 ;xmm0 = NewX * 40
cvtss2sd xmm1,c      ;xmm1 = c
mulsd xmm1,XCC     ;xmm1 = c * XCC
cvtss2sd xmm2,d       ;xmm2 = d
mulsd xmm2,YCC     ;xmm2 = d * YCC
addsd xmm1,xmm2    ;xmm1 = c * XCC + d * YCC
cvtss2sd xmm2,f
addsd xmm1,xmm2    ;xmm1 = c * XCC + d * YCC + f
movq NewY,xmm1    ;NewY = c * XCC + d * YCC + f
movq YCC,xmm1     ;YCC = NewY
addsd xmm0,const320;xmm0 = NewX * 40 + cdXSize/2
cvtsd2si ecx,xmm0       ;x = (int) (NewX*40+cdXSize/2)
cmp ecx,cdXSize
jae @f
movq xmm0,const1  ;xmm0 = 1
subsd xmm0,NewY    ;xmm0 = 1 - NewY
mulsd xmm0,const40 ;xmm0 = (1 - NewY)*40
addsd xmm0,const365;xmm0 = (1 - NewY)*40 + cdYSize - 35
cvtsd2si eax,xmm0; y = (int) ((1-NewY)*40+cdYSize-35)
cmp eax,cdYSize
jae @f
imul eax,2560
add rax,pMainDIB
mov dword ptr [rax+rcx*4],0FF00h ;*(pMainDIB + (y<<9)+(y<<7)+x) = Green color;
@@: movsd xmm0,NewX  ;XCC = NewX
movd XCC,xmm0
dec i
jnz bucle
wmBYE: leave
retn
WndProc endp
end

learn64bit

Thanks for updating!

Now I am reading "Maplex", It has same symptoms.

Mikl__

#69
; GUI #
include win64a.inc

RGBQUAD STRUCT
       rgbBlue BYTE ?
       rgbGreen BYTE ?
       rgbRed BYTE ?
       rgbReserved BYTE ?
RGBQUAD ENDS

BITMAPINFO STRUCT
       bmiHeader BITMAPINFOHEADER <>
       bmiColors RGBQUAD   <>
BITMAPINFO ENDS

cdXPos          equ 131
cdYPos          equ 217
cdYSize         equ 430
cdXSize         equ 640

.data
ClassName db 'Maple Fractal',0
bi BITMAPINFO <<28h,640,-430,1,32,0,0,0,0,0,0>>
bufDIBDC dq ?
pMainDIB dq ?
const470 dq 470.0
const82 dq 82.0
const42 dq 42.0
.code
WinMain proc
local msg: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
pushaddr WndProc      ;lpfnWndProc
push sizeof WNDCLASSEX ;cbSize & style
invoke RegisterClassExA,esp ;addr WNDCLASSEX
push rbx
push rsi ;rsi=400000h
push rbx
push rbx
push cdYSize
push cdXSize
push cdYPos
push cdXPos
sub esp,20h ; dwExStyle
invoke CreateWindowExA,0,edi,edi,WS_VISIBLE
        lea edi,msg
@@:     invoke GetMessageA,edi,0,0,0
cmp [rdi].MSG.wParam,VK_ESCAPE;user press 'Esc'?
je wmDESTROY
invoke DispatchMessageA,edi
jmp @b
WinMain endp
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 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

mov hWnd,rcx

cmp edx, WM_DESTROY
jz wmDESTROY
        cmp edx, WM_PAINT
jz wmPAINT
        cmp edx, WM_CREATE
jz wmCREATE
leave
        jmp NtdllDefWindowProc_
; ---------------------------------------------------------------------------
wmDESTROY::invoke SelectObject,hBackDC,hOldBmp
mov hGDITmp,rax
invoke DeleteObject,bufBMP
invoke DeleteDC,hBackDC
invoke SelectObject,bufDIBDC,hOldDIB
mov hGDITmp,rax
invoke DeleteDC,bufDIBDC
invoke DeleteObject,hMainDIB
invoke DestroyWindow,hWnd
invoke RtlExitUserProcess,NULL
; ---------------------------------------------------------------------------
wmPAINT:lea edx,ps
invoke 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 qword ptr[rsp+20h],cdYSize
invoke BitBlt,hdc,,0,cdXSize
lea edx,ps
invoke EndPaint,hWnd
jmp wmBYE
; ---------------------------------------------------------------------------
wmCREATE:invoke GetDC
mov hdc,rax
        invoke CreateCompatibleDC,eax
mov bufDIBDC,rax
mov [rsp+28h],rbx
mov [rsp+20h],rbx
mov r9d,offset pMainDIB
mov edx,offset bi
invoke CreateDIBSection,hdc,,DIB_RGB_COLORS
mov hMainDIB,rax
invoke SelectObject,bufDIBDC,eax; hMainDIB
        mov rax,hOldDIB
invoke ReleaseDC,hWnd,hdc
;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:  invoke 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: cvtss2sd xmm0,a      ;xmm0 = a
mulsd xmm0,XCC     ;xmm0 = a * XCC
cvtss2sd xmm1,b      ;xmm1 = b
mulsd xmm1,YCC     ;xmm1 = b * YCC
addsd xmm0,xmm1    ;xmm0 = a * XCC + b * YCC
cvtss2sd xmm1,e
        addsd xmm0,xmm1    ;xmm0 = a * XCC + b * YCC + e
movq NewX,xmm0    ;NewX  = a * XCC + b * YCC + e
mulsd xmm0,const470;st(0) = NewX * 470
        addsd xmm0,const82 ;st(0) = NewX * 470 + 82
cvtsd2si eax,xmm0    ;x = (int) (NewX * 470 + 82)
cmp eax,cdXSize
jae @f
cvtss2sd xmm0,c      ;xmm0 = c
mulsd xmm0,XCC     ;xmm0 = c * XCC
cvtss2sd xmm1,d      ;xmm1 = d
mulsd xmm1,YCC     ;xmm1 = d * YCC
addsd xmm0,xmm1    ;xmm0 = c * XCC + d * YCC
        cvtss2sd xmm1,f
addsd xmm0,xmm1    ;xmm0 = c * XCC + d * YCC + f
movq NewY,xmm0    ;NewY  = c * XCC + d * YCC + f
movq YCC,xmm0     ;YCC = NewY
xorps xmm1,xmm1    ;xmm1 = 0
subsd xmm1,xmm0    ;xmm1 = -NewY
mulsd xmm1,const470;xmm1 = -NewY * 470
addsd xmm1,const42 ;xmm1 = -NewY * 470 + 42
cvtsd2si ecx,xmm1    ;y = (int) (-NewY * 470 + 42)
cmp ecx,cdYSize
jae @f
imul ecx,cdXSize*4
add rcx,pMainDIB
mov dword ptr [rcx+rax*4],0FF8000h ;*(pMainDIB + y*cdXSize*4 + x*4) = orange color
@@: movq xmm0,NewX    ;XCC = NewX
movq XCC,xmm0
dec i
jnz bucle
wmBYE: leave
retn
WndProc endp
end

QuoteNow I am reading "Maplex", It has same symptoms.
learn64bit,
These programs were written 7 years ago. Now I don't write programs like that. Try to figure it out and redo them yourself.

learn64bit

7 years ago code style, it is still alive.

six_L

Hi,Mikl__
Have you researched the following mandelbrot fractal?

regard.
Say you, Say me, Say the codes together for ever.

Gunther

Mikl__,

Quote from: Mikl__ on August 23, 2022, 10:21:41 PM
These programs were written 7 years ago. ...

Wow. Has it been that long already? How time goes by. Это очень примечательно.
You have to know the facts before you can distort them.

Mikl__

Hi, six_L!
I haven't worked with fractals for a long time...

six_L

Hi,Mikl__
the fractal can create many beautiful graphics. we have learned many knowledge from your demos.
there are much variant about the mandelbrot fractal.

i only could draw the simple one.

regard.
Say you, Say me, Say the codes together for ever.