#26487 - ImInABand - Thu Sep 16, 2004 11:42 pm
How would I implement the use of SRAM? Could someone please give me a short run through? (if it makes a difference i use devkitadvance)
#26491 - DiscoStew - Fri Sep 17, 2004 12:41 am
If I'm correct on this, Save RAM is located at 0x0E000000, and is approx 64KBytes big (0x0E000000 - 0x0E00FFFF). You can only write 8-bits (1 byte) at a time, not 16/32 bits. Just an idea, though I don't know how you'd set up your stuff, is have a structure containing everything you want saved, then when you are ready to write/read, cast the struct as a char pointer, and write/read 8-bits at a time. Just an idea, since I never tried using SRAM before.
_________________
DS - It's all about DiscoStew
#26493 - ImInABand - Fri Sep 17, 2004 12:49 am
ill take a look at doing that when i get back from class.
#26499 - Krakken - Fri Sep 17, 2004 4:10 am
Yeah, it's pretty easy.
I use memcpy() myself and it works just fine.
#26534 - ImInABand - Fri Sep 17, 2004 11:29 pm
yeah i figured it out. it was pretty easy, but the way i set it up was i made a tag for it so it acts as a variable, so i can copy sram like this:
pSaveMemory[X] = variable;
and to load:
variable = pSaveMemory[X];
#26539 - tepples - Sat Sep 18, 2004 1:02 am
Directly accessing SRAM is a bad idea. Hide your game's cartridge SRAM accesses in a memcpy() style interface just in case you want to adapt your program to use EEPROM or flash save should you get signed by a label.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#26543 - Krakken - Sat Sep 18, 2004 1:41 am
You can save a struct for example by doing this.
Code: |
struct _xDataStruct {
int iData;
int iData2;
char cX;
char cY;
char* pcOtherData;
};
_xDataStruct xStruct;
memcpy((void*)0x0E000000 + iOffset, (void*)&xStruct, sizeof(_xDataStruct));
|
This will save the entire struct into SRAM. To load it again, swap the first two memcpy() params around the other way.
Last edited by Krakken on Sat Sep 18, 2004 1:42 am; edited 1 time in total
#26544 - ImInABand - Sat Sep 18, 2004 1:42 am
yeah, but as of right now, all i make are no-chance-of-going-anywhere pdroms, most of which i make for my own amusement.
IF AND ONLY IF I EVER get signed by a label [ fat chance of that happening] i will switch to memcpy()
have a nice day :)
#26545 - Krakken - Sat Sep 18, 2004 1:58 am
You can do that also without memcpy(). Use the data like this though:
char* pcDataSRAM = (char*)&xStruct;
Then use "pcDataSRAM" as if it were an array of bytes of size "sizeof(_xDataStruct)". It just allows you to organise your gamestates, player data much better.
#26560 - dagamer34 - Sat Sep 18, 2004 4:28 pm
I topic I made a very long time ago. Very useful I would think!
Saving RAW Data
It's usually a good idea to search around the forums before you make a topic as chances are it has been made before. You also get more insight into the topic itself, without having to wait for more people to reply. If you need more help then, then that's when its best to make a new topic as other people can be pointed to it in the future. :)
_________________
Little kids and Playstation 2's don't mix. :(