use better m4a variable/constant names

This commit is contained in:
Michael Panzlaff 2020-12-11 13:58:00 +01:00
parent 628ade247b
commit 15ff55eee5
4 changed files with 549 additions and 472 deletions

View File

@ -2,11 +2,41 @@
.equiv PCM_DMA_BUF_SIZE, 1584
.equiv C_V, 0x40
.equiv TONEDATA_TYPE_CGB, 0x07
.equiv TONEDATA_TYPE_FIX, 0x08
.equiv TONEDATA_TYPE_REV, 0x10
.equiv TONEDATA_TYPE_CMP, 0x20
.equiv TONEDATA_TYPE_SPL, 0x40 @ key split
.equiv TONEDATA_TYPE_RHY, 0x80 @ rhythm
.equiv TONEDATA_P_S_PAN, 0xc0
.equiv SOUND_CHANNEL_SF_START, 0x80
.equiv SOUND_CHANNEL_SF_STOP, 0x40
.equiv SOUND_CHANNEL_SF_SPECIAL, 0x20
.equiv SOUND_CHANNEL_SF_LOOP, 0x10
.equiv SOUND_CHANNEL_SF_IEC, 0x04
.equiv SOUND_CHANNEL_SF_ENV, 0x03
.equiv SOUND_CHANNEL_SF_ENV_ATTACK, 0x03
.equiv SOUND_CHANNEL_SF_ENV_DECAY, 0x02
.equiv SOUND_CHANNEL_SF_ENV_SUSTAIN, 0x01
.equiv SOUND_CHANNEL_SF_ENV_RELEASE, 0x00
.equiv SOUND_CHANNEL_SF_ON, (SOUND_CHANNEL_SF_START | SOUND_CHANNEL_SF_STOP | SOUND_CHANNEL_SF_IEC | SOUND_CHANNEL_SF_ENV)
.equiv CGB_CHANNEL_MO_PIT, 0x02
.equiv CGB_CHANNEL_MO_VOL, 0x01
.equiv WAVE_DATA_FLAG_LOOP, 0xC0
.equiv MPT_FLG_VOLSET, 0x01
.equiv MPT_FLG_VOLCHG, 0x03
.equiv MPT_FLG_PITSET, 0x04
.equiv MPT_FLG_PITCHG, 0x0C
.equiv MPT_FLG_START, 0x40
.equiv MPT_FLG_EXIST, 0x80
.macro struct_begin
.struct 0
.endm
@ -16,6 +46,28 @@
.struct \name + \size
.endm
struct_begin
struct_field o_WaveData_type, 2
struct_field o_WaveData_d1, 1
struct_field o_WaveData_flags, 1
struct_field o_WaveData_freq, 4
struct_field o_WaveData_loopStart, 4
struct_field o_WaveData_size, 4
struct_field o_WaveData_data, 0
struct_field WaveData_size, 0
struct_begin
struct_field o_ToneData_type, 1
struct_field o_ToneData_key, 1
struct_field o_ToneData_length, 1
struct_field o_ToneData_pan_sweep, 1
struct_field o_ToneData_wav, 4
struct_field o_ToneData_attack, 1
struct_field o_ToneData_decay, 1
struct_field o_ToneData_sustain, 1
struct_field o_ToneData_release, 1
struct_field ToneData_size, 0
struct_begin
struct_field o_SoundInfo_ident, 4
struct_field o_SoundInfo_pcmDmaCounter, 1
@ -32,8 +84,8 @@
struct_field o_SoundInfo_pcmFreq, 4
struct_field o_SoundInfo_divFreq, 4
struct_field o_SoundInfo_cgbChans, 4
struct_field o_SoundInfo_func, 4
struct_field o_SoundInfo_intp, 4
struct_field o_SoundInfo_MPlayMainHead, 4
struct_field o_SoundInfo_musicPlayerHead, 4
struct_field o_SoundInfo_CgbSound, 4
struct_field o_SoundInfo_CgbOscOff, 4
struct_field o_SoundInfo_MidiKeyToCgbFreq, 4
@ -46,7 +98,7 @@
struct_field SoundInfo_size, 0
struct_begin
struct_field o_SoundChannel_status, 1
struct_field o_SoundChannel_statusFlags, 1
struct_field o_SoundChannel_type, 1
struct_field o_SoundChannel_rightVolume, 1
struct_field o_SoundChannel_leftVolume, 1
@ -54,29 +106,29 @@
struct_field o_SoundChannel_decay, 1
struct_field o_SoundChannel_sustain, 1
struct_field o_SoundChannel_release, 1
struct_field o_SoundChannel_ky, 1
struct_field o_SoundChannel_ev, 1
struct_field o_SoundChannel_er, 1
struct_field o_SoundChannel_el, 1
struct_field o_SoundChannel_iev, 1
struct_field o_SoundChannel_iel, 1
struct_field o_SoundChannel_d1, 1
struct_field o_SoundChannel_d2, 1
struct_field o_SoundChannel_gt, 1
struct_field o_SoundChannel_mk, 1
struct_field o_SoundChannel_ve, 1
struct_field o_SoundChannel_pr, 1
struct_field o_SoundChannel_rp, 1
struct_field o_SoundChannel_d3, 3
struct_field o_SoundChannel_ct, 4
struct_field o_SoundChannel_key, 1
struct_field o_SoundChannel_envelopeVolume, 1
struct_field o_SoundChannel_envelopeVolumeRight, 1
struct_field o_SoundChannel_envelopeVolumeLeft, 1
struct_field o_SoundChannel_pseudoEchoVolume, 1
struct_field o_SoundChannel_pseudoEchoLength, 1
struct_field o_SoundChannel_dummy1, 1
struct_field o_SoundChannel_dummy2, 1
struct_field o_SoundChannel_gateTime, 1
struct_field o_SoundChannel_midiKey, 1
struct_field o_SoundChannel_velocity, 1
struct_field o_SoundChannel_priority, 1
struct_field o_SoundChannel_rhythmPan, 1
struct_field o_SoundChannel_dummy3, 3
struct_field o_SoundChannel_count, 4
struct_field o_SoundChannel_fw, 4
struct_field o_SoundChannel_freq, 4
struct_field o_SoundChannel_frequency, 4
struct_field o_SoundChannel_wav, 4
struct_field o_SoundChannel_cp, 4
struct_field o_SoundChannel_currentPointer, 4
struct_field o_SoundChannel_track, 4
struct_field o_SoundChannel_pp, 4
struct_field o_SoundChannel_np, 4
struct_field o_SoundChannel_d4, 4
struct_field o_SoundChannel_prevChannelPointer, 4
struct_field o_SoundChannel_nextChannelPointer, 4
struct_field o_SoundChannel_dummy4, 4
struct_field o_SoundChannel_xpi, 2
struct_field o_SoundChannel_xpc, 2
struct_field SoundChannel_size, 0
@ -112,8 +164,8 @@
struct_field o_MusicPlayerTrack_lfoDelay, 1
struct_field o_MusicPlayerTrack_lfoDelayC, 1
struct_field o_MusicPlayerTrack_priority, 1
struct_field o_MusicPlayerTrack_echoVolume, 1
struct_field o_MusicPlayerTrack_echoLength, 1
struct_field o_MusicPlayerTrack_pseudoEchoVolume, 1
struct_field o_MusicPlayerTrack_pseudoEchoLength, 1
struct_field o_MusicPlayerTrack_chan, 4
struct_field o_MusicPlayerTrack_ToneData_type, 1
struct_field o_MusicPlayerTrack_ToneData_key, 1
@ -159,41 +211,41 @@
struct_field MusicPlayerInfo_size, 0
struct_begin
struct_field o_CgbChannel_sf, 1
struct_field o_CgbChannel_ty, 1
struct_field o_CgbChannel_statusFlags, 1
struct_field o_CgbChannel_type, 1
struct_field o_CgbChannel_rightVolume, 1
struct_field o_CgbChannel_leftVolume, 1
struct_field o_CgbChannel_at, 1
struct_field o_CgbChannel_de, 1
struct_field o_CgbChannel_su, 1
struct_field o_CgbChannel_re, 1
struct_field o_CgbChannel_ky, 1
struct_field o_CgbChannel_ev, 1
struct_field o_CgbChannel_eg, 1
struct_field o_CgbChannel_ec, 1
struct_field o_CgbChannel_echoVolume, 1
struct_field o_CgbChannel_echoLength, 1
struct_field o_CgbChannel_d1, 1
struct_field o_CgbChannel_d2, 1
struct_field o_CgbChannel_gt, 1
struct_field o_CgbChannel_mk, 1
struct_field o_CgbChannel_ve, 1
struct_field o_CgbChannel_pr, 1
struct_field o_CgbChannel_rp, 1
struct_field o_CgbChannel_d3, 3
struct_field o_CgbChannel_d5, 1
struct_field o_CgbChannel_sg, 1
struct_field o_CgbChannel_attack, 1
struct_field o_CgbChannel_decay, 1
struct_field o_CgbChannel_sustain, 1
struct_field o_CgbChannel_release, 1
struct_field o_CgbChannel_key, 1
struct_field o_CgbChannel_envelopeVolume, 1
struct_field o_CgbChannel_envelopeGoal, 1
struct_field o_CgbChannel_envelopeCounter, 1
struct_field o_CgbChannel_pseudoEchoVolume, 1
struct_field o_CgbChannel_pseudoEchoLength, 1
struct_field o_CgbChannel_dummy1, 1
struct_field o_CgbChannel_dummy2, 1
struct_field o_CgbChannel_gateTime, 1
struct_field o_CgbChannel_midiKey, 1
struct_field o_CgbChannel_velocity, 1
struct_field o_CgbChannel_priority, 1
struct_field o_CgbChannel_rhythmPan, 1
struct_field o_CgbChannel_dummy3, 3
struct_field o_CgbChannel_dummy5, 1
struct_field o_CgbChannel_sustainGoal, 1
struct_field o_CgbChannel_n4, 1
struct_field o_CgbChannel_pan, 1
struct_field o_CgbChannel_panMask, 1
struct_field o_CgbChannel_mo, 1
struct_field o_CgbChannel_le, 1
struct_field o_CgbChannel_sw, 1
struct_field o_CgbChannel_fr, 4
struct_field o_CgbChannel_wp, 4
struct_field o_CgbChannel_cp, 4
struct_field o_CgbChannel_tp, 4
struct_field o_CgbChannel_pp, 4
struct_field o_CgbChannel_np, 4
struct_field o_CgbChannel_d4, 8
struct_field o_CgbChannel_modify, 1
struct_field o_CgbChannel_length, 1
struct_field o_CgbChannel_sweep, 1
struct_field o_CgbChannel_frequency, 4
struct_field o_CgbChannel_wavePointer, 4
struct_field o_CgbChannel_currentPointer, 4
struct_field o_CgbChannel_track, 4
struct_field o_CgbChannel_prevChannelPointer, 4
struct_field o_CgbChannel_nextChannelPointer, 4
struct_field o_CgbChannel_dummy4, 8
struct_field CgbChannel_size, 0

View File

@ -67,52 +67,22 @@ struct ToneData
u8 release;
};
#define SOUND_CHANNEL_SF_START 0x80
#define SOUND_CHANNEL_SF_STOP 0x40
#define SOUND_CHANNEL_SF_LOOP 0x10
#define SOUND_CHANNEL_SF_IEC 0x04
#define SOUND_CHANNEL_SF_ENV 0x03
#define SOUND_CHANNEL_SF_ENV_ATTACK 0x03
#define SOUND_CHANNEL_SF_ENV_DECAY 0x02
#define SOUND_CHANNEL_SF_ENV_SUSTAIN 0x01
#define SOUND_CHANNEL_SF_ON (SOUND_CHANNEL_SF_START | SOUND_CHANNEL_SF_STOP | SOUND_CHANNEL_SF_IEC | SOUND_CHANNEL_SF_ENV)
#define CGB_CHANNEL_MO_PIT 0x02
#define CGB_CHANNEL_MO_VOL 0x01
struct CgbChannel
{
u8 sf; // 0x0
u8 ty; // 0x1
u8 rightVolume; // 0x2
u8 leftVolume; // 0x3
u8 at; // 0x4
u8 de; // 0x5
u8 su; // 0x6
u8 re; // 0x7
u8 ky; // 0x8
u8 ev; // 0x9
u8 eg; // 0xA
u8 ec; // 0xB
u8 echoVolume; // 0xC
u8 echoLength; // 0xD
u8 d1; // 0xE
u8 d2; // 0xF
u8 gt; // 0x10
u8 mk; // 0x11
u8 ve; // 0x12
u8 pr; // 0x13
u8 rp; // 0x14
u8 d3[3]; // 0x15, 0x16, 0x17
u8 d5; // 0x18
u8 sg; // 0x19
u8 n4; // 0x1A
u8 pan; // 0x1B
u8 panMask; // 0x1C
u8 mo; // 0x1D
u8 le; // 0x1E
u8 sw; // 0x1F
u32 fr; // 0x20
u32 *wp;
u32 cp;
u32 tp;
u32 pp;
u32 np;
u8 d4[8];
};
struct MusicPlayerTrack;
struct SoundChannel
{
u8 status;
u8 statusFlags;
u8 type;
u8 rightVolume;
u8 leftVolume;
@ -120,29 +90,72 @@ struct SoundChannel
u8 decay;
u8 sustain;
u8 release;
u8 ky;
u8 ev;
u8 er;
u8 el;
u8 echoVolume;
u8 echoLength;
u8 d1;
u8 d2;
u8 gt;
u8 mk;
u8 ve;
u8 pr;
u8 rp;
u8 d3[3];
u32 ct;
u32 fw;
u32 freq;
struct WaveData *wav;
u32 cp;
u8 key;
u8 envelopeVolume;
u8 envelopeGoal;
u8 envelopeCounter;
u8 pseudoEchoVolume;
u8 pseudoEchoLength;
u8 dummy1;
u8 dummy2;
u8 gateTime;
u8 midiKey;
u8 velocity;
u8 priority;
u8 rhythmPan;
u8 dummy3[3];
u8 dummy5;
u8 sustainGoal;
u8 n4; // NR[1-4]4 register (initial, length bit)
u8 pan;
u8 panMask;
u8 modify;
u8 length;
u8 sweep;
u32 frequency;
u32 *wavePointer; // instructs CgbMain to load targeted wave
u32 *currentPointer; // stores the currently loaded wave
struct MusicPlayerTrack *track;
u32 pp;
u32 np;
u32 d4;
void *prevChannelPointer;
void *nextChannelPointer;
u8 dummy4[8];
};
struct MusicPlayerTrack;
struct SoundChannel
{
u8 statusFlags;
u8 type;
u8 rightVolume;
u8 leftVolume;
u8 attack;
u8 decay;
u8 sustain;
u8 release;
u8 key; // midi key as it was translated into final pitch
u8 envelopeVolume;
u8 envelopeVolumeRight;
u8 envelopeVolumeLeft;
u8 pseudoEchoVolume;
u8 pseudoEchoLength;
u8 dummy1;
u8 dummy2;
u8 gateTime;
u8 midiKey; // midi key as it was used in the track data
u8 velocity;
u8 priority;
u8 rhythmPan;
u8 dummy3[3];
u32 count;
u32 fw;
u32 frequency;
struct WaveData *wav;
s8 *currentPointer;
struct MusicPlayerTrack *track;
void *prevChannelPointer;
void *nextChannelPointer;
u32 dummy4;
u16 xpi;
u16 xpc;
};
@ -151,6 +164,16 @@ struct SoundChannel
#define PCM_DMA_BUF_SIZE 1584 // size of Direct Sound buffer
struct MusicPlayerInfo;
typedef void (*MPlayFunc)();
typedef void (*PlyNoteFunc)(u32, struct MusicPlayerInfo *, struct MusicPlayerTrack *);
typedef void (*CgbSoundFunc)(void);
typedef void (*CgbOscOffFunc)(u8);
typedef u32 (*MidiKeyToCgbFreqFunc)(u8, u8, u8);
typedef void (*ExtVolPitFunc)(void);
typedef void (*MPlayMainFunc)(struct MusicPlayerInfo *);
struct SoundInfo
{
// This field is normally equal to ID_NUMBER but it is set to other
@ -168,7 +191,7 @@ struct SoundInfo
u8 freq;
u8 mode;
u8 c15;
u8 c15; // periodically counts from 14 downto 0 (15 states)
u8 pcmDmaPeriod; // number of V-blanks per PCM DMA
u8 maxLines;
u8 gap[3];
@ -176,14 +199,14 @@ struct SoundInfo
s32 pcmFreq;
s32 divFreq;
struct CgbChannel *cgbChans;
u32 func;
u32 intp;
void (*CgbSound)(void);
void (*CgbOscOff)(u8);
u32 (*MidiKeyToCgbFreq)(u8, u8, u8);
u32 MPlayJumpTable;
u32 plynote;
u32 ExtVolPit;
MPlayMainFunc MPlayMainHead;
struct MusicPlayerInfo *musicPlayerHead;
CgbSoundFunc CgbSound;
CgbOscOffFunc CgbOscOff;
MidiKeyToCgbFreqFunc MidiKeyToCgbFreq;
MPlayFunc *MPlayJumpTable;
PlyNoteFunc plynote;
ExtVolPitFunc ExtVolPit;
u8 gap2[16];
struct SoundChannel chans[MAX_DIRECTSOUND_CHANNELS];
s8 pcmBuffer[PCM_DMA_BUF_SIZE * 2];
@ -270,8 +293,8 @@ struct MusicPlayerTrack
u8 lfoDelay;
u8 lfoDelayC;
u8 priority;
u8 echoVolume;
u8 echoLength;
u8 pseudoEchoVolume;
u8 pseudoEchoLength;
struct SoundChannel *chan;
struct ToneData tone;
u8 gap[10];
@ -312,8 +335,8 @@ struct MusicPlayerInfo
struct MusicPlayerTrack *tracks;
struct ToneData *tone;
u32 ident;
u32 func;
u32 intp;
MPlayMainFunc MPlayMainNext;
struct MusicPlayerInfo *musicPlayerNext;
};
struct MusicPlayer
@ -351,7 +374,7 @@ extern struct MusicPlayerTrack gPokemonCryTracks[];
extern char SoundMainRAM[];
extern void *gMPlayJumpTable[];
extern MPlayFunc gMPlayJumpTable[];
typedef void (*XcmdFunc)(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
extern const XcmdFunc gXcmdTable[];
@ -380,7 +403,7 @@ u32 umul3232H32(u32 multiplier, u32 multiplicand);
void SoundMain(void);
void SoundMainBTM(void);
void TrackStop(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track);
void MPlayMain(void);
void MPlayMain(struct MusicPlayerInfo *);
void RealClearChain(void *x);
void MPlayContinue(struct MusicPlayerInfo *mplayInfo);
@ -400,7 +423,7 @@ void CgbOscOff(u8);
void CgbModVol(struct CgbChannel *chan);
u32 MidiKeyToCgbFreq(u8, u8, u8);
void DummyFunc(void);
void MPlayJumpTableCopy(void **mplayJumpTable);
void MPlayJumpTableCopy(MPlayFunc *mplayJumpTable);
void SampleFreqSet(u32 freq);
void m4aSoundVSyncOn(void);
void m4aSoundVSyncOff(void);
@ -448,7 +471,7 @@ void ply_tune(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_port(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_xcmd(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_endtie(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_note(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_note(u32 note_cmd, struct MusicPlayerInfo *, struct MusicPlayerTrack *);
// extended sound command handler functions
void ply_xxx(struct MusicPlayerInfo *, struct MusicPlayerTrack *);

226
src/m4a.c
View File

@ -10,7 +10,7 @@ BSS_CODE ALIGNED(4) char SoundMainRAM_Buffer[0x800] = {0};
struct SoundInfo gSoundInfo;
struct PokemonCrySong gPokemonCrySongs[MAX_POKEMON_CRIES];
struct MusicPlayerInfo gPokemonCryMusicPlayers[MAX_POKEMON_CRIES];
void *gMPlayJumpTable[36];
MPlayFunc gMPlayJumpTable[36];
struct CgbChannel gCgbChans[4];
struct MusicPlayerTrack gPokemonCryTracks[MAX_POKEMON_CRIES * 2];
struct PokemonCrySong gPokemonCrySong;
@ -293,7 +293,7 @@ void MPlayExtender(struct CgbChannel *cgbChans)
gMPlayJumpTable[32] = FadeOutBody;
gMPlayJumpTable[33] = TrkVolPitSet;
soundInfo->cgbChans = (struct CgbChannel *)cgbChans;
soundInfo->cgbChans = cgbChans;
soundInfo->CgbSound = CgbSound;
soundInfo->CgbOscOff = CgbOscOff;
soundInfo->MidiKeyToCgbFreq = MidiKeyToCgbFreq;
@ -301,13 +301,13 @@ void MPlayExtender(struct CgbChannel *cgbChans)
CpuFill32(0, cgbChans, sizeof(struct CgbChannel) * 4);
cgbChans[0].ty = 1;
cgbChans[0].type = 1;
cgbChans[0].panMask = 0x11;
cgbChans[1].ty = 2;
cgbChans[1].type = 2;
cgbChans[1].panMask = 0x22;
cgbChans[2].ty = 3;
cgbChans[2].type = 3;
cgbChans[2].panMask = 0x44;
cgbChans[3].ty = 4;
cgbChans[3].type = 4;
cgbChans[3].panMask = 0x88;
soundInfo->ident = ident;
@ -362,15 +362,15 @@ void SoundInit(struct SoundInfo *soundInfo)
soundInfo->maxChans = 8;
soundInfo->masterVolume = 15;
soundInfo->plynote = (u32)ply_note;
soundInfo->plynote = ply_note;
soundInfo->CgbSound = DummyFunc;
soundInfo->CgbOscOff = (void (*)(u8))DummyFunc;
soundInfo->MidiKeyToCgbFreq = (u32 (*)(u8, u8, u8))DummyFunc;
soundInfo->ExtVolPit = (u32)DummyFunc;
soundInfo->CgbOscOff = (CgbOscOffFunc)DummyFunc;
soundInfo->MidiKeyToCgbFreq = (MidiKeyToCgbFreqFunc)DummyFunc;
soundInfo->ExtVolPit = (ExtVolPitFunc)DummyFunc;
MPlayJumpTableCopy(gMPlayJumpTable);
soundInfo->MPlayJumpTable = (u32)gMPlayJumpTable;
soundInfo->MPlayJumpTable = gMPlayJumpTable;
SampleFreqSet(SOUND_MODE_FREQ_13379);
@ -437,7 +437,7 @@ void m4aSoundMode(u32 mode)
while (temp != 0)
{
chan->status = 0;
chan->statusFlags = 0;
temp--;
chan++;
}
@ -483,7 +483,7 @@ void SoundClear(void)
while (i > 0)
{
((struct SoundChannel *)chan)->status = 0;
((struct SoundChannel *)chan)->statusFlags = 0;
i--;
chan = (void *)((s32)chan + sizeof(struct SoundChannel));
}
@ -497,7 +497,7 @@ void SoundClear(void)
while (i <= 4)
{
soundInfo->CgbOscOff(i);
((struct CgbChannel *)chan)->sf = 0;
((struct CgbChannel *)chan)->statusFlags = 0;
i++;
chan = (void *)((s32)chan + sizeof(struct CgbChannel));
}
@ -572,15 +572,18 @@ void MPlayOpen(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track
tracks++;
}
if (soundInfo->func != 0)
// append music player and MPlayMain to linked list
if (soundInfo->MPlayMainHead != NULL)
{
mplayInfo->func = soundInfo->func;
mplayInfo->intp = soundInfo->intp;
soundInfo->func = 0;
mplayInfo->MPlayMainNext = soundInfo->MPlayMainHead;
mplayInfo->musicPlayerNext = soundInfo->musicPlayerHead;
// NULL assignment semantically useless, but required for match
soundInfo->MPlayMainHead = NULL;
}
soundInfo->intp = (u32)mplayInfo;
soundInfo->func = (u32)MPlayMain;
soundInfo->musicPlayerHead = mplayInfo;
soundInfo->MPlayMainHead = MPlayMain;
soundInfo->ident = ID_NUMBER;
mplayInfo->ident = ID_NUMBER;
}
@ -884,7 +887,7 @@ void CgbModVol(struct CgbChannel *chan)
if ((soundInfo->mode & 1) || !CgbPan(chan))
{
chan->pan = 0xFF;
chan->eg = (u32)(chan->rightVolume + chan->leftVolume) >> 4;
chan->envelopeGoal = (u32)(chan->rightVolume + chan->leftVolume) >> 4;
}
else
{
@ -895,12 +898,12 @@ void CgbModVol(struct CgbChannel *chan)
asm("" : : : "memory");
#endif
chan->eg = (u32)(chan->rightVolume + chan->leftVolume) >> 4;
if (chan->eg > 15)
chan->eg = 15;
chan->envelopeGoal = (u32)(chan->rightVolume + chan->leftVolume) >> 4;
if (chan->envelopeGoal > 15)
chan->envelopeGoal = 15;
}
chan->sg = (chan->eg * chan->su + 15) >> 4;
chan->sustainGoal = (chan->envelopeGoal * chan->sustain + 15) >> 4;
chan->pan &= chan->panMask;
}
@ -927,7 +930,7 @@ void CgbSound(void)
for (ch = 1, channels = soundInfo->cgbChans; ch <= 4; ch++, channels++)
{
if (!(channels->sf & 0xc7))
if (!(channels->statusFlags & SOUND_CHANNEL_SF_ON))
continue;
switch (ch)
@ -965,53 +968,53 @@ void CgbSound(void)
prevC15 = soundInfo->c15;
evAdd = *nrx2ptr;
if (channels->sf & 0x80)
if (channels->statusFlags & SOUND_CHANNEL_SF_START)
{
if (!(channels->sf & 0x40))
if (!(channels->statusFlags & SOUND_CHANNEL_SF_STOP))
{
channels->sf = 3;
channels->mo = 3;
channels->statusFlags = SOUND_CHANNEL_SF_ENV_ATTACK;
channels->modify = CGB_CHANNEL_MO_PIT | CGB_CHANNEL_MO_VOL;
CgbModVol(channels);
switch (ch)
{
case 1:
*nrx0ptr = channels->sw;
*nrx0ptr = channels->sweep;
// fallthrough
case 2:
*nrx1ptr = ((u32)channels->wp << 6) + channels->le;
*nrx1ptr = ((u32)channels->wavePointer << 6) + channels->length;
goto loc_82E0E30;
case 3:
if ((u32)channels->wp != channels->cp)
if (channels->wavePointer != channels->currentPointer)
{
*nrx0ptr = 0x40;
REG_WAVE_RAM0 = channels->wp[0];
REG_WAVE_RAM1 = channels->wp[1];
REG_WAVE_RAM2 = channels->wp[2];
REG_WAVE_RAM3 = channels->wp[3];
channels->cp = (u32)channels->wp;
REG_WAVE_RAM0 = channels->wavePointer[0];
REG_WAVE_RAM1 = channels->wavePointer[1];
REG_WAVE_RAM2 = channels->wavePointer[2];
REG_WAVE_RAM3 = channels->wavePointer[3];
channels->currentPointer = channels->wavePointer;
}
*nrx0ptr = 0;
*nrx1ptr = channels->le;
if (channels->le)
channels->n4 = -64;
*nrx1ptr = channels->length;
if (channels->length)
channels->n4 = 0xC0;
else
channels->n4 = -128;
channels->n4 = 0x80;
break;
default:
*nrx1ptr = channels->le;
*nrx3ptr = (u32)channels->wp << 3;
*nrx1ptr = channels->length;
*nrx3ptr = (u32)channels->wavePointer << 3;
loc_82E0E30:
evAdd = channels->at + 8;
if (channels->le)
channels->n4 = 64;
evAdd = channels->attack + 8;
if (channels->length)
channels->n4 = 0x40;
else
channels->n4 = 0;
channels->n4 = 0x00;
break;
}
channels->ec = channels->at;
if ((s8)(channels->at & mask))
channels->envelopeCounter = channels->attack;
if ((s8)(channels->attack & mask))
{
channels->ev = 0;
channels->envelopeVolume = 0;
goto EC_MINUS;
}
else
@ -1024,28 +1027,28 @@ void CgbSound(void)
goto loc_82E0E82;
}
}
else if (channels->sf & 0x04)
else if (channels->statusFlags & SOUND_CHANNEL_SF_IEC)
{
channels->echoLength--;
if ((s8)(channels->echoLength & mask) <= 0)
channels->pseudoEchoLength--;
if ((s8)(channels->pseudoEchoLength & mask) <= 0)
{
loc_82E0E82:
CgbOscOff(ch);
channels->sf = 0;
channels->statusFlags = 0;
goto LAST_LABEL;
}
goto loc_82E0FD6;
}
else if ((channels->sf & 0x40) && (channels->sf & 0x03))
else if ((channels->statusFlags & SOUND_CHANNEL_SF_STOP) && (channels->statusFlags & SOUND_CHANNEL_SF_ENV))
{
channels->sf &= 0xfc;
channels->ec = channels->re;
if ((s8)(channels->re & mask))
channels->statusFlags &= ~SOUND_CHANNEL_SF_ENV;
channels->envelopeCounter = channels->release;
if ((s8)(channels->release & mask))
{
channels->mo |= 1;
channels->modify |= CGB_CHANNEL_MO_VOL;
if (ch != 3)
{
evAdd = channels->re;
evAdd = channels->release;
}
goto EC_MINUS;
}
@ -1057,24 +1060,24 @@ void CgbSound(void)
else
{
loc_82E0ED0:
if (channels->ec == 0)
if (channels->envelopeCounter == 0)
{
if (ch == 3)
{
channels->mo |= 1;
channels->modify |= CGB_CHANNEL_MO_VOL;
}
CgbModVol(channels);
if ((channels->sf & 0x3) == 0)
if ((channels->statusFlags & SOUND_CHANNEL_SF_ENV) == 0)
{
channels->ev--;
if ((s8)(channels->ev & mask) <= 0)
channels->envelopeVolume--;
if ((s8)(channels->envelopeVolume & mask) <= 0)
{
loc_82E0F02:
channels->ev = ((channels->eg * channels->echoVolume) + 0xFF) >> 8;
if (channels->ev)
channels->envelopeVolume = ((channels->envelopeGoal * channels->pseudoEchoVolume) + 0xFF) >> 8;
if (channels->envelopeVolume)
{
channels->sf |= 0x4;
channels->mo |= 1;
channels->statusFlags |= SOUND_CHANNEL_SF_IEC;
channels->modify |= CGB_CHANNEL_MO_VOL;
if (ch != 3)
{
evAdd = 8;
@ -1088,34 +1091,34 @@ void CgbSound(void)
}
else
{
channels->ec = channels->re;
channels->envelopeCounter = channels->release;
}
}
else if ((channels->sf & 0x3) == 1)
else if ((channels->statusFlags & SOUND_CHANNEL_SF_ENV) == 1)
{
loc_82E0F3A:
channels->ev = channels->sg;
channels->ec = 7;
channels->envelopeVolume = channels->sustainGoal;
channels->envelopeCounter = 7;
}
else if ((channels->sf & 0x3) == 2)
else if ((channels->statusFlags & SOUND_CHANNEL_SF_ENV) == 2)
{
int ev, sg;
int envelopeVolume, sustainGoal;
channels->ev--;
ev = (s8)(channels->ev & mask);
sg = (s8)(channels->sg);
if (ev <= sg)
channels->envelopeVolume--;
envelopeVolume = (s8)(channels->envelopeVolume & mask);
sustainGoal = (s8)(channels->sustainGoal);
if (envelopeVolume <= sustainGoal)
{
loc_82E0F5A:
if (channels->su == 0)
if (channels->sustain == 0)
{
channels->sf &= 0xfc;
channels->statusFlags &= ~SOUND_CHANNEL_SF_ENV;
goto loc_82E0F02;
}
else
{
channels->sf--;
channels->mo |= 1;
channels->statusFlags--;
channels->modify |= CGB_CHANNEL_MO_VOL;
if (ch != 3)
{
evAdd = 8;
@ -1125,24 +1128,24 @@ void CgbSound(void)
}
else
{
channels->ec = channels->de;
channels->envelopeCounter = channels->decay;
}
}
else
{
channels->ev++;
if ((u8)(channels->ev & mask) >= channels->eg)
channels->envelopeVolume++;
if ((u8)(channels->envelopeVolume & mask) >= channels->envelopeGoal)
{
loc_82E0F96:
channels->sf--;
channels->ec = channels->de;
if ((u8)(channels->ec & mask))
channels->statusFlags--;
channels->envelopeCounter = channels->decay;
if ((u8)(channels->envelopeCounter & mask))
{
channels->mo |= 1;
channels->ev = channels->eg;
channels->modify |= CGB_CHANNEL_MO_VOL;
channels->envelopeVolume = channels->envelopeGoal;
if (ch != 3)
{
evAdd = channels->de;
evAdd = channels->decay;
}
}
else
@ -1152,14 +1155,14 @@ void CgbSound(void)
}
else
{
channels->ec = channels->at;
channels->envelopeCounter = channels->attack;
}
}
}
}
EC_MINUS:
channels->ec--;
channels->envelopeCounter--;
if (prevC15 == 0)
{
prevC15--;
@ -1167,39 +1170,39 @@ void CgbSound(void)
}
loc_82E0FD6:
if (channels->mo & 0x2)
if (channels->modify & CGB_CHANNEL_MO_PIT)
{
if (ch < 4 && (channels->ty & 0x08))
if (ch < 4 && (channels->type & TONEDATA_TYPE_FIX))
{
int biasH = REG_SOUNDBIAS_H;
if (biasH < 64)
{
channels->fr = (channels->fr + 2) & 0x7fc;
channels->frequency = (channels->frequency + 2) & 0x7fc;
}
else if (biasH < 128)
{
channels->fr = (channels->fr + 1) & 0x7fe;
channels->frequency = (channels->frequency + 1) & 0x7fe;
}
}
if (ch != 4)
{
*nrx3ptr = channels->fr;
*nrx3ptr = channels->frequency;
}
else
{
*nrx3ptr = (*nrx3ptr & 0x08) | channels->fr;
*nrx3ptr = (*nrx3ptr & 0x08) | channels->frequency;
}
channels->n4 = (channels->n4 & 0xC0) + (*((u8*)(&channels->fr) + 1));
channels->n4 = (channels->n4 & 0xC0) + (*((u8*)(&channels->frequency) + 1));
*nrx4ptr = (s8)(channels->n4 & mask);
}
if (channels->mo & 1)
if (channels->modify & 1)
{
REG_NR51 = (REG_NR51 & ~channels->panMask) | channels->pan;
if (ch == 3)
{
*nrx2ptr = gCgb3Vol[channels->ev];
*nrx2ptr = gCgb3Vol[channels->envelopeVolume];
if (channels->n4 & 0x80)
{
*nrx0ptr = 0x80;
@ -1210,7 +1213,7 @@ void CgbSound(void)
else
{
evAdd &= 0xf;
*nrx2ptr = (channels->ev << 4) + evAdd;
*nrx2ptr = (channels->envelopeVolume << 4) + evAdd;
*nrx4ptr = channels->n4 | 0x80;
if (ch == 1 && !(*nrx0ptr & 0x08))
{
@ -1220,7 +1223,7 @@ void CgbSound(void)
}
LAST_LABEL:
channels->mo = 0;
channels->modify = 0;
}
}
@ -1504,8 +1507,8 @@ void ply_memacc(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *trac
cond_true:
{
void (*func)(struct MusicPlayerInfo *, struct MusicPlayerTrack *) = *(&gMPlayJumpTable[1]);
func(mplayInfo, track);
// *& is required for matching
(*&gMPlayJumpTable[1])(mplayInfo, track);
return;
}
@ -1523,8 +1526,7 @@ void ply_xcmd(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
void ply_xxx(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
{
void (*func)(struct MusicPlayerInfo *, struct MusicPlayerTrack *) = *(&gMPlayJumpTable[0]);
func(mplayInfo, track);
gMPlayJumpTable[0](mplayInfo, track);
}
#define READ_XCMD_BYTE(var, n) \
@ -1580,13 +1582,13 @@ void ply_xrele(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track
void ply_xiecv(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
{
track->echoVolume = *track->cmdPtr;
track->pseudoEchoVolume = *track->cmdPtr;
track->cmdPtr++;
}
void ply_xiecl(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
{
track->echoLength = *track->cmdPtr;
track->pseudoEchoLength = *track->cmdPtr;
track->cmdPtr++;
}

File diff suppressed because it is too large Load Diff