Age 25
Male
Seen August 31st, 2019
Posted August 31st, 2019
455 posts
6.3 Years
First Side Routine Rewrite
A rewrite of the pokemon turn order comparison routine during battles. It does not add any new features but decomposes the routine into a routine with 3 sub-modules which makes it easier to add new speed altering abilities and items (hooking in the original one required to make dual checks).

The rewrite also avoids redundant calculations. For example, if move priorities do not match then no need to calculate and compare effective speeds of the banked mons.
One of the sub-module returns the effective speed of the banked mon so it can readily used for accurate base power calculation of Gyro Ball and Electro Ball.


Spoiler:

.text
.align 2
.thumb
.thumb_func
.global bc_firstside_rewrite_hack
.org 0x14cD8

@MIf the modifed routine crosses x150A8 a hook will be required.
@Current Length: x220 bytes. Ends at x14f08

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 @Bank1
mov r9, r0
lsl r1, r1, #0x18
lsr r1, r1, #0x18
mov r10, r1 @Bank2
mov r0, #0x0
str r0, [sp, #0x0]

TurnModeCheck:
cmp r2, #0x0
bne SpeedCheck

CheckPriority:
mov r0, r9
bl LoadSelectionPriority
lsl r0, r0, #0x18
asr r3, r0, #0x18
mov r8, r3
mov r0, r10
bl LoadSelectionPriority
lsl r0, r0, #0x18
asr r4, r0, #0x18
mov r3, r8
cmp r3, r4
beq SpeedCheck
cmp r3, r4
bge Exit @First Bank Wins
mov r2, #0x1 @Second Bank Wins
str r2, [sp, #0x0]
b Exit

SpeedCheck:
mov r0, r9
bl BracketAlteration
mov r8, r0
mov r0, r10
bl BracketAlteration
mov r4, r0
mov r3, r8
cmp r3, r4
beq LoadBankSpeeds
cmp r3, r4
bge Exit @First Bank Wins
mov r2, #0x1 @Second Bank Wins
str r2, [sp, #0x0]
b Exit

LoadBankSpeeds:
mov r0, r9
bl GetSpeed
mov r8, r0
mov r0, r10
bl GetSpeed
mov r4, r0
mov r3, r8
cmp r3, r4
bne NoTie
bl 0x44EC8
mov r1, #0x1
and r0, r1
cmp r0, #0x0
bne Exit
mov r2, #0x2 @Speed Tied
str r2, [sp, #0x0]
b Exit

NoTie:
cmp r3, r4 @This can be Reversed for Trick Room
bcs Exit @First Bank Wins
mov r2, #0x1 @Second Bank Wins
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
LoadSelectionPriority:
mov r3, r0

LoadMenuChoice:
ldr r0, .MenuChoice
add r1, r3, r0
mov r0, #0x0
ldrb r1, [r1]
cmp r1, #0x0
bne Exit2

FightOptionChosen:
ldr r0, .ProtectStruct
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 LoadPriority

LoadMoveIndex:
ldr r0, .DP08_Pointer
ldr r0, [r0, #0x0]
add r0, r3
add r0, #0x80
ldrb r0, [r0] @Moveset Slot No. Chosen
lsl r0, r0, #0x1
mov r1, #0x58
mul r1, r3
add r0, r0, r1
ldr r1, .BattleStruct
add r0, r0, r1
ldrh r4, [r0, #0xC]

LoadPriority:
ldr r2, .MoveData
lsl r0, r4, #0x1
add r0, r0, r4
lsl r0, r0, #0x2
add r0, r0, r2
ldrb r0, [r0, #0x7]
@Gale Wings And Prankster can be added here easily

Exit2:
bx lr

.align 2
.MenuChoice: .word 0x02023D7C
.ProtectStruct: .word 0x02023E8C
.DP08_Pointer: .word 0x02023FE8
.BattleStruct: .word 0x02023Be4
.MoveData: .word 0x08250c04


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

.align 2
BracketAlteration: @Return 1 if Quick Claw activates, otherwise 0. Can be called in the

use of Quick Claw Message Battle Script
push {lr}
mov r7, #0x0
mov r3, r0
mov r1, #0x58
ldr r0, .BattleStruct2
mul r1, r3
add r4, r0, r1

CheckItem:
ldrh r0, [r4, #0x2e]
cmp r0, #0xAF
bne LoadItemEffect

EnigmaBerry:
ldr r1, .EnigmaRamArea
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 0x09A924
lsl r0, r0, #0x18
lsr r6, r0, #0x18
ldrh r0, [r4, #0x2e]
bl 0x09A948
lsl r0, r0, #0x18
lsr r5, r0, #0x18

QuickClawCheck: @Can be expanded to include Custap Berry, Lagging Tail, Stall
cmp r6, #0x1A
bne Exit3

LoadActivationChance:
ldr r0, .RandomNoLoc
ldrh r4, [r0]
lsl r0, r5, #0x10
sub r0, r0, r5
mov r1, #0x64
bl 0x1E4018
cmp r4, r0
bge Exit3
mov r7, #0x1

Exit3:
mov r0, r7

PopRegister:
pop {r1}
bx r1

.align 2
.BattleStruct2: .word 0x2023Be4
.RandomNoLoc: .word 0x2023E80
.EnigmaRamArea: .word 0x2023F54

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

.align 2
@The speed BL that can be used for Gyro Ball and Electro Ball.
@All speed abilities will go here

GetSpeed:

push {lr}
add sp, #-0x4
mov r7, r0
mov r5, #0x58
ldr r6, .BattleStruct3
mul r5, r7
add r6, r5, r6
mov r5, #0x1
str r0, [sp, #0x0]

CloudNineCheck:
mov r0, #0x13
mov r1, #0x0
mov r2, #0xD
mov r3, #0x0
bl 0x019F18
lsl r0, r0, #0x18
cmp r0, #0x0
bne CheckStat

AirLockCheck:
mov r0, #0x0
str r0, [sp, #0x0]
mov r0, #0x13
mov r1, #0x0
mov r2, #0x4D
mov r3, #0x0
bl 0x019F18
lsl r0, r0, #0x18
cmp r0, #0x0
bne CheckStat

LoadWeather:
ldr r4, .WeatherFlags
ldrh r4, [r4]
add r2, r2, r6
add r2, #0x20
ldrb r2, [r2]

CheckRain:
mov r0, #0x7
and r0, r4
cmp r0, #0x0
beq CheckSunlight
cmp r2, #0x21
beq WeatherBoost

CheckSunlight:
mov r0, #0x60
and r0, r4
cmp r0, #0x0
beq CheckStat
cmp r2, #0x22
bne CheckStat

WeatherBoost:
mov r5, #0x2

CheckStat:
MultiplySpeedAccToStat:
ldrh r3, [r6, #0x6]
mul r5, r3 @Speed
ldr r2, .StatFactors
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 r4, r0 @Speed

CheckItem2:
ldrh r0, [r6, #0x2e]
cmp r0, #0xAF
bne LoadItemEffect2

EnigmaBerry2:
ldr r1, .EnigmaRamArea2
lsl r0, r7, #0x3
sub r0, r0, r3
lsl r0, r0, #0x2
add r0, r0, r1
ldrb r0, [r0, #0x7]
b MachoCheck

LoadItemEffect2:
bl 0x09a924
lsl r0, r0, #0x18
lsr r0, r0, #0x18

MachoCheck:
cmp r0, #0x18
bne ParalysisCheck
lsr r4, r4, #0x1

ParalysisCheck:
ldr r0, [r6, #0x4C]
mov r1, #0x40
and r0, r1
cmp r0, #0x0
beq Exit4
lsr r4, r4, #0x2

Exit4:
mov r0, r4
add sp, #0x4
pop {r1}
bx r1

.align 2
.BattleStruct3: .word 0x2023Be4
.WeatherFlags: .word 0x2023F1c
.StatFactors: .word 0x825DEAD
.EnigmaRamArea2: .word 0x2023F54