In am trying to code a "Maurer Rose" in asm but can't find what is wrong. The program compiles without errors but displays nothing. Can anyone help?here is my code
".386
.MODEL FLAT,STDCALL
include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
WinMain PROTO :DWORD, :DWORD, :DWORD, :SDWORD
.data
ClassName DB "SimpleWinClass",0
AppName DB "Maurer Rose",0
scaleX DD ?
scaleY DD ?
cxClient DD ?
cyClient DD ?
x1 DD ?
y1 DD ?
x2 DD ?
y2 DD ?
tempx DD ?
tempy DD ?
mypie real4 0.0174603174603174603174603174603174603
theta real4 0.0
incr real4 1.0
radius real4 6.0
move real4 3.0
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
LOWORD MACRO bigword
mov eax,bigword
and eax,0FFFFh
ENDM
HIWORD MACRO bigword
mov ebx,bigword
shr ebx,16
ENDM
RGB MACRO red, green, blue
mov al,blue
shl eax,8
add al,green
shl eax,8
add al,red
and eax,0FFFFFFh
ENDM
;----------------------------------------------------------------------------
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:SDWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,0
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,200,200,500,500,NULL,NULL,\
hInst,NULL
mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc uses ebx esi edi, hWnd:HWND, uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL hdc:HDC, ps:PAINTSTRUCT
mov eax,uMsg
.IF eax==WM_SIZE
LOWORD lParam
mov cxClient,eax
invoke GetSystemMetrics, SM_CXSCREEN
mov tempx,eax
HIWORD lParam
mov cyClient,ebx
invoke GetSystemMetrics, SM_CYSCREEN
mov tempy,eax
.ELSEIF eax==WM_PAINT
invoke BeginPaint,hWnd, ADDR ps
mov hdc,eax
finit
fild cxClient
fild tempx
fdiv
fstp scaleX
fild cyClient
fild tempy
fdiv
fstp scaleY
mov si,0
.repeat
fld theta
fmul mypie
fcos
fmul radius
fmul scaleX
fstp x1
fld theta
fmul mypie
fsin
fmul radius
fmul scaleY
fstp y1
fld theta
fmul mypie
fmul move
fcos
fmul radius
fmul scaleX
fstp x2
fld theta
fmul mypie
fmul move
fsin
fmul radius
fmul scaleY
fstp y2
fld theta
fadd incr
fstp theta
invoke MoveToEx, hdc, x1, y1, NULL
invoke LineTo, hdc, x2,y2
inc si
.until si==360
invoke EndPaint,hWnd, ADDR ps
.ELSEIF eax==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
"
bigrichlegend,
It 'does' compile without errors and a window 'is' displayed. But you are using GetSystemMetrics in an incorrect way. This is usually used to get the height and width of a screen and then you would subtract the windows height and width from that so you can divide the remainder by 2 in order to center the window. I wonder if processing screen information from within the window code is a mistake?
Paul
the GetSystemMetrics functions I am use to try to scale the values - in the vain hope, so that they will display onscreen. Even when this routine isdeleted, nothing displays in the window.
That is correct, on the one hand you have incorrect values, on the other hand you have no values so nothing works. There is other Flags you could try. Try SM_CXMIN, SM_CYMIN or if they don't work use WM_GETMINMAXINFO
The WM_GETMINMAXINFO message is sent to a window when the size or position of the window is about to change. An application can use this message to override the window's default maximized size and position, or its default minimum or maximum tracking size.
So you can probably use that to force a specific size.
The best way is, when you created the window, you set these values as absolutes. Load them as variables so you can use those variables later in the program and if you do that you do not have to ask what the size is. For this to work you would need to modify the window so that it is not resizable.
Paul
I compiled the file, and I see the window. (but it's completely white)
Are you sure it compliled without errors? I had to add the line 'option casemap:none' to get it compiled.
Use the following to get the size of your window:
invoke GetClientRect, hWnd, addr rc
mov eax, rc.right
mov tempx, eax
mov eax, rc.bottom
mov tempy, eax
I don't get the following code:
fild cxClient
fild tempx
fdiv
fstp scaleX
Shouldn't you simply use tempx and tempy as scaling values?
fild tempx
fstp scaleX
And there really are errors in your calculations, i got x/y values ranging in billions!
EDIT: you used fstp instead of fistp to store the x/y values. Now I already get something on my screen, but I don't think it's correct :P
one problem might be that you use FSTP to store - float! - values in x1-y2. MoveTo() and LineTo() expect integer values!
Indeed.
I changed a few calculations, and now the rose fits the screen. Is http://i24.photobucket.com/albums/c3/stanhebben/maurer_rose.gif what you wanted?
I was already wondering what a maurer rose looked like :P
Stan
Many thanks. This is exactly what I was hoping to achieve. cheers guys!!!
Stan,
Can you post your code as an attachment? I would like to see your changes.
Paul
Quote from: Stan Hebben on September 29, 2006, 07:50:16 AMI was already wondering what a maurer rose looked like :P
Me too, but I did not think it would look too much like a programmer sitting naked on my computer screen. :eek
Regards, P1 :8)
Quote from: PBrennick on September 29, 2006, 10:55:46 AM
Can you post your code as an attachment? I would like to see your changes.
As soon as I'm back on my own PC (monday).
P1,
You are a very strange person! :bdg
Paul
Hi,
For those of you who have coded this for recreational purposes, try other values of move. I particularly like 37 and 73. :8)
Cordially,
RWM
Also, suppose that I want to print a rose? How can I do so?
agathon,
There have been several versions of a screen capture to bitmap utility (I did one). Once you have it as a bitmap, printing it should be no problem.
Paul
Quote from: PBrennick on October 01, 2006, 09:12:20 PMYou are a very strange person! :bdg
Well, I call'em as I see'em.
Just an alien in this world. :U
Regards, P1
Hi,
Let me rephrase my previous request. What sequence of API calls would be necessary in order to print the image produced by this application?
Cordially,
RWM
Hello,bigrichlegend
it isn't the maurer_rose. but it works.
.586
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include \masm32\include\windows.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\msimg32.inc
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\msimg32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include \masm32\macros\macros.asm
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
ClassName db "MainWinClass",0
AppName db "Greadient",0
Rct RECT<0>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hWnd dd ?
Points dd 82 dup (?)
ptrArr dd 2 dup (?)
crTRIVERTEX struct
x dword ?
y dword ?
Red word ?
Green word ?
Blue word ?
Alpha word ?
crTRIVERTEX ends
crGRADIENT_TRIANGLE struct
Vertex1 dword ?
Vertex2 dword ?
Vertex3 dword ?
crGRADIENT_TRIANGLE ends
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,150,50,650,670,NULL,NULL,hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WndProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
m2m hWnd,hWin
invoke SetWindowText,hWin,SADD("Please click the left button of mouse")
.elseif uMsg==WM_LBUTTONDOWN
.data
r dd 180.0
p dd 3.1415926535897
pp dd 0
.code
fld dword ptr[p]
fdiv dword ptr[r]
fstp dword ptr[pp]
Call DrawGtadient
.ELSE
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DrawGtadient proc uses ebx edi esi
LOCAL TV0 :crTRIVERTEX
LOCAL TV1 :crTRIVERTEX
LOCAL TV2 :crTRIVERTEX
LOCAL TV3 :crTRIVERTEX
LOCAL GradRect0 :crGRADIENT_TRIANGLE
LOCAL GradRect1 :crGRADIENT_TRIANGLE
LOCAL hDC :DWORD
LOCAL memDC :DWORD
LOCAL hBmp :DWORD
invoke GetClientRect,hWnd,ADDR Rct
invoke GetDC,hWnd
mov hDC,eax
invoke CreateCompatibleDC,hDC
mov memDC,eax
invoke CreateCompatibleBitmap,hDC,Rct.right,Rct.bottom
mov hBmp,eax
invoke SelectObject,memDC,hBmp
mov GradRect0.Vertex1,0
mov GradRect0.Vertex2,1
mov GradRect0.Vertex3,2
mov GradRect1.Vertex1,0
mov GradRect1.Vertex2,1
mov GradRect1.Vertex3,3
mov TV0.x, 0
mov TV0.y, 0
mov TV0.Red, 0f000h
mov TV0.Green, 00000h
mov TV0.Blue, 00000h
m2m TV1.x, Rct.right
m2m TV1.y, Rct.bottom
mov TV1.Red, 0f000h
mov TV1.Green, 0f000h ;D9D0C4
mov TV1.Blue, 00000h
mov TV1.Alpha, 0
mov TV2.x, 0
m2m TV2.y, Rct.bottom
mov TV2.Red, 0f000h
mov TV2.Green, 0f000h ;D9D0C4
mov TV2.Blue, 00000h
mov TV2.Alpha, 0
m2m TV3.x, Rct.right
mov TV3.y, 0
mov TV3.Red, 00000h
mov TV3.Green, 0f000h ;D9D0C4
mov TV3.Blue, 00000h
mov TV3.Alpha, 0
invoke GradientFill,memDC,ADDR TV3,4,ADDR GradRect1,2,2
call CalcPoints
mov ebx, offset Points
mov edi,0
mov esi,0
.while (esi<320)
.while (edi<320)
invoke MoveToEx, memDC,[ebx+esi],[ebx+esi+4],NULL
invoke LineTo,memDC,[ebx+edi],[ebx+edi+4]
add edi,8
.endw
add esi,8
mov edi,0
.endw
invoke BitBlt,hDC,0,0,Rct.right,Rct.bottom,memDC,0,0,SRCCOPY
invoke DeleteObject,hBmp
invoke DeleteDC,memDC
invoke ReleaseDC,hWnd,hDC
ret
DrawGtadient endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
CalcPoints proc uses ebx esi edi
LOCAL radius:DWORD
.data
angel dq 0.0
pi dq 0.157079632679 ;pi/40 39744830961566084581988
.code
mov ebx, offset Points
mov edi, 41
mov eax, Rct.bottom
shr eax, 1
mov radius, eax
mov esi, eax
@Loop:
fld qword ptr [angel]
fsin
fimul dword ptr [radius]
fistp dword ptr [ebx]
neg dword ptr [ebx]
add dword ptr [ebx],esi
fld qword ptr [angel]
fcos
fimul dword ptr [radius]
fistp dword ptr [ebx+4]
add dword ptr [ebx+4],esi
fld qword ptr [angel]
fadd qword ptr [pi]
fstp qword ptr [angel]
add ebx,8
dec edi
jnz @Loop
ret
CalcPoints endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
[edit for resizing]
Cheers six_L. I do like this result. It does work. Now to decipher it
Attached is the source code I used. (almost forgot it...)
[attachment deleted by admin]