summaryrefslogtreecommitdiff
path: root/soh/src/code
diff options
context:
space:
mode:
Diffstat (limited to 'soh/src/code')
-rw-r--r--soh/src/code/audio_load.c20
-rw-r--r--soh/src/code/audio_playback.c8
-rw-r--r--soh/src/code/audio_seqplayer.c21
-rw-r--r--soh/src/code/code_800E4FE0.c2
-rw-r--r--soh/src/code/code_800EC960.c4
5 files changed, 32 insertions, 23 deletions
diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c
index 239e312f3..d7de0389a 100644
--- a/soh/src/code/audio_load.c
+++ b/soh/src/code/audio_load.c
@@ -300,7 +300,7 @@ void AudioLoad_InitSampleDmaBuffers(s32 arg0) {
// SOH [Port] Completely reworked from decomp: SAF custom fontIds can exceed the native table; bounds-check against
// fontMapSize to avoid OOB reads.
s32 AudioLoad_IsFontLoadComplete(s32 fontId) {
- if (fontId == 0xFF) {
+ if (fontId == FONT_ID_NONE) {
return true;
}
// Resolve indirection (identity for FONT_TABLE today, but kept for parity with other tables).
@@ -337,7 +337,7 @@ s32 AudioLoad_IsSampleLoadComplete(s32 sampleBankId) {
}
void AudioLoad_SetFontLoadStatus(s32 fontId, s32 status) {
- if ((fontId != 0xFF) && ((size_t)fontId < fontMapSize) && (gAudioContext.fontLoadStatus[fontId] != 5)) {
+ if ((fontId != FONT_ID_NONE) && ((size_t)fontId < fontMapSize) && (gAudioContext.fontLoadStatus[fontId] != 5)) {
gAudioContext.fontLoadStatus[fontId] = status;
}
}
@@ -395,7 +395,7 @@ SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) {
return NULL;
}
- fontId = 0xFF;
+ fontId = FONT_ID_NONE;
index = ((u16*)gAudioContext.sequenceFontTable)[seqId];
numFonts = gAudioContext.sequenceFontTable[index++];
@@ -490,7 +490,7 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret
AudioLoad_AsyncLoad(FONT_TABLE, fontId, 0, retData, retQueue);
}
-u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
+u16* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
s32 index;
// Check for NA_BGM_DISABLED and account for seqId that are stripped with `& 0xFF` by the caller
@@ -585,7 +585,7 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) {
AudioSeq_SequencePlayerDisable(seqPlayer);
- fontId = 0xFF;
+ fontId = FONT_ID_NONE;
// seqId is the resolved 16-bit id from func_800F9280(). Reject ids with no loaded sequence; the
// map has sequenceMapSize + 0xF slots (custom ids skip the reserved 129-135 range).
@@ -1407,9 +1407,13 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
SequenceData* sDat = ResourceMgr_LoadSeqPtrByName(customSeqList[j]);
if (sDat->numFonts == -1) {
+ uint8_t crcBytes[sizeof(uint64_t)];
uint64_t crc;
- memcpy(&crc, sDat->fonts, sizeof(uint64_t));
+ for (size_t b = 0; b < sizeof(crcBytes); b++) {
+ crcBytes[b] = (uint8_t)sDat->fonts[b];
+ }
+ memcpy(&crc, crcBytes, sizeof(crc));
const char* res = ResourceGetNameByCrc(crc);
if (res == NULL) {
// Passing a null buffer and length of 0 to snprintf will return the required numbers of characters the
@@ -1426,6 +1430,10 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
continue;
}
SoundFont* sf = ResourceMgr_LoadAudioSoundFontByName(res);
+ if (sf->fntIndex >= FONT_ID_NONE) {
+ LUSLOG_ERROR("Font limit (0xFFFF) exceeded; sequence \"%s\" skipped.", customSeqList[j]);
+ continue;
+ }
memset(&sDat->fonts[0], 0, sizeof(sDat->fonts));
sDat->fonts[0] = sf->fntIndex;
sDat->numFonts = 1;
diff --git a/soh/src/code/audio_playback.c b/soh/src/code/audio_playback.c
index cffe35e1c..e4709d76b 100644
--- a/soh/src/code/audio_playback.c
+++ b/soh/src/code/audio_playback.c
@@ -327,7 +327,7 @@ SoundFontSound* Audio_InstrumentGetSound(Instrument* instrument, s32 semitone) {
Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
Instrument* inst;
- if (fontId == 0xFF) {
+ if (fontId == FONT_ID_NONE) {
return NULL;
}
@@ -355,7 +355,7 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
Drum* drum = NULL;
- if (fontId == 0xFF) {
+ if (fontId == FONT_ID_NONE) {
return NULL;
}
@@ -379,7 +379,7 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) {
SoundFontSound* sfx = NULL;
- if (fontId == 0xFF) {
+ if (fontId == FONT_ID_NONE) {
return NULL;
}
@@ -405,7 +405,7 @@ SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) {
}
s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value) {
- if (fontId == 0xFF) {
+ if (fontId == FONT_ID_NONE) {
return -1;
}
diff --git a/soh/src/code/audio_seqplayer.c b/soh/src/code/audio_seqplayer.c
index b99d29e1e..92efecd02 100644
--- a/soh/src/code/audio_seqplayer.c
+++ b/soh/src/code/audio_seqplayer.c
@@ -1005,6 +1005,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
u32 parameters[3];
s8 signedParam;
u8 command = AudioSeq_ScriptReadU8(scriptState);
+ u16 fontId;
u8 lowBits;
u8 highBits;
s32 result;
@@ -1060,20 +1061,20 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
break;
case 0xEB:
result = (u8)parameters[0];
- command = (u8)parameters[0];
+ fontId = (u8)parameters[0];
- if (seqPlayer->defaultFont != 0xFF) {
+ if (seqPlayer->defaultFont != FONT_ID_NONE) {
if (gAudioContext.seqReplaced[seqPlayer->playerIdx]) {
seqPlayer->seqId = gAudioContext.seqToPlay[seqPlayer->playerIdx];
gAudioContext.seqReplaced[seqPlayer->playerIdx] = 0;
}
u16 seqId = AudioEditor_GetReplacementSeq(seqPlayer->seqId);
SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqId]);
- command = sDat.fonts[sDat.numFonts - result - 1];
+ fontId = sDat.fonts[sDat.numFonts - result - 1];
}
- if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) {
- channel->fontId = command;
+ if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, fontId)) {
+ channel->fontId = fontId;
}
parameters[0] = parameters[1];
@@ -1175,9 +1176,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
break;
case 0xC6:
result = (u8)parameters[0];
- command = (u8)parameters[0];
+ fontId = (u8)parameters[0];
- if (seqPlayer->defaultFont != 0xFF) {
+ if (seqPlayer->defaultFont != FONT_ID_NONE) {
if (gAudioContext.seqReplaced[seqPlayer->playerIdx]) {
seqPlayer->seqId = gAudioContext.seqToPlay[seqPlayer->playerIdx];
gAudioContext.seqReplaced[seqPlayer->playerIdx] = 0;
@@ -1190,11 +1191,11 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
if (result > sDat.numFonts)
break;
- command = sDat.fonts[(sDat.numFonts - result - 1)];
+ fontId = sDat.fonts[(sDat.numFonts - result - 1)];
}
- if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) {
- channel->fontId = command;
+ if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, fontId)) {
+ channel->fontId = fontId;
}
break;
diff --git a/soh/src/code/code_800E4FE0.c b/soh/src/code/code_800E4FE0.c
index 3d6c9c571..e9bd7ac64 100644
--- a/soh/src/code/code_800E4FE0.c
+++ b/soh/src/code/code_800E4FE0.c
@@ -520,7 +520,7 @@ u32 func_800E5E20(u32* out) {
return sp1C >> 0x18;
}
-u8* func_800E5E84(s32 arg0, u32* arg1) {
+u16* func_800E5E84(s32 arg0, u32* arg1) {
return AudioLoad_GetFontsForSequence(arg0, arg1);
}
diff --git a/soh/src/code/code_800EC960.c b/soh/src/code/code_800EC960.c
index 31fc49de4..a118f3388 100644
--- a/soh/src/code/code_800EC960.c
+++ b/soh/src/code/code_800EC960.c
@@ -5016,8 +5016,8 @@ void func_800F5C2C(void) {
void Audio_PlayFanfare(u16 seqId) {
u16 curSeqId;
u32 outNumFonts;
- u8* curFontId;
- u8* requestedFontId;
+ u16* curFontId;
+ u16* requestedFontId;
curSeqId = func_800FA0B4(SEQ_PLAYER_FANFARE);