gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > how to manage a scoreboard and a level selection

#170941 - genecyst - Tue Oct 27, 2009 9:41 am

hi, i've got two questions:

1 - i need to create a simple scoreboard for my game, and i want to find the easier way to do it, suggestion?

2 - i whish to create a level selection screen at the beginning of the game, givin' the player the possibility of starting from the last level cleared.

how can i save these infos ("last level clear" and "scoreboard data")in the easier way?
thanks a lot.

#170954 - sgeos - Tue Oct 27, 2009 5:42 pm

You will need some sort of global game data struct. To save the data, put it in the struct and and save the struct to the cart. Your levels should be numbered, and scores are just integers. They eye candy should be more work than making the data persist after the power is turned off.

#171003 - genecyst - Wed Oct 28, 2009 10:45 am

that's the way i had in mind, but where i can find some references about saving data in gba cart? searching the forum give me 15000 results but without a real connection with this issue. maybe i'm searching for wrong words...

#171011 - gauauu - Wed Oct 28, 2009 3:04 pm

Assuming it's a normal GBA flash cart, it probably uses SRAM. Writing to SRAM is really easy -- you just write the data to a particular region of memory, which is SRAM.

I've read somewhere that some carts only support writing 8 bits at a time, this may or may not be true, but to be safe, that's what I've done (Somebody smarter may chime and on the validity of that statement?).

The SRAM address is defined in libgba in gba_base.h.

Code:

//this should be automatically done in gba_base.h from libgba
#define SRAM (0x0E000000)

void writeSaveGameToCart(SaveGameData * data)
{
   u8 * save = (u8*)SRAM;
   int slotSize = sizeof(SaveGameData);

   //use a slow u8 copy loop because supposedly save data
        //can only be written 8 bits at a time? 

   u8 * saveData = (u8*)data;

   int i = 0;
   for (i = 0; i < slotSize; i++)
   {
      *save++ = *saveData++;
   }
   
}


Loading data is just as easy...you just read the data directly from that memory, the same way.

#171015 - genecyst - Wed Oct 28, 2009 3:17 pm

i can't believe that i've never ask myself what gba_base.h were...

really really thanks a lot to both of you!

#174616 - genecyst - Thu Jul 01, 2010 2:04 pm

hi, i dig up this old topic couse i'm having issues related to saving data.
i've done my saving function and tested over any emulator i can... and all work well.
when i put my rom on a firelinker 128 it doesn't save anything at all...
i haven't any other type of flash card to try it out on hardware... someone has already had this sort of problems?
thanks a lot!

#174617 - Dwedit - Thu Jul 01, 2010 8:30 pm

Flash cartridges use mysterious voodoo magic to divide save games up between roms. Some look for a string like "SRAM_V113" before they will decide that a rom gets a save game.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#174622 - genecyst - Fri Jul 02, 2010 9:45 am

i've found this simply declaration searching around the forum,

const char* saveType = "SRAM_V113";

do you mean it's enough to declare it somewhere?
thanks a lot.

#174627 - genecyst - Fri Jul 02, 2010 3:36 pm

it works.

thanks so much!