flat assembler
Message board for the users of flat assembler.

Index > Windows > Problem with proc macro.

Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 24 Feb 2009, 00:03
When I call a function made with the proc macro with no parameters, I get a crash. But when I call the same function with one parameter [test] the program works as it should. Any idea what is wrong here? Below is the function:

Code:
proc oneTimeSystemInit, test

     invoke  Direct3DCreate9, D3D_SDK_VERSION
     .if     eax = NULL
             invoke  MessageBox, NULL, "Direct3DCreate9()", "ERROR", MB_OK or MB_ICONERROR
             invoke  PostQuitMessage, 0
             return  FALSE
     .endif
     mov     [pD3D], eax

     D3DCALL pD3D, GetAdapterDisplayMode, D3DADAPTER_DEFAULT, d3ddm
     .if     eax <> D3D_OK
             invoke  MessageBox, HWND_DESKTOP, "D3D->GetAdapterDisplayMode()", "ERROR",\
                     MB_OK or MB_ICONERROR
             invoke  PostQuitMessage, 0
             return
     .endif

     mov     [d3dpp.Windowed], TRUE
     mov     [d3dpp.SwapEffect], D3DSWAPEFFECT_DISCARD
     mov     eax, [d3ddm.Format]
     mov     [d3dpp.BackBufferFormat], eax
     mov     [d3dpp.EnableAutoDepthStencil], TRUE
     mov     [d3dpp.AutoDepthStencilFormat], D3DFMT_D16
     mov     [d3dpp.Presentation_Interval], D3DPRESENT_INTERVAL_IMMEDIATE

     D3DCALL pD3D, CreateDevice, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, [hWnd],\
             D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp, pd3dDevice
     .if     eax <> D3D_OK | [pd3dDevice] = NULL
             invoke  MessageBox, [hWnd], "D3D->CreateDevice()", "ERROR", MB_OK or MB_ICONERROR
             invoke  PostQuitMessage, 0
             return
     .endif

     ;Setup a material for the teapot
     finit
     fldz
     fstp    [teapotMtrl.Diffuse.r]
     fld1
     fst     [teapotMtrl.Diffuse.g]
     fst     [teapotMtrl.Diffuse.b]
     fst     [teapotMtrl.Diffuse.a]
     fst     [teapotMtrl.Specular.r]
     fst     [teapotMtrl.Specular.g]
     fst     [teapotMtrl.Specular.b]
     fstp    [teapotMtrl.Specular.a]
     fldd    40.0
     fstp    [teapotMtrl.Power]

     ;Setup a material for the textured quad
     fld1
     fst     [quadMtrl.Diffuse.r]
     fst     [quadMtrl.Diffuse.g]
     fst     [quadMtrl.Diffuse.b]
     fst     [quadMtrl.Diffuse.a]
     fst     [quadMtrl.Specular.r]
     fst     [quadMtrl.Specular.g]
     fst     [quadMtrl.Specular.b]
     fstp    [quadMtrl.Specular.a]
     fldd    40.0
     fstp    [quadMtrl.Power]

     ;Setup a simple directional light and some ambient
     mov     [pLight0.Type], D3DLIGHT_DIRECTIONAL
     fld1
     fstp    [pLight0.Direction.x]
     fldz
     fstp    [pLight0.Direction.y]
     fld1
     fst     [pLight0.Direction.z]
     fst     [pLight0.Diffuse.r]
     fst     [pLight0.Diffuse.g]
     fst     [pLight0.Diffuse.b]
     fst     [pLight0.Diffuse.a]
     fst     [pLight0.Specular.r]
     fst     [pLight0.Specular.g]
     fst     [pLight0.Specular.b]
     fstp    [pLight0.Specular.a]

     ;Any resources or settings that need to be restored after losing the
     ;DirectD device should probably be grouped together into one function so
     ;they can be re-created or reset in one call.
     call    restoreDeviceObjects
     return
endp
    

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 24 Feb 2009, 00:03
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 24 Feb 2009, 00:40
What package are you using? "return" is not supported since several years now, it should not compile in first place unless you have defined such macro.
Post 24 Feb 2009, 00:40
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 24 Feb 2009, 00:55
I'm using the latest fasmw package: 1.67.34
I've been using the return macro for years without problems. But, anyways, here is the macro define that I'm using:
Code:
macro return retval {
       if ~ retval eq
          mov eax, retval
       end if
       ret
}    

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 24 Feb 2009, 00:55
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 24 Feb 2009, 01:33
Odd, I'm getting the correct prologue and epilogue codes with your macro. Perhaps there is something else disturbing your macro?

What is the definition of "restoreDeviceObjects"? Your code also crash if you add a "test2" parameter?
Post 24 Feb 2009, 01:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20518
Location: In your JS exploiting you and your system
revolution 24 Feb 2009, 02:41
It is usual to write the first parameter without a comma:
Code:
proc oneTimeSystemInit test    
Post 24 Feb 2009, 02:41
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 24 Feb 2009, 04:55
Quote:
What is the definition of "restoreDeviceObjects"? Your code also crash if you add a "test2" parameter?

'restoreDeviceObjects' is the same kind of function as 'oneTimeSystemInit'.
No parameters, called using 'call' instruction. As for the second, (third, fourth) parameter, no, it doesn't. Just with zero parameters

Quote:
It is usual to write the first parameter without a comma

yeah, your right.

I'll post the whole source file:


Description: File causing me problems
Download
Filename: Resize Window.asm
Filesize: 20.2 KB
Downloaded: 356 Time(s)


_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 24 Feb 2009, 04:55
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 25 Feb 2009, 19:47
I've Figured out what the problem was, bad floating point load macro's.
I've replaced them with my older ones that work.
NEWER [bad] macro's:
Code:
macro fildd i32 {
      push    i32
      fild    dword [esp]
      sub     esp, 4
}

macro fldd f32 {
      pushd   f32
      fld     dword [esp]
      sub     esp, 4
}

macro fildq i64 {
      pushd   double i64
      fild    qword [esp]
      sub     esp, 8
}

macro fldq f64 {
      pushd   double f64
      fld     qword [esp]
      sub     esp, 8
}    


OLDER (good) macro's:
Code:
macro fldq dfloat {
     local ..mynumber, ..here
     fld [..mynumber]
     jmp ..here
     align 8
     ..mynumber dq dfloat
  ..here:
}

macro fldd dfloat {
     local ..mynumber, ..here
     fld [..mynumber]
     jmp ..here
     align 4
     ..mynumber dd dfloat
  ..here:
}

macro fildd integer {
     local ..mynumber, ..here
     jmp ..here
     align 4
     ..mynumber dd integer
..here:
     fild [..mynumber]
}

macro fildq integer {
     local ..mynumber, ..here
     jmp ..here
     align 8
     ..mynumber dq integer
..here:
     fild [..mynumber]
}    
Post 25 Feb 2009, 19:47
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 25 Feb 2009, 21:07
Glad you found the problem, I was looking to it for almost half an hour and couldn't find nothing. (it was all by eye because I don't have your includes so I couldn't compile and test nor look to your custom macros like fldd).
Post 25 Feb 2009, 21:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20518
Location: In your JS exploiting you and your system
revolution 26 Feb 2009, 00:07
Folks, another example of a good lesson here, always include everything when posting code and asking for help with a problem. You waste everyone's time (including your own) when you only post bits of things and assume that the bits you don't post are working.
Post 26 Feb 2009, 00:07
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 cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.