Don't like ROM dir littering.
Still looking there for .sav and .cht files though.
#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
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);
{
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);
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);
{
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);
#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
int main(int argc, char *argv[])
{
+ char bios_filename[512];
+ int ret;
+
#ifdef PSP_BUILD
sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0,
vblank_interrupt_handler, NULL);
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;
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;
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) \
{ \
#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();
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");
fclose(config_file);
}
+#ifndef PSP_BUILD
+ printf("game config missing\n");
+#endif
return -1;
}
{
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);