• 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] Accessing script banks in ASM

222
Posts
6
Years
    • Seen Nov 18, 2023
    Working on an ASM routine, and need to write that value of a register to a script bank. (Specifically, script bank 0). A buffer will not work in this case as it is a pointer and not text. The only alternative I think is possible would be to directly write the value of the register to the ROM to a specific pointer, but I don't think ASM can do that.

    What are the memory offsets for the script banks? Alternatively, how does one write 4 bytes of data to the rom?

    Edit: Script bank 0 is located at 0x03000F14. How do I write to this offset in ASM?
     
    Last edited:

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • Working on an ASM routine, and need to write that value of a register to a script bank. (Specifically, script bank 0). A buffer will not work in this case as it is a pointer and not text. The only alternative I think is possible would be to directly write the value of the register to the ROM to a specific pointer, but I don't think ASM can do that.

    What are the memory offsets for the script banks? Alternatively, how does one write 4 bytes of data to the rom?

    Edit: Script bank 0 is located at 0x03000F14. How do I write to this offset in ASM?

    You need to use str command to write to the address. Also, you cannot modify the ROM during runtime (look up what ROM stands for). I think something like this would work:
    ldr r0, =(0x03000F14)
    ldr r1, =(address of script)
    str r1, [r0]

    I might have the str registers backwards, it's been some time and I'm too lazy to double check :)
     
    222
    Posts
    6
    Years
    • Seen Nov 18, 2023
    You need to use str command to write to the address. Also, you cannot modify the ROM during runtime (look up what ROM stands for). I think something like this would work:
    ldr r0, =(0x03000F14)
    ldr r1, =(address of script)
    str r1, [r0]

    I might have the str registers backwards, it's been some time and I'm too lazy to double check :)

    Wow, didn't expect to have to original author of the tutorial I used to actually respond...

    Anyways, I have what I believe to be correct ASM, but it won't compile, with errors at line 9 (see below). For some reason, removing line 14 will allow the code to compile correctly. I've commented my code to the best of my understanding, using your script for navigating tables as a base. I would really appreciate it if you could tell me why it isn't compiling.

    The main purpose of the routine is to read a table of pointers to text based on the value of a variable, and write it to script bank 0 for use with the preparemsg command in XSE. The table is extremely simple, with 4 bytes per entry and no terminator byte or failsafe (the specific use case eliminates the need for a failsafe). Yeah, I probably coulda made a conditional script but the variable will have hundreds, maybe a thousand possible values, and I don't know what they all are right now. That makes for spaghetti code from Hades...

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    main:
    		push {r0-r1, lr}
    		mov r0, #0x4 @Length of a table entry, which is a simple collection of pointers.
    		ldr r1, var @load the [I]pointer[/I] of [B]var[/B] to r1. [B]errors present, see below[/B]
    		ldrh r1, [r1] @load the [I]value[/I] of var to r1
    		mul r1, r1, r0 @figure out how far past the table start we need to go
    		ldr r0, =(0x871AD60)  @start of table
    		add r0, r0, r1 @figure out the pointer to the pointer (lol)
    		ldr r0, [r0] @get the value of the pointer from the pointer (lol)
    		ldr r1, =(0x3000F14) @[URL="https://www.pokemonhackersonline.com/showthread.php?t=14126-PKMNFR-RAM-Address-Research"]offset of script bank 0[/URL]
    		str r0, [r1] @store pointer in r0 to script bank 0
    		pop {r0-r1,pc}
    		
    var:
    .word 0x020270B6 + (0x4011 * 2) @location of variable 0x4011
    
    .align 2 @Because I have no idea if i need it or not

    There are 2 errors at line 9. Keep in mind that removing line 14 will magically make these errors go away for some reason, although I sincerely doubt said code would work.
    Here is the output:
    Accessing script banks in ASM


    Thank you for any insight you could provide on this matter. I would also like to thank you for being the only hacking "giant" still active. (Well... diego is still around here somewhere.) I use your routines regularly, and I found your storage system especially useful. <3

    Edit: On a whim I decided to put an .align 2 before the var definition because that's what the error was saying. It compiled, and I can confirm it works in-game. So apparently I'm supposed to put .align 2 before every label definition? Could you please explain why that worked? What the heck does .align 2 actually do?
     
    Last edited:
    2
    Posts
    6
    Years
    • Seen Jan 16, 2020
    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    main:
    		push {r0-r1, lr}
    		mov r0, #0x4 @Length of a table entry, which is a simple collection of pointers.
    		ldr r1, var @load the [I]pointer[/I] of [B]var[/B] to r1. [B]errors present, see below[/B]
    		ldrh r1, [r1] @load the [I]value[/I] of var to r1
    		mul r1, r1, r0 @figure out how far past the table start we need to go
    		ldr r0, =(0x871AD60)  @start of table
    		add r0, r0, r1 @figure out the pointer to the pointer (lol)
    		ldr r0, [r0] @get the value of the pointer from the pointer (lol)
    		ldr r1, =(0x3000F14) @offset of script bank 0
    		str r0, [r1] @store pointer in r0 to script bank 0
    		pop {r0-r1,pc}
    
    .align 2 @Because I have no idea if i need it or not
    
    var:
    .word 0x020270B6 + (0x4011 * 2) @location of variable 0x4011
     
    Back
    Top