Files
tww/include/dolphin/gx/GX.h
T
Briggs Baltzell ea7c107eb7 d_menu_cloth matching (#937)
* Add `l_matDL` symbols and assets to config files for all regions for d_menu_cloth

* Extend `daCLOTH_HIO_c` with `JORReflexible` and add static instance `l_HIO` in `d_menu_cloth`

* Refactor `d_menu_cloth.h` to improve naming consistency for member variables.

* Initialize `dMCloth_c` member variables and create HIO child in constructor

* Include `l_matDL` in `d_menu_cloth` and call it in `dMCloth_c::draw`.

* Add private member variables to `daCLOTH_HIO_c` in `d_menu_cloth.h`

* Add virtual destructor to `daCLOTH_HIO_c` in `d_menu_cloth.h`

* Swap `daCLOTH_HIO_c` and `daCLOTH_ChildHIO_c` class definitions and adjust member variables in `d_menu_cloth.h`.

* Remove non-matching comments from `daCLOTH_ChildHIO_c` constructor and destructor in `d_menu_cloth.cpp`.

* Initialize `daCLOTH_HIO_c` member variables and update `daCLOTH_ChildHIO_c` access modifiers in `d_menu_cloth`.

* Remove unused member variables from `daCLOTH_HIO_c` and `daCLOTH_ChildHIO_c` in `d_menu_cloth.h`.

* Match dMCloth_c::dMCloth_c

* Match `dMCloth_c::init`.

* Match `dMCloth_c` destructor.

* Refactor `dMCloth_c` to use `mCurArr` for indexing and update structure definitions in `d_menu_cloth`.

* Define `ARR_SIZE` constant and replace hardcoded array sizes in `d_menu_cloth`.

* Match dMCloth_c::TevSetting

* Match dMCloth_c::TevSettingMenu

* Match `dMCloth_c::TevSettingMenu` and `dMCloth_c::TevSettingFileSelect`.

* Match `dMCloth_c::lightSet1`

* Start matching `dMCloth_c::cloth_init` and update structure definitions to use `INNER_SIZE` constant, optimize initialization logic, and replace redundant assignments with consolidated methods.

* Match `dMCloth_c::setNrmVtx` implementation and update header declaration.

* Match `daCLOTH_HIO_c` destructor implementation.

* Match `dMenu_ClothCreate`, `dMenu_ClothDelete`, `dMenu_ClothExecute`, `dMenu_ClothDraw`, and `dMenu_ClothIsDelete` implementations and update related structure definitions.

* Update `g_fopAc_Method` reference to `g_fopMsg_Method` in cloth menu structure.

* Match `dMCloth_c::cloth_move` implementation and update type definitions for `field_0xa` and `field_0x34` to `s16`.

* Start matching `dMCloth_c::cloth_move_sin` and `dMCloth_c::cloth_move_simple` implementations.

* Match `dMCloth_c::ShadowTevSetting` implementation.

* Match `dMCloth_c::ShadowTevSettingMenu` and `dMCloth_c::ShadowTevSettingFileSelect` implementations.

* Match `dMCloth_c::alpha_out` implementation.

* Match `dMCloth_c::plot` implementation and minor formatting fix in `dMCloth_c::ShadowTevSettingMenu`.

* Refactor `d_menu_cloth` to replace s16 color fields with `GXColorS10` and `GXColor` structures. Update all related logic and structure definitions accordingly.

* Match `dMCloth_c::draw` implementation, refactor initialization of `field_0x10`, and update associated structure definitions.

* Match `dMCloth_c::plot_shadow` implementation and update parameter names in `plot` and `plot_shadow` declarations.

* Update `d_menu_cloth` to use `msg_method_class` and `msg_process_profile_definition`. Refactor structure definitions and add TODO comment for size clarification.

* Add member comments in `dMenu_ClothMethodTable`

* Refactor `d_menu_cloth` to improve pointer arithmetic in `plot` loop and add missing implementations for `getOffsetVec` and `getShadowPos`.

* Refactor `dMCloth_c::plot` to improve naming consistency for loop variables and pointer arithmetic.

* Refactor `d_menu_cloth` to replace repeated member accesses with `HIO_CHILD` macro for improved readability and maintainability.

* Rename fields in `d_menu_cloth`

* Add clarifying comments in `dMenu_ClothMethodTable` about function order and usage

* Use `TRUE` and `FALSE` macros instead of literal values in `d_menu_cloth` methods for consistency.

* Replace numeric cloth type values with `MenuClothType` enum for improved readability and maintainability in `d_menu_cloth`.

* Refactor `dMCloth_c::cloth_init`: replace raw pointer arithmetic with `set` calls for improved clarity and maintainability.

* Refactor `MENU_CLOTH_TYPE_2` logic: replace hardcoded rotation calculation with `cM_deg2s` for clarity and maintainability.

* Change `wavePreSteps` type from `u16` to `s16` in `d_menu_cloth` for alignment with signed calculations.

* Replace hardcoded angle conversion with `cM_deg2s` in `MENU_CLOTH_TYPE_0` logic for improved clarity and maintainability.

* Change `mWaveProgress` type from `u16` to `s16` in `d_menu_cloth` for consistency with signed calculations.

* Match `cloth_init` in `d_menu_cloth`

* Fix `INNER_SIZE` iteration in `d_menu_cloth` to properly handle loop bounds.

* Update vertex attribute formats in `d_menu_cloth` for improved correctness.

* Add inline utility function `GXColor4x8` to `GX.h` for streamlined color input handling

* Refactor triangle strip generation in `d_menu_cloth` for improved readability and maintainability.

* Refactor vertex and texture coordinate handling in `dMCloth_c::plot_shadow` for improved clarity and correctness.

* Refactor vertex handling in `d_menu_cloth` to group vertex and texture operations for improved readability and structure.

* Add `GXNormal1x16` and `GXColor3x8` inline utility functions to `GX.h` for simplified normal and color input handling.

* Update vertex format in `d_menu_cloth` to use `GXPosition1x16` and `GXNormal1x16` for improved attribute handling.

* Add `dMs_clothOnly_create` and `dMs_clothOnly_delete` implementations in `d_menu_window`

* Implement `dMs_cloth_create` and `dMs_cloth_delete` functions in `d_menu_window` and update related structure definitions.

* Replace hardcoded cloth type with `MENU_CLOTH_TYPE_2` constant in `d_menu_window`.

* Refactor `MENU_CLOTH_TYPE` enum names for clarity and update all references across `d_menu_cloth`, `d_s_name`, and `d_menu_window`.

* Refactor `mChildren` array indexing in `daCLOTH_HIO_c` constructor to use `MENU_CLOTH_TYPE` constants for improved readability and maintainability.

* Refactor `color1` and `color2` fields to `clothColor` and `shadowColor` for improved clarity in `d_menu_cloth` structure and related logic.

* Simplify alpha blending logic by removing redundant variables in `d_menu_cloth`.

* Refactor `mColor1`/`mColor2` to `mClothColor`/`mShadowColor` for improved clarity in `d_menu_cloth` and update all related logic.

* Add temporary `dummy0` function in `d_menu_window` for placeholder debug strings.

* Refactor position array access in `d_menu_cloth` to use `getPos()` result for better clarity and maintainability.

* Change `waveFreqX` and `waveFreqY` types from `u16` to `s16` in `d_menu_cloth` structure for consistency.

* Add demo version-specific mipmap handling logic in `d_menu_cloth` initialization.

* Remove demo version-specific mipmap handling logic in `d_menu_cloth` initialization.

* Match `cloth_move_sin` and `cloth_move_simple`.

* Refactor loop variable initialization in `d_menu_cloth` for improved clarity.

* Refactor variable names in alpha calculation for improved clarity in `d_menu_cloth`.

* Inline vertex index calculations in `d_menu_cloth` to simplify code and reduce redundant variables.

* Match `plot` and `plot_shadow`.

* Refactor `lightDistance` variable in `d_menu_cloth` for improved clarity.

* Inline empty destructor for `daCLOTH_HIO_c` in `d_menu_cloth` to simplify code.

* Match `plot` and `plot_shadow` in demo build.

* Update vertex attribute formats and streamline vertex function calls in `d_cloth_packet`.

* Match `cloth_init` for JP version

* Match `init` for JP version

* Match `draw` for JP version

* Add TODO note to identify superclass for correct size in `menu_cloth_class`.

* Match `d_menu_cloth` for specific regions: GZLJ01, GZLE01, GZLP01.

* Adjust `plot_shadow` parameters in `d_menu_cloth` for consistent shadow scaling.

* Add dummy functions to ensure correct float order in `d_menu_cloth`.

* Use version-specific scale values for `MENU_CLOTH_TYPE_DEFAULT` in `d_menu_cloth`.

* Normalize hex color and value formatting in `d_menu_cloth`.

* Add `STATIC_ASSERT` checks for struct size validation in `d_menu_cloth`.

* Rename ambiguous `field` members to `padding` in `d_menu_cloth` and update struct size.

* Replace `menu_cloth_class` size calculation with `sizeof(dMCloth_c)` in `d_menu_cloth`.

* Revert "Replace `menu_cloth_class` size calculation with `sizeof(dMCloth_c)` in `d_menu_cloth`."

This reverts commit 3920b07e1a.

* Revert "Rename ambiguous `field` members to `padding` in `d_menu_cloth` and update struct size."

This reverts commit 153ee490bf.

* Rename placeholder fields to `padding_*` in `d_menu_cloth` for clarity.

* Update `menu_cloth_class` size handling with `STATIC_ASSERT` and padding.

* Clarify comment for `dMenu_ClothMethodTable` initialization.

* Replace hardcoded offsets with calculated `INNER_SIZE`-based sizes in `d_menu_cloth`.

* Remove stray comments in `setClothType` definition and invocation.

* Annotate `mStatus` with offset comment in `dDlst_MENU_CAPTURE_c`.

* Replace `g_dComIfG_gameInfo.play` calls with `dComIfGp_` equivalents in `d_menu_window`.
2026-03-11 23:54:58 -04:00

326 lines
8.0 KiB
C

#ifndef GX_H_
#define GX_H_
#include "dolphin/gx/GXAttr.h" // IWYU pragma: export
#include "dolphin/gx/GXBump.h" // IWYU pragma: export
#include "dolphin/gx/GXDisplayList.h" // IWYU pragma: export
#include "dolphin/gx/GXFifo.h" // IWYU pragma: export
#include "dolphin/gx/GXFrameBuf.h" // IWYU pragma: export
#include "dolphin/gx/GXGeometry.h" // IWYU pragma: export
#include "dolphin/gx/GXLight.h" // IWYU pragma: export
#include "dolphin/gx/GXMisc.h" // IWYU pragma: export
#include "dolphin/gx/GXPerf.h" // IWYU pragma: export
#include "dolphin/gx/GXPixel.h" // IWYU pragma: export
#include "dolphin/gx/GXTev.h" // IWYU pragma: export
#include "dolphin/gx/GXTexture.h" // IWYU pragma: export
#include "dolphin/gx/GXTransform.h" // IWYU pragma: export
#include "dolphin/gx/GXStruct.h" // IWYU pragma: export
#include "dolphin/os/OSUtil.h"
#ifdef __cplusplus
extern "C" {
#endif
// Pack value into bitfield
#define GX_BITFIELD_SET(field, pos, size, value) \
(field) = \
(field & ~(((1 << (size)) - 1) << (31 - (pos) - (size) + 1))) | \
((int)(value) << (31 - (pos) - (size) + 1))
#define GX_BITFIELD_TRUNC(field, pos, size, value) (__rlwimi((field), (value), 0, (pos), (pos) + (size)-1))
#define GX_BITGET(field, pos, size) ((field) >> (31 - (pos) - (size) + 1) & ((1 << (size)) - 1))
#define GX_GET_REG(reg, st, end) GX_BITGET(reg, st, (end - st + 1))
#define GX_SET_REG(reg, x, st, end) GX_BITFIELD_SET(reg, st, (end - st + 1), x)
#define GX_SET_TRUNC(reg, x, st, end) GX_BITFIELD_TRUNC((reg), (st), ((end) - (st) + 1), (x))
#define GXCOLOR_AS_U32(color) (*((u32*)&(color)))
#define INSERT_FIELD(reg, value, nbits, shift) \
(reg) = ((u32) (reg) & ~(((1 << (nbits)) - 1) << (shift))) | \
((u32) (value) << (shift));
#define SET_REG_FIELD(reg, size, shift, val) \
(reg) = ((u32)(reg) & ~(((1 << (size)) - 1) << (shift))) | ((u32)(val) << (shift)); \
#define GX_LOAD_BP_REG 0x61
#define GX_NOP 0
typedef union {
u8 u8;
u16 u16;
u32 u32;
u64 u64;
s8 s8;
s16 s16;
s32 s32;
s64 s64;
f32 f32;
f64 f64;
} PPCWGPipe;
#define GXFIFO_ADDR 0xCC008000
volatile PPCWGPipe GXFIFO AT_ADDRESS(GXFIFO_ADDR);
#define GX_CP_LOAD_REG(addr, data) \
GXFIFO.s8 = GX_FIFO_CMD_LOAD_CP_REG; \
GXFIFO.s8 = (addr); \
GXFIFO.s32 = (data);
/**
* Header for an XF register load
*/
#define GX_XF_LOAD_REG_HDR(addr) \
GXFIFO.s8 = GX_FIFO_CMD_LOAD_XF_REG; \
GXFIFO.s32 = (addr);
/**
* Load immediate value into XF register
*/
#define GX_XF_LOAD_REG(addr, data) \
GX_XF_LOAD_REG_HDR(addr); \
GXFIFO.s32 = (data);
/**
* Load immediate value into BP register
*/
#define GX_BP_LOAD_REG(data) \
GXFIFO.s8 = GX_FIFO_CMD_LOAD_BP_REG; \
GXFIFO.s32 = (data);
/**
* Load immediate values into multiple XF registers
*/
#define GX_XF_LOAD_REGS(size, addr) \
{ \
u32 cmd = (size) << 16 | addr; \
GX_XF_LOAD_REG_HDR(cmd); \
}
// Direct
inline void GXPosition2f32(f32 x, f32 z) {
GXFIFO.f32 = x;
GXFIFO.f32 = z;
}
inline void GXPosition3f32(f32 x, f32 y, f32 z) {
GXFIFO.f32 = x;
GXFIFO.f32 = y;
GXFIFO.f32 = z;
}
inline void GXPosition2s8(s8 x, s8 y) {
GXFIFO.s8 = x;
GXFIFO.s8 = y;
}
inline void GXPosition3s8(s8 x, s8 y, s8 z) {
GXFIFO.s8 = x;
GXFIFO.s8 = y;
GXFIFO.s8 = z;
}
inline void GXPosition2u16(u16 x, u16 y) {
GXFIFO.u16 = x;
GXFIFO.u16 = y;
}
inline void GXPosition2s16(s16 x, s16 y) {
GXFIFO.s16 = x;
GXFIFO.s16 = y;
}
inline void GXPosition3s16(s16 x, s16 y, s16 z) {
GXFIFO.s16 = x;
GXFIFO.s16 = y;
GXFIFO.s16 = z;
}
inline void GXNormal3f32(f32 x, f32 y, f32 z) {
GXFIFO.f32 = x;
GXFIFO.f32 = y;
GXFIFO.f32 = z;
}
inline void GXColor1u32(u32 c) {
GXFIFO.u32 = c;
}
inline void GXTexCoord2f32(f32 s, f32 t) {
GXFIFO.f32 = s;
GXFIFO.f32 = t;
}
inline void GXTexCoord2u8(u8 s, u8 t) {
GXFIFO.u8 = s;
GXFIFO.u8 = t;
}
inline void GXTexCoord1x8(u8 s) {
GXFIFO.u8 = s;
}
inline void GXTexCoord2s8(s8 x, s8 y) {
GXFIFO.s8 = x;
GXFIFO.s8 = y;
}
inline void GXTexCoord2u16(u16 x, u16 y) {
GXFIFO.u16 = x;
GXFIFO.u16 = y;
}
inline void GXTexCoord2s16(const s16 u, const s16 v) {
GXFIFO.s16 = u;
GXFIFO.s16 = v;
}
// Indexed
inline void GXPosition1x8(u8 x) {
GXFIFO.u8 = x;
}
inline void GXPosition1x16(u16 x) {
GXFIFO.u16 = x;
}
inline void GXNormal1x8(u8 x) {
GXFIFO.u8 = x;
}
inline void GXNormal1x16(u16 x) {
GXFIFO.u16 = x;
}
inline void GXColor1x16(u16 x) {
GXFIFO.u16 = x;
}
inline void GXColor3x8(u8 r, u8 g, u8 b) {
GXFIFO.u8 = r;
GXFIFO.u8 = g;
GXFIFO.u8 = b;
}
inline void GXColor4x8(u8 r, u8 g, u8 b, u8 a) {
GXFIFO.u8 = r;
GXFIFO.u8 = g;
GXFIFO.u8 = b;
GXFIFO.u8 = a;
}
inline void GXTexCoord1x16(u16 x) {
GXFIFO.u16 = x;
}
inline void GFWriteBPCmd(u32 x) {
GXFIFO.u8 = GX_CMD_LOAD_BP_REG;
GXFIFO.u32 = x;
}
inline void GXEnd() {}
#define GX_WRITE_U8(ub) \
GXFIFO.u8 = (u8)(ub)
#define GX_WRITE_U16(us) \
GXFIFO.u16 = (u16)(us)
#define GX_WRITE_U32(ui) \
GXFIFO.u32 = (u32)(ui)
#define GX_WRITE_F32(f) \
GXFIFO.f32 = (f32)(f);
#define GX_WRITE_XF_REG(addr, value) \
do { \
GX_WRITE_U8(0x10); \
GX_WRITE_U32(0x1000 + (addr)); \
GX_WRITE_U32(value); \
VERIF_XF_REG(addr, value); \
} while (0)
#if DEBUG
#define GX_WRITE_XF_REG_2(addr, value) \
do { \
u32 xfData = (value); &xfData; \
GX_WRITE_U32(value); \
VERIF_XF_REG_alt(addr, xfData); \
} while (0)
#define GX_WRITE_XF_REG_F(addr, value) \
do { \
f32 xfData = (value); \
GX_WRITE_F32(value); \
VERIF_XF_REG_alt(addr, *(u32 *)&xfData); \
} while (0)
#else
#define GX_WRITE_XF_REG_2(addr, value) \
do { \
GX_WRITE_U32(value); \
} while (0)
#define GX_WRITE_XF_REG_F(addr, value) \
do { \
GX_WRITE_F32(value); \
} while (0)
#endif
#define GX_WRITE_RAS_REG(value) \
do { \
GX_WRITE_U8(0x61); \
GX_WRITE_U32(value); \
VERIF_RAS_REG(value); \
} while (0)
#define GX_WRITE_SOME_REG2(a, b, c, addr) \
do { \
long regAddr; \
GX_WRITE_U8(a); \
GX_WRITE_U8(b); \
GX_WRITE_U32(c); \
regAddr = addr; \
if (regAddr >= 0 && regAddr < 4) { \
gx->indexBase[regAddr] = c; \
} \
} while (0)
#define GX_WRITE_SOME_REG3(a, b, c, addr) \
do { \
long regAddr; \
GX_WRITE_U8(a); \
GX_WRITE_U8(b); \
GX_WRITE_U32(c); \
regAddr = addr; \
if (regAddr >= 0 && regAddr < 4) { \
gx->indexStride[regAddr] = c; \
} \
} while (0)
#define GX_WRITE_SOME_REG4(a, b, c, addr) \
do { \
long regAddr; \
GX_WRITE_U8(a); \
GX_WRITE_U8(b); \
GX_WRITE_U32(c); \
regAddr = addr; \
} while (0)
static inline u32 __GXReadCPCounterU32(u32 regAddrL, u32 regAddrH) {
u32 ctrH0;
u32 ctrH1;
u32 ctrL;
ctrH0 = GX_GET_CP_REG(regAddrH);
do {
ctrH1 = ctrH0;
ctrL = GX_GET_CP_REG(regAddrL);
ctrH0 = GX_GET_CP_REG(regAddrH);
} while (ctrH0 != ctrH1);
return (ctrH0 << 0x10) | ctrL;
}
#ifdef __cplusplus
};
#endif
#endif