summaryrefslogtreecommitdiff
path: root/src/m4a.c
diff options
context:
space:
mode:
authorfroggestspirit <froggestspirit@gmail.com>2021-09-06 10:32:14 -0400
committerfroggestspirit <froggestspirit@gmail.com>2021-09-06 10:32:14 -0400
commit73554ec88d4f269b6146f6d1ab5d2742cb0a6f89 (patch)
treefac5bee8a4ce4757816dbbe42265523478b78781 /src/m4a.c
parentec6b1ea3735ff98a9714b219e4a999894ecc6010 (diff)
parent63e6b914e4d9b9bdb0a8d621b2ed233990f2ef66 (diff)
Merge remote-tracking branch 'pret/master'
Diffstat (limited to 'src/m4a.c')
-rw-r--r--src/m4a.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/m4a.c b/src/m4a.c
index 7d7193334..b159e3873 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;
}
@@ -911,7 +906,6 @@ void CgbSound(void)
{
s32 ch;
struct CgbChannel *channels;
- s32 envelopeStepTimeAndDir;
s32 prevC15;
struct SoundInfo *soundInfo = SOUND_INFO_PTR;
vu8 *nrx0ptr;
@@ -919,6 +913,7 @@ void CgbSound(void)
vu8 *nrx2ptr;
vu8 *nrx3ptr;
vu8 *nrx4ptr;
+ s32 envelopeStepTimeAndDir;
// Most comparision operations that cast to s8 perform 'and' by 0xFF.
int mask = 0xff;
@@ -1203,8 +1198,8 @@ void CgbSound(void)
}
else
{
- envelopeStepTimeAndDir &= 0xf;
- *nrx2ptr = (channels->envelopeVolume << 4) + envelopeStepTimeAndDir;
+ u32 envMask = 0xF;
+ *nrx2ptr = (envelopeStepTimeAndDir & envMask) + (channels->envelopeVolume << 4);
*nrx4ptr = channels->n4 | 0x80;
if (ch == 1 && !(*nrx0ptr & 0x08))
*nrx4ptr = channels->n4 | 0x80;
@@ -1530,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)
@@ -1597,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)
@@ -1616,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
@@ -1708,14 +1712,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)