- 9
- Posts
- 4
- Years
- Seen Dec 15, 2021
Hi guys
I've started to study asm, so I decided to try to create some routines as training, but I bumped into a problem:
The purpose of this routine is to heal every pokémon that is not fainted (so their hp must be different from 0, useful for things such as nuzlocke challenge ROM).
The routine iterates every pokémon in the party, until it finds a pokemon with level equal to 0 (because that's impossible so the party is over) and then quit
The Flow-Chart is the following:
The code is the following:
.arm
.align 2
main:
/*
r0 -> address
r1 -> offset to add to r0
r2 -> data taken from r0 address
*/
push {r0-r2,lr}
ldr r0,pokemon_memory_start
loop:
ldrb r1,level_offset
add r0,r1
ldr r2,[r0]
cmp r2,#0
blNE finish
sub r0,r1
ldrb r1,current_HP_offset
add r0,r1
ldr r2,[r0]
sub r0,r1
cmp r2,#0
blNE restore_pokemon
add r0,#0x64
bl loop
restore_pokemon:
ldrb r1,total_HP_offset
add r0,r1
ldrh r2,[r0]
sub r0,r1
ldrb r1,current_HP_offset
add r0,r1
strh r2,[r0]
sub r0,r1
add r0,#0x64
bl loop
finish:
pop {r0-r2,pc}
.align 2
pokemon_memory_start:
.word 0x020244EC
level_offset:
.byte 0x54
current_HP_offset:
.byte 0x56
total_HP_offset:
.byte 0x58
Code explanation:
In the register r0 I load the position of the current pokemon, starting from pokemon_memory_start, wich is the position of the first pokemon in the party
Everytime I have to read current pokemon's characteristic, such as level, the code adds the corrispective offset to the r0 register and then load the data into r2
To pass to the next pokemon in the party, the code adds 0x64 to r0, wich is the size of pokemon data structure (100 bytes)
I execute the routine in Littleroot town sign placed at position (000F;000D):
'---------------
#org 0x1E7BDE
msgbox 0x81E87F2 MSG_SIGN '"ALBANOVA\n["]Città di una bellezza..."
callasm 0x8E4CF70
end
'---------
' Strings
'---------
#org 0x1E87F2
= ALBANOVA\n["]Città di una bellezza ineguagliabile".
I know that that routine is not the best way to handle only-one-dead-rule in a nuzlocke rom (because I should remove all healing items, change all pkmn center script and then it wouldn't work anyway because of healing-box), but this is only an exercise.
I'm not 100% sure,but the offset should be right.
So I have some questions:
1) Why does the game restart when I talk to the sign?
2) Can I use thumb set instead of arm set? The compiler told me that "Thumb does not support conditional execution", but I saw that on this forum someone using conditional branches with thumb.
Thanks for all
-JapaBijou
I've started to study asm, so I decided to try to create some routines as training, but I bumped into a problem:
The purpose of this routine is to heal every pokémon that is not fainted (so their hp must be different from 0, useful for things such as nuzlocke challenge ROM).
The routine iterates every pokémon in the party, until it finds a pokemon with level equal to 0 (because that's impossible so the party is over) and then quit
The Flow-Chart is the following:
Spoiler:
I don't know how to upload image online, so I attached it as thumbnails
The code is the following:
Spoiler:
.arm
.align 2
main:
/*
r0 -> address
r1 -> offset to add to r0
r2 -> data taken from r0 address
*/
push {r0-r2,lr}
ldr r0,pokemon_memory_start
loop:
ldrb r1,level_offset
add r0,r1
ldr r2,[r0]
cmp r2,#0
blNE finish
sub r0,r1
ldrb r1,current_HP_offset
add r0,r1
ldr r2,[r0]
sub r0,r1
cmp r2,#0
blNE restore_pokemon
add r0,#0x64
bl loop
restore_pokemon:
ldrb r1,total_HP_offset
add r0,r1
ldrh r2,[r0]
sub r0,r1
ldrb r1,current_HP_offset
add r0,r1
strh r2,[r0]
sub r0,r1
add r0,#0x64
bl loop
finish:
pop {r0-r2,pc}
.align 2
pokemon_memory_start:
.word 0x020244EC
level_offset:
.byte 0x54
current_HP_offset:
.byte 0x56
total_HP_offset:
.byte 0x58
Code explanation:
Spoiler:
In the register r0 I load the position of the current pokemon, starting from pokemon_memory_start, wich is the position of the first pokemon in the party
Everytime I have to read current pokemon's characteristic, such as level, the code adds the corrispective offset to the r0 register and then load the data into r2
To pass to the next pokemon in the party, the code adds 0x64 to r0, wich is the size of pokemon data structure (100 bytes)
I execute the routine in Littleroot town sign placed at position (000F;000D):
Spoiler:
'---------------
#org 0x1E7BDE
msgbox 0x81E87F2 MSG_SIGN '"ALBANOVA\n["]Città di una bellezza..."
callasm 0x8E4CF70
end
'---------
' Strings
'---------
#org 0x1E87F2
= ALBANOVA\n["]Città di una bellezza ineguagliabile".
I know that that routine is not the best way to handle only-one-dead-rule in a nuzlocke rom (because I should remove all healing items, change all pkmn center script and then it wouldn't work anyway because of healing-box), but this is only an exercise.
I'm not 100% sure,but the offset should be right.
So I have some questions:
1) Why does the game restart when I talk to the sign?
2) Can I use thumb set instead of arm set? The compiler told me that "Thumb does not support conditional execution", but I saw that on this forum someone using conditional branches with thumb.
Thanks for all
-JapaBijou