rammemory-address

Translating flags into memory addresses ram map pokemon


I'm trying to understand how to get memory addresses from the page https://datacrystal.tcrf.net/wiki/Pok%C3%A9mon_Gold_and_Silver/Flags in order to put them in my pyboy project.

For instance I want to check if "Start Pokemon got" at address 0x1A00 but it seems not to work.

What I want is to understand the process to translate each of them in the correct ram address to put into pyboy.memory[0x...]


Solution

  • It looks like the flag IDs are actually big endian and make more sense to be reasoned about when reversing the byte order. So 1A00 means it's the 0x001A'th flag bit you are after.

    The first table in the article shows that 1800, i.e. the 0x0018'th flag bit, starts at memory address 0xD7BA.

    So I'd look at the third-lowest bit (i.e. bitmask 0x04) of the byte at address 0xD7BA:

    if pyboy.memory[0xD7BA] & 0x04:
      print("Start Pokémon got")
    

    (Why third? Because if the first bit in that byte is flag 0x0018, the second would be 0x0019 and the third would be 0x001A. Why 0x04? Because the bit values go 0x1, 0x2, 0x4, 0x8, 0x10, ...)