Skip to content

Commit

Permalink
Clean up the weak data fakematches to be slightly closer to the real …
Browse files Browse the repository at this point in the history
…code
  • Loading branch information
LagoLunatic committed Nov 20, 2024
1 parent ba31450 commit 3bdcd42
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 35 deletions.
31 changes: 22 additions & 9 deletions include/weak_data_1811.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,35 @@
#define WEAK_DATA_1811_H

// Fake header.

#include "dolphin/gx/GXEnum.h"
#include "weak_data_2100_2080.h" // IWYU pragma: keep

// @1811 is a weak object that gets included in the .data sections of several TUs.
// Its true source is this line:
// u8 attnFnTbl[] = { GX_AF_NONE, GX_AF_SPEC, GX_AF_NONE, GX_AF_SPOT };
// Which appears in the weak function J3DColorChan::getAttnFn, which is supposed to go in a header.
// But for some reason, that line causes the weak objects to appear in .rodata.
// But that line causes the weak object to appear in .rodata, while this weak object need to be in .data.
// So for now, that function is moved to the .cpp file, and TUs that need this object should include this header.

#include "weak_data_2100_2080.h" // IWYU pragma: keep
static inline void fake_getAttnFn() {
// Value is equivalent to: {0x02, 0x00, 0x02, 0x01}
static u8 attnFnTbl_1811[] = { GX_AF_NONE, GX_AF_SPEC, GX_AF_NONE, GX_AF_SPOT };
}

// These two weak objects are strange, as they have no symbols associated with them.
// They always seems to come after @1811 ends at offset 0x1C, getting padded to start at 0x20 and ending at 0x30.
// These are likely the 3.0 and .5 double literals from std::sqrtf.
// But those literals get placed in .rodata, while these weak objects need to be in .data.
// Also, the order of these two literals is reversed. std::sqrtf has _half before _three.
// static f64 data_no_symbol_3_5[2] = {3.0, 0.5};

static u8 data_1811[] = {0x02, 0x00, 0x02, 0x01};
extern inline void fake_sqrtf(float x) {
static double _three[1] = {3.0};
static double _half[1] = {.5};
}

// This object is strange, as it has no symbol associated with it.
// It always seems to come after @1811 ends at offset 0x1C, getting padded to start at 0x20 and ending at 0x30.
// It being an array of two doubles is guessed based on how it looks and its apparently 0x8 byte alignment.
// Its actual purpose is unknown since it's never used.
// Could this be somehow related to the two double constants in std::sqrtf?
static f64 data_no_symbol_3_5[2] = {3.0, 0.5};
// Note: These weak objects get stripped out for main.dol, because all three of them are within the
// 8-byte limit for .sdata. They do not get stripped out in RELs.

#endif /* WEAK_DATA_1811_H */
20 changes: 15 additions & 5 deletions include/weak_data_2100_2080.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
#define WEAK_DATA_2100_2080_H

// Fake header.
// These are weak objects that get included in the .data sections of several TUs.

#include "dolphin/mtx/vec.h"

// @2100 and @2080 are weak objects that get included in the .data sections of several TUs.
// Their true source is likely this line of code that appears twice in J3DJoint.h:
// J3DSys::mParentS = (Vec){1.0f, 1.0f, 1.0f};
// But for some reason, that line causes the weak objects to appear in .rodata.
// But that line causes the weak objects to appear in .rodata, while this weak object need to be in .data.
// So for now, the line is commented out, and TUs that need these objects should include this header.
// Note: For d_snap and J3DUClipper, these objects *are* supposed to appear in .rodata, but those are the only ones.
// Also, d_snap and J3DUClipper seem to be the only ones where the two symbols are in order by the compiler-generated
// names. In TUs where they appear in .data instead, their order is reversed (@2100 coming before @2080).

#include "dolphin/mtx/vec.h"
static inline void fake_data_2100() {
// Value is equivalent to: {0x3F800000, 0x3F800000, 0x3F800000}
static Vec data_2100 = {1.0f, 1.0f, 1.0f};
}

static Vec data_2100 = {1.0f, 1.0f, 1.0f};
static Vec data_2080 = {1.0f, 1.0f, 1.0f};
static inline void fake_data_2080() {
// Value is equivalent to: {0x3F800000, 0x3F800000, 0x3F800000}
static Vec data_2080 = {1.0f, 1.0f, 1.0f};
}

#endif /* WEAK_DATA_2100_2080_H */
2 changes: 1 addition & 1 deletion src/d/actor/d_a_agb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "stdio.h"

#include "weak_bss_3569.h" // IWYU pragma: keep
#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

static mDoDvdThd_toMainRam_c* l_gbaCommand;

Expand Down
2 changes: 1 addition & 1 deletion src/d/actor/d_a_arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ u32 daPy_py_c::checkPlayerFly() const { return 0; }
#include "d/d_s_play.h"
#include "d/res/res_link.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

s16 daArrow_c::m_count;

Expand Down
2 changes: 1 addition & 1 deletion src/d/actor/d_a_bomb2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "f_op/f_op_kankyo_mng.h"
#include "m_Do/m_Do_mtx.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

namespace daBomb2 {
namespace {
Expand Down
2 changes: 1 addition & 1 deletion src/d/actor/d_a_bomb3.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "m_Do/m_Do_lib.h"
#include "d/res/res_vbakh.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

namespace {
enum AttrSt_e {
Expand Down
2 changes: 1 addition & 1 deletion src/d/actor/d_a_dai_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "f_op/f_op_actor.h"
#include "weak_bss_3569.h" // IWYU pragma: keep
#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

const char daStandItem_c::m_arcname[] = "Fdai";
const s16 daStandItem_c::m_bmdidx[] = {
Expand Down
2 changes: 1 addition & 1 deletion src/d/actor/d_a_hookshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "d/actor/d_a_player_main.h"
#include "d/d_procname.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

#include "assets/l_chainS3TCTEX__d_hookshot.h"
const u16 l_chainS3TCTEX__width = 32;
Expand Down
2 changes: 1 addition & 1 deletion src/d/actor/d_a_ib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "global.h"
#include "m_Do/m_Do_mtx.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

struct daIball_c__data {
/* 0x00 */ u8 m00;
Expand Down
2 changes: 1 addition & 1 deletion src/d/actor/d_a_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "m_Do/m_Do_mtx.h"
#include "m_Do/m_Do_controller_pad.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

s32 daItem_c::m_timer_max = 10000;

Expand Down
2 changes: 1 addition & 1 deletion src/d/actor/d_a_player_main_data.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "d/actor/d_a_player_main.h"
#include "d/actor/d_a_player_main_data.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

char l_arcName[] = "Link";

Expand Down
2 changes: 1 addition & 1 deletion src/d/d_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "d/d_s_play.h"
#include "m_Do/m_Do_mtx.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

#include "assets/l_chainS3TCTEX__d_chain.h"
const u16 l_chainS3TCTEX__width = 32;
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_drawlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ShdwDrawPoly_c : public cBgS_ShdwDraw {

GXTexObj dDlst_shadowControl_c::mSimpleTexObj;

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

/* 800804A4-800804C0 .text setViewPort__14dDlst_window_cFffffff */
void dDlst_window_c::setViewPort(f32 x, f32 y, f32 w, f32 h, f32 n, f32 f) {
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_grass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "dolphin/gf/GFGeometry.h"
#include "dolphin/gf/GFTev.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

#include "assets/l_K_kusa_00TEX.h"
const u32 l_K_kusa_00TEX__width = 64;
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_item_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
#include "d/res/res_vtin5.h"
#include "d/res/res_vbeso.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

/* 80383F20-803840E0 .data item_arcname_tbl__10dItem_data */
char* dItem_data::item_arcname_tbl[0x70] = {
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_kankyo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "m_Do/m_Do_printf.h"
#include "math.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

class sub_kankyo__class : public kankyo_class {
};
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_magma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// #pragma sym on

#include "weak_bss_3569.h" // IWYU pragma: keep
#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

Mtx l_kuroOrthoMtx;
Mtx l_colOrthoMtx;
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "m_Do/m_Do_mtx.h"
#include "d/d_item_data.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

/* 8021A7B4-8021A858 .text angCalcS__14dNpc_JntCtrl_cFPssss */
bool dNpc_JntCtrl_c::angCalcS(s16* out, s16 targetY, s16 speed, s16 maxVel) {
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "stdio.h"

#include "weak_bss_3569.h" // IWYU pragma: keep
#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

/* 8007A4D8-8007A514 .text __ct__18dPa_modelEmitter_cFv */
dPa_modelEmitter_c::dPa_modelEmitter_c() {
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_s_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "JSystem/J2DGraph/J2DScreen.h"
#include "JSystem/JKernel/JKRExpHeap.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

dSn_HIO_c g_snHIO;

Expand Down
2 changes: 1 addition & 1 deletion src/d/d_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "d/d_tree.h"
#include "dolphin/types.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

#include "assets/l_Txa_swood_aTEX.h"
const u16 l_Txa_swood_aTEX__width = 64;
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_wood.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "m_Do/m_Do_lib.h"
#include "m_Do/m_Do_mtx.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

//-----------------------------------------
// Types
Expand Down
2 changes: 1 addition & 1 deletion src/m_Do/m_Do_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "m_Do/m_Do_machine.h"
#include "m_Do/m_Do_printf.h"

#include "weak_data_2100_2080.h" // IWYU pragma: keep
#include "weak_data_1811.h" // IWYU pragma: keep

class JUTGamePad;

Expand Down

0 comments on commit 3bdcd42

Please sign in to comment.