News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

What am I doing wrong??

Started by bigrichlegend, September 28, 2006, 08:54:20 PM

Previous topic - Next topic

bigrichlegend

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

"

PBrennick

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 GeneSys Project is available from:
The Repository or My crappy website

bigrichlegend

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.

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

stanhebben

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

japheth


one problem might be that you use FSTP to store - float! - values in x1-y2. MoveTo() and LineTo() expect integer values!

stanhebben

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

bigrichlegend

Many thanks. This is exactly what I was hoping to achieve. cheers guys!!!

PBrennick

Stan,
Can you post your code as an attachment?  I would like to see your changes.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

P1

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)

stanhebben

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

PBrennick

P1,
You are a very strange person!  :bdg

Paul
The GeneSys Project is available from:
The Repository or My crappy website

agathon

#12
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?

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

P1

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