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 25 Jun 2005, 14:04
Hello,
When using the 'proc' macro in my .dll, the last variable in the list is getting bad values. Example:

Code:
**problem here** -> proc D3DTextRectangle  x0, y0, x1, y1, angle    


And, yes I have verified that I am NOT passing it bad values.
I'm using this method to pass the value

Code:
mov     [angle], 45.0  ;<- **or problem here**
invoke  D3DTextRectangle, [x0], [y0], [x1], [y1], [angle]     
Post 25 Jun 2005, 14:04
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 25 Jun 2005, 14:31
I've checked it with the following sources:
Code:
format PE GUI 4.0 DLL
entry DllEntryPoint

include 'win32a.inc'

section '.code' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
        mov     eax,TRUE
        ret
endp

proc D3DTextRectangle  x0, y0, x1, y1, angle
        mov     edx,$ ; dummy fixup (Win32 doesn't like DLLs without fixups)
        mov     eax,[angle]
        ret
endp

section '.edata' export data readable

  export 'LIB.DLL',\
         D3DTextRectangle,'D3DTextRectangle'

section '.reloc' fixups data discardable    

and
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.data' data readable writeable

  x0 dd ?
  y0 dd ?
  x1 dd ?
  y1 dd ?
  angle dd ?

section '.code' code readable executable

  start:

        mov     [angle], 45.0
        invoke  D3DTextRectangle, [x0], [y0], [x1], [y1], [angle]

        int3 ; at this point verify EAX with debugger (should be 45.0 = 42340000h)

        invoke  ExitProcess,0

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          lib,'LIB.DLL'

  import kernel,\
         ExitProcess,'ExitProcess'

  import lib,\
         D3DTextRectangle,'D3DTextRectangle'    

and it works OK for me.

Can you post some minimum source that causes the problem?
Post 25 Jun 2005, 14:31
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 25 Jun 2005, 17:24
Try defining some locals right after the 'proc', and see if that changes anything.

Also, here is the calling fragment:

Code:
        invoke  D3DClearBack, $ff000090
        invoke  D3DBeginDraw

        mov     [angle], 45.0
        invoke  D3DTextRectangle, [x0], [y0], [x1], [y1], [angle]

        invoke  D3DEndDraw

        invoke  D3DFlip    


And, the procedure:
Code:
proc D3DTextRectangle  x0, y0, x1, y1, angle
     locals
         centerx  dd 0
         centery  dd 0
         top      dd 0
         bottom   dd 0
         left     dd 0
         right    dd 0
         radtheta dd 0
         sine     dd 0
         cosine   dd 0
     endl

     mov     [texture.rhw], 1.0
     mov     [texture.rhw + sizeof.CustomVertexUV], 1.0
     mov     [texture.rhw + (sizeof.CustomVertexUV*2)], 1.0
     mov     [texture.rhw + (sizeof.CustomVertexUV*3)], 1.0

     mov     [texture.u], 0.0
     mov     [texture.v], 0.0
     mov     [texture.u + sizeof.CustomVertexUV], 1.0
     mov     [texture.v + sizeof.CustomVertexUV], 0.0
     mov     [texture.u + (sizeof.CustomVertexUV*2)], 1.0
     mov     [texture.v + (sizeof.CustomVertexUV*2)], 1.0
     mov     [texture.u + (sizeof.CustomVertexUV*3)], 0.0
     mov     [texture.v + (sizeof.CustomVertexUV*3)], 1.0


     mov     eax, [x0]
     mov     [texture.x], eax
     mov     eax, [y0]
     mov     [texture.y], eax

     mov     eax, [x1]
     mov     [texture.x + sizeof.CustomVertexUV],eax
     mov     eax, [y0]
     mov     [texture.y + sizeof.CustomVertexUV],eax

     mov     eax, [x1]
     mov     [texture.x + (sizeof.CustomVertexUV*2)],eax
     mov     eax, [y1]
     mov     [texture.y + (sizeof.CustomVertexUV*2)],eax

     mov     eax, [x0]
     mov     [texture.x + (sizeof.CustomVertexUV*3)],eax
     mov     eax, [y1]
     mov     [texture.y + (sizeof.CustomVertexUV*3)],eax

     fninit
     fld     [angle]

     ;Debug Info Code
     mov     byte [debugtxt],0
     stdcall CnvtFtoA, debugtxt, 6
     invoke  ShowCursor, TRUE
     invoke  MessageBox, [debughwin], debugtxt, debugtxt, MB_OK
     invoke  ShowCursor, FALSE

     mov     [radtheta], 0.017453293
     fmul    [radtheta]
     fld     st0
     fsin
     fstp    [sine]
     fcos
     fstp    [cosine]

     ;center radii
     fld     [texture.x + sizeof.CustomVertexUV]
     fadd    [texture.x]
     fmul    [onehalf]
     fstp    [centerx]

     fld     [texture.y + (sizeof.CustomVertexUV*2)]
     fadd    [texture.y]
     fmul    [onehalf]
     fstp    [centery]

     ;rectangle of new coordinates
     fld     [texture.y]
     fsub    [centery]
     fstp    [top]

     fld     [texture.y + (sizeof.CustomVertexUV*2)]
     fsub    [centery]
     fstp    [bottom]

     fld     [texture.x]
     fsub    [centerx]
     fstp    [left]

     fld     [texture.x + sizeof.CustomVertexUV]
     fsub    [centerx]
     fstp    [right]

     fninit
     ;vertex 0
     fld     [sine]
     fmul    [top]
     fld     [cosine]
     fmul    [left]
     fsub    st0,st1
     fadd    [centerx]
     fstp    [texture.x]

     fld     [cosine]
     fmul    [top]
     fld     [sine]
     fmul    [left]
     fadd    st0,st1
     fadd    [centery]
     fstp    [texture.y]

     ;vertex 1
     fld     [sine]
     fmul    [top]
     fld     [cosine]
     fmul    [right]
     fsub    st0,st1
     fadd    [centerx]
     fstp    [texture.x + sizeof.CustomVertexUV]

     fld     [cosine]
     fmul    [top]
     fld     [sine]
     fmul    [right]
     fadd    st0,st1
     fadd    [centery]
     fstp    [texture.y + sizeof.CustomVertexUV]

     fninit
     ;vertex 2
     fld     [sine]
     fmul    [bottom]
     fld     [cosine]
     fmul    [right]
     fsub    st0,st1
     fadd    [centerx]
     fstp    [texture.x + (sizeof.CustomVertexUV * 2)]

     fld     [cosine]
     fmul    [bottom]
     fld     [sine]
     fmul    [right]
     fadd    st0,st1
     fadd    [centery]
     fstp    [texture.y + (sizeof.CustomVertexUV * 2)]

     ;vertex 3
     fld     [sine]
     fmul    [bottom]
     fld     [cosine]
     fmul    [left]
     fsub    st0,st1
     fadd    [centerx]
     fstp    [texture.x + (sizeof.CustomVertexUV * 3)]

     fld     [cosine]
     fmul    [bottom]
     fld     [sine]
     fmul    [left]
     fadd    st0,st1
     fadd    [centery]
     fstp    [texture.y + (sizeof.CustomVertexUV * 3)]

     D3DCALL d3dev, DrawPrimitiveUP, D3DPT_TRIANGLEFAN, 2, texture, sizeof.CustomVertexUV
     ret
endp
     
Post 25 Jun 2005, 17:24
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 25 Jun 2005, 17:32
No, even with the same block of locals it's still OK. Please try to cut the whole program to minimum that shows the problem - otherwise I'm not able to reproduce it.
Post 25 Jun 2005, 17:32
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 25 Jun 2005, 20:06
Look at the 'D3DTextRectangle' procedure above, just after the "endl". Here is where I print out the variable angle and get 0.0 when it should be 45.0. the other variables are ok (x0, y0, x1, y1). The fragment of code above the procedure is what I use to call the procedures. One other thing, mov [angle], 45.0 works ok, something is getting lost between here and the first instruction of the procedure. Also, All this worked perfectly before all the changes.
Post 25 Jun 2005, 20:06
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 25 Jun 2005, 21:08
Hello, Tomasz
I've managed to figured out what the problem was, two variables with the same name defined in the same proc, see code below:

Code:
proc D3DTextRectangle  x0, y0, x1, y1, angle
     locals
         centerx  dd 0
         centery  dd 0
         top      dd 0
         bottom   dd 0
         left     dd 0
         right    dd 0
         radtheta dd 0
         sine     dd 0
         cosine   dd 0
         angle dd 0
     endl
    


As you can see, there are two angle variables being defined in the same proc, also this type of thing was done in a few more procedures as well, I delete all the angle variables in the local definitions (which was an older varaible used for an old rotation algorithm.). For some reason, this affected all procedures that had the variable 'angle' defined in the locals as well as in the parameters. Well anyways, thanks for your quick response and help. Maybe there could be a warning generated when defining local and parameter variables with the same name within a procedure?
Post 25 Jun 2005, 21:08
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 26 Jun 2005, 09:12
Currently when you define local of the same name as some of the already defined locals or procedure arguments, it just replaces the previous meaning of this symbol. To make such situation an error condition, you can put this code in the beginning of deflocal@proc macro:
Code:
   match locals, all@args,all@vars
   \{ if name in <locals>
       display 'Error: local symbol ',`name,' already defined.',0Dh,0Ah
       halt
     end if \}    
Post 26 Jun 2005, 09:12
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 26 Jun 2005, 21:34
Ok, will do, thanks! Very Happy
Post 26 Jun 2005, 21:34
View user's profile Send private message 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.