lorom

lorom

;Repulsion Ball by black falcon

;this is based off insom's boostball patch, with the added features to deal contact damage to enemies when boosting and bouncing off of walls if boosted at while jumping

;----------------------------------------------------------------------


!fullcharge = #$0030
;This is the amount of frames the run button must be held before the boost is fully charged.

!run = $09B6
;If you want to change the button that you use to store the boost charge, change this. Refer to Kejardon's document:
;http://jathys.zophar.net/supermetroid/kejardon/ControllerInput.txt

!chargesfx = #$0003
!donesfx = #$000B
!boostsfx = #$0034
;Values for sound effects: while charging, while fully charged, and when boosting respectively.

!boostlength = #$0020
!boost3q = #$0015
!boost2q = #$0010
!boost1q = #$0005

!fullspeed = #$0007
!3qspeed = #$0005
!2qspeed = #$0004
!1qspeed = #$0003

!fulltimer = #$0002
;This value controls how quickly Samus will lose her boost of speed. (x frames/1 decrement of speed value) 

!jump = #$0006
;This value is the max jump height's pixels.
!air = #$00FF
;This value is the max jump height in subpixels.

;----------------------------------------------------------------------


;Don't touch these!
;Most of them are pointers that will break the code if changed.


!charge = $0729
!buttons = $8B
!nofx = #$0001
!sfx = $809143
!boossfx = $8090C1
!boosttimer = $072D
!speed = $0B42
!timer = $073B
!height = $0B2E
!heightminor = $0B2C

;----------------------------------------------------------------------

org $949747
DB $0C	;$8D

org $90E5ED

JMP FREE
BACK:
STZ $0B44
STZ $0B46
STZ $0B48
STZ $0B4A
YEAH:
;original boostballcode, the code I added is below
	{
org $90980D	;secondary hijack point.

	JSR PARTTHREE


org $90ECB6	;main hijack point.

	JSR BOOSTBALL


org $90F640	;main block of code.

BOOSTBALL:
	
	JSR PARTONE
	JSR PARTUNO
	JSR PARTTWO
	LDA $09A2
	RTS
CHECK:		;Checks if Samus unmorphed while charging/holding a charge to stop fx.
	LDA !charge
	BNE UNCHARGENOPRESS
LEAVE:
	RTS
PARTONE:
	LDA $09A2	;bomb replacement
	BIT #$1000
	BEQ CHECK
	LDA $0B00
	CMP #$0007
	BNE CHECK
	LDA !charge
	CMP !fullcharge
	BEQ FULLYCHARGED
	LDA !buttons
	BIT !run
	BEQ UNCHARGENOPRESS
	INC !charge
	LDA !chargesfx
	JSL !sfx
	LDA $7EC186
	CMP #$294F
	BEQ $06
	LDX #$9C40
	JSR PALETTECHANGER
	BRA GTFO
FULLYCHARGED:
	LDA !buttons
	BIT !run
	BNE CHARGEPRESS
	STZ !charge
	LDX #$9CA0
	JSR PALETTECHANGER
	LDA !boostsfx
	JSL !boossfx
	LDA $0B36
	BNE GTFO
	LDA !boostlength
	STA !boosttimer
	RTS
CHARGEPRESS:
	LDA $7EC186
	CMP #$1615
	BEQ $06
	LDX #$9C60
	JSR PALETTECHANGER
	LDA !donesfx
	JSL !sfx
GTFO:
	RTS
UNCHARGENOPRESS:
	STZ !charge
	LDA $7EC186
	CMP #$1405
	BEQ $06
	LDX #$9CA0
	JSR PALETTECHANGER
	LDA #$0001
	JSL $809139
	RTS
PARTTWO:
	LDA !boosttimer
	BEQ ARETEEESS
	LDA !boosttimer
	CMP !boostlength
	BPL B
	LDA !boosttimer
	CMP !boost3q
	BPL C
	LDA !boosttimer
	CMP !boost2q
	BPL D
	LDA !boosttimer
	CMP !boost1q
	BPL E
	BRA ARETEEESS
B:
	LDA !fullspeed
	STA !speed
	DEC !boosttimer
	LDA #$0002
	STA $0A6E
	BRA ARETEEESS
C:
	LDA !3qspeed
	STA !speed
	DEC !boosttimer
	LDA #$0002
	STA $0A6E
	BRA ARETEEESS
D:
	LDA !2qspeed
	STA !speed
	DEC !boosttimer
	LDA #$0002
	STA $0A6E
	BRA ARETEEESS
E:
	LDA !1qspeed
	STA !speed
	DEC !boosttimer
	BRA ARETEEESS
ARETEEESS:
	RTS
PARTTHREE:
	PHA
	LDA $09A2
	BIT #$1000
	BEQ NORMAL
	LDA $0B00
	CMP #$0007
	BNE NORMAL
	LDA $0B36
	BEQ SKIP
	LDA $0DD0
	CMP #$0001
	BEQ NORMAL
SKIP:
	LDA !speed
	BEQ NERMAL
	LDA $0B36
	BNE NERMAL
	LDA !timer
	CMP !fulltimer
	BEQ FULLTIMER
	INC !timer
	PLA
	RTS
FULLTIMER:
	STZ !timer
	DEC !speed
NERMAL:
	PLA
	RTS
NORMAL:
	PLA
	STZ !speed
	RTS
PALETTECHANGER:		;The code that normally does this is in another bank and is meant to be JSRed to, so I had to copy.
	PHB
	STX $12
	LDA $0A74
	XBA
	REP #$01
	ADC $12
	TAX
	LDA #$001F
	LDY #$C180
	MVN $9B7E
	PLB
	RTS
PARTUNO:
	LDA $09A2
	BIT #$1000
	BEQ GIT
	LDA $0B00
	CMP #$0007
	BNE GIT
	LDA !height
	CMP #$0007
	BMI GIT
	LDA !jump
	STA !height
	LDA !air
	STA !heightminor
GIT:
	RTS
	}
;==================================	

FREE:			;bounce off walls

	
	LDA $0B00	;check if morphball
	CMP #$0008
	BPL +
	
	LDA $09A2
	BIT #$0002	;hijump boots
	BEQ +
	LDA $0B42
	BNE ++
+	
	STZ $0B42	;boost timer
	JMP BACK	;no bounce

++

	DEC $072D
	LDA $072D
	AND #$0005
	BEQ HERE1
	JMP YEAH
HERE1:
	LDA $0B46
	ASL
	EOR #$FFFF
	INC
	STA $0B46
	
	LDA $0B48
	ASL
	EOR #$FFFF
	INC
	STA $0B48
	
	LDA #$0001
	STA $0B4A

;	LDA $0A1E
;	AND #$00FF
;	CMP #$0004	
;	BEQ +

;	LDA $0A1E
;	AND #$FF00
;	ORA #$0004
;	BRA ++
;+	
;	LDA $0A1E
;	AND #$FF00
;	ORA #$0008
;++
;	STA $0A1E

	JSL $9098BC	;jump
	LDA $0AF6
	STA $12		;X position
	LDA $0AFA
	STA $14		;Y position
	STZ $18
	LDA #$0012
	STA $16		;type
	JSL $B4BC26	;animate dust
	LDA #$001B
	JSL $8090A3	;sound
	JMP YEAH
