Page 1 of 1

EEPROM

PostPosted: Sun Aug 16, 2015 6:17 pm
by awesome101
Hey guys, I wanted to know how the gamebuino stores stuff in EEPROM. For example, let's say that we have a game and it stores the score in EEPROM at address 0. And then we run another game that stores your health in EEPROM at address 0. Will the value in address 0 be overwritten? If so, if we run the first game again the score will be different because the second game overwrote it. Can someone explain how this works?

Thanks in advance,
Awesome101

Re: EEPROM

PostPosted: Sun Aug 16, 2015 6:29 pm
by Valden
If you run your game trough the default loader, the EEPROM is saved in a .sav file when you quit the game, and that .sav file is loaded when you reload your game. So the data of other game will not interfere with yours.

I don't know is the EEPROM is cleared if you run the game without a save file though, so make sure it's cleared the first time you launch your game.

Re: EEPROM

PostPosted: Sun Aug 16, 2015 7:00 pm
by awesome101
Does the gamebuino create the file by itself when you first run the game?

Re: EEPROM

PostPosted: Sun Aug 16, 2015 7:08 pm
by Sutchig
You should use some of the bytes as a marker. E.g. "0xca,0xb2" is super crate buino I think. And d1 66 e? Is digger (I forgot the last nibble, there is just no "r" in hex ;-)
When you read the score, just make sure your marker fits.
If you are in a game and press c for the loader, the loader will store the entire eeprom in the sav file. Loading a game will restore the sav to eeprom. But if there is no sav-file, I'm not sure that the loader clean the eeprom.

Edit: I guess the loader generates the file when you quit a game

Re: EEPROM

PostPosted: Wed Aug 19, 2015 11:33 am
by rodot
If there is an existing .sav with the same name than game you selected from the loader, the Gamebuino will load it onto the EEPROM.
If there is no file, all the EEPROM will be cleared to 0.
When you come back to the loader from your game, the loader will backup the EEPROM to a .sav file. If there is already a .sav with this name, it will be overwritten. If there is nothing in the EEPROM, no .sav file will be created.
So theoretically, you should not worry about the content of the EEPROM, other games shouldn't interfere and it will be clean the first time. Although if a game is uploaded via USB, the Gamebuino won't know the game changed, and you might mess up your saved games. Anyway, it's good practice to use a token to check that the EEPROM is valid. For example set the first few bytes of the EEPROM to an arbitrary value when you save thing to the EEPROM, and check these bytes have the right value when the game starts. If it's not the correct value, clean the EEPROM to avoid running on a corrupted sav or a sav from another game.