• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • 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] Trying to mess with assembly in Pokecrystal.. not sure how to know which bytes to move to accomplish what I want.

  • 2
    Posts
    1
    Years
    • Seen Oct 3, 2023
    ^ Title. I have experience in other programming languages, but I've never tried my hand at anything close to assembly. From looking into guides and syntax lists, I can wrap my head around which commands to use to move data around as I need. The problem is that I don't know *which* areas have the data I want to move, and which areas I need to put that data.

    For example, I'm currently trying to implement something that raises a pokemon's stats in battle under the right conditions. If I knew where the player & enemy pokemon's stats were being stored, I may be able to figure out how to call, add to, and replace that data- but all of the documentation I've looked at is more focused on how the assembly commands themselves work, with no explanation or map that shows where I can find that data.

    There was something else where I wanted to change a pokemon's species into another's in battle, kind of like transform- but it would become a specific species, not a copy of the opponent. As far as I can tell, there's no way to learn where I could access that data in my code without guessing and checking?

    Is there any guide that I was unable to find that helps with this? I feel like I'm missing something because I haven't seen anyone else ask. While it would be helpful to have someone just show me how to do what I want to do like in pokecrystal's tutorial documentation, I also want to understand why that works so that I can do stuff on my own without asking the people who know where all the data is stored every time I want something done.
     
    ^ Title. I have experience in other programming languages, but I've never tried my hand at anything close to assembly. From looking into guides and syntax lists, I can wrap my head around which commands to use to move data around as I need. The problem is that I don't know *which* areas have the data I want to move, and which areas I need to put that data.

    For example, I'm currently trying to implement something that raises a pokemon's stats in battle under the right conditions. If I knew where the player & enemy pokemon's stats were being stored, I may be able to figure out how to call, add to, and replace that data- but all of the documentation I've looked at is more focused on how the assembly commands themselves work, with no explanation or map that shows where I can find that data.

    There was something else where I wanted to change a pokemon's species into another's in battle, kind of like transform- but it would become a specific species, not a copy of the opponent. As far as I can tell, there's no way to learn where I could access that data in my code without guessing and checking?

    Is there any guide that I was unable to find that helps with this? I feel like I'm missing something because I haven't seen anyone else ask. While it would be helpful to have someone just show me how to do what I want to do like in pokecrystal's tutorial documentation, I also want to understand why that works so that I can do stuff on my own without asking the people who know where all the data is stored every time I want something done.

    If you look in the ram folder, you can find the names of every variable in the game, which will probably help you find the variables you're looking for.
    You can also find some definitions for data structures in macros/ram.asm. And in constants/wram_constants.asm you can find what values specific variables should be set to.

    When it comes to making a new modification, a really good technique to use is to look for code in the base game that does something similar. It can tell you where you should put your own code, what variables you might need, what functions you might want to call and how those variables and functions are used. For your second example you should absolutely start by reading through the code of transform to see how it works.
     
    If you look in the ram folder, you can find the names of every variable in the game, which will probably help you find the variables you're looking for.
    You can also find some definitions for data structures in macros/ram.asm. And in constants/wram_constants.asm you can find what values specific variables should be set to.

    When it comes to making a new modification, a really good technique to use is to look for code in the base game that does something similar. It can tell you where you should put your own code, what variables you might need, what functions you might want to call and how those variables and functions are used. For your second example you should absolutely start by reading through the code of transform to see how it works.

    Thanks, this helped a lot! Although something I'm still not connecting the dots on is how I should visualize the code itself as I try to interpret or create modifications to it. Like, I now know which variables exist and why they're being called, and I understand that ld loads values or that srl shifts bytes or etc., but what I don't know is what the program sees when it calls a variable, and how I should go about modifying that to get the end result I want.

    For example, Pokecrystal's guide to adding Eviolite ends with this segment:

    +; boost the relevant defense stat in bc by 50%
    + ld a, c
    + srl a
    + add c
    + ld c, a
    + ret nc
    +
    + srl b
    + ld a, b
    + and a
    + jr nz, .done
    + inc b
    +.done
    + scf
    + rr c
    + ret

    Presumably, the code here is finding the base def/sp.def values, raising them by 50%, and then replacing them. I can assume that they've called the data that holds all of the active pokemon's stats, but that doesn't tell me which part of that code is for defense, which part is for special defense, or really anything about how that code looks for the purpose of interpreting/writing commands that move around data.
     
    Thanks, this helped a lot! Although something I'm still not connecting the dots on is how I should visualize the code itself as I try to interpret or create modifications to it. Like, I now know which variables exist and why they're being called, and I understand that ld loads values or that srl shifts bytes or etc., but what I don't know is what the program sees when it calls a variable, and how I should go about modifying that to get the end result I want.

    For example, Pokecrystal's guide to adding Eviolite ends with this segment:

    ...

    Presumably, the code here is finding the base def/sp.def values, raising them by 50%, and then replacing them. I can assume that they've called the data that holds all of the active pokemon's stats, but that doesn't tell me which part of that code is for defense, which part is for special defense, or really anything about how that code looks for the purpose of interpreting/writing commands that move around data.

    I don't know what you mean by "calling a variable" nor do I see how knowing what patterns of 1s and 0s the computer sees will help you in any way, so I'll just focus on your example.

    Could you tell what the value of z is in the following pseudocode?
    Code:
    z = f(x,y)

    Not really since you have no idea what the function f is doing or what its parameters x and y contain.
    You can't analyze the behaviour of a program by just staring at a single line of code, especially if it's assembly. You have to read though several lines of code while keeping track of what's stored in the registers and how each instruction changes that.
    It can help to write down comments as notes to help you keep track of what's happening, or you can step through the code in a debugger line by line to see what it's doing. But either way you'll need patience to understand the code, especially as the size of it increases.

    The code you posted is doing some operations on the values of b and c while using a as a temporary variable. Its operations aren't going to make much sense unless you know what those values are. This code snippet is from the very end of a function so you should look at the earlier parts to see what b and c contain. In this case you'll see that their value are being stored on the stack to avoid changing them, indicating that they're coming from an even earlier part of the code, the caller of the function.

    The function is called at the very end of PlayerAttackDamage, which has the comment:
    Code:
    ; Return move power d, player level e, enemy defense c and player attack b.
    Since the eviolite function call is added at the very end of this function, we now know what b and c should contain at the start and end of the eviolite function.

    With this knowledge you can read through the code again and see that it's increasing defense by 50% and dividing both attack and defense by 2 if an integer overflow occurs. Selecting between physical and special, finding their values or applying the changed values are not responsibilities of that code snippet.
     
    Last edited:
    Back
    Top