how to check if SRAM is working?

SGDK only sub forum

Moderator: Stef

Post Reply
danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

how to check if SRAM is working?

Post by danibus » Fri Aug 12, 2022 12:14 am

Good day all

I'm currently working in my own game and I want to use SRAM to keep top3 scores in cartridge.
Of course using severals emulators to check if everything is working properly.
I wrote some functions that are working well in GensKmod but i.e. they failed in KFusion.

I.e. I make this function to try to know if I can use SRAM.
Just try to save somewhere in SRAM, after that try to read same info and compare.
Then return 1 if success, if not return 0

Code: Select all

int thereis_sram()  // any SRAM there???
{

    u32 testSRAMoffset = 0x0100;
    char testSRAMtext[]="SEGADOES";
    SYS_disableInts();
    SRAM_enable();
    for(int i=0; i<8;i++) SRAM_writeByte(testSRAMoffset++, testSRAMtext[i]);
    SRAM_disable();
    SYS_enableInts();

    //now read
    SYS_disableInts();
    SRAM_enable();
    testSRAMoffset = 0x0100;
    char testSRAMtextREAD[9]={'X','X','X','X','X','X','X','X'};
    for(int i=0; i<8;i++) testSRAMtextREAD[i] = SRAM_readByte(testSRAMoffset++);
    SRAM_disable();
    SYS_enableInts();

	if(strcmp(testSRAMtext,testSRAMtextREAD)==0) return 1;  //strcmp: A zero value indicates that both strings are equal.
	else  return 0;
}
Then I have functions to save top scores in SRAM and to read scores from SRAM. Same like above but using struct to save/read top3 info.
ONLY if thereis_sram() returns 1.
If not, I just create my own "fake top3 scores" and don't read from SRAM.

All it's working in GensKMod or Blastem.
But then I put KFusion... and show me top3 with strange scores.... not sure what is happening.
Maybe I'm doing wrong.

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: how to check if SRAM is working?

Post by cero » Fri Aug 12, 2022 6:47 am

Check your SRAM header. Your code also needs to be below 2mb.

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: how to check if SRAM is working?

Post by danibus » Fri Aug 12, 2022 4:16 pm

cero wrote:
Fri Aug 12, 2022 6:47 am
Check your SRAM header. Your code also needs to be below 2mb.

Already did sram header. What do you want me to check exactly?
My rom.bin is 2048KB right now.
So I think I'm in the limit.

Post Reply