lorom		;Super Metroid (JU) Unheadered
			;Created by Flamestar666 on 12/13/10
			;http://Metroidconstruction.com
			;______INFORMATION
			;This patch lets you fake the heatbit in any area of the game that doesn't rely on a FX2 pointer. You can enable the heat by changing FX2 to FFFF
			;This patch also keeps you from taking damage in elevator rooms and in load stations while in the elevator poses. Letting you use this in any room with an elevator without killing yourself
			;Also another few fun features, if you turn on the fake heatbit, while in a heated room, you can jump into water you will stop taking heat damage.
			;_______END OF INFO

org $828B6D		;Address I hijacked
	JSR $F710	;Points to free space
	NOP			;NOP end of hijacked long address
org $82F710		;Free Space

	JSL $868104	;hijaccked routine. do not remove
	LDA $07DF	;ram address for FX2 pointer
	CMP #$FFFF	;check for FX2. Makes sure it's FFFF
	BNE END		;If its not, It branches to the END and resets the heat
	;__NOTE__: This part of the code checks and prevents you to from taking damage when loading in and riding the elevator. remove if needed/wanted
	LDA $0A1C	;Loads Samus's current pose. 
	BEQ NOHEAT	;If it's Zero (load/elevator pose w/o shoulders) it branches
	CMP #$009B
	BEQ NOHEAT
	;__ENDNOTE__
	;___WATER PROTECTION FROM HEAT___ REMOVE THIS TO REMOVE THE PROTECTION YOU GET FROM WATER
	LDA $0AD4
	CMP #$0007
	BEQ RESET
	LDA $0AD2
	CMP #$0001
	BEQ RESET
	;__ENDNOTE__
HEAT:	;This sets the addresses to enable the correct palette and pointers and mimics the heatbit.
	LDA $1E8B	;Loads the address of the psuedo heatbit.
	CMP #$F761	;If it's already on, It won't bother setting the palettes (if it sets it more than once, you won't glow and the game might crash)
	BEQ RUNONCE	;Branches to the rest of the code
	LDA #$0001	;loads 0001
	STA $1ED9	;timer
	LDA #$0002	;loads 0002
	STA $1EDB	;timer2
	LDA #$F0A5	;loads the correct palette pointer
	STA $1EC9	;Stores it to the first of the palette pointers	
	LDA #$E6B4	;Loads the correct palette pointer
	STA $1ECB	;Stores it to the second of the palette pointers	


RUNONCE:	;this runs all the time to keep the heat alive
	LDA #$F761	;loads the value of the heat bit into A (really any value higher than zero works. but this is the one used by the game)
	STA $1E8B	;stores to enable damage
	LDA #$00F0	;loads 00F0 into A
	STA $1E89	;stores it to enable the glow effect
	LDA #$00FF	;needed to tell you what part of the palette to affect.
	STA $1E99	;stores it
	LDA #$0182	;I'm not explaining this anymore. Don't delete anything. it's all needed from here on down
	STA $1E9B
	LDA #$C526 
	STA $1EB9
	LDA #$E379
	STA $1EBB
	RTS
NOHEAT:	
	LDA $1E83
	BNE HEAT
	STZ $1E8B
	STZ $1E89
END:
	RTS
RESET:
	LDA #$0C00		;Load palette to change to
	STA $12
	LDA #$0014		;Load tilemap size
	STA $16
	JSR $A29D		;update palettes
	LDA $0B32
	CMP #$1C00
	BEQ SUIT
	BRA NOHEAT
SUIT:
	LDA $09A2
	BIT #$0021
	BEQ HEAT
	BRA NOHEAT

org $8FFFFF
	RTS