.gba
.open "MFO.gba","mfrunbutton.gba",0x8000000

.definelabel freespace,0x879ECD0


;quieten charge sounds
;.include "MFhalfvolumecharge.asm"
;.include "MFthreequartervolumecharge.asm"



;hijack speedboostcode
.org 0x80068E4
	.word 	needbtoboost
.org 0x80068C2
	mov		r15,r0
	

;hijack
.org 0x08004F40
	ldr		r0,=fastbutton
	mov		r15,r0
.pool

.org freespace
needbtoboost:
	ldr		r0,=0x30011E8
	ldrh	r0,[r0]
	mov		r1,0x4 ;0x2 if you want B to be run button
	and		r0,r1
	cmp		r0,0
	beq		@@noboost
	ldr		r0,=0x3001310
	ldrb	r1,[r0,0xC]
	ldr		r0,=0x80068C4
	mov		r15,r0
@@noboost:
	ldr		r0,=0x8006920
	mov		r15,r0
.pool

	
fastbutton:
	ldr		r1,=0x30011E8
	ldrh	r1,[r1]
	mov		r0,0x4 ;0x2 if you want B to be run button
	and		r0,r1
	cmp		r0,0x0
	beq		@@return
;go fast
	ldr 	r1,=0x3001330
	ldrb	r0,[r1]
	cmp		r0,0x0
	bne		@@underwaterFast
;regular fast
	ldr 	r1,=0x3001330
	ldrh	r0,[r1,0x2]
	sub		r0,r0,0x1         ; amount to subtract from y acceleration
	strh	r0,[r1,0x2]
	ldrh	r0,[r1,0x8]
	add		r0,0x8            ; amount to add to midair x velocity cap
	strh	r0,[r1,0x8]
	ldrh	r0,[r1,0xA]
	add		r0,0x8            ; amount to add to midair morph x velocity cap
	strh	r0,[r1,0xA]
	ldrh	r0,[r1,0xC]
	add		r0,0x2            ; amount to add to x accel
	strh	r0,[r1,0xC]
	ldrh	r0,[r1,0xE]
	add		r0,0x20            ; amount to add to x velocity cap
	strh	r0,[r1,0xE]
	b		@@return

@@underwaterFast:
	ldr 	r1,=0x3001330
	ldrh	r0,[r1,0x2]
	sub		r0,r0,0x1         ; amount to subtract from y acceleration
	strh	r0,[r1,0x2]
	ldrh	r0,[r1,0x8]
	add		r0,0x8            ; amount to add to midair x velocity cap
	strh	r0,[r1,0x8]
	ldrh	r0,[r1,0xA]
	add		r0,0x8            ; amount to add to midair morph x velocity cap
	strh	r0,[r1,0xA]
	ldrh	r0,[r1,0xC]
	add		r0,0x2            ; amount to add to x accel
	strh	r0,[r1,0xC]
	ldrh	r0,[r1,0xE]
	add		r0,0x10            ; amount to add to x velocity cap
	strh	r0,[r1,0xE]
	b		@@return
	

@@return:
	ldrb 	r1,[r4,0xA]
	mov 	r0,0x10
	and		r0,r1
	cmp		r0,0
	beq		@@returnto08004F52
	ldr		r1,=0x8004f4a
	mov		r15,r1
@@returnto08004F52:
	ldr		r1,=0x8004f52
	mov		r15,r1
	
.pool
.close