From 9eb5794482fc1d529a866f53a6cadb743d8f9e2c Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Fri, 19 Mar 2021 18:58:50 -0400 Subject: cleanup some m4a code (thanks to shoomer) --- src/m4a.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/m4a.c') diff --git a/src/m4a.c b/src/m4a.c index e079ba4f6..7d7193334 100644 --- a/src/m4a.c +++ b/src/m4a.c @@ -1616,6 +1616,9 @@ void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tra void ply_xcmd_0D(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) { u32 unk; +#ifdef UBFIX + unk = 0; +#endif READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable READ_XCMD_BYTE(unk, 1) @@ -1657,18 +1660,12 @@ start_song: mplayInfo = &gPokemonCryMusicPlayers[i]; mplayInfo->ident++; -#define CRY ((s32)&gPokemonCrySongs + i * sizeof(struct PokemonCrySong)) -#define CRY_OFS(field) offsetof(struct PokemonCrySong, field) + gPokemonCrySongs[i] = gPokemonCrySong; - memcpy((void *)CRY, &gPokemonCrySong, sizeof(struct PokemonCrySong)); - - *(u32 *)(CRY + CRY_OFS(tone)) = (u32)tone; - *(u32 *)(CRY + CRY_OFS(part)) = CRY + CRY_OFS(part0); - *(u32 *)(CRY + CRY_OFS(part) + 4) = CRY + CRY_OFS(part1); - *(u32 *)(CRY + CRY_OFS(gotoTarget)) = CRY + CRY_OFS(cont); - -#undef CRY_OFS -#undef CRY + gPokemonCrySongs[i].tone = tone; + gPokemonCrySongs[i].part[0] = &gPokemonCrySongs[i].part0; + gPokemonCrySongs[i].part[1] = &gPokemonCrySongs[i].part1; + gPokemonCrySongs[i].gotoTarget = (u32)&gPokemonCrySongs[i].cont; mplayInfo->ident = ID_NUMBER; -- cgit v1.2.3 From d542baf14bd38110389046e90dde40043d4e2b6a Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Mon, 19 Apr 2021 23:44:24 -0400 Subject: THE BEAST IS SLAIN --- src/m4a.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/m4a.c') diff --git a/src/m4a.c b/src/m4a.c index 7d7193334..3bb440f65 100644 --- a/src/m4a.c +++ b/src/m4a.c @@ -887,18 +887,13 @@ void CgbModVol(struct CgbChannel *chan) if ((soundInfo->mode & 1) || !CgbPan(chan)) { chan->pan = 0xFF; - chan->envelopeGoal = (u32)(chan->rightVolume + chan->leftVolume) >> 4; + chan->envelopeGoal = (u32)(chan->leftVolume + chan->rightVolume); + chan->envelopeGoal /= 16; } else { - // Force chan->rightVolume and chan->leftVolume to be read from memory again, - // even though there is no reason to do so. - // The command line option "-fno-gcse" achieves the same result as this. - #ifndef NONMATCHING - asm("" : : : "memory"); - #endif - - chan->envelopeGoal = (u32)(chan->rightVolume + chan->leftVolume) >> 4; + chan->envelopeGoal = (u32)(chan->leftVolume + chan->rightVolume); + chan->envelopeGoal /= 16; if (chan->envelopeGoal > 15) chan->envelopeGoal = 15; } -- cgit v1.2.3 From 3e15a3ef8fe45373acb11d81046f081b6492a0d0 Mon Sep 17 00:00:00 2001 From: gAlfonso-bit <83477269+gAlfonso-bit@users.noreply.github.com> Date: Wed, 12 May 2021 16:58:34 -0400 Subject: Update IsPokemonCryPlaying --- src/m4a.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/m4a.c') diff --git a/src/m4a.c b/src/m4a.c index 3bb440f65..717cafc78 100644 --- a/src/m4a.c +++ b/src/m4a.c @@ -1703,14 +1703,14 @@ void SetPokemonCryProgress(u32 val) gPokemonCrySong.unkCmd0DParam = val; } -int IsPokemonCryPlaying(struct MusicPlayerInfo *mplayInfo) +bool32 IsPokemonCryPlaying(struct MusicPlayerInfo *mplayInfo) { struct MusicPlayerTrack *track = mplayInfo->tracks; if (track->chan && track->chan->track == track) - return 1; + return TRUE; else - return 0; + return FALSE; } void SetPokemonCryChorus(s8 val) -- cgit v1.2.3 From ff16812f99f62a495975e7cc3c68ede339171765 Mon Sep 17 00:00:00 2001 From: gAlfonso-bit <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sun, 23 May 2021 10:56:37 -0400 Subject: UBFix: uninitialized variables in m4a engine and siirtc.c (#1432) --- src/m4a.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/m4a.c') diff --git a/src/m4a.c b/src/m4a.c index 717cafc78..105312a40 100644 --- a/src/m4a.c +++ b/src/m4a.c @@ -1525,6 +1525,10 @@ void ply_xwave(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track { u32 wav; +#ifdef UBFIX + wav = 0; +#endif + READ_XCMD_BYTE(wav, 0) // UB: uninitialized variable READ_XCMD_BYTE(wav, 1) READ_XCMD_BYTE(wav, 2) @@ -1592,6 +1596,10 @@ void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tra { u32 unk; +#ifdef UBFIX + unk = 0; +#endif + READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable READ_XCMD_BYTE(unk, 1) @@ -1611,6 +1619,7 @@ void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tra void ply_xcmd_0D(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track) { u32 unk; + #ifdef UBFIX unk = 0; #endif -- cgit v1.2.3