MrDollSteak

Formerly known as 11bayerf1

Age 24
Male
Hong Kong
Seen 2 Days Ago
Posted 3 Days Ago
847 posts
10.9 Years
i have another request for abilites can u guys do ice body and magician for emerald?
Ice Body is written up at the moment but it's part of a huge set of routines so it might be a while. Magician I haven't looked into but I imagine it can go into the table that KDS did for the Life Orb thing.

So the Speed and Priority abilities are something I've had written up for awhile but since edited because of KDS and Kleenex's rewrite of the Turn Order Loader. This routine has new items included in it as well, and a few moves such as Trick Room and Tailwind.

Prankster, Gale Wings, Stall, Sand Rush, Slow Start and Quick Feet

Spoiler:
Fire Red
Spoiler:
.text
.align 2
.thumb
.thumb_func
.global TurnOrderLoader
.org 0x14CD8

Main:
	push {r4-r7, lr}
	mov r7, r10
	mov r6, r9
	mov r5, r8
	push {r5-r7}
	add sp, #0x04
	lsl r0, r0, #0x18
	lsr r0, r0, #0x18
	mov r9, r0
	lsl r1, r1, #0x18
	lsr r1, r1, #0x18
	mov r10, r1
	mov r0, #0x0
	str r0, [sp, #0x0]

#r9=UserBank
#r10=TargetBank

CheckTurn:
	cmp r2, #0x0
	bne BracketCalc
PriorityCalc:
	mov r0, r9
	bl PriorityBL
	lsl r0, r0, #0x18
	asr r3, r0, #0x18
	mov r8, r3
	mov r0, r10
	bl PriorityBL
	lsl r0, r0, #0x18
	asr r4, r0, #0x18
	mov r3, r8
	cmp r3, r4
	beq BracketCalc
	cmp r3, r4
	bge Exit @FirstBankGoesFirst
	mov r2, #0x1
	str r2, [sp, #0x0]
	b Exit @SecondBankGoesFirst
BracketCalc:
	mov r0, r9
	bl BracketBL
	mov r8, r0
	mov r0, r10
	bl BracketBL
	mov r4, r0
	mov r3, r8
	cmp r3, r4
	beq SpeedCalc
	cmp r3, r4
	bge Exit @FirstBankGoesFirst
	mov r2, #0x1
	str r2, [sp, #0x0]
	b Exit @SecondBankGoesFirst
SpeedCalc:
	mov r0, r9
	bl SpeedBL
	mov r8, r0
	mov r0, r10
	bl SpeedBL
	mov r4, r0
	mov r3, r8
	cmp r3, r4
	bne TrickRoomCheck
	bl 0x044EC8
	mov r1, #0x1
	and r0, r1
	cmp r0,	#0x0
	bne Exit
	mov r2, #0x2 @SpeedTie
	str r2, [sp, #0x0]
	b Exit
TrickRoomCheck:
	ldr r0, .TrickRoomLoc
	ldrb r0, [r0]
	cmp r0, #0x0
	beq SpeedCheck
TrickRoom:
	mov r8, r3
	mov r3, r4
	mov r4, r8
SpeedCheck:
	cmp r3, r4
	bcs Exit @FirstBankGoesFirst
	mov r2, #0x1
	str r2, [sp, #0x0]
Exit:
	ldr r0, [sp, #0x0]
	add sp, #0x4
	pop {r3-r5}
	mov r8, r3
	mov r9, r4
	mov r10, r5
	pop {r4-r7}
	pop {r1}
	bx r1

.align 2
.TrickRoomLoc: .word 0x02TRTRTR

.align 2

PriorityBL:
	mov r3, r0
LoadMenuChoice:
	ldr r0, .MenuChoiceLoc
	add r1, r3, r0
	mov r0, #0x0
	ldrb r1, [r1]
	cmp r1, #0x0
	bne Return
FightOptionChosen:
	ldr r0, .ProtectStructure
	lsl r1, r3, #0x4
	add r1, r1, r0
	ldrb r0, [r1]
	lsl r0, r0, #0x1D
	cmp r0, #0x0
	bge LoadMoveIndex
Struggle:
	mov r4, #0xA5
	b BufferMoveData
LoadMoveIndex:
	ldr r0, .Pointer
	ldr r0, [r0, #0x0]
	add r0, r3
	add r0, #0x80
	ldrb r0, [r0] @MoveSlotChosen
	lsl r0, r0, #0x1
	mov r1, #0x58
	mul r1, r3
	add r0, r0, r1
	ldr r1, .BattleData
	add r0, r0, r1
	ldrh r4, [r0, #0xC]
BufferMoveData:
	ldr r2, .MoveData
	lsl r0, r4, #0x1
	add r0, r0, r4
	lsl r0, r0, #0x2
	add r4, r0, r2
BufferBattleData:
	ldr r0, .BattleData
	add r0, #0x20
	mov r1, #0x58
	mul r1, r3
	add r0, r0, r1
	ldrb r1, [r0]
	mov r0, #0x0
PranksterCheck:
	cmp r1, #0x9F
	bne GaleWingsCheck
Prankster:
	ldrb r1, [r4, #0xA]
	cmp r1, #0x2
	bne LoadMovePriority
	mov r0, #0x1
	b LoadMovePriority
GaleWingsCheck:
	cmp r1, #0xB2
	bne LoadMovePriority
Galewings:
	ldrb r1, [r4, #0x2]
	cmp r1, #0x2
	bne LoadMovePriority
	mov r0, #0x1
LoadMovePriority:
	ldrb r1, [r4, #0x7]
	add r0, r0, r1
Return:
	bx lr

.align 2
.MenuChoiceLoc: .word 0x02023D7C
.ProtectStructure: .word 0x02023E8C
.Pointer: .word 0x02023FE8
.BattleData: .word 0x02023BE4
.MoveData: .word 0x08250C04

.align 2

BracketBL:
	push {lr}
	mov r3, r0
	mov r1, #0x58
	ldr r0, .BattleDataItem
	mul r1, r3
	add r4, r0, r1
CheckItem:
	ldrh r0, [r4, #0xE]
	cmp r0, #0xAF
	bne LoadItemEffect
EngimaBerry:
	ldr r1, .EnigmaRamLoc
	lsl r0, r3, #0x3
	sub r0, r0, r3
	lsl r0, r0, #0x2
	add r0, r0, r1
	ldrb r6, [r0, #0x7]
	ldrb r5, [r0, #0x1A]
	b QuickClawCheck
LoadItemEffect:
	bl 0x9A924
	lsl r0, r0, #0x18
	lsl r6, r0, #0x18
	ldrh r0, [r4, #0xE]
	bl 0x9A948
	lsl r0, r0, #0x18
	lsl r5, r0, #0x18
QuickClawCheck:
	cmp r6, #0x1A
	bne CustapBerryCheck
QuickClawActivationCalc:
	ldr r0, .RandomLoc
	ldrh r7, [r0]
	lsl r0, r5, #0x10
	sub r0, r0, r5
	mov r1, #0x64
	bl 0x1E4018
	cmp r7, r0
	bge StallCheck
	mov r7, #0x1
	b StoreBracket
CustapBerryCheck:
	cmp r6, #0x4D
	bne LaggingTailCheck
CustapBerry:
CheckHP:
	ldrh r0, [r4, #0x8]
	ldrh r1, [r4, #0xC]
	lsl r1, r1, #0x2
	cmp r0, r1
	bgt StallCheck
SetRamLoc:
	mov r7, #0x1
	ldr r0, .CustapBerryLoc
	strb r7, [r0]
	b StoreBracket
LaggingTailCheck:
	cmp r6, #0x4A
	bne StallCheck
LaggingTail:
	mov r0, #0x2
	neg r7, r0
	b StoreBracket
StallCheck:
	mov r7, #0x0
	ldrb r0, [r4]
	cmp r0, #0x65
	bne StoreBracket
Stall:
	mov r0, #0x1
	neg r7, r0
StoreBracket:
	mov r0, r7
PopRegister:
	pop {r1}
	bx r1
	
.align 2
.BattleDataItem: .word 0x2023C04
.EnigmaRamLoc: .word 0x2023F54
.RandomLoc: .word 0x2023E80
.CustapBerryLoc: .word 0x02CCCCCC

.align 2

SpeedBL:
	push {lr}
	add sp, #-0x4
	mov r7, r0
	mov r5, #0x58
	ldr r6, .BattleData2
	mul r5, r7
	add r6, r5, r6
	mov r5, #0x1
	str r0, [sp, #0x0]
ApplyStatBoost:
	ldrh r5, [r6, #0x6]
	ldr r2, .StatModTable
	ldrb r1, [r6, #0x1B]
	lsl r1, r1, #0x1
	add r2, r1, r2
	ldrb r0, [r2]
	mul r0, r5
	ldrb r1, [r2, #0x1]
	bl 0x1E4018
	mov r5, r0
CloudNineCheck:
	mov r0, #0x13
	mov r1, #0x0
	mov r2, #0xD
	mov r3, #0x0
	bl 0x19F18
	lsl r0, r0, #0x18
	cmp r0, #0x0
	bne NoWeather
AirLockCheck:
	mov r0, #0x0
	str r0, [sp, #0x0] 
	mov r0, #0x13
	mov r1, #0x0
	mov r2, #0x4D
	mov r3, #0x0
	bl 0x19F18
	lsl r0, r0, #0x18
	cmp r0, #0x0
	bne NoWeather
LoadWeather:
	ldr r4, .WeatherLoc
	ldrh r4, [r4]
	add r2, r2, r6
	add r2, #0x20
	ldrb r2, [r2]
RainCheck:
	mov r0, #0x7
	and r0, r4
	cmp r0, #0x0
	beq SunCheck
SwiftSwimCheck:
	cmp r2, #0x21
	beq WeatherBoost
SunCheck:
	mov r0, #0x60
	and r0, r4
	cmp r0, #0x0
	beq SandstormCheck
ChlorophyllCheck:
	cmp r2, #0x22
	beq WeatherBoost
SandstormCheck:
	mov r0, #0x18
	and r0, r4
	cmp r0, #0x0
	beq NoWeather
SandRushCheck:
	cmp r2, #0x93
	bne NoWeather
WeatherBoost:
	lsl r5, r5, #0x1
NoWeather:
	mov r2, r6
	add r2, #0x20
	ldrb r2, [r2]
SlowStartCheck:
	cmp r2, #0x71
	bne TailwindCheck
	ldr r0, .SlowStartLoc
	add r0, r0, r7
CheckTurnCounter:
	ldrb r0, [r0, #0x0]
	cmp r0, #0x0
	beq TailwindCheck
	lsr r5, r5, #0x1
TailwindCheck:
	ldr r0, .TailwindAddr
	cmp r7, #0x1
	beq EnemyTailwind
	cmp r7, #0x3
	beq EnemyTailwind
PlayerTailwind:
	b CheckFlag 
EnemyTailwind:
	add r0, #0x1
CheckFlag:
	ldrb r0, [r0, #0x0]
	cmp r0, #0x0
	beq CheckItem2
	lsl r5, r5, #0x1
CheckItem2:
	ldrh r0, [r6, #0x2e]
	cmp r0, #0xAF
	bne LoadItemEffect2
EnigmaBerry2:
	ldr r1, .EnigmaRamLoc2
	lsl r0, r7, #0x3
	sub r0, r0, r3
	lsl r0, r0, #0x2
	add r0, r0, r1
	ldrb r0, [r0, #0x7]
	b MachoBraceCheck
LoadItemEffect2:
	bl 0x9A924
	lsl r0, r0, #0x18
	lsr r0, r0, #0x18
MachoBraceCheck: 
	cmp r0, #0x18 
	bne IronBallCheck
	lsr r5, r5, #0x1
IronBallCheck:
	cmp r0, #0x47
	bne QuickPowderCheck
	lsr r5, r5, #0x1
QuickPowderCheck:
	cmp r0, #0x48
	bne ChoiceScarfCheck
	ldrh r0, [r6]
	cmp r0, #0x84
	bne ChoiceScarfCheck
	lsr r1, r5, #0x1
	add r5, r1, r5
ChoiceScarfCheck:
	cmp r0, #0x1D
	bne BadgeCheck
	bl 0x9A948
	lsl r0, r0, #0x18
	lsl r0, r0, #0x18
	cmp r0, #0x2
	bne BadgeCheck
	lsr r0, r5, #0x1
	add r5, r0, r5
BadgeCheck:
	ldr r0, .BadgeLoc
	ldr r0, [r0]
	mov r1, #0x2
	and r0, r1
	cmp r0, #0x0
	bne StatusCheck
	ldr r0, .Flag
	bl 0x6E6D0
	lsl r0, r0, #0x18
	cmp r0, #0x0
	beq StatusCheck
	mov r0, r7
	bl 0x751C4
	lsl r0, r0, #0x18
	cmp r0, #0x0
	bne StatusCheck
	mov r0, #0x6E
	mul r0, r5
	mov r1, #0x64
	bl 0x1E460C
	mov r5, r0
StatusCheck:
	ldr r0, [r6, #0x4c]
	add r6, #0x20
	ldrb r1, [r6, #0x0]
	cmp r1, #0x9B
	bne ParalysisCheck
QuickFeetCheck:
	cmp r0, #0x0
	beq ReturnSpeed
	lsl r5, r5, #0x1
	b ReturnSpeed
ParalysisCheck:
	mov r1, #0x40
	and r0, r1
	cmp r0, #0x0
	beq ReturnSpeed
	lsr r5, r5, #0x2
ReturnSpeed:
	mov r0, r5
	add sp, #0x4
	pop {r1}
	bx r1

.align 2
.BattleData2: .word 0x02023BE4
.StatModTable: .word 0x0825DEAD
.WeatherLoc: .word 0x02023F1C
.SlowStartLoc: .word 0x02SSSSSS
.TailwindAddr: .word 0x02TTTTTT
.EnigmaRamLoc2: .word 0x02023F54
.BadgeLoc: .word 0x02022B4C
.Flag: .word 0x00000822
This routine replaces the entire Turn Order calculation to make it more efficient and to work with Gyro Ball and Electro Ball. The locations for Trick Room, Custap Berry, Slow Start and Tailwind refer to free ram locations that you allocate yourself. The one for Slow Start must be the same as the other routines for the ability.

Emerald
Spoiler:
.text
.align 2
.thumb
.thumb_func
.global TurnOrderLoader
.org 0x3CF10

Main:
	push {r4-r7, lr}
	mov r7, r10
	mov r6, r9
	mov r5, r8
	push {r5-r7}
	add sp, #-0x4
	lsl r0, r0, #0x18
	lsr r0, r0, #0x18
	mov r9, r0
	lsl r1, r1, #0x18
	lsr r1, r1, #0x18
	mov r10, r1
	mov r0, #0x0
	str r0, [sp, #0x0]

#r9=UserBank
#r10=TargetBank

CheckTurn:
	cmp r2, #0x0
	bne BracketCalc
PriorityCalc:
	mov r0, r9
	bl PriorityBL
	lsl r0, r0, #0x18
	asr r3, r0, #0x18
	mov r8, r3
	mov r0, r10
	bl PriorityBL
	lsl r0, r0, #0x18
	asr r4, r0, #0x18
	mov r3, r8
	cmp r3, r4
	beq BracketCalc
	cmp r3, r4
	bge Exit @FirstBankGoesFirst
	mov r2, #0x1
	str r2, [sp, #0x0]
	b Exit @SecondBankGoesFirst
BracketCalc:
	mov r0, r9
	bl BracketBL
	mov r8, r0
	mov r0, r10
	bl BracketBL
	mov r4, r0
	mov r3, r8
	cmp r3, r4
	beq SpeedCalc
	cmp r3, r4
	bge Exit @FirstBankGoesFirst
	mov r2, #0x1
	str r2, [sp, #0x0]
	b Exit @SecondBankGoesFirst
SpeedCalc:
	mov r0, r9
	bl SpeedBL
	mov r8, r0
	mov r0, r10
	bl SpeedBL
	mov r4, r0
	mov r3, r8
	cmp r3, r4
	bne TrickRoomCheck
	bl 0x6F5CC
	mov r1, #0x1
	and r0, r1
	cmp r0,	#0x0
	bne Exit
	mov r2, #0x2 @SpeedTie
	str r2, [sp, #0x0]
	b Exit
TrickRoomCheck:
	ldr r0, .TrickRoomLoc
	ldrb r0, [r0]
	cmp r0, #0x0
	beq SpeedCheck
TrickRoom:
	mov r8, r3
	mov r3, r4
	mov r4, r8
SpeedCheck:
	cmp r3, r4
	bcs Exit @FirstBankGoesFirst
	mov r2, #0x1
	str r2, [sp, #0x0]
Exit:
	ldr r0, [sp, #0x0]
	add sp, #0x4
	pop {r3-r5}
	mov r8, r3
	mov r9, r4
	mov r10, r5
	pop {r4-r7}
	pop {r1}
	bx r1

.align 2
.TrickRoomLoc: .word 0x02TRTRTR

.align 2

PriorityBL:
	mov r3, r0
LoadMenuChoice:
	ldr r0, .MenuChoiceLoc
	add r1, r3, r0
	mov r0, #0x0
	ldrb r1, [r1]
	cmp r1, #0x0
	bne Return
FightOptionChosen:
	ldr r0, .ProtectStructure
	lsl r1, r3, #0x4
	add r1, r1, r0
	ldrb r0, [r1]
	lsl r0, r0, #0x1D
	cmp r0, #0x0
	bge LoadMoveIndex
Struggle:
	mov r4, #0xA5
	b BufferMoveData
LoadMoveIndex:
	ldr r0, .Pointer
	ldr r0, [r0, #0x0]
	add r0, r3
	add r0, #0x80
	ldrb r0, [r0] @MoveSlotChosen
	lsl r0, r0, #0x1
	mov r1, #0x58
	mul r1, r3
	add r0, r0, r1
	ldr r1, .BattleData
	add r0, r0, r1
	ldrh r4, [r0, #0xC]
BufferMoveData:
	ldr r2, .MoveData
	lsl r0, r4, #0x1
	add r0, r0, r4
	lsl r0, r0, #0x2
	add r4, r0, r2
BufferBattleData:
	ldr r0, .BattleData
	add r0, #0x20
	mov r1, #0x58
	mul r1, r3
	add r0, r0, r1
	ldrb r1, [r0]
	mov r0, #0x0
PranksterCheck:
	cmp r1, #0x9F
	bne GaleWingsCheck
Prankster:
	ldrb r1, [r4, #0xA]
	cmp r1, #0x2
	bne LoadMovePriority
	mov r0, #0x1
	b LoadMovePriority
GaleWingsCheck:
	cmp r1, #0xB2
	bne LoadMovePriority
Galewings:
	ldrb r1, [r4, #0x2]
	cmp r1, #0x2
	bne LoadMovePriority
	mov r0, #0x1
LoadMovePriority:
	ldrb r1, [r4, #0x7]
	add r0, r0, r1
Return:
	bx lr

.align 2
.MenuChoiceLoc: .word 0x0202421C
.ProtectStructure: .word 0x0202433C
.Pointer: .word 0x0202449C
.BattleData: .word 0x02024084
.MoveData: .word 0x0831C198

.align 2

BracketBL:
	push {lr}
	mov r3, r0
	mov r1, #0x58
	ldr r0, .BattleDataItem
	mul r1, r3
	add r4, r0, r1
CheckItem:
	ldrh r0, [r4, #0xE]
	cmp r0, #0xAF
	bne LoadItemEffect
EngimaBerry:
	ldr r1, .EnigmaRamLoc
	lsl r0, r3, #0x3
	sub r0, r0, r3
	lsl r0, r0, #0x2
	add r0, r0, r1
	ldrb r6, [r0, #0x7]
	ldrb r5, [r0, #0x1A]
	b QuickClawCheck
LoadItemEffect:
	bl 0xD74DC
	lsl r0, r0, #0x18
	lsl r6, r0, #0x18
	ldrh r0, [r4, #0xE]
	bl 0xD7500
	lsl r0, r0, #0x18
	lsl r5, r0, #0x18
QuickClawCheck:
	cmp r6, #0x1A
	bne CustapBerryCheck
QuickClawActivationCalc:
	ldr r0, .RandomLoc
	ldrh r7, [r0]
	lsl r0, r5, #0x10
	sub r0, r0, r5
	mov r1, #0x64
	bl 0x2E7540
	cmp r7, r0
	bge StallCheck
	mov r7, #0x1
	b StoreBracket
CustapBerryCheck:
	cmp r6, #0x4D
	bne LaggingTailCheck
CustapBerry:
CheckHP:
	ldrh r0, [r4, #0x8]
	ldrh r1, [r4, #0xC]
	lsl r1, r1, #0x2
	cmp r0, r1
	bgt StallCheck
SetRamLoc:
	mov r7, #0x1
	ldr r0, .CustapBerryLoc
	strb r7, [r0]
	b StoreBracket
LaggingTailCheck:
	cmp r6, #0x4A
	bne StallCheck
LaggingTail:
	mov r0, #0x2
	neg r7, r0
	b StoreBracket
StallCheck:
	mov r7, #0x0
	ldrb r0, [r4]
	cmp r0, #0x65
	bne StoreBracket
Stall:
	mov r0, #0x1
	neg r7, r0
StoreBracket:
	mov r0, r7
PopRegister:
	pop {r1}
	bx r1
	
.align 2
.BattleDataItem: .word 0x020240A4
.EnigmaRamLoc: .word 0x02024404
.RandomLoc: .word 0x02024330
.CustapBerryLoc: .word 0x02CCCCCC

.align 2

SpeedBL:
	push {lr}
	add sp, #-0x4
	mov r7, r0
	mov r5, #0x58
	ldr r6, .BattleData2
	mul r5, r7
	add r6, r5, r6
	mov r5, #0x1
	str r0, [sp, #0x0]
ApplyStatBoost:
	ldrh r5, [r6, #0x6]
	ldr r2, .StatModTable
	ldrb r1, [r6, #0x1B]
	lsl r1, r1, #0x1
	add r2, r1, r2
	ldrb r0, [r2]
	mul r0, r5
	ldrb r1, [r2, #0x1]
	bl 0x2E7540
	mov r5, r0
CloudNineCheck:
	mov r0, #0x13
	mov r1, #0x0
	mov r2, #0xD
	mov r3, #0x0
	bl 0x42828
	lsl r0, r0, #0x18
	cmp r0, #0x0
	bne NoWeather
AirLockCheck:
	mov r0, #0x0
	str r0, [sp, #0x0] 
	mov r0, #0x13
	mov r1, #0x0
	mov r2, #0x4D
	mov r3, #0x0
	bl 0x42828
	lsl r0, r0, #0x18
	cmp r0, #0x0
	bne NoWeather
LoadWeather:
	ldr r4, .WeatherLoc
	ldrh r4, [r4]
	add r2, r2, r6
	add r2, #0x20
	ldrb r2, [r2]
RainCheck:
	mov r0, #0x7
	and r0, r4
	cmp r0, #0x0
	beq SunCheck
SwiftSwimCheck:
	cmp r2, #0x21
	beq WeatherBoost
SunCheck:
	mov r0, #0x60
	and r0, r4
	cmp r0, #0x0
	beq SandstormCheck
ChlorophyllCheck:
	cmp r2, #0x22
	beq WeatherBoost
SandstormCheck:
	mov r0, #0x18
	and r0, r4
	cmp r0, #0x0
	beq NoWeather
SandRushCheck:
	cmp r2, #0x93
	bne NoWeather
WeatherBoost:
	lsl r5, r5, #0x1
NoWeather:
	mov r2, r6
	add r2, #0x20
	ldrb r2, [r2]
SlowStartCheck:
	cmp r2, #0x71
	bne TailwindCheck
	ldr r0, .SlowStartLoc
	add r0, r0, r7
CheckTurnCounter:
	ldrb r0, [r0, #0x0]
	cmp r0, #0x0
	beq TailwindCheck
	lsr r5, r5, #0x1
TailwindCheck:
	ldr r0, .TailwindAddr
	cmp r7, #0x1
	beq EnemyTailwind
	cmp r7, #0x3
	beq EnemyTailwind
PlayerTailwind:
	b CheckFlag 
EnemyTailwind:
	add r0, #0x1
CheckFlag:
	ldrb r0, [r0, #0x0]
	cmp r0, #0x0
	beq CheckItem2
	lsl r5, r5, #0x1
CheckItem2:
	ldrh r0, [r6, #0x2e]
	cmp r0, #0xAF
	bne LoadItemEffect2
EnigmaBerry2:
	ldr r1, .EnigmaRamLoc2
	lsl r0, r7, #0x3
	sub r0, r0, r3
	lsl r0, r0, #0x2
	add r0, r0, r1
	ldrb r0, [r0, #0x7]
	b MachoBraceCheck
LoadItemEffect2:
	bl 0xD74DC
	lsl r0, r0, #0x18
	lsr r0, r0, #0x18
MachoBraceCheck: 
	cmp r0, #0x18 
	bne IronBallCheck
	lsr r5, r5, #0x1
IronBallCheck:
	cmp r0, #0x47
	bne QuickPowderCheck
	lsr r5, r5, #0x1
QuickPowderCheck:
	cmp r0, #0x48
	bne ChoiceScarfCheck
	ldrh r0, [r6]
	cmp r0, #0x84
	bne ChoiceScarfCheck
	lsr r1, r5, #0x1
	add r5, r1, r5
ChoiceScarfCheck:
	cmp r0, #0x1D
	bne BadgeCheck
	bl 0xD7500
	lsl r0, r0, #0x18
	lsl r0, r0, #0x18
	cmp r0, #0x2
	bne BadgeCheck
	lsr r0, r5, #0x1
	add r5, r0, r5
BadgeCheck:
	ldr r0, .BadgeLoc
	ldr r0, [r0]
	ldr r1, .BadgeCheck
	and r0, r1
	cmp r0, #0x0
	bne StatusCheck
	ldr r0, .Flag
	bl 0x9D790
	lsl r0, r0, #0x18
	cmp r0, #0x0
	beq StatusCheck
	mov r0, r7
	bl 0xA6A30
	lsl r0, r0, #0x18
	cmp r0, #0x0
	bne StatusCheck
	mov r0, #0x6E
	mul r0, r5
	mov r1, #0x64
	bl 0x2E7B68
	mov r5, r0
StatusCheck:
	ldr r0, [r6, #0x4c]
	add r6, #0x20
	ldrb r1, [r6, #0x0]
	cmp r1, #0x9B
	bne ParalysisCheck
QuickFeetCheck:
	cmp r0, #0x0
	beq ReturnSpeed
	lsl r5, r5, #0x1
	b ReturnSpeed
ParalysisCheck:
	mov r1, #0x40
	and r0, r1
	cmp r0, #0x0
	beq ReturnSpeed
	lsr r5, r5, #0x2
ReturnSpeed:
	mov r0, r5
	add sp, #0x4
	pop {r1}
	bx r1

.align 2
.BattleData2: .word 0x02024084
.StatModTable: .word 0x08329D2E
.WeatherLoc: .word 0x020243CC
.SlowStartLoc: .word 0x02SSSSSS
.TailwindAddr: .word 0x02TTTTTT
.EnigmaRamLoc2: .word 0x02024404
.BadgeLoc: .word 0x02022FEC
.BadgeCheck: .word 0x023F0102
.Flag: .word 0x00000868
This routine replaces the entire Turn Order calculation to make it more efficient and to work with Gyro Ball and Electro Ball. The locations for Trick Room, Custap Berry, Slow Start and Tailwind refer to free ram locations that you allocate yourself. The one for Slow Start must be the same as the other routines for the ability.

If the command mov r10, r1 at the beginning of both routines is having trouble compiling, just set it to mov r0, r1, and once its inserted in your rom, change the hex manually of that section to 8A 46. It should be at 14CEE in Fire Red or 3CF26 in Emerald.