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 > DS cartridge EEPROM help

#51797 - bbennett69 - Tue Aug 23, 2005 4:25 pm

Has anybody got the cardReadEeprom and cardWriteEeprom code working.

Or can anybody help me in writing the code to read/write the DS save game.

Any help, pointers or any thing would help at this moment.

#52356 - DsPet - Tue Aug 30, 2005 12:55 am

The NDSLIB cardReadEeprom and cardWriteEeprom routines are significantly broken.
Even the #define for "CARD_CR1" is wrong.
The NDSLIB versions won't work for larger chips (addrtype=3, like Nintendogs)

Here's a read version that works (including addrtype=3). The write version is much more complicated since the larger chip needs blocks to be erased first.

Code:

#undef CARD_CR1
#define CARD_CR1       (*(vuint16*)0x040001A0) /*fixed*/

#define EepromWaitBusy()   while (CARD_CR1 & /*BUSY*/0x80);

void fixed_cardReadEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype)
{
    CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
    CARD_EEPDATA = 0x03 | ((addrtype == 1) ? address>>8<<3 : 0);
    EepromWaitBusy();

    if (addrtype == 3)
    {
        CARD_EEPDATA = (address >> 16) & 0xFF;
        EepromWaitBusy();
    }
    if (addrtype >= 2)
    {
        CARD_EEPDATA = (address >> 8) & 0xFF;
        EepromWaitBusy();
    }
    CARD_EEPDATA = (address) & 0xFF;
    EepromWaitBusy();

    while (length > 0)
    {
        CARD_EEPDATA = 0;
        EepromWaitBusy();
        *data++ = CARD_EEPDATA;
        length--;
    }
    CARD_CR1 = /*MODE*/0x40;
}

#52361 - The 9th Sage - Tue Aug 30, 2005 2:21 am

DsPet wrote:

The NDSLIB versions won't work for larger chips (addrtype=3, like Nintendogs)


Ah, I suspected Nintendogs used some kind of larger EEPROM. I was trying to back up the save, just for the sake of backing it up, and it would see that the NDS Max Drive software just gets confused (that and it seems like Nintendogs would have a heck of a lot of data to store compared to many games)...either that or it just doesn't have enough space for the save, which I kind of doubt.
_________________
Now with 20% More Old Man from Zelda 1 than ever before!

#52368 - josath - Tue Aug 30, 2005 6:21 am

The 9th Sage wrote:
DsPet wrote:

The NDSLIB versions won't work for larger chips (addrtype=3, like Nintendogs)


Ah, I suspected Nintendogs used some kind of larger EEPROM. I was trying to back up the save, just for the sake of backing it up, and it would see that the NDS Max Drive software just gets confused (that and it seems like Nintendogs would have a heck of a lot of data to store compared to many games)...either that or it just doesn't have enough space for the save, which I kind of doubt.


How much space does the 'NDS Max Drive' have? Most games are 8KB i believe, with a couple being 0.5KB, but nintendogs is 512KB...quite a difference in size.

#52471 - The 9th Sage - Wed Aug 31, 2005 3:38 am

josath wrote:
The 9th Sage wrote:
DsPet wrote:

The NDSLIB versions won't work for larger chips (addrtype=3, like Nintendogs)


Ah, I suspected Nintendogs used some kind of larger EEPROM. I was trying to back up the save, just for the sake of backing it up, and it would see that the NDS Max Drive software just gets confused (that and it seems like Nintendogs would have a heck of a lot of data to store compared to many games)...either that or it just doesn't have enough space for the save, which I kind of doubt.


How much space does the 'NDS Max Drive' have? Most games are 8KB i believe, with a couple being 0.5KB, but nintendogs is 512KB...quite a difference in size.


Actually, you may be right there...not sure EXACTLY how much there is, but assuming all my saves are 8k, and from my calculation you could fit roughly 17 of them on there, that would be quite a bit less than 512kb, so you are right there. Man, they really skimped on the space there I guess didn't they?
_________________
Now with 20% More Old Man from Zelda 1 than ever before!

#53550 - wintermute - Fri Sep 09, 2005 3:16 am

DsPet wrote:
The NDSLIB cardReadEeprom and cardWriteEeprom routines are significantly broken.
Even the #define for "CARD_CR1" is wrong.
The NDSLIB versions won't work for larger chips (addrtype=3, like Nintendogs)

Here's a read version that works (including addrtype=3). The write version is much more complicated since the larger chip needs blocks to be erased first.



It would be appreciated if things like this were posted to the devkitPro bug tracker for libnds found here -> http://sourceforge.net/tracker/?group_id=114505&atid=668551

this particular code made it into CVS and will probably be in the next release.