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.

DS development > Saving SRAM Files

#55569 - dannyboy - Thu Sep 29, 2005 3:02 pm

Hey guys
just started deving for the DS and I'm wondering how do you save and read files to the SRAM? I've looked at Chris Doubles SRAM Tutorial and it's easy enough. However that just writes to the SRAM as one big chunk. What I want is say, read and write "123" to test1.txt and "456" to test2.txt. How is that done?

Also, do fstream and iostream work? Here's some code I wrote for the computer, how would this translate to the DS?
Code:
#include <iostream>
#include <string>
#include <fstream.h>

void WriteFile(const string Filename)
{
    ofstream fout(Filename.c_str());
    if (fout) {
        for(int i = 0; i < 9; i++) {
            fout <<  Age[i].Value;
            fout << endl;
        }
    }
}

void Read(const string Filename)
{
    ifstream fin(Filename.c_str());
    if (fin) {
        for(int i = 0; i < 9; i++) {
            fin >> Age[i].Value;
        }
    }
    fin.close();
}


Thanks in advance for any light you can shed.

#55571 - dXtr - Thu Sep 29, 2005 3:30 pm

b\c there is no filesystem on the ds you can't read and write files. If you want to read files you have to create a virtual filesystem on the ROM and if you also want to write files it has to be created in RAM instead.

#55583 - tepples - Thu Sep 29, 2005 6:03 pm

dannyboy wrote:
What I want is say, read and write "123" to test1.txt and "456" to test2.txt. How is that done?

With a GBA Movie Player and chishm's CompactFlash code.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#55615 - Phan - Fri Sep 30, 2005 12:49 am

dannyboy,

I recently wrote a small SRAM demo that is getting incorporated into my organizer software demo.

Here you go:

http://home.houston.rr.com/poffyprog/sram.c


When you press the Left and Right D-pad buttons, it saves two different variables, then you press B and it assembles it into one big variable and then saves it to SRAM. Then by pressing L or R you can recall that data and its reformatted to whats specified. If you have any questions you can email me at po*f*fy@hou*st*on.rr.com (remove asterisks)