lorom

;default is set to disable jump if no springball and always disable up
;however you could easily switch it to something else if you needed to
!varia = #$0001
!springball = #$0002
!morph = #$0004
!screwattack = #$0008
!gravity = #$0020
!hijump = #$0100
!spacejump = #$0200
!bombs = #$1000
!speedbooster = #$2000

!shootbutton = $09B2
!jumpbutton = $09B4
!runbutton = $09B6

;what bts for solid tiles turns the lock on/off
!onblockbts = #$0020
!offblockbts = #$0010

org $809465
	JSR $D000	;hijack

org $80D000
	LDA $09A1	
	BMI GAMESTATE
	LDA $4218	;buttons pressed
	RTS

GAMESTATE:
	LDA $0998	
	CMP #$0008	;normal gameplay
	BEQ EQUIPCHECK
	CMP #$000C	;pausing
	BEQ EQUIPCHECK
	CMP #$0012	;unpausing
	BEQ EQUIPCHECK
	CMP #$001A	;dead or dying
	BNE IGNOREDSTATE
	LDA $09A1
	AND #$7FFF
	STA $09A1
IGNOREDSTATE:
	LDA $4218	
	RTS

EQUIPCHECK:
	LDA $09A2
	AND !springball	
	BNE HASSPRINGBALL	

DISABLEJUMP:
	LDA #$FFFF
	EOR !jumpbutton	
	AND $4218	
	BRA DISABLEUP

HASSPRINGBALL:
	LDA $4218

DISABLEUP:
	AND #$F7FF
	RTS

org $949505		;jumps to the value here whenever samus vertically collides with solid blocks (lands/walks on or hits from below)
			;$9494E5 for horizontal collisions
			;normal value is $8F82
			;see kej's BlockCollisReact.txt doc for more
	DW $B1C0	;hijack

org $94B1C0
	LDA $0DC4	;current block index (nth block of room)
	TAX
	LDA $7F6402,X	;room BTS map, indexed by X to get bts for nth block
	AND #$00FF	
	CMP !onblockbts
	BEQ TURNON 
	CMP !offblockbts
	BEQ TURNOFF 
	BRA EXIT 
TURNOFF:
	LDA $09A1
	AND #$7FFF	;BMI on $09A1 will not branch, see code at $80D000
	STA $09A1
	BRA EXIT 
TURNON:
	LDA $09A1
	ORA #$8000	;BMI on $09A1 will branch, see code at $80D000
	STA $09A1
EXIT:
	JMP $8F82	;return from hijack