From 41484cd73c4114228c12f6456f61cc5caa72fecf Mon Sep 17 00:00:00 2001 From: aliaspider Date: Wed, 10 Dec 2014 12:00:12 +0100 Subject: use correct save directory. --- gba_memory.c | 47 +++++++++++------------------------------------ gba_memory.h | 1 - libretro.c | 33 ++++++++++++--------------------- main.c | 16 ++-------------- main.h | 2 +- 5 files changed, 26 insertions(+), 73 deletions(-) diff --git a/gba_memory.c b/gba_memory.c index f043de1..5da018b 100644 --- a/gba_memory.c +++ b/gba_memory.c @@ -376,14 +376,6 @@ u32 gbc_sound_update = 0; // If the GBC audio waveform is modified: u32 gbc_sound_wave_update = 0; -// If the backup space is written (only update once this hits 0) -u32 backup_update = 0; - -// Write out backup file this many cycles after the most recent -// backup write. -const u32 write_backup_delay = 10; - - typedef enum { BACKUP_SRAM, @@ -569,7 +561,6 @@ void function_cc write_eeprom(u32 address, u32 value) eeprom_counter++; if(eeprom_counter == 64) { - backup_update = write_backup_delay; eeprom_counter = 0; eeprom_mode = EEPROM_WRITE_FOOTER_MODE; } @@ -1619,7 +1610,6 @@ void function_cc write_backup(u32 address, u32 value) memset(gamepak_backup, 0xFF, 1024 * 64); else memset(gamepak_backup, 0xFF, 1024 * 128); - backup_update = write_backup_delay; flash_mode = FLASH_BASE_MODE; } break; @@ -1646,7 +1636,6 @@ void function_cc write_backup(u32 address, u32 value) { // Erase sector memset(flash_bank_ptr + (address & 0xF000), 0xFF, 1024 * 4); - backup_update = write_backup_delay; flash_mode = FLASH_BASE_MODE; flash_command_position = 0; } @@ -1664,7 +1653,6 @@ void function_cc write_backup(u32 address, u32 value) if((flash_command_position == 0) && (flash_mode == FLASH_WRITE_MODE)) { // Write value to flash ROM - backup_update = write_backup_delay; flash_bank_ptr[address] = value; flash_mode = FLASH_BASE_MODE; } @@ -1673,7 +1661,6 @@ void function_cc write_backup(u32 address, u32 value) if(backup_type == BACKUP_SRAM) { // Write value to SRAM - backup_update = write_backup_delay; // Hit 64KB territory? if(address >= 0x8000) sram_size = SRAM_SIZE_64KB; @@ -2205,18 +2192,6 @@ u32 save_backup(char *name) } void update_backup() -{ - if(backup_update != (write_backup_delay + 1)) - backup_update--; - - if(backup_update == 0) - { - save_backup(backup_filename); - backup_update = write_backup_delay + 1; - } -} - -void update_backup_force() { save_backup(backup_filename); } @@ -2421,6 +2396,7 @@ char gamepak_filename[512]; u32 load_gamepak(const char *name) { char cheats_filename[256]; + char *p; s32 file_size = load_gamepak_raw(name); @@ -2433,14 +2409,16 @@ u32 load_gamepak(const char *name) strncpy(gamepak_filename, name, sizeof(gamepak_filename)); gamepak_filename[sizeof(gamepak_filename) - 1] = 0; - 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); - } + p = strrchr(gamepak_filename, PATH_SEPARATOR_CHAR); + if (p == NULL) + p = gamepak_filename; + + snprintf(backup_filename, sizeof(backup_filename), "%s/%s", save_path, p); + p = strrchr(backup_filename, '.'); + if (p != NULL) + strcpy(p, ".sav"); + + load_backup(backup_filename); memcpy(gamepak_title, gamepak_rom + 0xA0, 12); memcpy(gamepak_code, gamepak_rom + 0xAC, 4); @@ -2450,9 +2428,6 @@ u32 load_gamepak(const char *name) gamepak_maker[2] = 0; load_game_config(gamepak_title, gamepak_code, gamepak_maker); -#ifndef __LIBRETRO__ - load_game_config_file(); -#endif change_ext(gamepak_filename, cheats_filename, ".cht"); add_cheats(cheats_filename); diff --git a/gba_memory.h b/gba_memory.h index a8a976b..d39220e 100644 --- a/gba_memory.h +++ b/gba_memory.h @@ -179,7 +179,6 @@ u32 load_gamepak(const char *name); u32 load_backup(char *name); s32 load_bios(char *name); void update_backup(); -void update_backup_force(); void init_memory(); void init_gamepak_buffer(); void memory_term(void); diff --git a/libretro.c b/libretro.c index b873594..c469bf1 100644 --- a/libretro.c +++ b/libretro.c @@ -188,13 +188,13 @@ void retro_cheat_set(unsigned index, bool enabled, const char* code) {} void error_msg(const char* text) { if (log_cb) - log_cb(RETRO_LOG_ERROR, text); + log_cb(RETRO_LOG_ERROR, "[gpSP]: %s\n", text); } void info_msg(const char* text) { if (log_cb) - log_cb(RETRO_LOG_INFO, text); + log_cb(RETRO_LOG_INFO, "[gpSP]: %s\n", text); } static void extract_directory(char* buf, const char* path, size_t size) @@ -217,11 +217,7 @@ bool retro_load_game(const struct retro_game_info* info) enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) - { - if (log_cb) - log_cb(RETRO_LOG_INFO, "[TempGBA]: 0RGB1555 is not supported.\n"); - return false; - } + info_msg("RGB565 is not supported."); extract_directory(main_path, info->path, sizeof(main_path)); @@ -233,34 +229,29 @@ bool retro_load_game(const struct retro_game_info* info) strncat(filename_bios, "/gba_bios.bin", sizeof(filename_bios)); - // if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) - // strncpy(dir_save, dir, sizeof(dir_save)); - // else - // strncpy(dir_save, main_path, sizeof(dir_save)); - - // strncat(dir_save, "/",sizeof(dir_save)); - - // strncat(main_path, "/",sizeof(main_path)); + if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) + strncpy(save_path, dir, sizeof(save_path)); + else + strncpy(save_path, main_path, sizeof(save_path)); if (load_bios(filename_bios) != 0) { - error_msg("Could not load BIOS image file.\n"); + error_msg("Could not load BIOS image file."); return false; } if (bios_rom[0] != 0x18) { - info_msg("You have an incorrect BIOS image.\n"); - info_msg("While many games will work fine, some will not. It\n"); - info_msg("is strongly recommended that you obtain the\n"); - info_msg("correct BIOS file.\n"); + info_msg("You have an incorrect BIOS image."); + info_msg("While many games will work fine, some will not."); + info_msg("It is strongly recommended that you obtain the correct BIOS file."); } gamepak_filename[0] = 0; if (load_gamepak(info->path) != 0) { - error_msg("Could not load the game file.\n"); + error_msg("Could not load the game file."); return false; } diff --git a/main.c b/main.c index 5f734da..b1482d1 100644 --- a/main.c +++ b/main.c @@ -75,6 +75,7 @@ u32 synchronize_flag = 1; u32 update_backup_flag = 1; char main_path[512]; +char save_path[512]; void trigger_ext_event(); @@ -532,7 +533,7 @@ void synchronize() void quit() { if(!update_backup_flag) - update_backup_force(); + update_backup(); sound_exit(); } @@ -587,19 +588,6 @@ void change_ext(const char *src, char *buffer, const char *extension) strcpy(dot_position, extension); } -// make path: /. -void make_rpath(char *buff, size_t size, const char *ext) -{ - char *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(void) \ { \ diff --git a/main.h b/main.h index d4abadb..73f03a0 100644 --- a/main.h +++ b/main.h @@ -84,6 +84,7 @@ extern u32 flush_ram_count; extern u64 base_timestamp; extern char main_path[512]; +extern char save_path[512]; extern u32 update_backup_flag; @@ -119,7 +120,6 @@ extern u32 max_frameskip; extern u32 num_skipped_frames; void change_ext(const char *src, char *buffer, const char *extension); -void make_rpath(char *buff, size_t size, const char *ext); #endif -- cgit v1.2.3