# Macros

## Description

GX_FX16PAIR(a, b) | Packs two fixed-decimal `fx16` types in a `u32` type.
GX_RGB(r, g, b) | Packs each 5-bit rgb value into a `GXRgb` type.
GX_RGBA(r, g, b, a) | Packs each 5-bit rgb value and the 1-bit α value into a `GXRgba` type.
GX_VECFX10(x, y, z) | Packs normal vector and light vector information into a `VecFx10` type.
GX_VECVTX10(x, y, z) | Packs the 3-dimensional s3.6 vector into a `VecVtx10` type.
GX_ST(s, t) | Packs texture coordinates.
GX_COMP4x4_PLTT_IDX(image) | Calculates the palette address from the `COMP4x4` texture image address.

## Macro Definitions

    #define GX_FX16PAIR(a, b)              ((u32)((u32)(u16)(a) | ((u32)(u16)(b) << 16)))

    #define GX_RGB(r, g, b)           ((GXRgb)(((r) << GX_RGB_R_SHIFT) | \
                                                     ((g) << GX_RGB_G_SHIFT) | \
                                                     ((b) << GX_RGB_B_SHIFT)))

    #define GX_RGBA(r, g, b, a)       ((GXRgba)(((r) << GX_RGBA_R_SHIFT) | \
                                                      ((g) << GX_RGBA_G_SHIFT) | \
                                                      ((b) << GX_RGBA_B_SHIFT) | \
                                                      ((a) << GX_RGBA_A_SHIFT)))

    #define GX_VECFX10(x, y, z) \
        ((VecFx10)(((((x) >> (FX32_DEC_SIZE - GX_FX10_DEC_SIZE)) & GX_FX10_MASK) << GX_VEC_FX10_X_SHIFT) | \
                   ((((y) >> (FX32_DEC_SIZE - GX_FX10_DEC_SIZE)) & GX_FX10_MASK) << GX_VEC_FX10_Y_SHIFT) | \
                   ((((z) >> (FX32_DEC_SIZE - GX_FX10_DEC_SIZE)) & GX_FX10_MASK) << GX_VEC_FX10_Z_SHIFT)))

    #define GX_VECVTX10(x, y, z) \
        ((VecVtx10) (((((x) >> (FX32_DEC_SIZE - GX_VTX10_DEC_SIZE)) & GX_VTX10_MASK) << GX_VEC_VTX10_X_SHIFT) | \
                     ((((y) >> (FX32_DEC_SIZE - GX_VTX10_DEC_SIZE)) & GX_VTX10_MASK) << GX_VEC_VTX10_Y_SHIFT) | \
                     ((((z) >> (FX32_DEC_SIZE - GX_VTX10_DEC_SIZE)) & GX_VTX10_MASK) << GX_VEC_VTX10_Z_SHIFT)))

    #define GX_FX16ST(x)                   ((s16)((x) >> 8))
    // s: fx32/fx16, t: fx32/fx16
    #define GX_ST(s, t)                    ((GXSt)((u16)GX_FX16ST(s) | ((u16)GX_FX16ST(t) << 16)))

    #define GX_COMP4x4_PLTT_IDX(image) \
        ((u32)(0x20000 + (((image) & 0x1ffff) >> 1) + (((image) & 0x40000) >> 2)))

## Revision History

2004/02/23 Initial version.

CONFIDENTIAL