here is my mini tutorial of how I achived to use save with sram
(I can edit it, if someone find something wrong)
thanks to Chilly Willy, SIk, Stef and cloudstrifer.
---
1) to activate the sram save in your game, you should go to folder src/boot and look for file rom_head.c
you will find lines like these:
Code: Select all
...
0x00FF0000,
0x00FFFFFF,
" ",
0x0000,
0x00200000,
0x002001FF,
" ",
"DEMONSTRATION PROGRAM ",
"JUE "
...
following the comments in this file, you should do this
Code: Select all
...
0x00FF0000,
0x00FFFFFF,
"RA", /* "RA" for save ram (2) */
0xF820, /* 0xF820 for save ram on odd bytes (2) */
0x200001, /* SRAM start address - normally 0x200001 (4) */
0x2003FF, /* SRAM end address - start + 2*sram_size (4)
My comment: as Sik and Chilly Willy said, you can go up to 0x207FFF
(this is a hexadecimal number, base 16, and is equal to 32767) */
" ",
"DEMONSTRATION PROGRAM ",
"JUE "
...
2) now that sram save is active, you can code what you want.

example how to save three u8 variables and to take what was stored there to other three u8 variables.
Code: Select all
...
u32 sRAMoffset1;
u32 sRAMoffset2;
u32 sRAMoffset3;
SRAMoffset1 = 0x0000;
SRAMoffset2 = 0x0001;
SRAMoffset3 = 0x0003; /* as, in this example, it is activate do use memory up to address 0x2003FF,
you can create 0x03FF=1023 SRAMoffset variables. */
u8 variable1;
u8 variable2;
u8 variable3;
variable1 = 10;
variable2 = 255;
variable3 = 100;
SRAM_enable(); // to use SRAM, shoud enable it
SRAM_writeByte(SRAMoffset1,variable1); // will record the value of variable1 in SRAM at SRAMoffset1
SRAM_writeByte(SRAMoffset2,variable2); // will record the value of variable2 in SRAM at SRAMoffset2
SRAM_writeByte(SRAMoffset3,variable3); // will record the value of variable3 in SRAM at SRAMoffset3
SRAM_disable(); // after do what you want, should disable it
...
u8 var_value1;
u8 var_value2;
u8 var_value3;
SRAM_enable();
var_value1 = SRAM_readByte(SRAMoffset1); // will give the var_value1 the value stored in SRAMoffset1
var_value2 = SRAM_readByte(SRAMoffset1); // will give the var_value2 the value stored in SRAMoffset2
var_value3 = SRAM_readByte(SRAMoffset1); // will give the var_value3 the value stored in SRAMoffset3
SRAM_disable();
...