lorom

;A refiller patch by SMILEuser96. One of my more complicated ASMs, because this uses a timer and a lot of conditional branching. But it's still a fairly simple patch, if you just have a bit of ASM knowledge.
;Credit needed, or else... I'll be a sad panda or somethin'... Just give credit, 'kay?

;This patch makes Samus refill her energy, missiles, super missiles, power bombs and (optionally) reserve tanks (in that order) slowly, one item at a time.

org $9498B8	;\
DW $B600	;|Air Fool X-Ray BTS 06 and a pointer to free space. BTS 03-05 are overused :P
org $94B600	;/

	LDA $008D	;Used as a timer
	CMP #$0010	;Change this to change how fast Samus refills her stuff (lower value=faster. higher value=slower. I recommend either 10 or 20)
	BEQ Refill	;Branches to "Refill" routine if the value at 7FFA02 is the same as above CMP. In this case, 10 (hex)
	INC $008D	;Else, increase the timer.
	RTS		;Return

Refill:		;Refill routine, part 1
	LDA $09C2	;\
	CMP $09C4	;/Compares Samus's energy to her max energy
	BNE RefEnergy	;If NOT equal, go to refill her energy
	LDA $09C6	;Else, check for missiles...
	CMP $09C8
	BNE RefMissile	;Same as above BNE...
	LDA $09CA
	CMP $09CC
	BNE RefSuper	;Obvious...
	LDA $09CE
	CMP $09D0
	BNE RefPowBomb	;...
	;LDA $09D6
	;CMP $09D4
	;BNE RefReserve	;Uncomment these three commands if you want Samus to refill her reserve tanks as well. Uncomment the "INC $09D6" near the bottom too!
	BRA End		;If everything is maxed, reset timer, do nothing else and quit. (Check below)

		;Refill routine, part 2
RefEnergy:
	INC $09C2	;Increases Samus energy by 1.
	BRA End		;Then go to end. BRAnching is used to save space...

RefMissile:
	INC $09C6
	BRA End

RefSuper:
	INC $09CA
	BRA End

RefPowBomb:
	INC $09CE
	BRA End

RefReserve:
	;INC $09D6	;You must uncomment this too if you want Samus to refill her reserve tanks.

End:
	STZ $008D
	RTS		;Resets the timer, does nothing else and quits.