From d8225bb313a19bc3b65e257401d3cf5f3eaa32e3 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Sat, 5 Sep 2020 20:40:15 +0800 Subject: Add optional battery save using libretro save api - Adds core option to allow battery saves using the libretro api (retro_get_memory_data/size) - Initial save size set at 128KB and actual size is automatically determined internally by gba. - This will always assume that a save file is supported since save size or type cannot be determined until gba tries to write to backup memory. - A 128KB block of memory is used as buffer, similar method to VBA Next/Beetle GBA workarounds. Fix https://github.com/libretro/gpsp/issues/72 --- gba_memory.c | 54 ++++-------------------------------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) (limited to 'gba_memory.c') diff --git a/gba_memory.c b/gba_memory.c index a2d2a93..567010b 100644 --- a/gba_memory.c +++ b/gba_memory.c @@ -367,40 +367,11 @@ u32 gbc_sound_update = 0; // If the GBC audio waveform is modified: u32 gbc_sound_wave_update = 0; -typedef enum -{ - BACKUP_SRAM, - BACKUP_FLASH, - BACKUP_EEPROM, - BACKUP_NONE -} backup_type_type; - -typedef enum -{ - SRAM_SIZE_32KB, - SRAM_SIZE_64KB -} sram_size_type; - // Keep it 32KB until the upper 64KB is accessed, then make it 64KB. backup_type_type backup_type = BACKUP_NONE; sram_size_type sram_size = SRAM_SIZE_32KB; -typedef enum -{ - FLASH_BASE_MODE, - FLASH_ERASE_MODE, - FLASH_ID_MODE, - FLASH_WRITE_MODE, - FLASH_BANKSWITCH_MODE -} flash_mode_type; - -typedef enum -{ - FLASH_SIZE_64KB, - FLASH_SIZE_128KB -} flash_size_type; - flash_mode_type flash_mode = FLASH_BASE_MODE; u32 flash_command_position = 0; u8 *flash_bank_ptr = gamepak_backup; @@ -459,25 +430,6 @@ u8 read_backup(u32 address) // EEPROM is 512 bytes by default; it is autodetecte as 8KB if // 14bit address DMAs are made (this is done in the DMA handler). -typedef enum -{ - EEPROM_512_BYTE, - EEPROM_8_KBYTE -} eeprom_size_type; - -typedef enum -{ - EEPROM_BASE_MODE, - EEPROM_READ_MODE, - EEPROM_READ_HEADER_MODE, - EEPROM_ADDRESS_MODE, - EEPROM_WRITE_MODE, - EEPROM_WRITE_ADDRESS_MODE, - EEPROM_ADDRESS_FOOTER_MODE, - EEPROM_WRITE_FOOTER_MODE -} eeprom_mode_type; - - eeprom_size_type eeprom_size = EEPROM_512_BYTE; eeprom_mode_type eeprom_mode = EEPROM_BASE_MODE; u32 eeprom_address_length; @@ -2197,7 +2149,8 @@ u32 save_backup(char *name) void update_backup(void) { - save_backup(backup_filename); + if (!use_libretro_save_method) + save_backup(backup_filename); } #define CONFIG_FILENAME "game_config.txt" @@ -2480,7 +2433,8 @@ u32 load_gamepak(const struct retro_game_info* info, const char *name) if (p) strcpy(p, ".sav"); - load_backup(backup_filename); + if (!use_libretro_save_method) + load_backup(backup_filename); memcpy(gamepak_title, gamepak_rom + 0xA0, 12); memcpy(gamepak_code, gamepak_rom + 0xAC, 4); -- cgit v1.2.3