LoRom

org $909110  	;samus terminal velocity
DW $0005 		;max fall speed samus can achieve


org $909E8B  	;damage to samus while in lava
DW $8000  		;sub-unit damage
DW $0000  		;whole unit damage

org $909E8F  	;damage to samus while in acid
DW $8000  		;sub-unit damage
DW $0001  		;whole unit damage

org $909E93
DW $0003  		;samus animation slowdown speed (in frames) while in water (no gravity suit)
org $909E95
DW $0002  		;samus animation slowdown speed (in frames) while in lava/acid (no gravity suit)

org $909E97 	;vertical speed limiter for spacejump in air
DB $80,$02 	 	;values are sub-pixel speed and pixel speed.  If vertical speed are above these values
				;you can use space jump again
org $909E99 	;vertical speed limiter for spacejump in air
DB $00,$05 	 	;values are sub-pixel speed and pixel speed.  If vertical speed meets these values
				;you can NOT use space jump again
org $909E9B 	;vertical speed limiter for spacejump in water
DB $80,$00 		;values are sub-pixel speed and pixel speed.  If vertical speed are above these values
				;you can use space jump again
org $909E9D 	;vertical speed limiter for spacejump in water
DB $00,$05 	 	;values are sub-pixel speed and pixel speed.  If vertical speed meets these values
				;you can NOT use space jump again

org $909E9F
DW $0008  		;maximum distance from a wall (in pixels) samus can be for walljump to work

org $909EA1
DW $1C00  		;vertical acceleration modifier (planet's gravity) in sub-pixels in air
org $909EA3
DW $0800  		;vertical acceleration modifier (planet's gravity) in sub-pixels in water (no gravity suit)
org $909EA5
DW $0900  		;vertical acceleration modifier (planet's gravity) in sub-pixels in lava/acid (no gravity suit)
org $909EA7
DW $0000  		;vertical acceleration modifier (planet's gravity) in pixels in air
org $909EA9
DW $0000 		;vertical acceleration modifier (planet's gravity) in pixels in water (no gravity suit)
org $909EAB
DW $0000		;vertical acceleration modifier (planet's gravity) in pixels in lava/acid (no gravity suit)

org $909EAD		;used during distance calculations for samus total movement last frame
				;adjusts vertical/horizontal screen positioning relative to samus during direction changes
				;DO NOT ADJUST THESE VALUES
DW $0001  		;this is added to total horizontal distance in pixels
DW $0000 		;same with sub-pixels
DW $0001  		;this is added to total vertical distance in pixels
DW $0000 		;same with sub-pixels

org $909EB5		;samus vertical speed in morphball, set/used during morphball bounce
DW $0001  		;pixels/frame
DW $0000 		;sub-pixels/frame

ORG $909EB9		;vertical jump acceleration pixels/frame (includes springball)
DW $0004  		;air or gravity suit
DW $0001  		;water (no gravity suit)
DW $0002  		;lava/acid (no gravity suit)

ORG $909EBF		;vertical jump acceleration sub-pixels/frame (includes springball)
DW $E000  		;air or gravity suit
DW $C000  		;water (no gravity suit)
DW $C000  		;lava/acid no gravity suit

ORG $909EC5		;vertical jump acceleration with highjump pixels/frame (includes springball)
DW $0006  		;air or gravity suit
DW $0002  		;water (no gravity suit)
DW $0003  		;lava/acid (no gravity suit)

ORG $909ECB		;vertical jump acceleration with highjump sub-pixels/frame (includes springball)
DW $0000 		;air or gravity suit
DW $8000		;water (no gravity suit)
DW $8000		;lava/acid no gravity suit

ORG $909ED1		;vertical walljump acceleration pixels/frame
DW $0004		;air or gravity suit
DW $0000 		;water (no gravity suit)
DW $0002  		;lava/acid (no gravity suit)

ORG $909ED7		;vertical walljump acceleration sub-pixels/frame
DW $A000  		;air or gravity suit
DW $4000  		;water (no gravity suit)
DW $A000  		;lava/acid no gravity suit

ORG $909EDD		;vertical walljump acceleration pixels/frame (with hijump)
DW $0005  		;air or gravity suit
DW $0000 		;water (no gravity suit)
DW $0003  		;lava/acid (no gravity suit)

ORG $909EE3		;vertical walljump acceleration sub-pixels/frame (with hijump)
DW $8000  		;air or gravity suit
DW $8000		;water (no gravity suit)
DW $8000		;lava/acid no gravity suit

ORG $909EE9		;vertical acceleration for getting hurt pixels/frame
DW $0005		;air or gravity suit
DW $0002  		;water (no gravity suit)
DW $0002  		;lava/acid no gravity suit

ORG $909EEF		;vertical acceleration for getting hurt sub-pixels/frame
DW $0000		;air or gravity suit
DW $0000		;water no gravity suit
DW $0000 		;lava/acid no gravity suit

ORG $909EF5		;diagonal/bomb jump vertical acceleration, pixels/frame (affects powerbomb jumps as well)
				;special case instructions via JSR $DDE9
DW $0002		;air or gravity suit
DW $0000		;water no gravity suit
DW $0000		;lava/acid no gravity suit
ORG $909EFB		;diagonal/bomb jump vertical acceleration, sub-pixels/frame (affects powerbomb jumps as well)
DW $C000		;air or gravity suit
DW $1000		;water no gravity suit
DW $1000		;lava/acid no gravity suit

;indexing for the following appears to be unused, x always seems to = 0
;(after looking into it further, if samus is affected by fx3, then speed is always
;set to 0000 (pixel/sub-pixel speeds) and momentum tables below (#$A08D or #$A1DD) are used)
;these unused indexed speed values appear to be unused beta holdovers that were left in
ORG $909F01		;samus running horizontal speed acceleration (pixels/frame)
DW $0000		;air or with gravity suit
DW $0000		;water no gravity suit
DW $0000		;lava/acid no gravity suit
ORG $909F07		;samus running horizontal speed acceleration (sub-pixels/frame)
DW $1000  		;air or with gravity suit
DW $0400  		;water no gravity suit
DW $0400  		;lava/acid no gravity suit
ORG $909F0D		;samus running horizontal max speed (pixels/frame) with speedboost
DW $0007		;air or with gravity suit
DW $0004		;water no gravity suit
DW $0004		;lava/acid no gravity suit
ORG $909F13		;samus running horizontal max speed (sub-pixels/frame) with speedboost
DW $0000		;air or with gravity suit
DW $0000		;water no gravity suit
DW $0000		;lava/acid no gravity suit
ORG $909F19		;samus running horizontal max speed (pixels/frame) no speedboost
DW $0002		;air or with gravity suit
DW $0001		;water no gravity suit
DW $0000		;lava/acid no gravity suit
ORG $909F1F		;samus running horizontal max speed (sub-pixels/frame) no speedboost
DW $0000		;air or with gravity suit
DW $0000		;water no gravity suit
DW $0000 		;lava/acid no gravity suit


;Momentum table entries definition
;$0000,x added to $0B46 - Samus's horizontal 'momentum' forward (pixels/frame)
;$0002,x added to $0B48 - Samus's horizontal 'momentum' forward (1/65536ths pixel/frame)
;$0004,x max $0B46 - Samus's horizontal 'momentum' forward (pixels/frame)
;$0006,x max $0B48 - Samus's horizontal 'momentum' forward (1/65536ths pixel/frame)
;$0008,x subtracted from $0B46 - Samus's horizontal 'momentum' forward (pixels/frame)
;$000A,x subtracted from $0B48 - Samus's horizontal 'momentum' forward (1/65536ths pixel/frame)
;As an example:
;    Momentum increase pixels/frame
;    |     Momentum increase sub-pixels/frame
;    |     |     Maximum horizontal momentum forward pixels/frame
;    |     |     |     Maximum horizontal momentum forward sub-pixels/frame
;    |     |     |     |     Momentum decrease pixels/frame
;    |     |     |     |     |     Momentum decrease sub-pixels/frame
;    |     |     |     |     |     |
;DW $0000,$0000,$0000,$0000,$0000,$0000


ORG $909F25		;Diagonal bomb jump horizontal momentum. Used by routine @ $908EDF
DW $0000,$3000,$0003,$0000,$0000,$0800    

;Grapple beam disconnect momentum.  Used by routine @ $909C21
;$909C44 A2 31 9F    LDX #$9F31     
;$909C51 A2 3D 9F    LDX #$9F3D                    
;$909C56 A2 49 9F    LDX #$9F49  
ORG $909F31		;Air
DW $0000,$3000,$000F,$0000,$0000,$1000 
ORG $909F3D 	;under water (no gravity suit)
DW $0000,$3000,$000F,$0000,$0000,$1000  
ORG $909F49 	;under lava/acid (no gravity suit)
DW $0000,$3000,$000F,$0000,$0000,$1000  

;JSR $9BD1  [$90:9BD1]	Set $0A6C to #$A08D if affected by water, or #$A1DD if affected by lava/acid. 
;	Also, X = ($0A1F * #$0C) + $0A6C when leaving.
;$909BFE A9 8D A0    LDA #$A08D
;$909C06 A9 DD A1    LDA #$A1DD
;entries are indexed by movement type
;The following entries set the starting point for momentum table
;storing base value to $0A6C
;$9497D0 A9 55 9F    LDA #$9F55
;$9498A5 A9 55 9F    LDA #$9F55
;$9498DC A9 55 9F    LDA #$9F55
;$949909 A9 55 9F    LDA #$9F55
;$94992F A9 55 9F    LDA #$9F55

;$90/9F55 - $90/A08C		horizontal momentum table for if samus is in air or fx3 with gravity suit
;table is cut short by 2 entries according to movement type
;doesn't seem to affect anything though as those movement types don't actually move
ORG $909F55
	AIRGRAVITYMOMENTUM:
;   Momentum increase pixels/frame
;   |     Momentum increase sub-pixels/frame
;   |     |     Maximum horizontal momentum forward pixels/frame
;   |     |     |     Maximum horizontal momentum forward sub-pixels/frame
;   |     |     |     |     Momentum decrease pixels/frame
;   |     |     |     |     |     Momentum decrease sub-pixels/frame
;   |     |     |     |     |     |
DW $0000,$C000,$0000,$0000,$0000,$8000 	 	;00 = Standing
DW $0000,$3000,$0002,$C000,$0000,$8000 	 	;01 = Walking/running
DW $0000,$C000,$0001,$4000,$0000,$8000 	 	;02 = normal jump
DW $0000,$C000,$0001,$6000,$0000,$8000 	 	;03 = spin jump
DW $0000,$C000,$0003,$4000,$0000,$8000 	 	;04 = morph ball on ground
DW $0000,$C000,$0000,$0000,$0000,$8000 	 	;05 = crouch
DW $0000,$C000,$0001,$0000,$0000,$8000 	 	;06 = falling
DW $0002,$0000,$0001,$0000,$0000,$8000 	 	;07 = Glitchy (morph ball/spinjump), unused?
DW $0000,$C000,$0001,$0000,$0000,$8000 	 	;08 = morph ball in air
DW $0002,$0000,$0002,$0000,$0000,$8000 	 	;09 = Glitchy morph ball, unused?
DW $0001,$8000,$0005,$0000,$0000,$8000 	 	;0A = Hurt
DW $0000,$C000,$0000,$0000,$0000,$8000 	 	;0B = Can fire grapple beam, not moving. (unused?)
DW $0000,$C000,$0000,$0000,$0000,$8000 	 	;0C = Can fire grapple beam and change pose, no movement. (unused?)
DW $0000,$C000,$0002,$0000,$0000,$8000 	 	;0D = Can change pose, no movement or firing. (unused?)
DW $0000,$C000,$0000,$0000,$0000,$8000 	 	;0E = Turning around
DW $0000,$C000,$0001,$4000,$0000,$8000 	 	;0F = Standing/crouching, and crouching/morphball
DW $0000,$C000,$0000,$8000,$0000,$8000 	 	;10 = Moonwalking
DW $0000,$C000,$0003,$4000,$0000,$8000 	 	;11 = spring ball on ground
DW $0000,$C000,$0001,$4000,$0000,$8000 	 	;12 = spring ball in air
DW $0000,$C000,$0001,$0000,$0000,$8000 	 	;13 = falling with spring ball
DW $0000,$C000,$0001,$6000,$0000,$8000 	 	;14 = wall jump
DW $0000,$C000,$0000,$0000,$0000,$8000 	 	;15 = Ran into a wall
DW $0000,$C000,$0001,$4000,$0000,$8000 	 	;16 = Grappling
DW $0000,$C000,$0000,$0000,$0000,$8000 	 	;17 = Turning in mid-air (jumping)
DW $0000,$C000,$0000,$0000,$0000,$8000 	 	;18 = Turning while falling?
DW $0000,$C000,$0005,$0000,$0000,$8000 		;19 = Spin back
;	missing entry							 1A = Grabbed by Draygon
;	missing entry							 1B = Superjump / Drained by Metroid / Damaged by MB's attacks / CF

;$90/A08D - $90/A1DC		horizontal momentum table for if Samus is in water
ORG $90A08D
	WATERMOMENTUM:
;   Momentum increase pixels/frame
;   |     Momentum increase sub-pixels/frame
;   |     |     Maximum horizontal momentum forward pixels/frame
;   |     |     |     Maximum horizontal momentum forward sub-pixels/frame
;   |     |     |     |     Momentum decrease pixels/frame
;   |     |     |     |     |     Momentum decrease sub-pixels/frame
;   |     |     |     |     |     |
DW $0000,$C000,$0000,$0000,$0000,$8000 	;00 = Standing
DW $0000,$0400,$0002,$C000,$0000,$8000 	;01 = Walking/running
DW $0000,$C000,$0001,$4000,$0000,$8000 	;02 = normal jump
DW $0000,$C000,$0001,$6000,$0000,$8000 	;03 = spin jump
DW $0000,$0400,$0002,$C000,$0000,$8000 	;04 = morph ball on ground
DW $0000,$C000,$0000,$0000,$0000,$8000 	;05 = crouch
DW $0000,$C000,$0001,$0000,$0000,$8000 	;06 = falling
DW $0002,$0000,$0001,$0000,$0000,$8000 	;07 = Glitchy (morph ball/spinjump), unused?
DW $0000,$0400,$0001,$8000,$0000,$8000 	;08 = morph ball in air
DW $0002,$0000,$0002,$0000,$0000,$8000 	;09 = Glitchy morph ball, unused?
DW $0001,$8000,$0005,$0000,$0000,$8000 	;0A = Hurt
DW $0000,$C000,$0000,$0000,$0000,$8000 	;0B = Can fire grapple beam, not moving. (unused?)
DW $0000,$C000,$0000,$0000,$0000,$8000 	;0C = Can fire grapple beam and change pose, no movement. (unused?)
DW $0000,$C000,$0002,$0000,$0000,$8000 	;0D = Can change pose, no movement or firing. (unused?)
DW $0000,$C000,$0000,$0000,$0000,$8000 	;0E = Turning around
DW $0000,$C000,$0001,$4000,$0000,$8000 	;0F = Standing/crouching, and crouching/morphball
DW $0000,$C000,$0000,$8000,$0000,$8000 	;10 = Moonwalking
DW $0000,$0400,$0002,$C000,$0000,$8000 	;11 = spring ball on ground
DW $0000,$0400,$0001,$4000,$0000,$8000 	;12 = spring ball in air
DW $0000,$0400,$0001,$8000,$0000,$8000 	;13 = falling with spring ball
DW $0000,$C000,$0001,$6000,$0000,$8000 	;14 = wall jump
DW $0000,$C000,$0000,$0000,$0000,$8000 	;15 = Ran into a wall
DW $0000,$C000,$0001,$4000,$0000,$8000 	;16 = Grappling
DW $0000,$C000,$0000,$0000,$0000,$8000 	;17 = Turning in mid-air (jumping)
DW $0000,$C000,$0000,$0000,$0000,$8000 	;18 = Turning while falling?
DW $0000,$C000,$0000,$8000,$0000,$8000 	;19 = Spin back
DW $0000,$C000,$0005,$0000,$0000,$8000 	;1A = Grabbed by Draygon
DW $0000,$C000,$0005,$0000,$0000,$8000 	;1B = Superjump / Drained by Metroid / Damaged by MB's attacks / CF


;$90/A1DD - $90/A32C		horizontal momentum table for if Samus is in lava/acid
ORG $90A1DD
	LAVAACIDMOMENTUM:
;   Momentum increase pixels/frame
;   |     Momentum increase sub-pixels/frame
;   |     |     Maximum horizontal momentum forward pixels/frame
;   |     |     |     Maximum horizontal momentum forward sub-pixels/frame
;   |     |     |     |     Momentum decrease pixels/frame
;   |     |     |     |     |     Momentum decrease sub-pixels/frame
;   |     |     |     |     |     |
DW $0000,$C000,$0000,$0000,$0000,$4000 	;00 = Standing
DW $0000,$0400,$0001,$C000,$0000,$4000 	;01 = Walking/running
DW $0000,$C000,$0001,$4000,$0000,$4000 	;02 = normal jump
DW $0000,$C000,$0001,$6000,$0000,$4000 	;03 = spin jump
DW $0000,$0400,$0002,$C000,$0000,$4000 	;04 = morph ball on ground
DW $0000,$C000,$0000,$0000,$0000,$4000 	;05 = crouch
DW $0000,$C000,$0001,$0000,$0000,$4000 	;06 = falling
DW $0002,$0000,$0001,$0000,$0000,$4000 	;07 = Glitchy (morph ball/spinjump), unused?
DW $0000,$0400,$0001,$6000,$0000,$4000 	;08 = morph ball in air
DW $0002,$0000,$0002,$0000,$0000,$4000 	;09 = Glitchy morph ball, unused?
DW $0001,$8000,$0005,$0000,$0000,$4000 	;0A = Hurt
DW $0000,$C000,$0000,$0000,$0000,$4000 	;0B = Can fire grapple beam, not moving. (unused?)
DW $0000,$C000,$0000,$0000,$0000,$4000 	;0C = Can fire grapple beam and change pose, no movement. (unused?)
DW $0000,$C000,$0002,$0000,$0000,$4000 	;0D = Can change pose, no movement or firing. (unused?)
DW $0000,$C000,$0000,$0000,$0000,$4000 	;0E = Turning around
DW $0000,$C000,$0001,$4000,$0000,$4000 	;0F = Standing/crouching, and crouching/morphball
DW $0000,$C000,$0000,$8000,$0000,$4000 	;10 = Moonwalking
DW $0000,$0400,$0002,$C000,$0000,$4000 	;11 = spring ball on ground
DW $0000,$0400,$0001,$4000,$0000,$4000 	;12 = spring ball in air
DW $0000,$0400,$0001,$6000,$0000,$4000 	;13 = falling with spring ball
DW $0000,$C000,$0001,$6000,$0000,$4000 	;14 = wall jump
DW $0000,$C000,$0000,$0000,$0000,$4000 	;15 = Ran into a wall
DW $0000,$C000,$0001,$4000,$0000,$4000 	;16 = Grappling
DW $0000,$C000,$0000,$0000,$0000,$4000 	;17 = Turning in mid-air (jumping)
DW $0000,$C000,$0000,$0000,$0000,$4000 	;18 = Turning while falling?
DW $0000,$C000,$0000,$8000,$0000,$4000 	;19 = Spin back
DW $0000,$C000,$0005,$0000,$0000,$4000 	;1A = Grabbed by Draygon
DW $0000,$C000,$0005,$0000,$0000,$4000	;1B = Superjump / Drained by Metroid / Damaged by MB's attacks / CF



;The following section of ASM restores proper functioning to the indexed horizontal running speeds
; starting @ $909F01.  By uncommenting the ASM below (removing the ";") you will be able to have
; different speeds for running under water and lava/acid, AND be able to tweak those in the tables above.
;As a special note however, speedboosting under lava is still not allowed.

;ORG $909741
;	JMP.w FREESPACE
	
;ORG $90F63A
;	FREESPACE:
;	LDA $09A2 : BIT #$0020 : BNE AIRSPEEDS	;check for gravity suit
;	JSL $90EC3E						;calculate samus lower boundary and put in $12
;	LDA $195E : BMI LAVACHECK		;check fx3 height, minus = lava flag, if minus check if above or below lava/acid
;	CMP $12 : BMI WATERCHECK		;if lower boundary is less than fx3 height, check fx3 water flag
;LAVACHECK:
;	LDA $1962 : BMI AIRSPEEDS		;check alternate fx3 height, if above fx3, set x to 0000 and continue as normal
;	CMP $12 : BMI LAVAACIDSPEEDS	;if lower boundary is less than fx3 height
;	BRA AIRSPEEDS
;WATERCHECK:
;	LDA $197E						;FX3 'C'. Bitflags
;	BIT #$0004 : BNE AIRSPEEDS
;WATERSPEEDS:
;	LDX #$0002 : BRA CONTINUE	
;AIRSPEEDS:
;	LDX #$0000 : BRA CONTINUE
;LAVAACIDSPEEDS:
;	LDX #$0004
;CONTINUE:
;	JMP.w $9771



;these 2 tweaks make it so that you can actually run under lava/acid now
;ORG $9081D2			;$90/81D2 9C 42 0B    STZ $0B42
;	NOP : NOP : NOP
;ORG $9081D5			;$90/81D5 9C 44 0B    STZ $0B44
;	NOP : NOP : NOP
	
