#7879 - Gremlin - Fri Jun 27, 2003 11:04 am
HI.
Does anybody know how to read/write to the Sram (save games/ hi scores etc) and how much ram is there to be used.
Thank You
#7880 - Quirky - Fri Jun 27, 2003 11:36 am
It's criminally easy on Visoly flash carts - just access SRAM as if it was a normal array sat at 0x0E000000. To load and save a byte at a given offset into save ram I use this code:
Code: |
#define SRAM 0x0E000000
unsigned char LoadByte(unsigned short nOffset) {
return *(unsigned char *)(SRAM + nOffset);
}
void SaveByte(unsigned short nOffset, unsigned char cValue) {
//Save the value at the given offset
*(unsigned char *)(SRAM + nOffset) = cValue;
}
|
As for the size of the sram... I think it's 32kb, though VBA seems to indicate it could be as much as 64kb. Not tested that though as my saves are around 500 bytes and work without problems on my flash cartridge.
#7883 - djei-dot - Fri Jun 27, 2003 11:53 am
You mean 32kBytes and 64kBytes, right?
And since we're talking about SRAM, I also wanted to know a few things. Are this 32kb (or 64kb) always assigned to each program I write? Does that mean that if I have 12 programs on my flash cart and each program uses SRAM, the total SRAM in use would be 12 x 32kb? (theoretically, of course, I don't think the flash cart has that much SRAM memory). It seems an incredible waste of SRAM space, because if I only need 500 bytes of SRAM the rest of the 32kb would be totally unused...
#7887 - Quirky - Fri Jun 27, 2003 12:37 pm
I based the 64 k bytes on the save output from VBA - even though a game uses just 60 bytes to save scores, the .sav file is 64kb.
I guess that for carts, and this really is just a guess, that it places saves on 32kb boundaries, which is the requirement for "executables" on a flash cart IIRC. Though someone who knows for certain really should put us out of our misery :)
#7890 - niltsair - Fri Jun 27, 2003 2:53 pm
A nice thing about pogoshell is that it manage by itself the SRAM. It'll only keep the valide data and compress it in Bank 1-2-3. That give you a lot fo memory to spare once compressed. When you start your game, it'll uncompress data to Bank 0 and use the full 64k. Then, re-compress data back to bank 1-2-3.
That means you can just keep a whole bunch of saved games (>100) without needing to contantly backup /restore it.