Hello. At the moment I'm trying to convert a C macro into asm and I'm having difficulties because it uses floating points. The C macro is defined as


#define D3DCOLOR_COLORVALUE(r,g,b,a) \

I have written the D3DCOLOR_RGBA macro which uses another (Thats just the way it is the the header so I'm trying to be faithful to it). These look like

D3DCOLOR_RGBA macro r:REQ, g:REQ, b:REQ, a:REQ
exitm D3DCOLOR_ARGB(a, r, g, b)

D3DCOLOR_ARGB macro a:REQ, r:REQ, g:REQ, b:REQ
exitm %(((a and 0ffh) shl 24) or ((r and 0ffh) shl 16) or ((g and 0ffh) shl 8) or (b and 0ffh))

I think these macros are correct. My problem is that when I try converting the D3DCOLOR_COLORVALUE macro, it complains about using floating points when I use it.

error A2050: real or BCD number not allowed
D3DCOLOR_ARGB(1): Macro Called From
D3DCOLOR_RGBA(1): Macro Called From
D3DCOLOR_COLORVALUE(1): Macro Called From
Test.asm(100): Main Line Code

My current non-working version is

exitm D3DCOLOR_RGBA(&r * 255.0, &g * 255.0, &b * 255.0, &a * 255.0)

I try to use it as D3DCOLOR_COLORVALUE(1.0,1.0,1.0,1.0).

I'm still not very good with the &, %, and ! stuff, so those could be all wrong. I'd really appreciate any suggestions.
Posted on 2003-06-09 01:36:42 by AlexEiffel
MASM sucks in that it can't do FPU math with constants. Try something simple like:

REAL4 1.0 * 3.0

Error...how lame.

Temp solution: do the math in code. :(
Posted on 2003-06-09 03:25:44 by bitRAKE

I am not a C guru, but it appears that the C macro is trying to put the four floating point values into 4 double words. The documentation for D3DCOLOR appears to want to put the 0 to 255 integer values into the four eight-bits of a double word, using the format of (A,B,G,R) . Maybe they convert the floating point word into 8-bit integer first, and then insert it into the (A,B,G,R) format. You have to figure out what is needed before you can write an macro to duplicate it. The code below is similiar to yours. Ratch


ARG EQU (P4 SHL 24)+(P3 SHL 16)+(P2 SHL 8)+P1
Posted on 2003-06-09 10:18:28 by Ratch
Why do you use floating point constants?

Aren't integer constants just fine for the RGB values you're trying to create?
Randy Hyde
Posted on 2003-06-09 10:18:37 by rhyde
Thanks for the replies guys.

bitRAKE, can you use instructions in a macro that returns a value? I seem to remember reading that you cant, but I'm not sure.

Rath, you're exactly right with what they are trying to do. I understand what is going on in that code, I just didn't know how to translate the other macro.

randall.hyde, you're right that integers would be perfectly alright for a RGB thing. However, there is structure in Direct3D defined like the following

typedef struct _D3DCOLORVALUE {
float r;
float g;
float b;
float a;

They have a macro in the d3d9types.h header that will convert a D3DCOLORVALUE to a DWORD. I'm just trying to convert that macro into asm.
Posted on 2003-06-09 17:18:38 by AlexEiffel

bitRAKE, can you use instructions in a macro that returns a value? I seem to remember reading that you cant, but I'm not sure.
Macros inline the code - the concept of returning a value does not aply unless you define a interface for the macro (like assuming the value is placed in EAX). The fact that an MASM implementation of this macro requires loading a constant FPU value during runtime is absurd, imho. If all the values are constant then MASM should be able to compute a single constant DWORD as output, but it can't. :(
Posted on 2003-06-09 21:04:08 by bitRAKE

I think you or I could write a MACRO FUNCTION that would return a DWORD value in RGBA format and be called like D3DWORD(0437F0000H,03F800000H,040800000H,041000000H), where those four hex values represent D3DWORD(255.0,1.0,4.0,8.0) respectively. Unfortunately, MASM is crippled in its ability to generate floating point numbers for EQUs and MACRO parameters, so you have to explicitly code them in. Strangely, MASM has no problem doing floating point memory coding like DD 4.0 . Maybe it's time to jump ship to another assembler that has complete floating point capabilities. Ratch
Posted on 2003-06-09 21:46:05 by Ratch