#33516 - isildur - Tue Jan 04, 2005 9:19 pm
I just implemented a high score save in my game. I save the high scores to sram and read them back. In VBA, it works perfectly but with my EFA flash cart, the data read from SRAM is just garbage.
When writing the rom to the EFA cart, I specify 256kbits of sram. I only use 48 bytes of it though...
When I read or write to sram, I do it one byte at a time.
Any idea?
#33517 - sgeos - Tue Jan 04, 2005 9:24 pm
Write a simple SRAM read/write test program. If it doesn't work, post it.
-Brendan
#33519 - isildur - Tue Jan 04, 2005 9:33 pm
These are my sram routines:
Code: |
#define SRAM 0x0e000000
void SramWrite(u8* data, u16 size, u16 sram_offset)
{
volatile u8* sramMem;
int i = 0;
sramMem = (u8*)(SRAM + sram_offset);
i = size-1;
while(i >= 0)
{
sramMem[i] = data[i];
i--;
}
}
void SramRead(u8* data, u16 size, u16 sram_offset)
{
volatile u8* sramMem;
int i = 0;
sramMem = (u8*)(SRAM + sram_offset);
i = size-1;
while(i >= 0)
{
data[i] = sramMem[i];
i--;
}
}
|
#33522 - ScottLininger - Tue Jan 04, 2005 9:49 pm
I've been told that the first few bytes of SRAM are not "safe" for writing. Try changing from SRAM from 0x0e000000 to 0x0e000008 and see if there's any difference.
-Scott
#33524 - isildur - Tue Jan 04, 2005 9:58 pm
Ok, I just figured it out. I wrongly assumed that sram memory was all set to zeros by default. On VBA, it is zeroed but on my cart it's not, so I thought I was reading data when it was in fact garbage.
Scott, are you sure about this thing that its not safe to use the first sram bytes? In doubt, I will follow your advice.
#33526 - ScottLininger - Tue Jan 04, 2005 10:15 pm
isildur wrote: |
Scott, are you sure about this thing that its not safe to use the first sram bytes? In doubt, I will follow your advice. |
I haven't personally confirmed it, but I've erred on the side of safety and assumed it's more than a colorful rumor.
In the FAQ, it states:
Quote: |
Another tip: Don't use the first or last byte of SRAM, as those locations can become corrupted in some cases during power-cycle or pak-swapping. |
So I'd say stay away from the first byte, at least.
-Scott
#33566 - ampz - Wed Jan 05, 2005 3:37 pm
It is indeed true that it is safer to stay away from the first (and possibly the last) byte.
There is protection circuitry disabling the SRAM as soon as the power drops below 3Volts, but there is still a small chance that the first byte can become corrupted under worst case conditions. Like if someone yanks out the cart during runtime.