Skip to content

Commit

Permalink
Changes from decomp
Browse files Browse the repository at this point in the history
  • Loading branch information
SeekyCt committed Jan 3, 2025
1 parent b4704aa commit 0fea52b
Show file tree
Hide file tree
Showing 30 changed files with 1,049 additions and 53 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ It is recommended to use this with [git subrepo](https://github.com/ingydotnet/g

## Decomp

For use in decomp, the `include` and `decomp` folders should be added to the include path, and the preprocessor define `DECOMP` should be used.
For use in decomp, the `include`, `include_cpp` and `decomp` folders should be added to the include path, and the preprocessor define `DECOMP` should be used.

### Testing
## Mods

The `SKIP_PPCDIS` preprocessor define will stop `ppcdis.h` being included.
For use in mods, the `include`, `include_cpp` and `mod` folder should be added to the include path and an lst from `linker` should be used. If including your compiler's C++ standard library, the preprocessor define `USE_STL` should be used.

## Mods
## C

For use in mods, the `include` and `mod` folder should be added to the include path and an lst from `linker` should be used. If including your compiler's C++ standard library, the preprocessor define `USE_STL` should be used.
For the cases where C is required (such as m2c or maybe some niche modding cases), omitting the `include_cpp` folder should be all that's neccessary.

# Licensing

All code originally written for this project (everything under the `include`, `decomp` and `linker` directories) is available under the MIT license.
All code originally written for this project (everything under the `include`, `include_cpp`, `decomp` and `linker` directories) is available under the MIT license.

Everything under the `mod` folder is available under the GPLv3 license as it's derived from other GPL code.

Expand Down
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_old_mod_ctx(regions: List[str]):
def test_decomp_ctx(regions: List[str]):
assert args.codewarrior, "Error: decomp_ctx test requires --codewarrior"
compile_regions(os.path.join("$builddir", "{region}", "decomp.o"), "$decomp_source", regions,
DECOMP_INCLUDES, ["DECOMP", "SKIP_PPCDIS"], True)
DECOMP_INCLUDES, ["DECOMP"], True)

# Test shuffled include orders
def test_mod_ctx_shuffle(regions: List[str]):
Expand Down
14 changes: 8 additions & 6 deletions include/common.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#pragma once

#if (defined DECOMP) && !(defined SKIP_PPCDIS)
// Decomp should include ppcdis.h in all files
#include <ppcdis.h>
#else
// Unknown function is useful outside of decomp too
// Unknown function declaration
#define UNKNOWN_FUNCTION(name) void name(void)
#endif

// Intellisense doesn't like asm compiler extensions
#ifdef __INTELLISENSE__
Expand Down Expand Up @@ -110,6 +105,13 @@ typedef u8 unk8;
#define DECOMP_STATIC(expr) extern expr;
#endif

// Macro for something that is deadstripped outside of decomp
#ifdef DECOMP
#define STRIPPED(expr) expr;
#else
#define STRIPPED(expr)
#endif

// Use extern "C" in C++, use namespacing in mods
#ifdef __cplusplus
#ifndef DECOMP
Expand Down
3 changes: 2 additions & 1 deletion include/spm/camdrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

CPP_WRAPPER(spm::camdrv)

USING(wii::gx::GXProjectionType)
USING(wii::mtx::Vec3)
USING(wii::mtx::Mtx34)
USING(wii::mtx::Mtx44)
Expand Down Expand Up @@ -63,7 +64,7 @@ typedef struct _CamEntry
/* 0x0F8 */ f32 left;
/* 0x0FC */ f32 right;
/* 0x100 */ u8 unknown_0x100[0x158 - 0x100];
/* 0x158 */ s32 isOrtho;
/* 0x158 */ GXProjectionType projectionType;
/* 0x15C */ Vec3 pos;
/* 0x168 */ Vec3 target;
/* 0x174 */ Vec3 up;
Expand Down
2 changes: 1 addition & 1 deletion include/spm/evtmgr_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ f32 evtSetFloat(EvtEntry * entry, EvtVar variable, f32 value);
Returns a pointer to the instruction after the specified label
in an entry's script
*/
EvtScriptCode * evtSearchLabel(EvtEntry * entry, s32 id); // inlined
STRIPPED(EvtScriptCode * evtSearchLabel(EvtEntry * entry, s32 id))

/*
Returns a pointer to the instruction after the next else on the
Expand Down
5 changes: 4 additions & 1 deletion include/spm/fadedrv.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once

#include <common.h>
#include <wii/gx.h>

CPP_WRAPPER(spm::fadedrv)

USING(wii::gx::GXColor)

void fadeInit();
UNKNOWN_FUNCTION(fadeEntry);
void fadeEntry(u32 transitionType, s32 param_2, GXColor colour);
UNKNOWN_FUNCTION(func_80066558);
void fadeMain();
UNKNOWN_FUNCTION(func_80066e4c);
Expand Down
2 changes: 1 addition & 1 deletion include/spm/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ UNKNOWN_FUNCTION(hudDisp);
void func_8019af88();
void hudTurnOffFlipTimeBox(s32 idx);
UNKNOWN_FUNCTION(func_8019b0dc);
UNKNOWN_FUNCTION(func_8019be84);
void func_8019be84();
UNKNOWN_FUNCTION(func_8019bea8);

CPP_WRAPPER_END()
8 changes: 4 additions & 4 deletions include/spm/mario_pouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ DECOMP_STATIC(MarioPouchWork mario_pouch_work2)
Returns a pointer to the MarioPouchWork / MarioPouchWork2 instance
*/
MarioPouchWork * pouchGetPtr();
MarioPouchWork2 * pouch2GetPtr(); // inlined
STRIPPED(MarioPouchWork2 * pouch2GetPtr())

/*
Initialise data used by pouch functions
Overwritten later once a save is loaded
*/
void pouchInit();
void pouch2Init(); // inlined
STRIPPED(void pouch2Init())
void pouchReInit();

/*
Expand Down Expand Up @@ -169,7 +169,7 @@ s32 pouchGetMaxHp();
/*
Get/add to the player's xp
*/
void pouchSetXp(s32 xp); // inlined
STRIPPED(void pouchSetXp(s32 xp))
s32 pouchGetXp();
void pouchAddXp(s32 increase);

Expand All @@ -178,7 +178,7 @@ void pouchAddXp(s32 increase);
*/
void pouchSetCoin(s32 coins);
s32 pouchGetCoin();
void pouchAddTotalCoin(s32 increase); // inlined
STRIPPED(void pouchAddTotalCoin(s32 increase))
void pouchAddCoin(s32 increase); // increases totalCoinsCollected

/*
Expand Down
61 changes: 57 additions & 4 deletions include/spm/seq_title.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,72 @@

#include <common.h>
#include <spm/seqdrv.h>
#include <wii/mem.h>

#ifdef __cplusplus
#include <nw4r/lyt/arcResourceAccessor.h>
#include <nw4r/lyt/animation.h>
#include <nw4r/lyt/drawInfo.h>
#include <nw4r/lyt/layout.h>
#endif

CPP_WRAPPER(spm::seq_title)

USING(spm::seqdrv::SeqWork)
USING(wii::mem::MEMAllocator)

/*
seqWork stage values
*/

// Wait for button press, or to timeout and replay intro
#define SEQ_TITLE_WAIT_INPUT -1

// Button pressed, start file select transition
#define SEQ_TITLE_FILE_SELECT_PRESS 0

// Wait for file select transition
#define SEQ_TITLE_FILE_SELECT_FADE 1

// Timeout, replay intro
#define SEQ_TITLE_REPLAY_TIMEOUT 2

// Wait for intro replay transition
#define SEQ_TITLE_REPLAY_FADE 3

typedef struct
{
/* 0x00 */ s32 openingReplayTimer;
/* 0x04 */ u32 unknown_0x4; // unused?
/* 0x08 */ void * arc;
/* 0x0C */ void * heap;
/* 0x10 */ u32 heapSize;
/* 0x14 */ void * heapHandle;
/* 0x18 */ MEMAllocator allocator;
#ifdef __cplusplus
/* 0x28 */ nw4r::lyt::ArcResourceAccessor * arcResAccessor;
/* 0x2C */ nw4r::lyt::Layout * layout;
/* 0x30 */ nw4r::lyt::Pane * pushu2Pane;
/* 0x30 */ nw4r::lyt::Pane * pushuBotanPane;
/* 0x38 */ nw4r::lyt::AnimTransform * animations[2]; // 0 start, 1 loop
/* 0x40 */ nw4r::lyt::DrawInfo drawInfo;
#else
/* 0x28 */ u8 cpp_pad[0x94 - 0x28];
#endif
/* 0x94 */ s32 animNum;
/* 0x98 */ f32 animFrame;
} SeqTitleWork;
SIZE_ASSERT(SeqTitleWork, 0x9c)

void seq_titleInit(SeqWork * work);
void seq_titleMain(SeqWork * work);
void seq_titleExit(SeqWork * work);
UNKNOWN_FUNCTION(func_8017b49c);
UNKNOWN_FUNCTION(seqTitleInitLayout);
UNKNOWN_FUNCTION(func_8017b8ac);
void seqTitleDispCb(s32 cameraId, void * param);
void seqTitleInitLayout();
STRIPPED(void seqTitleDeleteLayout())
void seqTitleDisp();

// No idea why this is in this file of all places, but it is
const char * getNextDanMapname(s32 dungeonNo);
const char * getDanMapName(s32 dungeonNo);

CPP_WRAPPER_END()
14 changes: 7 additions & 7 deletions include/spm/spmario_snd.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ UNKNOWN_FUNCTION(spsndPause);
UNKNOWN_FUNCTION(spsndUnpause);
UNKNOWN_FUNCTION(func_8023872c);
UNKNOWN_FUNCTION(spsndSetPosDirListener);
UNKNOWN_FUNCTION(spsndSetSFXReverbMode);
void spsndSetSFXReverbMode(u8 mode);
UNKNOWN_FUNCTION(func_80238804);
UNKNOWN_FUNCTION(func_80238868);
UNKNOWN_FUNCTION(spsndSetFlag);
UNKNOWN_FUNCTION(spsndClearFlag);
void spsndClearFlag(u16 flags);
UNKNOWN_FUNCTION(spsndGetFlag);
UNKNOWN_FUNCTION(func_802388f4);
UNKNOWN_FUNCTION(func_80238b04);
Expand All @@ -29,7 +29,7 @@ UNKNOWN_FUNCTION(spsndSFXOn_UnkEffect);
UNKNOWN_FUNCTION(_spsndSFXOn);
UNKNOWN_FUNCTION(spsndSFXOn_3D);
UNKNOWN_FUNCTION(spsndSFXOff);
UNKNOWN_FUNCTION(func_8023b38c);
void func_8023b38c(u32 param_1, u32 param_2);
UNKNOWN_FUNCTION(spsndSetSfxPlayerPos);
UNKNOWN_FUNCTION(spsndSFX_vol);
UNKNOWN_FUNCTION(spsndSFX_pit);
Expand All @@ -50,13 +50,13 @@ bool spsndBGMOn(u32 flags, const char * name);
UNKNOWN_FUNCTION(spsndBGMOn_f_d_alt);
bool spsndBGMOff_f_d(s32 player, u32 fadeoutTime);
UNKNOWN_FUNCTION(spsndBGMOff);
UNKNOWN_FUNCTION(spsndBGMOff_f_d_alt);
bool spsndBGMOff_f_d_alt(s32 player, s32 fadeoutTime);
UNKNOWN_FUNCTION(func_8023cab4);
UNKNOWN_FUNCTION(func_8023cc90);
UNKNOWN_FUNCTION(func_8023cc98);
UNKNOWN_FUNCTION(func_8023cc9c);
UNKNOWN_FUNCTION(func_8023ce1c);
UNKNOWN_FUNCTION(func_8023ce20);
void func_8023ce20(s32 player, s32 param_2, s32 param_3);
UNKNOWN_FUNCTION(func_8023cf14);
UNKNOWN_FUNCTION(func_8023cfe8);
UNKNOWN_FUNCTION(func_8023d0dc);
Expand All @@ -68,9 +68,9 @@ UNKNOWN_FUNCTION(func_8023d2b8);
UNKNOWN_FUNCTION(spsndENVMain);
UNKNOWN_FUNCTION(spsndENVOn_f_d);
UNKNOWN_FUNCTION(spsndENVOn);
UNKNOWN_FUNCTION(func_8023db5c);
bool func_8023db5c(s32 param_1, s32 param_2);
UNKNOWN_FUNCTION(func_8023dc88);
UNKNOWN_FUNCTION(func_8023dc90);
bool func_8023dc90(s32 param_1, s32 param_2);
UNKNOWN_FUNCTION(func_8023dc94);
UNKNOWN_FUNCTION(func_8023dda4);
UNKNOWN_FUNCTION(func_8023de90);
Expand Down
6 changes: 2 additions & 4 deletions include/spm/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ s32 NORETURN ATTRIBUTE_FORMAT(printf, 4, 5) __assert2(

/*
Rounds a float to an int
Deadstripped, always inlined
*/
s32 roundi(f32 x);
STRIPPED(s32 roundi(f32 x))

/*
Adjusts an angle to be 0 <= x < 360
Expand Down Expand Up @@ -144,9 +143,8 @@ void sysRandInit();

/*
Gets the current screen draw token
Deadstripped, always inlined
*/
u16 sysGetToken();
STRIPPED(u16 sysGetToken())

/*
Waits until the next screen draw, or max 100ms
Expand Down
16 changes: 15 additions & 1 deletion include/wii/gx.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ typedef struct
{
u8 r, g, b, a;
} GXColor;
SIZE_ASSERT(GXColor, 0x4)

typedef struct
{
s16 r, g, b, a;
} GXColorS10;
SIZE_ASSERT(GXColorS10, 0x8)

typedef struct
{
Expand All @@ -29,6 +36,13 @@ typedef struct
} GXTexObj;
SIZE_ASSERT(GXTexObj, 0x20)


typedef enum
{
/* 0x0 */ GX_PERSPECTIVE,
/* 0x1 */ GX_ORTHOGRAPHIC
} GXProjectionType;

// Parameters from libogc's gx.h

UNKNOWN_FUNCTION(__GXDefaultTexRegionCallback);
Expand Down Expand Up @@ -200,7 +214,7 @@ UNKNOWN_FUNCTION(GXEndDisplayList);
UNKNOWN_FUNCTION(GXCallDisplayList);
UNKNOWN_FUNCTION(GXProject);
UNKNOWN_FUNCTION(__GXSetProjection);
void GXSetProjection(Mtx44 * mtx, u32 type);
void GXSetProjection(Mtx44 mtx, GXProjectionType type);
UNKNOWN_FUNCTION(GXSetProjectionv);
UNKNOWN_FUNCTION(GXGetProjectionv);
void GXLoadPosMtxImm(Mtx34 * mtx, u32 pnidx);
Expand Down
20 changes: 18 additions & 2 deletions include/wii/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ typedef struct _MEMEXPHeap
} MEMEXPHeap;
SIZE_ASSERT(MEMEXPHeap, 0x50)

typedef struct
{
/* 0x0 */ void * alloc;
/* 0x4 */ void * free;
} MEMAllocatorFunc;
SIZE_ASSERT(MEMAllocatorFunc, 8)

typedef struct
{
/* 0x0 */ MEMAllocatorFunc * func;
/* 0x4 */ void * heap;
/* 0x8 */ u32 heapP0;
/* 0x8 */ u32 heapP1;
} MEMAllocator;
SIZE_ASSERT(MEMAllocator, 0x10)

#define MEM_FLAG_FILL_0 (1 << 0) // initialise allocated memory as 0
#define MEM_FLAG_THREAD_CONTROL (1 << 2) // use mutexes for access when handling heap

Expand Down Expand Up @@ -63,9 +79,9 @@ UNKNOWN_FUNCTION(AllocatorAllocForExpHeap_);
UNKNOWN_FUNCTION(AllocatorFreeForExpHeap_);
UNKNOWN_FUNCTION(AllocatorAllocForFrmHeap_);
UNKNOWN_FUNCTION(AllocatorFreeForFrmHeap_);
UNKNOWN_FUNCTION(MEMAllocFromAllocator);
void * MEMAllocFromAllocator(MEMAllocator * allocator, size_t size);
UNKNOWN_FUNCTION(MEMFreeToAllocator);
UNKNOWN_FUNCTION(MEMInitAllocatorForExpHeap);
void MEMInitAllocatorForExpHeap(MEMAllocator * allocator, MEMHeapHandle heap, u32 alignment);
UNKNOWN_FUNCTION(MEMInitAllocatorForFrmHeap);
UNKNOWN_FUNCTION(MEMInitList);
UNKNOWN_FUNCTION(MEMAppendListObject);
Expand Down
Loading

0 comments on commit 0fea52b

Please sign in to comment.