Page 1 of 1

Reading gba SRAM

Posted: Wed Mar 16, 2011 10:24 pm
by Dren
I want to load a gba save file into a gba cartridge's sram - I don't have a flash cartridge for gba. I can't seem to access the sram correctly. With this code I get no output, which means I'm getting a bunch of zeros:

Code: Select all

	vramSetBankE(VRAM_E_MAIN_BG);
	vramSetBankF(VRAM_F_MAIN_SPRITE);

	consoleDemoInit();
	consoleDebugInit(DebugDevice_CONSOLE);

	sysSetCardOwner(true);
	for (int i=0; i<0x10000; i++)
	{
		if (SRAM[i] != 0)
			printf("%d ", i);
	}
Writing to it had no effect either, didn't even corrupt the save file, but I'm probably missing something obvious. I also don't know what I'm doing with sysSetCardOwner(), but I read that I need it. The only examples I could find were very outdated and they don't compile anymore.

Re: Reading gba SRAM

Posted: Mon Mar 21, 2011 4:01 am
by zeromus
use sysSetCartOwner. Car_t_ is GBA slot-2; Car_d_ is NDS slot-1. of course, the comments say that.

Re: Reading gba SRAM

Posted: Mon Mar 21, 2011 9:10 pm
by Dren
Oops. Well now it works, almost.
I've uploaded a save file into Final Fantasy V, but I can't yet write data to Pokemon Sapphire. As far as I can tell it uses a 1Mb flash chip. According to the nocash technical info on the gba I'm supposed to use commands instead of writing directly but none have any effect - I'm probably using them wrong. It says:
Erase Entire Chip (all device types)

[E005555h]=AAh, [E002AAAh]=55h, [E005555h]=80h (erase command)
[E005555h]=AAh, [E002AAAh]=55h, [E005555h]=10h (erase entire chip)
wait until [E000000h]=FFh (or timeout)

Erases all memory in chip, erased memory is FFh-filled.
I tried writing the values like this:

Code: Select all

	SRAM[0x005555] = 0xAA;
	SRAM[0x002AAA] = 0x55;
	SRAM[0x005555] = 0x80;

	SRAM[0x005555] = 0xAA;
	SRAM[0x002AAA] = 0x55;
	SRAM[0x005555] = 0x10;
Is that the way to go about it? It had no effect.

Re: Reading gba SRAM

Posted: Tue Mar 22, 2011 6:39 am
by zeromus
that's probably beyond the scope of this forum. you can't really expect to find experts on accessing flash memory on a gba cart.

Re: Reading gba SRAM

Posted: Tue Mar 22, 2011 8:35 pm
by Dren
I was afraid of that. Well thanks for the help.