EEPROM

Advice on general approaches or feasibility and discussions about game design

EEPROM

Postby awesome101 » Sun Aug 16, 2015 6:17 pm

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
awesome101
 
Posts: 159
Joined: Sat Jun 20, 2015 6:56 pm

Re: EEPROM

Postby Valden » Sun Aug 16, 2015 6:29 pm

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.
User avatar
Valden
 
Posts: 31
Joined: Mon Jun 08, 2015 5:33 pm

Re: EEPROM

Postby awesome101 » Sun Aug 16, 2015 7:00 pm

Does the gamebuino create the file by itself when you first run the game?
awesome101
 
Posts: 159
Joined: Sat Jun 20, 2015 6:56 pm

Re: EEPROM

Postby Sutchig » Sun Aug 16, 2015 7:08 pm

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
Sutchig
 
Posts: 67
Joined: Sat May 23, 2015 3:48 pm

Re: EEPROM

Postby rodot » Wed Aug 19, 2015 11:33 am

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.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France


Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 109 guests