Skip to content

Commit

Permalink
store saves and configs in gpsp dir
Browse files Browse the repository at this point in the history
Don't like ROM dir littering.
Still looking there for .sav and .cht files though.
  • Loading branch information
notaz committed Sep 7, 2011
1 parent a88b043 commit d0944fc
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 39 deletions.
8 changes: 8 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
#define ror(dest, value, shift) \
dest = ((value) >> shift) | ((value) << (32 - shift)) \

#if defined(_WIN32) || defined(_WIN32_WCE)
#define PATH_SEPARATOR "\\"
#define PATH_SEPARATOR_CHAR '\\'
#else
#define PATH_SEPARATOR "/"
#define PATH_SEPARATOR_CHAR '/'
#endif

// These includes must be used before SDL is included.
#ifdef ARM_ARCH

Expand Down
30 changes: 9 additions & 21 deletions gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ s32 load_game_config_file()
char game_config_filename[512];
u32 file_loaded = 0;
u32 i;
change_ext(gamepak_filename, game_config_filename, ".cfg");
make_rpath(game_config_filename, sizeof(game_config_filename), ".cfg");

file_open(game_config_file, game_config_filename, read);

Expand Down Expand Up @@ -841,11 +841,7 @@ s32 load_config_file()
{
char config_path[512];

#if defined(_WIN32) || defined(_WIN32_WCE)
sprintf(config_path, "%s\\%s", main_path, GPSP_CONFIG_FILENAME);
#else
sprintf(config_path, "%s/%s", main_path, GPSP_CONFIG_FILENAME);
#endif
sprintf(config_path, "%s" PATH_SEPARATOR "%s", main_path, GPSP_CONFIG_FILENAME);

file_open(config_file, config_path, read);

Expand Down Expand Up @@ -915,7 +911,7 @@ s32 save_game_config_file()
char game_config_filename[512];
u32 i;

change_ext(gamepak_filename, game_config_filename, ".cfg");
make_rpath(game_config_filename, sizeof(game_config_filename), ".cfg");

file_open(game_config_file, game_config_filename, write);

Expand Down Expand Up @@ -947,11 +943,7 @@ s32 save_config_file()
{
char config_path[512];

#if (defined(PSP_BUILD) || defined(ARM_ARCH)) && !defined(_WIN32_WCE)
sprintf(config_path, "%s/%s", main_path, GPSP_CONFIG_FILENAME);
#else
sprintf(config_path, "%s\\%s", main_path, GPSP_CONFIG_FILENAME);
#endif
sprintf(config_path, "%s" PATH_SEPARATOR "%s", main_path, GPSP_CONFIG_FILENAME);

file_open(config_file, config_path, write);

Expand Down Expand Up @@ -1044,22 +1036,18 @@ void get_savestate_snapshot(char *savestate_filename)
#endif
}

void get_savestate_filename(u32 slot, char *name_buffer)
void get_savestate_filename_noshot(u32 slot, char *name_buffer)
{
char savestate_ext[16];

sprintf(savestate_ext, "%d.svs", slot);
change_ext(gamepak_filename, name_buffer, savestate_ext);

get_savestate_snapshot(name_buffer);
make_rpath(name_buffer, 512, savestate_ext);
}

void get_savestate_filename_noshot(u32 slot, char *name_buffer)
void get_savestate_filename(u32 slot, char *name_buffer)
{
char savestate_ext[16];

sprintf(savestate_ext, "%d.svs", slot);
change_ext(gamepak_filename, name_buffer, savestate_ext);
get_savestate_filename_noshot(slot, name_buffer);
get_savestate_snapshot(name_buffer);
}

#ifdef PSP_BUILD
Expand Down
33 changes: 24 additions & 9 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ void init_main()

int main(int argc, char *argv[])
{
char bios_filename[512];
int ret;

#ifdef PSP_BUILD
sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0,
vblank_interrupt_handler, NULL);
Expand Down Expand Up @@ -208,13 +211,11 @@ int main(int argc, char *argv[])

init_video();

#ifdef GP2X_BUILD
char bios_filename[512];
sprintf(bios_filename, "%s/%s", main_path, "gba_bios.bin");
if(load_bios(bios_filename) == -1)
#else
if(load_bios("gba_bios.bin") == -1)
#endif
sprintf(bios_filename, "%s" PATH_SEPARATOR "%s", main_path, "gba_bios.bin");
ret = load_bios(bios_filename);
if (ret != 0)
ret = load_bios("gba_bios.bin");
if (ret != 0)
{
gui_action_type gui_action = CURSOR_NONE;

Expand Down Expand Up @@ -579,10 +580,10 @@ u32 update_gba()
frame_ticks++;

#ifdef PC_BUILD
printf("frame update (%x), %d instructions total, %d RAM flushes\n",
/* printf("frame update (%x), %d instructions total, %d RAM flushes\n",
reg[REG_PC], instruction_count - last_frame, flush_ram_count);
last_frame = instruction_count;

*/
/* printf("%d gbc audio updates\n", gbc_update_count);
printf("%d oam updates\n", oam_update_count); */
gbc_update_count = 0;
Expand Down Expand Up @@ -943,6 +944,20 @@ void change_ext(const char *src, char *buffer, const char *extension)
strcpy(dot_position, extension);
}

// make path: <main_path>/<romname>.<ext>
void make_rpath(char *buff, size_t size, const char *ext)
{
char *p;
p = strrchr(gamepak_filename, PATH_SEPARATOR_CHAR);
if (p == NULL)
p = gamepak_filename;

snprintf(buff, size, "%s/%s", main_path, p);
p = strrchr(buff, '.');
if (p != NULL)
strcpy(p, ext);
}

#define main_savestate_builder(type) \
void main_##type##_savestate(file_tag_type savestate_file) \
{ \
Expand Down
1 change: 1 addition & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ static u32 prescale_table[] = { 0, 6, 8, 10 };
#endif // IN_MEMORY_C

void change_ext(const char *src, char *buffer, const char *extension);
void make_rpath(char *buff, size_t size, const char *ext);

void set_clock_speed();

Expand Down
23 changes: 14 additions & 9 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2022,11 +2022,7 @@ s32 load_game_config(char *gamepak_title, char *gamepak_code, char *gamepak_make
translation_gate_targets = 0;
flash_device_id = FLASH_DEVICE_MACRONIX_64KB;

#if (defined(PSP_BUILD) || defined(ARM_ARCH)) && !defined(_WIN32_WCE)
sprintf(config_path, "%s/%s", main_path, CONFIG_FILENAME);
#else
sprintf(config_path, "%s\\%s", main_path, CONFIG_FILENAME);
#endif
sprintf(config_path, "%s" PATH_SEPARATOR "%s", main_path, CONFIG_FILENAME);

config_file = fopen(config_path, "rb");

Expand Down Expand Up @@ -2113,6 +2109,9 @@ s32 load_game_config(char *gamepak_title, char *gamepak_code, char *gamepak_make
fclose(config_file);
}

#ifndef PSP_BUILD
printf("game config missing\n");
#endif
return -1;
}

Expand Down Expand Up @@ -2182,11 +2181,17 @@ u32 load_gamepak(char *name)
{
gamepak_size = (file_size + 0x7FFF) & ~0x7FFF;

strcpy(backup_filename, name);
strncpy(gamepak_filename, name, 512);
change_ext(gamepak_filename, backup_filename, ".sav");
strncpy(gamepak_filename, name, sizeof(gamepak_filename));
gamepak_filename[sizeof(gamepak_filename) - 1] = 0;

load_backup(backup_filename);
make_rpath(backup_filename, sizeof(backup_filename), ".sav");
if (!load_backup(backup_filename))
{
// try path used by older versions
strcpy(backup_filename, name);
change_ext(gamepak_filename, backup_filename, ".sav");
load_backup(backup_filename);
}

memcpy(gamepak_title, gamepak_rom + 0xA0, 12);
memcpy(gamepak_code, gamepak_rom + 0xAC, 4);
Expand Down

0 comments on commit d0944fc

Please sign in to comment.