• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[ASM & Hex] Ability Insertion Help

82
Posts
6
Years
Hello PC, I am trying to add MRDS Prankster, Gale Wings, Stall, Sand Rush, Slow Start and Quick Feet Routine into my rom but i am having some trouble. Here is the code:

Code:
.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 0x0203C012

.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 0x08799F24

.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 0x0203C036

.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 0x0203C024
.TailwindAddr: .word 0x0203C012
.EnigmaRamLoc2: .word 0x02023F54
.BadgeLoc: .word 0x02022B4C
.Flag: .word 0x00000822

There are several RAM locations that needed inputting. I started at 0x0203C012(Freespace starts at 0203c000) and went up every 12 bytes (c024, C036, C048). I only had to go up to C060.

Next, i had to add in my index numbers which i did.

When add the code in at the proper location(14cd8) and start the rom, it crashes at loading a battle. I cannot figure out what i am doing wrong. I have tried the debugger, it gets stuck at 14d20 which is the Branch with Link to "BracketBL". I checked bracketbl and it looks like it should branch back? I cant see a reason as to why it wouldnt.

EDIT: Ive seen the debugger say "ARM no instruction" at 0x02023C14 but thats the name to the opposing pokemon(and its not changing the bytes) so i dont see why that comes up? It doesnt before i add the routine so i do know its the routine messing with that.

Any advice would be helpful! Thank you :)
 
Last edited:
88
Posts
7
Years
  • Age 34
  • Seen Jan 16, 2020
I had this same problem, and changing how much the stack pointer (sp) is varied worked for me
Code:
Main:
	push {r4-r7, lr}
	mov r7, r10
	mov r6, r9
	mov r5, r8
	push {r5-r7}
	[B]add sp, #-0x0C[/B]

[...]

Exit:
	ldr r0, [sp]
	[B]add sp, #0xC[/B]
	pop {r3-r5}
	mov r8, r3
	mov r9, r4
	mov r10, r5
	pop {r4-r7}
	pop {r1}
	bx r1

Also, make sure the code isn't going past 0x150A8 (it probably won't, but its always good to check)
 
82
Posts
6
Years
I had this same problem, and changing how much the stack pointer (sp) is varied worked for me
Code:
Main:
	push {r4-r7, lr}
	mov r7, r10
	mov r6, r9
	mov r5, r8
	push {r5-r7}
	[B]add sp, #-0x0C[/B]

[...]

Exit:
	ldr r0, [sp]
	[B]add sp, #0xC[/B]
	pop {r3-r5}
	mov r8, r3
	mov r9, r4
	mov r10, r5
	pop {r4-r7}
	pop {r1}
	bx r1

Also, make sure the code isn't going past 0x150A8 (it probably won't, but its always good to check)

Thats so upsetting :(
I have been fiddling with this thing for a week and it took changing 1 line of code? It works, abilities work but i still need to test the items.

Thank you very much! I do appreciate the help! :)
 
88
Posts
7
Years
  • Age 34
  • Seen Jan 16, 2020
Thats so upsetting :(
I have been fiddling with this thing for a week and it took changing 1 line of code? It works, abilities work but i still need to test the items.

Thank you very much! I do appreciate the help! :)

Yeah it usually is something small like that, welcome to rom hacking :laugh-squinted: On the bright side it probably helped you understand ASM a bit more!
 
82
Posts
6
Years
Yeah it usually is something small like that, welcome to rom hacking :laugh-squinted: On the bright side it probably helped you understand ASM a bit more!

Its funny, this whole load order has taught me the most about asm. I was actually able to get a few abilities and items working before your post. I found the original redo by KDS and i was ripping code from MRDS version. Of course i replaced it with the whole MRDS load order once you came in but yeah. I dont understand what i specifically changed but ill get there. Thank you again for the help!
 
Back
Top