• 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] Need help with reloading map + NPC palettes with ASM in Fire Red

13
Posts
7
Years
    • Seen Sep 12, 2019
    Hi folks,

    I'm writing a simple ASM routine that will call the functions in Fire Red. So far, my code looks like this...

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    main:
    	push {r0-r7, lr}
    	ldr r4, battleCheck
    	ldrh r4, [r4]
    	cmp r4, #0x0
    	bne end
    	ldr r3, callback
    	ldr r3, [r3]
    	ldr r4, mainloop
    	cmp r3, r4
    	bne end
    	ldr r4, map
    	ldr r4, [r4]
    	cmp r4, #0x0
    	beq end
    	ldr r5, updatePal
    	bl bx_r5
    	ldr r5, updateNPCPal
    	bl bx_r5
    
    end:
    	pop {r0-r7, pc}
    
    bx_r5:
    	bx r5
    
    .align 2
    
    updatePal:
    	.word 0x08059AD8+1
    
    updateNPCPal:
    	.word 0x0805FECC+1
    
    battleCheck:
    	.word 0x02024018
    
    callback:
    	.word 0x03005090
    
    mainloop:
    	.word 0x08079E0D
    
    map:
    	.word 0x02036DFC

    As you can see, it performs a variety of checks before loading the pointers to the palette loading routines into r5 and calling them in sequence. However, whenever I try to run the code, the game will freeze or the palettes will get messed up. If anyone could point out where I've went wrong here and help me get this code working that would be greatly appreciated. Thank you!
     

    Phantom Phoenix

    Lost on the road of life
    167
    Posts
    8
    Years
    • Age 27
    • ???
    • Seen Jul 1, 2020
    hmm ...
    you are calling functions without giving parameters which takes parameters
    Here is what FBI said in his asm tut:
    Code:
    Remember when I was talking about paramaters to ASM functions? I said that paramaters, by ASM standards, are defined to be the first four low registers. If there are more than four paramaters, that's a different story (the extra paramaters are writting to the stack pointer). Similarly to paramaters, the output from a function is also like this. Generally, if a function outputs values or pointers for other functions to use (these are often called helper functions in other programming languages), the outputs are stored into r0-r3. They are always filled in consecutive order. So if some function outputted one value, that value would be in r0. Never will you see the value in r1, r2, or r3 and not in r0. Hopefully that makes sense to you, as it's important.
    So.....
    * before calling update_pal function you have to put current_mapheader in r0
    .
    like this:
    Code:
     ldr 0, map
    ldr r0, [r0]
    ldr r5, updatePal
    bl bx_r5
    * And updateNPCPal also takes a parameter.
    You don't need to push that many register. You just did some check in this routine so r0-r2 is enough for the task.
     
    Last edited:
    Back
    Top