News:

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

Floating constant with macros....

Started by Tron2.0, January 28, 2010, 05:02:11 PM

Previous topic - Next topic

Tron2.0

I was trying to recode some examples of DirectX9 using Win32Inc, when i found a problem: masm don't pass real numbers as parameters.... :boohoo:
So, because i can't obviously modify the macros of the include package, i tried to code a macro to convert real (only single and double) into hex.
If somebody else needs it....

Use these for single precision:

.data?
one   REAL4   ?
.code
mov      one,@R4(1.234)

or

movr4   one,1.234

and this for double:

.data?
two    REAL8   ?
.code
movr8   two,-987.654

One more thing: invoke don't accept constant of 8 bytes, but only vars....i suppose  :red

dedndave

masm passes real4's just fine
if you are using larger reals, pass a pointer instead   :U

Tron2.0

Look this code.....

;; Setup a simple directional light and some ambient...
mov   sDxLight0.Type,D3DLIGHT_DIRECTIONAL
mov   sDxLight0.Direction,D3DXVECTOR3(1.0,0.0,1.0)
mov   sDxLight0.Diffuse.r,1.0
mov   sDxLight0.Diffuse.g,1.0
mov   sDxLight0.Diffuse.b,1.0
mov   sDxLight0.Diffuse.a,1.0
mov   sDxLight0.Specular.r,1.0
mov   sDxLight0.Specular.g,1.0
mov   sDxLight0.Specular.b,1.0
mov   sDxLight0.Specular.a,1.0
invoke   IDirect3DDevice9_SetLight(pDxDevice,0,addr sDxLight0)
invoke   IDirect3DDevice9_LightEnable(pDxDevice,0,TRUE)
invoke   IDirect3DDevice9_SetRenderState(pDxDevice,D3DRS_AMBIENT,D3DCOLOR_COLORVALUE(0.2,0.2,0.2,1.0))

Is extracted from the example that i'm converting to masm and Win32Inc....

dedndave

hmmmmm
i wonder if you put it into an EQUate, first ?
the parser may not like the decimal point on the instruction line

Real4_One EQU 1.0

i am not sure if you can use reals in EQUates   :P

but, 1.0 is 3F800000h - that must be what you are up to

oex

literal_float      macro   lit_float
         local   local_float

         .data
local_float      real4   lit_float

         .code
         exitm   <local_float>
         endm

CFLT         macro   lit_float
         exitm   <literal_float(lit_float)>
         endm


Usage CFLT(1.0)

Honestly dont 100% understand macro though

EDIT: At least I didnt understand well enough to write it myself, I get it now....

I believe nehe has a better way so you can include actual 2.0,5.1 etc but never checked how
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Tron2.0

My macro don't require the .data section and give back a constant in hexadecimal.....

try proto one:real4

invoke try,@R4(1.0)  = invoke try,03F800000h

drizz

There is a simpler way for Real4 floats
MovR4 macro __rmi:req,__num:req
   mov __rmi,DWORD PTR 0
   ORG $-4
   dd __num
endm


MovR4 num,1.0

ps: you don't need this with jwasm!
The truth cannot be learned ... it can only be recognized.

Tron2.0

#7
I tested the macro with Nehe tutorials and it doesn't work correctly with all numbers....
It's because i forgot to normalize the range from 0.0 to 1.0..... :naughty:
So, i added the missing code and now seems to work fine.....(err... i think  :red)
The pushr8 works well with OpenGL functions call.

Tron2.0

Update.....
Ok, last time i thinked wrong :snooty:.....there is a problem with 0.0 conversion (- and +).
I fixed the code, and now the macro returns the correct constant.....
I added to the zip a simple test of movr4/movr8 macros. It's only for debugging purpose....