@include
; tweaks.asm
; Changes the song numbers for various default actions in the ROM.
; Needed because, by design, the song numbers for this program are different
; from the default in SMW.  Normally nothing but the definitions at the start
; here need to be changed, and even then that's only necessary if you've
; changed list.txt (see instructions below).
; 
; This also removes various routines that play with the music mirrors in SMW.
; The engine has changed, so there's no longer any need for most of the code.
; It all has been NOP'd out and branched over.
				
!Miss		= #$01			; If you've changed list.txt and plan on using the original SMW songs
!GameOver	= #$0A			; change these constants to whatever they are in list.txt
!BossClear	= #$0B			; For example, if you changed the "Stage Clear" music to be number 9,
!StageClear	= #$0C			; Then you'd change "!StageClear = #$04" to "!StageClear = #$09".
!Starman	= #$0D
!PSwitch	= #$0E
!Keyhole	= #$0F
!IrisOut	= #$10
!BonusEnd	= #$11
!Piano		= #$0A
!HereWeGo	= #$0B
!Water		= #$0C
!Bowser		= #$0D
!Boss		= #$0E
!Cave		= #$0F
!GhostHouse	= #$10
!Castle		= #$11
!SwitchPalace	= #$12
!Welcome	= #$13
!RescueEgg	= #$14
!Title		= #$18
!VoBAppears	= #$16
!Overworld	= #$17
!YoshisIsland	= #$18
!VanillaDome	= #$19
!StarRoad	= #$1A
!ForestOfIllusion = #$1B
!ValleyOfBowser	= #$1C
!SpecialWorld	= #$1D
!NintPresents   = #$12		; Note that this is a song, not a sound effect!
!CreditsSong1	= #$FF		; \ The three songs used for the credits sequence.
!CreditsSong2	= #$FF		; | These songs have yet to be ripped, so they are not included with AMK (they just fade the music by default).
!CreditsSong3	= #$FF		; / Change these to whatever songs you're using if you're using the default music.


org $9724		; Fix the title music
	db !Title
org $94B3
	db !RescueEgg
org $96C7
	db !Title
org $009737
	db !Bowser
org $009E18
	db $FF
org $00C526
	db !BonusEnd
org $00C9BD
	db !IrisOut
org $00D0DE
	db !GameOver
org $00E304
	db !PSwitch
org $00EEC3
	db !StageClear
org $00F60B
	db !Miss
org $018784
	db !BossClear
org $01AB08
	db !PSwitch
org $01C0F0
	db !StageClear
org $01C586
	db !Starman
org $01D04F
	db !BossClear
org $01E216
	db !Keyhole
org $01FB2E
	db !BossClear
org $028968
	db !PSwitch
org $03809D
	db !BossClear
org $0398E7
	db !BossClear
org $03A702
	db $00
org $03A7A8
	db $00
org $03A7C2
	db $00
org $03ABF4
	db $00
org $03AC53
	db $00
org $03CE9A
	db !BossClear
org $0483D2
	db !VoBAppears
org $048D8A
	db !Overworld, !YoshisIsland, !VanillaDome, !ForestOfIllusion, !ValleyOfBowser, !SpecialWorld, !StarRoad

org $048E44
	NOP : NOP : NOP

org $0491E1
	db $FF



;if read1($04DBC8) == $02 && read1($04DBC9) == $03 && read1($04DBCA) == $04 && read1($04DBCB) == $06 && read1($04DBCC) == $07 && read1($04DBCD) == $09 && read1($04DBCE) == $05 
;org $04DBC8
;	db !Overworld, !YoshisIsland, !VanillaDome, !ForestOfIllusion, !ValleyOfBowser, !SpecialWorld, !StarRoad
;endif
	
org $0584DB
	db !HereWeGo, !Cave, !Piano, !Castle, !GhostHouse, !Water, !Boss, !SwitchPalace
org $0C9447
	db !CreditsSong1
org $0CA40C
	db !CreditsSong2
org $0CA5C2
	db !CreditsSong3
	

	
	
org $009723
	LDA.b !Welcome
	STA.w $1DFB|!SA1Addr2
	
	
	
org $009734			; Skip over Bowser fight music stuff.
	BNE $05
	
	
	
	
	
	

org $008134			; Don't upload the overworld music bank.
        RTS

if read1($008176) != $5c
	
	org $008179			; Skip over the standard NMI audio port stuff.  We handle that ourselves now every loop.
		BRA Skip : NOP
		NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
	Skip:

else
	org $00817C			; For LevelNMI.  Three fewer bytes placed three bytes later.
		BRA Skip : NOP
		NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
		NOP : NOP : NOP
	Skip:
endif

org $0094A0				; Don't upload music bank 1
	BRA Skip1Point25 : NOP
Skip1Point25:
	
org $0096C3				; Don't upload music bank 1
	BRA Skip1Point5 : NOP
Skip1Point5:

org $009702				; Don't upload music bank 2...or something.
	NOP #3

org $009728					
	LDA.w $0DDA|!SA1Addr2	; 
;	NOP : NOP		; ;;;;;;;;;;COMMENTED OUT RECOMMENED BY LUI37 TO FIX
;	NOP : NOP		; ;;;;;;;;;; THE OVERWORLD ISSUE
	LDY.w $0D9B|!SA1Addr2	; 
	CPY.b #$C1		; 
	BNE CODE_009738		; 
	LDA.b !Bowser		; 
CODE_009738:			;
	STA.w $1DFB|!SA1Addr2	; 
CODE_00973B:			;
BRA +				; 
	NOP : NOP : NOP		; 
+



org $00A0B3				; Don't upload music bank 1
	BRA + : NOP : +	

org $00A635
	BRA Skip2 : NOP
	NOP : NOP : NOP
	NOP : NOP : NOP
	NOP : NOP
	NOP : NOP : NOP
	NOP : NOP
	NOP : NOP : NOP
	NOP : NOP
	NOP : NOP : NOP
	NOP : NOP
	NOP : NOP
	NOP : NOP : NOP
Skip2:	

org $00C53E
	LDA !RestoreSong
	NOP	

;org $00C53E
	
	;BRA Skip3 : NOP 
	;NOP : NOP 
	;Skip3:
	
;org $00C54C
;	BRA Skip4 : NOP
;	Skip4:
	
org $02E277
	RTS

org $03A88E
	BRA Skip5 : NOP
Skip5:
	
org $00973B
	NOP : NOP		;BRA Skip6
	STA.w $0DDA|!SA1Addr2	;NOP : NOP : NOP
Skip6:
	
org $00A645			; Related to restoring the music upon level load.
	BRA Skip7 : NOP
	NOP : NOP
	NOP : NOP : NOP
	NOP : NOP
	NOP : NOP
	NOP : NOP : NOP
Skip7:

org $00A6ED
	BRA Skip8 : NOP
	NOP : NOP
	NOP : NOP : NOP
Skip8:

;org $00E2EB
	;BRA Skip9 : NOP
	;NOP : NOP
org $00E2EE
	BRA Skip9
	NOP : NOP
	NOP : NOP
	NOP : NOP : NOP
	;NOP
Skip9:

org $01AB02
	BRA Skip10 : NOP
	NOP : NOP
Skip10:

org $01C585	; 13 bytes
	;LDA $1DFB|!SA1Addr2
	;STA $0DDA|!SA1Addr2
	LDA !Starman
	STA $1DFB|!SA1Addr2
	RTL
	
;org $01C58A
;	RTL
	
;org $01C58A
;	RTL
	
org $02E27F
	RTS
	
org $058555
	LDX $0100|!SA1Addr2
	CPX #$07
	BCC Skip11

	STA $0DDA|!SA1Addr2
	BRA Skip11 

	NOP : NOP
	NOP : NOP : NOP
Skip11:


org $00805E			; Don't upload the standard sample bank.
	NOP : NOP : NOP
	
org $0093C0
LDA.b !NintPresents
STA $1DFB|!SA1Addr2


org $049AC2
JMP OWMusicHijack		; Force music to play when fading out from an exit tile, not just from pipe/star fade-outs.

org $049882
JMP OWMusicHijack


org $04FFB1			; 5 free bytes in bank 4 required.
OWMusicHijack:
	SEP #$30		; Restore hijacked code (if it weren't for this, we could just JMP directly there...
	JMP $DBD7		; Jump to normal music changing code, which perform the RTS that we overwrote.
	








; Remap the jump SFX to $1DFC

org $00D65E
LDA #$35
STA $1DFC|!SA1Addr2

org $00DBA7 	;was org $00DBA5. These lines were edited and
;LDA #$35 		;commented out to fix the jumping from vine
STA $1DFC|!SA1Addr2

org $01D745
LDA #$1A
STA $1DF9|!SA1Addr2

org $01DB70
LDA #$1A
STA $1DF9|!SA1Addr2

org $0392B8
LDA #$1A
STA $1DF9|!SA1Addr2


