diff --git a/src/BGM.asm b/src/BGM.asm index 59b605a8..38f73e22 100644 --- a/src/BGM.asm +++ b/src/BGM.asm @@ -24,6 +24,13 @@ scope BGM { // Stops background music. constant stop_(0x80020A74) + // @ Description + // Changes BGM volume + // @ Arguments + // a0 - unknown, set to 0 + // a1 - volume, max = 30720 (0x7800) + constant change_vol_(0x80020B38) + // @ Description // This hook runs right after the stage file is loaded. // This contains the default stage bgm_id, so this hook let's us override with alt/random music. @@ -56,6 +63,58 @@ scope BGM { lw v1, 0x0040(t9) // original line 2 } + // @ Description + // Edits function 0x80020B38 (Set BGM Volume) to take into account the master BGM volume + // a0 - unknown, set to 0 + // a1 - volume, max = 30720 (0x7800) + scope master_bgm_volume: { + OS.patch_start(0x2173C, 0x80020B3C) + sw ra, 0x0014(sp) // original line 2 + jal master_bgm_volume + or a3, a0, r0 // original line 3 + _return: + OS.patch_end() + + li at, Toggles.entry_bgm_volume// at = address of master BGM volume + lw at, 0x0004(at) // ~ + addiu at, at, 0x0001 // at = master BGM volume (1 to 10) + mtc1 at, f8 // ~ + cvt.s.w f8, f8 // f8 = master BGM volume fp + lui at, 0x4120 // ~ + mtc1 at, f4 // f4 = 10.0 + div.s f6, f8, f4 // f6 = (master BGM volume / 10.0) + mtc1 a1, f4 // ~ + cvt.s.w f4, f4 // f4 = new volume fp + mul.s f4, f4, f6 // f4 = new volume * (master BGM volume / 10.0) + cvt.w.s f8, f4 // f8 = (word)f4 + mfc1 a1, f8 // a1 = updated volume + + j _return + sltiu at, a1, 0x7801 // original line 1 + } + + // @ Description + // Updates BGM & FGM volumes when pressing start on title screen so previously saved master volumes apply sooner + scope load_master_volume: { + OS.patch_start(0x117714, 0x80132094) + sw ra, 0x001C(sp) // original line 1 + jal load_master_volume + nop + _return: + OS.patch_end() + + lli a1, 0x7800 // a1 = volume + jal BGM.change_vol_ // update BGM volume + lli a0, 0x0000 // a0 = unknown, set to 0 + + jal FGM.change_vol_ // update FGM volume + lli a0, 0x7800 // a0 = volume + + addiu t6, r0, 0x00FF // original line 2 + j _return + sw t6, 0x0010(sp) // original line 3 + } + default_track: dw 0 diff --git a/src/FGM.asm b/src/FGM.asm index 9cdfd978..52a6ee7e 100644 --- a/src/FGM.asm +++ b/src/FGM.asm @@ -181,6 +181,54 @@ scope FGM { addiu a0, r0, {sfx} } + // @ Description + // Changes FGM volume + // @ Arguments + // a0 - volume, max = 30720 (0x7800) + constant change_vol_(0x80020E64) + + // @ Description + // Edits function 0x80020E64 (Set FGM Volume) to take into account the master SFX volume + // a0 - volume, max = 30720 (0x7800) + scope master_fgm_volume: { + OS.patch_start(0x21A64, 0x80020E64) + addiu sp, sp, -0x0018 // original line 1 + sw ra, 0x0014(sp) // original line 3 + jal master_fgm_volume + nop + nop + nop + nop + _return: + OS.patch_end() + + li at, Toggles.entry_fgm_volume // at = address of master SFX volume + lw at, 0x0004(at) // ~ + addiu at, at, 0x0001 // at = master SFX volume (1 to 10) + mtc1 at, f4 // ~ + cvt.s.w f4, f4 // f4 = master SFX volume fp + lui at, 0x4120 // ~ + mtc1 at, f0 // f0 = 10.0 + div.s f2, f4, f0 // f2 = (master SFX volume / 10.0) + mtc1 a0, f0 // ~ + cvt.s.w f0, f0 // f0 = new volume fp + mul.s f0, f0, f2 // f0 = new volume * (master SFX volume / 10.0) + cvt.w.s f4, f0 // f4 = (word)f4 + mfc1 a0, f4 // a0 = updated volume + + sltiu at, a0, 0x7801 // original line 2 + //bnez at, 0x80020E80 // original line 4 (need to 'j' instead of 'b') + bnez at, _srl // original line 4, modified + or a1, a0, r0 // original line 5 + //b 0x80020E88 // original line 6 (need to 'j' instead of 'b') + j _return+8 // original line 6, modified + addiu a0, r0, 0x007F // original line 7 + + _srl: + j _return + nop + } + // Extended Sound Effects print "=============================== SOUND FILES ==============================\n" diff --git a/src/SRAM.asm b/src/SRAM.asm index edbb33e3..846b6ab0 100644 --- a/src/SRAM.asm +++ b/src/SRAM.asm @@ -22,7 +22,7 @@ scope SRAM { // - A new MIDI is added // - A new toggle is added // - The order of the toggles is changed - constant REVISION(0x00F5) + constant REVISION(0x00F7) // @ Description // Struct that holds information for a block of save data. diff --git a/src/Toggles.asm b/src/Toggles.asm index b31a5a49..a00e1ae8 100644 --- a/src/Toggles.asm +++ b/src/Toggles.asm @@ -744,6 +744,14 @@ scope Toggles { _exit_super_menu: jal save_ // save toggles nop + + lli a0, 0x0000 // a0 = unknown, set to 0 + jal BGM.change_vol_ // update BGM volume + lli a1, 0x7800 // a1 = max volume + + jal FGM.change_vol_ // update FGM volume + lli a0, 0x7800 // a0 = max volume + // check if we got here by using the 'L' shortcut, and retrieve current_screen if so li t3, shortcut_stored_screens // t3 = shortcut_stored_screens lbu a0, 0x0000(t3) // a0 = 0 if we didn't use 'L' shortcut @@ -1561,6 +1569,18 @@ scope Toggles { light:; db "LIGHT", 0x00 OS.align(4) + string_table_volume: + dw num_1 + dw num_2 + dw num_3 + dw num_4 + dw num_5 + dw num_6 + dw num_7 + dw num_8 + dw num_9 + dw num_10 + // @ Description // Pokemon Stadium Announcer strings announcer_mode_pokemon:; db "STADIUM", 0x00 @@ -2141,6 +2161,37 @@ scope Toggles { nop } + // @ Description + // Run BGM volume change to update volume + scope update_bgm_volume: { + addiu sp, sp,-0x0020 // allocate stack space + sw ra, 0x0008(sp) // save registers + + lli a1, 0x7800 // a1 = max volume + jal BGM.change_vol_ // update BGM volume with toggle value + lli a0, 0x0000 // a0 = unknown, set to 0 + + lw ra, 0x0008(sp) // ~ + addiu sp, sp, 0x0020 // deallocate stack space + jr ra + nop + } + + // @ Description + // Run FGM volume change to update volume + scope update_fgm_volume: { + addiu sp, sp,-0x0020 // allocate stack space + sw ra, 0x0008(sp) // save registers + + jal FGM.change_vol_ // update FGM volume with toggle value + lli a0, 0x7800 // a0 = max volume + + lw ra, 0x0008(sp) // ~ + addiu sp, sp, 0x0020 // deallocate stack space + jr ra + nop + } + string_table_gallery: dw mario dw dk @@ -2308,7 +2359,9 @@ scope Toggles { entry_dpad_css_control:; entry_bool("Dpad CSS Cursor Control", OS.FALSE, OS.FALSE, OS.FALSE, OS.FALSE, entry_pk_thunder_reflect_crash_fix) entry_pk_thunder_reflect_crash_fix:;entry_bool("PK Thunder Reflect Crash Fix", OS.TRUE, OS.TRUE, OS.TRUE, OS.TRUE, entry_flash_guard) entry_flash_guard:; entry_bool("Flash Guard", OS.FALSE, OS.FALSE, OS.FALSE, OS.FALSE, entry_screenshake) - entry_screenshake:; entry("Screenshake", Menu.type.INT, OS.FALSE, OS.FALSE, OS.FALSE, OS.FALSE, 0, 2, OS.NULL, string_table_screenshake, OS.NULL, OS.NULL) + entry_screenshake:; entry("Screenshake", Menu.type.INT, OS.FALSE, OS.FALSE, OS.FALSE, OS.FALSE, 0, 2, OS.NULL, string_table_screenshake, OS.NULL, entry_bgm_volume) + entry_bgm_volume:; entry("BGM Volume", Menu.type.INT, 9, 9, 9, 9, 0, 9, update_bgm_volume, string_table_volume, OS.NULL, entry_fgm_volume) + entry_fgm_volume:; entry("SFX Volume", Menu.type.INT, 9, 9, 9, 9, 0, 9, update_fgm_volume, string_table_volume, OS.NULL, OS.NULL) evaluate num_remix_toggles(num_toggles) evaluate remix_toggles_block_size(block_size)