• 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✓] Help with this ASM routine for evolution based on a flag.

Dr. Seuss

Will finish GS Chronicles, I swear!
525
Posts
10
Years
  • I've been trying to insert an evolution method based on a flag. So basically if a flag is set, then Pokémon evolves. The issue I´m facing is that if the flag is nto set, everything continues, if the flag is set, rom crashes.

    Here is the ASM code I wrote:

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    .global setflagevo
    
    main:
    	push {r0-r7}
    	add r0, r6, r7
    	lsl r0, r0, #0x3
    	add r0, r2, r0
    	add r3, r0, r3
    	ldrh r2, [r3, #0x2]
    	mov r0, r8
    	mov r5, #0x0
    	ldr r0, flag_number
    	ldr r2, flag_routine
    	ldrh r2, [r2, #0x0]
    	bl linker
    	cmp r0, #0x1	
    	bne flagnotset
    	mov r10, r3
    	pop {r0-r7}
    	mov r1, r10
    	ldr r0, levelcheckloc
    	bx r0
    
    linker:
    	bx r2
    
    flagnotset:
    	pop {r0-r7}
    	ldr r0, noevo
    	bx r0
    
    .align
    flag_number: .word 0x00000(Flag Number)
    flag_routine: .word 0x0806E6D0 +1
    levelcheckloc: .word 0x08043017
    noevo: .word 0x08043111

    Why does my routine isn't working as intended?
     
    Last edited:
    218
    Posts
    10
    Years
    • Seen Nov 12, 2021
    I've been trying to insert an evolution method based on a flag. So basically if a flag is set, then Pokémon evolves. The issue I´m facing is that if the flag is nto set, everything continues, if the flag is set, rom crashes.

    Here is the ASM code I wrote:

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    .global setflagevo
    
    main:
    	push {r0-r7}
    	add r0, r6, r7
    	lsl r0, r0, #0x3
    	add r0, r2, r0
    	add r3, r0, r3
    	ldrh r2, [r3, #0x2]
    	mov r0, r8
    	mov r5, #0x0
    	ldr r0, flag_number
    	ldr r2, flag_routine
    	ldrh r2, [r2, #0x0]
    	bl linker
    	cmp r0, #0x1	
    	bne flagnotset
    	mov r10, r3
    	pop {r0-r7}
    	mov r1, r10
    	ldr r0, levelcheckloc
    	bx r0
    
    linker:
    	bx r2
    
    flagnotset:
    	pop {r0-r7}
    	ldr r0, noevo
    	bx r0
    
    .align
    flag_number: .word 0x00000(Flag Number)
    flag_routine: .word 0x0806E6D0 +1
    levelcheckloc: .word 0x08043017
    noevo: .word 0x08043111

    Why does my routine isn't working as intended?

    This routine looks completely broken to me, I'm surprised it doesn't crash all the time. Maybe try this :

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    .global setflagevo
    
    main:
    	push {r0-r7}
    	add r0, r6, r7
    	lsl r0, r0, #0x3
    	add r0, r2, r0
    	add r3, r0, r3
    	ldrh r2, [r3, #0x2]
    	mov r0, r8 @ THIS is actually useless, r0 is overwritten 2 instruction after
    	mov r5, #0x0
    	ldr r0, flag_number
    	ldr r2, flag_routine
           @  ldrh r2, [r2, #0x0] @ really bad, you're basically calling a function that is supposed to be at an address in the bios, and that's the reason I'm surprised it doesn't crash just all the time
    	bl linker
    	cmp r0, #0x1	
    	bne flagnotset
    	mov r10, r3 @ I hope the person who did the routine checked r10 was safe to use here
    	pop {r0-r7}
    	mov r1, r10
    	ldr r0, levelcheckloc
    	bx r0
    
    linker:
    	bx r2
    
    flagnotset:
    	pop {r0-r7}
    	ldr r0, noevo
    	bx r0
    
    .align
    flag_number: .word 0x00000(Flag Number)
    flag_routine: .word 0x0806E6D0 +1
    levelcheckloc: .word 0x08043017
    noevo: .word 0x08043111
     

    Dr. Seuss

    Will finish GS Chronicles, I swear!
    525
    Posts
    10
    Years
  • This routine looks completely broken to me, I'm surprised it doesn't crash all the time. Maybe try this :

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    .global setflagevo
    
    main:
    	push {r0-r7}
    	add r0, r6, r7
    	lsl r0, r0, #0x3
    	add r0, r2, r0
    	add r3, r0, r3
    	ldrh r2, [r3, #0x2]
    	mov r0, r8 @ THIS is actually useless, r0 is overwritten 2 instruction after
    	mov r5, #0x0
    	ldr r0, flag_number
    	ldr r2, flag_routine
           @  ldrh r2, [r2, #0x0] @ really bad, you're basically calling a function that is supposed to be at an address in the bios, and that's the reason I'm surprised it doesn't crash just all the time
    	bl linker
    	cmp r0, #0x1	
    	bne flagnotset
    	mov r10, r3 @ I hope the person who did the routine checked r10 was safe to use here
    	pop {r0-r7}
    	mov r1, r10
    	ldr r0, levelcheckloc
    	bx r0
    
    linker:
    	bx r2
    
    flagnotset:
    	pop {r0-r7}
    	ldr r0, noevo
    	bx r0
    
    .align
    flag_number: .word 0x00000(Flag Number)
    flag_routine: .word 0x0806E6D0 +1
    levelcheckloc: .word 0x08043017
    noevo: .word 0x08043111

    Duuuuude. I tested it and it works perfectly. I'm a total ASMnoob so I realize now why it didn't work.

    Thanks a lot. My question has been resolved.
     
    Back
    Top