header lorom !FreeRAM = $87 !Freespace = $3F8000 !DebugOn = $00 ; If set to $00, can't use R to change gravity at will (for debugging purposes) !DisableFlight = $00 ; If set to $01, Mario can't fly ever org $00D80C JML FixFlight org $00E3CD JSL TEST NOP org $00E482 JSL FixAnim44 NOP org $019F86 JML OffsetCarriedItem NOP #2 org $01A928 JSL FixSpinJumpDeath org $01ABBF JSL FixContactGFX NOP #2 org $01A8AC JML DefaultInteractionFix JML SpeedCheckFix org $009510 JSL CheckUp org $00953F JSL GravityImage org $009860 JSL GravityImage org $00A2D8 JSL GravityImage org $00C572 JSL CheckUp org $00CEBF JML FixCape3 org $00CF2A JML FixCape2 org $00CFC7 JSL CheckUp org $00D111 JSL FixDeath NOP org $00D600 JSL CheckDown org $00D612 JSL CheckCeiling org $00D663 JSL YSpeedsJump NOP org $00D808 JML FixCape1 org $00D8CD JML CustomGravity org $00D952 JML FixYSpeed1 org $00D9AF JSL CheckDown org $00DA33 JSL CheckDown org $00DBA0 JSL FixClimbingJump NOP org $00E830 db $0C,$0E dw $0008,$000E,$000E,$0008,$0005,$000B dw $0008,$0002,$0002,$0008,$000B,$0005 dw $0008,$000E,$000E,$0008,$0005,$000B dw $0008,$0002,$0002,$0008,$000B,$0005 dw $0008,$000E,$000E,$0008,$0005,$000B dw $0008,$0002,$0002,$0008,$000B,$0005 dw $0008,$000E,$000E,$0008,$0005,$000B dw $0008,$0002,$0002,$0008,$000B,$0005 dw $0010,$0020,$0007,$0000,$FFF0,$0008 org $00E89C db $08,$00 dw $0018,$001A,$0016,$0010,$0020,$0020 dw $0018,$001A,$0016,$0010,$0020,$0020 dw $000C,$0016,$0006,$0000,$0020,$0020 dw $000C,$0016,$0006,$0000,$0020,$0020 dw $001D,$0028,$0019,$0013,$0030,$0030 dw $001D,$0028,$0019,$0013,$0030,$0030 dw $001A,$0028,$0016,$0010,$0030,$0030 dw $001A,$0028,$0016,$0010,$0030,$0030 dw $0018,$0018,$0018,$0018,$0018,$0018 org $00EA51 JML FixYSpeed2 org $00EA92 JSL CheckCeiling org $00EC0A JSL CheckUp2 org $00ED37 JSL OnCeiling org $00ED41 JSL CeilingSound NOP #5 org $00EE2D JSL CheckGround org $00EEF2 JSL CheckDown org $00EF68 JSL HitGround NOP #9 org $00F187 JSL BlockInteractionChange org $00F44D JML MarioObjInteraction org $00F606 JSL FixDeathSpeed org $00F919 JSL CeilingSound NOP org $00FE58 JSL CheckDown org $00FE7E JSL FixDust NOP #12 org $01AA33 JML FixSpeedBoost org $01C9E3 JSL GravityImage org $029145 JSL BounceYPos NOP #21 org $029163 JSL BounceCheck NOP #3 org $02916C JML FixNoteBlock org $02D732 JSL GravityImage org $02D746 JSL GravityImage org $03B1B1 JSL CeilingSound NOP org $03B68E JSL MarioSprInteraction NOP #11 org $0485CF JSL GravityImage org $0CA7B4 JSL GravityImage reset bytes org !Freespace db "STAR" dw End-Start-$01 dw End-Start-$01^$FFFF Start: TEST: PHA LDA !FreeRAM BNE .UpsideDown PLA LDX $76 ORA $E18C,x RTL .UpsideDown PLA LDX $76 ORA $E18C,x ORA #$80 RTL CeilingSound: LDA !FreeRAM BNE .NoSound LDA #$01 STA $1DF9 .NoSound RTL CheckCeiling: LDA !FreeRAM BNE .UpsideDown LDA $77 AND #$08 RTL .UpsideDown LDA $77 AND #$04 RTL CheckGround: LDA !FreeRAM BNE .UpsideDown LDA $77 AND #$04 RTL .UpsideDown LDA $77 AND #$08 RTL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CheckDown: LDA !FreeRAM BNE .UpsideDown LDA $15 AND #$04 RTL .UpsideDown LDA $15 AND #$08 RTL CheckDown2: LDA !FreeRAM BNE .UpsideDown LDA $16 AND #$04 RTL .UpsideDown LDA $16 AND #$08 RTL CheckUp: LDA !FreeRAM BNE .UpsideDown LDA $15 AND #$08 RTL .UpsideDown LDA $15 AND #$04 RTL CheckUp2: LDA !FreeRAM BNE .UpsideDown LDA $16 AND #$08 RTL .UpsideDown LDA $16 AND #$04 RTL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; JumpHeight: db $B0,$B6,$AE,$B4,$AB,$B2,$A9,$B0 db $A6,$AE,$A4,$AB,$A1,$A9,$9F,$A6 YSpeedsJump: PHY LDA JumpHeight,x LDY !FreeRAM BEQ .Store EOR #$FF INC .Store STA $7D PLY RTL BounceYPos: LDA !FreeRAM BNE .UpsideDown LDA $16A1,x SEC SBC $00 STA $96 LDA $16A9,x SBC #$00 STA $97 LDA #$01 STA $1471 STA $1402 STZ $7D RTL .UpsideDown RTL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SpeedCheckPositive: LDA !FreeRAM BNE .UpsideDown LDA $7D BPL .LoadOne .LoadZero CLC RTS .LoadOne SEC RTS .UpsideDown LDA $7D BMI .LoadOne CLC RTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SpeedCheckNegative: LDA !FreeRAM BNE .UpsideDown LDA $7D BMI .LoadOne .LoadZero CLC RTS .LoadOne SEC RTS .UpsideDown LDA $7D BPL .LoadOne BRA .LoadZero ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MaxFallingSpeed: LDA !FreeRAM BNE .UpsideDown LDA $7D CMP MaxFallSpeed,y BCC .Return LDA MaxFallSpeed,y .Return RTS .UpsideDown LDA $7D CMP MaxFallSpeedUD,y BCS .Return LDA MaxFallSpeedUD,y RTS OffsetMarioYPos: LDA $19 BEQ .Small LDA $73 BNE .Small RTS .Small LDA !FreeRAM BNE .MoveDown REP #$20 LDA $96 SEC SBC #$0010 STA $96 SEP #$20 RTS .MoveDown REP #$20 LDA $96 CLC ADC #$0010 STA $96 SEP #$20 RTS SetCapeYSpeeds: LDA !FreeRAM BNE .UpsideDown LDA CapeYSpeeds,y CMP $7D BEQ .Set BMI .Set RTS .Set STA $7D PLA PLA RTS .UpsideDown LDA CapeYSpeedsUD,y CMP $7D BEQ .Set BPL .Set RTS Compare1: LDA !FreeRAM BNE .UpsideDown LDA $7D BMI .Set CMP CapeYSpeeds,y BCC .Set BRA .Clear .UpsideDown LDA $7D BPL .Set CMP CapeYSpeedsUD,y BCS .Set .Clear CLC RTS .Set SEC RTS Compare2: PHA LDA !FreeRAM BNE .UpsideDown PLA LDX CapeYSpeeds,y BPL .Set BRA .Clear .UpsideDown PLA LDX CapeYSpeedsUD,y BPL .Set .Clear CLC RTS .Set SEC RTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; OnCeiling: LDA #$08 TSB $77 LDA !FreeRAM BEQ .NotUpsideDown STZ $140D STZ $18B5 STZ $74 STZ $1406 STZ $72 STZ $1697 .NotUpsideDown RTL HitGround: LDA !FreeRAM BNE .UpsideDown STZ $140D STZ $18B5 STZ $74 STZ $1406 STZ $72 RTL .UpsideDown LDA #$01 STA $1DF9 RTL Index: db $10,$D4,$10,$E8 CapeYOffsets: db $13,$06,$06,$06 db $06,$06,$06,$EE db $EE,$EE,$EE,$00 db $00,$00,$00,$00 CapeYOffsetsDucking: db $13,$06,$06,$06 db $06,$06,$06,$F9 db $F9,$F9,$F9,$00 db $00,$00,$00,$00 ReturnAAAA: RTL GravityImage_FixAnim: LDA $0301,y CLC ADC #$06 STA $0301,y LDA $0305,y SEC SBC #$1A STA $0305,y RTL GravityImage: JSL $00E2BD LDA $1497 BEQ .Start LSR #3 PHX TAX LDA $00E292,x PLX AND $1497 ORA $9D ORA $13FB BEQ ReturnAAAA .Start LDA !FreeRAM BEQ ReturnAAAA LDA $78 BNE ReturnAAAA LDX $13F9 LDA.l Index,x TAY LDA $0309,y SEC SBC #$0B STA $0309,y LDA $13E0 CMP #$3D BEQ .FixAnim LDA $19 BEQ .YOffset LDA $13E0 CMP #$0C BNE .SkipFix .FixShoe LDA $030D,y SEC SBC #$1A STA $030D,y BRA .YOffset .SkipFix LDA $13E0 CMP #$16 BEQ .FixShoe .YOffset REP #$20 LDA $80 CMP #$00E0 SEP #$20 BCS + LDA $0301,y CLC ADC #$10 STA $0301,y + LDA $0305,y SEC SBC #$10 STA $0305,y LDA $19 BEQ .Skip TYX DEC $0301,x DEC $0301,x DEC $0305,x DEC $0305,x .Skip LDA $19 CMP #$02 BEQ .Cape RTL .Cape LDX $13DF LDA $1470 BNE .FixItemPose .Back LDA $73 BNE .Ducking LDA $0311,y SEC SBC.l CapeYOffsets,x .Shared2 STA $0311,y RTL .Ducking LDA $0311,y SEC SBC.l CapeYOffsetsDucking,x BRA .Shared2 .FixItemPose LDA $13E0 CMP #$0F BNE .Back LDA $0311,y SEC SBC #$10 BRA .Shared2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FixDust: LDA !FreeRAM BNE .UpsideDown LDA $96 ADC #$1A PHX LDX $187A BEQ .aaaa ADC #$10 .aaaa STA $17C4,y PLX RTL .UpsideDown LDA $96 SEC SBC #$02 STA $17C4,y RTL ClimbJumpHeightUD: db $50,$10 FixClimbingJump: LDA !FreeRAM BNE .UpsideDown LDA $DABB,y STA $7D RTL .UpsideDown PHX TYX LDA.l ClimbJumpHeightUD,x PLX STA $7D RTL FixDeath: PHB PHK PLB JSR DeathLabel PLB LDA $13 RTL FixDeathSpeed: PHY LDA #$90 LDY !FreeRAM BEQ .Normal LDA #$70 .Normal STA $7D PLY RTL FixNoteBlock: LDA $1699,x CMP #$02 BNE .Return LDA #$A0 PHY LDY !FreeRAM BEQ .Skip LDA #$60 .Skip PLY STA $7D LDA !FreeRAM BNE .Change REP #$20 DEC $96 DEC $96 SEP #$20 JML $02917D .Change REP #$20 INC $96 INC $96 SEP #$20 JML $02917D .Return JML $029182 FixCape1: LDA !FreeRAM BNE .UpsideDown LDA $7D BMI + JML $00D80C + - JML $00D811 .UpsideDown LDA $7D BPL - JML $00D80C FixCape2: LDA !FreeRAM BNE .UpsideDown LDA $7D BMI + JML $00CF2E + - JML $00CF2F .UpsideDown LDA $7D BPL - JML $00CF2E FixCape3: PHA LDA !FreeRAM BNE .UpsideDown PLA BIT $7D BPL + JML $00CEC3 + - JML $00CECD .UpsideDown PLA BIT $7D BMI - JML $00CEC3 BounceCheck: LDA !FreeRAM BNE .UpsideDown LDA $16C9,x AND #$03 CMP #$03 RTL .UpsideDown LDA $16C9,x RTL FixYSpeed1: LDA !FreeRAM BNE .UpsideDown LDA $7D BPL + JML $00D956 + - JML $00D958 .UpsideDown LDA $7D BMI - JML $00D956 FixYSpeed2: LDA !FreeRAM BNE .UpsideDown LDA $7D BMI + JML $00EA55 + - JML $00EA65 .UpsideDown LDA $7D BPL - JML $00EA55 Anim44YOff: db $FB,$00,$00,$00 db $FB,$00,$00,$00 db $FB,$00,$00,$00 db $FB,$00,$00,$00 db $0E,$00,$00,$00 db $EE,$00,$00,$00 Anim44YOffFalling: db $10,$00,$00,$00 db $10,$00,$00,$00 db $10,$00,$00,$00 db $10,$00,$00,$00 db $0E,$00,$00,$00 db $EE,$00,$00,$00 Anim15YOff: db $EF,$00,$00,$00 db $EF,$00,$00,$00 db $EF,$00,$00,$00 db $EF,$00,$00,$00 db $0E,$00,$00,$00 db $EE,$00,$00,$00 FixAnim44: PHA LDA !FreeRAM BEQ .Return LDA $19 CMP #$02 BNE .Return LDA $13E0 CMP #$44 BEQ .Start LDA $74 BNE .FixClimb .Return PLA STA $0301,y REP #$20 RTL .Start LDA $13DF CMP #$07 BCS .FixFalling PLA PHB PHK PLB CPY #$16 BNE + REP #$20 LDA $80 CMP #$00E0 SEP #$20 BCS .Shared + CLC ADC Anim44YOff,y .Shared PLB STA $0301,y REP #$20 RTL .FixFalling PLA PHB PHK PLB CLC ADC Anim44YOffFalling,y BRA .Shared .FixClimb PLA PHB PHK PLB CLC ADC Anim15YOff,y BRA .Shared FixSpeedBoost: LDA !FreeRAM BNE .UpsideDown LDA $74 BNE .Return LDA #$D0 BIT $15 BPL .Store LDA #$A8 .Store STA $7D .Return RTL .UpsideDown LDA $74 BNE .Return LDA #$30 BIT $15 BPL .Store LDA #$58 BRA .Store FixFlight: LDA #!DisableFlight BNE + LDA !FreeRAM BNE + LDA $149F BEQ + JML $00D814 + JML $00D811 DefaultInteractionFix: PHA LDA !FreeRAM BNE .UpsideDown PLA SBC $D4 BMI + JML $01A8B0 + - JML $01A8E6 .UpsideDown PLA SBC $D4 BPL - JML $01A8B0 SpeedCheckFix: LDA !FreeRAM BNE .UpsideDown LDA $7D BPL + JML $01A8B4 + - JML $01A8C0 .UpsideDown LDA $7D BMI - JML $01A8B4 FixContactGFX: PHA LDA !FreeRAM BNE .UpsideDown PLA CLC ADC $96 .Shared STA $17C4,y RTL .UpsideDown PLA CLC ADC $96 SEC SBC #$18 BRA .Shared OffsetCarriedItem: LDA !FreeRAM BNE .UpsideDown .Return LDA $64 PHA LDA $1419 JML $019F8C .UpsideDown LDA $D3 STA $D8,x LDA $D4 STA $14D4,x BRA .Return FixSpinJumpDeath: LDA #$F8 LDY !FreeRAM BEQ .Norm LDA #$08 .Norm STA $7D RTL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; YAcceleration: db $06,$03,$04,$10,$F4,$01,$03,$04 db $05,$06 MaxFallSpeed: db $40,$40,$20,$40,$40,$40,$40,$40 db $40,$40 MaxFallSpeedUD: db $C0,$C0,$E0,$C0,$C0,$C0,$C0,$C0 db $C0,$C0 CapeYSpeeds: db $10,$C8,$E0,$02,$03,$03,$04,$03 db $02,$00,$01,$00,$00,$00,$00 CapeYSpeedsUD: db $F0,$38,$20,$FE,$FD,$FD,$FC,$FD db $FE,$00,$FF,$00,$00,$00,$00 DATA_00D7C8: db $01,$10,$30,$30,$38,$38,$40 CapeSpeed: db $FF,$01,$01,$FF,$FF DATA_00D7D4: db $01,$06,$03,$01,$00 DATA_00D7D9: db $00,$00,$00,$F8,$F8,$F8,$F4,$F0 db $C8,$02,$01 CustomGravity: LDA $18 AND #$10 BEQ + LDA $87 EOR #$01 STA $87 LDA #$0B STA $1DF9 + PHB PHK PLB JSR RealRoutine PLB JML $00D94E RealRoutine: LDA $72 BEQ .OnGround LDX #$00 ;$00D8D1 | LDA $187A ;$00D8D3 | BEQ .Label1337 ;$00D8D6 | LDA $141E ;$00D8D8 | LSR ;$00D8DB | BEQ .Label1337 ;$00D8DC | LDY #$02 ;$00D8DE | CPY $19 ;$00D8E0 | BEQ .Label69 ;$00D8E2 | INX ;$00D8E4 | .Label69 BRA .Label1 .Label1337 LDA $19 CMP #$02 BNE .NoCape LDA $72 CMP #$0C BNE .NotFlyingUp LDA !FreeRAM BNE .NotFlyingUp LDY #$01 CPY $149F BCC .Label1 INC $149F .NotFlyingUp LDY #$00 .Label1 LDA $14A5 BNE .AlreadyFloating LDA $15,x BPL .NoFloat LDA #$10 STA $14A5 .AlreadyFloating JSR SpeedCheckPositive BCS .GoingDown JSR Compare2 BCS .Label2 JSR Compare1 BCC .Label2 .GoingDown JSR SetCapeYSpeeds .NoFloat .Label2 CPY #$02 BEQ Label3 .NoCape .OnGround LDY #$01 LDA $15 BMI Label3 DeathLabel: LDY #$00 Label3: JSR SpeedCheckNegative BCS .StillRising JSR MaxFallingSpeed LDX $72 BEQ .OnGround2 CPX #$0B BNE .StillRising LDX #$24 STX $72 .OnGround2 .StillRising PHA LDA !FreeRAM BEQ .NormalGravity PLA SEC SBC YAcceleration,y STA $7D BRA Return .NormalGravity PLA CLC ADC YAcceleration,y SetYSpeed: STA $7D Return: RTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; YDispInteraction: db $08,$00 dw $0008,$000A,$0006,$0000,$0010,$0010 dw $0008,$000A,$0006,$0000,$0010,$0010 dw $000C,$0016,$0006,$0000,$0020,$0020 dw $000C,$0016,$0006,$0000,$0020,$0020 dw $001D,$0028,$0019,$0013,$0030,$0030 dw $001D,$0028,$0019,$0013,$0030,$0030 dw $001A,$0028,$0016,$0010,$0030,$0030 dw $001A,$0028,$0016,$0010,$0030,$0030 dw $0018,$0018,$0018,$0018,$0018,$0018 MarioObjInteraction: LDA !FreeRAM BNE .UpsideDown INX #2 REP #$20 LDA $94 CLC ADC $E830,x STA $9A LDA $96 CLC ADC $E89C,x STA $98 SEP #$20 JML $00F461 .UpsideDown PHB PHK PLB INX #2 REP #$20 LDA $94 CLC ADC $00E830,x STA $9A LDA $96 CLC ADC YDispInteraction,x STA $98 SEP #$20 PLB JML $00F461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MarioYDisp: db $06,$14,$10,$18 MarioYDispUD: dw $06,$30,$10,$18 MarioSprInteraction: PHB PHK PLB LDA !FreeRAM BNE .UpsideDown LDA $96 CLC ADC MarioYDisp,x .Shared STA $01 LDA $97 ADC #$00 STA $09 PLB RTL .UpsideDown LDA $96 CLC ADC MarioYDispUD,x STA $01 LDA $97 ADC #$00 STA $09 PLB RTL BlockInteractionUD: db $0C,$04,$0C,$04,$0C,$0F,$04,$04 db $04,$04,$04,$04,$04,$04,$04,$04 db $04,$04,$04,$04,$04,$04,$04,$04 db $04,$03,$03,$04,$04,$04,$04,$04 db $04,$08,$04,$04 BlockInteractionChange: PHA LDA $13E8 BNE .Norm LDA !FreeRAM BNE .UpsideDown .Norm PLA AND.l $00F0A4,x RTL .UpsideDown PLA AND.l BlockInteractionUD,x RTL End: print bytes