;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;To be applied with the included INIT.asm.  This just fixes a few things with the death routine   ;
;to make it look less like the game freezes when Mario dies.  It only hijacks one point, so       ;
;it shouldn't cause too much trouble.  Note that if you're using custom death music, you must     ;
;include the sound effect Mario makes when he dies (the little "bedelip" right before the music   ;
;plays), otherwise this won't work right.  Also note that if you're using custom death music that ;
;you may have to edit the "wait until Mario jumps up after he died" timer; instructions are below.;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

header
lorom

org $00D0B6	
autoclean JSL Code	;If the default freespace doesn't work, then you may have to change this to JSL
NOP
NOP
NOP

org $00F60A	;Stop the death music from playing immediatly when Mario dies.
NOP #10		;This gives the game a chance to update Mario's pose before the game temporarily
			;freezes during SPC transfer so the player won't notice that the game stopped.
org $00F61B
LDA.b #$36	;The "wait until Mario jumps up after he died" timer is modified slightly here

freecode 	;org $1D8000	;<-This is freespace that is already in the ROM.  If something else uses this,
Code:		;then you'll have to change one of them, obviously.
LDA $1496
CMP #$35	;This should be one less than the wait until Mario jumps up after he died" timer.
BNE DontChange
PHB
PHK
PLB
LDX $13BF
LDA MusicTable,x	
STA.w $1DFB
PLB
LDA.b #$FF 	;Still have no clue what the significance of this is...
STA.w $0DDA
RTL
DontChange:
STZ $19		;Recover old code
LDA #$3E
STA $13E0
RTL			;If you changed the above code to "JSL Code" then change this to RTL.

MusicTable:

db $70,$70,$70,$70,$70,$70,$70,$70,$70								;World 1, levels 001-009
db $71,$71,$71,$71,$71,$71,$71,$71									;World 2, levels 00A-011
db $72,$72,$72,$72,$72,$72,$72										;World 3, levels 012-018
db $73,$73,$73,$73,$73,$73,$73,$73,$73,$73,$73,$73,$73,$73,$73,$73	;World 4, levels 019-024 + 101-104
db $76																;World 7, level  105
db $00,$00,$00,$00,$00,$00,$00,$00,$00								;World ?, levels 106-10E
db $74,$74,$74,$74,$74,$74,$74										;World 5, levels 10F-115
db $75,$75,$75,$75,$75,$75,$75,$75,$75,$75,$75,$75					;World 6, levels 116-121
db $76,$76,$76,$76,$76,$76,$76,$76,$76,$76							;World 7, levels 122-12A
db $77,$77,$77,$77,$77,$77,$77,$77									;World 8, levels 12B-132
db $78,$78,$78,$78,$78,$78,$78,$78,$78								;World 9, levels 133-13A
db $00																;World ?, level  13B