Move persistent memory outside of the RAM #483
This commit is contained in:
parent
bac3a9c3b6
commit
9786c6dcc5
|
@ -2186,7 +2186,7 @@ static void onConsoleRamCommand(Console* console, const char* param)
|
||||||
{offsetof(tic_ram, tiles), "TILES"},
|
{offsetof(tic_ram, tiles), "TILES"},
|
||||||
{offsetof(tic_ram, sprites), "SPRITES"},
|
{offsetof(tic_ram, sprites), "SPRITES"},
|
||||||
{offsetof(tic_ram, map), "MAP"},
|
{offsetof(tic_ram, map), "MAP"},
|
||||||
{offsetof(tic_ram, persistent), "PERSISTENT MEMORY"},
|
{offsetof(tic_ram, unknown), "..."},
|
||||||
{offsetof(tic_ram, registers), "SOUND REGISTERS"},
|
{offsetof(tic_ram, registers), "SOUND REGISTERS"},
|
||||||
{offsetof(tic_ram, sfx.waveform), "WAVEFORMS"},
|
{offsetof(tic_ram, sfx.waveform), "WAVEFORMS"},
|
||||||
{offsetof(tic_ram, sfx.samples), "SFX"},
|
{offsetof(tic_ram, sfx.samples), "SFX"},
|
||||||
|
|
|
@ -518,10 +518,10 @@ static duk_ret_t duk_pmem(duk_context* duk)
|
||||||
|
|
||||||
if(index < TIC_PERSISTENT_SIZE)
|
if(index < TIC_PERSISTENT_SIZE)
|
||||||
{
|
{
|
||||||
s32 val = memory->ram.persistent.data[index];
|
s32 val = memory->persistent.data[index];
|
||||||
|
|
||||||
if(!duk_is_null_or_undefined(duk, 1))
|
if(!duk_is_null_or_undefined(duk, 1))
|
||||||
memory->ram.persistent.data[index] = duk_to_int(duk, 1);
|
memory->persistent.data[index] = duk_to_int(duk, 1);
|
||||||
|
|
||||||
duk_push_int(duk, val);
|
duk_push_int(duk, val);
|
||||||
|
|
||||||
|
|
|
@ -993,11 +993,11 @@ static s32 lua_pmem(lua_State *lua)
|
||||||
|
|
||||||
if(index < TIC_PERSISTENT_SIZE)
|
if(index < TIC_PERSISTENT_SIZE)
|
||||||
{
|
{
|
||||||
s32 val = memory->ram.persistent.data[index];
|
s32 val = memory->persistent.data[index];
|
||||||
|
|
||||||
if(top >= 2)
|
if(top >= 2)
|
||||||
{
|
{
|
||||||
memory->ram.persistent.data[index] = getLuaNumber(lua, 2);
|
memory->persistent.data[index] = getLuaNumber(lua, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushinteger(lua, val);
|
lua_pushinteger(lua, val);
|
||||||
|
|
31
src/run.c
31
src/run.c
|
@ -76,16 +76,12 @@ static char* data2md5(const void* data, s32 length)
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* getPMemName(Run* run)
|
static void initPMemName(Run* run)
|
||||||
{
|
{
|
||||||
static char buffer[FILENAME_MAX];
|
|
||||||
|
|
||||||
const char* data = strlen(run->tic->saveid) ? run->tic->saveid : run->tic->cart.bank0.code.data;
|
const char* data = strlen(run->tic->saveid) ? run->tic->saveid : run->tic->cart.bank0.code.data;
|
||||||
char* md5 = data2md5(data, (s32)strlen(data));
|
char* md5 = data2md5(data, (s32)strlen(data));
|
||||||
strcpy(buffer, TIC_LOCAL);
|
strcpy(run->saveid, TIC_LOCAL);
|
||||||
strcat(buffer, md5);
|
strcat(run->saveid, md5);
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tick(Run* run)
|
static void tick(Run* run)
|
||||||
|
@ -99,11 +95,10 @@ static void tick(Run* run)
|
||||||
|
|
||||||
enum {Size = sizeof(tic_persistent)};
|
enum {Size = sizeof(tic_persistent)};
|
||||||
|
|
||||||
if(SDL_memcmp(&run->tic->ram.persistent, run->persistent, Size) != 0)
|
if(SDL_memcmp(&run->tic->persistent, &run->persistent, Size) != 0)
|
||||||
{
|
{
|
||||||
fsSaveRootFile(run->console->fs, getPMemName(run), &run->tic->ram.persistent, Size, true);
|
fsSaveRootFile(run->console->fs, run->saveid, &run->tic->persistent, Size, true);
|
||||||
|
SDL_memcpy(&run->persistent, &run->tic->persistent, Size);
|
||||||
SDL_memcpy(run->persistent, &run->tic->ram.persistent, Size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(run->exit)
|
if(run->exit)
|
||||||
|
@ -203,15 +198,19 @@ void initRun(Run* run, Console* console, tic_mem* tic)
|
||||||
|
|
||||||
{
|
{
|
||||||
enum {Size = sizeof(tic_persistent)};
|
enum {Size = sizeof(tic_persistent)};
|
||||||
SDL_memset(&run->tic->ram.persistent, 0, Size);
|
SDL_memset(&run->tic->persistent, 0, Size);
|
||||||
|
|
||||||
|
initPMemName(run);
|
||||||
|
|
||||||
s32 size = 0;
|
s32 size = 0;
|
||||||
void* data = fsLoadRootFile(run->console->fs, getPMemName(run), &size);
|
void* data = fsLoadRootFile(run->console->fs, run->saveid, &size);
|
||||||
|
|
||||||
if(size == Size && data)
|
if(size > Size) size = Size;
|
||||||
|
|
||||||
|
if(data)
|
||||||
{
|
{
|
||||||
SDL_memcpy(&run->tic->ram.persistent, data, Size);
|
SDL_memcpy(&run->tic->persistent, data, size);
|
||||||
SDL_memcpy(run->persistent, data, Size);
|
SDL_memcpy(&run->persistent, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data) SDL_free(data);
|
if(data) SDL_free(data);
|
||||||
|
|
|
@ -34,7 +34,8 @@ struct Run
|
||||||
|
|
||||||
bool exit;
|
bool exit;
|
||||||
|
|
||||||
s32 persistent[TIC_PERSISTENT_SIZE];
|
tic_persistent persistent;
|
||||||
|
char saveid[TIC_SAVEID_SIZE];
|
||||||
|
|
||||||
void(*tick)(Run*);
|
void(*tick)(Run*);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1509,7 +1509,7 @@ static void updateSaveid(tic_mem* memory)
|
||||||
const char* saveid = readMetatag(memory->cart.bank0.code.data, "saveid", api_get_script_config(memory)->singleComment);
|
const char* saveid = readMetatag(memory->cart.bank0.code.data, "saveid", api_get_script_config(memory)->singleComment);
|
||||||
if(saveid)
|
if(saveid)
|
||||||
{
|
{
|
||||||
strcpy(memory->saveid, saveid);
|
strncpy(memory->saveid, saveid, TIC_SAVEID_SIZE-1);
|
||||||
free((void*)saveid);
|
free((void*)saveid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
#define TIC_MAP_WIDTH (TIC_MAP_SCREEN_WIDTH * TIC_MAP_ROWS)
|
#define TIC_MAP_WIDTH (TIC_MAP_SCREEN_WIDTH * TIC_MAP_ROWS)
|
||||||
#define TIC_MAP_HEIGHT (TIC_MAP_SCREEN_HEIGHT * TIC_MAP_COLS)
|
#define TIC_MAP_HEIGHT (TIC_MAP_SCREEN_HEIGHT * TIC_MAP_COLS)
|
||||||
|
|
||||||
#define TIC_PERSISTENT_SIZE ((56-25)/sizeof(s32))
|
#define TIC_PERSISTENT_SIZE (1024/sizeof(s32)) // 1K
|
||||||
#define TIC_SAVEID_SIZE 64
|
#define TIC_SAVEID_SIZE 64
|
||||||
|
|
||||||
#define TIC_SOUND_CHANNELS 4
|
#define TIC_SOUND_CHANNELS 4
|
||||||
|
@ -415,7 +415,7 @@ typedef union
|
||||||
tic_tiles tiles;
|
tic_tiles tiles;
|
||||||
tic_tiles sprites;
|
tic_tiles sprites;
|
||||||
tic_map map;
|
tic_map map;
|
||||||
tic_persistent persistent;
|
u8 unknown[28];
|
||||||
tic_sound_register registers[TIC_SOUND_CHANNELS];
|
tic_sound_register registers[TIC_SOUND_CHANNELS];
|
||||||
tic_sfx sfx;
|
tic_sfx sfx;
|
||||||
tic_music music;
|
tic_music music;
|
||||||
|
|
|
@ -173,6 +173,7 @@ struct tic_mem
|
||||||
tic_input_method input;
|
tic_input_method input;
|
||||||
tic_font font;
|
tic_font font;
|
||||||
tic_api api;
|
tic_api api;
|
||||||
|
tic_persistent persistent;
|
||||||
|
|
||||||
char saveid[TIC_SAVEID_SIZE];
|
char saveid[TIC_SAVEID_SIZE];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue