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 > EEPROM Problems

#168235 - Conutmonky - Thu Apr 16, 2009 9:51 am

Hello world,

So I am working on saving my game using the EEPROM. I have looked through the forum and found some posts about not using it, but I want to try and so here is what i'm doing:

uint8 writeBuffer[6] = "Hello";
uint8 readBuffer[6];
cardWriteEeprom(0, writeBuffer, sizeof(writeBuffer), 2);
cardReadEeprom(0, readBuffer, sizeof(readBuffer), 2);
iprintf("Data is :%s or :%s \n", readBuffer, writeBuffer);

So the idea was just something very simple. First off, I know the last argument for the Eeprom functions is "type" but i'm not sure which type they are referring to (I think different size eeprom). I also read that many emulators don't support eeprom, but the posts were old and i'm not sure if that is still true considering my emulator has save options to configure for eeprom.

Also, the first argument is the address I believe, and I thought I read 0 would be the beginning of the eeprom but perhaps that isn't true. Should I be getting a file generated from my emulator when I do the cardWriteEeprom?

I was hoping for either some ideas, or a good place to look, or some help fixing up my code just to get something basic written and retrieved.

Thanks,
Mike

#168378 - josath - Sun Apr 26, 2009 6:12 am

Hi,

EEPROM is only for commercial game carts. The eeprom functions will not work for homebrew in 90% of the flashcarts, so you should not use them. Instead you should use libfat, and create a file on the card. Basically you call fatInitDefault(), and then use the standard C file I/O functions, fopen, fwrite, fread, fclose, etc.

#168432 - spinal_cord - Wed Apr 29, 2009 6:56 am

[Hijack] (sorry)

I am also having eeprom problems, but in conjunction with FAT. I am trying to backup eeprom to a file, but if I init fat before reading the eeprom, the fat functions don't work. However if I do it after reading the eeprom it works fine.

Code:

   fatInitDefault();

   int cardtype=cardmeGetType();

   if(cardtype==-1){PA_OutputText(0,3,4,"No card or No EEPROM");}
//   if(cardtype==0) {PA_OutputText(0,3,4,"Unknown save type");}
//   if(cardtype==1) {PA_OutputText(0,3,4,"You have Save Type 1");}
//   if(cardtype==2) {PA_OutputText(0,3,4,"You have Save Type 2");}
   if(cardtype==3) {PA_OutputText(0,3,4,"You have Save Type 3");
   int i=0;
   for (i = 0; i < 262144; i += 8192) {
      cardmeReadEeprom(i, saveData + i, 8192, 3);
      PA_OutputText(0,3,4,"%d/262144      ",i);
   }
      PA_OutputText(0,3,4,"Done!                      ",i);

   PA_OutputText(0,3,5,"Problem."); // if you read this, it crashed :(
   
   FILE *fp;
   fp=fopen("test.dat", "wb");
   if(fp){
      PA_OutputText(0,3,4,"File Open");
      for (i = 0; i < 262144; i += 1) {
         fwrite(saveData+i, 1, 1, fp); //8192
         PA_OutputText(0,3,5,"%d/262144      ",i); // Just to show something happening
      }
      fclose(fp);
      PA_OutputText(0,3,5,"File Closed");
   }
} // savetype == 3


Can anyone suggest what the problem might be? I would really like to restore eeprom from a file also, but not being able to use fat sorta rules that out :(
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#168433 - josath - Wed Apr 29, 2009 7:11 am

What flashcart are you using, is it slot-1 or slot-2, and what DS game cart are you using?

#168472 - spinal_cord - Wed Apr 29, 2009 8:17 pm

josath wrote:
What flashcart are you using, is it slot-1 or slot-2, and what DS game cart are you using?


Currently, i'm trying to use a neoflash mk5, which is a slot-1 card with 2mbit eeprom. Your eepinator (that was you wasn't it?) works fine, so I at least know what it should work.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#168504 - josath - Fri May 01, 2009 10:57 pm

So...you're trying to read from the eeprom inside the mk5, and write to the SD card inside the mk5? That seems pointless, so I must be missing something here.

Most likely it's not working because the mk5 does something funny, maybe you need some proprietary unlock codes to switch between eeprom and fat usage correctly

#168513 - Conutmonky - Sat May 02, 2009 3:31 am

Alright, with much remorse I will indeed use libfat. Are there any emulators that work with libfat for testing purposes? I tried no$gba and desmume and they both give errors on fatInitDefault. Or should I just do my testing, etc. on a DS?

Thanks,
Mike

#168517 - dantheman - Sat May 02, 2009 6:29 am

The FCSR process lets you build a virtual FAT12 filesystem with your files packed inside, which is appended to the rom file. This lets you test apps that use Libfat in emulators like no$gba. Just make sure you search the forums here for a program Dwedit made called AddToDiskImage which is more stable than the "bfi.exe" program normally used to inject files into the FAT12 filesystem.

Something else you can try: iDeaS has DLDI support for the R4. Patch your game with the R4 DLDI file and select the appropriate option in the iDeaS menu.