Skip to content

Commit

Permalink
add music control codes
Browse files Browse the repository at this point in the history
  • Loading branch information
JLaferri committed Aug 15, 2023
1 parent 8e359d5 commit 273b1fb
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 18 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions Common/Common.s
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ add \reg, r3, r4

# Misc
.set CONST_SlippiCmdGetDelay, 0xD5
.set CONST_SlippiPlayMusic, 0xD6
.set CONST_SlippiStopMusic, 0xD7
.set CONST_SlippiChangeMusicVolume, 0xD8

# For Slippi Premade Texts
.set CONST_SlippiCmdGetPremadeTextLength, 0xE1
Expand Down Expand Up @@ -606,6 +609,7 @@ add \reg, r3, r4
.set frameIndex,-0x49ac
.set textStructDescriptorBuffer,-0x3D24
.set isWidescreen,-0x5020
.set OFST_R13_SB_ADDR,-0x503C # Scene buffer, persists throughout scenes

################################################################################
# Log levels
Expand Down
79 changes: 79 additions & 0 deletions Online/Core/Music/StartSong.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
################################################################################
# Address: 0x8038e910 # fileLoad_HPS, after entry num is fetched
################################################################################

.include "Common/Common.s"

.set REG_PMQ, 31
.set REG_ENTRYNUM, 30
.set REG_INTERRUPT_IDX, 29

# This will contain the DVDFileInfo struct which has length 0x40
.set SPO_STRUCT_START, BKP_FREE_SPACE_OFFSET
.set SPO_FILE_OFFSET, SPO_STRUCT_START + 0x30
.set SPO_FILE_SIZE, SPO_FILE_OFFSET + 4

# This space will be used to transfer over EXI. EXI buffers must be 32 byte aligned though
# so we don't know exactly where the buffer will start
.set SPO_EXI_SPACE_START, SPO_STRUCT_START + 0x40

# PlayMusicQuery args
.set PMQ_COMMAND, 0
.set PMQ_FILE_OFFSET, PMQ_COMMAND + 1
.set PMQ_FILE_SIZE, PMQ_FILE_OFFSET + 4
.set PMQ_SIZE, PMQ_FILE_SIZE + 4 # Confusing but this is the size of the buffer

# Grab enough space that no matter where we are, we can byteAlign32 and still fit the PMQ data
.set SPACE_NEEDED, SPO_EXI_SPACE_START + PMQ_SIZE + 32

backup SPACE_NEEDED

mr REG_ENTRYNUM, r3

branchl r12, OSDisableInterrupts
mr REG_INTERRUPT_IDX, r3

mr r3, REG_ENTRYNUM
addi r4, sp, SPO_STRUCT_START
branchl r12, 0x80337c60 # DVDFastOpen

# TODO: File_GetLength asserts when result = 0, hopefully just ignoring it and doing nothing is fine
cmpwi r3, 0
beq CLEANUP_AND_EXIT

# Log
# lwz r5, SPO_FILE_OFFSET(sp)
# lwz r6, SPO_FILE_SIZE(sp)
# logf LOG_LEVEL_WARN, "[Music] Starting song at 0x%x with size %d"

addi REG_PMQ, sp, SPO_EXI_SPACE_START
byteAlign32 REG_PMQ

# Write command
li r3, CONST_SlippiPlayMusic
stb r3, PMQ_COMMAND(REG_PMQ)

# Write file offset and size
lwz r3, SPO_FILE_OFFSET(sp)
stw r3, PMQ_FILE_OFFSET(REG_PMQ)
lwz r3, SPO_FILE_SIZE(sp)
stw r3, PMQ_FILE_SIZE(REG_PMQ)

# Exec EXI transfer
mr r3, REG_PMQ
li r4, PMQ_SIZE
li r5, CONST_ExiWrite
branchl r12, FN_EXITransferBuffer

CLEANUP_AND_EXIT:
addi r3, sp, SPO_STRUCT_START
branchl r12, 0x80337cd4 # DVDClose

mr r3, REG_INTERRUPT_IDX
branchl r12, OSRestoreInterrupts

mr r3, REG_ENTRYNUM

restore SPACE_NEEDED

lwz r0, -0x5668(r13) # replaced code line
40 changes: 40 additions & 0 deletions Online/Core/Music/Stop.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
################################################################################
# Address: 0x800236ec # Music_StopMusic, after function call
################################################################################

.include "Common/Common.s"

.set REG_SMQ, 31

# This space will be used to transfer over EXI. EXI buffers must be 32 byte aligned though
# so we don't know exactly where the buffer will start
.set SPO_EXI_SPACE_START, BKP_FREE_SPACE_OFFSET

# PlayMusicQuery args
.set SMQ_COMMAND, 0
.set SMQ_SIZE, SMQ_COMMAND + 1

# Grab enough space that no matter where we are, we can byteAlign32 and still fit the SMQ data
.set SPACE_NEEDED, SPO_EXI_SPACE_START + SMQ_SIZE + 32

backup SPACE_NEEDED

# logf LOG_LEVEL_WARN, "[Music] Stopping music"

addi REG_SMQ, sp, SPO_EXI_SPACE_START
byteAlign32 REG_SMQ

# Write command
li r3, CONST_SlippiStopMusic
stb r3, SMQ_COMMAND(REG_SMQ)

# Exec EXI transfer
mr r3, REG_SMQ
li r4, SMQ_SIZE
li r5, CONST_ExiWrite
branchl r12, FN_EXITransferBuffer

CLEANUP_AND_EXIT:
restore SPACE_NEEDED

li r0, 0 # replaced code line
66 changes: 66 additions & 0 deletions Online/Core/Music/VolumeChange.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
################################################################################
# Address: 0x800249f0 # DSP_Process, where volume is written
################################################################################

.include "Common/Common.s"

.set REG_CMVQ, 31
.set REG_DATA, 30

# This space will be used to transfer over EXI. EXI buffers must be 32 byte aligned though
# so we don't know exactly where the buffer will start
.set SPO_EXI_SPACE_START, BKP_FREE_SPACE_OFFSET

# PlayMusicQuery args
.set CMVQ_COMMAND, 0
.set CMVQ_VOLUME, CMVQ_COMMAND + 1
.set CMVQ_SIZE, CMVQ_VOLUME + 1

# Grab enough space that no matter where we are, we can byteAlign32 and still fit the CMVQ data
.set SPACE_NEEDED, SPO_EXI_SPACE_START + CMVQ_SIZE + 32

b CODE_START

DATA_BLRL:
blrl
.set DO_PREV_VOLUME, 0
.long 0x00000000

CODE_START:
stw r0, -0x7E18(r13) # replaced code line

backup SPACE_NEEDED

bl DATA_BLRL
mflr REG_DATA

lwz r4, -0x7E18(r13) # load new value
lwz r3, DO_PREV_VOLUME(REG_DATA) # load old value
cmpw r3, r4
beq CLEANUP_AND_EXIT

# Update prev value to current
stw r4, DO_PREV_VOLUME(REG_DATA)

# Here the volume differs from the previous. Let's send the new volume to Dolphin
# mr r5, r4
# logf LOG_LEVEL_WARN, "[Music] Volume changed: %d"

addi REG_CMVQ, sp, SPO_EXI_SPACE_START
byteAlign32 REG_CMVQ

# Write command
li r3, CONST_SlippiChangeMusicVolume
stb r3, CMVQ_COMMAND(REG_CMVQ)

# Write new volume
stb r4, CMVQ_VOLUME(REG_CMVQ)

# Exec EXI transfer
mr r3, REG_CMVQ
li r4, CMVQ_SIZE
li r5, CONST_ExiWrite
branchl r12, FN_EXITransferBuffer

CLEANUP_AND_EXIT:
restore SPACE_NEEDED
1 change: 0 additions & 1 deletion Online/Online.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# Offsets from r13
################################################################################
.set OFST_R13_ODB_ADDR,-0x49e4 # Online data buffer
.set OFST_R13_SB_ADDR,-0x503C # Scene buffer, persists throughout scenes
.set OFST_R13_ONLINE_MODE,-0x5060 # Byte, Selected online mode
.set OFST_R13_APP_STATE,-0x505F # Byte, App state / online status
.set OFST_R13_FORCE_MENU_CLEAR,-0x505E # Byte, Force menu clear
Expand Down
5 changes: 5 additions & 0 deletions Output/Console/GALE01r2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ C208D698 00000005 #Recording/GetLCancelStatus/GetLCancelStatus.asm
C206C324 00000002 #Recording/GetLCancelStatus/ResetLCancelStatus.asm
38600000 987E25FF
807E00B0 00000000
C21A4CB4 00000004 #Common/AllocBuffer.asm
38600080 3D808037
618CF1E4 7D8903A6
4E800421 906DAFC4
38000000 00000000
C20055F8 0000000F #Common/GetIsFollower.asm
7C0802A6 90010004
9421FF20 BE8100B0
Expand Down
Binary file modified Output/Console/g_core.bin
Binary file not shown.
Binary file modified Output/Console/g_core_porta.bin
Binary file not shown.
7 changes: 7 additions & 0 deletions Output/InjectionLists/list_console_core.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@
"Annotation": "Recording/GetLCancelStatus/ResetLCancelStatus.asm",
"Tags": ""
},
{
"InjectionAddress": "801A4CB4",
"Name": "Slippi Recording",
"Codetype": "Auto",
"Annotation": "Common/AllocBuffer.asm",
"Tags": ""
},
{
"InjectionAddress": "800055F8",
"Name": "Slippi Recording",
Expand Down
35 changes: 28 additions & 7 deletions Output/InjectionLists/list_netplay.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@
"Annotation": "Recording/GetLCancelStatus/ResetLCancelStatus.asm",
"Tags": ""
},
{
"InjectionAddress": "801A4CB4",
"Name": "Required: Slippi Recording",
"Codetype": "Auto",
"Annotation": "Common/AllocBuffer.asm",
"Tags": ""
},
{
"InjectionAddress": "800055F8",
"Name": "Required: Slippi Recording",
Expand Down Expand Up @@ -651,13 +658,6 @@
"Annotation": "Online/Core/TriggerSendInput.asm",
"Tags": ""
},
{
"InjectionAddress": "801A4CB4",
"Name": "Required: Slippi Online",
"Codetype": "Auto",
"Annotation": "Online/Core/EXIFileLoad/AllocBuffer.asm",
"Tags": ""
},
{
"InjectionAddress": "800163FC",
"Name": "Required: Slippi Online",
Expand Down Expand Up @@ -728,6 +728,27 @@
"Annotation": "Online/Core/Hacks/PreventPadAlarmDuringRollback.asm",
"Tags": ""
},
{
"InjectionAddress": "8038E910",
"Name": "Required: Slippi Online",
"Codetype": "Auto",
"Annotation": "Online/Core/Music/StartSong.asm",
"Tags": ""
},
{
"InjectionAddress": "800236EC",
"Name": "Required: Slippi Online",
"Codetype": "Auto",
"Annotation": "Online/Core/Music/Stop.asm",
"Tags": ""
},
{
"InjectionAddress": "800249F0",
"Name": "Required: Slippi Online",
"Codetype": "Auto",
"Annotation": "Online/Core/Music/VolumeChange.asm",
"Tags": ""
},
{
"InjectionAddress": "801D4578",
"Name": "Required: Slippi Online",
Expand Down
67 changes: 62 additions & 5 deletions Output/Netplay/GALE01r2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,11 @@ C208D698 00000005 #Recording/GetLCancelStatus/GetLCancelStatus.asm
C206C324 00000002 #Recording/GetLCancelStatus/ResetLCancelStatus.asm
38600000 987E25FF
807E00B0 00000000
C21A4CB4 00000004 #Common/AllocBuffer.asm
38600080 3D808037
618CF1E4 7D8903A6
4E800421 906DAFC4
38000000 00000000
C20055F8 0000000F #Common/GetIsFollower.asm
7C0802A6 90010004
9421FF20 BE8100B0
Expand Down Expand Up @@ -2040,11 +2045,6 @@ BA8100B0 800100E4
800100E4 382100E0
7C0803A6 2C1E0000
60000000 00000000
C21A4CB4 00000004 #Online/Core/EXIFileLoad/AllocBuffer.asm
38600080 3D808037
618CF1E4 7D8903A6
4E800421 906DAFC4
38000000 00000000
C20163FC 0000001B #Online/Core/EXIFileLoad/GetFileSize.asm
7C7E1B78 7C0802A6
90010004 9421FF20
Expand Down Expand Up @@ -2194,6 +2194,63 @@ C2019608 0000000F #Online/Core/Hacks/PreventPadAlarmDuringRollback.asm
618C9618 7D8903A6
4E800420 38600000
60000000 00000000
C238E910 0000001A #Online/Core/Music/StartSong.asm
7C0802A6 90010004
9421FF54 BE81007C
7C7E1B78 3D808034
618C7364 7D8903A6
4E800421 7C7D1B78
7FC3F378 38810008
3D808033 618C7C60
7D8903A6 4E800421
2C030000 41820044
3BE10048 3BFF001F
57FF0034 386000D6
987F0000 80610038
907F0001 8061003C
907F0005 7FE3FB78
38800009 38A00001
3D808000 618C55F0
7D8903A6 4E800421
38610008 3D808033
618C7CD4 7D8903A6
4E800421 7FA3EB78
3D808034 618C738C
7D8903A6 4E800421
7FC3F378 BA81007C
800100B0 382100AC
7C0803A6 800DA998
60000000 00000000
C20236EC 0000000B #Online/Core/Music/Stop.asm
7C0802A6 90010004
9421FF9C BE810034
3BE10008 3BFF001F
57FF0034 386000D7
987F0000 7FE3FB78
38800001 38A00001
3D808000 618C55F0
7D8903A6 4E800421
BA810034 80010068
38210064 7C0803A6
38000000 00000000
C20249F0 00000011 #Online/Core/Music/VolumeChange.asm
4800000C 4E800021
00000000 900D81E8
7C0802A6 90010004
9421FF9C BE810034
4BFFFFE5 7FC802A6
808D81E8 807E0000
7C032000 4182003C
909E0000 3BE10008
3BFF001F 57FF0034
386000D8 987F0000
989F0001 7FE3FB78
38800002 38A00001
3D808000 618C55F0
7D8903A6 4E800421
BA810034 80010068
38210064 7C0803A6
60000000 00000000
C21D4578 00000003 #Online/Core/PreventFileAlarms/FreezeStadium.asm
FFE00890 3D80801D
618C4FD8 7D8903A6
Expand Down
Loading

0 comments on commit 273b1fb

Please sign in to comment.