lorom

	
org $908526

	JSR SPEED			;Used by Morphroll patch

org $90831E
	JSR SPEED			;Used by Morphroll patch

org $908022

	JSR CHECKMORPH		;Used by Morphroll patch
	
;================================================	
	
org $91FC99	
	JSL SPINRESTART		;Used by SpinRestart patch
	RTS

org $90F63A		;I put a lot of custom ASM here, so you should check whether it's  free first
{
SPINRESTART:
	LDA $0A23
	AND #$00FF
	CMP #$0003
	BEQ ENDAIR
	CMP #$0002
	BEQ ENDAIR
	CMP #$0006
	BEQ ENDAIR
	CMP #$0014
	BEQ ENDAIR
	JSL $9098BC
ENDAIR:
	RTL
}
;================================================
{
	!underwater = #$0007
!gravity = #$0003
!jumppeak = #$0005
!item = #$0020		;gravity suit


CHECKMORPH:


	PHA
	LDA $0A1F	;movement type
	AND #$00FF
	CMP #$0004
	BEQ BALLGROUND
	CMP #$0011
	BEQ BALLGROUND
	BRA NORMAL

BALLGROUND:
	LDA $09A2
	BIT !item
	BNE GRAVITY

	LDA $195E
	BMI GRAVITY
	CMP $0AFA
	BPL GRAVITY

	LDA $0B48	;hor. momentum, spx/f
	BRA CHING
GRAVITY:
	LDA $0B48	;hor. momentum, px/f
CHING:
	BNE NORMAL
	PLA
 	LDA #$0001
	BRA BLOCK
NORMAL:
	PLA
BLOCK:
EDITED:
	STA $0A94	;frames till next animation frame
	RTS

SPEED:

	PHA
	LDA $0A1F
	AND #$00FF
	CMP #$0004
	BEQ GROUNDBALL
	CMP #$0008
	BEQ AIRBALL
	CMP #$0011
	BEQ GROUNDBALL
	CMP #$0012
	BEQ AIRBALL		;SPRINGAIR
	CMP #$0013
	BEQ AIRBALL
	BRA NORMAL 
GROUNDBALL:
	PLA
	LDA $09A2
	BIT !item
	BNE GRAVITY1

	LDA $195E
	BMI GRAVITY1
	CMP $0AFA
	BPL GRAVITY1

	LDA !underwater
	BRA CHANG
GRAVITY1:
	LDA !gravity
CHANG:
	
	SEC
	SBC $0B42	;horizontal speed in px/f
	BMI $04
	BEQ $02
	BPL EDITED
	LDA #$0001
	BRA EDITED

AIRBALL:
	PLA
	LDA $0B2E	;vertical speed in px/f
	BNE $05
	LDA !jumppeak
	BRA EDITED
	EOR #$FFFF
	AND #$000F
	LSR
	LSR
	BPL EDITED
	LDA #$0001
	BRA EDITED
}
;================================================
;TABLE FOR SPINRESTART PATCH TO FUNCTION PROPERLY:	
	
org $919EE2
	DW T00,T01,T02,T03,T04,T05,T06,T07,T08,T09,T0A,T0B,T0C,T0D,T0E,T0F
	DW T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T1A,T1B,T1C,T1D,T1E,T1F
	DW T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T2A,T2B,T2C,T2D,T2E,T2F
	DW T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T3A,T3B,T3C,T3D,T3E,T3F
	DW T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T4A,T4B,T4C,T4D,T4E,T4F
	DW T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T5A,T5B,T5C,T5D,T5E,T5F
	DW T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T6A,T6B,T6C,T6D,T6E,T6F
	DW T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T7A,T7B,T7C,T7D,T7E,T7F
	DW T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T8A,T8B,T8C,T8D,T8E,T8F
	DW T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T9A,T9B,T9C,T9D,T9E,T9F
	DW TA0,TA1,TA2,TA3,TA4,TA5,TA6,TA7,TA8,TA9,TAA,TAB,TAC,TAD,TAE,TAF
	DW TB0,TB1,TB2,TB3,TB4,TB5,TB6,TB7,TB8,TB9,TBA,TBB,TBC,TBD,TBE,TBF
	DW TC0,TC1,TC2,TC3,TC4,TC5,TC6,TC7,TC8,TC9,TCA,TCB,TCC,TCD,TCE,TCF
	DW TD0,TD1,TD2,TD3,TD4,TD5,TD6,TD7,TD8,TD9,TDA,TDB,TDC,TDD,TDE,TDF
	DW TE0,TE1,TE2,TE3,TE4,TE5,TE6,TE7,TE8,TE9,TEA,TEB,TEC,TED,TEE,TEF
	DW TF0,TF1,TF2,TF3,TF4,TF5,TF6,TF7,TF8,TF9,TFA,TFB,TFC

T00:
T9B:
DW $0000,$0100,$0026
DW $0000,$0200,$0025
DW $FFFF

T01:
T03:
T05:
T07:
TA4:
TA6:
TE0:
TE2:
TE4:
TE6:
DW $0080,$0800,$0055
DW $0080,$0010,$0057
DW $0080,$0020,$0059
DW $0080,$0000,$004B
DW $0400,$0030,$00F1
DW $0400,$0010,$00F3
DW $0400,$0020,$00F5
DW $0400,$0000,$0035
DW $0000,$0260,$0078
DW $0000,$0250,$0076
DW $0000,$0230,$0025
DW $0000,$0030,$0003
DW $0000,$0110,$000F
DW $0000,$0120,$0011
DW $0000,$0900,$000F
DW $0000,$0500,$0011
DW $0000,$0240,$004A
DW $0000,$0200,$0025
DW $0000,$0800,$0003
DW $0000,$0010,$0005
DW $0000,$0020,$0007
DW $0000,$0100,$0009
DW $FFFF

T02:
T04:
T06:
T08:
TA5:
TA7:
TE1:
TE3:
TE5:
TE7:
DW $0080,$0800,$0056
DW $0080,$0010,$0058
DW $0080,$0020,$005A
DW $0080,$0000,$004C
DW $0400,$0030,$00F2
DW $0400,$0010,$00F4
DW $0400,$0020,$00F6
DW $0400,$0000,$0036
DW $0000,$0160,$0077
DW $0000,$0150,$0075
DW $0000,$0140,$0049
DW $0000,$0100,$0026
DW $0000,$0030,$0004
DW $0000,$0210,$0010
DW $0000,$0220,$0012
DW $0000,$0A00,$0010
DW $0000,$0600,$0012
DW $0000,$0800,$0004
DW $0000,$0010,$0006
DW $0000,$0020,$0008
DW $0000,$0200,$000A
DW $FFFF

T09:
T0D:
T0F:
T11:
DW $0400,$0000,$0035
DW $0080,$0000,$0019
DW $0000,$0110,$000F
DW $0000,$0120,$0011
DW $0000,$0900,$000F
DW $0000,$0500,$0011
DW $0000,$0140,$000B
DW $0000,$0100,$0009
DW $0000,$0200,$0025
DW $0000,$0800,$0003
DW $0000,$0010,$0005
DW $0000,$0020,$0007
DW $FFFF

T0A:
T0E:
T10:
T12:
DW $0400,$0000,$0036
DW $0080,$0000,$001A
DW $0000,$0210,$0010
DW $0000,$0220,$0012
DW $0000,$0A00,$0010
DW $0000,$0600,$0012
DW $0000,$0240,$000C
DW $0000,$0200,$000A
DW $0000,$0100,$0026
DW $0000,$0800,$0004
DW $0000,$0010,$0006
DW $0000,$0020,$0008
DW $FFFF

T0B:
DW $0400,$0000,$0035
DW $0080,$0000,$0019
DW $0000,$0110,$000F
DW $0000,$0120,$0011
DW $0000,$0900,$000F
DW $0000,$0500,$0011
DW $0000,$0100,$000B
DW $0000,$0200,$0025
DW $0000,$0800,$0003
DW $0000,$0010,$0005
DW $0000,$0020,$0007
DW $FFFF

T0C:
DW $0400,$0000,$0036
DW $0080,$0000,$001A
DW $0000,$0210,$0010
DW $0000,$0220,$0012
DW $0000,$0A00,$0010
DW $0000,$0600,$0012
DW $0000,$0200,$000C
DW $0000,$0100,$0026
DW $0000,$0800,$0004
DW $0000,$0010,$0006
DW $0000,$0020,$0008
DW $FFFF

T13:
DW $0080,$0000,$0019
DW $0000,$0900,$0069
DW $0000,$0500,$006B
DW $0000,$0190,$0069
DW $0000,$01A0,$006B
DW $0000,$0200,$002F
DW $0000,$0800,$0015
DW $0000,$0400,$0017
DW $0000,$0010,$0069
DW $0000,$0020,$006B
DW $0000,$0100,$0051
DW $0000,$0040,$0013
DW $FFFF

T14:
DW $0080,$0000,$001A
DW $0000,$0A00,$006A
DW $0000,$0600,$006C
DW $0000,$0290,$006A
DW $0000,$02A0,$006C
DW $0000,$0100,$0030
DW $0000,$0800,$0016
DW $0000,$0400,$0018
DW $0000,$0010,$006A
DW $0000,$0020,$006C
DW $0000,$0200,$0052
DW $0000,$0040,$0014
DW $FFFF

T15:
T4D:
T51:
T69:
T6B:
DW $0080,$0000,$0019
DW $0000,$0900,$0069
DW $0000,$0500,$006B
DW $0000,$0190,$0069
DW $0000,$01A0,$006B
DW $0000,$0200,$002F
DW $0000,$0800,$0015
DW $0000,$0400,$0017
DW $0000,$0010,$0069
DW $0000,$0020,$006B
DW $0000,$0100,$0051
DW $0000,$00C0,$0013
DW $0000,$0080,$004D
DW $0000,$0040,$0013
DW $FFFF

T16:
T4E:
T52:
T6A:
T6C:
DW $0080,$0000,$001A
DW $0000,$0A00,$006A
DW $0000,$0600,$006C
DW $0000,$0290,$006A
DW $0000,$02A0,$006C
DW $0000,$0100,$0030
DW $0000,$0800,$0016
DW $0000,$0400,$0018
DW $0000,$0010,$006A
DW $0000,$0020,$006C
DW $0000,$0200,$0052
DW $0000,$00C0,$0014
DW $0000,$0080,$004E
DW $0000,$0040,$0014
DW $FFFF

T17:
DW $0080,$0000,$0019
DW $0400,$0000,$0037
DW $0000,$0900,$0069
DW $0000,$0500,$006B
DW $0000,$0190,$0069
DW $0000,$01A0,$006B
DW $0000,$0200,$002F
DW $0000,$0800,$0015
DW $0000,$0400,$0017
DW $0000,$0010,$0069
DW $0000,$0020,$006B
DW $0000,$0100,$0051
DW $0000,$00C0,$0013
DW $0000,$0080,$0017
DW $0000,$0040,$0013
DW $FFFF

T18:
DW $0080,$0000,$001A
DW $0400,$0000,$0038
DW $0000,$0A00,$006A
DW $0000,$0600,$006C
DW $0000,$0290,$006A
DW $0000,$02A0,$006C
DW $0000,$0100,$0030
DW $0000,$0800,$0016
DW $0000,$0400,$0018
DW $0000,$0010,$006A
DW $0000,$0020,$006C
DW $0000,$0200,$0052
DW $0000,$00C0,$0014
DW $0000,$0080,$0018
DW $0000,$0040,$0014
DW $FFFF

T19:
DW $0040,$0000,$0013
DW $0000,$0840,$0015
DW $0000,$0440,$0017
DW $0000,$0050,$0069
DW $0000,$0060,$006B
DW $0000,$0180,$0019
DW $0000,$0800,$0015
DW $0000,$0010,$0069
DW $0000,$0020,$006B
DW $0000,$0400,$0017
DW $0000,$0100,$0019
DW $0000,$0200,$001A
DW $FFFF

T1A:
DW $0040,$0000,$0014
DW $0000,$0840,$0016
DW $0000,$0440,$0018
DW $0000,$0050,$006A
DW $0000,$0060,$006C
DW $0000,$0280,$001A
DW $0000,$0800,$0016
DW $0000,$0010,$006A
DW $0000,$0020,$006C
DW $0000,$0400,$0018
DW $0000,$0200,$001A
DW $0000,$0100,$0019
DW $FFFF

T1B:
DW $0040,$0000,$0013
DW $0000,$0840,$0015
DW $0000,$0440,$0017
DW $0000,$0050,$0069
DW $0000,$0060,$006B
DW $0000,$0180,$001B
DW $0000,$0800,$0015
DW $0000,$0010,$0069
DW $0000,$0020,$006B
DW $0000,$0400,$0017
DW $0000,$0100,$001B
DW $0000,$0200,$001C
DW $FFFF

T1C:
DW $0040,$0000,$0014
DW $0000,$0840,$0016
DW $0000,$0440,$0018
DW $0000,$0050,$006A
DW $0000,$0060,$006C
DW $0000,$0280,$001C
DW $0000,$0800,$0016
DW $0000,$0010,$006A
DW $0000,$0020,$006C
DW $0000,$0400,$0018
DW $0000,$0200,$001C
DW $0000,$0100,$001B
DW $FFFF

T1D:
T1E:
DW $0800,$0000,$003D
DW $0080,$0000,$003D
T1F:
T41:
DW $0800,$0000,$003E
DW $0080,$0000,$003E
DW $0000,$0100,$001E
DW $0000,$0200,$001F
DW $FFFF

T20:
T21:
T22:
T23:
T24:
T2F:
T30:
T33:
T34:
T35:
T36:
T37:
T38:
T39:
T3A:
T3B:
T3C:
T3D:
T3E:
T3F:
T40:
T42:
T43:
T44:
T47:
T48:
T4B:
T4C:
T55:
T56:
T57:
T58:
T59:
T5A:
T5B:
T5C:
T5D:
T5E:
T5F:
T60:
T61:
T62:
T63:
T64:
T65:
T66:
T87:
T88:
T8F:
T90:
T91:
T92:
T93:
T94:
T95:
T96:
T97:
T98:
T99:
T9A:
T9C:
T9D:
T9E:
T9F:
TA0:
TA1:
TA2:
TA3:
TA8:
TA9:
TAA:
TAB:
TAC:
TAD:
TAE:
TAF:
TB0:
TB1:
TB2:
TB3:
TB4:
TB5:
TB6:
TB7:
TB8:
TB9:
TC5:
TC6:
TC9:
TCA:
TCB:
TCC:
TCD:
TCE:
TD3:
TD4:
TD5:
TD6:
TD7:
TD8:
TD9:
TDA:
TDB:
TDC:
TDD:
TDE:
TE8:
TE9:
TEA:
TEB:
TF1:
TF2:
TF3:
TF4:
TF5:
TF6:
TF7:
TF8:
TF9:
TFA:
TFB:
TFC:
	DW $FFFF

T25:
DW $0000,$0280,$001A
DW $0080,$0000,$004C
DW $0000,$0200,$0025
DW $FFFF

T26:
DW $0000,$0180,$0019
DW $0080,$0000,$004B
DW $0000,$0100,$0026
DW $FFFF

T27:
T71:
T73:
T85:
DW $0800,$0030,$00F7
DW $0800,$0010,$00F9
DW $0800,$0020,$00FB
DW $0800,$0000,$003B
DW $0200,$0000,$0043
DW $0400,$0000,$0037
DW $0080,$0000,$004B
DW $0000,$0030,$0085
DW $0000,$0100,$0001
DW $0000,$0010,$0071
DW $0000,$0020,$0073
DW $FFFF

T28:
T72:
T74:
T86:
DW $0800,$0030,$00F8
DW $0800,$0010,$00FA
DW $0800,$0020,$00FC
DW $0800,$0000,$003C
DW $0100,$0000,$0044
DW $0400,$0000,$0038
DW $0080,$0000,$004C
DW $0000,$0030,$0086
DW $0000,$0200,$0002
DW $0000,$0010,$0072
DW $0000,$0020,$0074
DW $FFFF

T29:
T2B:
T6D:
T6F:
DW $0080,$0000,$0019
DW $0000,$0900,$006D
DW $0000,$0500,$006F
DW $0000,$0200,$0087
DW $0000,$0800,$002B
DW $0000,$0400,$002D
DW $0000,$0010,$006D
DW $0000,$0020,$006F
DW $0000,$0040,$0067
DW $0000,$0100,$0029
DW $FFFF

T2A:
T2C:
T6E:
T70:
DW $0080,$0000,$001A
DW $0000,$0A00,$006E
DW $0000,$0600,$0070
DW $0000,$0100,$0088
DW $0000,$0800,$002C
DW $0000,$0400,$002E
DW $0000,$0010,$006E
DW $0000,$0020,$0070
DW $0000,$0040,$0068
DW $0000,$0200,$002A
DW $FFFF

T2D:
DW $0080,$0000,$0019
DW $0400,$0000,$0037
DW $0000,$0900,$006D
DW $0000,$0500,$006F
DW $0000,$0800,$002B
DW $0000,$0400,$002D
DW $0000,$0200,$0087
DW $0000,$0010,$006D
DW $0000,$0020,$006F
DW $0000,$0040,$0067
DW $0000,$0100,$0029
DW $FFFF

T2E:
DW $0080,$0000,$001A
DW $0400,$0000,$0038
DW $0000,$0A00,$006E
DW $0000,$0600,$0070
DW $0000,$0800,$002C
DW $0000,$0400,$002E
DW $0000,$0100,$0088
DW $0000,$0010,$006E
DW $0000,$0020,$0070
DW $0000,$0040,$0068
DW $0000,$0200,$002A
DW $FFFF

T31:
DW $0800,$0000,$003D
DW $0080,$0000,$003D
T32:
DW $0800,$0000,$003E
DW $0080,$0000,$003E
DW $0000,$0100,$0031
DW $0000,$0200,$0032
DW $FFFF

T45:
DW $0000,$0240,$0045
DW $0000,$0100,$0009
DW $0000,$0200,$0025
DW $FFFF

T46:
DW $0000,$0140,$0046
DW $0000,$0200,$000A
DW $0000,$0100,$0026
DW $FFFF

T49:
T75:
T77:
DW $0400,$0000,$0036
DW $0080,$0000,$00C0
DW $0000,$0160,$0077
DW $0000,$0150,$0075
DW $0000,$0140,$0049
DW $0000,$0200,$000A
DW $0000,$0100,$0026
DW $FFFF

T4A:
T76:
T78:
DW $0400,$0000,$0035
DW $0080,$0000,$00BF
DW $0000,$0250,$0076
DW $0000,$0260,$0078
DW $0000,$0240,$004A
DW $0000,$0100,$0009
DW $0000,$0200,$0025
DW $FFFF

T4F:
DW $0000,$0280,$0052
DW $0000,$0180,$004F
DW $0000,$0080,$004E
DW $FFFF

T50:
DW $0000,$0280,$0050
DW $0000,$0180,$0051
DW $0000,$0080,$004D
DW $FFFF

T53:
DW $0000,$0280,$0050
DW $FFFF

T54:
DW $0000,$0180,$004F
DW $FFFF

T67:
DW $0080,$0000,$0019
DW $0000,$0900,$006D
DW $0000,$0500,$006F
DW $0000,$0800,$002B
DW $0000,$0400,$002D
DW $0000,$0200,$0087
DW $0000,$0010,$006D
DW $0000,$0020,$006F
DW $0000,$0040,$0067
DW $0000,$0100,$0067
DW $FFFF

T68:
DW $0080,$0000,$001A
DW $0000,$0A00,$006E
DW $0000,$0600,$0070
DW $0000,$0800,$002C
DW $0000,$0400,$002E
DW $0000,$0100,$0088
DW $0000,$0010,$006E
DW $0000,$0020,$0070
DW $0000,$0040,$0068
DW $0000,$0200,$0068
DW $FFFF

T79:
T7B:
DW $0800,$0000,$003D
DW $0080,$0000,$007F
T7A:
T7C:
DW $0800,$0000,$003E
DW $0080,$0000,$0080
DW $0000,$0100,$007B
DW $0000,$0200,$007C
DW $FFFF

T7D:
DW $0800,$0000,$003D
T7E:
DW $0800,$0000,$003E
DW $0000,$0100,$007D
DW $0000,$0200,$007E
DW $FFFF

T7F:
DW $0800,$0000,$003D
T80:
DW $0800,$0000,$003E
DW $0000,$0100,$007F
DW $0000,$0200,$0080
DW $FFFF

T81:
DW $0040,$0000,$0013
DW $0000,$0840,$0015
DW $0000,$0440,$0017
DW $0000,$0050,$0069
DW $0000,$0060,$006B
DW $0000,$0180,$0081
DW $0000,$0800,$0015
DW $0000,$0010,$0069
DW $0000,$0020,$006B
DW $0000,$0400,$0017
DW $0000,$0100,$0081
DW $0000,$0200,$0082
DW $FFFF

T82:
DW $0040,$0000,$0014
DW $0000,$0840,$0016
DW $0000,$0440,$0018
DW $0000,$0050,$006A
DW $0000,$0060,$006C
DW $0000,$0280,$0082
DW $0000,$0800,$0016
DW $0000,$0010,$006A
DW $0000,$0020,$006C
DW $0000,$0400,$0018
DW $0000,$0200,$0082
DW $0000,$0100,$0081
DW $FFFF

T83:
DW $0400,$0000,$0037
DW $0000,$0200,$001A
DW $0000,$0010,$0069
DW $0000,$0020,$006B
DW $0000,$0040,$0013
DW $0000,$0080,$0083
DW $FFFF

T84:
DW $0400,$0000,$0038
DW $0000,$0100,$0019
DW $0000,$0010,$006A
DW $0000,$0020,$006C
DW $0000,$0040,$0014
DW $0000,$0080,$0084
DW $FFFF

T89:
TCF:
TD1:
DW $0080,$0000,$004B
DW $0000,$0900,$000F
DW $0000,$0500,$0011
DW $0400,$0000,$0035
DW $0000,$0220,$0078
DW $0000,$0210,$0076
DW $0000,$0800,$0003
DW $0000,$0010,$0005
DW $0000,$0020,$0007
DW $0000,$0200,$0025
DW $0000,$0100,$0009
DW $FFFF

T8A:
TD0:
TD2:
DW $0080,$0000,$004C
DW $0000,$0A00,$0010
DW $0000,$0600,$0012
DW $0400,$0000,$0036
DW $0000,$0120,$0077
DW $0000,$0110,$0075
DW $0000,$0800,$0004
DW $0000,$0010,$0006
DW $0000,$0020,$0008
DW $0000,$0100,$0026
DW $0000,$0200,$000A
DW $FFFF

T8B:
T8D:
TBF:
TC1:
TC3:
DW $0080,$0200,$001A
DW $0080,$0000,$004C
DW $FFFF

T8C:
T8E:
TC0:
TC2:
TC4:
DW $0080,$0100,$0019
DW $0080,$0000,$004B
DW $FFFF

TBA:
TBB:
TBC:
TBD:
TBE:
DW $0000,$0A40,$00BB
DW $0000,$0640,$00BD
DW $0000,$0240,$00BC
DW $0000,$0010,$00BB
DW $0000,$0020,$00BD
DW $0000,$0040,$00BC
DW $0000,$0200,$00BE
DW $0000,$0100,$00BE
DW $0000,$0800,$00BE
DW $0000,$0400,$00BE
DW $FFFF

TC7:
DW $0000,$0880,$00CB
DW $0000,$0090,$00CD
DW $0000,$0180,$00C9
DW $FFFF

TC8:
DW $0000,$0880,$00CC
DW $0000,$0090,$00CE
DW $0000,$0280,$00CA
DW $FFFF

TDF:
DW $0800,$0000,$00DE
DW $FFFF

TEC:
TED:
TEE:
TEF:
TF0:
DW $0000,$0940,$00ED
DW $0000,$0540,$00EF
DW $0000,$0140,$00EE
DW $0000,$0010,$00ED
DW $0000,$0020,$00EF
DW $0000,$0040,$00EE
DW $0000,$0200,$00F0
DW $0000,$0100,$00F0
DW $0000,$0800,$00F0
DW $0000,$0400,$00F0
DW $FFFF

