#104037 - Moeity - Tue Sep 26, 2006 2:57 am
I'm trying to save a simple single uint32 value to SRAM. I'm using some standard write and read functions:
Then using:
It appears to write, and load back fine when testing, however after powering off I always get a constant value that is not what I saved back. Am I doing anything obviously wrong in code?
It could also be I'm not setting up my Supercard Lite properly... I compiled in devkitarm, copied the program.nds file to my SD card as /program.nds, and copied the default .sav file from the Supercard program directory as /program.sav.
Any ideas? Once this is working I should have a version 0.1 of a working ebook reader with loadable aa fonts, run-time font-resizing and coloring, switchable potrait/landscape modes, and automatic page saving whose souce I can give to anyone interested. Hope to add some very basic html tag parsing and filesytem reading for version 0.2, at which time it should be a decent ebook reader.
Code: |
void writeSram(int offset, char const* src, int size) { WAIT_CR &= ~0x0880; char* dest = (char*)SRAM; if(offset>0){ while(offset--){ *dest++; } } int x = 0; while(size--){ *dest++ = (uint8)(src[x]); x++; } } void readSram(int offset, char* dest, int size) { WAIT_CR &= ~0x0880; char const* src = (char const*)SRAM; if(offset>0){ while(offset--){ *src++; } } int x = 0; while(size--){ *dest++ = (uint8)(src[x]); x++; } } |
Then using:
Code: |
uint32 now_index; const int S_INDEX_LOC = 0; ... void save(){ writeSram(S_INDEX_LOC, (char*)&now_index, sizeof(now_index)); } void load(){ readSram(S_INDEX_LOC, (char*)&now_index, sizeof(now_index)); } |
It appears to write, and load back fine when testing, however after powering off I always get a constant value that is not what I saved back. Am I doing anything obviously wrong in code?
It could also be I'm not setting up my Supercard Lite properly... I compiled in devkitarm, copied the program.nds file to my SD card as /program.nds, and copied the default .sav file from the Supercard program directory as /program.sav.
Any ideas? Once this is working I should have a version 0.1 of a working ebook reader with loadable aa fonts, run-time font-resizing and coloring, switchable potrait/landscape modes, and automatic page saving whose souce I can give to anyone interested. Hope to add some very basic html tag parsing and filesytem reading for version 0.2, at which time it should be a decent ebook reader.