Spy:28464 want to write a Byte at 00600001
Thank you!
Code: Select all
//write score
SRAM_writeWord(0x00200000, score);
...
//read score
score= SRAM_readWord(0x00200000);
Moderator: Stef
Code: Select all
//write score
SRAM_writeWord(0x00200000, score);
...
//read score
score= SRAM_readWord(0x00200000);
Code: Select all
void sd_op_delay() __attribute__ ((section (".data")));
void sd_op_delay()
{
short i;
for (i=0; i<16; i++)
{
asm("nop\n");
}
}
Or enable SRAM from work RAM and disable before returning? :PChilly Willy wrote: ↑Tue Oct 01, 2019 2:56 pmThat will still need the game programmer to ensure that his code that calls SRAM functions aren't above 0x200000.
Wouldn't it be as slow as now? (bonus points if they can be optimized to a word-sized jump, since they'd be below the 32KB mark actually)Chilly Willy wrote: ↑Tue Oct 01, 2019 2:56 pmChanging the SRAM functions to work from sega.s makes them slower, but safe regardless of how they're used.
Huh, yeah, that may be a problem. When a game reaches over 2MB it'll be likely because of lots of data (not lots of code), so it's generally safe to assume that code is below the 2MB mark save extreme freak cases… but only if things are organized correctly.
still dont get what is this offset.Stef wrote: ↑Mon Sep 30, 2019 8:14 amSGDK uses SEGA SRAM mapper so it assumes base SRAM address to be 0x020000 and just require an offset (that is why the argument is called offset and not address).
So in your case just use offset 0x0000.
Also don't forget to enable SRAM (SRAM_enable()) before trying to read/write from/to it, then when it's done disable it otherwise ROM located at 0x020000 won't be accessible anymore.
Code: Select all
u32 offset0;
u32 offset1;
u32 offset2;
offset0 = 0;
offset1 = 1;
offset2 = 2;
array[0] = 1;
array[1] = 2;
array[2] = 3;
SRAM_enable();
SRAM_writeByte(offset0,array[0]);
SRAM_writeByte(offset1,array[1]);
SRAM_writeByte(offset2,array[2]);
SRAM_disable();
Code: Select all
u8 test;
SRAM_enable();
test = SRAM_readByte(offset0);
SRAM_disable();
if (test == 1)
{
... do stuff;
}
Code: Select all
//SAVE
SYS_disableInts();
SRAM_enable ();
waitMs(1000);
u32 sRamOffSet = 0x0000;
//Save ID
SRAM_writeByte(sRamOffSet, -99);
//KLog_S1("sRamOffSet:", sRamOffSet);
sRamOffSet ++;
for (u8 screenIndex = 0; screenIndex < 150; screenIndex ++)
{
for (u8 objectIndex = 0; objectIndex < 20; objectIndex ++)
{
SRAM_writeByte(sRamOffSet, arrDBObjects[screenIndex][objectIndex]);
//KLog_S1("sRamOffSet:", sRamOffSet);
sRamOffSet ++;
}
}
[code]
SRAM_disable ();
SYS_enableInts();
Code: Select all
//LOAD
SYS_disableInts();
SRAM_enableRO ();
u32 sRamOffSet = 0x0000;
//Verify Save ID
s8 saveTest = SRAM_readByte(sRamOffSet);
//KLog_S1("sRamOffSet:", sRamOffSet);
sRamOffSet ++;
if(saveTest != -99)
{
SRAM_disable();
SYS_enableInts();
VDP_drawText("FAILED. ", 6, 24);
SPR_update();
waitMs(1000);
return FALSE;
}
for (u8 screenIndex = 0; screenIndex < 150; screenIndex ++)
{
for (u8 objectIndex = 0; objectIndex < 20; objectIndex ++)
{
arrDBObjects[screenIndex][objectIndex] = SRAM_readByte(sRamOffSet);
//KLog_S1("sRamOffSet:", sRamOffSet);
sRamOffSet ++;
}
}
SRAM_disable ();
SYS_enableInts();