Hi there!
Just playing with SRAM instructions and Genskmod to check with Klog, all seems to work well.
I just want to save some data, player name (i.e. "AAA\0") and its points. Doing this, maybe not best method.
Do you see anything wrong here?
Code: Select all
struct {
char player_name[4];
u16 points;
}Ranking[NUM_PLAYERS_RANKING];
[..]
//data "by default" when 1st time game running
strcpy( Ranking[0].player_name, "AAA\0" );
Ranking[0].points=10000;
strcpy( Ranking[1].player_name, "BBB\0" );
Ranking[1].points=9000;
strcpy( Ranking[2].player_name, "CCC\0" );
Ranking[2].points=8000;
[..]
int save_ranking()
{
u16 SRAMoffset = 0x0000;
SRAM_enable();
for(u8 i=0; i<NUM_PLAYERS_RANKING; i++)
{
SRAM_writeByte(SRAMoffset, Ranking[0].player_name[0]); SRAMoffset++;
SRAM_writeByte(SRAMoffset, Ranking[0].player_name[1]); SRAMoffset++;
SRAM_writeByte(SRAMoffset, Ranking[0].player_name[2]); SRAMoffset++;
SRAM_writeByte(SRAMoffset, Ranking[0].player_name[3]); SRAMoffset++;
SRAM_writeWord(SRAMoffset, Ranking[0].points); SRAMoffset++;
}
SRAM_disable();
return 1;
}
int read_ranking()
{
u16 SRAMoffset = 0x0000;
u16 temp = NULL;
char ctemp[4], ctemp2[4];
SRAM_enable();
for(u8 i=0; i<NUM_PLAYERS_RANKING; i++)
{
ctemp[0] = SRAM_readByte(SRAMoffset); SRAMoffset++;
ctemp[1] = SRAM_readByte(SRAMoffset); SRAMoffset++;
ctemp[2] = SRAM_readByte(SRAMoffset); SRAMoffset++;
ctemp[3] = SRAM_readByte(SRAMoffset); SRAMoffset++;
sprintf(ctemp2, "%c%c%c%c", ctemp[0],ctemp[1],ctemp[2],ctemp[3]);
strcpy( Ranking[0].player_name, ctemp2 );
temp = SRAM_readWord(SRAMoffset); SRAMoffset++;
Ranking[0].points= temp;
}
SRAM_disable();
//update high score
Game.high_score = (Ranking[0].points> 10000) ? Ranking[0].points: 10000;
return 1;
}
I think I don't understand is offset. I just make
after read/write a byte, this is logical. But also make the same when reading/writing a word... I mean... word=2 bytes... so why is this working if offset is "moving" just "1 byte"?
Another question is where I can found SRAM... is in BIN file? I tried to open BIN and look for AAA, BBB, CCC.
Only found this using HxD
- Captura.PNG (5.64 KiB) Viewed 56205 times
I honestly I don't know what to do... where are the points???