Skip to content

Commit 4e4a5fe

Browse files
Merge pull request #2242 from AlmostSeagull/music-display-fix-round2
music display fix, with less crashes this time!
2 parents f4ee03e + b72d28d commit 4e4a5fe

File tree

9 files changed

+730
-712
lines changed

9 files changed

+730
-712
lines changed

base-hack/asm/symbols.asm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@
201201
.definelabel CBTurnedInArray, 0x807FC930
202202
.definelabel charspawnerflags, 0x80755DA8
203203
.definelabel songData, 0x80745658
204+
.definelabel trackStateArray, 0x80745924
205+
.definelabel SongInWriteSlot, 0x80770560
204206
.definelabel songVolumes, 0x807454F0
205207
.definelabel compactSequencePlayers, 0x8076BF20
206208
.definelabel MusicTrackChannels, 0x807458DC

base-hack/include/dk64.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ extern int FileGBCount;
677677
extern float FileScreenDLOffset;
678678
extern short CBTurnedInArray[8];
679679
extern short songData[SONG_COUNT];
680+
extern short trackStateArray[12];
681+
extern char songInWriteSlot[4];
680682
extern short songVolumes[SONG_COUNT];
681683
extern int* compactSequencePlayers[4];
682684
extern unsigned int DKTVData[5];

base-hack/include/global.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ extern void initDingSprite(void);
194194
extern void fastWarpShockwaveFix(void);
195195
extern void setPrevSaveMap(void);
196196
extern int filterSong(int* song_write);
197+
extern void detectSongChange();
197198
extern int getTotalCBCount(void);
198199

199200
extern void swapKremlingModel(void);

base-hack/src/lib.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,17 +1395,6 @@ int filterSong(int* song_write) {
13951395
}
13961396
}
13971397
}
1398-
initSongDisplay(song);
1399-
return getTrackChannel(song);
1400-
}
1401-
1402-
int filterSong_Cancelled(songs song) {
1403-
for (int i = 0; i < 12; i++) {
1404-
if ((MusicTrackChannels[i] != SONG_SILENCE) && (MusicTrackChannels[i] != song)) {
1405-
initSongDisplay(MusicTrackChannels[i]);
1406-
break;
1407-
}
1408-
}
14091398
return getTrackChannel(song);
14101399
}
14111400

base-hack/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void cFuncLoop(void) {
141141
}
142142
}
143143
handleSFXCache();
144+
detectSongChange();
144145
handleDPadFunctionality();
145146
if (Rando.helm_hurry_mode) {
146147
checkTotalCache();

base-hack/src/misc/music_text.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,44 @@
1313

1414
static unsigned char display_timer = 0;
1515
static short displayed_text_offset = -1;
16+
static short storedMusicTrackChannel[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
17+
static char storedTrackState[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1618

1719
void resetDisplayedMusic(void) {
1820
DisplayedSongNamePointer = 0; // Uses a static address for autotrackers
1921
}
2022

23+
24+
void detectSongChange(){
25+
char trackChannelsChanged = 0;
26+
for(int i = 0; i < 12; i++){
27+
if(storedMusicTrackChannel[i] != MusicTrackChannels[i]){
28+
// Block song display from occurring in the pause menu
29+
// Other instances of this occurring are fair game, maybe even desired
30+
if(MusicTrackChannels[i] != 41){
31+
// New song was requested to play on this channel
32+
// Do record pause music playing, so we know when it stops playing
33+
storedMusicTrackChannel[i] = MusicTrackChannels[i];
34+
if(MusicTrackChannels[i] != 34){
35+
trackChannelsChanged = 1;
36+
}
37+
}
38+
}
39+
}
40+
for(int i = 0; i < 12; i++){
41+
if(trackStateArray[i] != storedTrackState[i]){
42+
if(trackStateArray[i] == 2 && storedTrackState[i] == 1){
43+
// New song has loaded in and has now started
44+
initSongDisplay(MusicTrackChannels[i]);
45+
}
46+
storedTrackState[i] = trackStateArray[i];
47+
} else if(trackStateArray[i] == 2 && trackChannelsChanged){
48+
// Song that was newly requested was already loaded in and has now started
49+
initSongDisplay(MusicTrackChannels[i]);
50+
}
51+
}
52+
}
53+
2154
void initSongDisplay(int song) {
2255
if (song == 0) {
2356
return;
@@ -33,17 +66,6 @@ void initSongDisplay(int song) {
3366
// In K Rool gets launched cutscene
3467
return;
3568
}
36-
int channel = getTrackChannel(song);
37-
int writeSlot = getSongWriteSlot(song);
38-
if ((MusicTrackChannels[channel] == song) && ((songData[song] & 0x200) == 0)) {
39-
if(cspGetState(compactSequencePlayers[writeSlot]) == 1){
40-
// If CompactSequence Player is already playing this song
41-
// Not gonna bother looking through the event queue whether or not
42-
// the CompactSequence Player is being stopped and started on the same audio frame
43-
// because that's hard to trigger and very expensive, if even reliable.
44-
return;
45-
}
46-
}
4769
if (DisplayedSongNamePointer) {
4870
complex_free(DisplayedSongNamePointer);
4971
}

randomizer/Patching/ASMPatcher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,6 @@ def patchAssembly(ROM_COPY, spoiler):
23292329

23302330
writeFunction(ROM_COPY, 0x80602AB0, Overlay.Static, "filterSong", offset_dict)
23312331
writeValue(ROM_COPY, 0x80602AAC, Overlay.Static, 0x27A40018, offset_dict, 4) # addiu $a0, $sp, 0x18I
2332-
writeFunction(ROM_COPY, 0x80602B80, Overlay.Static, "filterSong_Cancelled", offset_dict)
23332332
# Decompressed Overlays
23342333
overlays_being_decompressed = [
23352334
0x08, # Cutscenes

static/patches/shrink-dk64.bps

-8 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)