• 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!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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✓] How do (some?) fractions work in hex?

Manekimoney

Banned
  • 169
    Posts
    7
    Years
    • Seen Jan 18, 2024
    For example, these bytes in Fire Red at 0x01856A correspond to burn damage for each turn:

    C0 08

    This corresponds to 1/8 of max HP that the Pokemon takes each turn

    Changing these bytes to 00 09, will change the max HP damage to 1/16 each turn.

    How does that work? I see no correlation or logic between these bytes and what they are supposed to represent, neither for C0 08 representing 1/8 and 00 09 representing 1/16.

    I mainly want to change these values (and some similar ones) to 1/64 (or different, depending on how 1/64 turns out), but I think learning how they work will be helpful
     
    Last edited:
    uhh, hey I'm new but if you want to add another head to the issue and hopefully get more attention I can try to help.
    I'm interested in doing something with those variables too, anyway.

    I've been reading the xse scripting guide and I believe that may be a "special flag" (?) I'm thinking that 08 and 09 have nothing to do with the definition of the value itself by maybe are just pointers to/referencing the source of those values.

    08 isn't 1/8 and 09 isn't 1/16.
    and I just ran a quick test in a hex - dec converter and hex doesn't have any symbol for values less than 1.
    Which reminds me of something on another post somewhere that burn damage takes its percentage of total health to calc burn status damage but if it would return a value below 1 it just uses 1 instead.

    Possibly because itself isn't capable of storing that type of value.
    oh but I also came across something else while looking up action replay
    8 bit = 1 bytes
    16 bits = 2 bytes
    32 bits = 4 bytes
    Each byte contains two nibbles or a half a hexadecimal
    So
    8 bits = 00
    16 bits = 0000
    32 bits is 00000000

    don't know if that is useful but if a nibble is half a hexadecimal idk maybe you can search it or find a way to represent it.

    How did you find the status damage I'd be very interested in finding that out.
    on second thought that 1/16 may have nothing to do with burn damage, and instead be the parameter/variable/flag/idk for the badly poisoned status.

    When you tested that with the other parameter 09, did the burn damage stay constant or increase over time?
     
    uhh, hey I'm new but if you want to add another head to the issue and hopefully get more attention I can try to help.
    I'm interested in doing something with those variables too, anyway.

    don't know if that is useful but if a nibble is half a hexadecimal idk maybe you can search it or find a way to represent it.

    How did you find the status damage I'd be very interested in finding that out.
    on second thought that 1/16 may have nothing to do with burn damage, and instead be the parameter/variable/flag/idk for the badly poisoned status.

    When you tested that with the other parameter 09, did the burn damage stay constant or increase over time?

    Yeah, I did kind of suspect that it could have been something different than just a number, but the data structure doesn't suggest that it's a pointer or something similar.

    I've found this burn damage parameter in the "Quick Research and Development" thread for updating the move to new gen standards. The damage is a constant 1/16 every turn.
     
    Interesting, and thanks I'll check that out for my own stuff later, but yeah I don't have enough knowledge to figure this out, you probably know much more than me on this.

    I don't know enough to recognize the signs of any specific data type, I just know from some videos and reading the xse guide, that for something that's returning a specific effect it must (in my limited knowledge) be either a pointer or a variable.

    Hope you get an answer, if I figure something out I'll be sure to pass it on to you.
     
    Interesting, and thanks I'll check that out for my own stuff later, but yeah I don't have enough knowledge to figure this out, you probably know much more than me on this.

    I don't know enough to recognize the signs of any specific data type, I just know from some videos and reading the xse guide, that for something that's returning a specific effect it must (in my limited knowledge) be either a pointer or a variable.

    Hope you get an answer, if I figure something out I'll be sure to pass it on to you.

    OK, I might have figured it out.

    After some messing around, it seems that incrementing the first byte by 40 (from 00 to 40 to 80 to C0), decreases the amount of damage dealt by a half. Once the byte reaches C0 and you go beyond (which would overflow the byte), it increases the second byte instead (which changes the 08 to 09)

    So:
    80 08 corresponds to 1/4
    C0 08 corresponds to 1/8
    00 09 corresponds to 1/16
    40 09 corresponds to 1/32
    80 09 corresponds to 1/64
    C0 09 corresponds to 1/128
    (Note that this may not be 100% confirmed. At some point, the damage becomes too low to properly confirm if it really takes 128 turns to kill someone without wasting too much of my time)

    It seems that messing around with the second byte can lead to glitchy situations. For instance, changing it to 5, will make all the damage 0.

    Anyway, this seems to be the solution to my answer. I'll probably mark the thread as solved, unless someone can elaborate on the system further (for instance, how to implement 3/8 for example or something similar (if that is even possible))
     
    OK, I might have figured it out.

    After some messing around, it seems that incrementing the first byte by 40 (from 00 to 40 to 80 to C0), decreases the amount of damage dealt by a half. Once the byte reaches C0 and you go beyond (which would overflow the byte), it increases the second byte instead (which changes the 08 to 09)

    So:
    80 08 corresponds to 1/4
    C0 08 corresponds to 1/8
    00 09 corresponds to 1/16
    40 09 corresponds to 1/32
    80 09 corresponds to 1/64
    C0 09 corresponds to 1/128
    (Note that this may not be 100% confirmed. At some point, the damage becomes too low to properly confirm if it really takes 128 turns to kill someone without wasting too much of my time)

    It seems that messing around with the second byte can lead to glitchy situations. For instance, changing it to 5, will make all the damage 0.

    Anyway, this seems to be the solution to my answer. I'll probably mark the thread as solved, unless someone can elaborate on the system further (for instance, how to implement 3/8 for example or something similar (if that is even possible))

    Ok that's awesome, congrats and great job.
    and the value you find for 5 may not be a glitch, its seemed you've stumbled into a table so that "no damage" could be the right affect being matched with a wrong variable? Point is its a table but its unknown, atleast to us exactly what its for. So there could be more to learn if you can figure out how big the table is, how many variables are in it. etc. I went to that thread you mentioned found a lot of great stuff.
    what may be relevant is someone used I believe the string length to find how many options/places were in a table that they found was used to define pokemon habitats for the fire red pokedex. Maybe string length can show something here. I just looked it up here's the link. https://www.pokecommunity.com/posts/6263014

    And since you've been incrementing statically by forty to get changes of a half, maybe if you increment by the proportion/percent that 3/8th is above one of your known values you can get there.

    quick cal (1/4)/(3/8) 1 quarter over the whole of 3/8 is about 2/3. My math isn't perfect (and I usually misstep when it comes to proportions) but I'm thinking if you subtract(?) the 80 that goes with 08, well not subtract but multiply it by 2/3 wait that was wrong ok take that 80 and DIVIDE it by 2/3 I think you can get the closest to that effect.

    If my math and logic is correct here, then you should get 120, which i believe you would need to translate into hexidecimal and substitute in for the first part of that byte sequence(?)

    hope tha't s right and it works, I don't know much about bytes.
    idk but that's still a change of 40 isn't it idk hope you can make sense of that.

    nother thought, 3/8 is just 1/8 away from (greater than) 1/4. and since 40 equals a change of 1/2 incrementing by 10 could give a change of 1/8. So try putting 10 in the direction you need and see what happens.
     
    Last edited:
    For example, these bytes in Fire Red at 0x01856A correspond to burn damage for each turn:

    C0 08

    This corresponds to 1/8 of max HP that the Pokemon takes each turn

    Changing these bytes to 00 09, will change the max HP damage to 1/16 each turn.

    How does that work? I see no correlation or logic between these bytes and what they are supposed to represent, neither for C0 08 representing 1/8 and 00 09 representing 1/16.

    I mainly want to change these values (and some similar ones) to 1/64 (or different, depending on how 1/64 turns out), but I think learning how they work will be helpful

    Those are thumb instructions, use an assembler/disassembler to read/write them:
    C0 80 = lsr r0, #3 => divides r0 by 8 (2^3)
    00 09 = lsr r0, #4 => divides r0 by 16 (2^4)
     
    Alright, thanks to Anon822 for explaining how the entire thing works.

    For anyone looking to edit burn damage or any similar mechanic, I'll post the offsets that function with this formula as well, so you can mess with them, if you want to (test these first, cuz I didn't, but it should be correct):
    Code:
    18384 - INGRAIN      (1/16)
    18446 - LEECH SEED   (1/8)
    184A2 - POISON       (1/8)
    184EC - TOXIC        (1/16) (increases each turn. Don't know how changing it affects the stacking damage)
    1856A - BURN         (1/8)
    185C2 - NIGHTMARE    (1/4)
    18618 - CURSE        (1/4)
    186C4 - WRAP         (1/16)
     
    Alright, thanks to Anon822 for explaining how the entire thing works.

    For anyone looking to edit burn damage or any similar mechanic, I'll post the offsets that function with this formula as well, so you can mess with them, if you want to (test these first, cuz I didn't, but it should be correct):
    Code:
    18384 - INGRAIN      (1/16)
    18446 - LEECH SEED   (1/8)
    184A2 - POISON       (1/8)
    184EC - TOXIC        (1/16) (increases each turn. Don't know how changing it affects the stacking damage)
    1856A - BURN         (1/8)
    185C2 - NIGHTMARE    (1/4)
    18618 - CURSE        (1/4)
    186C4 - WRAP         (1/16)

    lol yup that's exactly the kind of thing I was looking for. Thanks and glad you got your answer.

    Those are thumb instructions, use an assembler/disassembler to read/write them:
    C0 80 = lsr r0, #3 => divides r0 by 8 (2^3)
    00 09 = lsr r0, #4 => divides r0 by 16 (2^4)

    Thanks a lot Anon822 I'm just getting started but I didn't know to look into ASM tools, Can you recommend some programs/tools and/or a place for me to get started learning about these thumb instruction things? Since this thread is pretty much complete, if you have any advice to give me can you post it in my thread?
    https://www.pokecommunity.com/threads/443686
     
    Last edited:
    lol yup that's exactly the kind of thing I was looking for. Thanks and glad you got your answer.



    Thanks a lot Anon822 I'm just getting started but I didn't know to look into ASM tools, Can you recommend some programs/tools and/or a place for me to get started learning about these thumb instruction things? Since this thread is pretty much complete, if you have any advice to give me can you post it in my thread?
    https://www.pokecommunity.com/threads/443686

    Thumb Assembler by HackMew:
    https://www.mediafire.com/file/0mccyai8hefoxde/Hackmew%27s_ASM_Compiler_by_Hackmew.rar/file

    Usage: https://www.pokecommunity.com/posts/8526603/

    THUMB Editor and Assembler:
    https://www.mediafire.com/file/kmfq...tor_%26_Assembler_by_thekaratekid522.rar/file


    https://www.pokecommunity.com/threads/233645
     
    Last edited:
    Back
    Top