Registrarse

[ASM] Check STAT

MetalKaktus

A la luz del quinto día, mira al este
Miembro insignia
CHECK STAT

Es una rutina realmente sencilla que es muy fácil de usar. Su función es decir si una determinada caracteristica de un determinado Pokemon de equipo es menor, igual o superior a un valor a determinar.

Parámetros recividos:

Variable 0x8003: Slot del Pokemon en el equipo (0x0 para el primero y 0x5 para el sexto)

Variable 0x8004: Característica a analizar, a continuación dejo una tabla

Variable 0x8005: Valor al que comparar la estadística

----------------------------------------------------------------------

Parametros devueltos:

Variable 0x8003 Devuelve 0x0 si la estadistica del Pokemon es menor a nuestro valor, 0x1 si es igual y 0x2 si es mayor
0x0: Max PS
0x1: Attack
0x2: Defense
0x3: Speed
0x4: Special Attack
0x5: Special Defense

Rutina para Fire Red USA:

Código:
//Check STATS
//Esta rutina comprueba si un determinado stat de un determinado Pokemon
//del equipo es menor, igual o mayor a un valor a determinar

.text
.align 2
.thumb

main:
	push {r0-r2,lr}
	ldr r0, var_8003
	ldrh r0, [r0] //slot del Pokemon
	mov r1, #0x64
	mul r0, r1
	ldr r1, firstpokemon
	add r0, r0, r1
	add r0, r0, #0x58 //offset de max PS
	ldr r1, var_8004
	ldrh r1, [r1]
	lsl r1, r1, #0x2
	add r0, r0, r1
	ldrh r0, [r0] //valor de la estadística deseada
	ldr r1, var_8005
	ldrh r1, [r1] //parámetro al que comparar la estadística
	cmp r0, r1
	beq equal
	cmp r0, r1
	blo minus
	mov r0, #0x2
	b end	


equal:
	mov r0, #0x1
	b end

minus:
	mov r0, #0x0
	
end:
	ldr r1, var_8003
	strh r0, [r1]
	pop {r0-r2,pc}

.align 2
	var_8003:	.word 0x020370BE
	var_8004:	.word 0x020370C0
	var_8005:	.word 0x020370C2
	firstpokemon:	.word 0x02024284
Créditos @Turambar por la rutina

Como siempre dejo los offsets que haya usado para que puedan ser editados para poder usar la rutina en otras ROMs.

Script de ejemplo:

Código:
#dynamic 0x800000
#org @start
...
setvar 0x8003 0x0
setvar 0x8004 0x2
setvar 0x8005 0xA
callasm 0x(offset de la rutina +1)
compare 0x8003 0x0
if 0x1 call @minus
compare 0x8003 0x1
if 0x1 call @equal
compare 0x8003 0x2
if 0x1 call @plus
...
Cualquier duda, cualquier sugerencia, cualquier cosa comentad sin miedo ;)
 
Última edición:

Naren Jr.

Puto amo
Usuario de Platino
Respuesta: GBA | ASM | Check STAT

No mames, ¿cómo que nadie comenta estas cosas?

Realmente es un detalle muy hermoso para sacar pequeñas cosas y ser mas dinamico y mas realista con ciertos detalles.

A decir verdad un tiempo busque algo similar para según el los stats en los que estaban los Pokémon decirle: "Tu Pokémon tiene un ataque de maravilla, pero debes refozar esto..."

Es muy genial, gracias por compartirlo!!!
 

MACHINE

Space Cowboy
Respuesta: GBA | ASM | Check STAT

No mames, ¿cómo que nadie comenta estas cosas?

Realmente es un detalle muy hermoso para sacar pequeñas cosas y ser mas dinamico y mas realista con ciertos detalles.

A decir verdad un tiempo busque algo similar para según el los stats en los que estaban los Pokémon decirle: "Tu Pokémon tiene un ataque de maravilla, pero debes refozar esto..."

Es muy genial, gracias por compartirlo!!!
Bueno, tal vez sea por que la comunidad de WaH! esta mas inactiva que nunca : ( Es triste la verdad...

Gracias @Turambar

Es un genial aporte, con pequeñas cosas como esta, se logran grandes resultados ^^
 

Eddie

U Got Woomy
Respuesta: GBA | ASM | Check STAT

Y es por esto que muchos hack son únicos,por los pequeños detalles como este.

Un buen aporte de parte tuya,se me hace gracioso que digas (créditos a @Turambar por la rutina) xD.

Bueno sigue asi.
 

jiangzhengwenjz

Usuario mítico
Hi, i just took a glance at your routine and i think some points need to be improved obviously.
1. When you write a C function (e.g. something to be called by callasm script command), you never need to push r0-r3, as they're assumed to be 'temporary variables' and other functions won't need their value.
You even don't need to push the LR (aka. r14) here, because it's never changed. so you don't need to push and pop anything. What you need is just a 'bx lr' when you want to 'return'.
2.
Código:
mov r2, #0x2 
mul r1, r2
This is not good coding habit, as we can use LSL opcode instead, which is much faster to be executed.
3. in all three cases you have
Código:
ldr r1, var_8003
strh r0, [r1]
so why not put them under label 'end'?

Anyway it's still nice work to practise on your own!
 
Última edición:

MetalKaktus

A la luz del quinto día, mira al este
Miembro insignia
Hi, i just took a glance at your routine and i think some points need to be improved obviously.
1. When you write a C function (e.g. something to be called by callasm script command), you never need to push r0-r3, as they're assumed to be 'temporary variables' and other functions won't need their value.
You even don't need to push the LR (aka. r14) here, because it's never changed. so you don't need to push and pop anything. What you need is just a 'bx lr' when you want to 'return'.
2.
Código:
mov r2, #0x2 
mul r1, r2
This is not good coding habit, as we can use LSL opcode instead, which is much faster to be executed.
3. in all three cases you have
Código:
ldr r1, var_8003
strh r0, [r1]
so why not put them under label 'end'?

Anyway it's still nice work to practise on your own!
I've seen the routine and realize that u're right. I really appreciate you to show me how to optimize it.

Of course I've already change it.
 

jiangzhengwenjz

Usuario mítico
I've seen the routine and realize that u're right. I really appreciate you to show me how to optimize it.

Of course I've already change it.
Hi.
LSL with the immediate number 1 is already 2x, so you should have put #1 instead of your #0x2.

And as I've mentioned, you don't need push and pop here. What you need is a simple 'bx lr' under label 'end', w/o any push/pop in your routine. LR is usually only changed by BL.


i.e.
Código:
	ldr r0, var_8003
	ldrh r0, [r0] //slot del Pokemon
	mov r1, #0x64
	mul r0, r1
	ldr r1, firstpokemon
	add r0, r0, r1
	add r0, r0, #0x58 //offset de max PS
	ldr r1, var_8004
	ldrh r1, [r1]
	lsl r1, r1, #1
	add r0, r0, r1
	ldrh r0, [r0] //valor de la estadística deseada
	ldr r1, var_8005
	ldrh r1, [r1] //parámetro al que comparar la estadística
	cmp r0, r1
	beq equal
	cmp r0, r1
	blo minus
	mov r0, #0x2
	b end	


equal:
	mov r0, #0x1
	b end

minus:
	mov r0, #0x0
	
end:
	ldr r1, var_8003
	strh r0, [r1]
	bx lr

.align 2
var_8003:	.word 0x020370BE
var_8004:	.word 0x020370C0
var_8005:	.word 0x020370C2
firstpokemon:	.word 0x02024284
 
Última edición:
Arriba