Skip to content

Commit

Permalink
Various matches
Browse files Browse the repository at this point in the history
  • Loading branch information
hatal175 committed Nov 10, 2023
1 parent 46d2283 commit 2d79f2e
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 458 deletions.
2 changes: 2 additions & 0 deletions include/JSystem/JAudio2/JASCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct JASCalc {
/* 8028F454 */ static void bzerofast(void*, u32);
/* 8028F480 */ static void bzero(void*, u32);
/* 8028F578 */ static f32 pow2(f32);

// Could not make it work as inline - specialization is in JASCalc.cpp
template <typename A, typename B>
static A clamp(B x); /* {
if (std::numeric_limits<A>::min() >= x)
Expand Down
3 changes: 2 additions & 1 deletion include/Z2AudioLib/Z2Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class Z2CreatureLink : public Z2Creature, public Z2LinkSoundStarter {
void setInWater(bool status) { mInWater = status; }
bool isInWater() { return mInWater; }
u8 getLinkState() const { return mLinkState; }
u8 getMoveSpeed() const { return mMoveSpeed; }
bool isRiding() const { return mRiding; }

static Z2CreatureLink* mLinkPtr;

Expand Down Expand Up @@ -159,7 +161,6 @@ class Z2CreatureEnemy : public Z2Creature {
/* 802C1B7C */ void setLinkSearch(bool);
/* 802C1B90 */ void setEnemyName(char const*);

private:
/* 0x90 */ JSULink<Z2CreatureEnemy> mLink;
/* 0xA0 */ u8 mEnemyID;
/* 0xA1 */ s8 field_0xa1;
Expand Down
16 changes: 16 additions & 0 deletions include/Z2AudioLib/Z2SeqMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ class Z2SeqMgr : public JASGlobalInstance<Z2SeqMgr> {
return field_0x08.isSoundAttached() || field_0xba != 0;
}

u32 getMainBgmID() {
if (mMainBgmHandle) {
return mMainBgmHandle->getID();
}

return -1;
}

u32 getSubBgmID() {
if (mSubBgmHandle) {
return mSubBgmHandle->getID();
}

return -1;
}

private:
/* 0x00 */ JAISoundHandle mMainBgmHandle;
/* 0x04 */ JAISoundHandle mSubBgmHandle;
Expand Down
30 changes: 19 additions & 11 deletions include/Z2AudioLib/Z2SoundObjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,42 @@

class Z2CreatureEnemy;

class Z2SoundObjMgr : protected JSUList<Z2CreatureEnemy>, public JASGlobalInstance<Z2SoundObjMgr> {
struct Z2EnemyArea {
/* 0x00 */ u8 field_0x0;
/* 0x02 */ u16 field_0x2;
/* 0x04 */ u16 field_0x4;
/* 0x06 */ u16 field_0x6;
};

enum Z2EnemyID {
Z2_ENEMY_ID_0,
};

class Z2SoundObjMgr : public JASGlobalInstance<Z2SoundObjMgr>, protected JSUList<Z2CreatureEnemy> {
public:
Z2SoundObjMgr();
void setForceBattleArea(bool, u16, u16, u16);
void searchEnemy();
void setGhostEnemyState(u8);
void getEnemyID(char const*, JSULink<Z2CreatureEnemy>*);
u8 getEnemyID(char const*, JSULink<Z2CreatureEnemy>*);
void setBattleInit();
void checkBattleFinish();
bool checkBattleFinish();
void deleteEnemyAll();
void removeEnemy(JSULink<Z2CreatureEnemy>*);
bool isTwilightBattle();
bool removeEnemy(JSULink<Z2CreatureEnemy>*);
u8 isTwilightBattle();

bool isForceBattle() { return mForceBattle; }

private:
/* 0x0C */ u8 field_0xc[2];
/* 0x0E */ u16 field_0xe;
/* 0x10 */ u16 field_0x10;
/* 0x12 */ u16 field_0x12;
/* 0x0C */ Z2EnemyArea mEnemyArea;
/* 0x14 */ u8 field_0x14;
/* 0x15 */ u8 mEnemyNumNear;
/* 0x16 */ u8 field_0x16;
/* 0x17 */ u8 mEnemyNumVeryFar;
/* 0x18 */ u8 field_0x18;
/* 0x19 */ u8 mGhostEnemyState;
/* 0x1A */ bool field_0x1a;
/* 0x1B */ bool mTwilightBattle;
/* 0x1A */ u8 field_0x1a;
/* 0x1B */ u8 mTwilightBattle;
/* 0x1C */ bool mForceBattle;
}; // Size = 0x20

Expand Down
7 changes: 1 addition & 6 deletions libs/JSystem/J3DGraphAnimator/J3DJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ void J3DJoint::appendChild(J3DJoint* pChild) {
SECTION_DEAD static u32 const pad_803A2080[2] = {0,0};
#pragma pop

struct copyhelper {
u32 x[8];
};

/* 8032F170-8032F254 329AB0 00E4+00 0/0 1/1 0/0 .text __ct__8J3DJointFv */
J3DJoint::J3DJoint() {
mCallBackUserData = NULL;
Expand All @@ -198,8 +194,7 @@ J3DJoint::J3DJoint() {
mJntNo = 0;
mKind = 1;
mScaleCompensate = false;
// This line is probably a fake match but the normal = works nothing like this.
*(copyhelper*)&mTransformInfo = *(copyhelper*)&j3dDefaultTransformInfo;
__memcpy(&mTransformInfo, &j3dDefaultTransformInfo, sizeof(J3DTransformInfo));
mBoundingSphereRadius = 0.0f;
mMtxCalc = NULL;
mMesh = NULL;
Expand Down
123 changes: 26 additions & 97 deletions libs/JSystem/JAudio2/JASAiCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,6 @@ asm void JASDriver::readDspBuffer(s16* param_0, u32 param_1) {
#pragma pop
#endif

/* ############################################################################################## */
/* 8039B2F0-8039B2F0 027950 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */
#pragma push
#pragma force_active on
SECTION_DEAD static char const* const stringBase_8039B30C = "DSP-MAIN";
#pragma pop

/* 8029C900-8029C9DC 297240 00DC+00 1/1 1/1 0/0 .text finishDSPFrame__9JASDriverFv */
void JASDriver::finishDSPFrame() {
int r30 = sDspDacWriteBuffer + 1;
Expand Down Expand Up @@ -439,141 +432,77 @@ u32 JASDriver::getFrameSamples() {
return sSubFrames * 0x50;
}

/* ############################################################################################## */
/* 8039B2F0-8039B2F0 027950 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */
#pragma push
#pragma force_active on
SECTION_DEAD static char const* const stringBase_8039B315 = "MONO-MIX";
#pragma pop

/* 8029CA10-8029CAC0 297350 00B0+00 1/0 0/0 0/0 .text mixMonoTrack__9JASDriverFPsUlPFl_Ps
*/
// regalloc
#ifdef NONMATCHING
void JASDriver::mixMonoTrack(s16* param_0, u32 param_1, MixCallback param_2) {
void JASDriver::mixMonoTrack(s16* buffer, u32 param_1, MixCallback param_2) {
JASProbe::start(5, "MONO-MIX");
s16* r31 = param_2(param_1);
s16* pTrack = buffer;
if (r31 == NULL) {
return;
}
JASProbe::stop(5);
for (u32 i = param_1; i != 0; i--) {
param_0[0] = JASCalc::clamp<s16, s32>(param_0[0] + r31[0]);
param_0[1] = JASCalc::clamp<s16, s32>(param_0[1] + r31[0]);
param_0 += 2;
pTrack[0] = JASCalc::clamp<s16, s32>(pTrack[0] + r31[0]);
pTrack[1] = JASCalc::clamp<s16, s32>(pTrack[1] + r31[0]);
pTrack += 2;
r31++;
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void JASDriver::mixMonoTrack(s16* param_0, u32 param_1, MixCallback param_2) {
nofralloc
#include "asm/JSystem/JAudio2/JASAiCtrl/mixMonoTrack__9JASDriverFPsUlPFl_Ps.s"
}
#pragma pop
#endif

/* ############################################################################################## */
/* 8039B2F0-8039B2F0 027950 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */
#pragma push
#pragma force_active on
SECTION_DEAD static char const* const stringBase_8039B31E = "MONO(W)-MIX";
#pragma pop

/* 8029CAC0-8029CB70 297400 00B0+00 1/0 0/0 0/0 .text mixMonoTrackWide__9JASDriverFPsUlPFl_Ps */
// instruction order
#ifdef NONMATCHING
void JASDriver::mixMonoTrackWide(s16* param_0, u32 param_1, MixCallback param_2) {
void JASDriver::mixMonoTrackWide(s16* buffer, u32 param_1, MixCallback param_2) {
JASProbe::start(5, "MONO(W)-MIX");
s16* r31 = param_2(param_1);
s16* pTrack = buffer;
if (!r31) {
return;
}
JASProbe::stop(5);
for (u32 i = param_1; i != 0; i--) {
param_0[0] = JASCalc::clamp<s16, s32>(param_0[0] + r31[0]);
param_0[1] = JASCalc::clamp<s16, s32>(param_0[1] - r31[0]);
param_0 += 2;
pTrack[0] = JASCalc::clamp<s16, s32>(pTrack[0] + r31[0]);
s32 src = pTrack[1];
src -= r31[0];
pTrack[1] = JASCalc::clamp<s16, s32>(src);
pTrack += 2;
r31++;
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void JASDriver::mixMonoTrackWide(s16* param_0, u32 param_1, MixCallback param_2) {
nofralloc
#include "asm/JSystem/JAudio2/JASAiCtrl/mixMonoTrackWide__9JASDriverFPsUlPFl_Ps.s"
}
#pragma pop
#endif

/* ############################################################################################## */
/* 8039B2F0-8039B2F0 027950 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */
#pragma push
#pragma force_active on
SECTION_DEAD static char const* const stringBase_8039B32A = "DSPMIX";
SECTION_DEAD static char const* const stringBase_8039B331 = "MIXING";
#pragma pop

/* 8029CB70-8029CC50 2974B0 00E0+00 1/0 0/0 0/0 .text mixExtraTrack__9JASDriverFPsUlPFl_Ps */
// missing instruction
#ifdef NONMATCHING
void JASDriver::mixExtraTrack(s16* param_0, u32 param_1, MixCallback param_2) {
void JASDriver::mixExtraTrack(s16* buffer, u32 param_1, MixCallback param_2) {
JASProbe::start(5, "DSPMIX");
s16* r31 = param_2(param_1);
if (!r31) {
return;
}
JASProbe::stop(5);
JASProbe::start(6, "MIXING");
s16* pTrack = buffer;
s16* r29 = r31 + getFrameSamples();
for (u32 i = param_1; i != 0; i--) {
param_0[0] = JASCalc::clamp<s16, s32>(param_0[0] + r29[0]);
param_0[1] = JASCalc::clamp<s16, s32>(param_0[1] + r31[0]);
param_0 += 2;
pTrack[0] = JASCalc::clamp<s16, s32>(pTrack[0] + r29[0]);
pTrack[1] = JASCalc::clamp<s16, s32>(pTrack[1] + r31[0]);
pTrack += 2;
r29++;
r31++;
}
JASProbe::stop(6);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void JASDriver::mixExtraTrack(s16* param_0, u32 param_1, MixCallback param_2) {
nofralloc
#include "asm/JSystem/JAudio2/JASAiCtrl/mixExtraTrack__9JASDriverFPsUlPFl_Ps.s"
}
#pragma pop
#endif

/* 8029CC50-8029CCD4 297590 0084+00 1/0 0/0 0/0 .text mixInterleaveTrack__9JASDriverFPsUlPFl_Ps */
// missing instructions
#ifdef NONMATCHING
void JASDriver::mixInterleaveTrack(s16* param_0, u32 param_1, MixCallback param_2) {
void JASDriver::mixInterleaveTrack(s16* buffer, u32 param_1, MixCallback param_2) {
s16* r31 = param_2(param_1);
if (!r31) {
return;
}
for (u32 i = param_1 * 2; i != 0; i--) {
param_0[0] = JASCalc::clamp<s16, s32>(param_0[0] + r31[0]);
param_0 += 1;
r31++;
if (r31) {
s16* pTrack = buffer;
s16* r30 = r31;
for (u32 i = param_1 * 2; i != 0; i--) {
pTrack[0] = JASCalc::clamp<s16, s32>(pTrack[0] + r30[0]);
pTrack += 1;
r30++;
}
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void JASDriver::mixInterleaveTrack(s16* param_0, u32 param_1, MixCallback param_2) {
nofralloc
#include "asm/JSystem/JAudio2/JASAiCtrl/mixInterleaveTrack__9JASDriverFPsUlPFl_Ps.s"
}
#pragma pop
#endif

/* 8029CCD4-8029CCDC -00001 0008+00 0/0 0/0 0/0 .text getSubFrameCounter__9JASDriverFv */
u32 JASDriver::getSubFrameCounter() {
Expand Down
19 changes: 9 additions & 10 deletions libs/JSystem/JAudio2/JASCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "dol2asm.h"
#include "dolphin/os/OSCache.h"
#include "MSL_C/math.h"
#include "MSL_C/MSL_Common/Src/limits"

//
// Types:
Expand Down Expand Up @@ -340,13 +341,11 @@ f32 JASCalc::pow2(f32 x) {
return ret;
}

/* 8028F69C-8028F6C4 289FDC 0028+00 0/0 4/4 0/0 .text clamp<s,l>__7JASCalcFl */
// Could not make clamp not inline
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
extern "C" asm void func_8028F69C(void* _this, s32 param_0) {
nofralloc
#include "asm/JSystem/JAudio2/JASCalc/func_8028F69C.s"
}
#pragma pop
template <>
s16 JASCalc::clamp(s32 x) {
if (std::numeric_limits<s16>::min() >= x)
return std::numeric_limits<s16>::min();
if (x >= std::numeric_limits<s16>::max())
return std::numeric_limits<s16>::max();
return x;
}
Loading

0 comments on commit 2d79f2e

Please sign in to comment.