Save game?

Libraries, utilities, bootloaders...

Save game?

Postby RackhamLeNoir » Sun Apr 09, 2017 9:08 pm

Hi,

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?
RackhamLeNoir
 
Posts: 15
Joined: Sat Apr 08, 2017 2:59 pm

Re: Save game?

Postby Sutchig » Mon Apr 10, 2017 6:42 am

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

Re: Save game?

Postby wuuff » Mon Apr 10, 2017 7:40 am

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.
wuuff
 
Posts: 61
Joined: Sun Aug 28, 2016 6:05 am

Re: Save game?

Postby RackhamLeNoir » Mon Apr 10, 2017 8:39 am

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?
RackhamLeNoir
 
Posts: 15
Joined: Sat Apr 08, 2017 2:59 pm


Return to Software Development

Who is online

Users browsing this forum: No registered users and 26 guests

cron