openai / retro

Retro Games in Gym
MIT License
3.35k stars 524 forks source link

Hexadecimal memory locations for data.json #265

Open isledge opened 2 years ago

isledge commented 2 years ago

Currently, it appears that JSON not support hexadecimal memory addresses. What is the correct way to handle mapping these addresses?

For example, my data.json file for the GameBoy game Super Mario Land looks like the following:

{
  "info": {
    "gameover": {
      "address": C0A4,
      "type": "=d1"
    },
    "lives": {
      "address": DA15,
      "type": "=d1"
    },
    "coins-tens": {
      "address": 9829,
      "type": "=d1"
    },
    "coins-ones": {
      "address": 982A,
      "type": "=d1"
    },
    "current-world": {
      "address": 982C,
      "type": "=d1"
    },
    "current-stage": {
      "address": 982E,
      "type": "=d1"
    },
    "mario-x-pos": {
      "address": C202,
      "type": "=d1"
    },
    "mario-y-pos": {
      "address": C201,
      "type": "=d1"
    },
    "score": {
      "address": C0A0,
      "type": "=d4"
    }
  }
}

This, naturally, will fail to import, since the JSON parser has no idea about how to read those hexadecimal values. Do we just convert from hex to decimal, i.e., 0xC0A4 becomes 49316?

Thank you!

endrift commented 2 years ago

Yeah, just convert to decimal. It's definitely very annoying, but it's what needs to be done. I think there may be some offsetting involved due to memory domains and limitations of the libretro API, but I forget. Take a look at some of the others for examples.