Skip to content

Commit

Permalink
Fixing issues with save state code writing pointers into save states.
Browse files Browse the repository at this point in the history
This breaks compatibility with older save states.
Nebuleon/ReGBA@c4447cb
  • Loading branch information
gameblabla committed Jun 27, 2019
1 parent 807d7ab commit dccd8e8
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ typedef enum

flash_mode_type flash_mode = FLASH_BASE_MODE;
u32 flash_command_position = 0;
u8 *flash_bank_ptr = gamepak_backup;
u32 flash_bank_offset = 0;

flash_device_id_type flash_device_id = FLASH_DEVICE_MACRONIX_64KB;
flash_manufacturer_id_type flash_manufacturer_id =
Expand Down Expand Up @@ -198,7 +198,7 @@ u8 read_backup(u32 address)
}
else
{
value = flash_bank_ptr[address];
value = gamepak_backup[flash_bank_offset + address];
}

return value;
Expand Down Expand Up @@ -1370,7 +1370,7 @@ void function_cc write_backup(u32 address, u32 value)
(flash_mode == FLASH_ERASE_MODE) && (value == 0x30))
{
// Erase sector
memset(flash_bank_ptr + (address & 0xF000), 0xFF, 1024 * 4);
memset(gamepak_backup + flash_bank_offset + (address & 0xF000), 0xFF, 1024 * 4);
backup_update = write_backup_delay;
flash_mode = FLASH_BASE_MODE;
flash_command_position = 0;
Expand All @@ -1381,7 +1381,7 @@ void function_cc write_backup(u32 address, u32 value)
(flash_mode == FLASH_BANKSWITCH_MODE) && (address == 0x0000) &&
(flash_size == FLASH_SIZE_128KB))
{
flash_bank_ptr = gamepak_backup + ((value & 0x01) * (1024 * 64));
flash_bank_offset = ((value & 0x01) * (1024 * 64));
flash_mode = FLASH_BASE_MODE;
}
else
Expand All @@ -1390,7 +1390,7 @@ void function_cc write_backup(u32 address, u32 value)
{
// Write value to flash ROM
backup_update = write_backup_delay;
flash_bank_ptr[address] = value;
gamepak_backup[flash_bank_offset + address] = value;
flash_mode = FLASH_BASE_MODE;
}
else
Expand Down Expand Up @@ -3123,7 +3123,7 @@ void init_memory()

backup_type = BACKUP_NONE;

flash_bank_ptr = gamepak_backup;
flash_bank_offset = 0;
flash_command_position = 0;
eeprom_mode = EEPROM_BASE_MODE;
eeprom_address = 0;
Expand Down Expand Up @@ -3255,7 +3255,7 @@ void memory_##type##_savestate(file_tag_type savestate_file) \
file_##type##_variable(savestate_file, sram_size); \
file_##type##_variable(savestate_file, flash_mode); \
file_##type##_variable(savestate_file, flash_command_position); \
file_##type##_variable(savestate_file, flash_bank_ptr); \
file_##type##_variable(savestate_file, flash_bank_offset); \
file_##type##_variable(savestate_file, flash_device_id); \
file_##type##_variable(savestate_file, flash_manufacturer_id); \
file_##type##_variable(savestate_file, flash_size); \
Expand Down Expand Up @@ -3286,12 +3286,6 @@ void memory_##type##_savestate(file_tag_type savestate_file) \
file_##type(savestate_file, palette_ram, 0x400); \
file_##type(savestate_file, io_registers, 0x8000); \
\
/* This is a hack, for now. */ \
if((flash_bank_ptr < gamepak_backup) || \
(flash_bank_ptr > (gamepak_backup + (1024 * 64)))) \
{ \
flash_bank_ptr = gamepak_backup; \
} \
} \

memory_savestate_builder(read);
Expand Down

0 comments on commit dccd8e8

Please sign in to comment.