Fix for BRSTM with Fewer Audio Tracks [stebler]
#1
Fix for BRSTM with Fewer Audio Tracks [stebler]

This code prevents the bgm from stopping due to the low number of tracks in BRSTM.

Original code was written by stebler as a part of mkw-sp.

I ported it to gecko code.

It is recommended to use with this code.

NTSC-K is not tested.

(NTSC-U)
c20a4f10 0000001e
7cac2b78 558c463e
718c0080 2c0c0080
40820014 3d807fff
618cffff 7ca56038
480000c4 9421ff80
7c0802a6 90010084
bc610008 48000021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 3d608000
9421ff80 7c0802a6
90010084 bc610008
7ca55b78 3d80800a
618c4f10 7d8803a6
4e800021 9061fffc
b8610008 80010084
7c0803a6 38210080
8181ff7c 2c0c0000
4182000c 38600001
4e800020 3ca08000
9421ff80 7c0802a6
90010084 bc610008
3d80800a 618c4f10
7d8803a6 4e800021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 9421ffe0
60000000 00000000
0409ebd0 38000000


(PAL)
c20a4fb0 0000001e
7cac2b78 558c463e
718c0080 2c0c0080
40820014 3d807fff
618cffff 7ca56038
480000c4 9421ff80
7c0802a6 90010084
bc610008 48000021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 3d608000
9421ff80 7c0802a6
90010084 bc610008
7ca55b78 3d80800a
618c4fb0 7d8803a6
4e800021 9061fffc
b8610008 80010084
7c0803a6 38210080
8181ff7c 2c0c0000
4182000c 38600001
4e800020 3ca08000
9421ff80 7c0802a6
90010084 bc610008
3d80800a 618c4fb0
7d8803a6 4e800021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 9421ffe0
60000000 00000000
0409ec70 38000000


(NTSC-J)
c20a4ed0 0000001e
7cac2b78 558c463e
718c0080 2c0c0080
40820014 3d807fff
618cffff 7ca56038
480000c4 9421ff80
7c0802a6 90010084
bc610008 48000021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 3d608000
9421ff80 7c0802a6
90010084 bc610008
7ca55b78 3d80800a
618c4ed0 7d8803a6
4e800021 9061fffc
b8610008 80010084
7c0803a6 38210080
8181ff7c 2c0c0000
4182000c 38600001
4e800020 3ca08000
9421ff80 7c0802a6
90010084 bc610008
3d80800a 618c4ed0
7d8803a6 4e800021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 9421ffe0
60000000 00000000
0409EB90 38000000


(NTSC-K)
c20a5010 0000001e
7cac2b78 558c463e
718c0080 2c0c0080
40820014 3d807fff
618cffff 7ca56038
480000c4 9421ff80
7c0802a6 90010084
bc610008 48000021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 3d608000
9421ff80 7c0802a6
90010084 bc610008
7ca55b78 3d80800a
618c5010 7d8803a6
4e800021 9061fffc
b8610008 80010084
7c0803a6 38210080
8181ff7c 2c0c0000
4182000c 38600001
4e800020 3ca08000
9421ff80 7c0802a6
90010084 bc610008
3d80800a 618c5010
7d8803a6 4e800021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 9421ffe0
60000000 00000000
0409ecd0 38000000


Code:
#Source

#First ASM

#inject at 0x800a4f10 (NTSC-U)
#inject at 0x800a4fb0 (PAL)
#inject at 0x800a4ed0 (NTSC-J)
#inject at 0x800a5010 (NTSC-K)

.macro call_link address
lis r12, \address@h
ori r12, r12, \address@l
mtlr r12
blrl
.endm

.macro pushStack
    stwu sp, -0x80 (sp)
    mflr r0
    stw r0, 0x84 (sp)
    stmw r3, 8 (sp)
.endm

.macro popStack
    lmw r3, 8 (sp)
    lwz r0, 0x84 (sp)
    mtlr r0
    addi sp, sp, 0x80
.endm

.set region, 'K'

.if (region == 'P')
    .set nw4r__snd__StrmFileReader__readStrmTrackInfo, 0x800a4fb0
.elseif (region == 'E')
    .set nw4r__snd__StrmFileReader__readStrmTrackInfo, 0x800a4f10
.elseif (region == 'J')
    .set nw4r__snd__StrmFileReader__readStrmTrackInfo, 0x800a4ed0
.elseif (region == 'K')
    .set nw4r__snd__StrmFileReader__readStrmTrackInfo, 0x800a5010
.else
        .err
.endif

    mr r12, r5
    rlwinm  r12, r12, 8, 24, 31
    andi. r12, r12, 0x80
    cmpwi r12, 0x80
    bne not_default_behave
    lis r12, 0x7FFF
    ori r12, r12, 0xFFFF
    and r5, r5, r12
    b skip_all
    not_default_behave:
    pushStack
    bl strmTrackInfoReadHook
    stw r3, -4 (sp)
    popStack
    lwz r3, -0x84 (sp)
    blr
strmTrackInfoReadHook:
    lis r11, 0x8000
    pushStack
    #r3 = this pointer (nw4r::snd::StrmFileReader)
    #r4 = pointer to soundInfo
    #r5 = trackId
    or r5, r5, r11
    call_link nw4r__snd__StrmFileReader__readStrmTrackInfo
    stw r3, -4 (sp)
    popStack
    lwz r12, -0x84 (sp)
    cmpwi r12, 0
    beq read_track_0
    li r3, 1
    blr
    read_track_0:
    lis r5, 0x8000
    pushStack
    call_link nw4r__snd__StrmFileReader__readStrmTrackInfo
    stw r3, -4 (sp)
    popStack
    lwz r3, -0x84 (sp)
    blr
skip_all:
    stwu sp, -0x20 (sp) #default instruction

Code:
#Source

#Second ASM
#fix STRM params alloc channel count for brsar to 0

#replace at 0x8009ebd0 (NTSC-U)
#replace at 0x8009ec70 (PAL)
#replace at 0x8009eb90 (NTSC-J)
#replace at 0x8009ecd0 (NTSC-K)

li r0, 0
Reply


Messages In This Thread
Fix for BRSTM with Fewer Audio Tracks [stebler] - by Kazuki - 09-08-2023, 10:01 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)