Skip to content

Commit

Permalink
Merge pull request #355 from Vivelin/msu-fixes
Browse files Browse the repository at this point in the history
Msu fixes
  • Loading branch information
MattEqualsCoder authored Jun 30, 2023
2 parents 79d6c83 + e3957d0 commit f20598e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 59 deletions.
27 changes: 19 additions & 8 deletions alttp_sm_combo_randomizer_rom/src/credits.asm
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,29 @@ init:
lda #$0000
tcd

; Start SPC song
jsl playmusic
; Check if MSU-1 is available
lda.w $2002 : cmp.w #$2D53 : bne .playspc

; If MSU music is previously playing, play the combo credits MSU track
; Play MSU-1 track 99 if available
sep #$30
lda $2002 : cmp.b #'S' : bne +
lda #99 : sta $2004 : stz $2005 ; Play track 99
lda #1 : sta $2007 ; Sets the track to not repeat
lda #$FF : sta $2006 ; Set to max volume
+
lda.b #99 : sta.w $2004 : stz.w $2005
- lda.w $2000 : bit.b #$40 : bne - ; Wait for MSU-1 BUSY
lda.w $2000 : bit.b #$08 : bne .fallback ; Check MSU-1 Track missing otherwise fall back to SPC
lda.b #1 : sta.w $2007 ; Sets the track to not repeat
lda.b #$FF : sta.w $2006 ; Set to max volume
bra .load_graphics

.fallback
; Mute any currently playing MSU-1 track
stz.w $2007 : stz.w $2006
stz.w $2004 : stz.w $2005

.playspc
; Start SPC song
jsl playmusic

; Load credits fonts and palettes into VRAM/CGRAM
.load_graphics
%ai16()
jsr load_graphics
jsr load_tilemap
Expand Down
40 changes: 36 additions & 4 deletions alttp_sm_combo_randomizer_rom/src/sm/msu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ macro CheckMSUPresence(labelToJump)
BEQ + : jmp <labelToJump> : +
endmacro

macro CheckMSUPresence16(labelToJump)
lda.w !MSU_ID
cmp.w #$2D53
BEQ + : jmp <labelToJump> : +
endmacro

; Init MSU and check for missing tracks
org $C08564
jsl init_msu1
Expand All @@ -91,12 +97,36 @@ org $C08F27
base $808F27
jsr SM_MSU_Main

org $C0FA00
base $80FA00
org $C0F900
base $80F900
init_msu1:
%CheckMSUPresence16(.exit)

; Check if SRAM seed data matches ROM seed data.
; If it does then there's no need to check the track data
ldx #$0000
.check_seed
lda.l rando_seed_data+$10, x ; Seed guid
cmp.l !SRAM_MSU_SEED_DATA, x
bne .do_init
inx : inx
cpx #$0020
bne .check_seed
bra .exit

.do_init
jsl MSUInit

ldx #$0000
.store_seed
lda.l rando_seed_data+$10, x ; Seed guid
sta.l !SRAM_MSU_SEED_DATA, x
inx : inx
cpx #$0020
bne .store_seed

; original hooked code
.exit
jsl $808261 ; Check for non-corrupt SRAM
rtl

Expand Down Expand Up @@ -242,11 +272,11 @@ SM_MSU_Main:
.TryExtended
CPX #00 : BNE +
TYA
bra .CheckFallbacks
jmp .CheckFallbacks
+
CPX #$FF : BNE +
TYA
bra .OriginalCode
jmp .OriginalCode
+

PHX
Expand Down Expand Up @@ -297,6 +327,8 @@ SM_MSU_Main:
stz.w !MSU_AUDIO_TRACK_HI

.CheckAudioStatus
lda.w !MSU_STATUS : bit.b #!MSU_STATUS_AUDIO_BUSY : bne .CheckAudioStatus

;; Play the song and add repeat if needed
jsr TrackNeedLooping
sta.w !MSU_AUDIO_CONTROL
Expand Down
55 changes: 22 additions & 33 deletions alttp_sm_combo_randomizer_rom/src/spc_play.asm
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,17 @@ loadspc:

; Copy $02-ef to SPC RAM
; sendmusicblock $e0 $c002 $0002 $00ee
; Only begin playing if there is no MSU track playing
sep #$30
lda $2002 : cmp.b #'S' : beq +
rep #$30
sep #!A_8BIT
lda #$f6 ; 1
sta $14
rep #!A_8BIT
lda #$0002 ; 2
sta $12

rep #!XY_8BIT
ldx #$0002 ; 3
ldy #$00ee ; 4
jsr copyblocktospc
+
sep #!A_8BIT
lda #$f6 ; 1
sta $14
rep #!A_8BIT
lda #$0002 ; 2
sta $12

rep #!XY_8BIT
ldx #$0002 ; 3
ldy #$00ee ; 4
jsr copyblocktospc

; sendmusicblock $f6 $0100 $0100 $7f00
sep #!A_8BIT
Expand All @@ -124,22 +118,17 @@ loadspc:
jsr copyblocktospc

; sendmusicblock $f7 $0000 $8000 $7fc0
; Only begin playing if there is no MSU track playing
sep #$30
lda $2002 : cmp.b #'S' : beq +
rep #$30
sep #!A_8BIT
lda #$f7 ; 1
sta $14
rep #!A_8BIT
lda #$0000 ; 2
sta $12

rep #!XY_8BIT
ldx #$8000 ; 3
ldy #$7fc0 ; 4
jsr copyblocktospc
+
sep #!A_8BIT
lda #$f7 ; 1
sta $14
rep #!A_8BIT
lda #$0000 ; 2
sta $12

rep #!XY_8BIT
ldx #$8000 ; 3
ldy #$7fc0 ; 4
jsr copyblocktospc

; Create SPC init code that sets up registers
jsr makespcinitcode
Expand Down Expand Up @@ -453,4 +442,4 @@ credits_sm_spc_data:
db $8f, $00, $f3 ; KOFF
db $8f, $80, $f1 ; Enable IPL ROM
db $5f, $c0, $ff ; jmp $ffc0
dw $0000, $1500
dw $0000, $1500
4 changes: 3 additions & 1 deletion alttp_sm_combo_randomizer_rom/src/sram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
!SRAM_ALTTP_SPC_BUF = $a17e00 ; to $a17eff
!SRAM_ALTTP_STATS_BUF = $a17f00 ; to $a17f47
!SRAM_ALTTP_SMALLKEY_BUF = $a17f50 ; to $a17f5f

!SRAM_MSU_FALLBACK = $a17f60 ; to $a17f7f
!SRAM_MSU_SEED_DATA = $a17f80 ; to $a17f9f

!SRAM_RANDOLIVE = $a17700 ; to $a178f0

Expand All @@ -45,4 +47,4 @@
!SRAM_MW_ITEMS_SENT_WPTR = $a26682
!SRAM_MW_ITEMS_SENT = $a26700 ; [worldId, itemId, itemIndex] (need unique item index to prevent duping)

!SRAM_MW_SEED_DATA = $a266a0
!SRAM_MW_SEED_DATA = $a266a0
19 changes: 6 additions & 13 deletions alttp_sm_combo_randomizer_rom/src/z3/randomizer/msu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ CheckMusicLoadRequest:
STA.w MusicControl : STZ.w MusicControlRequest
REP #$30 : PLY : PLX : PLA : PLD : PLB : PLP
RTL

.continue
LDA.l TournamentSeed : BNE +++
LDA.w MSUPackRequest
Expand Down Expand Up @@ -243,11 +243,11 @@ CheckMusicLoadRequest:
AND.b #$07 : TAY
PLA : LSR #3 : TAX
LDA.l MSUFallbackTable,X : BEQ .secondary_fallback : CMP.b #$FF : BEQ .mute

- : CPY #$00 : BEQ +
LSR : DEY : BRA -
+

AND.b #$01 : BEQ .secondary_fallback

.mute
Expand Down Expand Up @@ -401,7 +401,7 @@ StoreMusicOnDeath:
;--------------------------------------------------------------------------------
MSUInit:
PHP

SEP #$30
LDA.b #$00
STA.w MSULoadedTrack
Expand All @@ -421,15 +421,8 @@ MSUInit:

REP #$20

LDA.w MSUID : CMP.w #!VAL_MSU_ID_01 : BEQ + : JMP .done
LDA.w MSUID+2 : CMP.w #!VAL_MSU_ID_23 : BEQ + : JMP .done
LDA.w MSUID+4 : CMP.w #!VAL_MSU_ID_45 : BEQ + : JMP .done

.done
PLP
RTL

+
; Count the number of available MSU-1 packs
LDA.w #$0000
LDX.b #$00
Expand Down Expand Up @@ -575,7 +568,7 @@ MSUMain:
+
LDA.b #!VAL_VOLUME_FULL
STA.w TargetVolume

LDA.w MSUResumeControl : BIT.b #!FLAG_RESUME_FADEIN : BEQ +
EOR.b #!FLAG_RESUME_FADEIN : STA.w MSUResumeControl
LDA.b #$00
Expand All @@ -585,7 +578,7 @@ MSUMain:
++
STA.w CurrentVolume
STA.w MSUVOL

LDA.w CurrentMSUTrack : DEC : PHA
AND.b #$07 : TAY
PLA : LSR #3 : TAX
Expand Down
Binary file modified src/Randomizer.App/Patches/zsm.ips
Binary file not shown.

0 comments on commit f20598e

Please sign in to comment.