Coding for the 3-in-1

Discussion in 'EZ-Flash' started by spinal_cord, May 1, 2010.

May 1, 2010

Coding for the 3-in-1 by spinal_cord at 1:18 PM (760 Views / 0 Likes) 3 replies

  1. spinal_cord
    OP

    Member spinal_cord Knows his stuff

    Joined:
    Jul 21, 2007
    Messages:
    2,871
    Location:
    somewhere
    Country:
    United Kingdom
    A Quick question... Has anyone here had any experience with coding for the 3in1?
    I am trying to use the following code to backup and restore the sram, but when I start the actual gba games, I am told that the saves are corrupt.
    As far as I know, the games are supposed to use sram, so it shouldn't be causing a problem from that angle.

    Anyone able to help?

    CODEvoid writeSRAMToFile(char* filename)
    {

    ÂÂÂÂu8 pages = 0;

    ÂÂÂÂFILE* saver = fopen(filename, "rb+");

    ÂÂÂÂu8* buf = (u8*)malloc(sramBufferSize);

    ÂÂÂÂint i = 0; // the setup for which page to start dumping from if it is a prototype
    ÂÂÂÂ
    ÂÂ pages = TOT_SRAM_PAGES;

    ÂÂÂÂOpenNorWrite();
    ÂÂÂÂfor (; i < pages; i ++)
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂmemset(buf, 0, sramBufferSize);
    ÂÂÂÂÂÂÂÂSetRampage(i);
    ÂÂÂÂÂÂÂÂReadSram(0x0A000000, buf, sramBufferSize);
    ÂÂÂÂÂÂÂÂfwrite(buf, sramBufferSize, 1, saver);
    ÂÂÂÂ}

    ÂÂÂÂfree(buf);
    ÂÂÂÂfclose(saver);
    ÂÂÂÂSetRampage(0);

    ÂÂÂÂCloseNorWrite();
    }

    void writeFileToSRAM(char* filename)
    {

    ÂÂÂÂFILE* saveFile = fopen(filename, "rb");
    ÂÂ
    ÂÂÂÂu8* saveBuf;
    ÂÂÂÂsaveBuf = (u8*)malloc(sramBufferSize);

    ÂÂÂÂblankSRAM((64+256)/4);

    ÂÂÂÂint ret = 1;
    ÂÂÂÂÂÂ
    ÂÂ int i = 16;
    ÂÂÂÂfor (i = getStartpage(); i < MAX_SRAM_PAGES && ret == 1; i ++)
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂmemset(saveBuf, 0, sramBufferSize);
    ÂÂÂÂÂÂÂÂSetRampage(i);
    ÂÂÂÂÂÂÂÂret = fread(saveBuf, sramBufferSize, 1, saveFile);
    ÂÂÂÂÂÂÂÂif (ret == 1) WriteSram(0x0A000000, (u8*)saveBuf, sramBufferSize);
    ÂÂÂÂ}

    ÂÂÂÂfclose(saveFile);
    ÂÂÂÂfree(saveBuf);
    ÂÂÂÂSetRampage(0);

    }

    void writeSAV(void) {

    ÂÂ PA_OutputText(0,0,ln,"Backing up save file.\n"); ln++;
    ÂÂ
    ÂÂ char* saveLocation = calloc(1, 512);
    ÂÂ FILE* configFile;
    ÂÂ FILE* saveTest;
    ÂÂ
    ÂÂ configFile = fopen("/gba.cfg", "a");
    ÂÂ fclose(configFile);
    ÂÂ configFile = fopen("/gba.cfg", "r");
    ÂÂ fgets(saveLocation, 512, configFile);
    ÂÂ fclose(configFile);
    ÂÂ saveTest = fopen(saveLocation, "w");
    ÂÂ if(saveTest){
    ÂÂÂÂÂÂfclose(saveTest);
    ÂÂÂÂÂÂwriteSRAMToFile(saveLocation);
    ÂÂ }
    ÂÂ
    ÂÂ free(saveLocation);
    ÂÂ
    }


    void readSAV(void) {

    ÂÂ PA_OutputText(0,0,ln,"Writing save file.\n"); ln++;

    ÂÂ char savename[256] = "";
    ÂÂ FILE* saveConfig;
    ÂÂ
    ÂÂ strncpy(savename, GBA_Game, strlen(GBA_Game)-3);
    ÂÂ strcat(savename, "sav");

    ÂÂ PA_OutputText(0,0,ln,"copying %s", savename); ln++;
    ÂÂ writeFileToSRAM(savename);ÂÂ

    ÂÂ saveConfig = fopen("/gba.cfg", "wb");
    ÂÂ fwrite(savename, strlen(savename), 1, saveConfig);
    ÂÂ
    ÂÂ fclose(saveConfig);
    ÂÂ
    }
     
  2. how_do_i_do_that

    Member how_do_i_do_that Blue Wizard is about to die.

    Joined:
    May 16, 2008
    Messages:
    4,803
    Country:
    Antarctica
    you need a trigger in your config so that when someone loads a game you set the trigger to on in the config. That way on the next startup of the program it will automatically execute the backup procedure. Then after the procedure set the trigger in the config to off.
     
  3. spinal_cord
    OP

    Member spinal_cord Knows his stuff

    Joined:
    Jul 21, 2007
    Messages:
    2,871
    Location:
    somewhere
    Country:
    United Kingdom
    I'm not sure that information is any help to me. The problem I'm having, is that the games say that teh data is corrupt when it is loaded to the card.
     
  4. how_do_i_do_that

    Member how_do_i_do_that Blue Wizard is about to die.

    Joined:
    May 16, 2008
    Messages:
    4,803
    Country:
    Antarctica
    you can look at cory's source code to see what you might have done wrong. Or the wood code.
     

Share This Page