Match InitializeAudio

This commit is contained in:
y.demaisonregne 2023-05-22 19:39:24 +02:00
parent 2d1d9939bc
commit 27ec85d41f
7 changed files with 172 additions and 17 deletions

View File

@ -2,7 +2,7 @@
This is a work in progress decompilation of Metroid - Zero Mission.
2490/2721 functions decompiled (91.51%, 231 left)
2491/2721 functions decompiled (91.55%, 230 left)
Progress can be seen here : https://docs.google.com/spreadsheets/d/1X8XarD5evY8ZI7r_GQqh1pYmdVMbBcINYfRBUlogmKY/edit#gid=0
**This decomp is not shiftable, don't use it as a base to work on anything**

View File

@ -138,7 +138,7 @@ lbl_080011b4:
bne lbl_080011ba
b lbl_08001430
lbl_080011ba:
ldr r6, lbl_08001204 @ =gSoundData
ldr r6, lbl_08001204 @ =gMusicInfo+0xC24
mov r0, sl
adds r1, r0, r6
ldr r0, lbl_08001208 @ =0xfffff400
@ -174,14 +174,14 @@ lbl_080011f2:
str r1, [sp, #4]
b lbl_080013da
.align 2, 0
lbl_08001204: .4byte gSoundData
lbl_08001204: .4byte gMusicInfo+0xC24
lbl_08001208: .4byte 0xfffff400
lbl_0800120c: .4byte gSoundCodeBPointer
lbl_08001210: .4byte 0xfffff3dc
lbl_08001214:
movs r0, #0x34
muls r0, r2, r0
ldr r1, lbl_08001254 @ =gSoundChannels
ldr r1, lbl_08001254 @ =gMusicInfo+0x1824
adds r4, r0, r1
ldrb r0, [r4]
adds r2, #1
@ -214,7 +214,7 @@ lbl_0800123c:
str r0, [r4, #0x18]
b lbl_0800125e
.align 2, 0
lbl_08001254: .4byte gSoundChannels
lbl_08001254: .4byte gMusicInfo+0x1824
lbl_08001258: .4byte 0xffffe7dc
lbl_0800125c:
str r6, [r4, #0x18]
@ -438,7 +438,7 @@ lbl_080013f4:
bhs lbl_080013fc
b lbl_08001214
lbl_080013fc:
ldr r4, lbl_0800144c @ =gSoundData
ldr r4, lbl_0800144c @ =gMusicInfo+0xC24
mov r0, sl
adds r1, r0, r4
ldr r0, lbl_08001450 @ =0xfffff400
@ -475,7 +475,7 @@ lbl_08001430:
lbl_08001440: .4byte gMusicInfo
lbl_08001444: .4byte gSoundCodeAPointer
lbl_08001448: .4byte 0x04000006
lbl_0800144c: .4byte gSoundData
lbl_0800144c: .4byte gMusicInfo+0xC24
lbl_08001450: .4byte 0xfffff400
lbl_08001454: .4byte gSoundCodeCPointer
@ -1957,7 +1957,7 @@ lbl_08001eee:
mov r3, sl
adds r1, r0, r3
ldr r5, [r1]
ldr r1, lbl_08001f38 @ =gSoundChannels
ldr r1, lbl_08001f38 @ =gMusicInfo+0x1824
adds r6, r0, r1
lbl_08001f04:
adds r0, r2, #1
@ -1986,7 +1986,7 @@ lbl_08001f1e:
.align 2, 0
lbl_08001f30: .4byte gMusicInfo
lbl_08001f34: .4byte 0x00001826
lbl_08001f38: .4byte gSoundChannels
lbl_08001f38: .4byte gMusicInfo+0x1824
thumb_func_start sub_08001f3c
sub_08001f3c: @ 0x08001f3c
@ -3375,7 +3375,7 @@ sub_080028f4: @ 0x080028f4
movs r0, #0
mov sl, r0
str r0, [sp]
ldr r6, lbl_080029e8 @ =gSoundData
ldr r6, lbl_080029e8 @ =gMusicInfo+0xC24
ldr r2, lbl_080029ec @ =0x01000300
mov r0, sp
adds r1, r6, #0
@ -3470,7 +3470,7 @@ lbl_080029d8: .4byte 0x040000c4
lbl_080029dc: .4byte 0x84400004
lbl_080029e0: .4byte 0x040000c6
lbl_080029e4: .4byte 0x040000d2
lbl_080029e8: .4byte gSoundData
lbl_080029e8: .4byte gMusicInfo+0xC24
lbl_080029ec: .4byte 0x01000300
lbl_080029f0: .4byte 0xfffff3dc
lbl_080029f4: .4byte 0x0808cc60

View File

@ -20,6 +20,9 @@
#define REG_SOUNDCNT_L (REG_BASE + 0x80)
#define REG_SOUNDCNT_H (REG_BASE + 0x82)
#define REG_SOUNDCNT_X (REG_BASE + 0x84)
#define REG_SOUNDBIAS (REG_BASE + 0x88)
#define SOUNDCNT_RESTART_SOUND (1 << 15)
#endif /* GBA_AUDIO_H */

View File

@ -251,6 +251,7 @@ struct MusicInfo {
u16 musicTrackOnTransition;
u32 musicRawData[768];
u8 soundRawData[3072];
struct SoundChannel soundChannels[11];
};
@ -260,6 +261,8 @@ extern struct MusicTrackInfo gMusicTrackInfo;
extern struct MusicInfo gMusicInfo;
extern char gNumMusicPlayers[];
extern char gUnk_Audio0x64[];
extern char gUnk_Audio0x194F700[];
extern struct TrackData gTrackData0;
extern struct TrackData gTrackData1;
@ -285,4 +288,14 @@ extern struct TrackVariables gTrack6Variables[3];
extern struct TrackVariables gTrack7Variables[1];
extern struct TrackVariables gTrack8Variables[6];
// TODO type
extern void* gSoundCodeAPointer;
extern u8 gSoundCodeA[1624];
extern void* gSoundCodeBPointer;
extern u8 gSoundCodeB[164];
extern void* gSoundCodeCPointer;
extern u8 gSoundCodeC[176];
extern struct PSGSoundData gPsgSounds[4];
#endif

View File

@ -5,6 +5,8 @@ MEMORY {
}
gNumMusicPlayers = 9;
gUnk_Audio0x64 = 0x64;
gUnk_Audio0x194F700 = 0x194F700;
SECTIONS {
ewram (NOLOAD) : ALIGN(4) {
@ -239,9 +241,7 @@ SECTIONS {
. = 0x00001cf8; gSerialCommunicationCallback = .;
. = 0x00001cfc; gTimer3Callback = .;
. = 0x00001d00; gMusicInfo = .;
. = 0x00002924; gSoundData = .;
. = 0x00003524; gSoundChannels = .;
. = 0x0000376c; gUnk_300376c = .;
. = 0x00003794; gPsgSounds = .;
. = 0x00003834; gSoundChannelBackup = .;

View File

@ -1,9 +1,97 @@
#include "audio_wrappers.h"
#include "data/audio.h"
#include "gba.h"
#include "macros.h"
extern void call_soundcode_a(void);
extern void call_soundcode_b(void);
extern void call_soundcode_c(void);
/**
* @brief 2564 | 294 | Initializes the audio
*
*/
void InitializeAudio(void)
{
vu16 zero;
u8 i;
if (gMusicInfo.occupied)
return;
gMusicInfo.occupied = TRUE;
write16(REG_IE, read16(REG_IE) | IF_DMA2);
write8(REG_SOUNDCNT_X, 0x80);
write16(REG_SOUNDCNT_H, 0xA90E);
write8(REG_SOUNDBIAS + 1, (read8(REG_SOUNDBIAS + 1) & 0x3F) | 0x40);
write8(REG_BASE + 0x63, 0x8);
write8(REG_BASE + 0x65, 0x80);
write8(REG_BASE + 0x69, 0x8);
write8(REG_BASE + 0x6D, 0x80);
write8(REG_BASE + 0x79, 0x8);
write8(REG_BASE + 0x7D, 0x80);
write8(REG_SOUND3CNT_L, 0x0);
write8(REG_SOUNDCNT_L, 0x77);
gSoundCodeAPointer = gSoundCodeA + 1;
dma_set(3, call_soundcode_a, gSoundCodeA, DMA_ENABLE << 16 | sizeof(gSoundCodeA) / 2);
gSoundCodeBPointer = gSoundCodeB + 1;
dma_set(3, call_soundcode_b, gSoundCodeB, DMA_ENABLE << 16 | sizeof(gSoundCodeB) / 2);
gSoundCodeCPointer = gSoundCodeC + 1;
dma_set(3, call_soundcode_c, gSoundCodeC, DMA_ENABLE << 16 | sizeof(gSoundCodeC) / 2);
zero = 0;
dma_set(3, &zero, &gMusicInfo, (DMA_ENABLE | DMA_SRC_FIXED) << 16 | 0xE);
gMusicInfo.unknown_9 = (u8)gUnk_Audio0x64;
for (i = 0; i < 4; i++)
{
zero = 0;
dma_set(3, &zero, &gPsgSounds[i], (DMA_ENABLE | DMA_SRC_FIXED) << 16 | sizeof(struct PSGSoundData) / 2);
}
for (i = 0; i < (u16)gNumMusicPlayers; i++)
{
zero = 0;
dma_set(3, &zero, sMusicTrackDataROM[i].pTrack, (DMA_ENABLE | DMA_SRC_FIXED) << 16 | 0x16);
}
for (i = 0; i < (u16)gNumMusicPlayers; i++)
{
sMusicTrackDataROM[i].pTrack->pVariables = sMusicTrackDataROM[i].pVariables;
sMusicTrackDataROM[i].pTrack->maxAmountOfTracks = sMusicTrackDataROM[i].maxAmountOfTracks;
sMusicTrackDataROM[i].pTrack->unknown_1D = sMusicTrackDataROM[i].unknonw_A;
}
UpdateSOUNDCNT_H((u32)gUnk_Audio0x194F700);
for (i = 0; i < gMusicInfo.maxSoundChannels; i++)
{
zero = 0;
dma_set(3, &zero, &gMusicInfo.soundChannels[i], (DMA_ENABLE | DMA_SRC_FIXED) << 16 | sizeof(struct SoundChannel) / 2);
}
for (i = 0; i < ARRAY_SIZE(gSoundChannelBackup); i++)
{
zero = 0;
dma_set(3, &zero, &gSoundChannelBackup[i], (DMA_ENABLE | DMA_SRC_FIXED) << 16 | sizeof(struct SoundChannelBackup) / 2);
}
for (i = 0; i < (u16)gNumMusicPlayers; i++)
{
zero = 0;
dma_set(3, &zero, &gSoundQueue[i], (DMA_ENABLE | DMA_SRC_FIXED) << 16 | sizeof(struct SoundQueue) / 2);
}
gMusicInfo.occupied = FALSE;
}
void UpdateSOUNDCNT_H(u32 action)

View File

@ -305,13 +305,17 @@ void ApplySmoothMonochromeToPalette(u16* srcBase, u16* srcMonochrome, u16* dst,
{
colorMono = *srcMonochrome;
monoR = RED(colorMono);
monoG = (colorMono >> 5) & COLOR_MASK;
monoB = (colorMono >> 10) & COLOR_MASK;
colorMono >>= 5;
monoG = colorMono & COLOR_MASK;
colorMono >>= 5;
monoB = colorMono & COLOR_MASK;
colorBase = *srcBase;
baseR = RED(colorBase);
baseG = (colorBase >> 5) & COLOR_MASK;
baseB = (colorBase >> 10) & COLOR_MASK;
colorBase >>= 5;
baseG = colorBase & COLOR_MASK;
colorBase >>= 5;
baseB = colorBase & COLOR_MASK;
newR = (stage * (monoR - baseR) / 32);
newG = (stage * (monoG - baseG) / 32);
@ -329,7 +333,54 @@ void ApplySmoothMonochromeToPalette(u16* srcBase, u16* srcMonochrome, u16* dst,
void ApplySmoothPaletteTransition(u16* srcStart, u16* srcEnd, u16* dst, u8 stage)
{
i32 i;
i32 rEnd;
i32 gEnd;
i32 bEnd;
u8 r;
u8 g;
u8 b;
i32 color;
if (stage == 0)
{
DMATransfer(3, srcStart, dst, 16 * 2, 16);
return;
}
if (stage >= 0x1F)
{
DMATransfer(3, srcEnd, dst, 16 * 2, 16);
return;
}
for (i = 0; i <= 0x1F; )
{
color = *srcEnd;
rEnd = RED(color);
color >>= 5;
gEnd = color & COLOR_MASK;
color >>= 5;
bEnd = color & COLOR_MASK;
color = *srcStart;
r = RED(color);
color >>= 5;
g = color & COLOR_MASK;
color >>= 5;
b = color & COLOR_MASK;
r += (rEnd - r) * stage / 32;
g += (gEnd - g) * stage / 32;
b += (bEnd - b) * stage / 32;
*dst = COLOR(r, g, b);
i++;
srcStart++;
dst++;
srcEnd++;
}
}
void ApplySpecialBackgroundEffectColorOnBG(u16 mask, u16 color, u8 stage)