FASTfix

by tjb0607

Game: SMW

Description: same as FAST, but with a bugfix for 64+ speed jumps

; if you want to yoink this as uberasm for your own hack please use the other version instead
; and use the 64+ speed jump fix included in https://www.smwcentral.net/?p=section&a=details&id=24862

	LDA $0100|!addr	; \ only run in gamemode 14
	EOR #$14	; |
	ORA $9D		; | and when the game isn't paused
	BEQ +		; |
	RTL		; |
	+		; /

	PHB		; \ push old data bank to stack, and set data bank to current program bank
	PHK		; | this allows inline data using db
	PLB		; / !! WARNING!! YOU *MUST* ALWAYS PLB BEFORE YOU RTL

LDA #$70	; give p-speed
STA $13E4|!addr ;

LDA $15
BIT #$03
BEQ done
AND #$01
TAY

LDA $75    ; the logic here is a mess and im sorry
BEQ +      ; i already see a better way to implement it but it already works as is so i wont fix it
INY #2
LDA $72
BNE ++
INY #2
BRA ++
+

LDA $15
BIT #$40
BNE +
++
INY #2
BRA ++
+

LDA $13E4|!addr
CMP #$70
BNE +
++
INY #2
+         ; end very bad code

LDA speedcap,Y
BMI minus

CMP $7B
BCS done
LDY $7B
BMI done
LDA $7A
CLC
ADC #$80
STA $7A
TYA
CLV
ADC #$02
BVC +
LDA #$7F
+
STA $7B
BRA done

minus:

CMP $7B
BCC done
LDY $7B
BPL done
LDA $7A
SEC
SBC #$80
STA $7A
TYA
CLV
SBC #$02
BVC +
LDA #$80
+
STA $7B

done:
	LDA !carl_initialized	; \ check if on the ground last frame
	BNE rtl			; /

LDA $7B		; check if abs(speed) >= 60
CMP #$3C	;
BCC rtl		;
CMP #$C1	;
BCS rtl		;

	
	LDA $16			; \ check for newly pressed jump inputs
	ORA $18			; |
	BPL rtl			; /
	
	LDA $18			; \ check whether jump was a spin
	AND #$80		; |
	EOR #$80		; |
	ORA $148F|!addr		; /
	BNE +
	LDA #$01
	STA $140D|!addr		; set spin flag
	+

	LDA $7B			; \ https://smwc.me/m/smw/rom/00D2BD/
	BPL +			; | algorithm to give jump speed.
	EOR #$FF		; |
	INC A			; |
	+			; |
	LSR #2			; |
	AND #$FE		; |
	TAX			; |
	LDA $140D|!addr		; |
	BEQ +			; |
	INX			; |
	+			; |
	LDA JumpYSpeeds,x	; |
	STA $7D			; /

	LDA #$0C		; \ set player as in the air
	STA $72			; /

rtl:
LDA $72
STA !carl_initialized
	PLB
	RTL

speedcap:
  db $DD, $24, $D1, $30, $ED, $14, $F1, $10, $F9, $08
;game's usual speed caps (+1 is added to negative speeds)

JumpYSpeeds:		; X speed
	db $B0,$B6	; ±00-07 speed
	db $AE,$B4	; ±08-0F speed
	db $AB,$B2	; ±10-17 speed
	db $A9,$B0	; ±18-1F speed
	db $A6,$AE	; ±20-27 speed - running speed
	db $A4,$AB	; ±28-2F speed - (possible p-speed/flight oscillation if oscillation is unpatched)
	db $A1,$A9	; ±30-37 speed - p-speed/flight speed
	db $9F,$A6	; ±38-3F speed
	db $9C,$A3	; ±40-47 speed - diagonal pipe speed
	db $9A,$A1	; ±48-4F speed
	db $97,$9F	; ±50-57 speed
	db $95,$9C	; ±58-5F speed
	db $92,$9A	; ±60-67 speed
	db $90,$98	; ±68-6F speed
	db $8E,$96	; ±70-77 speed
	db $8B,$93	; ±78-7F speed
	db $89,$91	; -80 speed
back to listings