Page 1 of 1

Save game?

PostPosted: Sun Apr 09, 2017 9:08 pm
by RackhamLeNoir

In the JezzBall game I used the EEPROM to store the high score, so that it is kept when turning off the console. The problem is there is no way to know whether the value was initialized at some point. The factory value in EEPROM is 0xFF for every byte. So with a fresh EEPROM (never used) it is quite easy to test. Otherwise it is impossible. The idea is to run a simple program which sets all bytes to 0xFF to clear it.

This is OK if only one game would like to use it. But with several games it is a mess. I think it would be great to have a solution in the library itself. Maybe storing data on the SD card would be much better. Is there a plan for this?

Re: Save game?

PostPosted: Mon Apr 10, 2017 6:42 am
by Sutchig
The Gamebuino loader saves the current EEPROM to SD-Card when changing the game (via loader, not upload trough USB) and restores the content if there is a EEPROM-"Savegame" on SD-Card (there is a little disk-symbol at the loader menu)

To be sure to use only initialised values when accessing EEPROM you can use "magic numbers" (at any place) in eeprom. several games use this approach: When starting the game you look for token 1 at eeprom[0], token 2 at eeprom[1] and so on. 3 bytes should be enough to be sure. if they are correct, you can use highscore, if not, initalise first 3 bytes and set highscore to 0.

Re: Save game?

PostPosted: Mon Apr 10, 2017 7:40 am
by wuuff
As Sutchig said, the Gamebuino loader saves and loads EEPROM values, and if there is no savegame it makes sure to clear EEPROM to all zero. The code for loading saved data can be found here.

You have been using an emulator, right? I found that the emulator I have used sets EEPROM to nonzero values (probably all 0xFF, though I would have to check). Since it loads a game without going through the loader, it never sets EEPROM like the loader does, so the result is different from a real device.

Re: Save game?

PostPosted: Mon Apr 10, 2017 8:39 am
by RackhamLeNoir
I'll use the magic umbers technique then. Thanks!

If it is a common technique, would it be worth including it in he GameBuino library?