store saves and configs in gpsp dir
authornotaz <notaz@pixelinis>
Wed, 7 Sep 2011 20:45:45 +0000 (23:45 +0300)
committernotaz <notaz@pixelinis>
Wed, 7 Sep 2011 21:48:33 +0000 (00:48 +0300)
Don't like ROM dir littering.
Still looking there for .sav and .cht files though.

common.h
gui.c
main.c
main.h
memory.c

index 9d4f605..f97549f 100644 (file)
--- a/common.h
+++ b/common.h
 #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
 
diff --git a/gui.c b/gui.c
index cd8f4f3..893d7c9 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -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);
 
@@ -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);
 
@@ -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);
 
@@ -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);
 
@@ -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
diff --git a/main.c b/main.c
index 340b0be..967ac73 100644 (file)
--- a/main.c
+++ b/main.c
@@ -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);
@@ -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;
 
@@ -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;
@@ -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)                    \
 {                                                                             \
diff --git a/main.h b/main.h
index 671974c..96739dc 100644 (file)
--- a/main.h
+++ b/main.h
@@ -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();
 
index 103e85a..db05001 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -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");
 
@@ -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;
 }
 
@@ -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);