Skip to content

Commit 6bf843e

Browse files
committed
Create Zelda3.asm
1 parent e9a7512 commit 6bf843e

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

Zelda3.asm

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
MSU_STATUS = $2000
2+
MSU_READ = $2001
3+
MSU_ID = $2002
4+
MSU_SEEK = $2000
5+
MSU_TRACK = $2004
6+
MSU_VOLUME = $2006
7+
MSU_CONTROL = $2007
8+
SCRATCH_MSU_VOL = $00C2
9+
SCRATCH_MSU_DEC = $00C3
10+
11+
lorom
12+
13+
ORG $04EC1C
14+
CheckForMSU: ;Is the MSU-1 chip present? If not, then go to PullAAndPlay()
15+
PHA ;Push A onto the stack
16+
LDA MSU_ID ;Load the MSU-ID's address
17+
CMP #$53 ; 'S'
18+
BNE PullAAndPlay ;MSU-1 not detected.
19+
20+
MSUFound: ;We have an MSU-1 chip detected, so let's use it.
21+
PLA ;Pull A off the stack
22+
SEP #$30 ;Set registers to 8-bit
23+
STZ SCRATCH_MSU_DEC ;stop any fade out that we might be doing
24+
STA $0130 ;Store our BGM command
25+
CMP #$F1 ;Is the command to fade out?
26+
BEQ PlayNonMSUTrack ;If so, call FadeOut()
27+
CMP #$F2 ;Is it to set to half volume?
28+
BEQ HalfVol ;If so, call HalfVol()
29+
CMP #$F3 ;Is it to set to full volume?
30+
BEQ FullVol ;If so, call FullVol()
31+
CMP #$08 ;Is it the mirror warp sound?
32+
BEQ PlayNonMSUTrack ;Don't play the mirror warp sound over MSU because we're not going to have it.
33+
STA MSU_TRACK ;If it is none of the above special commands, then tell the MSU-1 what track to look for.
34+
PHA ;Push A
35+
STZ $2005 ;Clear $2005 so that the MSU-1 will load the new track
36+
LDA #$FF ;Load max volume into A
37+
STA MSU_VOLUME ;Set volume to max
38+
loop:
39+
BIT MSU_STATUS ;Wait for the MSU-1 to finish seeking
40+
BVS loop ;BVS loop (?)
41+
LDA #$03 ;
42+
STA MSU_CONTROL ; Set audio state to play, with repeat.
43+
LDA #$F1 ;
44+
STA $2140 ;If the audio track is not missing, then
45+
STA $0133 ;we need to mute the game audio
46+
; We need to status check here. If the track is no good, then we need to branch to PlayNonMSUTrack
47+
LDA MSU_STATUS ;Load A into MSU_Status
48+
AND #$08 ;AND the error bit
49+
BNE PullAAndPlay ;If the error bit is set, the audio track is missing
50+
PLA ;Pull A off the stack
51+
RTL ;Return to where we were in code
52+
53+
PullAAndPlay:
54+
PLA ;Pull A off the stack
55+
BRA PlayNonMSUTrack ;Play the non-MSU track
56+
57+
PlayNonMSUTrack:
58+
STA $2140 ;Load the bgm command normally into $2140
59+
STA $0133 ;Also set it here
60+
PHA ;Push A onto the stack
61+
LDA #$00 ;
62+
STA MSU_CONTROL ;Make the MSU-1 stop playing audio
63+
PLA ;Pull A off the stack
64+
RTL ;Return
65+
66+
FadeOut:
67+
;lda MSU_VOLUME ;This doesn't work and causes problems. So I'm just going to cut the music out entirely when I get the fade out command until I can fix it.
68+
;sbc #$0F
69+
;sta MSU_VOLUME
70+
;sta SCRATCH_MSU_VOL
71+
;lda #$0F
72+
;sta SCRATCH_MSU_DEC
73+
LDA #$00 ;Load the lowest volume setting
74+
STA MSU_VOLUME ;Set the volume of the MSU-1
75+
RTL ;Return
76+
77+
HalfVol:
78+
STA $2140 ;
79+
STA $0133 ;Send the fade out command to the SPU
80+
LDA #$7F ;Load the half volume setting
81+
STA MSU_VOLUME ;Set the volume of the MSU-1
82+
STA SCRATCH_MSU_VOL ;Store this value to the Scrach RAM for the MSU volume
83+
RTL ;Go play the non-MSU-1 track
84+
85+
FullVol:
86+
STA $2140 ;
87+
STA $0133 ;Send the fade out command to the SPU
88+
LDA #$FF ;Load the full volume setting
89+
STA MSU_VOLUME ;Set the volume of the MSU-1
90+
STA SCRATCH_MSU_VOL ;Store this value tot he scractch RAM for the MSU volume
91+
RTL ;Go play the non-MSU-1 track
92+
93+
;Single hijack point for playing music
94+
ORG $0080F3
95+
JSL CheckForMSU
96+
NOP
97+
NOP
98+
99+
ORG $0080FD ;Overwrites the game's efforts to write a track number itself.
100+
NOP
101+
NOP
102+
NOP

0 commit comments

Comments
 (0)