Cleaned up the libraries.

This commit is contained in:
PokeCodec 2020-08-20 18:27:35 -04:00
parent d2c7a862c7
commit cbb94035e3
8 changed files with 283 additions and 335 deletions

View File

@ -109,7 +109,7 @@ _1a0:
strh r1, [r0, 0xa] @ SIOMLT_SEND strh r1, [r0, 0xa] @ SIOMLT_SEND
ldr r0, =_data_2f0 ldr r0, =_data_2f0
ldr r1, =gCode ldr r1, =gCode
swi 0x11 << 16 svc 0x11 << 16
ldr lr, =gCode ldr lr, =gCode
bx lr bx lr
.pool .pool

View File

@ -100,12 +100,12 @@ struct CgbChannel
u8 le; u8 le;
u8 sw; u8 sw;
u32 fr; u32 fr;
u32 wp; u32 *wp;
u32 cp; u32 *cp;
u32 tp; void *tp;
u32 pp; void *pp;
u32 np; void *np;
u8 d4[8]; u32 d4[2];
}; };
struct MusicPlayerTrack; struct MusicPlayerTrack;
@ -138,10 +138,10 @@ struct SoundChannel
u32 fw; u32 fw;
u32 freq; u32 freq;
struct WaveData *wav; struct WaveData *wav;
u32 cp; s8 *cp;
struct MusicPlayerTrack *track; struct MusicPlayerTrack *track;
u32 pp; void *pp;
u32 np; void *np;
u32 d4; u32 d4;
u16 xpi; u16 xpi;
u16 xpc; u16 xpc;
@ -172,11 +172,11 @@ struct SoundInfo
u8 pcmDmaPeriod; // number of V-blanks per PCM DMA u8 pcmDmaPeriod; // number of V-blanks per PCM DMA
u8 maxLines; u8 maxLines;
u8 gap[3]; u8 gap[3];
s32 pcmSamplesPerVBlank; u32 pcmSamplesPerVBlank;
s32 pcmFreq; u32 pcmFreq;
s32 divFreq; u32 divFreq;
struct CgbChannel *cgbChans; struct CgbChannel *cgbChans;
u32 func; void (*func)();
u32 intp; u32 intp;
void (*CgbSound)(void); void (*CgbSound)(void);
void (*CgbOscOff)(u8); void (*CgbOscOff)(u8);
@ -184,7 +184,7 @@ struct SoundInfo
u32 MPlayJumpTable; u32 MPlayJumpTable;
u32 plynote; u32 plynote;
u32 ExtVolPit; u32 ExtVolPit;
u8 gap2[16]; u32 gap2[4];
struct SoundChannel chans[MAX_DIRECTSOUND_CHANNELS]; struct SoundChannel chans[MAX_DIRECTSOUND_CHANNELS];
s8 pcmBuffer[PCM_DMA_BUF_SIZE * 2]; s8 pcmBuffer[PCM_DMA_BUF_SIZE * 2];
}; };
@ -248,7 +248,7 @@ struct MusicPlayerTrack
u8 key; u8 key;
u8 velocity; u8 velocity;
u8 runningStatus; u8 runningStatus;
u8 keyM; s8 keyM;
u8 pitM; u8 pitM;
s8 keyShift; s8 keyShift;
s8 keyShiftX; s8 keyShiftX;
@ -312,7 +312,7 @@ struct MusicPlayerInfo
struct MusicPlayerTrack *tracks; struct MusicPlayerTrack *tracks;
struct ToneData *tone; struct ToneData *tone;
u32 ident; u32 ident;
u32 func; void (*func)();
u32 intp; u32 intp;
}; };
@ -447,7 +447,7 @@ void ply_tune(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_port(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_port(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_xcmd(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_xcmd(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_endtie(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_endtie(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_note(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_note(u8, struct MusicPlayerInfo *, struct MusicPlayerTrack *);
// extended sound command handler functions // extended sound command handler functions
void ply_xxx(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_xxx(struct MusicPlayerInfo *, struct MusicPlayerTrack *);

View File

@ -26,9 +26,9 @@
.set OAM, 0x7000000 .set OAM, 0x7000000
.set SOUND_INFO_PTR, 0x3007FF0 .set SOUND_INFO_PTR, IWRAM_END - 0x10
.set INTR_CHECK, 0x3007FF8 .set INTR_CHECK, IWRAM_END - 0x8
.set INTR_VECTOR, 0x3007FFC .set INTR_VECTOR, IWRAM_END - 0x4
.set INTR_FLAG_VBLANK, 1 << 0 .set INTR_FLAG_VBLANK, 1 << 0
.set INTR_FLAG_HBLANK, 1 << 1 .set INTR_FLAG_HBLANK, 1 << 1

View File

@ -6,194 +6,178 @@
.equiv TONEDATA_TYPE_FIX, 0x08 .equiv TONEDATA_TYPE_FIX, 0x08
.equiv TONEDATA_TYPE_SPL, 0x40 @ key split .equiv TONEDATA_TYPE_SPL, 0x40 @ key split
.equiv TONEDATA_TYPE_RHY, 0x80 @ rhythm .equiv TONEDATA_TYPE_RHY, 0x80 @ rhythm
.equiv TONEDATA_P_S_PAN, 0xc0
.macro struct_begin .equiv o_SoundChannel_status, 0
.struct 0 .equiv o_SoundChannel_type, 1
.endm .equiv o_SoundChannel_rightVolume, 2
.equiv o_SoundChannel_leftVolume, 3
.equiv o_SoundChannel_attack, 4
.equiv o_SoundChannel_decay, 5
.equiv o_SoundChannel_sustain, 6
.equiv o_SoundChannel_release, 7
.equiv o_SoundChannel_ky, 8
.equiv o_SoundChannel_ev, 9
.equiv o_SoundChannel_er, 10
.equiv o_SoundChannel_el, 11
.equiv o_SoundChannel_iev, 12
.equiv o_SoundChannel_iel, 13
.equiv o_SoundChannel_d1, 14
.equiv o_SoundChannel_d2, 15
.equiv o_SoundChannel_gt, 16
.equiv o_SoundChannel_mk, 17
.equiv o_SoundChannel_ve, 18
.equiv o_SoundChannel_pr, 19
.equiv o_SoundChannel_d3, 20
.equiv o_SoundChannel_ct, 24
.equiv o_SoundChannel_fw, 28
.equiv o_SoundChannel_freq, 32
.equiv o_SoundChannel_wav, 36
.equiv o_SoundChannel_cp, 40
.equiv o_SoundChannel_track, 44
.equiv o_SoundChannel_pp, 48
.equiv o_SoundChannel_np, 52
.equiv o_SoundChannel_d4, 56
.equiv o_SoundChannel_xpi, 60
.equiv o_SoundChannel_xpc, 62
.macro struct_field name, size .equiv SoundChannel_size, 64
\name:
.struct \name + \size
.endm
struct_begin .equiv o_SoundInfo_ident, 0
struct_field o_SoundInfo_ident, 4 .equiv o_SoundInfo_pcmDmaCounter, 4
struct_field o_SoundInfo_pcmDmaCounter, 1 .equiv o_SoundInfo_reverb, 5
struct_field o_SoundInfo_reverb, 1 .equiv o_SoundInfo_maxChans, 6
struct_field o_SoundInfo_maxChans, 1 .equiv o_SoundInfo_masterVolume, 7
struct_field o_SoundInfo_masterVolume, 1 .equiv o_SoundInfo_freq, 8
struct_field o_SoundInfo_freq, 1 .equiv o_SoundInfo_mode, 9
struct_field o_SoundInfo_mode, 1 .equiv o_SoundInfo_c15, 10
struct_field o_SoundInfo_c15, 1 .equiv o_SoundInfo_pcmDmaPeriod, 11
struct_field o_SoundInfo_pcmDmaPeriod, 1 .equiv o_SoundInfo_maxLines, 12
struct_field o_SoundInfo_maxLines, 1 .equiv o_SoundInfo_gap, 13
struct_field o_SoundInfo_gap, 3 .equiv o_SoundInfo_pcmSamplesPerVBlank, 16
struct_field o_SoundInfo_pcmSamplesPerVBlank, 4 .equiv o_SoundInfo_pcmFreq, 20
struct_field o_SoundInfo_pcmFreq, 4 .equiv o_SoundInfo_divFreq, 24
struct_field o_SoundInfo_divFreq, 4 .equiv o_SoundInfo_cgbChans, 28
struct_field o_SoundInfo_cgbChans, 4 .equiv o_SoundInfo_func, 32
struct_field o_SoundInfo_func, 4 .equiv o_SoundInfo_intp, 36
struct_field o_SoundInfo_intp, 4 .equiv o_SoundInfo_CgbSound, 40
struct_field o_SoundInfo_CgbSound, 4 .equiv o_SoundInfo_CgbOscOff, 44
struct_field o_SoundInfo_CgbOscOff, 4 .equiv o_SoundInfo_MidiKeyToCgbFreq, 48
struct_field o_SoundInfo_MidiKeyToCgbFreq, 4 .equiv o_SoundInfo_MPlayJumpTable, 52
struct_field o_SoundInfo_MPlayJumpTable, 4 .equiv o_SoundInfo_plynote, 56
struct_field o_SoundInfo_plynote, 4 .equiv o_SoundInfo_ExtVolPit, 60
struct_field o_SoundInfo_ExtVolPit, 4 .equiv o_SoundInfo_gap2, 64
struct_field o_SoundInfo_gap2, 16 .equiv o_SoundInfo_chans, 80
struct_field o_SoundInfo_chans, 768 .equiv o_SoundInfo_pcmBuffer, o_SoundInfo_chans + (SoundChannel_size * 12)
struct_field o_SoundInfo_pcmBuffer, PCM_DMA_BUF_SIZE * 2
struct_field SoundInfo_size, 0
struct_begin .equiv o_MusicPlayerTrack_flags, 0
struct_field o_SoundChannel_status, 1 .equiv o_MusicPlayerTrack_wait, 1
struct_field o_SoundChannel_type, 1 .equiv o_MusicPlayerTrack_patternLevel, 2
struct_field o_SoundChannel_rightVolume, 1 .equiv o_MusicPlayerTrack_repN, 3
struct_field o_SoundChannel_leftVolume, 1 .equiv o_MusicPlayerTrack_gateTime, 4
struct_field o_SoundChannel_attack, 1 .equiv o_MusicPlayerTrack_key, 5
struct_field o_SoundChannel_decay, 1 .equiv o_MusicPlayerTrack_velocity, 6
struct_field o_SoundChannel_sustain, 1 .equiv o_MusicPlayerTrack_runningStatus, 7
struct_field o_SoundChannel_release, 1 .equiv o_MusicPlayerTrack_keyM, 8
struct_field o_SoundChannel_ky, 1 .equiv o_MusicPlayerTrack_pitM, 9
struct_field o_SoundChannel_ev, 1 .equiv o_MusicPlayerTrack_keyShift, 10
struct_field o_SoundChannel_er, 1 .equiv o_MusicPlayerTrack_keyShiftX, 11
struct_field o_SoundChannel_el, 1 .equiv o_MusicPlayerTrack_tune, 12
struct_field o_SoundChannel_iev, 1 .equiv o_MusicPlayerTrack_pitX, 13
struct_field o_SoundChannel_iel, 1 .equiv o_MusicPlayerTrack_bend, 14
struct_field o_SoundChannel_d1, 1 .equiv o_MusicPlayerTrack_bendRange, 15
struct_field o_SoundChannel_d2, 1 .equiv o_MusicPlayerTrack_volMR, 16
struct_field o_SoundChannel_gt, 1 .equiv o_MusicPlayerTrack_volML, 17
struct_field o_SoundChannel_mk, 1 .equiv o_MusicPlayerTrack_vol, 18
struct_field o_SoundChannel_ve, 1 .equiv o_MusicPlayerTrack_volX, 19
struct_field o_SoundChannel_pr, 1 .equiv o_MusicPlayerTrack_pan, 20
struct_field o_SoundChannel_rp, 1 .equiv o_MusicPlayerTrack_panX, 21
struct_field o_SoundChannel_d3, 3 .equiv o_MusicPlayerTrack_modM, 22
struct_field o_SoundChannel_ct, 4 .equiv o_MusicPlayerTrack_mod, 23
struct_field o_SoundChannel_fw, 4 .equiv o_MusicPlayerTrack_modT, 24
struct_field o_SoundChannel_freq, 4 .equiv o_MusicPlayerTrack_lfoSpeed, 25
struct_field o_SoundChannel_wav, 4 .equiv o_MusicPlayerTrack_lfoSpeedC, 26
struct_field o_SoundChannel_cp, 4 .equiv o_MusicPlayerTrack_lfoDelay, 27
struct_field o_SoundChannel_track, 4 .equiv o_MusicPlayerTrack_lfoDelayC, 28
struct_field o_SoundChannel_pp, 4 .equiv o_MusicPlayerTrack_priority, 29
struct_field o_SoundChannel_np, 4 .equiv o_MusicPlayerTrack_echoVolume, 30
struct_field o_SoundChannel_d4, 4 .equiv o_MusicPlayerTrack_echoLength, 31
struct_field o_SoundChannel_xpi, 2 .equiv o_MusicPlayerTrack_chan, 32
struct_field o_SoundChannel_xpc, 2 .equiv o_MusicPlayerTrack_ToneData_type, 36
struct_field SoundChannel_size, 0 .equiv o_MusicPlayerTrack_ToneData_key, 37
.equiv o_MusicPlayerTrack_ToneData_length, 38
struct_begin .equiv o_MusicPlayerTrack_ToneData_pan_sweep, 39
struct_field o_MusicPlayerTrack_flags, 1 .equiv o_MusicPlayerTrack_ToneData_wav, 40
struct_field o_MusicPlayerTrack_wait, 1 .equiv o_MusicPlayerTrack_ToneData_attack, 44
struct_field o_MusicPlayerTrack_patternLevel, 1 .equiv o_MusicPlayerTrack_ToneData_decay, 45
struct_field o_MusicPlayerTrack_repN, 1 .equiv o_MusicPlayerTrack_ToneData_sustain, 46
struct_field o_MusicPlayerTrack_gateTime, 1 .equiv o_MusicPlayerTrack_ToneData_release, 47
struct_field o_MusicPlayerTrack_key, 1 .equiv o_MusicPlayerTrack_gap, 48
struct_field o_MusicPlayerTrack_velocity, 1 .equiv o_MusicPlayerTrack_unk_3A, 58
struct_field o_MusicPlayerTrack_runningStatus, 1 .equiv o_MusicPlayerTrack_unk_3C, 60
struct_field o_MusicPlayerTrack_keyM, 1 .equiv o_MusicPlayerTrack_cmdPtr, 64
struct_field o_MusicPlayerTrack_pitM, 1 .equiv o_MusicPlayerTrack_patternStack, 68
struct_field o_MusicPlayerTrack_keyShift, 1 .equiv MusicPlayerTrack_size, 80
struct_field o_MusicPlayerTrack_keyShiftX, 1
struct_field o_MusicPlayerTrack_tune, 1
struct_field o_MusicPlayerTrack_pitX, 1
struct_field o_MusicPlayerTrack_bend, 1
struct_field o_MusicPlayerTrack_bendRange, 1
struct_field o_MusicPlayerTrack_volMR, 1
struct_field o_MusicPlayerTrack_volML, 1
struct_field o_MusicPlayerTrack_vol, 1
struct_field o_MusicPlayerTrack_volX, 1
struct_field o_MusicPlayerTrack_pan, 1
struct_field o_MusicPlayerTrack_panX, 1
struct_field o_MusicPlayerTrack_modM, 1
struct_field o_MusicPlayerTrack_mod, 1
struct_field o_MusicPlayerTrack_modT, 1
struct_field o_MusicPlayerTrack_lfoSpeed, 1
struct_field o_MusicPlayerTrack_lfoSpeedC, 1
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_chan, 4
struct_field o_MusicPlayerTrack_ToneData_type, 1
struct_field o_MusicPlayerTrack_ToneData_key, 1
struct_field o_MusicPlayerTrack_ToneData_length, 1
struct_field o_MusicPlayerTrack_ToneData_pan_sweep, 1
struct_field o_MusicPlayerTrack_ToneData_wav, 4
struct_field o_MusicPlayerTrack_ToneData_attack, 1
struct_field o_MusicPlayerTrack_ToneData_decay, 1
struct_field o_MusicPlayerTrack_ToneData_sustain, 1
struct_field o_MusicPlayerTrack_ToneData_release, 1
struct_field o_MusicPlayerTrack_gap, 10
struct_field o_MusicPlayerTrack_unk_3A, 2
struct_field o_MusicPlayerTrack_unk_3C, 4
struct_field o_MusicPlayerTrack_cmdPtr, 4
struct_field o_MusicPlayerTrack_patternStack, 12
struct_field MusicPlayerTrack_size, 0
.equiv o_MusicPlayerTrack_ToneData_keySplitTable, o_MusicPlayerTrack_ToneData_attack .equiv o_MusicPlayerTrack_ToneData_keySplitTable, o_MusicPlayerTrack_ToneData_attack
struct_begin .equiv o_MusicPlayerInfo_songHeader, 0
struct_field o_MusicPlayerInfo_songHeader, 4 .equiv o_MusicPlayerInfo_status, 4
struct_field o_MusicPlayerInfo_status, 4 .equiv o_MusicPlayerInfo_trackCount, 8
struct_field o_MusicPlayerInfo_trackCount, 1 .equiv o_MusicPlayerInfo_priority, 9
struct_field o_MusicPlayerInfo_priority, 1 .equiv o_MusicPlayerInfo_cmd, 10
struct_field o_MusicPlayerInfo_cmd, 1 .equiv o_MusicPlayerInfo_unk_B, 11
struct_field o_MusicPlayerInfo_unk_B, 1 .equiv o_MusicPlayerInfo_clock, 12
struct_field o_MusicPlayerInfo_clock, 4 .equiv o_MusicPlayerInfo_memAccArea, 16
struct_field o_MusicPlayerInfo_gap, 8 .equiv o_MusicPlayerInfo_tempoD, 28
struct_field o_MusicPlayerInfo_memAccArea, 4 .equiv o_MusicPlayerInfo_tempoU, 30
struct_field o_MusicPlayerInfo_tempoD, 2 .equiv o_MusicPlayerInfo_tempoI, 32
struct_field o_MusicPlayerInfo_tempoU, 2 .equiv o_MusicPlayerInfo_tempoC, 34
struct_field o_MusicPlayerInfo_tempoI, 2 .equiv o_MusicPlayerInfo_fadeOI, 36
struct_field o_MusicPlayerInfo_tempoC, 2 .equiv o_MusicPlayerInfo_fadeOC, 38
struct_field o_MusicPlayerInfo_fadeOI, 2 .equiv o_MusicPlayerInfo_fadeOV, 40
struct_field o_MusicPlayerInfo_fadeOC, 2 .equiv o_MusicPlayerInfo_padding, 42
struct_field o_MusicPlayerInfo_fadeOV, 2 .equiv o_MusicPlayerInfo_tracks, 44
struct_field o_MusicPlayerInfo_padding, 2 .equiv o_MusicPlayerInfo_tone, 48
struct_field o_MusicPlayerInfo_tracks, 4 .equiv o_MusicPlayerInfo_ident, 52
struct_field o_MusicPlayerInfo_tone, 4 .equiv o_MusicPlayerInfo_func, 56
struct_field o_MusicPlayerInfo_ident, 4 .equiv o_MusicPlayerInfo_intp, 60
struct_field o_MusicPlayerInfo_func, 4 .equiv MusicPlayerInfo_size, 64
struct_field o_MusicPlayerInfo_intp, 4
struct_field MusicPlayerInfo_size, 0
struct_begin .equiv o_CgbChannel_sf, 0
struct_field o_CgbChannel_sf, 1 .equiv o_CgbChannel_ty, 1
struct_field o_CgbChannel_ty, 1 .equiv o_CgbChannel_rightVolume, 2
struct_field o_CgbChannel_rightVolume, 1 .equiv o_CgbChannel_leftVolume, 3
struct_field o_CgbChannel_leftVolume, 1 .equiv o_CgbChannel_at, 4
struct_field o_CgbChannel_at, 1 .equiv o_CgbChannel_de, 5
struct_field o_CgbChannel_de, 1 .equiv o_CgbChannel_su, 6
struct_field o_CgbChannel_su, 1 .equiv o_CgbChannel_re, 7
struct_field o_CgbChannel_re, 1 .equiv o_CgbChannel_ky, 8
struct_field o_CgbChannel_ky, 1 .equiv o_CgbChannel_ev, 9
struct_field o_CgbChannel_ev, 1 .equiv o_CgbChannel_eg, 10
struct_field o_CgbChannel_eg, 1 .equiv o_CgbChannel_ec, 11
struct_field o_CgbChannel_ec, 1 .equiv o_CgbChannel_echoVolume, 12
struct_field o_CgbChannel_echoVolume, 1 .equiv o_CgbChannel_echoLength, 13
struct_field o_CgbChannel_echoLength, 1 .equiv o_CgbChannel_d1, 14
struct_field o_CgbChannel_d1, 1 .equiv o_CgbChannel_d2, 15
struct_field o_CgbChannel_d2, 1 .equiv o_CgbChannel_gt, 16
struct_field o_CgbChannel_gt, 1 .equiv o_CgbChannel_mk, 17
struct_field o_CgbChannel_mk, 1 .equiv o_CgbChannel_ve, 18
struct_field o_CgbChannel_ve, 1 .equiv o_CgbChannel_pr, 19
struct_field o_CgbChannel_pr, 1 .equiv o_CgbChannel_d3, 20
struct_field o_CgbChannel_rp, 1 .equiv o_CgbChannel_d5, 24
struct_field o_CgbChannel_d3, 3 .equiv o_CgbChannel_sg, 25
struct_field o_CgbChannel_d5, 1 .equiv o_CgbChannel_n4, 26
struct_field o_CgbChannel_sg, 1 .equiv o_CgbChannel_pan, 27
struct_field o_CgbChannel_n4, 1 .equiv o_CgbChannel_panMask, 28
struct_field o_CgbChannel_pan, 1 .equiv o_CgbChannel_mo, 29
struct_field o_CgbChannel_panMask, 1 .equiv o_CgbChannel_le, 30
struct_field o_CgbChannel_mo, 1 .equiv o_CgbChannel_sw, 31
struct_field o_CgbChannel_le, 1 .equiv o_CgbChannel_fr, 32
struct_field o_CgbChannel_sw, 1 .equiv o_CgbChannel_wp, 36
struct_field o_CgbChannel_fr, 4 .equiv o_CgbChannel_cp, 40
struct_field o_CgbChannel_wp, 4 .equiv o_CgbChannel_tp, 44
struct_field o_CgbChannel_cp, 4 .equiv o_CgbChannel_pp, 48
struct_field o_CgbChannel_tp, 4 .equiv o_CgbChannel_np, 52
struct_field o_CgbChannel_pp, 4 .equiv o_CgbChannel_d4, 56
struct_field o_CgbChannel_np, 4 .equiv CgbChannel_size, 64
struct_field o_CgbChannel_d4, 8
struct_field CgbChannel_size, 0

View File

@ -140,55 +140,13 @@ struct SoundChannel
struct WaveData *wav; struct WaveData *wav;
u32 cp; u32 cp;
struct MusicPlayerTrack *track; struct MusicPlayerTrack *track;
u32 pp; void* pp;
u32 np; void* np;
u32 d4; void* d4;
u16 xpi; u16 xpi;
u16 xpc; u16 xpc;
}; };
#define MAX_DIRECTSOUND_CHANNELS 12
#define PCM_DMA_BUF_SIZE 1584 // size of Direct Sound buffer
struct SoundInfo
{
// This field is normally equal to ID_NUMBER but it is set to other
// values during sensitive operations for locking purposes.
// This field should be volatile but isn't. This could potentially cause
// race conditions.
u32 ident;
vu8 pcmDmaCounter;
// Direct Sound
u8 reverb;
u8 maxChans;
u8 masterVolume;
u8 freq;
u8 mode;
u8 c15;
u8 pcmDmaPeriod; // number of V-blanks per PCM DMA
u8 maxLines;
u8 gap[3];
s32 pcmSamplesPerVBlank;
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;
u8 gap2[16];
struct SoundChannel chans[MAX_DIRECTSOUND_CHANNELS];
s8 pcmBuffer[PCM_DMA_BUF_SIZE * 2];
};
struct SongHeader struct SongHeader
{ {
u8 trackCount; u8 trackCount;
@ -312,7 +270,7 @@ struct MusicPlayerInfo
struct MusicPlayerTrack *tracks; struct MusicPlayerTrack *tracks;
struct ToneData *tone; struct ToneData *tone;
u32 ident; u32 ident;
u32 func; void (*func)();
u32 intp; u32 intp;
}; };
@ -334,7 +292,47 @@ struct Song
extern const struct MusicPlayer gMPlayTable[]; extern const struct MusicPlayer gMPlayTable[];
extern const struct Song gSongTable[]; extern const struct Song gSongTable[];
#define MAX_DIRECTSOUND_CHANNELS 12
#define PCM_DMA_BUF_SIZE 1584 // size of Direct Sound buffer
struct SoundInfo
{
// This field is normally equal to ID_NUMBER but it is set to other
// values during sensitive operations for locking purposes.
// This field should be volatile but isn't. This could potentially cause
// race conditions.
u32 ident;
vu8 pcmDmaCounter;
// Direct Sound
u8 reverb;
u8 maxChans;
u8 masterVolume;
u8 freq;
u8 mode;
u8 c15;
u8 pcmDmaPeriod; // number of V-blanks per PCM DMA
u8 maxLines;
u8 gap[3];
s32 pcmSamplesPerVBlank;
s32 pcmFreq;
s32 divFreq;
struct CgbChannel *cgbChans;
void (*func)();
u32 intp;
void (*CgbSound)();
void (*CgbOscOff)(u8);
u32 (*MidiKeyToCgbFreq)(u8, u8, u8);
void (**MPlayJumpTable)();
void (*plynote)(u8, struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void (*ExtVolPit)(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
u32 gap2[4];
struct SoundChannel chans[MAX_DIRECTSOUND_CHANNELS];
s8 pcmBuffer[PCM_DMA_BUF_SIZE * 2];
};
extern u8 gMPlayMemAccArea[]; extern u8 gMPlayMemAccArea[];
@ -448,7 +446,7 @@ void ply_tune(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_port(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_port(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_xcmd(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_xcmd(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_endtie(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_endtie(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
void ply_note(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_note(u8, struct MusicPlayerInfo *, struct MusicPlayerTrack *);
// extended sound command handler functions // extended sound command handler functions
void ply_xxx(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_xxx(struct MusicPlayerInfo *, struct MusicPlayerTrack *);

View File

@ -1,9 +1,12 @@
.include "../constants/gba_constants.inc" .include "../constants/gba_constants.inc"
.include "../asm/macros/function.inc" .include "../asm/macros/function.inc"
.syntax unified
.text .text
.set SOFT_RESET_DIRECT_BUF, 0x03007FFA .set SOFT_RESET_DIRECT_BUF, 0x03007FFA
.set USER_STACK, 0x03007F00
.set RESET_EX_WRAM_FLAG, 0x1 .set RESET_EX_WRAM_FLAG, 0x1
.ifdef NO_GRANULAR_AGBSYSCALL .ifdef NO_GRANULAR_AGBSYSCALL
@ -106,7 +109,7 @@ SoundDriverVSyncOn:
thumb_func_start Mod thumb_func_start Mod
Mod: Mod:
svc #6 svc #6
mov r0, r1 adds r0, r1, #0
bx lr bx lr
thumb_func_end Mod thumb_func_end Mod
.endif .endif
@ -145,7 +148,7 @@ HuffUnComp:
.endif .endif
.ifdef L_SoftResetExram .ifdef L_SoftResetExram
arm_func_start SoftResetExram thumb_func_start SoftResetExram
SoftResetExram: SoftResetExram:
ldr r3, =REG_IME ldr r3, =REG_IME
movs r2, #0 movs r2, #0
@ -153,14 +156,14 @@ SoftResetExram:
ldr r3, =SOFT_RESET_DIRECT_BUF ldr r3, =SOFT_RESET_DIRECT_BUF
movs r2, #1 movs r2, #1
strb r2, [r3, #0] strb r2, [r3, #0]
subs r3, #SOFT_RESET_DIRECT_BUF - 0x3007f00 subs r3, #SOFT_RESET_DIRECT_BUF - USER_STACK
mov sp, r3 mov sp, r3
movs r2, #RESET_EX_WRAM_FLAG movs r2, #RESET_EX_WRAM_FLAG
bics r0, r2 bics r0, r2
svc #1 svc #1
svc #0 svc #0
.pool .pool
arm_func_end SoftResetExram thumb_func_end SoftResetExram
.endif .endif
.ifdef L_MusicPlayerFadeOut .ifdef L_MusicPlayerFadeOut
@ -231,7 +234,7 @@ DivArm:
thumb_func_start ModArm thumb_func_start ModArm
ModArm: ModArm:
svc #7 svc #7
mov r0, r1 adds r0, r1, #0
bx lr bx lr
thumb_func_end ModArm thumb_func_end ModArm
.endif .endif
@ -271,7 +274,7 @@ Diff8bitUnFilterWram:
.ifdef L_MultiBoot .ifdef L_MultiBoot
thumb_func_start MultiBoot thumb_func_start MultiBoot
MultiBoot: MultiBoot:
mov r1, #1 movs r1, #1
svc #37 svc #37
bx lr bx lr
thumb_func_end MultiBoot thumb_func_end MultiBoot
@ -326,7 +329,7 @@ SoftResetRom:
ldr r3, =SOFT_RESET_DIRECT_BUF ldr r3, =SOFT_RESET_DIRECT_BUF
movs r2, #0 movs r2, #0
strb r2, [r3, #0] strb r2, [r3, #0]
sub r3, #SOFT_RESET_DIRECT_BUF - 0x3007f00 subs r3, #SOFT_RESET_DIRECT_BUF - USER_STACK
mov sp, r3 mov sp, r3
svc #1 svc #1
svc #0 svc #0
@ -413,7 +416,7 @@ SoftReset:
ldr r3, =REG_IME ldr r3, =REG_IME
movs r2, #0 movs r2, #0
strb r2, [r3, #0] strb r2, [r3, #0]
ldr r1, =0x3007f00 ldr r1, =USER_STACK
mov sp, r1 mov sp, r1
svc #1 svc #1
svc #0 svc #0

View File

@ -352,7 +352,7 @@ static bool8 rfu_LMAN_linkWatcher(u16 REQ_commandID)
{ {
for (i = 0; i < RFU_CHILD_MAX; i++) for (i = 0; i < RFU_CHILD_MAX; i++)
{ {
if ((bm_linkLossSlot >> i) & 1) if ((bm_linkLossSlot) & (1 << i))
{ {
lman.linkRecoveryTimer.active |= (1 << i); lman.linkRecoveryTimer.active |= (1 << i);
lman.linkRecoveryTimer.count[i] = lman.linkRecoveryTimer.count_max; lman.linkRecoveryTimer.count[i] = lman.linkRecoveryTimer.count_max;
@ -396,7 +396,7 @@ static bool8 rfu_LMAN_linkWatcher(u16 REQ_commandID)
bm_disconnectSlot = 0; bm_disconnectSlot = 0;
for (i = 0; i < RFU_CHILD_MAX; i++) for (i = 0; i < RFU_CHILD_MAX; i++)
{ {
if ((lman.linkRecoveryTimer.active >> i) & 1 && lman.linkRecoveryTimer.count[i] && --lman.linkRecoveryTimer.count[i] == 0) if ((lman.linkRecoveryTimer.active) & (1 << i) && lman.linkRecoveryTimer.count[i] && --lman.linkRecoveryTimer.count[i] == 0)
{ {
lman.linkRecoveryTimer.active &= ~(1 << i); lman.linkRecoveryTimer.active &= ~(1 << i);
bm_disconnectSlot |= (1 << i); bm_disconnectSlot |= (1 << i);

111
src/m4a.c
View File

@ -22,8 +22,7 @@ u8 gMPlayMemAccArea[0x10];
u32 MidiKeyToFreq(struct WaveData *wav, u8 key, u8 fineAdjust) u32 MidiKeyToFreq(struct WaveData *wav, u8 key, u8 fineAdjust)
{ {
u32 val1; u32 val1, val2;
u32 val2;
u32 fineAdjustShifted = fineAdjust << 24; u32 fineAdjustShifted = fineAdjust << 24;
if (key > 178) if (key > 178)
@ -315,7 +314,7 @@ void MPlayExtender(struct CgbChannel *cgbChans)
void MusicPlayerJumpTableCopy(void) void MusicPlayerJumpTableCopy(void)
{ {
asm("swi 0x2A"); asm("svc 0x2A");
} }
void ClearChain(void *x) void ClearChain(void *x)
@ -352,25 +351,25 @@ void SoundInit(struct SoundInfo *soundInfo)
| SOUND_ALL_MIX_FULL; | SOUND_ALL_MIX_FULL;
REG_SOUNDBIAS_H = (REG_SOUNDBIAS_H & 0x3F) | 0x40; REG_SOUNDBIAS_H = (REG_SOUNDBIAS_H & 0x3F) | 0x40;
REG_DMA1SAD = (s32)soundInfo->pcmBuffer; REG_DMA1SAD = (u32)soundInfo->pcmBuffer;
REG_DMA1DAD = (s32)&REG_FIFO_A; REG_DMA1DAD = (u32)&REG_FIFO_A;
REG_DMA2SAD = (s32)soundInfo->pcmBuffer + PCM_DMA_BUF_SIZE; REG_DMA2SAD = (u32)soundInfo->pcmBuffer + PCM_DMA_BUF_SIZE;
REG_DMA2DAD = (s32)&REG_FIFO_B; REG_DMA2DAD = (u32)&REG_FIFO_B;
SOUND_INFO_PTR = soundInfo; SOUND_INFO_PTR = soundInfo;
CpuFill32(0, soundInfo, sizeof(struct SoundInfo)); CpuFill32(0, soundInfo, sizeof(struct SoundInfo));
soundInfo->maxChans = 8; soundInfo->maxChans = 8;
soundInfo->masterVolume = 15; soundInfo->masterVolume = 15;
soundInfo->plynote = (u32)ply_note; soundInfo->plynote = ply_note;
soundInfo->CgbSound = DummyFunc; soundInfo->CgbSound = DummyFunc;
soundInfo->CgbOscOff = (void (*)(u8))DummyFunc; soundInfo->CgbOscOff = (void (*)(u8))DummyFunc;
soundInfo->MidiKeyToCgbFreq = (u32 (*)(u8, u8, u8))DummyFunc; soundInfo->MidiKeyToCgbFreq = (u32 (*)(u8, u8, u8))DummyFunc;
soundInfo->ExtVolPit = (u32)DummyFunc; soundInfo->ExtVolPit = (void (*)(struct MusicPlayerInfo *, struct MusicPlayerTrack *))DummyFunc;
MPlayJumpTableCopy(gMPlayJumpTable); MPlayJumpTableCopy(gMPlayJumpTable);
soundInfo->MPlayJumpTable = (u32)gMPlayJumpTable; soundInfo->MPlayJumpTable = (void (**)())gMPlayJumpTable;
SampleFreqSet(SOUND_MODE_FREQ_13379); SampleFreqSet(SOUND_MODE_FREQ_13379);
@ -381,7 +380,7 @@ void SampleFreqSet(u32 freq)
{ {
struct SoundInfo *soundInfo = SOUND_INFO_PTR; struct SoundInfo *soundInfo = SOUND_INFO_PTR;
freq = (freq & 0xF0000) >> 16; freq = (freq & SOUND_MODE_FREQ) >> SOUND_MODE_FREQ_SHIFT;
soundInfo->freq = freq; soundInfo->freq = freq;
soundInfo->pcmSamplesPerVBlank = gPcmSamplesPerVBlankTable[freq - 1]; soundInfo->pcmSamplesPerVBlank = gPcmSamplesPerVBlankTable[freq - 1];
soundInfo->pcmDmaPeriod = PCM_DMA_BUF_SIZE / soundInfo->pcmSamplesPerVBlank; soundInfo->pcmDmaPeriod = PCM_DMA_BUF_SIZE / soundInfo->pcmSamplesPerVBlank;
@ -433,13 +432,10 @@ void m4aSoundMode(u32 mode)
soundInfo->maxChans = temp >> SOUND_MODE_MAXCHN_SHIFT; soundInfo->maxChans = temp >> SOUND_MODE_MAXCHN_SHIFT;
temp = MAX_DIRECTSOUND_CHANNELS; temp = MAX_DIRECTSOUND_CHANNELS;
chan = &soundInfo->chans[0];
while (temp != 0) for (temp = MAX_DIRECTSOUND_CHANNELS, chan = soundInfo->chans; temp != 0; temp--,chan++)
{ {
chan->status = 0; chan->status = 0;
temp--;
chan++;
} }
} }
@ -469,37 +465,28 @@ void m4aSoundMode(u32 mode)
void SoundClear(void) void SoundClear(void)
{ {
struct SoundInfo *soundInfo = SOUND_INFO_PTR;
s32 i; s32 i;
void *chan; struct SoundInfo *soundInfo = SOUND_INFO_PTR;
struct SoundChannel *chan;
if (soundInfo->ident != ID_NUMBER) if (soundInfo->ident != ID_NUMBER)
return; return;
soundInfo->ident++; soundInfo->ident++;
i = MAX_DIRECTSOUND_CHANNELS; for (i = MAX_DIRECTSOUND_CHANNELS, chan = soundInfo->chans; i > 0; i--,chan++)
chan = &soundInfo->chans[0];
while (i > 0)
{ {
((struct SoundChannel *)chan)->status = 0; chan->status = 0;
i--;
chan = (void *)((s32)chan + sizeof(struct SoundChannel));
} }
chan = soundInfo->cgbChans; chan = (struct SoundChannel *)soundInfo->cgbChans;
if (chan) if (chan)
{ {
i = 1; for (i=1; i<=4; i++,chan++)
while (i <= 4)
{ {
soundInfo->CgbOscOff(i); soundInfo->CgbOscOff(i);
((struct CgbChannel *)chan)->sf = 0; chan->status = 0;
i++;
chan = (void *)((s32)chan + sizeof(struct CgbChannel));
} }
} }
@ -510,27 +497,26 @@ void m4aSoundVSyncOff(void)
{ {
struct SoundInfo *soundInfo = SOUND_INFO_PTR; struct SoundInfo *soundInfo = SOUND_INFO_PTR;
if (soundInfo->ident >= ID_NUMBER && soundInfo->ident <= ID_NUMBER + 1) if (soundInfo->ident < ID_NUMBER || soundInfo->ident > ID_NUMBER + 1)
{ return;
soundInfo->ident += 10; soundInfo->ident += 10;
if (REG_DMA1CNT & (DMA_REPEAT << 16)) if (REG_DMA1CNT & (DMA_REPEAT << 16))
REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4;
if (REG_DMA2CNT & (DMA_REPEAT << 16)) if (REG_DMA2CNT & (DMA_REPEAT << 16))
REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4;
REG_DMA1CNT_H = DMA_32BIT; REG_DMA1CNT_H = DMA_32BIT;
REG_DMA2CNT_H = DMA_32BIT; REG_DMA2CNT_H = DMA_32BIT;
CpuFill32(0, soundInfo->pcmBuffer, sizeof(soundInfo->pcmBuffer)); CpuFill32(0, soundInfo->pcmBuffer, sizeof(soundInfo->pcmBuffer));
}
} }
void m4aSoundVSyncOn(void) void m4aSoundVSyncOn(void)
{ {
struct SoundInfo *soundInfo = SOUND_INFO_PTR; struct SoundInfo *soundInfo = SOUND_INFO_PTR;
u32 ident = soundInfo->ident; const u32 ident = soundInfo->ident;
if (ident == ID_NUMBER) if (ident == ID_NUMBER)
return; return;
@ -580,7 +566,7 @@ void MPlayOpen(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track
} }
soundInfo->intp = (u32)mplayInfo; soundInfo->intp = (u32)mplayInfo;
soundInfo->func = (u32)MPlayMain; soundInfo->func = MPlayMain;
soundInfo->ident = ID_NUMBER; soundInfo->ident = ID_NUMBER;
mplayInfo->ident = ID_NUMBER; mplayInfo->ident = ID_NUMBER;
} }
@ -614,28 +600,21 @@ void MPlayStart(struct MusicPlayerInfo *mplayInfo, struct SongHeader *songHeader
mplayInfo->tempoC = 0; mplayInfo->tempoC = 0;
mplayInfo->fadeOI = 0; mplayInfo->fadeOI = 0;
i = 0; for (i = 0, track = mplayInfo->tracks; i < songHeader->trackCount && i < mplayInfo->trackCount; i++, track++)
track = mplayInfo->tracks;
while (i < songHeader->trackCount && i < mplayInfo->trackCount)
{ {
TrackStop(mplayInfo, track); TrackStop(mplayInfo, track);
track->flags = MPT_FLG_EXIST | MPT_FLG_START; track->flags = MPT_FLG_EXIST | MPT_FLG_START;
track->chan = 0; track->chan = 0;
track->cmdPtr = songHeader->part[i]; track->cmdPtr = songHeader->part[i];
i++;
track++;
} }
while (i < mplayInfo->trackCount) for (; i < mplayInfo->trackCount; i++, track++)
{ {
TrackStop(mplayInfo, track); TrackStop(mplayInfo, track);
track->flags = 0; track->flags = 0;
i++;
track++;
} }
if (songHeader->reverb & 0x80) if (songHeader->reverb & SOUND_MODE_REVERB_SET)
m4aSoundMode(songHeader->reverb); m4aSoundMode(songHeader->reverb);
mplayInfo->ident = ID_NUMBER; mplayInfo->ident = ID_NUMBER;
@ -653,14 +632,9 @@ void m4aMPlayStop(struct MusicPlayerInfo *mplayInfo)
mplayInfo->ident++; mplayInfo->ident++;
mplayInfo->status |= MUSICPLAYER_STATUS_PAUSE; mplayInfo->status |= MUSICPLAYER_STATUS_PAUSE;
i = mplayInfo->trackCount; for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++)
track = mplayInfo->tracks;
while (i > 0)
{ {
TrackStop(mplayInfo, track); TrackStop(mplayInfo, track);
i--;
track++;
} }
mplayInfo->ident = ID_NUMBER; mplayInfo->ident = ID_NUMBER;
@ -704,10 +678,8 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo)
if ((s16)(mplayInfo->fadeOV & mask) <= 0) if ((s16)(mplayInfo->fadeOV & mask) <= 0)
{ {
i = mplayInfo->trackCount;
track = mplayInfo->tracks;
while (i > 0) for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++)
{ {
u32 val; u32 val;
@ -719,9 +691,6 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo)
if (!val) if (!val)
track->flags = 0; track->flags = 0;
i--;
track++;
} }
if (mplayInfo->fadeOV & TEMPORARY_FADE) if (mplayInfo->fadeOV & TEMPORARY_FADE)
@ -734,10 +703,7 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo)
} }
} }
i = mplayInfo->trackCount; for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++)
track = mplayInfo->tracks;
while (i > 0)
{ {
if (track->flags & MPT_FLG_EXIST) if (track->flags & MPT_FLG_EXIST)
{ {
@ -746,9 +712,6 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo)
track->volX = (fadeOV >> FADE_VOL_SHIFT); track->volX = (fadeOV >> FADE_VOL_SHIFT);
track->flags |= MPT_FLG_VOLCHG; track->flags |= MPT_FLG_VOLCHG;
} }
i--;
track++;
} }
} }
@ -756,7 +719,7 @@ void TrkVolPitSet(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tr
{ {
if (track->flags & MPT_FLG_VOLSET) if (track->flags & MPT_FLG_VOLSET)
{ {
s32 x; u32 x;
s32 y; s32 y;
x = (u32)(track->vol * track->volX) >> 5; x = (u32)(track->vol * track->volX) >> 5;